Skip to content

Commit

Permalink
CSR: fix the wmask of mstatus
Browse files Browse the repository at this point in the history
  • Loading branch information
poemonsense committed May 13, 2024
1 parent e3e5807 commit 1b80938
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Binary file modified ready-to-run/riscv64-nemu-interpreter-so
Binary file not shown.
19 changes: 17 additions & 2 deletions src/main/scala/nutcore/backend/fu/CSR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{
// | spp | 0 |
// | pie | 0000 |
// | ie | 0000 | uie hardlinked to 0, as N ext is not implemented
private def GenMask(i: Int): UInt = GenMask(i, i)
private def GenMask(i: Int, j: Int): UInt = ZeroExt(Fill(i - j + 1, true.B) << j, 64)
val mstatusWMask = (~ZeroExt((
GenMask(63) | // SD is read-only
GenMask(62, 38) | // WPRI
GenMask(37) | // MBE is read-only
GenMask(36) | // SBE is read-only
GenMask(35, 32) | // SXL and UXL cannot be changed
GenMask(31, 23) | // WPRI
GenMask(16, 15) | // XS is read-only
GenMask(14, 13) | // FS is read-only
GenMask(6) | // UBE, always little-endian (0)
GenMask(4) | // WPRI
GenMask(2) | // WPRI
GenMask(0) // WPRI
), 64)).asUInt
val mstatusStruct = mstatus.asTypeOf(new MstatusStruct)
def mstatusUpdateSideEffect(mstatus: UInt): UInt = {
val mstatusOld = WireInit(mstatus.asTypeOf(new MstatusStruct))
Expand Down Expand Up @@ -426,8 +442,7 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{
MaskedRegMap(Mhartid, mhartid, 0.U, MaskedRegMap.Unwritable),

// Machine Trap Setup
// MaskedRegMap(Mstatus, mstatus, "hffffffffffffffee".U, (x=>{printf("mstatus write: %x time: %d\n", x, GTimer()); x})),
MaskedRegMap(Mstatus, mstatus, "hffffffffffffffff".U(64.W), mstatusUpdateSideEffect),
MaskedRegMap(Mstatus, mstatus, mstatusWMask, mstatusUpdateSideEffect),
MaskedRegMap(Misa, misa), // now MXL, EXT is not changeable
MaskedRegMap(Medeleg, medeleg, "hbbff".U(64.W)),
MaskedRegMap(Mideleg, mideleg, "h222".U(64.W)),
Expand Down

0 comments on commit 1b80938

Please sign in to comment.