riscv / sail-riscv

Sail RISC-V model
https://lists.riscv.org/g/tech-golden-model
Other
463 stars 168 forks source link

Simplify getPendingSet() interrupt handling #616

Open Timmmm opened 1 week ago

Timmmm commented 1 week ago

As noted by @KotorinMinami the getPendingSet() function can be simplified quite a lot now that N is gone:

function getPendingSet(priv : Privilege) -> option((xlenbits, Privilege)) = {
  assert(extensionEnabled(Ext_S) | mideleg == zeros());

  let pending_m = mip.bits & mie.bits & ~(mideleg);
  let pending_s = mip.bits & mie.bits & mideleg;

  let mIE = (priv == Machine & mstatus[MIE] == 0b1) | priv == User | priv == Supervisor;
  let sIE = (priv == Supervisor & mstatus[SIE] == 0b1)) | priv == User;

  if     mIE & (pending_m != zeros()) then Some((pending_m, Machine))
  else if sIE & (pending_s != zeros()) then Some((pending_s, Supervisor))
  else None()
}

(not tested!)