From 0e245bc0d07d7b3406ed6257ab367f60a3f49132 Mon Sep 17 00:00:00 2001 From: lewislzh Date: Thu, 28 Nov 2024 13:26:59 +0800 Subject: [PATCH] fix(dbltrp): fix sdt/dte interaction logic * menvcfg.DTE only control Smode dbltrp. Thus mstatus.sdt will not control by DTE. * as sstatus is alias of mstatus, when menvcfg.DTE close write sstatus.sdt cannot lead to shadow write of mstatus.sdt. As a result, we add wmask of sdt, when write source is from alias write. While vsstatus is not alias of any other CSR fields, so origin logic is correct. --- .../scala/xiangshan/backend/fu/NewCSR/MachineLevel.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/scala/xiangshan/backend/fu/NewCSR/MachineLevel.scala b/src/main/scala/xiangshan/backend/fu/NewCSR/MachineLevel.scala index ba3b430bbc..b91eaff16b 100644 --- a/src/main/scala/xiangshan/backend/fu/NewCSR/MachineLevel.scala +++ b/src/main/scala/xiangshan/backend/fu/NewCSR/MachineLevel.scala @@ -500,9 +500,9 @@ class MstatusModule(implicit override val p: Parameters) extends CSRModule("MSta } // when DTE is zero, SDT field is read-only zero(write any, read zero, side effect of write 1 is block) val writeSDT = Wire(Bool()) - writeSDT := Mux(this.menvcfg.DTE.asBool, (w.wdataFields.SDT && w.wen) || (wAliasSstatus.wdataFields.SDT && wAliasSstatus.wen), 0.U) - when (!this.menvcfg.DTE) { - regOut.SDT := false.B + writeSDT := (w.wdataFields.SDT && w.wen) || (this.menvcfg.DTE.asBool && wAliasSstatus.wdataFields.SDT && wAliasSstatus.wen) + when (!this.menvcfg.DTE.asBool && wAliasSstatus.wdataFields.SDT && wAliasSstatus.wen ) { + reg.SDT := reg.SDT } // SDT and SIE is the same as MDT and MIE when (writeSDT) { @@ -511,6 +511,7 @@ class MstatusModule(implicit override val p: Parameters) extends CSRModule("MSta // read connection mstatus :|= regOut sstatus := mstatus + sstatus.SDT := regOut.SDT && menvcfg.DTE rdata := mstatus.asUInt sstatusRdata := sstatus.asUInt }