From d90ce1756c7e8f812904d5333be17e4e1d1fc20c Mon Sep 17 00:00:00 2001 From: Julian Bailey Date: Mon, 18 Dec 2023 09:57:59 -0800 Subject: [PATCH] * Remove line that does an H to S mode mapping as this isn't specified by the manuals. * Fix the mapping when we access scontext or hcontext to ensure we don't switch targets. * Add comment to indicate why we are mapping the S to VS and VS to S. --- src/main/scala/rocket/CSR.scala | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/scala/rocket/CSR.scala b/src/main/scala/rocket/CSR.scala index 737f18673c4..67812022773 100644 --- a/src/main/scala/rocket/CSR.scala +++ b/src/main/scala/rocket/CSR.scala @@ -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) }