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 517// add mbmc csr 518class MbmcStruct(implicit p: Parameters) extends XSBundle { 519 val BME = UInt(1.W) 520 val CMODE = UInt(1.W) 521 val BCLEAR = UInt(1.W) 522 val BMA = UInt(58.W) 523} 524 525class TlbMbmcBundle(implicit p: Parameters) extends MbmcStruct { 526 def apply(mbmc_value: UInt): Unit = { 527 require(mbmc_value.getWidth == XLEN) 528 val mc = mbmc_value.asTypeOf(new MbmcStruct) 529 BME := mc.BME 530 CMODE := mc.CMODE 531 BCLEAR := mc.BCLEAR 532 BMA := mc.BMA 533 } 534} 535 536class TlbCsrBundle(implicit p: Parameters) extends XSBundle { 537 val satp = new TlbSatpBundle() 538 val vsatp = new TlbSatpBundle() 539 val hgatp = new TlbHgatpBundle() 540 val mbmc = new TlbMbmcBundle() 541 val priv = new Bundle { 542 val mxr = Bool() 543 val sum = Bool() 544 val vmxr = Bool() 545 val vsum = Bool() 546 val virt = Bool() 547 val spvp = UInt(1.W) 548 val imode = UInt(2.W) 549 val dmode = UInt(2.W) 550 } 551 val mPBMTE = Bool() 552 val hPBMTE = Bool() 553 val pmm = new Bundle { 554 val mseccfg = UInt(2.W) 555 val menvcfg = UInt(2.W) 556 val henvcfg = UInt(2.W) 557 val hstatus = UInt(2.W) 558 val senvcfg = UInt(2.W) 559 } 560 561 override def toPrintable: Printable = { 562 p"Satp mode:0x${Hexadecimal(satp.mode)} asid:0x${Hexadecimal(satp.asid)} ppn:0x${Hexadecimal(satp.ppn)} " + 563 p"Priv mxr:${priv.mxr} sum:${priv.sum} imode:${priv.imode} dmode:${priv.dmode}" 564 } 565} 566 567class SfenceBundle(implicit p: Parameters) extends XSBundle { 568 val valid = Bool() 569 val bits = new Bundle { 570 val rs1 = Bool() 571 val rs2 = Bool() 572 val addr = UInt(VAddrBits.W) 573 val id = UInt((AsidLength).W) // asid or vmid 574 val flushPipe = Bool() 575 val hv = Bool() 576 val hg = Bool() 577 } 578 579 override def toPrintable: Printable = { 580 p"valid:0x${Hexadecimal(valid)} rs1:${bits.rs1} rs2:${bits.rs2} addr:${Hexadecimal(bits.addr)}, flushPipe:${bits.flushPipe}" 581 } 582} 583 584// Bundle for load violation predictor updating 585class MemPredUpdateReq(implicit p: Parameters) extends XSBundle { 586 val valid = Bool() 587 588 // wait table update 589 val waddr = UInt(MemPredPCWidth.W) 590 val wdata = Bool() // true.B by default 591 592 // store set update 593 // by default, ldpc/stpc should be xor folded 594 val ldpc = UInt(MemPredPCWidth.W) 595 val stpc = UInt(MemPredPCWidth.W) 596} 597 598class CustomCSRCtrlIO(implicit p: Parameters) extends XSBundle { 599 // Prefetcher 600 val pf_ctrl = Output(new PrefetchCtrl) 601 // Load violation predictor 602 val lvpred_disable = Output(Bool()) 603 val no_spec_load = Output(Bool()) 604 val storeset_wait_store = Output(Bool()) 605 val storeset_no_fast_wakeup = Output(Bool()) 606 val lvpred_timeout = Output(UInt(5.W)) 607 // Branch predictor 608 val bp_ctrl = Output(new BPUCtrl) 609 // Memory Block 610 val sbuffer_threshold = Output(UInt(4.W)) 611 val ldld_vio_check_enable = Output(Bool()) 612 val soft_prefetch_enable = Output(Bool()) 613 val cache_error_enable = Output(Bool()) 614 val uncache_write_outstanding_enable = Output(Bool()) 615 val hd_misalign_st_enable = Output(Bool()) 616 val hd_misalign_ld_enable = Output(Bool()) 617 val power_down_enable = Output(Bool()) 618 val flush_l2_enable = Output(Bool()) 619 // Rename 620 val fusion_enable = Output(Bool()) 621 val wfi_enable = Output(Bool()) 622 623 // distribute csr write signal 624 val distribute_csr = new DistributedCSRIO() 625 // TODO: move it to a new bundle, since single step is not a custom control signal 626 val singlestep = Output(Bool()) 627 val frontend_trigger = new FrontendTdataDistributeIO() 628 val mem_trigger = new MemTdataDistributeIO() 629 // Virtualization Mode 630 val virtMode = Output(Bool()) 631 // xstatus.fs field is off 632 val fsIsOff = Output(Bool()) 633} 634 635class DistributedCSRIO(implicit p: Parameters) extends XSBundle { 636 // CSR has been written by csr inst, copies of csr should be updated 637 val w = ValidIO(new Bundle { 638 val addr = Output(UInt(12.W)) 639 val data = Output(UInt(XLEN.W)) 640 }) 641} 642 643class DistributedCSRUpdateReq(implicit p: Parameters) extends XSBundle { 644 // Request csr to be updated 645 // 646 // Note that this request will ONLY update CSR Module it self, 647 // copies of csr will NOT be updated, use it with care! 648 // 649 // For each cycle, no more than 1 DistributedCSRUpdateReq is valid 650 val w = ValidIO(new Bundle { 651 val addr = Output(UInt(12.W)) 652 val data = Output(UInt(XLEN.W)) 653 }) 654 def apply(valid: Bool, addr: UInt, data: UInt, src_description: String) = { 655 when(valid){ 656 w.bits.addr := addr 657 w.bits.data := data 658 } 659 println("Distributed CSR update req registered for " + src_description) 660 } 661} 662 663class AddrTransType(implicit p: Parameters) extends XSBundle { 664 val bare, sv39, sv39x4, sv48, sv48x4 = Bool() 665 666 def checkAccessFault(target: UInt): Bool = bare && target(XLEN - 1, PAddrBits).orR 667 def checkPageFault(target: UInt): Bool = 668 sv39 && target(XLEN - 1, 39) =/= VecInit.fill(XLEN - 39)(target(38)).asUInt || 669 sv48 && target(XLEN - 1, 48) =/= VecInit.fill(XLEN - 48)(target(47)).asUInt 670 def checkGuestPageFault(target: UInt): Bool = 671 sv39x4 && target(XLEN - 1, 41).orR || sv48x4 && target(XLEN - 1, 50).orR 672} 673 674object AddrTransType { 675 def apply(bare: Boolean = false, 676 sv39: Boolean = false, 677 sv39x4: Boolean = false, 678 sv48: Boolean = false, 679 sv48x4: Boolean = false)(implicit p: Parameters): AddrTransType = 680 (new AddrTransType).Lit(_.bare -> bare.B, 681 _.sv39 -> sv39.B, 682 _.sv39x4 -> sv39x4.B, 683 _.sv48 -> sv48.B, 684 _.sv48x4 -> sv48x4.B) 685 686 def apply(bare: Bool, sv39: Bool, sv39x4: Bool, sv48: Bool, sv48x4: Bool)(implicit p: Parameters): AddrTransType = { 687 val addrTransType = Wire(new AddrTransType) 688 addrTransType.bare := bare 689 addrTransType.sv39 := sv39 690 addrTransType.sv39x4 := sv39x4 691 addrTransType.sv48 := sv48 692 addrTransType.sv48x4 := sv48x4 693 addrTransType 694 } 695} 696 697class L1CacheErrorInfo(implicit p: Parameters) extends XSBundle { 698 // L1CacheErrorInfo is also used to encode customized CACHE_ERROR CSR 699 val source = Output(new Bundle() { 700 val tag = Bool() // l1 tag array 701 val data = Bool() // l1 data array 702 val l2 = Bool() 703 }) 704 val opType = Output(new Bundle() { 705 val fetch = Bool() 706 val load = Bool() 707 val store = Bool() 708 val probe = Bool() 709 val release = Bool() 710 val atom = Bool() 711 }) 712 val paddr = Output(UInt(PAddrBits.W)) 713 714 // report error and paddr to beu 715 // bus error unit will receive error info iff ecc_error.valid 716 val report_to_beu = Output(Bool()) 717 718 def toL1BusErrorUnitInfo(valid: Bool): L1BusErrorUnitInfo = { 719 val beu_info = Wire(new L1BusErrorUnitInfo) 720 beu_info.ecc_error.valid := valid && report_to_beu 721 beu_info.ecc_error.bits := paddr 722 beu_info 723 } 724} 725 726object TriggerAction extends NamedUInt(4) { 727 // Put breakpoint Exception gererated by trigger in ExceptionVec[3]. 728 def BreakpointExp = 0.U(width.W) // raise breakpoint exception 729 def DebugMode = 1.U(width.W) // enter debug mode 730 def TraceOn = 2.U(width.W) 731 def TraceOff = 3.U(width.W) 732 def TraceNotify = 4.U(width.W) 733 def None = 15.U(width.W) // use triggerAction = 15.U to express that action is None; 734 735 def isExp(action: UInt) = action === BreakpointExp 736 def isDmode(action: UInt) = action === DebugMode 737 def isNone(action: UInt) = action === None 738} 739 740// these 3 bundles help distribute trigger control signals from CSR 741// to Frontend, Load and Store. 742class FrontendTdataDistributeIO(implicit p: Parameters) extends XSBundle { 743 val tUpdate = ValidIO(new Bundle { 744 val addr = Output(UInt(log2Up(TriggerNum).W)) 745 val tdata = new MatchTriggerIO 746 }) 747 val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool())) 748 val debugMode = Output(Bool()) 749 val triggerCanRaiseBpExp = Output(Bool()) 750} 751 752class MemTdataDistributeIO(implicit p: Parameters) extends XSBundle { 753 val tUpdate = ValidIO(new Bundle { 754 val addr = Output(UInt(log2Up(TriggerNum).W)) 755 val tdata = new MatchTriggerIO 756 }) 757 val tEnableVec: Vec[Bool] = Output(Vec(TriggerNum, Bool())) 758 val debugMode = Output(Bool()) 759 val triggerCanRaiseBpExp = Output(Bool()) 760} 761 762class MatchTriggerIO(implicit p: Parameters) extends XSBundle { 763 val matchType = Output(UInt(2.W)) 764 val select = Output(Bool()) 765 val timing = Output(Bool()) 766 val action = Output(TriggerAction()) 767 val chain = Output(Bool()) 768 val execute = Output(Bool()) 769 val store = Output(Bool()) 770 val load = Output(Bool()) 771 val tdata2 = Output(UInt(64.W)) 772 773 def GenTdataDistribute(tdata1: Tdata1Bundle, tdata2: Tdata2Bundle): MatchTriggerIO = { 774 val mcontrol6 = Wire(new Mcontrol6) 775 mcontrol6 := tdata1.DATA.asUInt 776 this.matchType := mcontrol6.MATCH.asUInt 777 this.select := mcontrol6.SELECT.asBool 778 this.timing := false.B 779 this.action := mcontrol6.ACTION.asUInt 780 this.chain := mcontrol6.CHAIN.asBool 781 this.execute := mcontrol6.EXECUTE.asBool 782 this.load := mcontrol6.LOAD.asBool 783 this.store := mcontrol6.STORE.asBool 784 this.tdata2 := tdata2.asUInt 785 this 786 } 787} 788 789class StallReasonIO(width: Int) extends Bundle { 790 val reason = Output(Vec(width, UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 791 val backReason = Flipped(Valid(UInt(log2Ceil(TopDownCounters.NumStallReasons.id).W))) 792} 793 794// custom l2 - l1 interface 795class L2ToL1Hint(implicit p: Parameters) extends XSBundle with HasDCacheParameters { 796 val sourceId = UInt(log2Up(cfg.nMissEntries).W) // tilelink sourceID -> mshr id 797 val isKeyword = Bool() // miss entry keyword -> L1 load queue replay 798} 799 800class TopDownInfo(implicit p: Parameters) extends XSBundle { 801 val lqEmpty = Input(Bool()) 802 val sqEmpty = Input(Bool()) 803 val l1Miss = Input(Bool()) 804 val noUopsIssued = Output(Bool()) 805 val l2TopMiss = Input(new TopDownFromL2Top) 806} 807 808class TopDownFromL2Top(implicit p: Parameters) extends XSBundle { 809 val l2Miss = Bool() 810 val l3Miss = Bool() 811} 812