From d29584ca1361f7268511fda2404f15991ca9c5c9 Mon Sep 17 00:00:00 2001 From: cheapie Date: Sun, 8 Nov 2026 08:12:18 -0600 Subject: Mask mnepc as needed on reads --- rvcontroller.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rvcontroller.lua b/rvcontroller.lua index bf9877f..801178c 100644 --- a/rvcontroller.lua +++ b/rvcontroller.lua @@ -413,6 +413,15 @@ local function readcsr(address) ret = ret - 2 end return ret + elseif address == 0x741 then --mnepc + local ret = mem.csr[0x741] + --mnepc[0] must be 0 + if ret%2 == 1 then ret = ret-1 end + --mnepc[1] must be 0 if IALIGN=32 + if not mem.isa.c and ret%4 >= 2 then + ret = ret - 2 + end + return ret elseif address == 0x300 then --mstatus local bits = {} bits[3] = mem.mie -- cgit v1.2.3