This is a project of Computer Organization and Achitecture, PKU. LAB2 and LAB3.2 are included. I believe my solution is quite elegant and may sparks you.
The simulator simulates on RV64I and RV64F ISA. (There are still some bugs in RV64F, yet I'm not going to debug them.)
The specification of RISC-V ISA is available in this repo. Or you may retrieve the latest version from https://riscv.org/specifications/.
Find more details at https://github.com/LC-John/Notes-and-homeworks/tree/master/体系实习.
MIT License
-
Simply download this repo by clicking the
DOWNLOAD
button or callgit git@github.com:LC-John/RISCV-Simulator.git
in command line. -
Use QtCreator or other IDEs to open the
.pro
project file. -
Build and run.
-
Have fun playing with this simulator.
Use sim -h
to get the help menu. Everything you need is in it.
There are 5 main units (actually there exsists 4 units) in this simulator.
This unit fetch an instruction from the instruction memory, and update PC. Then the unit split the instruction into several domains, such as rd
, rs1
, rs2
, etc.
This unit takes the domains of instructions as input, and performs some decoding -- read the register file and generate an immediate number if necessary.
This unit perform some logical/arithmetic calculation, such as logical and
, add
, etc. Also this unit perform a comparison between two numbers, and the result is passed to the controller. Such results will be used by instructions such as BEQ
, etc.
There is another extra Excutor unit, called EX2. During the process of multiplication and division, the time cost is usually more than one cycle. EX2 is activated when EX excutes such a time-costing instruction.
This unit reads/writes a byte/half word/word/double word/etc to the data memory (main memory). It cannot read and write in the same time.
This unit write one register in the register file. The content has multiple sources.
This unit is lately added. It simulates the data cache and the instruction cache. The cache hierarchy simulator is in anothr repo. Portal here! (https://github.com/LC-John/Cache-Simulator)
This simulator has 3 modes -- single-cycle, multi-cycle and pipeline. single-cycle and multi-cycle mode are easy. The architecture of the pipelie mode is shown below.
See the PDF reports at https://github.com/LC-John/Notes-and-homeworks/tree/master/体系实习.
Last but the most important thing is that you can reference them, but PLEASE DO NOT COPY! If you copy this project and get caught, no one can help you, and you deserve nothing but a zero score.
Heads up! I've inserted something into my code. It will somehow show the identification information of the true author, which is me. So again, DO NOT COPY.
Good luck and have fun. :)