diff --git a/include/common.h b/include/common.h index 52b03ef20115e9bf4956cb81514b182c97d6eb74..a5d8474c3b6a43b8a085c465955e73a0bbdc306d 100644 --- a/include/common.h +++ b/include/common.h @@ -1,7 +1,7 @@ #ifndef __COMMON_H__ #define __COMMON_H__ -#define DEBUG +//#define DEBUG //#define DIFF_TEST #define ISA64 diff --git a/include/monitor/diff-test.h b/include/monitor/diff-test.h index 8c9c43d10966b5285c636a307fff6aedfb889d72..8aef569037382adbc7ee241267be6a2388178605 100644 --- a/include/monitor/diff-test.h +++ b/include/monitor/diff-test.h @@ -22,7 +22,7 @@ extern void (*ref_difftest_exec)(uint64_t n); static inline bool difftest_check_reg(const char *name, vaddr_t pc, rtlreg_t ref, rtlreg_t dut) { if (ref != dut) { #ifdef ISA64 - Log("%s is different after executing instruction at pc = 0x%16lx, right = 0x%16lx, wrong = 0x%16lx", + Log("%s is different after executing instruction at pc = 0x%016lx, right = 0x%016lx, wrong = 0x%016lx", name, pc, ref, dut); #else Log("%s is different after executing instruction at pc = 0x%08x, right = 0x%08x, wrong = 0x%08x", diff --git a/include/rtl/rtl.h b/include/rtl/rtl.h index 77477d03eb44738bf29feb278a80e330ad1cf8eb..3d9ecd9610eaa6e2769645da27f2752559f098dc 100644 --- a/include/rtl/rtl.h +++ b/include/rtl/rtl.h @@ -13,7 +13,7 @@ bool interpret_relop(uint32_t relop, const rtlreg_t src1, const rtlreg_t src2); /* RTL basic instructions */ -static inline void interpret_rtl_li(rtlreg_t* dest, uint64_t imm) { +static inline void interpret_rtl_li(rtlreg_t* dest, rtlreg_t imm) { *dest = imm; } @@ -158,17 +158,24 @@ static inline void rtl_not(rtlreg_t *dest, const rtlreg_t* src1) { static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) { // dest <- signext(src1[(width * 8 - 1) .. 0]) // TODO(); + +#ifdef ISA64 if (width == 8) { rtl_mv(dest, src1); } else { assert(width == 1 || width == 2 || width == 4); rtl_shli(dest, src1, (8 - width) * 8); -#ifdef ISA64 rtl_sar64i(dest, dest, (8 - width) * 8); + } #else - rtl_sari(dest, dest, (8 - width) * 8); -#endif + if (width == 4) { + rtl_mv(dest, src1); + } else { + assert(width == 1 || width == 2); + rtl_shli(dest, src1, (4 - width) * 8); + rtl_sari(dest, dest, (4 - width) * 8); } +#endif } static inline void rtl_setrelopi(uint32_t relop, rtlreg_t *dest, diff --git a/runall.sh b/runall.sh index d0dad91a6e80e1ce7f52e2ed55d64172f2ffdce6..c2b8e8b52d3c59082cf43bb34b34b662d7b42908 100644 --- a/runall.sh +++ b/runall.sh @@ -30,7 +30,7 @@ for file in $files; do if (grep 'nemu: .*HIT GOOD TRAP' $logfile > /dev/null) then echo -e "\033[1;32mPASS!\033[0m" - #rm $logfile + rm $logfile else echo -e "\033[1;31mFAIL!\033[0m see $logfile for more information" if (test -e $ori_log) then diff --git a/src/cpu/inv.c b/src/cpu/inv.c index c255f51f538726a0a7b5392c2c0e6b8ddbdff8ee..4afab7e907729ad957b3abafdfc601892f3e2c77 100644 --- a/src/cpu/inv.c +++ b/src/cpu/inv.c @@ -5,9 +5,9 @@ void display_inv_msg(vaddr_t pc) { #ifdef ISA64 printf("There are two cases which will trigger this unexpected exception:\n" - "1. The instruction at PC = 0x%16lx is not implemented.\n" + "1. The instruction at PC = 0x%016lx is not implemented.\n" "2. Something is implemented incorrectly.\n", pc); - printf("Find this PC(0x%16lx) in the disassembling result to distinguish which case it is.\n\n", pc); + printf("Find this PC(0x%016lx) in the disassembling result to distinguish which case it is.\n\n", pc); #else printf("There are two cases which will trigger this unexpected exception:\n" "1. The instruction at PC = 0x%08x is not implemented.\n" diff --git a/src/device/io/map.c b/src/device/io/map.c index 25668bcdb37f028e83db71acbbc03e3589ccf2d3..8f969fd78eb4544a2081bc71bced95d4b777032b 100644 --- a/src/device/io/map.c +++ b/src/device/io/map.c @@ -19,7 +19,7 @@ uint8_t* new_space(int size) { static inline void check_bound(IOMap *map, paddr_t addr) { #ifdef ISA64 Assert(map != NULL && addr <= map->high && addr >= map->low, - "address (0x%08x) is out of bound {%s} [0x%08x, 0x%08x] at pc = 0x%16lx", + "address (0x%08x) is out of bound {%s} [0x%08x, 0x%08x] at pc = 0x%016lx", addr, (map ? map->name : "???"), (map ? map->low : 0), (map ? map->high : 0), cpu.pc); #else Assert(map != NULL && addr <= map->high && addr >= map->low, diff --git a/src/isa/riscv32/decode.c b/src/isa/riscv32/decode.c index 336ee24de6db84f6461db181256750d60509f284..2f5614ab667ecd99940d93cc9c3bf4ddd64c829e 100644 --- a/src/isa/riscv32/decode.c +++ b/src/isa/riscv32/decode.c @@ -1,7 +1,7 @@ #include "cpu/decode.h" #include "rtl/rtl.h" -// decode operand helper (i & r) +// decode operand helper #define make_DopHelper(name) void concat(decode_op_, name) (Operand *op, uint32_t val, bool load_val) static inline make_DopHelper(i) { @@ -16,13 +16,12 @@ static inline make_DopHelper(r) { op->type = OP_TYPE_REG; op->reg = val; if (load_val) { - rtl_lr(&op->val, op->reg, 4); // here reg is index of reg, width is ignored + rtl_lr(&op->val, op->reg, 4); } print_Dop(op->str, OP_STR_SIZE, "%s", reg_name(op->reg, 4)); } -// decode helper (I, R, U, J, B, ld, st, csr) make_DHelper(I) { decode_op_r(id_src, decinfo.isa.instr.rs1, true); decode_op_i(id_src2, decinfo.isa.instr.simm11_0, true); diff --git a/src/isa/riscv64/exec/special.c b/src/isa/riscv64/exec/special.c index 7cfb8bb708069b3dfe2473cc2d8cb44c019e051a..f89cc6e25042063a7b04111cd7c8bca834984492 100644 --- a/src/isa/riscv64/exec/special.c +++ b/src/isa/riscv64/exec/special.c @@ -9,7 +9,7 @@ make_EHelper(inv) { instr[0] = instr_fetch(pc, 4); instr[1] = instr_fetch(pc, 4); - printf("invalid opcode(PC = 0x%16lx): %08x %08x ...\n\n", + printf("invalid opcode(PC = 0x%016lx): %08x %08x ...\n\n", cpu.pc, instr[0], instr[1]); display_inv_msg(cpu.pc); diff --git a/src/isa/riscv64/reg.c b/src/isa/riscv64/reg.c index 4023f4fc118e8376287bae3ec871f4d63f87fc65..b98abbe0a52e629fb7d29db097f248c1f6dd91da 100644 --- a/src/isa/riscv64/reg.c +++ b/src/isa/riscv64/reg.c @@ -10,12 +10,12 @@ const char *regsl[] = { void isa_reg_display() { int i; for (i = 0; i < 32; i ++) { - printf("%s: 0x%16lx ", regsl[i], cpu.gpr[i]._64); + printf("%s: 0x%016lx ", regsl[i], cpu.gpr[i]._64); if (i % 4 == 3) { printf("\n"); } } - printf("pc: 0x%16lx\n", cpu.pc); + printf("pc: 0x%016lx\n", cpu.pc); } rtlreg_t isa_reg_str2val(const char *s, bool *success) { diff --git a/src/monitor/cpu-exec.c b/src/monitor/cpu-exec.c index ad25a3eb282a4b7272b2cb069117d6f401b50f1c..54e7fb96211f8e3852d49b6195c2551486544b9f 100644 --- a/src/monitor/cpu-exec.c +++ b/src/monitor/cpu-exec.c @@ -62,7 +62,7 @@ void cpu_exec(uint64_t n) { WP *wp = scan_watchpoint(); if(wp != NULL) { #ifdef ISA64 - printf("\n\nHint watchpoint %d at address 0x%16lx, expr = %s\n", wp->NO, ori_pc, wp->expr); + printf("\n\nHint watchpoint %d at address 0x%016lx, expr = %s\n", wp->NO, ori_pc, wp->expr); #else printf("\n\nHint watchpoint %d at address 0x%08x, expr = %s\n", wp->NO, ori_pc, wp->expr); #endif @@ -88,7 +88,7 @@ void cpu_exec(uint64_t n) { case NEMU_END: case NEMU_ABORT: #ifdef ISA64 - _Log("nemu: %s\33[0m at pc = 0x%16lx\n\n", + _Log("nemu: %s\33[0m at pc = 0x%016lx\n\n", (nemu_state.state == NEMU_ABORT ? "\33[1;31mABORT" : (nemu_state.halt_ret == 0 ? "\33[1;32mHIT GOOD TRAP" : "\33[1;31mHIT BAD TRAP")), nemu_state.halt_pc); diff --git a/src/monitor/debug/expr.c b/src/monitor/debug/expr.c index 23a0ab1b9699d601b3b405803e4e8feaccf46ed6..f870f01fb04c30413f952082234c23f73f15eede 100644 --- a/src/monitor/debug/expr.c +++ b/src/monitor/debug/expr.c @@ -175,7 +175,7 @@ static int find_dominated_op(int s, int e, bool *success) { uint32_t isa_reg_str2val(const char*, bool *); -static uint64_t eval(int s, int e, bool *success) { +static rtlreg_t eval(int s, int e, bool *success) { if (s > e) { // bad expression *success = false; @@ -183,7 +183,7 @@ static uint64_t eval(int s, int e, bool *success) { } else if (s == e) { // single token - uint64_t val; + rtlreg_t val; switch (tokens[s].type) { case TK_REG: val = isa_reg_str2val(tokens[s].str + 1, success); // +1 to skip '$' if (!*success) { return 0; } @@ -205,7 +205,7 @@ static uint64_t eval(int s, int e, bool *success) { int op_type = tokens[dominated_op].type; if (op_type == '!' || op_type == TK_NEG || op_type == TK_REF) { - uint64_t val = eval(dominated_op + 1, e, success); + rtlreg_t val = eval(dominated_op + 1, e, success); if (!*success) { return 0; } switch (op_type) { @@ -216,9 +216,9 @@ static uint64_t eval(int s, int e, bool *success) { } } - uint64_t val1 = eval(s, dominated_op - 1, success); + rtlreg_t val1 = eval(s, dominated_op - 1, success); if (!*success) { return 0; } - uint64_t val2 = eval(dominated_op + 1, e, success); + rtlreg_t val2 = eval(dominated_op + 1, e, success); if (!*success) { return 0; } switch (op_type) { @@ -236,7 +236,7 @@ static uint64_t eval(int s, int e, bool *success) { } } -uint64_t expr(char *e, bool *success) { +rtlreg_t expr(char *e, bool *success) { if (!make_token(e)) { *success = false; return 0; diff --git a/src/monitor/debug/log.c b/src/monitor/debug/log.c index b027509fae04e8e87d8e588edb34591c3e457133..d917a858471ed642fbfe105d0099f24194fa62a1 100644 --- a/src/monitor/debug/log.c +++ b/src/monitor/debug/log.c @@ -23,10 +23,10 @@ void strcatf(char *buf, const char *fmt, ...) { void asm_print(vaddr_t ori_pc, int instr_len, bool print_flag) { #ifdef ISA64 - snprintf(tempbuf, sizeof(tempbuf), "%16lx: %s%*.s%s", ori_pc, log_bytebuf, + snprintf(tempbuf, sizeof(tempbuf), "%016lx: %s%*.s%s", ori_pc, log_bytebuf, 50 - (12 + 3 * instr_len), "", log_asmbuf); #else - snprintf(tempbuf, sizeof(tempbuf), "%08x: %s%*.s%s", ori_pc, log_bytebuf, + snprintf(tempbuf, sizeof(tempbuf), "%8x: %s%*.s%s", ori_pc, log_bytebuf, 50 - (12 + 3 * instr_len), "", log_asmbuf); #endif log_write("%s\n", tempbuf); diff --git a/src/monitor/debug/ui.c b/src/monitor/debug/ui.c index 3362a65f61f3f9c51be920d0b6aa985b8e51777f..11fd05063455a80133d5f4bd53f9af6051cd9792 100644 --- a/src/monitor/debug/ui.c +++ b/src/monitor/debug/ui.c @@ -93,7 +93,7 @@ static int cmd_p(char *args) { if(success) { printf("0x%lx\n", r); } #else uint32_t r = expr(args, &success); - if(success) { printf("0x%x\n", r); } + if(success) { printf("%d\n", r); } #endif else { printf("Bad expression\n"); } } @@ -128,7 +128,7 @@ static int cmd_x(char *args) { for (i = 0; i < n; i ++) { if (i % 4 == 0) { #ifdef ISA64 - printf("0x%16lx: ", addr); + printf("0x%016lx: ", addr); #else printf("0x%08x: ", addr); #endif diff --git a/tools/qemu-diff/src/diff-test.c b/tools/qemu-diff/src/diff-test.c index 1c214ee2c59b2ebf31e0cc7604026160c361e55b..2589fb56ced56eac77be2f089320d82a72862634 100644 --- a/tools/qemu-diff/src/diff-test.c +++ b/tools/qemu-diff/src/diff-test.c @@ -68,6 +68,7 @@ void difftest_init(void) { printf("Connect to QEMU successfully\n"); atexit(gdb_exit); + init_isa(); } } diff --git a/tools/qemu-diff/src/gdb-host.c b/tools/qemu-diff/src/gdb-host.c index 7e30617716582a076fd51a3f9ee2f79753ac5821..341ab851ec5455c3b75fee1f1984f5e74b82f5a9 100644 --- a/tools/qemu-diff/src/gdb-host.c +++ b/tools/qemu-diff/src/gdb-host.c @@ -90,7 +90,6 @@ bool gdb_setregs(union isa_gdb_regs *r) { } bool gdb_si(void) { - char buf[] = "vCont;s:1"; gdb_send(conn, (const uint8_t *)buf, strlen(buf)); size_t size;