diff --git a/am/include/arch/native.h b/am/include/arch/native.h index 5cf5d8aa..13b66cbc 100644 --- a/am/include/arch/native.h +++ b/am/include/arch/native.h @@ -7,9 +7,6 @@ #include -#define false 0 -#define true 1 - struct _Context { union { uint8_t pad[1024]; diff --git a/am/include/navy.h b/am/include/navy.h index cb1ee35d..d5c1d822 100644 --- a/am/include/navy.h +++ b/am/include/navy.h @@ -4,9 +4,6 @@ #include #include -#define false 0 -#define true 1 - struct _Context { }; diff --git a/am/include/riscv32.h b/am/include/riscv32.h index ac2cd462..d4da5d1c 100644 --- a/am/include/riscv32.h +++ b/am/include/riscv32.h @@ -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; } diff --git a/am/src/navy/dev/input.c b/am/src/navy/dev/input.c index 85092a7a..df9146cd 100644 --- a/am/src/navy/dev/input.c +++ b/am/src/navy/dev/input.c @@ -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) { diff --git a/am/src/riscv32/noop/instr.c b/am/src/riscv32/noop/instr.c index aacb0765..a6ced816 100644 --- a/am/src/riscv32/noop/instr.c +++ b/am/src/riscv32/noop/instr.c @@ -1,6 +1,7 @@ #include #include #include +#include static uint32_t mul(uint32_t a, uint32_t b, int sign, int hi) { if (a == 0x80000000 && b == 0x80000000) { diff --git a/apps/dhrystone/dry.c b/apps/dhrystone/dry.c index 03e50774..d6af49b9 100644 --- a/apps/dhrystone/dry.c +++ b/apps/dhrystone/dry.c @@ -352,6 +352,7 @@ #include #include +#include #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; diff --git a/apps/litenes/include/common.h b/apps/litenes/include/common.h index b946b692..7b1b8c05 100644 --- a/apps/litenes/include/common.h +++ b/apps/litenes/include/common.h @@ -4,14 +4,11 @@ #include #include #include +#include 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); diff --git a/apps/litenes_opt/include/common.h b/apps/litenes_opt/include/common.h index 98a04515..76ca906d 100644 --- a/apps/litenes_opt/include/common.h +++ b/apps/litenes_opt/include/common.h @@ -4,14 +4,11 @@ #include #include #include +#include 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, ...) diff --git a/apps/microbench/include/benchmark.h b/apps/microbench/include/benchmark.h index 40428754..48a9d9fb 100644 --- a/apps/microbench/include/benchmark.h +++ b/apps/microbench/include/benchmark.h @@ -3,6 +3,7 @@ #include #include +#include #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 diff --git a/apps/typing/game.h b/apps/typing/game.h index bfc1a9d7..528123d4 100644 --- a/apps/typing/game.h +++ b/apps/typing/game.h @@ -12,6 +12,7 @@ #include #include +#include /* 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); diff --git a/libs/klib/include/klib-macros.h b/libs/klib/include/klib-macros.h index 1ab99bf5..da2d8877 100644 --- a/libs/klib/include/klib-macros.h +++ b/libs/klib/include/klib-macros.h @@ -3,6 +3,12 @@ #include +#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)) diff --git a/libs/klib/src/stdio.c b/libs/klib/src/stdio.c index ca83c76c..5235362a 100644 --- a/libs/klib/src/stdio.c +++ b/libs/klib/src/stdio.c @@ -1,8 +1,6 @@ #include "klib.h" #include - -#define true 1 -#define false 0 +#include #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:; } diff --git a/tests/cputest/tests/bit.c b/tests/cputest/tests/bit.c index 74ca6530..bfa5f941 100644 --- a/tests/cputest/tests/bit.c +++ b/tests/cputest/tests/bit.c @@ -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;