1package xiangshan.backend.fu.NewCSR 2 3import chisel3._ 4import chisel3.util._ 5import chisel3.experimental.BundleLiterals._ 6import org.chipsalliance.cde.config.Parameters 7import xiangshan.backend.fu.NewCSR.CSRDefines.{CSRROField => RO, CSRRWField => RW, CSRWARLField => WARL, _} 8import xiangshan.backend.fu.NewCSR.CSRFunc._ 9import xiangshan.backend.fu.fpu.Bundles.Fflags 10import xiangshan.backend.fu.vector.Bundles.{Vl, Vstart, Vxsat} 11import xiangshan.frontend.BPUCtrl 12import xiangshan.mem.prefetch.PrefetchCtrl 13import chisel3.experimental.noPrefix 14 15object CSRBundles { 16 class XtvecBundle extends CSRBundle { 17 val mode = XtvecMode(1, 0, wNoFilter).withReset(0.U) 18 val addr = WARL(63, 2, wNoFilter).withReset(0.U) 19 } 20 21 class CauseBundle extends CSRBundle { 22 val Interrupt = RW(63).withReset(0.U) 23 val ExceptionCode = RW(62, 0).withReset(0.U) 24 } 25 26 class Counteren extends CSRBundle { 27 // Todo: remove reset after adding mcounteren in difftest 28 val CY = RW(0).withReset(0.U) 29 val TM = RW(1).withReset(0.U) 30 val IR = RW(2).withReset(0.U) 31 val HPM = RW(31, 3).withReset(0.U) 32 } 33 34 class OneFieldBundle extends CSRBundle { 35 val ALL = RW(63, 0) 36 } 37 38 class FieldInitBundle extends OneFieldBundle { 39 this.ALL.setRW().withReset(0.U) 40 } 41 42 class XtvalBundle extends FieldInitBundle 43 44 class XtinstBundle extends FieldInitBundle 45 46 abstract class EnvCfg extends CSRBundle { 47 // Set all fields not supported as RO in base class 48 val STCE = RO( 63) .withReset(0.U) // Sstc Enable 49 val PBMTE = RO( 62) .withReset(0.U) // Svpbmt Enable 50 val ADUE = RO( 61) .withReset(0.U) // Svadu extension Enable 51 val DTE = RO( 59) .withReset(0.U) // Ssdbltrp extension Enable 52 val PMM = EnvPMM(33, 32, wNoEffect).withReset(EnvPMM.Disable) // Smnpm extension 53 val CBZE = RW( 7) .withReset(1.U) // Zicboz extension 54 val CBCFE = RW( 6) .withReset(1.U) // Zicbom extension 55 val CBIE = EnvCBIE( 5, 4, wNoEffect).withReset(EnvCBIE.Inval) // Zicbom extension 56 val SSE = RO( 3) .withReset(0.U) // Zicfiss extension Enable in S mode 57 val LPE = RO( 2) .withReset(0.U) // Zicfilp extension 58 val FIOM = RO( 0) .withReset(0.U) // Fence of I/O implies Memory 59 } 60 61 class PrivState extends Bundle { self => 62 val PRVM = PrivMode(0) 63 val V = VirtMode(0) 64 65 def isModeM: Bool = isModeMImpl() 66 67 def isModeHS: Bool = isModeHSImpl() 68 69 def isModeHU: Bool = isModeHUImpl() 70 71 def isModeVU: Bool = isModeVUImpl() 72 73 def isModeVS: Bool = isModeVSImpl() 74 75 def isModeHUorVU: Bool = this.PrvmIsU() 76 77 def isModeHSorHU: Bool = (this.PrvmIsU() || this.PrvmIsS()) && !this.isVirtual 78 79 def isVirtual: Bool = this.V.isOneOf(VirtMode.On) 80 81 private[this] object PrvmIsM { 82 val v: Bool = dontTouch(WireInit(self.PRVM === PrivMode.M).suggestName("PrvmIsM")) 83 def apply(): Bool = v 84 } 85 86 private[this] object PrvmIsS { 87 val v: Bool = dontTouch(WireInit(self.PRVM === PrivMode.S).suggestName("PrvmIsS")) 88 def apply(): Bool = v 89 } 90 91 private[this] object PrvmIsU { 92 val v: Bool = dontTouch(WireInit(self.PRVM === PrivMode.U).suggestName("PrvmIsU")) 93 def apply(): Bool = v 94 } 95 96 private[this] object isModeMImpl { 97 val v: Bool = dontTouch(WireInit(PrvmIsM()).suggestName("isModeM")) 98 def apply(): Bool = v 99 } 100 101 private[this] object isModeHSImpl { 102 val v: Bool = dontTouch(WireInit(!self.isVirtual && noPrefix(PrvmIsS())).suggestName("isModeHS")) 103 def apply(): Bool = v 104 } 105 106 private[this] object isModeHUImpl { 107 val v: Bool = dontTouch(WireInit(!self.isVirtual && noPrefix(PrvmIsU())).suggestName("isModeHU")) 108 def apply(): Bool = v 109 } 110 111 private[this] object isModeVSImpl { 112 val v: Bool = dontTouch(WireInit(self.isVirtual && noPrefix(PrvmIsS())).suggestName("isModeVS")) 113 def apply(): Bool = v 114 } 115 116 private[this] object isModeVUImpl { 117 val v: Bool = dontTouch(WireInit(self.isVirtual && noPrefix(PrvmIsU())).suggestName("isModeVU")) 118 def apply(): Bool = v 119 } 120 121 // VU < VS < HS < M 122 // HU < HS < M 123 def < (that: PrivState): Bool = { 124 (this.isVirtual && (that.isModeM || that.isModeHS)) || 125 (this.V === that.V && this.PRVM < that.PRVM) 126 } 127 128 def > (that: PrivState): Bool = { 129 (that.isVirtual && (this.isModeM || this.isModeHS)) || 130 (that.V === this.V && that.PRVM < this.PRVM) 131 } 132 } 133 134 object PrivState { 135 def ModeM: PrivState = WireInit((new PrivState).Lit( 136 _.PRVM -> PrivMode.M, 137 _.V -> VirtMode.Off, 138 )) 139 140 def ModeHS: PrivState = WireInit((new PrivState).Lit( 141 _.PRVM -> PrivMode.S, 142 _.V -> VirtMode.Off, 143 )) 144 145 def ModeHU: PrivState = WireInit((new PrivState).Lit( 146 _.PRVM -> PrivMode.U, 147 _.V -> VirtMode.Off, 148 )) 149 150 def ModeVS: PrivState = WireInit((new PrivState).Lit( 151 _.PRVM -> PrivMode.S, 152 _.V -> VirtMode.On, 153 )) 154 155 def ModeVU: PrivState = WireInit((new PrivState).Lit( 156 _.PRVM -> PrivMode.U, 157 _.V -> VirtMode.On, 158 )) 159 } 160 161 class RobCommitCSR(implicit p: Parameters) extends Bundle { 162 // need contain 8x8 163 val instNum = ValidIO(UInt(7.W)) 164 val fflags = ValidIO(Fflags()) 165 val fsDirty = Bool() 166 val vxsat = ValidIO(Vxsat()) 167 val vsDirty = Bool() 168 val vtype = ValidIO(new CSRVTypeBundle) 169 val vl = Vl() 170 val vstart = ValidIO(Vstart()) 171 } 172 173 class CSRCustomState(implicit p: Parameters) extends Bundle { 174 // Prefetcher 175 val pf_ctrl = Output(new PrefetchCtrl) 176 // Load violation predictor 177 val lvpred_disable = Output(Bool()) 178 val no_spec_load = Output(Bool()) 179 val storeset_wait_store = Output(Bool()) 180 val storeset_no_fast_wakeup = Output(Bool()) 181 val lvpred_timeout = Output(UInt(5.W)) 182 // Branch predictor 183 val bp_ctrl = Output(new BPUCtrl) 184 // Memory Block 185 val sbuffer_threshold = Output(UInt(4.W)) 186 val ldld_vio_check_enable = Output(Bool()) 187 val soft_prefetch_enable = Output(Bool()) 188 val cache_error_enable = Output(Bool()) 189 val uncache_write_outstanding_enable = Output(Bool()) 190 val hd_misalign_st_enable = Output(Bool()) 191 val hd_misalign_ld_enable = Output(Bool()) 192 val power_down_enable = Output(Bool()) 193 val flush_l2_enable = Output(Bool()) 194 // Rename 195 val fusion_enable = Output(Bool()) 196 val wfi_enable = Output(Bool()) 197 } 198} 199