提交 495c2d73 编写于 作者: P Parallels

Add "ISA64" micro to control the system, support all ISAs to pass the tests

上级 7a4a23cd
......@@ -21,10 +21,17 @@
typedef uint8_t bool;
#ifdef ISA64
typedef uint64_t rtlreg_t;
typedef uint32_t paddr_t;
typedef uint64_t vaddr_t;
#else
typedef uint32_t rtlreg_t;
typedef uint32_t paddr_t;
typedef uint32_t vaddr_t;
#endif
typedef uint16_t ioaddr_t;
......
......@@ -12,12 +12,21 @@ enum { OP_TYPE_REG, OP_TYPE_MEM, OP_TYPE_IMM };
typedef struct {
uint32_t type;
int width;
#ifdef ISA64
union {
uint64_t reg;
rtlreg_t addr;
uint64_t imm;
int64_t simm;
};
#else
union {
uint32_t reg;
rtlreg_t addr;
uint32_t imm;
int32_t simm;
};
#endif
rtlreg_t val;
char str[OP_STR_SIZE];
} Operand;
......
......@@ -17,18 +17,24 @@ void register_pmem(paddr_t base);
uint32_t isa_vaddr_read(vaddr_t, int);
void isa_vaddr_write(vaddr_t, uint32_t, int);
#ifdef ISA64
uint64_t isa_vaddr_read64(vaddr_t, int);
void isa_vaddr_write64(vaddr_t, uint64_t, int);
#endif
#define vaddr_read isa_vaddr_read
#define vaddr_write isa_vaddr_write
#ifdef ISA64
#define vaddr_read64 isa_vaddr_read64
#define vaddr_write64 isa_vaddr_write64
#endif
uint32_t paddr_read(paddr_t, int);
void paddr_write(paddr_t, uint32_t, int);
#ifdef ISA64
uint64_t paddr_read64(paddr_t, int);
void paddr_write64(paddr_t, uint64_t, int);
#endif
#define PAGE_SIZE 4096
#define PAGE_MASK (PAGE_SIZE - 1)
......
......@@ -21,8 +21,13 @@ 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",
name, pc, ref, dut);
#else
Log("%s is different after executing instruction at pc = 0x%08x, right = 0x%08x, wrong = 0x%08x",
name, pc, ref, dut);
#endif
return false;
}
return true;
......
......@@ -39,21 +39,24 @@ make_rtl_arith_logic(or)
make_rtl_arith_logic(xor)
make_rtl_arith_logic(shl)
make_rtl_arith_logic(shr)
make_rtl_arith_logic(shr64)
make_rtl_arith_logic(sar)
make_rtl_arith_logic(sar64)
make_rtl_arith_logic(mul_lo)
make_rtl_arith_logic(mul_hi)
make_rtl_arith_logic(imul_lo)
make_rtl_arith_logic(imul_hi)
make_rtl_arith_logic(div_q)
make_rtl_arith_logic(div_q64)
make_rtl_arith_logic(div_r)
make_rtl_arith_logic(div_r64)
make_rtl_arith_logic(idiv_q)
make_rtl_arith_logic(idiv_q64)
make_rtl_arith_logic(idiv_r)
#ifdef ISA64
make_rtl_arith_logic(shr64)
make_rtl_arith_logic(sar64)
make_rtl_arith_logic(div_q64)
make_rtl_arith_logic(div_r64)
make_rtl_arith_logic(idiv_q64)
make_rtl_arith_logic(idiv_r64)
#endif
static inline void interpret_rtl_div64_q(rtlreg_t* dest,
const rtlreg_t* src1_hi, const rtlreg_t* src1_lo, const rtlreg_t* src2) {
......@@ -84,16 +87,20 @@ static inline void interpret_rtl_idiv64_r(rtlreg_t* dest,
}
static inline void interpret_rtl_lm(rtlreg_t *dest, const rtlreg_t* addr, int len) {
#ifdef ISA64
if (len == 8)
*dest = vaddr_read64(*addr, len);
else
#endif
*dest = vaddr_read(*addr, len);
}
static inline void interpret_rtl_sm(const rtlreg_t* addr, const rtlreg_t* src1, int len) {
#ifdef ISA64
if (len == 8)
vaddr_write64(*addr, *src1, len);
else
#endif
vaddr_write(*addr, *src1, len);
}
......
......@@ -2,10 +2,18 @@
void display_inv_msg(vaddr_t pc) {
extern char isa_logo[];
#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"
"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);
#else
printf("There are two cases which will trigger this unexpected exception:\n"
"1. The instruction at PC = 0x%08x is not implemented.\n"
"2. Something is implemented incorrectly.\n", pc);
printf("Find this PC(0x%08x) in the disassembling result to distinguish which case it is.\n\n", pc);
#endif
printf("\33[1;31mIf it is the first case, see\n%s\nfor more details.\n\nIf it is the second case, remember:\n"
"* The machine is always right!\n"
"* Every line of untested code is always wrong!\33[0m\n\n", isa_logo);
......
......@@ -17,9 +17,15 @@ 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",
addr, (map ? map->name : "???"), (map ? map->low : 0), (map ? map->high : 0), cpu.pc);
#else
Assert(map != NULL && addr <= map->high && addr >= map->low,
"address (0x%08x) is out of bound {%s} [0x%08x, 0x%08x] at pc = 0x%08x",
addr, (map ? map->name : "???"), (map ? map->low : 0), (map ? map->high : 0), cpu.pc);
#endif
}
static inline void invoke_callback(io_callback_t c, uint32_t offset, int len, bool is_write) {
......
......@@ -61,7 +61,11 @@ void cpu_exec(uint64_t n) {
/* TODO: check watchpoints here. */
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);
#else
printf("\n\nHint watchpoint %d at address 0x%08x, expr = %s\n", wp->NO, ori_pc, wp->expr);
#endif
printf("old value = %#08x\nnew value = %#08x\n", wp->old_val, wp->new_val);
wp->old_val = wp->new_val;
return;
......@@ -83,10 +87,17 @@ void cpu_exec(uint64_t n) {
case NEMU_RUNNING: nemu_state.state = NEMU_STOP; break;
case NEMU_END: case NEMU_ABORT:
#ifdef ISA64
_Log("nemu: %s\33[0m at pc = 0x%16lx\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);
#else
_Log("nemu: %s\33[0m at pc = 0x%08x\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);
#endif
monitor_statistic();
}
}
......@@ -22,8 +22,13 @@ 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,
50 - (12 + 3 * instr_len), "", log_asmbuf);
#else
snprintf(tempbuf, sizeof(tempbuf), "%08x: %s%*.s%s", ori_pc, log_bytebuf,
50 - (12 + 3 * instr_len), "", log_asmbuf);
#endif
log_write("%s\n", tempbuf);
if (print_flag) {
puts(tempbuf);
......
......@@ -88,8 +88,13 @@ static int cmd_d(char *args) {
static int cmd_p(char *args) {
if (args != NULL) {
bool success;
#ifdef ISA64
uint64_t r = expr(args, &success);
if(success) { printf("0x%lx\n", r); }
#else
uint32_t r = expr(args, &success);
if(success) { printf("0x%x\n", r); }
#endif
else { printf("Bad expression\n"); }
}
return 0;
......@@ -122,7 +127,11 @@ static int cmd_x(char *args) {
if (success) {
for (i = 0; i < n; i ++) {
if (i % 4 == 0) {
#ifdef ISA64
printf("0x%16lx: ", addr);
#else
printf("0x%08x: ", addr);
#endif
}
printf("0x%08x ", vaddr_read(addr, 4));
......
......@@ -95,7 +95,11 @@ void difftest_step(vaddr_t ori_pc, vaddr_t next_pc) {
}
skip_dut_nr_instr --;
if (skip_dut_nr_instr == 0)
#ifdef ISA64
panic("can not catch up with ref.pc = %lx at pc = %lx", ref_r.pc, ori_pc);
#else
panic("can not catch up with ref.pc = %x at pc = %x", ref_r.pc, ori_pc);
#endif
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册