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