@@ -10,80 +10,77 @@ import java.nio.ByteBuffer
1010import chisel3 .simulator .PeekPokeAPI .TestableRecord
1111
1212class MainSpec extends AnyFreeSpec with Matchers with ChiselSim {
13- // "Main should execute LUI correctly" in {
14- // simulate(new Main()) { dut =>
15- // val bytes = Files.readAllBytes(Paths.get("./programs/fib-loop.bin"))
16-
17- // val instructions = bytes.grouped(4).map { instrBytes =>
18- // val paddedBytes = instrBytes.padTo(4, 0.toByte)
19- // val signedInt = ByteBuffer.wrap(paddedBytes).order(java.nio.ByteOrder.BIG_ENDIAN).getInt()
20- // signedInt.toLong & 0xFFFFFFFFL
21- // }.toSeq
22-
23- // dut.io.debug_write.poke(true.B)
24- // instructions.zipWithIndex.foreach { case (instr, idx) =>
25- // println(s"Instruction: ${instr.toBinaryString.reverse.padTo(32, '0').reverse}")
26- // println(s"Address: ${idx * 4}")
13+ " Main should execute Store and Load Instructions correctly" in {
14+ simulate(new Main ()) { dut =>
15+ // Load hex file, one instruction per line
16+ val instructions = Source
17+ .fromFile(" ./programs/hello.hex" )
18+ .getLines()
19+ .filter(_.trim.nonEmpty)
20+ .map(line => java.lang.Long .parseLong(line.trim, 16 ))
21+ .toSeq
2722
28- // dut.io.debug_write_data.poke(instr.U(32.W))
29- // dut.io.debug_write_addressess.poke((idx * 4).U)
30- // dut.clock.step(1)
31- // }
23+ dut.io.debug_write.poke(true .B )
3224
33- // dut.io.debug_write.poke(false.B);
34- // dut.io.execute.poke(true.B);
25+ instructions.zipWithIndex.foreach { case (instr, idx) =>
26+ dut.io.debug_write_address.poke(idx.U )
27+ dut.io.debug_write_data.poke(instr.U (32 .W ))
28+ dut.clock.step(1 )
29+ }
3530
36- // dut.clock.step(1);
31+ dut.io.debug_write.poke(false .B )
32+ dut.clock.step(1 )
3733
38- // dut.clock.step(50);
39- // }
40- // }
34+ dut.io.execute.poke(true .B )
35+ dut.clock.step(100 )
36+ }
37+ }
4138
42- " Main should execute Store and Load Instructions correctly" in {
43- simulate(new Main ()) { dut =>
44- dut.io.debug_write.poke(true .B )
39+ // "Main should execute Store and Load Instructions correctly" in {
40+ // simulate(new Main()) { dut =>
41+ // dut.io.debug_write.poke(true.B)
4542
46- dut.io.debug_write_address.poke(0 .U )
47- dut.io.debug_write_data.poke(0x00004137L.U )
48- dut.clock.step(1 )
43+ // dut.io.debug_write_address.poke(0.U)
44+ // dut.io.debug_write_data.poke(0x00004137L.U)
45+ // dut.clock.step(1)
4946
50- dut.io.debug_write_address.poke(1 .U )
51- dut.io.debug_write_data.poke(0x000041b7L.U )
52- dut.clock.step(1 )
47+ // dut.io.debug_write_address.poke(1.U)
48+ // dut.io.debug_write_data.poke(0x000041b7L.U)
49+ // dut.clock.step(1)
5350
54- dut.io.debug_write_address.poke(2 .U )
55- dut.io.debug_write_data.poke(0x00408093L.U )
56- dut.clock.step(1 )
51+ // dut.io.debug_write_address.poke(2.U)
52+ // dut.io.debug_write_data.poke(0x00408093L.U)
53+ // dut.clock.step(1)
5754
58- dut.io.debug_write_address.poke(3 .U )
59- dut.io.debug_write_data.poke(0x00218133L.U )
60- dut.clock.step(1 )
55+ // dut.io.debug_write_address.poke(3.U)
56+ // dut.io.debug_write_data.poke(0x00218133L.U)
57+ // dut.clock.step(1)
6158
62- dut.io.debug_write_address.poke(4 .U )
63- dut.io.debug_write_data.poke(0x00110023L.U )
64- dut.clock.step(1 )
59+ // dut.io.debug_write_address.poke(4.U)
60+ // dut.io.debug_write_data.poke(0x00110023L.U)
61+ // dut.clock.step(1)
6562
66- dut.io.debug_write_address.poke(5 .U )
67- dut.io.debug_write_data.poke(0xff5ff06fL.U )
68- dut.clock.step(1 )
63+ // dut.io.debug_write_address.poke(5.U)
64+ // dut.io.debug_write_data.poke(0xff5ff06fL.U)
65+ // dut.clock.step(1)
6966
70- // dut.io.debug_write_address.poke(0.U)
71- // dut.io.debug_write_data.poke(0b000000000111_00000_000_00001_0010011.U) // ADDI
72- // dut.clock.step(1)
67+ // // dut.io.debug_write_address.poke(0.U)
68+ // // dut.io.debug_write_data.poke(0b000000000111_00000_000_00001_0010011.U) // ADDI
69+ // // dut.clock.step(1)
7370
74- // dut.io.debug_write_address.poke(1.U)
75- // dut.io.debug_write_data.poke(0b0000000_00001_00000_010_00000_0100011.U) // SW
76- // dut.clock.step(1)
71+ // // dut.io.debug_write_address.poke(1.U)
72+ // // dut.io.debug_write_data.poke(0b0000000_00001_00000_010_00000_0100011.U) // SW
73+ // // dut.clock.step(1)
7774
78- // dut.io.debug_write_address.poke(2.U)
79- // dut.io.debug_write_data.poke(0b000000000000_00000_010_00010_0000011.U) // LW
80- // dut.clock.step(1)
75+ // // dut.io.debug_write_address.poke(2.U)
76+ // // dut.io.debug_write_data.poke(0b000000000000_00000_010_00010_0000011.U) // LW
77+ // // dut.clock.step(1)
8178
82- dut.io.debug_write.poke(false .B )
83- dut.clock.step(1 )
79+ // dut.io.debug_write.poke(false.B)
80+ // dut.clock.step(1)
8481
85- dut.io.execute.poke(true .B )
86- dut.clock.step(24 )
87- }
88- }
82+ // dut.io.execute.poke(true.B)
83+ // dut.clock.step(24)
84+ // }
85+ // }
8986}
0 commit comments