|
1 | | -package treecorel2 |
2 | | - |
3 | | -import chisel3._ |
4 | | -import chisel3.util._ |
5 | | - |
6 | | -import difftest._ |
7 | | - |
8 | | -import treecorel2.common.ConstVal |
9 | | - |
10 | | -class WBU extends Module { |
11 | | - val io = IO(new Bundle { |
12 | | - val globalEn = Input(Bool()) |
13 | | - val socEn = Input(Bool()) |
14 | | - val mem2wb = Flipped(new MEM2WBIO) |
15 | | - val wbdata = new WBDATAIO |
16 | | - val gpr = Input(Vec(32, UInt(64.W))) |
17 | | - val instComm = Flipped(new DiffInstrCommitIO) |
18 | | - val archIntRegState = Flipped(new DiffArchIntRegStateIO) |
19 | | - val csrState = Flipped(new DiffCSRStateIO) |
20 | | - val trapEvt = Flipped(new DiffTrapEventIO) |
21 | | - val archFpRegState = Flipped(new DiffArchFpRegStateIO) |
22 | | - val archEvt = Flipped(new DiffArchEventIO) |
23 | | - }) |
24 | | - |
25 | | - protected val wbReg = RegEnable(io.mem2wb, WireInit(0.U.asTypeOf(new MEM2WBIO())), io.globalEn) |
26 | | - protected val valid = wbReg.valid |
27 | | - protected val inst = wbReg.inst |
28 | | - protected val pc = wbReg.pc |
29 | | - protected val isa = wbReg.isa |
30 | | - protected val src1 = wbReg.src1 |
31 | | - protected val src2 = wbReg.src2 |
32 | | - protected val imm = wbReg.imm |
33 | | - protected val wen = wbReg.wen |
34 | | - protected val wdest = wbReg.wdest |
35 | | - protected val aluRes = wbReg.aluRes |
36 | | - protected val branch = wbReg.branch |
37 | | - protected val tgt = wbReg.tgt |
38 | | - protected val link = wbReg.link |
39 | | - protected val auipc = wbReg.auipc |
40 | | - protected val loadData = wbReg.loadData |
41 | | - protected val csrData = wbReg.csrData |
42 | | - protected val cvalid = wbReg.cvalid |
43 | | - protected val timeIntrEn = wbReg.timeIntrEn |
44 | | - protected val ecallEn = wbReg.ecallEn |
45 | | - protected val csr = wbReg.csr |
46 | | - |
47 | | - protected val cycleCnt = RegInit(0.U(64.W)) |
48 | | - protected val instrCnt = RegInit(0.U(64.W)) |
49 | | - cycleCnt := cycleCnt + 1.U |
50 | | - when(io.globalEn && valid) { instrCnt := instrCnt + 1.U } |
51 | | - |
52 | | - protected val wbdata = aluRes | link | auipc | loadData | csrData |
53 | | - |
54 | | - io.wbdata.wen := valid && wen |
55 | | - io.wbdata.wdest := wdest |
56 | | - io.wbdata.data := wbdata |
57 | | - |
58 | | - protected val printVis = inst(6, 0) === "h7b".U(7.W) |
59 | | - protected val haltVis = inst(6, 0) === "h6b".U(7.W) |
60 | | - |
61 | | - when(~io.socEn) { |
62 | | - when(io.globalEn && valid && printVis) { |
63 | | - printf("%c", io.gpr(10)) |
64 | | - } |
65 | | - } |
66 | | - |
67 | | - // for difftest commit |
68 | | - protected val mmioEn = cvalid |
69 | | - protected val csrVis = isa.CSRRW || isa.CSRRS || isa.CSRRC || isa.CSRRWI || isa.CSRRSI || isa.CSRRCI |
70 | | - protected val mcycleVis = csrVis && (inst(31, 20) === ConstVal.mcycleAddr) |
71 | | - protected val mipVis = csrVis && (inst(31, 20) === ConstVal.mipAddr) |
72 | | - protected val timeIntrEnReg = RegEnable(timeIntrEn, false.B, io.globalEn) |
73 | | - protected val diffValid = io.globalEn && (RegEnable(valid, false.B, io.globalEn) || timeIntrEnReg) |
74 | | - |
75 | | - io.instComm.clock := clock |
76 | | - io.instComm.coreid := 0.U |
77 | | - io.instComm.index := 0.U |
78 | | - io.instComm.valid := diffValid && ~timeIntrEnReg |
79 | | - io.instComm.pc := RegEnable(pc, 0.U, io.globalEn) |
80 | | - io.instComm.instr := RegEnable(inst, 0.U, io.globalEn) |
81 | | - io.instComm.special := 0.U |
82 | | - io.instComm.skip := diffValid && RegEnable(printVis || mcycleVis || mmioEn || mipVis, false.B, io.globalEn) |
83 | | - io.instComm.isRVC := false.B |
84 | | - io.instComm.scFailed := false.B |
85 | | - io.instComm.wen := RegEnable(wen, false.B, io.globalEn) |
86 | | - io.instComm.wdata := RegEnable(wbdata, 0.U, io.globalEn) |
87 | | - io.instComm.wdest := RegEnable(wdest, 0.U, io.globalEn) |
88 | | - |
89 | | - io.archIntRegState.clock := clock |
90 | | - io.archIntRegState.coreid := 0.U |
91 | | - io.archIntRegState.gpr := io.gpr |
92 | | - |
93 | | - io.csrState.clock := clock |
94 | | - io.csrState.coreid := 0.U |
95 | | - io.csrState.mstatus := csr.mstatus |
96 | | - io.csrState.mcause := csr.mcause |
97 | | - io.csrState.mepc := csr.mepc |
98 | | - io.csrState.sstatus := csr.mstatus & "h8000_0003_000d_e122".U |
99 | | - io.csrState.scause := 0.U |
100 | | - io.csrState.sepc := 0.U |
101 | | - io.csrState.satp := 0.U |
102 | | - io.csrState.mip := 0.U |
103 | | - io.csrState.mie := csr.mie |
104 | | - io.csrState.mscratch := csr.mscratch |
105 | | - io.csrState.sscratch := 0.U |
106 | | - io.csrState.mideleg := 0.U |
107 | | - io.csrState.medeleg := csr.medeleg |
108 | | - io.csrState.mtval := 0.U |
109 | | - io.csrState.stval := 0.U |
110 | | - io.csrState.mtvec := csr.mtvec |
111 | | - io.csrState.stvec := 0.U |
112 | | - io.csrState.priviledgeMode := 3.U |
113 | | - |
114 | | - io.archEvt.clock := clock |
115 | | - io.archEvt.coreid := 0.U |
116 | | - io.archEvt.intrNO := Mux(diffValid && timeIntrEnReg, 7.U, 0.U) |
117 | | - io.archEvt.cause := 0.U |
118 | | - io.archEvt.exceptionPC := RegEnable(pc, 0.U, io.globalEn) |
119 | | - io.archEvt.exceptionInst := RegEnable(inst, 0.U, io.globalEn) |
120 | | - |
121 | | - io.trapEvt.clock := clock |
122 | | - io.trapEvt.coreid := 0.U |
123 | | - io.trapEvt.valid := diffValid && RegEnable(haltVis, false.B, io.globalEn) |
124 | | - io.trapEvt.code := io.gpr(10)(7, 0) |
125 | | - io.trapEvt.pc := RegEnable(pc, 0.U, io.globalEn) |
126 | | - io.trapEvt.cycleCnt := cycleCnt |
127 | | - io.trapEvt.instrCnt := instrCnt |
128 | | - |
129 | | - io.archFpRegState.clock := clock |
130 | | - io.archFpRegState.coreid := 0.U |
131 | | - io.archFpRegState.fpr := RegInit(VecInit(Seq.fill(32)(0.U(64.W)))) |
132 | | -} |
| 1 | +package treecorel2 |
| 2 | + |
| 3 | +import chisel3._ |
| 4 | +import chisel3.util._ |
| 5 | + |
| 6 | +import difftest._ |
| 7 | + |
| 8 | +import treecorel2.common.ConstVal |
| 9 | +import treecorel2.common.InstConfig |
| 10 | + |
| 11 | +class WBU extends Module with InstConfig { |
| 12 | + val io = IO(new Bundle { |
| 13 | + val globalEn = Input(Bool()) |
| 14 | + val socEn = Input(Bool()) |
| 15 | + val mem2wb = Flipped(new MEM2WBIO) |
| 16 | + val wbdata = new WBDATAIO |
| 17 | + val gpr = Input(Vec(32, UInt(64.W))) |
| 18 | + }) |
| 19 | + |
| 20 | + protected val wbReg = RegEnable(io.mem2wb, WireInit(0.U.asTypeOf(new MEM2WBIO())), io.globalEn) |
| 21 | + protected val valid = wbReg.valid |
| 22 | + protected val inst = wbReg.inst |
| 23 | + protected val pc = wbReg.pc |
| 24 | + protected val isa = wbReg.isa |
| 25 | + protected val src1 = wbReg.src1 |
| 26 | + protected val src2 = wbReg.src2 |
| 27 | + protected val imm = wbReg.imm |
| 28 | + protected val wen = wbReg.wen |
| 29 | + protected val wdest = wbReg.wdest |
| 30 | + protected val aluRes = wbReg.aluRes |
| 31 | + protected val branch = wbReg.branch |
| 32 | + protected val tgt = wbReg.tgt |
| 33 | + protected val link = wbReg.link |
| 34 | + protected val auipc = wbReg.auipc |
| 35 | + protected val loadData = wbReg.loadData |
| 36 | + protected val csrData = wbReg.csrData |
| 37 | + protected val cvalid = wbReg.cvalid |
| 38 | + protected val timeIntrEn = wbReg.timeIntrEn |
| 39 | + protected val ecallEn = wbReg.ecallEn |
| 40 | + protected val csr = wbReg.csr |
| 41 | + |
| 42 | + protected val cycleCnt = RegInit(0.U(64.W)) |
| 43 | + protected val instrCnt = RegInit(0.U(64.W)) |
| 44 | + cycleCnt := cycleCnt + 1.U |
| 45 | + when(io.globalEn && valid) { instrCnt := instrCnt + 1.U } |
| 46 | + |
| 47 | + protected val wbdata = aluRes | link | auipc | loadData | csrData |
| 48 | + |
| 49 | + io.wbdata.wen := valid && wen |
| 50 | + io.wbdata.wdest := wdest |
| 51 | + io.wbdata.data := wbdata |
| 52 | + |
| 53 | + protected val printVis = inst(6, 0) === "h7b".U(7.W) |
| 54 | + protected val haltVis = inst(6, 0) === "h6b".U(7.W) |
| 55 | + |
| 56 | + when(~io.socEn) { |
| 57 | + when(io.globalEn && valid && printVis) { |
| 58 | + printf("%c", io.gpr(10)) |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + // for difftest commit |
| 63 | + protected val mmioEn = cvalid |
| 64 | + protected val csrVis = isa.CSRRW || isa.CSRRS || isa.CSRRC || isa.CSRRWI || isa.CSRRSI || isa.CSRRCI |
| 65 | + protected val mcycleVis = csrVis && (inst(31, 20) === ConstVal.mcycleAddr) |
| 66 | + protected val mipVis = csrVis && (inst(31, 20) === ConstVal.mipAddr) |
| 67 | + protected val timeIntrEnReg = RegEnable(timeIntrEn, false.B, io.globalEn) |
| 68 | + protected val diffValid = io.globalEn && (RegEnable(valid, false.B, io.globalEn) || timeIntrEnReg) |
| 69 | + |
| 70 | + if (!SoCEna) { |
| 71 | + val instComm = Module(new DifftestInstrCommit) |
| 72 | + val archIntRegState = Module(new DifftestArchIntRegState) |
| 73 | + val csrState = Module(new DifftestCSRState) |
| 74 | + val trapEvt = Module(new DifftestTrapEvent) |
| 75 | + val archFpRegState = Module(new DifftestArchFpRegState) |
| 76 | + val archEvt = Module(new DifftestArchEvent) |
| 77 | + |
| 78 | + instComm.io.clock := clock |
| 79 | + instComm.io.coreid := 0.U |
| 80 | + instComm.io.index := 0.U |
| 81 | + instComm.io.valid := diffValid && ~timeIntrEnReg |
| 82 | + instComm.io.pc := RegEnable(pc, 0.U, io.globalEn) |
| 83 | + instComm.io.instr := RegEnable(inst, 0.U, io.globalEn) |
| 84 | + instComm.io.special := 0.U |
| 85 | + instComm.io.skip := diffValid && RegEnable(printVis || mcycleVis || mmioEn || mipVis, false.B, io.globalEn) |
| 86 | + instComm.io.isRVC := false.B |
| 87 | + instComm.io.scFailed := false.B |
| 88 | + instComm.io.wen := RegEnable(wen, false.B, io.globalEn) |
| 89 | + instComm.io.wdata := RegEnable(wbdata, 0.U, io.globalEn) |
| 90 | + instComm.io.wdest := RegEnable(wdest, 0.U, io.globalEn) |
| 91 | + |
| 92 | + archIntRegState.io.clock := clock |
| 93 | + archIntRegState.io.coreid := 0.U |
| 94 | + archIntRegState.io.gpr := io.gpr |
| 95 | + |
| 96 | + csrState.io.clock := clock |
| 97 | + csrState.io.coreid := 0.U |
| 98 | + csrState.io.mstatus := csr.mstatus |
| 99 | + csrState.io.mcause := csr.mcause |
| 100 | + csrState.io.mepc := csr.mepc |
| 101 | + csrState.io.sstatus := csr.mstatus & "h8000_0003_000d_e122".U |
| 102 | + csrState.io.scause := 0.U |
| 103 | + csrState.io.sepc := 0.U |
| 104 | + csrState.io.satp := 0.U |
| 105 | + csrState.io.mip := 0.U |
| 106 | + csrState.io.mie := csr.mie |
| 107 | + csrState.io.mscratch := csr.mscratch |
| 108 | + csrState.io.sscratch := 0.U |
| 109 | + csrState.io.mideleg := 0.U |
| 110 | + csrState.io.medeleg := csr.medeleg |
| 111 | + csrState.io.mtval := 0.U |
| 112 | + csrState.io.stval := 0.U |
| 113 | + csrState.io.mtvec := csr.mtvec |
| 114 | + csrState.io.stvec := 0.U |
| 115 | + csrState.io.priviledgeMode := 3.U |
| 116 | + |
| 117 | + archEvt.io.clock := clock |
| 118 | + archEvt.io.coreid := 0.U |
| 119 | + archEvt.io.intrNO := Mux(diffValid && timeIntrEnReg, 7.U, 0.U) |
| 120 | + archEvt.io.cause := 0.U |
| 121 | + archEvt.io.exceptionPC := RegEnable(pc, 0.U, io.globalEn) |
| 122 | + archEvt.io.exceptionInst := RegEnable(inst, 0.U, io.globalEn) |
| 123 | + |
| 124 | + trapEvt.io.clock := clock |
| 125 | + trapEvt.io.coreid := 0.U |
| 126 | + trapEvt.io.valid := diffValid && RegEnable(haltVis, false.B, io.globalEn) |
| 127 | + trapEvt.io.code := io.gpr(10)(7, 0) |
| 128 | + trapEvt.io.pc := RegEnable(pc, 0.U, io.globalEn) |
| 129 | + trapEvt.io.cycleCnt := cycleCnt |
| 130 | + trapEvt.io.instrCnt := instrCnt |
| 131 | + |
| 132 | + archFpRegState.io.clock := clock |
| 133 | + archFpRegState.io.coreid := 0.U |
| 134 | + archFpRegState.io.fpr := RegInit(VecInit(Seq.fill(32)(0.U(64.W)))) |
| 135 | + } |
| 136 | +} |
0 commit comments