A RISC-V RV32I+Zicsr FPGA implementation.
Mini-Bus is a simple bus protocol used to connect the CPU core with other components like memory and memory-mapped peripherals in this project.
clk
: bus clocknrst
: bus resetaddr
: bus address signals, 32-bitwdata
: bus write data signals, 32-bit- Always right-aligned for storing byte or half-word
rdata
: bus read data signals, 32-bitwidth
: bus data width, 2-bit00
: byte access01
: half word access10
: full word access
ren
: bus read enable- If set, signaling this request is a read request
wen
: bus write enable- If set, signaling this is a write request
err
: bus master error signal- Connect to the current slave device being selected
ack
: bus master acknowledge- If set, signaling the request is completed and master should read available data/start next request
- Slave signals
selx
: bus slave x select signal- Set based on the memory address assigned to each slave device
ackx
: bus slave x acknowledge signalerrx
: bus slave x error signal
Using Wavedrom for visualization.
- Implement unprivileged isa
- Implement machine-mode (privileged) isa
- CSR register and instruction support
- What CSR registers needed?
- Those in machine-mode
- A total of 4096 CSRs with default values
-
misa
-
mvendorid
: zeros -
marchid
: zeros -
mimpid
: zeros -
mhartid
: zeros -
mstatus
-
mstatush
-
mtvec
-
medeleg
andmideleg
-
mie
andmip
-
mscratch
-
mepc
-
mcause
-
mtval
-
- Map those in user and supervisor mode to zeros
- A total of 4096 CSRs with default values
- Performance monitor could be optional
- Those in machine-mode
- Instruction needed: Zicsr extension
- Instruction needed: machine-level privileged instructions
-
ecall
-
ebreak
-
mret
: need to modify CSRmstatus
-
(Implemented as NOP for now)fence
-
wfi
: could be a nop
-
- CSR R/W permission protection, check
index[11:10]
bits - CSR fields WARL, WLRL protection
- Need to determine what additional signals needed to the CSR module
- Like interrupt and exception signals
- What CSR registers needed?
- Interrupt/Exception generator/handler
- Merge with the CSR unit to faciliate easy CSR values modification
- What are the interrupts and execptions needed to support?
- Just implement Exception for now?
- Inst addr misalign
- Inst illegal
- environment breakpoint
- load/store addr misalign
- environment call m-mode
- Also need to set epc
-
Also need to save context?Unlike STM32, software saves the context
- Just implement Exception for now?
- CSR register and instruction support
- Need to pass riscv isa tests in machine mode
- RTL Level
- GATE Level
- Let TB listen on the RAM signals, waiting for writes to toHOST memory region with the value
- Multi-cycle latency RAM
- 0 cycle latency
- 2 cycles latency
- 3 cycles latency
- 7 cycles latency
- 10 cycles latency
- For odd cycles latency, dhit/ihit will need hit twice
- Since the first hit is on the failing edge of CPU clock (RAM clk is twice as fast as the CPU clk)
- So the effective latency will be double if we don't sync the RAM ack with CPU clock
- Fix this in later iteration since we don't want single cycle to be burdened with performance.
- Need to update processor state only once in a multi-cycle wait for inst fetch
- By updating CSR and regfile only when ihit for regular inst
- Update regfile for load operation only when dhit
- Auto tester for unit test asm from riscv-tests
- Mini-Bus protocol
- For non-word loads, put data in right-aligned format or maintain same offset in memory?
- If load a byte
0xAA
at address0x1
, do we want0x000000AA
or0x0000AA00
? - Probably the first one as the address bus already contain the offset information, no need to include redundant information on the data bus as well
- Also no need on RISCV side to shift the offseted data
- Add this to Mini-Bus protocol
- If load a byte
- Simple IO
- LED Segement
- Off-chip RAM
- Create a custom testbench compilation script to properly load folders in
components
with simulator- The default one will prompt
Folder exists
error if rerun simulation, requiring manually deletion of themodelsim
folder everytime
- The default one will prompt
- Create different revisions for testbench mapped simulation and FPGA download
- The FPGA one is with
system_fpga.sv
and the testbench should havesystem.sv
as top module
- The FPGA one is with
- CI/CD integration with coverage report?
- Implement pipeline CPU with machine-mode
- Make sure the exception/interrupt are precise
- Group interface signals into event packet struct, like instruction fetch, memory_ldst
- Add
M-
extension - Add
A-
extension
- Implement a memory bus to connect on-chip and off-chip RAM/ROM
-
FENCE
and RISCV memory consistency model? - Implement programmer? To program the chip without quartus, like a real embedded system
- Debugger support? Like On-chip breakpoints
- Also other embedded peripheral
- Build a memory map
- Coverage report?
- RISC-V Testsuite
- Use
make benchmark_BENCHMARK
ormake isa_ISATEST
to generate thememinit.hex
- Use
make own_PROG
to compile programs insideprog
folder
- Use
- RISCV ISA Manual
- Used 20191214-draft for unprivileged ISA
- Used 20211203 for privileged ISA
- RISCV ISA simulator
- RISCV unit test benchmark suite
- Intel Quartus Lite
- For linux
- Also if want to use the waveform simulator, need to register for a license