Skip to content

Commit 6188e4d

Browse files
committed
Fix reset and the initial instruction for the ROM
1 parent b4230a0 commit 6188e4d

7 files changed

Lines changed: 69 additions & 132 deletions

File tree

doc/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ Some notes collected along exploring RISC-V.
1313
* 4 stages: standard without the WB
1414
* 5 stages: mostly useless WB (just a Mux)
1515

16+
## Reset
17+
18+
ASIC memories with an input register have a random address value in the first clock cycle.
19+
Therefore, the first instruction shall not be executed.
20+
The instruction memory (SPM or cache) shall assert stall on this initial cycle, and Wildcat will substitute the instruction with a NOP.
21+
Stalling keeps the PC constant, therefore we can reset it to 0 (and not -4).
22+
23+
Caches on a miss assert stall as well.
24+
1625
## Notes, Ideas
1726

1827
* LUI could be recoded as ADDI with R0

doc/TODO.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
* [ ] Write documentation
44
* [ ] Change memory interface to `PipeCon`
55
* [ ] Have a better drawing of `PipeCon` (in soc-comm)
6-
* [ ] why does // val pcReg = RegInit(-4.S(32.W).asUInt) result in failing tests?
7-
- [ ] Do not execute the first instruction from on-chip memory
8-
- [ ] but start PC with -4
9-
- [ ] remove initialization of the address register from the instruction ROM
6+
* [x] why does // val pcReg = RegInit(-4.S(32.W).asUInt) result in failing tests?
7+
- [x] Do not execute the first instruction from on-chip memory
8+
- [x] but start PC with -4
9+
- [x] remove initialization of the address register from the instruction ROM
1010
* [ ] Something is fishy with testing, as SingleCycle works (even without branch)
1111
* [ ] Single cycle is not finished - tests are failing, disabled
12-
* [ ] Two tests fail with co-simulation when adding stall to fetch (the toggle)
12+
* [x] Two tests fail with co-simulation when adding stall to fetch (the toggle)
1313
* [ ] Better names for signals (e.g., for those with feedback, e.g., RF write)
14-
* [ ] width.s should not fail in the ISA simulator
14+
* [ ] width.s and string.s should not fail in the ISA simulator
1515
- [ ] string should work as well, do we need a linker script?
1616
- [ ] Work on failing simple tests (Simulator and Wildcat)
1717
* [ ] Start collecting information on other core interfaces (in my paper)
1818
* [ ] Make it super easy to see Wildcat in action, like in DrakRISCV
1919
* [ ] UART
2020
* [ ] Add caches
21+
* [ ] I do not have a real CoSim test for the pipeline
22+
* [ ] There are still three failing test with CA cosimlation
2123
* [ ] Have performance (PPA) as GitHub CI action
2224
- [ ] with a more useful external memory interface - instructions and data
2325
* [ ] Forwarding from ALU/memory to address computation is missing (missing a test?)

