xref: /XiangShan/src/main/scala/xiangshan/backend/fu/NewCSR/CSREvents/DretEvent.scala (revision b03c55a5df5dc8793cb44b42dd60141566e57e78)
1package xiangshan.backend.fu.NewCSR.CSREvents
2
3import chisel3._
4import chisel3.util._
5import xiangshan.backend.fu.NewCSR.CSRConfig.VaddrMaxWidth
6import xiangshan.backend.fu.NewCSR.CSRDefines.PrivMode
7import xiangshan.backend.fu.NewCSR._
8
9
10class DretEventOutput extends Bundle with EventUpdatePrivStateOutput with EventOutputBase {
11  val dcsr = ValidIO((new DcsrBundle).addInEvent(_.V, _.PRV))
12  val mstatus = ValidIO((new MstatusBundle).addInEvent(_.MPRV))
13  val debugMode = ValidIO(Bool())
14  val debugIntrEnable = ValidIO(Bool())
15  val targetPc = ValidIO(UInt(VaddrMaxWidth.W))
16
17  override def getBundleByName(name: String): ValidIO[CSRBundle] = {
18    name match {
19      case "dcsr" => this.dcsr
20      case "mstatus" => this.mstatus
21    }
22  }
23}
24
25class DretEventInput extends Bundle {
26  val dcsr = Input(new DcsrBundle)
27  val dpc = Input(new Epc)
28  val mstatus = Input(new MstatusBundle)
29}
30
31class DretEventModule extends Module with CSREventBase {
32  val in = IO(new DretEventInput)
33  val out = IO(new DretEventOutput)
34
35  out := DontCare
36
37  out.debugMode.valid       := valid
38  out.privState.valid       := valid
39  out.dcsr.valid            := valid
40  out.mstatus.valid         := valid
41  out.debugIntrEnable.valid := valid
42  out.targetPc.valid        := valid
43
44  out.privState.bits.PRVM  := in.dcsr.PRV.asUInt
45  out.privState.bits.V     := in.dcsr.V
46  out.mstatus.bits.MPRV    := Mux(!out.privState.bits.isModeM, 0.U, in.mstatus.MPRV.asUInt)
47  out.debugMode.bits       := false.B
48  out.debugIntrEnable.bits := true.B
49  out.targetPc.bits        := in.dpc.asUInt
50}
51
52trait DretEventSinkBundle { self: CSRModule[_] =>
53  val retFromD = IO(Flipped(new DretEventOutput))
54
55  private val updateBundle: ValidIO[CSRBundle] = retFromD.getBundleByName(self.modName.toLowerCase())
56
57  (reg.asInstanceOf[CSRBundle].getFields zip updateBundle.bits.getFields).foreach { case(sink, source) =>
58    if (updateBundle.bits.eventFields.contains(source)) {
59      when(updateBundle.valid) {
60        sink := source
61      }
62    }
63  }
64}
65