From 36c42dfccf502160fb3df656c8639b123137e304 Mon Sep 17 00:00:00 2001 From: Tim Hutt Date: Fri, 14 Feb 2025 13:05:00 +0000 Subject: [PATCH] Simplify PMP code Inline `pmpCheckPerms` and use `== Machine` instead of `match`. I think this is a lot easier to understand, and shorter. --- model/riscv_pmp_control.sail | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/model/riscv_pmp_control.sail b/model/riscv_pmp_control.sail index 59ed270ec..62cd060c0 100644 --- a/model/riscv_pmp_control.sail +++ b/model/riscv_pmp_control.sail @@ -39,25 +39,14 @@ function pmpAddrRange(cfg: Pmpcfg_ent, pmpaddr: xlenbits, prev_pmpaddr: xlenbits /* permission checks */ val pmpCheckRWX: (Pmpcfg_ent, AccessType(ext_access_type)) -> bool -function pmpCheckRWX(ent, acc) = { +function pmpCheckRWX(ent, acc) = match acc { Read(_) => ent[R] == 0b1, Write(_) => ent[W] == 0b1, ReadWrite(_) => ent[R] == 0b1 & ent[W] == 0b1, - Execute() => ent[X] == 0b1 + Execute() => ent[X] == 0b1, } -} -// this needs to be called with the effective current privilege. -val pmpCheckPerms: (Pmpcfg_ent, AccessType(ext_access_type), Privilege) -> bool -function pmpCheckPerms(ent, acc, priv) = { - match priv { - Machine => if pmpLocked(ent) - then pmpCheckRWX(ent, acc) - else true, - _ => pmpCheckRWX(ent, acc) - } -} /* matching logic */ @@ -95,7 +84,7 @@ function pmpMatchEntry(addr: physaddr, width: xlenbits, acc: AccessType(ext_acce match pmpMatchAddr(addr, width, rng) { PMP_NoMatch => PMP_Continue, PMP_PartialMatch => PMP_Fail, - PMP_Match => if pmpCheckPerms(ent, acc, priv) + PMP_Match => if pmpCheckRWX(ent, acc) | (priv == Machine & not(pmpLocked(ent))) then PMP_Success else PMP_Fail }