contributed by kk908676
Follow the instructions from here
$sudo apt install default-jdk
$ sudo apt install build-essential verilator gtkwave
$ git clone https://github.com/ucb-bar/chisel-tutorial
Before testing your system, ensure that you have sbt (the Scala build tool) installed.
$ git clone https://github.com/sysprog21/ca2023-lab3
The following image is the single-cycle CPU that we will be implementing in this assignment.
Full
Simplifed
As the instructor has already completed the majority of the content, I only need to make modifications to the following file :
After completion, you can obtain the following information.
[info] ExecuteTest:
[info] Execution of Single Cycle CPU
[info] - should execute correctly
[info] ByteAccessTest:
[info] Single Cycle CPU
[info] - should store and load a single byte
[info] FibonacciTest:
[info] Single Cycle CPU
[info] - should recursively calculate Fibonacci(10)
[info] InstructionDecoderTest:
[info] InstructionDecoder of Single Cycle CPU
[info] - should produce correct control signal
[info] QuicksortTest:
[info] Single Cycle CPU
[info] - should perform a quicksort on 10 numbers
[info] InstructionFetchTest:
[info] InstructionFetch of Single Cycle CPU
[info] - should fetch instruction
[info] RegisterFileTest:
[info] Register File of Single Cycle CPU
[info] - should read the written content
[info] - should x0 always be zero
[info] - should read the writing content
[info] Run completed in 20 seconds, 443 milliseconds.
[info] Total number of tests run: 9
[info] Suites: completed 7, aborted 0
[info] Tests: succeeded 9, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
Below is the complete C code.
Generating Waveform Files During Testing:
While running tests, if you set the environment variable WRITE_VCD
to 1, waveform files will be generated.
After the first run and every time you modify the Chisel code, you need to execute the following command in the project's root directory to generate Verilog files:
For example, load the hello.asmbin
file, simulate for 1000 cycles, and save the simulation waveform to the dump.vcd
file
Observing the pattern, it is evident that with each clock cycle, our program counter (pc) increments by 4.
Taking clock cycle 3 for example, the instruction is 0x22B7 (equivalent to 'lui x5, 2'). Therefore, the io_reg_write_address is 5, and io_ex_immediate is 2.
Here, with an opcode of 33 (equivalent to addu), the operation involves adding io_op1 (0x05B3E659) to io_op2 (0x0380F18C), and the result is stored in io_result (0x934D7E5).
Later, we need to add our own test data in CPUTest.scala.
Finally, use $ sbt test to ensure that our modifications have passed compilation.
[info] Find_stringTest:
[info] Single Cycle CPU
[info] - should execute calculate find_string
Afterwards, perform the same test as above by checking the values inside the registers to ensure their correctness
generate Wave
At the 3ns timestamp, it is evident from our inspection of register_21 that the observed value perfectly aligns with our expectations, being '29' in hexadecimal (0x1d).