李尚宸
You don't have to copy and paste Chisel code. Instead, discuss and reflect what you have done. Seek for compliance and improvements.
In the InstructionFetchTest
, the goal is to verify the module's ability to correctly set the PC
(0x1000
) by using a multiplexer to choose between PC + 4.U
and jump_address_id
, with the selection determined randomly using Random.nextInt(2)
.
Original entry address: 0x1010
When io_jump_flag_id
set to 0, entry address = PC + 4.U
= 0x1014
When io_jump_flag_id
set to 1, entry address = 0x1000
In the InstructionDecoderTest
, the task is to set io_memory_read_enable
and io_memory_write_enable
depending on the opcode.
For the first instruction sw x10, 4(x0)
:
io_memory_read_enable
should be 0io_memory_write_enable
should be 1For the second instruction lui x5, 2
:
io_memory_read_enable
should be 0io_memory_write_enable
should be 0FOr the third instruction add x3, x1, x2
:
io_memory_read_enable
should be 0io_memory_write_enable
should be 0In the ExecuteTest
, the task is to connect alu_func
and set alu.io.op1
and alu.io.op2
based on their respective sources.
alu.io.op1
should be io_op1
alu.io.op2
should be io_op2
For the first instruction add x3, x1, x2
:
For the second instruction, beq x1, x2, 2
:
When x1 != x2
, io_if_jump_flag
should be 0
When x1 == x2
, io_if_jump_flag
should be 1
The M standard extension is for integer multiplication and division instructions. RV32IM
is the RV32I
instruction set with the M standard extension, which includes the mul
, mulh
, mulhsu
, mulhum
, div
, divu
, rem
, and remu
instructions.
Code can be found in
src/main/scala/riscv/core
Add the corresponding operations for each M instruction respectively.
The diagrams below show the instruction codes for RV32I
and RV32M
. Both share the same opcode (0110011
for R-type instructions), but RV32M
is identified by funct7 = 0x01
, while RV32I uses other funct7
values 0x00
.
We can distinguish between the two using funct7
, as shown in the following code:
Reference: RISCOF Official Documentation
The riscv-arch-test is an official RISC-V Architectural Test Framework used to verify compliance with the RISC-V Instruction Set Architecture (ISA) specifications. It ensures that a processor implementation correctly implements the required features of the RISC-V ISA.
The RISC-V GNU Toolchain is a complete set of tools based on the GNU Project, customized for the RISC-V architecture. It provides essential tools for compiling, linking, and debugging applications targeting RISC-V processors.
The official website provides the following installation steps. However, I encountered an error while executing the command:
To resolve this issue, I opted to download the prebuilt RISC-V GNU toolchain.
Then add the path /path/to/install
to $PATH in the .bashrc/cshrc
.
Install SPIKE (riscv-isa-sim)
Install SAIL (SAIL C-emulator)
I rewrote three RISC-V programs to test the correctness of the M extension. The following are my implementations.
This program multiplies two numbers using the mul instruction in RISC-V and stores the result
This program implements Ancient Egyptian Multiplication using the M extension for multiplication and division.
This program calculates the square of an integer (a0 = n) and returns the result in a0.
makefile
to enable M Extension