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