xref: /XiangShan/src/main/scala/xiangshan/Bundle.scala (revision e983e862d126810434a87857a9130847042a9cc3)
1package xiangshan
2
3import chisel3._
4import chisel3.util._
5import bus.simplebus._
6import xiangshan.backend.brq.BrqPtr
7import xiangshan.backend.rename.FreeListPtr
8
9// Fetch FetchWidth x 32-bit insts from Icache
10class FetchPacket extends XSBundle {
11  val instrs = Vec(FetchWidth, UInt(32.W))
12  val mask = UInt((FetchWidth*2).W)
13  val pc = UInt(VAddrBits.W) // the pc of first inst in the fetch group
14  val pnpc = Vec(FetchWidth, UInt(VAddrBits.W))
15}
16
17// Branch prediction result from BPU Stage1 & 3
18class BranchPrediction extends XSBundle {
19  val redirect = Bool()
20
21  // mask off all the instrs after the first redirect instr
22  val instrValid = Vec(FetchWidth, Bool())
23  // target and BTBtype of the first redirect instr in a fetch package
24  val target = UInt(VAddrBits.W)
25  val _type = UInt(2.W)
26
27  // save these info in brq!
28  // global history of each valid(or uncancelled) instruction, excluding branch's own prediction result
29  val hist = Vec(FetchWidth, UInt(HistoryLength.W))
30  // ras checkpoint, only used in Stage3
31  val rasSp = Vec(FetchWidth, UInt(log2Up(RasSize).W))
32  val rasTopCtr = Vec(FetchWidth, UInt(8.W))
33}
34
35// Save predecode info in icache
36class Predecode extends XSBundle {
37  val mask = UInt(FetchWidth.W)
38  val fuTypes = Vec(FetchWidth, FuType())
39  val fuOpTypes = Vec(FetchWidth, FuOpType())
40}
41
42// Dequeue DecodeWidth insts from Ibuffer
43class CtrlFlow extends XSBundle {
44  val instr = UInt(32.W)
45  val pc = UInt(VAddrBits.W)
46  val pnpc = UInt(VAddrBits.W)
47  val exceptionVec = Vec(16, Bool())
48  val intrVec = Vec(12, Bool())
49  val isRVC = Bool()
50  val isBr = Bool()
51}
52
53// Decode DecodeWidth insts at Decode Stage
54class CtrlSignals extends XSBundle {
55  val src1Type, src2Type, src3Type = SrcType()
56  val lsrc1, lsrc2, lsrc3 = UInt(5.W)
57  val ldest = UInt(5.W)
58  val fuType = FuType()
59  val fuOpType = FuOpType()
60  val rfWen = Bool()
61  val fpWen = Bool()
62  val isXSTrap = Bool()
63  val noSpecExec = Bool()  // This inst can not be speculated
64  val isBlocked  = Bool()  // This inst requires pipeline to be blocked
65  val isRVF = Bool()
66  val imm = UInt(XLEN.W)
67}
68
69class CfCtrl extends XSBundle {
70  val cf = new CtrlFlow
71  val ctrl = new CtrlSignals
72  val brTag = new BrqPtr
73}
74
75// CfCtrl -> MicroOp at Rename Stage
76class MicroOp extends CfCtrl {
77
78  val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W)
79  val src1State, src2State, src3State = SrcState()
80  val freelistAllocPtr = new FreeListPtr
81  val roqIdx = UInt(RoqIdxWidth.W)
82}
83
84class Redirect extends XSBundle {
85  val pc = UInt(VAddrBits.W) // wrongly predicted pc
86  val target = UInt(VAddrBits.W)
87  val brTarget = UInt(VAddrBits.W)
88  val brTag = new BrqPtr
89  val _type = UInt(2.W)
90  val isCall = Bool()
91  val taken = Bool()
92  val hist = UInt(HistoryLength.W)
93  val isException = Bool()
94  val roqIdx = UInt(RoqIdxWidth.W)
95  val freelistAllocPtr = new FreeListPtr
96}
97
98class Dp1ToDp2IO extends XSBundle {
99  val intDqToDp2 = Vec(IntDqDeqWidth, DecoupledIO(new MicroOp))
100  val fpDqToDp2 = Vec(FpDqDeqWidth, DecoupledIO(new MicroOp))
101  val lsDqToDp2 = Vec(LsDqDeqWidth, DecoupledIO(new MicroOp))
102}
103
104class DebugBundle extends XSBundle{
105  val isMMIO = Bool()
106}
107
108class ExuInput extends XSBundle {
109  val uop = new MicroOp
110  val src1, src2, src3 = UInt(XLEN.W)
111}
112
113class ExuOutput extends XSBundle {
114  val uop = new MicroOp
115  val data = UInt(XLEN.W)
116  val redirectValid = Bool()
117  val redirect = new Redirect
118  val debug = new DebugBundle
119}
120
121class ExuIO extends XSBundle {
122  val in = Flipped(DecoupledIO(new ExuInput))
123  val redirect = Flipped(ValidIO(new Redirect))
124  val out = DecoupledIO(new ExuOutput)
125
126  // for Lsu
127  val dmem = new SimpleBusUC
128  val scommit = Input(UInt(3.W))
129}
130
131class RoqCommit extends XSBundle {
132  val uop = new MicroOp
133  val isWalk = Bool()
134}
135
136class FrontendToBackendIO extends XSBundle {
137  // to backend end
138  val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow))
139  // from backend
140  val redirect = Flipped(ValidIO(new Redirect))
141  val commits = Vec(CommitWidth, Flipped(ValidIO(new RoqCommit))) // update branch pred
142}
143