Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify PMP code #738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions model/riscv_pmp_control.sail
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the other options would be

  1. pass priv to pmpcheckRWX() and add if priv == Machine & not(pmpLocked(ent)) then true else match ...?
  2. change pmpCheckPerms to an if instead of a match().

But 2) seems unnecessary since there is only one caller of pmpCheckPerms() so we might as inline it. LGTM.

then PMP_Success
else PMP_Fail
}
Expand Down
Loading