summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rvcontroller.lua57
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