A modular 64-bit RISC-V CPU and SoC implemented in SystemVerilog.
Features a multi-cycle microarchitecture, RV64I base integer support, the RV64M multiply/divide extension, machine-mode CSRs, and synchronous trap handling.
The design is simulated with Verilator, supporting both directed assembly regressions and self-checking bare-metal C programs.
- RV64I base ISA
- RV64M multiply/divide extension
- Zicsr CSR instructions
- Zifencei FENCE.I instruction
- Multi-cycle CPU architecture
- 32 x 64-bit integer register file
- Unified instruction/data bus
- Byte, halfword, word, and doubleword memory access
- Machine-mode CSR file
- Synchronous exception and trap handling
- MRET trap return
- Bare-metal C execution
- Cycle-accurate RAM model
- Verilator simulation with VCD waveform output
- Self-checking assembly and C tests
- Automated assembly regression suite
- GitHub Actions CI
Required tools:
- Verilator
- RISC-V GCC toolchain
- make
- g++
- GTKWave (optional)
From the project root:
- Run full assembly regression:
make asm
- Run bare-metal C self-test:
make c
- Clean build outputs:
make clean
Use gtkwave sim/dump.vcd to view waveforms.
ADD SUB AND OR XOR
SLL SRL SRA
SLT SLTU
MUL MULH MULHU MULHSU
DIV DIVU REM REMU
ADDI ANDI ORI XORI
SLTI SLTIU
SLLI SRLI SRAI
ADDIW
ADDW SUBW
SLLIW SRLIW SRAIW
SLLW SRLW SRAW
MULW
DIVW DIVUW REMW REMUW
LUI AUIPC
LB LBU LH LHU LW LWU LD
SB SH SW SD
JAL JALR
BEQ BNE
BLT BGE
BLTU BGEU
CSRRW CSRRS CSRRC
CSRRWI CSRRSI CSRRCI
Implemented machine-mode CSRs:
mstatus mtvec mscratch mepc mcause mtval
EBREAK
ECALL
MRET
Treated as legal NOPs:
FENCE
FENCE.I
Implemented synchronous exceptions:
- Instruction address misaligned
- Instruction access fault
- Illegal instruction
- Breakpoint
- Load address misaligned
- Load access fault
- Store address misaligned
- Store access fault
- Environment call from M-mode
Trap entry saves:
- Faulting PC to
mepc - Cause to
mcause - Fault information to
mtval
and redirects execution to mtvec.
MRET returns execution to mepc.
Current privileged support is machine mode only. Interrupts are not implemented.
Assembly regression includes:
rv64_test.Scsr_test.Strap_test.Sinvalid_csr_test.Smstatus_test.S
The simulator automatically detects PASS and FAIL addresses and exits with the corresponding status.
Run all assembly tests with:
make asm
Run the bare-metal C self-test with:
make c
See docs/ for detailed descriptions.
- Milestone 0: Project setup
- Milestone 1: Smoke simulation
- Milestone 2: SoC + RAM
- Milestone 3: Multi-cycle CPU skeleton
- Milestone 4: RV64I implementation
- Milestone 5: Run bare-metal C
- Milestone 6: M Extension
- Milestone 7: CSRs + Traps
The CPU uses a multi-cycle architecture controlled by a central FSM.
Main flow:
IFETCH -> DECODE -> MEM / EXEC -> IFETCH
Exceptions redirect through a trap state:
EXCEPTION -> TRAP -> mtvec
The design uses a single unified bus for instruction fetch and memory operations.
Main RTL modules include:
frontend.svdecoder.svregfile.svalu.svmuldiv.svexu.svlsu.svcsr_file.svcontrol_fsm.svsoc.svram.sv
RAM base / reset PC:
0x0000000080000000
Current simulated RAM size:
1 MiB