xref: /XiangShan/src/main/scala/xiangshan/backend/fu/NewCSR/CSREvents/DretEvent.scala (revision 25dc4a827ee27e3ccbaf02e8e5134872cba28fcd)
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 = Bool()
14  val debugIntrEnable = 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 Dpc)
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.privState.valid := valid
38  out.dcsr.valid      := valid
39  out.mstatus.valid   := valid
40  out.targetPc.valid  := valid
41
42  out.privState.bits.PRVM := in.dcsr.PRV.asUInt
43  out.privState.bits.V    := in.dcsr.V
44  out.mstatus.bits.MPRV   := Mux(in.dcsr.PRV =/= PrivMode.M, 0.U, in.mstatus.MPRV.asUInt)
45  out.debugMode           := false.B
46  out.debugIntrEnable     := true.B
47  out.targetPc.bits       := in.dpc.asUInt
48}
49
50trait DretEventSinkBundle { self: CSRModule[_] =>
51  val retFromD = IO(Flipped(new DretEventOutput))
52
53  private val updateBundle: ValidIO[CSRBundle] = retFromD.getBundleByName(self.modName.toLowerCase())
54
55  (reg.asInstanceOf[CSRBundle].getFields zip updateBundle.bits.getFields).foreach { case(sink, source) =>
56    if (updateBundle.bits.eventFields.contains(source)) {
57      when(updateBundle.valid) {
58        sink := source
59      }
60    }
61  }
62}
63