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