From 9ac49984784ab784f109fd5564f56d2063753e40 Mon Sep 17 00:00:00 2001 From: Dolu1990 Date: Thu, 28 Mar 2019 00:38:38 +0100 Subject: [PATCH] Fix emulator nested exception redirection privilege --- src/main/c/emulator/build/emulator.asm | 8 ++++---- src/main/c/emulator/build/emulator.hex | 6 +++--- src/main/c/emulator/src/main.c | 2 +- src/test/cpp/regression/main.cpp | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/c/emulator/build/emulator.asm b/src/main/c/emulator/build/emulator.asm index e2dcdda..cb720c3 100644 --- a/src/main/c/emulator/build/emulator.asm +++ b/src/main/c/emulator/build/emulator.asm @@ -181,8 +181,8 @@ Disassembly of section .text: 8000026c: 000027b7 lui a5,0x2 80000270: 80078793 addi a5,a5,-2048 # 1800 <__stack_size+0x1000> 80000274: 3007b073 csrc mstatus,a5 -80000278: 000087b7 lui a5,0x8 -8000027c: 08078793 addi a5,a5,128 # 8080 <__stack_size+0x7880> +80000278: 000017b7 lui a5,0x1 +8000027c: 88078793 addi a5,a5,-1920 # 880 <__stack_size+0x80> 80000280: 3007a073 csrs mstatus,a5 80000284: 00008067 ret @@ -396,8 +396,8 @@ Disassembly of section .text: 800005b0: 000027b7 lui a5,0x2 800005b4: 80078793 addi a5,a5,-2048 # 1800 <__stack_size+0x1000> 800005b8: 3007b073 csrc mstatus,a5 -800005bc: 000087b7 lui a5,0x8 -800005c0: 08078793 addi a5,a5,128 # 8080 <__stack_size+0x7880> +800005bc: 000017b7 lui a5,0x1 +800005c0: 88078793 addi a5,a5,-1920 # 880 <__stack_size+0x80> 800005c4: 3007a073 csrs mstatus,a5 800005c8: e81ff06f j 80000448 800005cc: 00f45993 srli s3,s0,0xf diff --git a/src/main/c/emulator/build/emulator.hex b/src/main/c/emulator/build/emulator.hex index 99d25ea..1892272 100644 --- a/src/main/c/emulator/build/emulator.hex +++ b/src/main/c/emulator/build/emulator.hex @@ -38,8 +38,8 @@ :10023C00F327303473903714F3272034739027143A :10024C0073101514F3275010739017349307001084 :10025C0073B0071093D5350093F5051073A00510F6 -:10026C00B72700009387078073B00730B78700006B -:10027C009387070873A007306780000037070200D8 +:10026C00B72700009387078073B00730B7170000DB +:10027C009387078873A00730678000003707020058 :10028C0073200730170700001307870173105730CE :10029C009306100083270500930600003707020021 :1002AC00733007301385060023A0F500678000002B @@ -91,7 +91,7 @@ :10058C007390271473901414F3275010739017342E :10059C009307001073B0071093D5350093F5051031 :1005AC0073A00510B72700009387078073B007303E -:1005BC00B78700009387070873A007306FF01FE818 +:1005BC00B71700009387078873A007306FF01FE808 :1005CC009359F40093F9F901B33930016FF01FDE40 :1005DC0033060601135454001374C407B306D40035 :1005EC0023A00601B707020073A00730970700008D diff --git a/src/main/c/emulator/src/main.c b/src/main/c/emulator/src/main.c index 1147c4b..1181786 100755 --- a/src/main/c/emulator/src/main.c +++ b/src/main/c/emulator/src/main.c @@ -47,7 +47,7 @@ void emulationTrapToSupervisorTrap(uint32_t sepc, uint32_t mstatus){ csr_clear(sstatus, MSTATUS_SPP); csr_set(sstatus, (mstatus >> 3) & MSTATUS_SPP); csr_clear(mstatus, MSTATUS_MPP); - csr_set(mstatus, 0x8000 | MSTATUS_MPIE); + csr_set(mstatus, 0x0800 | MSTATUS_MPIE); } #define max(a,b) \ diff --git a/src/test/cpp/regression/main.cpp b/src/test/cpp/regression/main.cpp index d25ff39..5355333 100644 --- a/src/test/cpp/regression/main.cpp +++ b/src/test/cpp/regression/main.cpp @@ -561,7 +561,8 @@ public: return value; } -#define maskedWrite(dst, src, mask) dst=(dst & ~mask)|(src & mask); + #define maskedWrite(dst, src, mask) dst=(dst & ~mask)|(src & mask); + virtual bool csrWrite(int32_t csr, uint32_t value){ if(((csr >> 8) & 0x3) > privilege) return true; switch(csr){