From 4cc6b82fb0f1d7feaa3f7e7e324d9f3728c47c59 Mon Sep 17 00:00:00 2001 From: Zihao Yu Date: Mon, 14 Jan 2019 01:54:01 +0800 Subject: [PATCH] mips32: pass litenes --- src/arch/mips32/exec/all-instr.h | 3 +++ src/arch/mips32/exec/control.c | 13 +++++++++++++ src/arch/mips32/exec/exec.c | 6 +++--- src/arch/mips32/exec/ldst.c | 11 ----------- src/arch/mips32/exec/muldiv.c | 7 +++++++ src/arch/mips32/include/arch/rtl.h | 5 +++-- src/device/io/mmio.c | 2 +- src/device/keyboard.c | 4 +++- src/device/vga.c | 2 ++ 9 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/arch/mips32/exec/all-instr.h b/src/arch/mips32/exec/all-instr.h index e9e9b1b2..be209386 100644 --- a/src/arch/mips32/exec/all-instr.h +++ b/src/arch/mips32/exec/all-instr.h @@ -27,6 +27,7 @@ make_EHelper(mfhi); make_EHelper(mflo); make_EHelper(mul); make_EHelper(mult); +make_EHelper(multu); make_EHelper(div); make_EHelper(divu); @@ -38,6 +39,8 @@ make_EHelper(bne); make_EHelper(beq); make_EHelper(blez); make_EHelper(bltz); +make_EHelper(bgtz); +make_EHelper(bgez); make_EHelper(inv); make_EHelper(nemu_trap); diff --git a/src/arch/mips32/exec/control.c b/src/arch/mips32/exec/control.c index a14d7b20..3a590255 100644 --- a/src/arch/mips32/exec/control.c +++ b/src/arch/mips32/exec/control.c @@ -52,3 +52,16 @@ make_EHelper(bltz) { print_asm_template3(bltz); } + +make_EHelper(bgtz) { + rtl_jrelop(RELOP_GT, &id_src->val, &id_src2->val, decinfo.jmp_pc); + + print_asm_template3(blez); +} + +make_EHelper(bgez) { + rtl_li(&t0, 0); + rtl_jrelop(RELOP_GE, &id_src->val, &t0, decinfo.jmp_pc); + + print_asm_template3(bltz); +} diff --git a/src/arch/mips32/exec/exec.c b/src/arch/mips32/exec/exec.c index 79d6e5cb..685f302c 100644 --- a/src/arch/mips32/exec/exec.c +++ b/src/arch/mips32/exec/exec.c @@ -5,7 +5,7 @@ static OpcodeEntry special_table [64] = { /* b000 */ IDEX(shift, sll), EMPTY, IDEX(shift, srl), IDEX(shift, sra), IDEX(R, sll), EMPTY, IDEX(R, srl), IDEX(R, sra), /* b001 */ IDEX(R, jr), IDEX(R, jalr), IDEX(cmov, movz), IDEX(cmov, movn), EMPTY, EMPTY, EMPTY, EMPTY, /* b010 */ IDEX(R, mfhi), EMPTY, IDEX(R, mflo), EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, - /* b011 */ IDEX(R, mult), EMPTY, IDEX(R, div), IDEX(R, divu), EMPTY, EMPTY, EMPTY, EMPTY, + /* b011 */ IDEX(R, mult), IDEX(R, multu), IDEX(R, div), IDEX(R, divu), EMPTY, EMPTY, EMPTY, EMPTY, /* b100 */ EMPTY, IDEX(R, add), EMPTY, IDEX(R, sub), IDEX(R, and), IDEX(R, or), IDEX(R, xor), IDEX(R, nor), /* b101 */ EMPTY, EMPTY, IDEX(R, slt), IDEX(R, sltu), EMPTY, EMPTY, EMPTY, EMPTY, /* b110 */ EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, @@ -32,7 +32,7 @@ static make_EHelper(special2) { } static OpcodeEntry regimm_table [32] = { - /* b00 */ IDEX(B, bltz), EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, + /* b00 */ IDEX(B, bltz), IDEX(B, bgez), EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, /* b01 */ EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, /* b10 */ EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, /* b11 */ EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, @@ -43,7 +43,7 @@ static make_EHelper(regimm) { } static OpcodeEntry opcode_table [64] = { - /* b000 */ EX(special), EX(regimm), IDEX(J, j), IDEX(J, jal), IDEX(B, beq), IDEX(B, bne), IDEX(B, blez), EMPTY, + /* b000 */ EX(special), EX(regimm), IDEX(J, j), IDEX(J, jal), IDEX(B, beq), IDEX(B, bne), IDEX(B, blez), IDEX(B, bgtz), /* b001 */ EMPTY, IDEX(I, add), IDEX(I, slt), IDEX(I, sltu), IDEX(IU, and), IDEX(IU, or), IDEX(IU, xor), IDEX(I, lui), /* b010 */ EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, /* b011 */ EMPTY, EMPTY, EMPTY, EMPTY, EX(special2), EMPTY, EMPTY, EMPTY, diff --git a/src/arch/mips32/exec/ldst.c b/src/arch/mips32/exec/ldst.c index a8cd0f9e..a34f14a0 100644 --- a/src/arch/mips32/exec/ldst.c +++ b/src/arch/mips32/exec/ldst.c @@ -53,8 +53,6 @@ make_EHelper(swl) { // write back rtl_sm(&t0, &t1, 4); - Log("addr = 0x%08x, val = 0x%08x", t0, t1); - print_asm_template3(swl); } @@ -85,8 +83,6 @@ make_EHelper(swr) { // write back rtl_sm(&t0, &t1, 4); - Log("addr = 0x%08x, val = 0x%08x", t0, t1); - print_asm_template3(swr); } @@ -118,8 +114,6 @@ make_EHelper(lwl) { // write back rtl_sr(id_dest->reg, &id_dest->val, 4); - Log("val = 0x%08x", id_dest->val); - print_asm_template3(lwl); } @@ -133,7 +127,6 @@ make_EHelper(lwr) { // load the aligned memory word rtl_andi(&t0, &t0, ~0x3u); rtl_lm(&t1, &t0, 4); - Log("addr = 0x%08x, mem = 0x%08x", t0, t1); // prepare memory data rtl_shr(&t1, &t1, &t3); @@ -146,15 +139,11 @@ make_EHelper(lwr) { // prepare register data rtl_and(&id_dest->val, &id_dest->val, &t2); - Log("mem = 0x%08x, reg = 0x%08x", t1, id_dest->val); - // merge the word rtl_or(&id_dest->val, &id_dest->val, &t1); // write back rtl_sr(id_dest->reg, &id_dest->val, 4); - Log("val = 0x%08x", id_dest->val); - print_asm_template3(lwr); } diff --git a/src/arch/mips32/exec/muldiv.c b/src/arch/mips32/exec/muldiv.c index e8dbfcd0..f1f6f76c 100644 --- a/src/arch/mips32/exec/muldiv.c +++ b/src/arch/mips32/exec/muldiv.c @@ -26,6 +26,13 @@ make_EHelper(mult) { print_asm_template3(mult); } +make_EHelper(multu) { + rtl_mul_lo(&cpu.lo, &id_src->val, &id_src2->val); + rtl_mul_hi(&cpu.hi, &id_src->val, &id_src2->val); + + print_asm_template3(multu); +} + make_EHelper(div) { rtl_idiv_q(&cpu.lo, &id_src->val, &id_src2->val); rtl_idiv_r(&cpu.hi, &id_src->val, &id_src2->val); diff --git a/src/arch/mips32/include/arch/rtl.h b/src/arch/mips32/include/arch/rtl.h index dd9777fe..b19ba171 100644 --- a/src/arch/mips32/include/arch/rtl.h +++ b/src/arch/mips32/include/arch/rtl.h @@ -4,11 +4,12 @@ #include "cpu/rtl.h" static inline void rtl_lr(rtlreg_t* dest, int r, int width) { - rtl_mv(dest, ®_l(r)); + if (r != 0) { rtl_mv(dest, ®_l(r)); } + else { rtl_li(dest, 0); } } static inline void rtl_sr(int r, const rtlreg_t *src1, int width) { - rtl_mv(®_l(r), src1); + if (r != 0) { rtl_mv(®_l(r), src1); } } #endif diff --git a/src/device/io/mmio.c b/src/device/io/mmio.c index 6cd9f480..32184b01 100644 --- a/src/device/io/mmio.c +++ b/src/device/io/mmio.c @@ -1,7 +1,7 @@ #include "common.h" #include "device/map.h" -#define NR_MAP 4 +#define NR_MAP 8 static IOMap maps[NR_MAP]; static int nr_map = 0; diff --git a/src/device/keyboard.c b/src/device/keyboard.c index bb89acbb..b1c5ff0e 100644 --- a/src/device/keyboard.c +++ b/src/device/keyboard.c @@ -3,6 +3,7 @@ #include #define I8042_DATA_PORT 0x60 +#define I8042_DATA_MMIO 0x4060 #define KEYBOARD_IRQ 1 static uint32_t *i8042_data_port_base; @@ -59,6 +60,7 @@ static void i8042_data_io_handler(uint32_t offset, int len, bool is_write) { void init_i8042() { i8042_data_port_base = (void *)new_space(4); - add_pio_map(I8042_DATA_PORT, (void *)i8042_data_port_base, 4, i8042_data_io_handler); i8042_data_port_base[0] = _KEY_NONE; + add_pio_map(I8042_DATA_PORT, (void *)i8042_data_port_base, 4, i8042_data_io_handler); + add_mmio_map(I8042_DATA_MMIO, (void *)i8042_data_port_base, 4, i8042_data_io_handler); } diff --git a/src/device/vga.c b/src/device/vga.c index 3e96f1ed..991f1a46 100644 --- a/src/device/vga.c +++ b/src/device/vga.c @@ -8,6 +8,7 @@ #define VMEM 0x40000 #define SCREEN_PORT 0x100 // Note that this is not the standard +#define SCREEN_MMIO 0x4100 #define SCREEN_H 300 #define SCREEN_W 400 @@ -35,6 +36,7 @@ void init_vga() { screensize_port_base = (void *)new_space(4); *screensize_port_base = ((SCREEN_W) << 16) | (SCREEN_H); add_pio_map(SCREEN_PORT, (void *)screensize_port_base, 4, NULL); + add_mmio_map(SCREEN_MMIO, (void *)screensize_port_base, 4, NULL); vmem = (void *)new_space(0x80000); add_mmio_map(VMEM, (void *)vmem, 0x80000, NULL); -- GitLab