From a62a132587b8afd8c7e8c14ae6ca9d59be213289 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Wed, 20 Mar 2024 20:07:28 +0800 Subject: [PATCH] pa2.2: cleanup includes --- nemu/include/common.h | 19 +------------------ nemu/include/debug.h | 3 ++- nemu/include/types.h | 21 +++++++++++++++++++++ nemu/include/utils.h | 5 +---- nemu/src/cpu/cpu-exec.c | 2 +- nemu/src/isa/riscv32/inst.c | 3 ++- nemu/src/monitor/monitor.c | 1 + nemu/src/monitor/sdb/addrexp.y | 1 + nemu/src/utils/ftrace.c | 3 +-- nemu/src/utils/log.c | 1 + 10 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 nemu/include/types.h diff --git a/nemu/include/common.h b/nemu/include/common.h index fbffaa5..08a46e5 100644 --- a/nemu/include/common.h +++ b/nemu/include/common.h @@ -17,12 +17,12 @@ #define __COMMON_H__ #include -#include #include #include #include #include +#include #ifdef CONFIG_TARGET_AM #include @@ -31,23 +31,6 @@ #include #endif -#if CONFIG_MBASE + CONFIG_MSIZE > 0x100000000ul -#define PMEM64 1 -#endif - -typedef MUXDEF(CONFIG_ISA64, uint64_t, uint32_t) word_t; -typedef MUXDEF(CONFIG_ISA64, int64_t, int32_t) sword_t; -static const word_t WORD_T_MAX = MUXDEF(CONFIG_ISA64, UINT64_MAX, UINT32_MAX); -static const sword_t SWORD_T_MAX = MUXDEF(CONFIG_ISA64, INT64_MAX, INT32_MAX); -static const sword_t SWORD_T_MIN = MUXDEF(CONFIG_ISA64, INT64_MIN, INT32_MIN); -#define WORD_BYTES MUXDEF(CONFIG_ISA64, 8, 4) -#define FMT_WORD MUXDEF(CONFIG_ISA64, "0x%016" PRIx64, "0x%08" PRIx32) - -typedef word_t vaddr_t; -typedef MUXDEF(PMEM64, uint64_t, uint32_t) paddr_t; -#define FMT_PADDR MUXDEF(PMEM64, "0x%016" PRIx64, "0x%08" PRIx32) -typedef uint16_t ioaddr_t; - #include #endif diff --git a/nemu/include/debug.h b/nemu/include/debug.h index 057f8bf..3aae781 100644 --- a/nemu/include/debug.h +++ b/nemu/include/debug.h @@ -16,10 +16,11 @@ #ifndef __DEBUG_H__ #define __DEBUG_H__ -#include #include #include +IFDEF(CONFIG_ITRACE, void log_itrace_print()); + #define Trace(format, ...) \ _Log("[TRACE] " format "\n", ## __VA_ARGS__) diff --git a/nemu/include/types.h b/nemu/include/types.h new file mode 100644 index 0000000..364f2ed --- /dev/null +++ b/nemu/include/types.h @@ -0,0 +1,21 @@ +#ifndef __TYPES_H__ +#define __TYPES_H__ +#include +#include +#if CONFIG_MBASE + CONFIG_MSIZE > 0x100000000ul +#define PMEM64 1 +#endif + +typedef MUXDEF(CONFIG_ISA64, uint64_t, uint32_t) word_t; +typedef MUXDEF(CONFIG_ISA64, int64_t, int32_t) sword_t; +static const word_t WORD_T_MAX = MUXDEF(CONFIG_ISA64, UINT64_MAX, UINT32_MAX); +static const sword_t SWORD_T_MAX = MUXDEF(CONFIG_ISA64, INT64_MAX, INT32_MAX); +static const sword_t SWORD_T_MIN = MUXDEF(CONFIG_ISA64, INT64_MIN, INT32_MIN); +#define WORD_BYTES MUXDEF(CONFIG_ISA64, 8, 4) +#define FMT_WORD MUXDEF(CONFIG_ISA64, "0x%016" PRIx64, "0x%08" PRIx32) + +typedef word_t vaddr_t; +typedef MUXDEF(PMEM64, uint64_t, uint32_t) paddr_t; +#define FMT_PADDR MUXDEF(PMEM64, "0x%016" PRIx64, "0x%08" PRIx32) +typedef uint16_t ioaddr_t; +#endif \ No newline at end of file diff --git a/nemu/include/utils.h b/nemu/include/utils.h index 59bc9df..f974584 100644 --- a/nemu/include/utils.h +++ b/nemu/include/utils.h @@ -16,7 +16,7 @@ #ifndef __UTILS_H__ #define __UTILS_H__ -#include +#include // ----------- state ----------- @@ -74,7 +74,4 @@ uint64_t get_time(); } while (0) -IFDEF(CONFIG_ITRACE, void log_itrace_print()); - - #endif diff --git a/nemu/src/cpu/cpu-exec.c b/nemu/src/cpu/cpu-exec.c index 72e1265..1e402ab 100644 --- a/nemu/src/cpu/cpu-exec.c +++ b/nemu/src/cpu/cpu-exec.c @@ -13,7 +13,7 @@ * See the Mulan PSL v2 for more details. ***************************************************************************************/ -#include "utils.h" +#include #include #include #include diff --git a/nemu/src/isa/riscv32/inst.c b/nemu/src/isa/riscv32/inst.c index 54b9044..c4d824f 100644 --- a/nemu/src/isa/riscv32/inst.c +++ b/nemu/src/isa/riscv32/inst.c @@ -13,12 +13,13 @@ * See the Mulan PSL v2 for more details. ***************************************************************************************/ -#include "common.h" +#include #include "local-include/reg.h" #include #include #include #include +#include #define R(i) gpr(i) #define Mr vaddr_read diff --git a/nemu/src/monitor/monitor.c b/nemu/src/monitor/monitor.c index 1920ae4..6755edf 100644 --- a/nemu/src/monitor/monitor.c +++ b/nemu/src/monitor/monitor.c @@ -15,6 +15,7 @@ #include #include +#include void init_rand(); void init_log(const char *log_file); diff --git a/nemu/src/monitor/sdb/addrexp.y b/nemu/src/monitor/sdb/addrexp.y index 8e7df9a..4094e0b 100644 --- a/nemu/src/monitor/sdb/addrexp.y +++ b/nemu/src/monitor/sdb/addrexp.y @@ -7,6 +7,7 @@ } %{ #include + #include #include #include #include diff --git a/nemu/src/utils/ftrace.c b/nemu/src/utils/ftrace.c index 25f097a..ec668c0 100644 --- a/nemu/src/utils/ftrace.c +++ b/nemu/src/utils/ftrace.c @@ -1,9 +1,8 @@ -#include "debug.h" -#include "macro.h" #include #include #include #include +#include // Put this into another file #ifdef CONFIG_FTRACE diff --git a/nemu/src/utils/log.c b/nemu/src/utils/log.c index 7939d42..a041a2d 100644 --- a/nemu/src/utils/log.c +++ b/nemu/src/utils/log.c @@ -14,6 +14,7 @@ ***************************************************************************************/ #include +#include extern uint64_t g_nr_guest_inst;