1/*************************************************************************************** 2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3* Copyright (c) 2020-2021 Peng Cheng Laboratory 4* 5* XiangShan is licensed under Mulan PSL v2. 6* You can use this software according to the terms and conditions of the Mulan PSL v2. 7* You may obtain a copy of Mulan PSL v2 at: 8* http://license.coscl.org.cn/MulanPSL2 9* 10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13* 14* See the Mulan PSL v2 for more details. 15***************************************************************************************/ 16 17package xiangshan 18 19import org.chipsalliance.cde.config.Parameters 20import chisel3._ 21import chisel3.util.BitPat.bitPatToUInt 22import chisel3.util._ 23import chisel3.experimental.BundleLiterals._ 24import utility._ 25import utils._ 26import xiangshan.backend.decode.{ImmUnion, XDecode} 27import xiangshan.backend.fu.FuType 28import xiangshan.backend.rob.RobPtr 29import xiangshan.frontend._ 30import xiangshan.mem.{LqPtr, SqPtr} 31import xiangshan.backend.Bundles.{DynInst, UopIdx} 32import xiangshan.backend.fu.vector.Bundles.VType 33import xiangshan.frontend.{AllAheadFoldedHistoryOldestBits, AllFoldedHistories, BPUCtrl, CGHPtr, FtqPtr, FtqToCtrlIO} 34import xiangshan.frontend.{Ftq_Redirect_SRAMEntry, HasBPUParameter, IfuToBackendIO, PreDecodeInfo, RASPtr} 35import xiangshan.cache.HasDCacheParameters 36import utility._ 37 38import org.chipsalliance.cde.config.Parameters 39import chisel3.util.BitPat.bitPatToUInt 40import chisel3.util.experimental.decode.EspressoMinimizer 41import xiangshan.backend.CtrlToFtqIO 42import xiangshan.backend.fu.NewCSR.{Mcontrol6, Tdata1Bundle, Tdata2Bundle} 43import xiangshan.backend.fu.PMPEntry 44import xiangshan.frontend.Ftq_Redirect_SRAMEntry 45import xiangshan.frontend.AllFoldedHistories 46import xiangshan.frontend.AllAheadFoldedHistoryOldestBits 47import xiangshan.frontend.RASPtr 48import xiangshan.backend.rob.RobBundles.RobCommitEntryBundle 49 50class ValidUndirectioned[T <: Data](gen: T) extends Bundle { 51 val valid = Bool() 52 val bits = gen.cloneType.asInstanceOf[T] 53 54} 55 56object ValidUndirectioned { 57 def apply[T <: Data](gen: T) = { 58 new ValidUndirectioned[T](gen) 59 } 60} 61 62object RSFeedbackType { 63 val lrqFull = 0.U(4.W) 64 val tlbMiss = 1.U(4.W) 65 val mshrFull = 2.U(4.W) 66 val dataInvalid = 3.U(4.W) 67 val bankConflict = 4.U(4.W) 68 val ldVioCheckRedo = 5.U(4.W) 69 val feedbackInvalid = 7.U(4.W) 70 val issueSuccess = 8.U(4.W) 71 val rfArbitFail = 9.U(4.W) 72 val fuIdle = 10.U(4.W) 73 val fuBusy = 11.U(4.W) 74 val fuUncertain = 12.U(4.W) 75 76 val allTypes = 16 77 def apply() = UInt(4.W) 78 79 def isStageSuccess(feedbackType: UInt) = { 80 feedbackType === issueSuccess 81 } 82 83 def isBlocked(feedbackType: UInt) = { 84 feedbackType === rfArbitFail || feedbackType === fuBusy || feedbackType >= lrqFull && feedbackType <= feedbackInvalid 85 } 86} 87 88class PredictorAnswer(implicit p: Parameters) extends XSBundle { 89 val hit = if (!env.FPGAPlatform) Bool() else UInt(0.W) 90 val taken = if (!env.FPGAPlatform) Bool() else UInt(0.W) 91 val target = if (!env.FPGAPlatform) UInt(VAddrBits.W) else UInt(0.W) 92} 93 94class CfiUpdateInfo(implicit p: Parameters) extends XSBundle with HasBPUParameter { 95 // from backend 96 val pc = UInt(VAddrBits.W) 97 // frontend -> backend -> frontend 98 val pd = new PreDecodeInfo 99 val ssp = UInt(log2Up(RasSize).W) 100 val sctr = UInt(RasCtrSize.W) 101 val TOSW = new RASPtr 102 val TOSR = new RASPtr 103 val NOS = new RASPtr 104 val topAddr = UInt(VAddrBits.W) 105 // val hist = new ShiftingGlobalHistory 106 val folded_hist = new AllFoldedHistories(foldedGHistInfos) 107 val afhob = new AllAheadFoldedHistoryOldestBits(foldedGHistInfos) 108 val lastBrNumOH = UInt((numBr+1).W) 109 val ghr = UInt(UbtbGHRLength.W) 110 val histPtr = new CGHPtr 111 val specCnt = Vec(numBr, UInt(10.W)) 112 // need pipeline update 113 val br_hit = Bool() // if in ftb entry 114 val jr_hit = Bool() // if in ftb entry 115 val sc_hit = Bool() // if used in ftb entry, invalid if !br_hit 116 val predTaken = Bool() 117 val target = UInt(VAddrBits.W) 118 val taken = Bool() 119 val isMisPred = Bool() 120 val shift = UInt((log2Ceil(numBr)+1).W) 121 val addIntoHist = Bool() 122 // raise exceptions from backend 123 val backendIGPF = Bool() // instruction guest page fault 124 val backendIPF = Bool() // instruction page fault 125 val backendIAF = Bool() // instruction access fault 126 127 def fromFtqRedirectSram(entry: Ftq_Redirect_SRAMEntry) = { 128 // this.hist := entry.ghist 129 this.histPtr := entry.histPtr 130 this.ssp := entry.ssp 131 this.sctr := entry.sctr 132 this.TOSW := entry.TOSW 133 this.TOSR := entry.TOSR 134 this.NOS := entry.NOS 135 this.topAddr := entry.topAddr 136 this 137 } 138 139 def hasBackendFault = backendIGPF || backendIPF || backendIAF 140} 141 142// Dequeue DecodeWidth insts from Ibuffer 143class CtrlFlow(implicit p: Parameters) extends XSBundle { 144 val instr = UInt(32.W) 145 val pc = UInt(VAddrBits.W) 146 val foldpc = UInt(MemPredPCWidth.W) 147 val exceptionVec = ExceptionVec() 148 val backendException = Bool() 149 val trigger = TriggerAction() 150 val pd = new PreDecodeInfo 151 val pred_taken = Bool() 152 val crossPageIPFFix = Bool() 153 val storeSetHit = Bool() // inst has been allocated an store set 154 val waitForRobIdx = new RobPtr // store set predicted previous store robIdx 155 // Load wait is needed 156 // load inst will not be executed until former store (predicted by mdp) addr calcuated 157 val loadWaitBit = Bool() 158 // If (loadWaitBit && loadWaitStrict), strict load wait is needed 159 // load inst will not be executed until ALL former store addr calcuated 160 val loadWaitStrict = Bool() 161 val ssid = UInt(SSIDWidth.W) 162 val ftqPtr = new FtqPtr 163 val ftqOffset = UInt(log2Up(PredictWidth).W) 164 val isLastInFtqEntry = Bool() 165} 166 167 168class FPUCtrlSignals(implicit p: Parameters) extends XSBundle { 169 val isAddSub = Bool() // swap23 170 val typeTagIn = UInt(2.W) // H S D 171 val typeTagOut = UInt(2.W) // H S D 172 val fromInt = Bool() 173 val wflags = Bool() 174 val fpWen = Bool() 175 val fmaCmd = UInt(2.W) 176 val div = Bool() 177 val sqrt = Bool() 178 val fcvt = Bool() 179 val typ = UInt(2.W) 180 val fmt = UInt(2.W) 181 val ren3 = Bool() //TODO: remove SrcType.fp 182 val rm = UInt(3.W) 183} 184 185// Decode DecodeWidth insts at Decode Stage 186class CtrlSignals(implicit p: Parameters) extends XSBundle { 187 // val debug_globalID = UInt(XLEN.W) 188 val srcType = Vec(4, SrcType()) 189 val lsrc = Vec(4, UInt(LogicRegsWidth.W)) 190 val ldest = UInt(LogicRegsWidth.W) 191 val fuType = FuType() 192 val fuOpType = FuOpType() 193 val rfWen = Bool() 194 val fpWen = Bool() 195 val vecWen = Bool() 196 val isXSTrap = Bool() 197 val noSpecExec = Bool() // wait forward 198 val blockBackward = Bool() // block backward 199 val flushPipe = Bool() // This inst will flush all the pipe when commit, like exception but can commit 200 val uopSplitType = UopSplitType() 201 val selImm = SelImm() 202 val imm = UInt(32.W) 203 val commitType = CommitType() 204 val fpu = new FPUCtrlSignals 205 val uopIdx = UopIdx() 206 val isMove = Bool() 207 val vm = Bool() 208 val singleStep = Bool() 209 // This inst will flush all the pipe when it is the oldest inst in ROB, 210 // then replay from this inst itself 211 val replayInst = Bool() 212 val canRobCompress = Bool() 213 214 private def allSignals = srcType.take(3) ++ Seq(fuType, fuOpType, rfWen, fpWen, vecWen, 215 isXSTrap, noSpecExec, blockBackward, flushPipe, canRobCompress, uopSplitType, selImm) 216 217 def decode(inst: UInt, table: Iterable[(BitPat, List[BitPat])]): CtrlSignals = { 218 val decoder = freechips.rocketchip.rocket.DecodeLogic(inst, XDecode.decodeDefault, table, EspressoMinimizer) 219 allSignals zip decoder foreach { case (s, d) => s := d } 220 commitType := DontCare 221 this 222 } 223 224 def decode(bit: List[BitPat]): CtrlSignals = { 225 allSignals.zip(bit.map(bitPatToUInt(_))).foreach{ case (s, d) => s := d } 226 this 227 } 228 229 def isWFI: Bool = fuType === FuType.csr.U && fuOpType === CSROpType.wfi 230 def isSoftPrefetch: Bool = { 231 fuType === FuType.alu.U && fuOpType === ALUOpType.or && selImm === SelImm.IMM_I && ldest === 0.U 232 } 233 def needWriteRf: Bool = rfWen || fpWen || vecWen 234 def isHyperInst: Bool = { 235 fuType === FuType.ldu.U && LSUOpType.isHlv(fuOpType) || fuType === FuType.stu.U && LSUOpType.isHsv(fuOpType) 236 } 237} 238 239class CfCtrl(implicit p: Parameters) extends XSBundle { 240 val cf = new CtrlFlow 241 val ctrl = new CtrlSignals 242} 243 244class PerfDebugInfo(implicit p: Parameters) extends XSBundle { 245 val eliminatedMove = Bool() 246 // val fetchTime = UInt(XLEN.W) 247 val renameTime = UInt(XLEN.W) 248 val dispatchTime = UInt(XLEN.W) 249 val enqRsTime = UInt(XLEN.W) 250 val selectTime = UInt(XLEN.W) 251 val issueTime = UInt(XLEN.W) 252 val writebackTime = UInt(XLEN.W) 253 // val commitTime = UInt(XLEN.W) 254 val runahead_checkpoint_id = UInt(XLEN.W) 255 val tlbFirstReqTime = UInt(XLEN.W) 256 val tlbRespTime = UInt(XLEN.W) // when getting hit result (including delay in L2TLB hit) 257} 258 259// Separate LSQ 260class LSIdx(implicit p: Parameters) extends XSBundle { 261 val lqIdx = new LqPtr 262 val sqIdx = new SqPtr 263} 264 265// CfCtrl -> MicroOp at Rename Stage 266class MicroOp(implicit p: Parameters) extends CfCtrl { 267 val srcState = Vec(4, SrcState()) 268 val psrc = Vec(4, UInt(PhyRegIdxWidth.W)) 269 val pdest = UInt(PhyRegIdxWidth.W) 270 val robIdx = new RobPtr 271 val instrSize = UInt(log2Ceil(RenameWidth + 1).W) 272 val lqIdx = new LqPtr 273 val sqIdx = new SqPtr 274 val eliminatedMove = Bool() 275 val snapshot = Bool() 276 val debugInfo = new PerfDebugInfo 277 def needRfRPort(index: Int, isFp: Boolean, ignoreState: Boolean = true) : Bool = { 278 val stateReady = srcState(index) === SrcState.rdy || ignoreState.B 279 val readReg = if (isFp) { 280 ctrl.srcType(index) === SrcType.fp 281 } else { 282 ctrl.srcType(index) === SrcType.reg && ctrl.lsrc(index) =/= 0.U 283 } 284 readReg && stateReady 285 } 286 def srcIsReady: Vec[Bool] = { 287 VecInit(ctrl.srcType.zip(srcState).map{ case (t, s) => SrcType.isPcOrImm(t) || s === SrcState.rdy }) 288 } 289 def clearExceptions( 290 exceptionBits: Seq[Int] = Seq(), 291 flushPipe: Boolean = false, 292 replayInst: Boolean = false 293 ): MicroOp = { 294 cf.exceptionVec.zipWithIndex.filterNot(x => exceptionBits.contains(x._2)).foreach(_._1 := false.B) 295 if (!flushPipe) { ctrl.flushPipe := false.B } 296 if (!replayInst) { ctrl.replayInst := false.B } 297 this 298 } 299} 300 301class XSBundleWithMicroOp(implicit p: Parameters) extends XSBundle { 302 val uop = new DynInst 303} 304 305class MicroOpRbExt(implicit p: Parameters) extends XSBundleWithMicroOp { 306 val flag = UInt(1.W) 307} 308 309class Redirect(implicit p: Parameters) extends XSBundle { 310 val isRVC = Bool() 311 val robIdx = new RobPtr 312 val ftqIdx = new FtqPtr 313 val ftqOffset = UInt(log2Up(PredictWidth).W) 314 val level = RedirectLevel() 315 val interrupt = Bool() 316 val cfiUpdate = new CfiUpdateInfo 317 val fullTarget = UInt(XLEN.W) // only used for tval storage in backend 318 319 val stFtqIdx = new FtqPtr // for load violation predict 320 val stFtqOffset = UInt(log2Up(PredictWidth).W) 321 322 val debug_runahead_checkpoint_id = UInt(64.W) 323 val debugIsCtrl = Bool() 324 val debugIsMemVio = Bool() 325 326 def flushItself() = RedirectLevel.flushItself(level) 327} 328 329object Redirect extends HasCircularQueuePtrHelper { 330 331 def selectOldestRedirect(xs: Seq[Valid[Redirect]]): Vec[Bool] = { 332 val compareVec = (0 until xs.length).map(i => (0 until i).map(j => isAfter(xs(j).bits.robIdx, xs(i).bits.robIdx))) 333 val resultOnehot = VecInit((0 until xs.length).map(i => Cat((0 until xs.length).map(j => 334 (if (j < i) !xs(j).valid || compareVec(i)(j) 335 else if (j == i) xs(i).valid 336 else !xs(j).valid || !compareVec(j)(i)) 337 )).andR)) 338 resultOnehot 339 } 340} 341 342class ResetPregStateReq(implicit p: Parameters) extends XSBundle { 343 // NOTE: set isInt and isFp both to 'false' when invalid 344 val isInt = Bool() 345 val isFp = Bool() 346 val isVec = Bool() 347 val isV0 = Bool() 348 val isVl = Bool() 349 val preg = UInt(PhyRegIdxWidth.W) 350} 351 352class DebugBundle(implicit p: Parameters) extends XSBundle { 353 val isMMIO = Bool() 354 val isNC = Bool() 355 val isPerfCnt = Bool() 356 val paddr = UInt(PAddrBits.W) 357 val vaddr = UInt(VAddrBits.W) 358 359 def isSkipDiff: Bool = isMMIO || isNC || isPerfCnt 360 /* add L/S inst info in EXU */ 361 // val L1toL2TlbLatency = UInt(XLEN.W) 362 // val levelTlbHit = UInt(2.W) 363} 364 365class SoftIfetchPrefetchBundle(implicit p: Parameters) extends XSBundle { 366 val vaddr = UInt(VAddrBits.W) 367} 368 369class ExternalInterruptIO(implicit p: Parameters) extends XSBundle { 370 val mtip = Input(Bool()) 371 val msip = Input(Bool()) 372 val meip = Input(Bool()) 373 val seip = Input(Bool()) 374 val debug = Input(Bool()) 375 val nmi = new NonmaskableInterruptIO() 376} 377 378class NonmaskableInterruptIO() extends Bundle { 379 val nmi_31 = Input(Bool()) 380 val nmi_43 = Input(Bool()) 381 // reserve for other nmi type 382} 383 384class CSRSpecialIO(implicit p: Parameters) extends XSBundle { 385 val exception = Flipped(ValidIO(new DynInst)) 386 val isInterrupt = Input(Bool()) 387 val memExceptionVAddr = Input(UInt(VAddrBits.W)) 388 val trapTarget = Output(UInt(VAddrBits.W)) 389 val externalInterrupt = new ExternalInterruptIO 390 val interrupt = Output(Bool()) 391} 392 393class DiffCommitIO(implicit p: Parameters) extends XSBundle { 394 val isCommit = Bool() 395 val commitValid = Vec(CommitWidth * MaxUopSize, Bool()) 396 397 val info = Vec(CommitWidth * MaxUopSize, new RabCommitInfo) 398} 399 400class RobCommitInfo(implicit p: Parameters) extends RobCommitEntryBundle 401 402class RobCommitIO(implicit p: Parameters) extends XSBundle { 403 val isCommit = Bool() 404 val commitValid = Vec(CommitWidth, Bool()) 405 406 val isWalk = Bool() 407 // valid bits optimized for walk 408 val walkValid = Vec(CommitWidth, Bool()) 409 410 val info = Vec(CommitWidth, new RobCommitInfo) 411 val robIdx = Vec(CommitWidth, new RobPtr) 412 413 def hasWalkInstr: Bool = isWalk && walkValid.asUInt.orR 414 def hasCommitInstr: Bool = isCommit && commitValid.asUInt.orR 415} 416 417class RabCommitInfo(implicit p: Parameters) extends XSBundle { 418 val ldest = UInt(LogicRegsWidth.W) 419 val pdest = UInt(PhyRegIdxWidth.W) 420 val rfWen = Bool() 421 val fpWen = Bool() 422 val vecWen = Bool() 423 val v0Wen = Bool() 424 val vlWen = Bool() 425 val isMove = Bool() 426} 427 428class RabCommitIO(implicit p: Parameters) extends XSBundle { 429 val isCommit = Bool() 430 val commitValid = Vec(RabCommitWidth, Bool()) 431 432 val isWalk = Bool() 433 // valid bits optimized for walk 434 val walkValid = Vec(RabCommitWidth, Bool()) 435 436 val info = Vec(RabCommitWidth, new RabCommitInfo) 437 val robIdx = OptionWrapper(!env.FPGAPlatform, Vec(RabCommitWidth, new RobPtr)) 438 439 def hasWalkInstr: Bool = isWalk && walkValid.asUInt.orR 440 def hasCommitInstr: Bool = isCommit && commitValid.asUInt.orR 441} 442 443class SnapshotPort(implicit p: Parameters) extends XSBundle { 444 val snptEnq = Bool() 445 val snptDeq = Bool() 446 val useSnpt = Bool() 447 val snptSelect = UInt(log2Ceil(RenameSnapshotNum).W) 448 val flushVec = Vec(RenameSnapshotNum, Bool()) 449} 450 451class RSFeedback(isVector: Boolean = false)(implicit p: Parameters) extends XSBundle { 452 val robIdx = new RobPtr 453 val hit = Bool() 454 val flushState = Bool() 455 val sourceType = RSFeedbackType() 456 val dataInvalidSqIdx = new SqPtr 457 val sqIdx = new SqPtr 458 val lqIdx = new LqPtr 459} 460 461class MemRSFeedbackIO(isVector: Boolean = false)(implicit p: Parameters) extends XSBundle { 462 // Note: you need to update in implicit Parameters p before imp MemRSFeedbackIO 463 // for instance: MemRSFeedbackIO()(updateP) 464 val feedbackSlow = ValidIO(new RSFeedback(isVector)) // dcache miss queue full, dtlb miss 465 val feedbackFast = ValidIO(new RSFeedback(isVector)) // bank conflict 466} 467 468class LoadCancelIO(implicit p: Parameters) extends XSBundle { 469 val ld1Cancel = Bool() 470 val ld2Cancel = Bool() 471} 472 473class FrontendToCtrlIO(implicit p: Parameters) extends XSBundle { 474 // to backend end 475 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 476 val stallReason = new StallReasonIO(DecodeWidth) 477 val fromFtq = new FtqToCtrlIO 478 val fromIfu = new IfuToBackendIO 479 // from backend 480 val toFtq = Flipped(new CtrlToFtqIO) 481 val canAccept = Input(Bool()) 482} 483 484class SatpStruct(implicit p: Parameters) extends XSBundle { 485 val mode = UInt(4.W) 486 val asid = UInt(16.W) 487 val ppn = UInt(44.W) 488} 489 490class TlbSatpBundle(implicit p: Parameters) extends SatpStruct { 491 val changed = Bool() 492 493 // Todo: remove it 494 def apply(satp_value: UInt): Unit = { 495 require(satp_value.getWidth == XLEN) 496 val sa = satp_value.asTypeOf(new SatpStruct) 497 mode := sa.mode 498 asid := sa.asid 499 ppn := sa.ppn 500 changed := DataChanged(sa.asid) // when ppn is changed, software need do the flush 501 } 502} 503 504class HgatpStruct(implicit p: Parameters) extends XSBundle { 505 val mode = UInt(4.W) 506 val vmid = UInt(16.W) 507 val ppn = UInt(44.W) 508} 509 510class TlbHgatpBundle(implicit p: Parameters) extends HgatpStruct { 511 val changed = Bool() 512 513 // Todo: remove it 514 def apply(hgatp_value: UInt): Unit = { 515 require(hgatp_value.getWidth == XLEN) 516 val sa = hgatp_value.asTypeOf(new HgatpStruct) 517 mode := sa.mode 518 vmid := sa.vmid 519 ppn := sa.ppn 520 changed := DataChanged(sa.vmid) // when ppn is changed, software need do the flush 521 } 522} 523 524class TlbCsrBundle(implicit p: Parameters) extends XSBundle { 525 val satp = new TlbSatpBundle() 526 val vsatp = new TlbSatpBundle() 527 val hgatp = new TlbHgatpBundle() 528 val priv = new Bundle { 529 val mxr = Bool() 530 val sum = Bool() 531 val vmxr = Bool() 532 val vsum = Bool() 533 val virt = Bool() 534 val spvp = UInt(1.W) 535 val imode = UInt(2.W) 536 val dmode = UInt(2.W) 537 } 538 val mPBMTE = Bool() 539 val hPBMTE = Bool() 540 val pmm = new Bundle { 541 val mseccfg = UInt(2.W) 542 val menvcfg = UInt(2.W) 543 val henvcfg = UInt(2.W) 544 val hstatus = UInt(2.W) 545 val senvcfg = UInt(2.W) 546 } 547 548 override def toPrintable: Printable = { 549 p"Satp mode:0x${Hexadecimal(satp.mode)} asid:0x${Hexadecimal(satp.asid)} ppn:0x${Hexadecimal(satp.ppn)} " + 550 p"Priv mxr:${priv.mxr} sum:${priv.sum} imode:${priv.imode} dmode:${priv.dmode}" 551 } 552} 553 554class SfenceBundle(implicit p: Parameters) extends XSBundle { 555 val valid = Bool() 556 val bits = new Bundle { 557 val rs1 = Bool() 558 val rs2 = Bool() 559 val addr = UInt(VAddrBits.W) 560 val id = UInt((AsidLength).W) // asid or vmid 561 val flushPipe = Bool() 562 val hv = Bool() 563 val hg = Bool() 564 } 565 566 override def toPrintable: Printable = { 567 p"valid:0x${Hexadecimal(valid)} rs1:${bits.rs1} rs2:${bits.rs2} addr:${Hexadecimal(bits.addr)}, flushPipe:${bits.flushPipe}" 568 } 569} 570 571// Bundle for load violation predictor updating 572class MemPredUpdateReq(implicit p: Parameters) extends XSBundle { 573 val valid = Bool() 574 575 // wait table update 576 val waddr = UInt(MemPredPCWidth.W) 577 val wdata = Bool() // true.B by default 578 579 // store set update 580 // by default, ldpc/stpc should be xor folded 581 val ldpc = UInt(MemPredPCWidth.W) 582 val stpc = UInt(MemPredPCWidth.W) 583} 584 585class CustomCSRCtrlIO(implicit p: Parameters) extends XSBundle { 586 // Prefetcher 587 val l1I_pf_enable = Output(Bool()) 588 val l2_pf_enable = Output(Bool()) 589 val l1D_pf_enable = Output(Bool()) 590 val l1D_pf_train_on_hit = Output(Bool()) 591 val l1D_pf_enable_agt = Output(Bool()) 592 val l1D_pf_enable_pht = Output(Bool()) 593 val l1D_pf_active_threshold = Output(UInt(4.W)) 594 val l1D_pf_active_stride = Output(UInt(6.W)) 595 val l1D_pf_enable_stride = Output(Bool()) 596 val l2_pf_store_only = Output(Bool()) 597 // ICache 598 val icache_parity_enable = Output(Bool()) 599 // Load violation predictor 600 val lvpred_disable = Output(Bool()) 601 val no_spec_load = Output(Bool()) 602 val storeset_wait_store = Output(Bool()) 603 val storeset_no_fast_wakeup = Output(Bool()) 604 val lvpred_timeout = Output(UInt(5.W)) 605 // Branch predictor 606 val bp_ctrl = Output(new BPUCtrl) 607 // Memory Block 608 val sbuffer_threshold = Output(UInt(4.W)) 609 val ldld_vio_check_enable = Output(Bool()) 610 val soft_prefetch_enable = Output(Bool()) 611 val cache_error_enable = Output(Bool()) 612 val uncache_write_outstanding_enable = Output(Bool()) 613 val hd_misalign_st_enable = Output(Bool()) 614 val hd_misalign_ld_enable = Output(Bool()) 615 // Rename 616 val fusion_enable = Output(Bool()) 617 val wfi_enable = Output(Bool()) 618 619 // distribute csr write signal 620 val distribute_csr = new DistributedCSRIO() 621 // TODO: move it to a new bundle, since single step is not a custom control signal 622 val singlestep = Output(Bool()) 623 val frontend_trigger = new FrontendTdataDistributeIO() 624 val mem_trigger = new MemTdataDistributeIO() 625 // Virtualization Mode 626 val virtMode = Output(Bool()) 627 // xstatus.fs field is off 628 val fsIsOff = Output(Bool()) 629} 630 631class DistributedCSRIO(implicit p: Parameters) extends XSBundle { 632 // CSR has been written by csr inst, copies of csr should be updated 633 val w = ValidIO(new Bundle { 634 val addr = Output(UInt(12.W)) 635 val data = Output(UInt(XLEN.W)) 636 }) 637} 638 639class DistributedCSRUpdateReq(implicit p: Parameters) extends XSBundle { 640 // Request csr to be updated 641 // 642 // Note that this request will ONLY update CSR Module it self, 643 // copies of csr will NOT be updated, use it with care! 644 // 645 // For each cycle, no more than 1 DistributedCSRUpdateReq is valid 646 val w = ValidIO(new Bundle { 647 val addr = Output(UInt(12.W)) 648 val data = Output(UInt(XLEN.W)) 649 }) 650 def apply(valid: Bool, addr: UInt, data: UInt, src_description: String) = { 651 when(valid){ 652 w.bits.addr := addr 653 w.bits.data := data 654 } 655 println("Distributed CSR update req registered for " + src_description) 656 } 657} 658 659class AddrTransType(implicit p: Parameters) extends XSBundle { 660 val bare, sv39, sv39x4, sv48, sv48x4 = Bool() 661 662 def checkAccessFault(target: UInt): Bool = bare && target(XLEN - 1, PAddrBits).orR 663 def checkPageFault(target: UInt): Bool = 664 sv39 && target(XLEN - 1, 39) =/= VecInit.fill(XLEN - 39)(target(38)).asUInt || 665 sv48 && target(XLEN - 1, 48) =/= VecInit.fill(XLEN - 48)(target(47)).asUInt 666 def checkGuestPageFault(target: UInt): Bool = 667 sv39x4 && target(XLEN - 1, 41).orR || sv48x4 && target(XLEN - 1, 50).orR 668} 669 670object AddrTransType { 671 def apply(bare: Boolean = false, 672 sv39: Boolean = false, 673 sv39x4: Boolean = false, 674 sv48: Boolean = false, 675 sv48x4: Boolean = false)(implicit p: Parameters): AddrTransType = 676 (new AddrTransType).Lit(_.bare -> bare.B, 677 _.sv39 -> sv39.B, 678 _.sv39x4 -> sv39x4.B, 679 _.sv48 -> sv48.B, 680 _.sv48x4 -> sv48x4.B) 681 682 def apply(bare: Bool, sv39: Bool, sv39x4: Bool, sv48: Bool, sv48x4: Bool)(implicit p: Parameters): AddrTransType = { 683 val addrTransType = Wire(new AddrTransType) 684 addrTransType.bare := bare 685 addrTransType.sv39 := sv39 686 addrTransType.sv39x4 := sv39x4 687 addrTransType.sv48 := sv48 688 addrTransType.sv48x4 := sv48x4 689 addrTransType 690 } 691} 692 693class L1CacheErrorInfo(implicit p: Parameters) extends XSBundle { 694 // L1CacheErrorInfo is also used to encode customized CACHE_ERROR CSR 695 val source = Output(new Bundle() { 696 val tag = Bool() // l1 tag array 697 val data = Bool() // l1 data array 698 val l2 = Bool() 699 }) 700 val opType = Output(new Bundle() { 701 val fetch = Bool() 702 val load = Bool() 703 val store = Bool() 704 val probe = Bool() 705 val release = Bool() 706 val atom = Bool() 707 }) 708 val paddr = Output(UInt(PAddrBits.W)) 709 710 // report error and paddr to beu 711 // bus error unit will receive error info iff ecc_error.valid 712 val report_to_beu = Output(Bool()) 713 714 def toL1BusErrorUnitInfo(valid: Bool): L1BusErrorUnitInfo = { 715 val beu_info = Wire(new L1BusErrorUnitInfo) 716 beu_info.ecc_error.valid := valid && report_to_beu 717 beu_info.ecc_error.bits := paddr 718 beu_info 719 } 720} 721 722object TriggerAction extends NamedUInt(4) { 723 // Put breakpoint Exception gererated by trigger in ExceptionVec[3]. 724 def BreakpointExp = 0.U(width.W) // raise breakpoint exception 725 def DebugMode = 1.U(width.W) // enter debug mode 726 def TraceOn = 2.U(width.W) 727 def TraceOff = 3.U(width.W) 728 def TraceNotify = 4.U(width.W) 729 def None = 15.U(width.W) // use triggerAction = 15.U to express that action is None; 730 731 def isExp(action: UInt) = action === BreakpointExp 732 def isDmode(action: UInt) = action === DebugMode 733 def isNone(action: UInt) = action === None 734} 735 736// these 3 bundles help distribute trigger control signals from CSR 737// to Frontend, Load and Store. 738class FrontendTdataDistributeIO(implicit p: Parameters) extends XSBundle { 739 val tUpdate = ValidIO(new Bundle { 740 val addr = Output(UInt(log2Up(TriggerNum).W)) 741 val tdata = new MatchTriggerIO 742 }) 743 val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool())) 744 val debugMode = Output(Bool()) 745 val triggerCanRaiseBpExp = Output(Bool()) 746} 747 748class MemTdataDistributeIO(implicit p: Parameters) extends XSBundle { 749 val tUpdate = ValidIO(new Bundle { 750 val addr = Output(UInt(log2Up(TriggerNum).W)) 751 val tdata = new MatchTriggerIO 752 }) 753 val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool())) 754 val debugMode = Output(Bool()) 755 val triggerCanRaiseBpExp = Output(Bool()) 756} 757 758class MatchTriggerIO(implicit p: Parameters) extends XSBundle { 759 val matchType = Output(UInt(2.W)) 760 val select = Output(Bool()) 761 val timing = Output(Bool()) 762 val action = Output(TriggerAction()) 763 val chain = Output(Bool()) 764 val execute = Output(Bool()) 765 val store = Output(Bool()) 766 val load = Output(Bool()) 767 val tdata2 = Output(UInt(64.W)) 768 769 def GenTdataDistribute(tdata1: Tdata1Bundle, tdata2: Tdata2Bundle): MatchTriggerIO = { 770 val mcontrol6 = Wire(new Mcontrol6) 771 mcontrol6 := tdata1.DATA.asUInt 772 this.matchType := mcontrol6.MATCH.asUInt 773 this.select := mcontrol6.SELECT.asBool 774 this.timing := false.B 775 this.action := mcontrol6.ACTION.asUInt 776 this.chain := mcontrol6.CHAIN.asBool 777 this.execute := mcontrol6.EXECUTE.asBool 778 this.load := mcontrol6.LOAD.asBool 779 this.store := mcontrol6.STORE.asBool 780 this.tdata2 := tdata2.asUInt 781 this 782 } 783} 784 785class StallReasonIO(width: Int) extends Bundle { 786 val reason = Output(Vec(width, UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 787 val backReason = Flipped(Valid(UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 788} 789 790// custom l2 - l1 interface 791class L2ToL1Hint(implicit p: Parameters) extends XSBundle with HasDCacheParameters { 792 val sourceId = UInt(log2Up(cfg.nMissEntries).W) // tilelink sourceID -> mshr id 793 val isKeyword = Bool() // miss entry keyword -> L1 load queue replay 794} 795 796