xref: /XiangShan/src/main/scala/xiangshan/Bundle.scala (revision 694b0180118f79a40a1d26af0ea93ead726ab5e4)
1package xiangshan
2
3import chisel3._
4import chisel3.util._
5import xiangshan.backend.brq.BrqPtr
6import xiangshan.backend.fu.fpu.Fflags
7import xiangshan.backend.rename.FreeListPtr
8import xiangshan.backend.roq.RoqPtr
9import xiangshan.mem.{LqPtr, SqPtr}
10import xiangshan.frontend.PreDecodeInfo
11import xiangshan.frontend.HasBPUParameter
12import xiangshan.frontend.HasTageParameter
13
14// Fetch FetchWidth x 32-bit insts from Icache
15class FetchPacket extends XSBundle {
16  val instrs = Vec(PredictWidth, UInt(32.W))
17  val mask = UInt(PredictWidth.W)
18  // val pc = UInt(VAddrBits.W)
19  val pc = Vec(PredictWidth, UInt(VAddrBits.W))
20  val pnpc = Vec(PredictWidth, UInt(VAddrBits.W))
21  val brInfo = Vec(PredictWidth, new BranchInfo)
22  val pd = Vec(PredictWidth, new PreDecodeInfo)
23  val ipf = Bool()
24  val crossPageIPFFix = Bool()
25  val predTaken = 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+1).W)
202}
203
204class ExuOutput extends XSBundle {
205  val uop = new MicroOp
206  val data = UInt((XLEN+1).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 ExternalInterruptIO extends XSBundle {
215  val mtip = Input(Bool())
216  val msip = Input(Bool())
217  val meip = Input(Bool())
218}
219
220class CSRSpecialIO extends XSBundle {
221  val exception = Flipped(ValidIO(new MicroOp))
222  val isInterrupt = Input(Bool())
223  val memExceptionVAddr = Input(UInt(VAddrBits.W))
224  val trapTarget = Output(UInt(VAddrBits.W))
225  val externalInterrupt = new ExternalInterruptIO
226  val interrupt = Output(Bool())
227}
228
229//class ExuIO extends XSBundle {
230//  val in = Flipped(DecoupledIO(new ExuInput))
231//  val redirect = Flipped(ValidIO(new Redirect))
232//  val out = DecoupledIO(new ExuOutput)
233//  // for csr
234//  val csrOnly = new CSRSpecialIO
235//  val mcommit = Input(UInt(3.W))
236//}
237
238class RoqCommit extends XSBundle {
239  val uop = new MicroOp
240  val isWalk = Bool()
241}
242
243class TlbFeedback extends XSBundle {
244  val roqIdx = new RoqPtr
245  val hit = Bool()
246}
247
248class FrontendToBackendIO extends XSBundle {
249  // to backend end
250  val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow))
251  // from backend
252  val redirect = Flipped(ValidIO(new Redirect))
253  val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo))
254  val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo))
255  val sfence = Input(new SfenceBundle)
256  val tlbCsrIO = Input(new TlbCsrBundle)
257}
258
259class TlbCsrBundle extends XSBundle {
260  val satp = new Bundle {
261    val mode = UInt(4.W) // TODO: may change number to parameter
262    val asid = UInt(16.W)
263    val ppn  = UInt(44.W) // just use PAddrBits - 3 - vpnnLen
264  }
265  val priv = new Bundle {
266    val mxr = Bool()
267    val sum = Bool()
268    val imode = UInt(2.W)
269    val dmode = UInt(2.W)
270  }
271
272  override def toPrintable: Printable = {
273    p"Satp mode:0x${Hexadecimal(satp.mode)} asid:0x${Hexadecimal(satp.asid)} ppn:0x${Hexadecimal(satp.ppn)} " +
274    p"Priv mxr:${priv.mxr} sum:${priv.sum} imode:${priv.imode} dmode:${priv.dmode}"
275  }
276}
277
278class SfenceBundle extends XSBundle {
279  val valid = Bool()
280  val bits = new Bundle {
281    val rs1 = Bool()
282    val rs2 = Bool()
283    val addr = UInt(VAddrBits.W)
284  }
285
286  override def toPrintable: Printable = {
287    p"valid:0x${Hexadecimal(valid)} rs1:${bits.rs1} rs2:${bits.rs2} addr:${Hexadecimal(bits.addr)}"
288  }
289}
290