1package xiangshan 2 3import chisel3._ 4import chisel3.util._ 5import bus.simplebus._ 6import xiangshan.backend.brq.BrqPtr 7import xiangshan.backend.fu.fpu.Fflags 8import xiangshan.backend.rename.FreeListPtr 9import xiangshan.backend.roq.RoqPtr 10import xiangshan.mem.{LqPtr, SqPtr} 11import xiangshan.frontend.PreDecodeInfo 12import xiangshan.frontend.HasBPUParameter 13import xiangshan.frontend.HasTageParameter 14 15// Fetch FetchWidth x 32-bit insts from Icache 16class FetchPacket extends XSBundle { 17 val instrs = Vec(PredictWidth, UInt(32.W)) 18 val mask = UInt(PredictWidth.W) 19 // val pc = UInt(VAddrBits.W) 20 val pc = Vec(PredictWidth, UInt(VAddrBits.W)) 21 val pnpc = Vec(PredictWidth, UInt(VAddrBits.W)) 22 val brInfo = Vec(PredictWidth, new BranchInfo) 23 val pd = Vec(PredictWidth, new PreDecodeInfo) 24 val ipf = Bool() 25 val crossPageIPFFix = Bool() 26} 27 28class ValidUndirectioned[T <: Data](gen: T) extends Bundle { 29 val valid = Bool() 30 val bits = gen.cloneType.asInstanceOf[T] 31 override def cloneType = new ValidUndirectioned(gen).asInstanceOf[this.type] 32} 33 34object ValidUndirectioned { 35 def apply[T <: Data](gen: T) = { 36 new ValidUndirectioned[T](gen) 37 } 38} 39 40class TageMeta extends XSBundle with HasTageParameter { 41 val provider = ValidUndirectioned(UInt(log2Ceil(TageNTables).W)) 42 val altDiffers = Bool() 43 val providerU = UInt(2.W) 44 val providerCtr = UInt(3.W) 45 val allocate = ValidUndirectioned(UInt(log2Ceil(TageNTables).W)) 46} 47 48class BranchPrediction extends XSBundle { 49 val redirect = Bool() 50 val taken = Bool() 51 val jmpIdx = UInt(log2Up(PredictWidth).W) 52 val hasNotTakenBrs = Bool() 53 val target = UInt(VAddrBits.W) 54 val saveHalfRVI = Bool() 55 val takenOnBr = Bool() 56} 57 58class BranchInfo extends XSBundle with HasBPUParameter { 59 val ubtbWriteWay = UInt(log2Up(UBtbWays).W) 60 val ubtbHits = Bool() 61 val btbWriteWay = UInt(log2Up(BtbWays).W) 62 val btbHitJal = Bool() 63 val bimCtr = UInt(2.W) 64 val histPtr = UInt(log2Up(ExtHistoryLength).W) 65 val predHistPtr = UInt(log2Up(ExtHistoryLength).W) 66 val tageMeta = new TageMeta 67 val rasSp = UInt(log2Up(RasSize).W) 68 val rasTopCtr = UInt(8.W) 69 val rasToqAddr = UInt(VAddrBits.W) 70 val fetchIdx = UInt(log2Up(PredictWidth).W) 71 val specCnt = UInt(10.W) 72 val sawNotTakenBranch = Bool() 73 74 val debug_ubtb_cycle = if (EnableBPUTimeRecord) UInt(64.W) else UInt(0.W) 75 val debug_btb_cycle = if (EnableBPUTimeRecord) UInt(64.W) else UInt(0.W) 76 val debug_tage_cycle = if (EnableBPUTimeRecord) UInt(64.W) else UInt(0.W) 77 78 def apply(histPtr: UInt, tageMeta: TageMeta, rasSp: UInt, rasTopCtr: UInt) = { 79 this.histPtr := histPtr 80 this.tageMeta := tageMeta 81 this.rasSp := rasSp 82 this.rasTopCtr := rasTopCtr 83 this.asUInt 84 } 85 def size = 0.U.asTypeOf(this).getWidth 86 def fromUInt(x: UInt) = x.asTypeOf(this) 87} 88 89class Predecode extends XSBundle { 90 val isFetchpcEqualFirstpc = Bool() 91 val mask = UInt((FetchWidth*2).W) 92 val pd = Vec(FetchWidth*2, (new PreDecodeInfo)) 93} 94 95class BranchUpdateInfo extends XSBundle { 96 // from backend 97 val pc = UInt(VAddrBits.W) 98 val pnpc = UInt(VAddrBits.W) 99 val target = UInt(VAddrBits.W) 100 val brTarget = UInt(VAddrBits.W) 101 val taken = Bool() 102 val fetchIdx = UInt(log2Up(FetchWidth*2).W) 103 val isMisPred = Bool() 104 val brTag = new BrqPtr 105 106 // frontend -> backend -> frontend 107 val pd = new PreDecodeInfo 108 val brInfo = new BranchInfo 109} 110 111// Dequeue DecodeWidth insts from Ibuffer 112class CtrlFlow extends XSBundle { 113 val instr = UInt(32.W) 114 val pc = UInt(VAddrBits.W) 115 val exceptionVec = Vec(16, Bool()) 116 val intrVec = Vec(12, Bool()) 117 val brUpdate = new BranchUpdateInfo 118 val crossPageIPFFix = Bool() 119} 120 121// Decode DecodeWidth insts at Decode Stage 122class CtrlSignals extends XSBundle { 123 val src1Type, src2Type, src3Type = SrcType() 124 val lsrc1, lsrc2, lsrc3 = UInt(5.W) 125 val ldest = UInt(5.W) 126 val fuType = FuType() 127 val fuOpType = FuOpType() 128 val rfWen = Bool() 129 val fpWen = Bool() 130 val isXSTrap = Bool() 131 val noSpecExec = Bool() // This inst can not be speculated 132 val isBlocked = Bool() // This inst requires pipeline to be blocked 133 val flushPipe = Bool() // This inst will flush all the pipe when commit, like exception but can commit 134 val isRVF = Bool() 135 val imm = UInt(XLEN.W) 136 val commitType = CommitType() 137} 138 139class CfCtrl extends XSBundle { 140 val cf = new CtrlFlow 141 val ctrl = new CtrlSignals 142 val brTag = new BrqPtr 143} 144 145// Load / Store Index 146// 147// When using unified lsroq, lsIdx serves as lsroqIdx, 148// while separated lq and sq is used, lsIdx consists of lqIdx, sqIdx and l/s type. 149// All lsroqIdx will be replaced by new lsIdx in the future. 150trait HasLSIdx { this: HasXSParameter => 151 152 // if(EnableUnifiedLSQ){ 153 // Unified LSQ 154 val lsroqIdx = UInt(LsroqIdxWidth.W) 155 // } else { 156 // Separate LSQ 157 val lqIdx = new LqPtr 158 val sqIdx = new SqPtr 159} 160 161class LSIdx extends XSBundle with HasLSIdx {} 162 163// CfCtrl -> MicroOp at Rename Stage 164class MicroOp extends CfCtrl with HasLSIdx { 165 val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W) 166 val src1State, src2State, src3State = SrcState() 167 val roqIdx = new RoqPtr 168 val diffTestDebugLrScValid = Bool() 169} 170 171class Redirect extends XSBundle { 172 val roqIdx = new RoqPtr 173 val isException = Bool() 174 val isMisPred = Bool() 175 val isReplay = Bool() 176 val isFlushPipe = Bool() 177 val pc = UInt(VAddrBits.W) 178 val target = UInt(VAddrBits.W) 179 val brTag = new BrqPtr 180} 181 182class Dp1ToDp2IO extends XSBundle { 183 val intDqToDp2 = Vec(dpParams.IntDqDeqWidth, DecoupledIO(new MicroOp)) 184 val fpDqToDp2 = Vec(dpParams.FpDqDeqWidth, DecoupledIO(new MicroOp)) 185 val lsDqToDp2 = Vec(dpParams.LsDqDeqWidth, DecoupledIO(new MicroOp)) 186} 187 188class ReplayPregReq extends XSBundle { 189 // NOTE: set isInt and isFp both to 'false' when invalid 190 val isInt = Bool() 191 val isFp = Bool() 192 val preg = UInt(PhyRegIdxWidth.W) 193} 194 195class DebugBundle extends XSBundle{ 196 val isMMIO = Bool() 197} 198 199class ExuInput extends XSBundle { 200 val uop = new MicroOp 201 val src1, src2, src3 = UInt(XLEN.W) 202} 203 204class ExuOutput extends XSBundle { 205 val uop = new MicroOp 206 val data = UInt(XLEN.W) 207 val fflags = new Fflags 208 val redirectValid = Bool() 209 val redirect = new Redirect 210 val brUpdate = new BranchUpdateInfo 211 val debug = new DebugBundle 212} 213 214class ExuIO extends XSBundle { 215 val in = Flipped(DecoupledIO(new ExuInput)) 216 val redirect = Flipped(ValidIO(new Redirect)) 217 val out = DecoupledIO(new ExuOutput) 218 // for csr 219 val exception = Flipped(ValidIO(new MicroOp)) 220 // for Lsu 221 val dmem = new SimpleBusUC 222 val mcommit = Input(UInt(3.W)) 223} 224 225class RoqCommit extends XSBundle { 226 val uop = new MicroOp 227 val isWalk = Bool() 228} 229 230class TlbFeedback extends XSBundle { 231 val roqIdx = new RoqPtr 232 val hit = Bool() 233} 234 235class FrontendToBackendIO extends XSBundle { 236 // to backend end 237 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 238 // from backend 239 val redirect = Flipped(ValidIO(new Redirect)) 240 val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 241 val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 242} 243 244class TlbCsrBundle extends XSBundle { 245 val satp = new Bundle { 246 val mode = UInt(4.W) // TODO: may change number to parameter 247 val asid = UInt(16.W) 248 val ppn = UInt(44.W) // just use PAddrBits - 3 - vpnnLen 249 } 250 val priv = new Bundle { 251 val mxr = Bool() 252 val sum = Bool() 253 val imode = UInt(2.W) 254 val dmode = UInt(2.W) 255 } 256 257 override def toPrintable: Printable = { 258 p"Satp mode:0x${Hexadecimal(satp.mode)} asid:0x${Hexadecimal(satp.asid)} ppn:0x${Hexadecimal(satp.ppn)} " + 259 p"Priv mxr:${priv.mxr} sum:${priv.sum} imode:${priv.imode} dmode:${priv.dmode}" 260 } 261} 262 263class SfenceBundle extends XSBundle { 264 val valid = Bool() 265 val bits = new Bundle { 266 val rs1 = Bool() 267 val rs2 = Bool() 268 val addr = UInt(VAddrBits.W) 269 } 270 271 override def toPrintable: Printable = { 272 p"valid:0x${Hexadecimal(valid)} rs1:${bits.rs1} rs2:${bits.rs2} addr:${Hexadecimal(bits.addr)}" 273 } 274} 275