summaryrefslogtreecommitdiff
path: root/rvcontroller.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rvcontroller.lua')
-rw-r--r--rvcontroller.lua24
1 files changed, 22 insertions, 2 deletions
diff --git a/rvcontroller.lua b/rvcontroller.lua
index 6a54c3c..c4e27d6 100644
--- a/rvcontroller.lua
+++ b/rvcontroller.lua
@@ -445,6 +445,12 @@ local function readcsr(address)
elseif address == 0xb00 or address == 0xb02 or address == 0xb80 or address == 0xb82 then --mcycle(h)/minstret(h)
--Transform into cycle(h)/instret(h)
address = address + 0x100
+ elseif address == 0x321 or address == 0x322 then --mcyclecfg/minstretcfg
+ return 0
+ elseif address == 0x721 then --mcyclecfgh
+ return mem.cycleminh and 0x40000000 or 0
+ elseif address == 0x722 then --minstretcfgh
+ return mem.instretminh and 0x40000000 or 0
elseif address == 0x747 then --mseccfg
local bits = {}
bits[10] = mem.mlpe
@@ -626,6 +632,14 @@ local function writecsr(address,data)
elseif address >= 0xb83 and address <= 0xb86 then --mhpmcounter3h-mhpmcounter6h
--Transform into hpmcounter3h-hpmcounter6h (but allow the write)
address = address + 0x100
+ elseif address == 0x321 or address == 0x322 then --mcyclecfg/minstretcfg
+ return
+ elseif address == 0x721 then --mcyclecfgh
+ mem.cycleminh = explodebits(data,32)[30]
+ return
+ elseif address == 0x722 then --minstretcfgh
+ mem.instretminh = explodebits(data,32)[30]
+ return
elseif address == 0xb00 or address == 0xb02 or address == 0xb80 or address == 0xb82 then --mcycle(h)/minstret(h)
--Transform into cycle(h)/instret(h) (but allow the write)
address = address + 0x100
@@ -3151,7 +3165,7 @@ end
local function run(limit)
--0xc00 = CYCLE
--0xc80 = CYCLEH
- if not mem.mcountinhibit[0] then
+ if not (mem.mcountinhibit[0] or mem.cycleminh) then
mem.csr[0xc00] = mem.csr[0xc00] + 1
if mem.csr[0xc00] >= 2^32 then
mem.csr[0xc80] = mem.csr[0xc80] + math.floor(mem.csr[0xc00]/2^32)
@@ -3209,7 +3223,7 @@ local function run(limit)
--0xc02 = INSTRET
--0xc82 = INSTRETH
- if not mem.mcountinhibit[2] then
+ 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)
@@ -3387,6 +3401,10 @@ local csraliases = {
mhpmevent31 = 0x33f,
mcountinhibit = 0x320,
mconfigptr = 0xf15,
+ mcyclecfg = 0x321,
+ minstretcfg = 0x322,
+ mcyclecfgh = 0x721,
+ minstretcfgh = 0x722,
}
if event.type == "program" or event.iid == "reset" then
@@ -3477,6 +3495,8 @@ if event.type == "program" or event.iid == "reset" then
mem.elp = false
mem.mpelp = false
mem.mcountinhibit = {}
+ mem.cycleminh = false
+ mem.instretminh = false
elseif event.type == "on" or event.type == "off" then
local pname = string.lower(event.pin.name)
local pstate = pin[pname]