A Simple RISC-V CPU Simulator with 5 Stage Pipeline, Branch Prediction and Cache Simulation
It is a simple RISC-V Emulator suppprting user mode RV64I instruction set, from PKU Computer Architecture Labs, Spring 2019. I made my project open source in the hope that others can learn from my code about how to make a CPU Emulator and get a deeper understanding in computer architecture. As it is implemented entirely from scratch (with no code from Prof or TA), I think it's fine to make it open source.
Note that this is just a toy for learning and is NOT a robust and full solution to RISC-V CPU Emulation. Use qemu for that purpose instead.
- Supporting 54 RISC-V instructions from the RV64I instruction set.
- Branch perdiction module with a set of branch perdicton algorithms.
- Simulation of five stage pipeline like that in the "Computer Organization and Design, Hardware/Software Interface" Book.
- Simulation of cache and various cache eviction strategies.
mkdir build
cd build
cmake ..
make
./Simulator riscv-elf-file-name [-v] [-s] [-d] [-b strategy]
Parameters:
-vfor verbose output, can redirect output to file for further analysis-sfor single step execution, often used in combination with-v.-dfor creating memory and register history dump indump.txt-bfor branch perdiction strategy (defaultBTFNT), accepted parameters areAT,NT,BTFNTandBPB.- AT: Always Taken
- NT: Always Not Taken
- BTFNT: Back Taken Forward Not Taken
- BPB: Branch Prediction Buffer (2 bit history information)
There are a number of reference RISC-V ELFs and its corresponding assembly code in the riscv-elf/ folder.
See the doc/ folder.
Also, you can see the corresponding blog.