diff options
author | Ved Shanbhogue <91900059+ved-rivos@users.noreply.github.com> | 2024-06-18 15:07:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 21:07:28 +0100 |
commit | 157d4d14d0cf7016efc0023d499c6fdc1c22deaa (patch) | |
tree | 275d6050286e269fcae1f9e03b28790971c273d1 | |
parent | 0e9850fed5bee44346e583f334c6e2a6a25d5cd3 (diff) | |
download | sail-riscv-157d4d14d0cf7016efc0023d499c6fdc1c22deaa.zip sail-riscv-157d4d14d0cf7016efc0023d499c6fdc1c22deaa.tar.gz sail-riscv-157d4d14d0cf7016efc0023d499c6fdc1c22deaa.tar.bz2 |
Add missing mstatus.MPP legalization
`mstatus.MPP` legal values are User (`0b00`) (if U-mode implemented), Supervisor (`0b01`) (if S-mode implemented) and Machine (`0b11`). Encoding `0b10` is illegal.
-rw-r--r-- | model/riscv_sys_control.sail | 1 | ||||
-rw-r--r-- | model/riscv_sys_regs.sail | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/model/riscv_sys_control.sail b/model/riscv_sys_control.sail index 1baa337..95ed4d6 100644 --- a/model/riscv_sys_control.sail +++ b/model/riscv_sys_control.sail @@ -501,6 +501,7 @@ function init_sys() -> unit = { mstatus = set_mstatus_SXL(mstatus, misa[MXL]); mstatus = set_mstatus_UXL(mstatus, misa[MXL]); mstatus[SD] = 0b0; + mstatus[MPP] = privLevel_to_bits(lowest_supported_privLevel()); /* set to little-endian mode */ if sizeof(xlen) == 64 then { diff --git a/model/riscv_sys_regs.sail b/model/riscv_sys_regs.sail index 3537abc..65d1419 100644 --- a/model/riscv_sys_regs.sail +++ b/model/riscv_sys_regs.sail @@ -168,6 +168,21 @@ function haveZalrsc() -> bool = haveAtomics() /* Zicond extension support */ function haveZicond() -> bool = true +/* + * Illegal values legalized to least privileged mode supported. + * Note: the only valid combinations of supported modes are M, M+U, M+S+U. + */ +function lowest_supported_privLevel() -> Privilege = + if haveUsrMode() then User else Machine + +function have_privLevel(priv : priv_level) -> bool = + match priv { + 0b00 => haveUsrMode(), + 0b01 => haveSupMode(), + 0b10 => false, + 0b11 => true, + } + bitfield Mstatush : bits(32) = { MBE : 5, SBE : 4 @@ -255,6 +270,10 @@ function legalize_mstatus(o : Mstatus, v : xlenbits) -> Mstatus = { */ let m : Mstatus = Mk_Mstatus(zero_extend(v[22 .. 7] @ 0b0 @ v[5 .. 3] @ 0b0 @ v[1 .. 0])); + /* Legalize MPP */ + let m = [m with MPP = if have_privLevel(m[MPP]) then m[MPP] + else privLevel_to_bits(lowest_supported_privLevel())]; + /* We don't have any extension context yet. */ let m = [m with XS = extStatus_to_bits(Off)]; |