src/main/scala/wildcat/isasim/SimRV.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ class SimRV(mem: Array[Int], start: Int, stop: Int) {
194194
def ecall(): Int = {
195195
funct3 match {
196196
case ESYS => {
197-
println("ecall")
198197
run = false
199198
return 0
200199
}

src/main/scala/wildcat/pipeline/InstructionROM.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import chisel3._
88
class InstructionROM(code: Array[Int]) extends Module {
99
val io = IO(Flipped(new InstrIO()))
1010

11-
// TODO: this should not be reset, as ASIC memories have no reset
12-
// val addrReg = Reg(UInt(32.W))
13-
val addrReg = RegInit(0.U(32.W))
11+
// No reset, as ASIC memories have no reset
12+
val addrReg = Reg(UInt(32.W))
1413
addrReg := io.address
1514
val instructions = VecInit(code.toIndexedSeq.map(_.S(32.W).asUInt))
1615
io.data := instructions(addrReg(31, 2))
17-
// for checking two failing tests
16+
// simulating cache misses
1817
val toggle = RegInit(false.B)
1918
toggle := !toggle
20-
io.stall := false.B
19+
// first instruction shall not be executed (random address register)
20+
val firstReg = RegInit(true.B)
21+
firstReg := false.B
22+
io.stall := firstReg || false.B // add toggle
2123
}

src/main/scala/wildcat/pipeline/ThreeCats.scala

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,16 @@ class ThreeCats() extends Wildcat() {
3535
}
3636
val exFwdReg = RegInit(0.U.asTypeOf(exFwd))
3737

38-
// PC generation
39-
// the following should be correct, but 2 tests fail
40-
// TODO: don't execute first instruction coming from memory
41-
// val pcReg = RegInit(-4.S(32.W).asUInt)
42-
val pcReg = RegInit(0.S(32.W).asUInt)
38+
// PC generation, first (invalid) instruction will stall, so init with 0 is OK
39+
val pcReg = RegInit(0.U(32.W))
4340
val pcNext = WireDefault(Mux(doBranch, branchTarget, pcReg + 4.U))
4441
pcReg := pcNext
4542
io.imem.address := pcNext
4643

4744
// Fetch
4845
val instr = WireDefault(io.imem.data)
49-
val firstClocReg = RegInit(false.B)
50-
firstClocReg := true.B
51-
when(firstClocReg) {
52-
// instr := 0x00000013.U
53-
}
5446
when (io.imem.stall) {
55-
instr := 0x00000013.U
47+
instr := 0x00000033.U
5648
pcNext := pcReg
5749
}
5850

src/test/scala/wildcat/CACoSimTest.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import wildcat.isasim.SimRV
1212
class CACoSimTest extends AnyFlatSpec with ChiselScalatestTester {
1313

1414
val files = Util.getSimpleTests("risc-v-lab/tests/simple")
15-
// val failed = List("string.bin", "width.bin")
16-
val failed = List("shift2.bin", "shift.bin", "recursive.bin", "branchcnt.bin", "branchmany.bin", "branchtrap.bin", "loop.bin","string.bin", "width.bin")
17-
15+
val failed = List("string.bin", "recursive.bin", "loop.bin")
1816

1917
for (f <- files) {
2018
s"Simulation: CA co-simulatoin (simple) $f" should "pass" in {
@@ -24,13 +22,17 @@ class CACoSimTest extends AnyFlatSpec with ChiselScalatestTester {
2422
succeed
2523
} else {
2624
val sim = SimRV.runSimRV(f.toString())
27-
test(new WildcatTestTop(f.getAbsolutePath)) {
25+
test(new WildcatTestTop(f.getAbsolutePath)).withAnnotations(Seq(WriteVcdAnnotation)) {
2826
d => {
29-
d.clock.step(100)
27+
for (i <- 0 until 100) {
28+
if (!d.io.stop.peekBoolean()) {
29+
d.clock.step()
30+
}
31+
}
3032
for (i <- 0 until 32) {
3133
val r = d.io.regFile(i).peekInt().toInt
3234
val e = sim.reg(i)
33-
assert(r == e, f"reg($i) = $r, expected $e")
35+
assert(r == e, f"reg($i) = 0x${r.toHexString}, expected 0x${e.toHexString} at ${sim.pc % 4} in $f")
3436
}
3537
}
3638
}

wildcat.gtkw

Lines changed: 34 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,52 @@
11
[*]
22
[*] GTKWave Analyzer v3.4.0 (w)1999-2022 BSI
3-
[*] Wed Sep 18 21:21:41 2024
3+
[*] Tue Aug 26 09:30:05 2025
44
[*]
5-
[dumpfile] "/Users/martin/source/wildcat/test_run_dir/Single_asmjals_should_pass/ThreeTestTop.vcd"
6-
[dumpfile_mtime] "Wed Sep 18 21:11:24 2024"
7-
[dumpfile_size] 40876
5+
[dumpfile] "/Users/martin/source/wildcat/test_run_dir/Simulation_CA_cosimulatoin_simple_riscvlabtestssimpleboolbin_should_pass/WildcatTestTop.vcd"
6+
[dumpfile_mtime] "Tue Aug 26 09:29:09 2025"
7+
[dumpfile_size] 55572
88
[savefile] "/Users/martin/source/wildcat/wildcat.gtkw"
99
[timestart] 0
10-
[size] 1576 948
10+
[size] 1336 600
1111
[pos] -1 -1
12-
*-4.372963 36 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
13-
[treeopen] ThreeTestTop.
14-
[treeopen] ThreeTestTop.three.
15-
[treeopen] ThreeTestTop.three.dmem.
16-
[treeopen] ThreeTestTop.three.dmem.mem.
17-
[sst_width] 253
12+
*-4.905419 15 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
13+
[treeopen] WildcatTestTop.
14+
[treeopen] WildcatTestTop.cpuTop.
15+
[sst_width] 255
1816
[signals_width] 394
1917
[sst_expanded] 1
2018
[sst_vpaned_height] 158
2119
@28
22-
ThreeTestTop.three.cpu.clock
23-
ThreeTestTop.three.cpu.reset
20+
WildcatTestTop.clock
21+
WildcatTestTop.reset
2422
@22
25-
ThreeTestTop.three.cpu.pcNext[31:0]
26-
ThreeTestTop.three.cpu.pcReg[31:0]
27-
ThreeTestTop.three.cpu.instrReg[31:0]
28-
@200
29-
-
30-
@22
31-
ThreeTestTop.three.cpu.decExReg__rs1[4:0]
32-
ThreeTestTop.three.cpu.decExReg__rs2[4:0]
33-
ThreeTestTop.three.cpu.decExReg__rd[4:0]
23+
WildcatTestTop.io_regFile_0[31:0]
24+
WildcatTestTop.io_regFile_1[31:0]
25+
WildcatTestTop.io_regFile_2[31:0]
26+
WildcatTestTop.io_regFile_3[31:0]
27+
WildcatTestTop.io_regFile_4[31:0]
28+
WildcatTestTop.io_regFile_5[31:0]
29+
WildcatTestTop.io_regFile_6[31:0]
30+
WildcatTestTop.io_regFile_7[31:0]
31+
WildcatTestTop.io_regFile_8[31:0]
32+
WildcatTestTop.io_regFile_9[31:0]
33+
WildcatTestTop.io_regFile_10[31:0]
34+
WildcatTestTop.cpuTop.cpu.pcReg[31:0]
35+
WildcatTestTop.cpuTop.cpu.pcNext[31:0]
36+
WildcatTestTop.cpuTop.cpu.instr[31:0]
37+
WildcatTestTop.cpuTop.cpu.instrReg[31:0]
3438
@28
35-
ThreeTestTop.three.cpu.decExReg__valid
36-
ThreeTestTop.three.cpu.decExReg__decOut_isJal
37-
ThreeTestTop.three.cpu.decExReg__decOut_isJalr
38-
@22
39-
ThreeTestTop.three.cpu.decExReg__rs1Val[31:0]
40-
ThreeTestTop.three.cpu.decExReg__rs2Val[31:0]
41-
ThreeTestTop.three.cpu.debugRegs_1[31:0]
42-
ThreeTestTop.three.cpu.debugRegs_2[31:0]
43-
ThreeTestTop.three.cpu.debugRegs_3[31:0]
44-
ThreeTestTop.three.cpu.debugRegs_4[31:0]
45-
ThreeTestTop.three.cpu.debugRegs_5[31:0]
46-
ThreeTestTop.three.cpu.debugRegs_6[31:0]
47-
ThreeTestTop.three.cpu.debugRegs_7[31:0]
48-
@200
49-
-
50-
@c00023
51-
ThreeTestTop.three.cpu.res[31:0]
52-
@29
53-
(0)ThreeTestTop.three.cpu.res[31:0]
54-
(1)ThreeTestTop.three.cpu.res[31:0]
55-
(2)ThreeTestTop.three.cpu.res[31:0]
56-
(3)ThreeTestTop.three.cpu.res[31:0]
57-
(4)ThreeTestTop.three.cpu.res[31:0]
58-
(5)ThreeTestTop.three.cpu.res[31:0]
59-
(6)ThreeTestTop.three.cpu.res[31:0]
60-
(7)ThreeTestTop.three.cpu.res[31:0]
61-
(8)ThreeTestTop.three.cpu.res[31:0]
62-
(9)ThreeTestTop.three.cpu.res[31:0]
63-
(10)ThreeTestTop.three.cpu.res[31:0]
64-
(11)ThreeTestTop.three.cpu.res[31:0]
65-
(12)ThreeTestTop.three.cpu.res[31:0]
66-
(13)ThreeTestTop.three.cpu.res[31:0]
67-
(14)ThreeTestTop.three.cpu.res[31:0]
68-
(15)ThreeTestTop.three.cpu.res[31:0]
69-
(16)ThreeTestTop.three.cpu.res[31:0]
70-
(17)ThreeTestTop.three.cpu.res[31:0]
71-
(18)ThreeTestTop.three.cpu.res[31:0]
72-
(19)ThreeTestTop.three.cpu.res[31:0]
73-
(20)ThreeTestTop.three.cpu.res[31:0]
74-
(21)ThreeTestTop.three.cpu.res[31:0]
75-
(22)ThreeTestTop.three.cpu.res[31:0]
76-
(23)ThreeTestTop.three.cpu.res[31:0]
77-
(24)ThreeTestTop.three.cpu.res[31:0]
78-
(25)ThreeTestTop.three.cpu.res[31:0]
79-
(26)ThreeTestTop.three.cpu.res[31:0]
80-
(27)ThreeTestTop.three.cpu.res[31:0]
81-
(28)ThreeTestTop.three.cpu.res[31:0]
82-
(29)ThreeTestTop.three.cpu.res[31:0]
83-
(30)ThreeTestTop.three.cpu.res[31:0]
84-
(31)ThreeTestTop.three.cpu.res[31:0]
85-
@1401201
86-
-group_end
39+
WildcatTestTop.cpuTop.cpu.io_imem_stall
8740
@22
88-
ThreeTestTop.three.cpu.wbData[31:0]
89-
ThreeTestTop.three.cpu.wbDest[4:0]
90-
@28
91-
ThreeTestTop.three.cpu.wrEna
41+
WildcatTestTop.cpuTop.imem.addrReg[31:0]
42+
WildcatTestTop.cpuTop.imem.instructions_0[31:0]
43+
WildcatTestTop.cpuTop.imem.instructions_1[31:0]
44+
WildcatTestTop.cpuTop.imem.instructions_2[31:0]
45+
WildcatTestTop.cpuTop.imem.instructions_3[31:0]
46+
WildcatTestTop.cpuTop.imem.instructions_4[31:0]
47+
WildcatTestTop.cpuTop.imem.instructions_5[31:0]
9248
@200
9349
-
9450
-
95-
@22
96-
ThreeTestTop.three.cpu.debugRegs_8[31:0]
97-
ThreeTestTop.three.cpu.debugRegs_9[31:0]
98-
ThreeTestTop.three.cpu.debugRegs_10[31:0]
99-
ThreeTestTop.three.cpu.debugRegs_11[31:0]
100-
ThreeTestTop.three.cpu.debugRegs_12[31:0]
101-
ThreeTestTop.three.cpu.debugRegs_13[31:0]
102-
ThreeTestTop.three.cpu.debugRegs_14[31:0]
103-
ThreeTestTop.three.cpu.debugRegs_15[31:0]
104-
ThreeTestTop.three.cpu.debugRegs_16[31:0]
105-
ThreeTestTop.three.cpu.debugRegs_17[31:0]
106-
ThreeTestTop.three.cpu.debugRegs_18[31:0]
107-
ThreeTestTop.three.cpu.debugRegs_19[31:0]
108-
ThreeTestTop.three.cpu.debugRegs_20[31:0]
109-
ThreeTestTop.three.cpu.debugRegs_21[31:0]
110-
ThreeTestTop.three.cpu.debugRegs_22[31:0]
111-
ThreeTestTop.three.cpu.debugRegs_23[31:0]
112-
ThreeTestTop.three.cpu.debugRegs_24[31:0]
113-
ThreeTestTop.three.cpu.debugRegs_25[31:0]
114-
ThreeTestTop.three.cpu.debugRegs_26[31:0]
115-
ThreeTestTop.three.cpu.debugRegs_27[31:0]
116-
ThreeTestTop.three.cpu.debugRegs_28[31:0]
117-
ThreeTestTop.three.cpu.debugRegs_29[31:0]
118-
ThreeTestTop.three.cpu.debugRegs_30[31:0]
119-
ThreeTestTop.three.cpu.debugRegs_31[31:0]
12051
[pattern_trace] 1
12152
[pattern_trace] 0

0 commit comments

Comments
 (0)