Skip to content

Commit

Permalink
Merge pull request #3546 from JulianBailey/master
Browse files Browse the repository at this point in the history
SContext is remaps to HContext when in VSMode
  • Loading branch information
jerryz123 authored Dec 28, 2023
2 parents 74d65ca + d90ce17 commit e4572b0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/scala/rocket/CSR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,17 @@ class CSRFile(
val unvirtualized_mapping = (for (((k, _), v) <- read_mapping zip decoded) yield k -> v.asBool).toMap

for ((k, v) <- unvirtualized_mapping) yield k -> {
val alt = CSR.mode(k) match {
case PRV.S => unvirtualized_mapping.lift(k + (1 << CSR.modeLSB))
case PRV.H => unvirtualized_mapping.lift(k - (1 << CSR.modeLSB))
case _ => None
val alt: Option[Bool] = CSR.mode(k) match {
// hcontext was assigned an unfortunate address; it lives where a
// hypothetical vscontext will live. Exclude them from the S/VS remapping.
// (on separate lines so scala-lint doesnt do something stupid)
case _ if k == CSRs.scontext => None
case _ if k == CSRs.hcontext => None
// When V=1, if a corresponding VS CSR exists, access it instead...
case PRV.H => unvirtualized_mapping.lift(k - (1 << CSR.modeLSB))
// ...and don't access the original S-mode version.
case PRV.S => unvirtualized_mapping.contains(k + (1 << CSR.modeLSB)).option(false.B)
case _ => None
}
alt.map(Mux(reg_mstatus.v, _, v)).getOrElse(v)
}
Expand Down

0 comments on commit e4572b0

Please sign in to comment.