Skip to content

Commit

Permalink
Split check_CSR_access up
Browse files Browse the repository at this point in the history
Split the privilege level checking and read-only checking into separate functions. This is slightly neater and also helps CHERI where ASR permissions need to use `check_CSR_priv()`.
  • Loading branch information
Timmmm authored Jan 14, 2025
1 parent 8458a88 commit 5672835
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions model/riscv_sys_control.sail
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
function csrAccess(csr : csreg) -> csrRW = csr[11..10]
function csrPriv(csr : csreg) -> priv_level = csr[9..8]

val check_CSR_access : (csrRW, priv_level, Privilege, bool) -> bool
function check_CSR_access(csrrw, csrpr, p, isWrite) =
not(isWrite == true & csrrw == 0b11) /* read/write */
& (privLevel_to_bits(p) >=_u csrpr) /* privilege */
// Check that the CSR access is made with sufficient privilege.
function check_CSR_priv(csr : csreg, p : Privilege) -> bool =
privLevel_to_bits(p) >=_u csrPriv(csr)

// Check that the CSR access isn't a write and read-only.
function check_CSR_access(csr : csreg, isWrite : bool) -> bool =
not(isWrite & (csrAccess(csr) == 0b11))

function check_TVM_SATP(csr : csreg, p : Privilege) -> bool =
not(csr == 0x180 & p == Supervisor & mstatus[TVM] == 0b1)
Expand Down Expand Up @@ -67,7 +70,8 @@ function check_seed_CSR (csr : csreg, p : Privilege, isWrite : bool) -> bool = {

function check_CSR(csr : csreg, p : Privilege, isWrite : bool) -> bool =
is_CSR_defined(csr)
& check_CSR_access(csrAccess(csr), csrPriv(csr), p, isWrite)
& check_CSR_priv(csr, p)
& check_CSR_access(csr, isWrite)
// TODO: If we add `p` back to is_CSR_defined() we could move these three
// check_ functions back there. We should also rename is_CSR_defined()
// to is_CSR_accessible() or similar.
Expand Down

0 comments on commit 5672835

Please sign in to comment.