libs,klib,macros: define bool/true/false for C files

This commit is contained in:
Zihao Yu 2020-02-07 17:23:16 +08:00
parent 2f890daa56
commit b2cd0c447b
13 changed files with 31 additions and 49 deletions

View File

@ -7,9 +7,6 @@
#include <ucontext.h>
#define false 0
#define true 1
struct _Context {
union {
uint8_t pad[1024];

View File

@ -4,9 +4,6 @@
#include <unistd.h>
#include <sys/types.h>
#define false 0
#define true 1
struct _Context {
};

View File

@ -10,9 +10,6 @@ typedef union {
int64_t val;
} R64;
#define true 1
#define false 0
static inline uint8_t inb(uintptr_t addr) { return *(volatile uint8_t *)addr; }
static inline uint16_t inw(uintptr_t addr) { return *(volatile uint16_t *)addr; }
static inline uint32_t inl(uintptr_t addr) { return *(volatile uint32_t *)addr; }

View File

@ -31,10 +31,10 @@ int __am_event_thread(void) {
key_queue[key_r] = am_code;
key_r = (key_r + 1) % KEY_QUEUE_LEN;
}
return true;
return 1;
}
return false;
return 0;
}
size_t __am_input_read(uintptr_t reg, void *buf, size_t size) {

View File

@ -1,6 +1,7 @@
#include <am.h>
#include <riscv32.h>
#include <klib.h>
#include <klib-macros.h>
static uint32_t mul(uint32_t a, uint32_t b, int sign, int hi) {
if (a == 0x80000000 && b == 0x80000000) {

View File

@ -352,6 +352,7 @@
#include <am.h>
#include <klib.h>
#include <klib-macros.h>
#define Start_Timer() Begin_Time = uptime()
#define Stop_Timer() End_Time = uptime()
@ -383,8 +384,6 @@
#define Null 0
/* Value of a Null pointer */
#define true 1
#define false 0
typedef int One_Thirty;
typedef int One_Fifty;

View File

@ -4,14 +4,11 @@
#include <am.h>
#include <amdev.h>
#include <klib.h>
#include <klib-macros.h>
typedef uint8_t byte;
typedef uint16_t word;
typedef uint32_t dword;
typedef int bool;
#define true 1
#define false 0
// Binary Operations
bool common_bit_set(long long value, byte position);

View File

@ -4,14 +4,11 @@
#include <am.h>
#include <amdev.h>
#include <klib.h>
#include <klib-macros.h>
typedef uint8_t byte;
typedef uint16_t word;
typedef uint32_t dword;
typedef int bool;
#define true 1
#define false 0
// #define log(fmt, ...) printf("%s:%d: " fmt, __func__, __LINE__, ## __VA_ARGS__)
#define log(fmt, ...)

View File

@ -3,6 +3,7 @@
#include <am.h>
#include <klib.h>
#include <klib-macros.h>
#ifdef __cplusplus
extern "C" {
@ -11,9 +12,6 @@ extern "C" {
#define MB * 1024 * 1024
#define KB * 1024
#define true 1
#define false 0
#define REF_CPU "i7-7700K @ 4.20GHz"
#define REF_SCORE 100000

View File

@ -12,6 +12,7 @@
#include <am.h>
#include <klib.h>
#include <klib-macros.h>
/* Usage:
* my_list.h:
@ -98,11 +99,6 @@ LINKLIST_DEF(fly)
int v;
LINKLIST_DEF_FI(fly)
typedef char bool;
#define true 1
#define false 0
/* 按键相关 */
void press_key(int scan_code);
void release_key(int ch);

View File

@ -3,6 +3,12 @@
#include <am.h>
#ifndef __cplusplus
typedef uint8_t bool;
#define false 0
#define true 1
#endif
#define ROUNDUP(a, sz) ((((uintptr_t)a)+(sz)-1) & ~((sz)-1))
#define ROUNDDOWN(a, sz) ((((uintptr_t)a)) & ~((sz)-1))

View File

@ -1,8 +1,6 @@
#include "klib.h"
#include <stdarg.h>
#define true 1
#define false 0
#include <klib-macros.h>
#if !defined(__ISA_NATIVE__) || defined(__NATIVE_USE_KLIB__)
@ -17,7 +15,7 @@ typedef struct {
size_t nbyte;
} format_t;
static void putch(char c, int n, format_t *f) {
static void __putch(char c, int n, format_t *f) {
while (n --) {
if (f->out == NULL) _putc(c);
// do not output if we reach the given size of the buffer
@ -26,8 +24,8 @@ static void putch(char c, int n, format_t *f) {
}
}
static void putstr(const char *s, int len, format_t *f) {
while (len --) putch(*s ++, 1, f);
static void __putstr(const char *s, int len, format_t *f) {
while (len --) __putch(*s ++, 1, f);
}
#define FORMAT_FUN_DEF(name, base) \
@ -66,7 +64,7 @@ static int vsnprintf_internal(char *out, size_t size, const char *fmt, va_list a
while (*pfmt) {
char ch = *pfmt ++;
if (ch != '%') {
putch(ch, 1, &f);
__putch(ch, 1, &f);
continue;
}
@ -157,18 +155,18 @@ print_num:;
conv_len = sign_len + prec_pad0_len + digit_len;
width_pad_len = (width > conv_len ? width - conv_len : 0);
if (!f.pad.is_right && f.pad.ch == ' ') { putch(f.pad.ch, width_pad_len, &f); }
if (sign_len) putch(f.sign.ch, 1, &f);
if (!f.pad.is_right && f.pad.ch == '0') { putch(f.pad.ch, width_pad_len, &f); }
putch('0', prec_pad0_len, &f);
putstr(p_digit, digit_len, &f);
if (f.pad.is_right) { putch(f.pad.ch, width_pad_len, &f); }
if (!f.pad.is_right && f.pad.ch == ' ') { __putch(f.pad.ch, width_pad_len, &f); }
if (sign_len) __putch(f.sign.ch, 1, &f);
if (!f.pad.is_right && f.pad.ch == '0') { __putch(f.pad.ch, width_pad_len, &f); }
__putch('0', prec_pad0_len, &f);
__putstr(p_digit, digit_len, &f);
if (f.pad.is_right) { __putch(f.pad.ch, width_pad_len, &f); }
break;
case 'p':
varguint = va_arg(ap, uintptr_t);
if (varguint == 0) { putstr("(nil)", 5, &f); break; }
putstr("0x", 2, &f);
if (varguint == 0) { __putstr("(nil)", 5, &f); break; }
__putstr("0x", 2, &f);
base = 16;
goto print_num;
@ -183,12 +181,12 @@ print_num:;
conv_len = (prec == 0 ? strlen(p_str) : prec);
print_str:
width_pad_len = (width > conv_len ? width - conv_len : 0);
if (!f.pad.is_right) { putch(f.pad.ch, width_pad_len, &f); }
putstr(p_str, conv_len, &f);
if (f.pad.is_right) { putch(f.pad.ch, width_pad_len, &f); }
if (!f.pad.is_right) { __putch(f.pad.ch, width_pad_len, &f); }
__putstr(p_str, conv_len, &f);
if (f.pad.is_right) { __putch(f.pad.ch, width_pad_len, &f); }
break;
case '%': putch('%', 1, &f); break;
case '%': __putch('%', 1, &f); break;
default:;
}

View File

@ -1,7 +1,6 @@
#include "trap.h"
typedef unsigned char uint8_t;
typedef char bool;
__attribute__((noinline))
bool getbit(void *buf, int offset){
int byte = offset >> 3;