王彥珽
I followed the senior's steps to set up the environment, but I encountered an issue where I couldn't generate the .asmbin
file. The problem was caused by the absence of the riscv-none-elf
toolchain. After some investigation, I discovered that the installation instructions were actually provided after Lab2.
The first issue encountered when reproducing last year's experiment:
The reason for this error is the absence of the SimpleTrapTest test file. Since the goal is to test the behavior of interrupts and CSR, the hello.asmbin
file is used as a test file to serve as the side data for SimpleTrapTest.
(hello.asmbin maynot be the test file to serve as the side data.)(to be solved)
RV32C is a compressed instruction set in the RISC-V architecture. It is designed to reduce the size of instructions, thereby decreasing memory usage and increasing instruction density, which improves processor performance.
After studying the introduction to RV32C instructions, I initially planned to decode the 16-bit instructions in the InstructionDecode stage, similar to the approach used for RV32IM. However, as I progressed, the process became increasingly complex. Therefore, I decided to handle the mapping of 16-bit RV32C instructions during the InstructionFetch stage instead, expanding them into RV32I instructions.
instruction | op | funct | corresponding rv32i instr. |
---|---|---|---|
c.jr | 10 | 1000 | jalr x0, rs1, 0 |
c.jalr | 10 | 1001 | jalr ra, rs1, 0 |
c.mv | 10 | 1000 | add rd, x0, rs2 |
c.add | 10 | 1001 | add rd, rd, rs2 |
c.ebreak | 10 | 1001 | ebreak |
instruction | op | funct | corresponding rv32i instr. |
---|---|---|---|
c.lwsp | 10 | 010 | lw rd, (4 * imm)(sp) |
c.li | 01 | 010 | addi rd, x0, imm |
c.lui | 01 | 011 | lui rd, imm |
c.addi | 01 | 000 | addi rd, rd, imm |
c. addi16sp | 01 | 011 | addi sp, sp, 16 * imm |
c.slli | 10 | 000 | slli rd, rd, imm |
c.nop | 01 | 000 | addi x0, x0, 0 |
instruction | op | funct | corresponding rv32i instr. |
---|---|---|---|
c.swsp | 10 | 110 | sw rs2, (4 * imm)(sp) |
instruction | op | funct | corresponding rv32i instr. |
---|---|---|---|
c.addi4spn | 00 | 000 | addi rd', sp, 4 * imm |
instruction | op | funct | corresponding rv32i instr. |
---|---|---|---|
c.lw | 00 | 010 | lw rd', (4 * imm)(rs1') |
instruction | op | funct | corresponding rv32i instr. |
---|---|---|---|
c.sw | 00 | 110 | sw rs1', (4 * imm)(rs2') |
c.and | 01 | 10001111 | and rd', rd', rs2' |
c.or | 01 | 10001110 | or rd', rd', rs2' |
c.xor | 01 | 10001101 | xor rd', rd' rs2' |
c.sub | 01 | 10001100 | sub rd', rd', rs2' |
instruction | op | funct | corresponding rv32i instr. |
---|---|---|---|
c.beqz | 01 | 110 | beq rs', x0, 2 * imm |
c.bnez | 01 | 111 | bne rs', x0, 2 * imm |
c.srli | 01 | 100x00 | srli rd', rd', imm |
c.srai | 01 | 100x01 | srai rd', rd', imm |
c.andi | 01 | 100x10 | andi rd', rd', imm |
instruction | op | funct | corresponding rv32i instr. |
---|---|---|---|
c.j | 01 | 101 | jal x0, 2 * offset |
c.jal | 01 | 001 | jal ra, 2 * offset |
I noticed that the senior did not include multiplication, division, and remainder operations in the ALU, so I added them.
In ALUControl.scala :
In ALU.scala :
After implementing RV32MC, it successfully passed all the original test cases.
The riscv-arch-test framework is an official RISC-V International project designed to verify compliance with the RISC-V ISA specifications. It provides a standardized set of architectural tests to ensure that RISC-V implementations conform to the expected behavior as defined in the ISA manual.
using git clone
to get riscv-arch-test
:
Follow this tutorial to install.
After completing the installation, we use following instruction to generate the configuration file.
Here, dutname
refers to testing model, while refname
refers to the reference model.
Subsequently, the files are validated, and the required test database is generated.
However, certain modifications are required in riscof_mycpu.py
. First, use Verilator to generate the VTop
file, and then update the path of dut.exe
to point to the location of VTop
.
Perform the test.
After executing the test, the following issues arose:
It is speculated that this issue arises because the compile command in the .py file still needs modification, and sbt must also support generating the required files.