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