A simplified CPU implementation featuring a custom datapath and controller, written in SpinalHDL.
Ensure you have the following tools installed:
- Python 3
- Rust Toolchain: For sourcecode.
- Scala & SBT: For SpinalHDL.
- Verilator: For simulation backend.
- Spike (riscv-isa-sim): For instruction set verification (optional, used by
checker.py).
assembler/: Contains the Rust source code for the firmware and Python scripts to compile/assemble it into machine code.spinal/: The SpinalHDL hardware description project.checker.py: A script to verify the CPU execution against the Spike simulator.
The firmware is written in Rust.
-
Navigate to
assembler/sourcecode/src/. -
Copy
main.rs.exampletomain.rs(if not already done). -
Modify
main.rswith your desired code. -
Run the assembler from the root directory:
python3 -m assembler.main
This will generate
assembler/firmware.asm(assembly) andassembler/firmware.hex(machine code).
Simulate the CPU running your firmware using Verilator.
-
Navigate to the
spinaldirectory:cd spinal -
Run the simulation:
sbt "runMain minicpu.CpuTopSim"This will execute the firmware and generate a commit log at
logs/minicpu.log.
To generate the Verilog RTL for synthesis or implementation:
cd spinal
sbt "runMain minicpu.CpuTopVerilog"The output file CpuTop.v will be generated in spinal/hw/gen/.
You can verify the CPU's execution against the Spike simulator.
python3 checker.pyThis script converts the hex file to binary, runs it in Spike, and compares the execution logs.
args:
-d: Generate hex from esisting asm file instead of compiled Rust code.--max <number>: Maximum number of cycles to execute.