diff options
| author | cheapie <cheapiephp@gmail.com> | 2026-11-08 10:51:32 -0600 |
|---|---|---|
| committer | cheapie <cheapiephp@gmail.com> | 2026-11-08 10:51:32 -0600 |
| commit | 6606efb7a449f2ff2bc5dd49b20b12d9138861e9 (patch) | |
| tree | 43817f40d6a05a32e4fda47f793944a8bafa2cbf /rvcontroller.lua | |
| parent | 71c0c2ed2d9af9aff2b334f02e105904a90453a6 (diff) | |
| download | rvcontroller-6606efb7a449f2ff2bc5dd49b20b12d9138861e9.tar rvcontroller-6606efb7a449f2ff2bc5dd49b20b12d9138861e9.tar.gz rvcontroller-6606efb7a449f2ff2bc5dd49b20b12d9138861e9.tar.bz2 rvcontroller-6606efb7a449f2ff2bc5dd49b20b12d9138861e9.tar.xz rvcontroller-6606efb7a449f2ff2bc5dd49b20b12d9138861e9.zip | |
Smrnmi improvements
Diffstat (limited to 'rvcontroller.lua')
| -rw-r--r-- | rvcontroller.lua | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/rvcontroller.lua b/rvcontroller.lua index 801178c..73de551 100644 --- a/rvcontroller.lua +++ b/rvcontroller.lua @@ -3240,6 +3240,7 @@ local function run(limit) end first = false local instruction = readram(mem.registers.pc,4,true) + local lptrap = false if mem.elp and mem.mlpe then if instruction%2^12 == 0x017 and mem.registers.pc%4 == 0 @@ -3247,37 +3248,41 @@ local function run(limit) or math.floor(instruction/2^12) == 0) then mem.elp = false else - trap(18,2) + local _,stop = trap(18,2) + lptrap = true + if stop then break end end end - mem.elp = mem.mlpe and checklpe(instruction) - if instruction%4 == 3 or not mem.isa.c then - if mem.registers.pc%4 ~= 0 and not mem.isa.c then - local _,stop = trap(0) + if not lptrap then + mem.elp = mem.mlpe and checklpe(instruction) + if instruction%4 == 3 or not mem.isa.c then + if mem.registers.pc%4 ~= 0 and not mem.isa.c then + local _,stop = trap(0) + if stop then break end + end + local jumped,stop = runinst(instruction) + if fault then + jumped,stop = trap(fault,fval) + end + if not jumped then mem.registers.pc = (mem.registers.pc + 4) % 2^32 end + if stop then break end + else + local jumped,stop = runcinst(instruction%2^16) + if fault then + jumped,stop = trap(fault,fval) + end + if not jumped then mem.registers.pc = (mem.registers.pc + 2) % 2^32 end if stop then break end end - local jumped,stop = runinst(instruction) - if fault then - jumped,stop = trap(fault,fval) - end - if not jumped then mem.registers.pc = (mem.registers.pc + 4) % 2^32 end - if stop then break end - else - local jumped,stop = runcinst(instruction%2^16) - if fault then - jumped,stop = trap(fault,fval) - end - if not jumped then mem.registers.pc = (mem.registers.pc + 2) % 2^32 end - if stop then break end - end - --0xc02 = INSTRET - --0xc82 = INSTRETH - if not (mem.mcountinhibit[2] or mem.instretminh) then - mem.csr[0xc02] = mem.csr[0xc02] + 1 - if mem.csr[0xc02] >= 2^32 then - mem.csr[0xc82] = mem.csr[0xc82] + math.floor(mem.csr[0xc02]/2^32) - mem.csr[0xc02] = mem.csr[0xc02]%2^32 + --0xc02 = INSTRET + --0xc82 = INSTRETH + if not (mem.mcountinhibit[2] or mem.instretminh) then + mem.csr[0xc02] = mem.csr[0xc02] + 1 + if mem.csr[0xc02] >= 2^32 then + mem.csr[0xc82] = mem.csr[0xc82] + math.floor(mem.csr[0xc02]/2^32) + mem.csr[0xc02] = mem.csr[0xc02]%2^32 + end end end limit = limit - 1 |
