From f7d281900a3f0dc2ad4cbc06b4df17cc6db1b5f8 Mon Sep 17 00:00:00 2001 From: tracer-ics2018 <tracer@njuics.org> Date: Sat, 14 Dec 2019 00:41:29 +0800 Subject: [PATCH] > Manual commit: Fixed reg.h bug. U201614531 recolic Linux RECOLICPC 5.4.2-arch1-1 #1 SMP PREEMPT Thu, 05 Dec 2019 12:29:40 +0000 x86_64 GNU/Linux 00:41:29 up 2 days, 7:59, 1 user, load average: 3.60, 4.50, 3.61 496b55efe62eef0d86968bc914082bf4134d2102 --- nemu/include/cpu/reg.h | 14 ++++++++------ nemu/src/cpu/reg.c | 8 ++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/nemu/include/cpu/reg.h b/nemu/include/cpu/reg.h index 469a8d5..bcfa3f9 100644 --- a/nemu/include/cpu/reg.h +++ b/nemu/include/cpu/reg.h @@ -14,21 +14,22 @@ enum { R_AL, R_CL, R_DL, R_BL, R_AH, R_CH, R_DH, R_BH }; * For more details about the register encoding scheme, see i386 manual. */ -typedef struct { - struct { +typedef union { + union { uint32_t _32; uint16_t _16; uint8_t _8[2]; - } gpr[8]; + } gpr[9]; /* Do NOT change the order of the GPRs' definitions. */ /* In NEMU, rtlreg_t is exactly uint32_t. This makes RTL instructions * in PA2 able to directly access these registers. */ - rtlreg_t eax, ecx, edx, ebx, esp, ebp, esi, edi; - - vaddr_t eip; + struct { + rtlreg_t eax, ecx, edx, ebx, esp, ebp, esi, edi; + vaddr_t eip; + }; } CPU_state; @@ -57,4 +58,5 @@ static inline const char* reg_name(int index, int width) { } } + #endif diff --git a/nemu/src/cpu/reg.c b/nemu/src/cpu/reg.c index 2f85402..2eba473 100644 --- a/nemu/src/cpu/reg.c +++ b/nemu/src/cpu/reg.c @@ -8,7 +8,15 @@ const char *regsl[] = {"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"}; const char *regsw[] = {"ax", "cx", "dx", "bx", "sp", "bp", "si", "di"}; const char *regsb[] = {"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh"}; +inline void rcpu_bootstrap_check_1() { + assert(sizeof(rtlreg_t) == sizeof(uint32_t)); + assert(sizeof(vaddr_t) == sizeof(uint32_t)); + printf("Recolic bootstrap test %s passed.\n", __FILE__); +} + void reg_test() { + rcpu_bootstrap_check_1(); + srand(time(0)); uint32_t sample[8]; uint32_t eip_sample = rand(); -- GitLab