|
| 1 | +package RISCV |
| 2 | + |
| 3 | +import chisel3._ |
| 4 | +import chisel3.simulator.scalatest.ChiselSim |
| 5 | +import org.scalatest.freespec.AnyFreeSpec |
| 6 | +import org.scalatest.matchers.must.Matchers |
| 7 | +import scala.io.Source |
| 8 | +import java.nio.file.{Files, Paths} |
| 9 | +import java.nio.ByteBuffer |
| 10 | +import chisel3.simulator.PeekPokeAPI.TestableRecord |
| 11 | + |
| 12 | +class MainSpec extends AnyFreeSpec with Matchers with ChiselSim { |
| 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 |
| 22 | + |
| 23 | + dut.io.debug_write.poke(true.B) |
| 24 | + |
| 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 | + } |
| 30 | + |
| 31 | + dut.io.debug_write.poke(false.B) |
| 32 | + dut.clock.step(1) |
| 33 | + |
| 34 | + dut.io.execute.poke(true.B) |
| 35 | + dut.clock.step(64) |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + // "Main should execute Store and Load Instructions correctly" in { |
| 40 | + // simulate(new Main()) { dut => |
| 41 | + // dut.io.debug_write.poke(true.B) |
| 42 | + |
| 43 | + // dut.io.debug_write_address.poke(0.U) |
| 44 | + // dut.io.debug_write_data.poke(0x00004137L.U) |
| 45 | + // dut.clock.step(1) |
| 46 | + |
| 47 | + // dut.io.debug_write_address.poke(1.U) |
| 48 | + // dut.io.debug_write_data.poke(0x000041b7L.U) |
| 49 | + // dut.clock.step(1) |
| 50 | + |
| 51 | + // dut.io.debug_write_address.poke(2.U) |
| 52 | + // dut.io.debug_write_data.poke(0x00408093L.U) |
| 53 | + // dut.clock.step(1) |
| 54 | + |
| 55 | + // dut.io.debug_write_address.poke(3.U) |
| 56 | + // dut.io.debug_write_data.poke(0x00218133L.U) |
| 57 | + // dut.clock.step(1) |
| 58 | + |
| 59 | + // dut.io.debug_write_address.poke(4.U) |
| 60 | + // dut.io.debug_write_data.poke(0x00110023L.U) |
| 61 | + // dut.clock.step(1) |
| 62 | + |
| 63 | + // dut.io.debug_write_address.poke(5.U) |
| 64 | + // dut.io.debug_write_data.poke(0xff5ff06fL.U) |
| 65 | + // dut.clock.step(1) |
| 66 | + |
| 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) |
| 70 | + |
| 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) |
| 74 | + |
| 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) |
| 78 | + |
| 79 | + // dut.io.debug_write.poke(false.B) |
| 80 | + // dut.clock.step(1) |
| 81 | + |
| 82 | + // dut.io.execute.poke(true.B) |
| 83 | + // dut.clock.step(24) |
| 84 | + // } |
| 85 | + // } |
| 86 | +} |
0 commit comments