diff options
Diffstat (limited to 'rvcontroller.lua')
| -rw-r--r-- | rvcontroller.lua | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/rvcontroller.lua b/rvcontroller.lua index 29dd903..8033a01 100644 --- a/rvcontroller.lua +++ b/rvcontroller.lua @@ -13,6 +13,8 @@ local CLOCK_SPEED = 20 --Clock speed in Hz when not in lightweight mode local INSTRUCTIONS_PER_CLOCK = 50 --Maximum number of instructions that will be run on each clock cycle local STDOUT_TO_TERMINAL = false --Whether to show standard output on the Luacontroller terminal in addition to the screen +local seed = math.random(0,0xffff) + 0x80000000 + local traptypes = { --Not all of these are implemented, some are impossible on RVController [0x0] = "Inst addr misaligned", @@ -398,7 +400,11 @@ local function stdout(text) end local function readcsr(address) - if address == 0x341 then --mepc + if address == 0x015 then --seed + local out = seed + seed = 0x40000000 + return out + elseif address == 0x341 then --mepc local ret = mem.csr[0x341] --mepc[0] must be 0 if ret%2 == 1 then ret = ret-1 end @@ -570,7 +576,10 @@ local function readcsr(address) end local function writecsr(address,data) - if address == 0x17 then + if address == 0x15 then + --seed + return + elseif address == 0x17 then --jvt data = math.floor(data/2^6)*2^6 --WARL, and mode is required to be 0 elseif address == 0xc00 or address == 0xc01 or address == 0xc02 or address == 0xc80 or address == 0xc81 or address == 0xc82 then @@ -1181,6 +1190,10 @@ local operations = { csrrs = function(rd,rs1,imm) local out = readcsr(imm) if rs1 == 0 then + if imm == 0x015 then + --Read-only access to seed + return trap(2) + end setreg(rd,out) return end @@ -1196,6 +1209,10 @@ local operations = { csrrc = function(rd,rs1,imm) local out = readcsr(imm) if rs1 == 0 then + if imm == 0x015 then + --Read-only access to seed + return trap(2) + end setreg(rd,out) return end @@ -1220,6 +1237,10 @@ local operations = { return checkinterrupts() end, csrrsi = function(rd,rs1,imm) + if getreg(rs1) == 0 and imm == 0x015 then + --Read-only access to seed + return trap(2) + end setreg(rd,readcsr(imm)) if rs1 == 0 then return end local csrbits = explodebits(readcsr(imm),32) @@ -1231,6 +1252,10 @@ local operations = { return checkinterrupts() end, csrrci = function(rd,rs1,imm) + if getreg(rs1) == 0 and imm == 0x015 then + --Read-only access to seed + return trap(2) + end setreg(rd,readcsr(imm)) if rs1 == 0 then return end local csrbits = explodebits(readcsr(imm),32) @@ -2993,6 +3018,7 @@ local regaliases = { } local csraliases = { + seed = 0x015, cycle = 0xc00, time = 0xc01, instret = 0xc02, |
