Project 2: A RV32I Toy CPU

Computer Architecture I @ ShanghaiTech University

Project 2: A RV32I Toy CPU

IMPORTANT INFO - PLEASE READ

The projects are part of CS110P course project worth 2 credit points. As such they run in parallel to the actual course. So be aware that the due date for project and homework might be very close to each other! Start early and do not procrastinate.

Introduction

In this individual project, you will embark on a journey to create a toy RV32I CPU. Before diving into the task, please pay close attention to the following important points:

Project 2.1: Implement a Single-cycle CPU (DDL: May 5th)

In this part, your task involves implementing a single-cycle CPU which can process the instructions shown in The Instruction Set below. Feel free to refer to the advice provided in the How to Get Started section to start your circuit adventure.

The Instruction Set

The instructions you need to implement are shown in the table below:

Format Instructions Implementation
R add x[rd] = x[rs1] + x[rs2]
R sra x[rd] = x[rs1] >>s x[rs2]
R slt x[rd] = x[rs1] <s x[rs2]
I srli x[rd] = x[rs1] >>u shamt
I sltiu x[rd] = x[rs1] <u sext(immediate)
I andi x[rd] = x[rs1] & sext(immediate)
I addi x[rd] = x[rs1] + sext(immediate)
I lw x[rd] = sext(M[x[rs1] + sext(offset)][31:0])
I lh x[rd] = sext(M[x[rs1] + sext(offset)][15:0])
I jalr t =pc+4; pc=(x[rs1]+sext(offset))&~1; x[rd]=t
U auipc x[rd] = pc + sext(immediate[31:12] << 12)
U lui x[rd] = sext(immediate[31:12] << 12)
S sw M[x[rs1] + sext(offset)] = x[rs2][31:0]
S sh M[x[rs1] + sext(offset)] = x[rs2][15:0]
J jal x[rd] = pc+4; pc += sext(offset)
B beq if (x[rs1] == x[rs2]) pc += sext(offset)

A detailed description of RV32I is provided in The RISC-V Instruction Set Manual Volume I: Unprivileged ISA (Version: 20240411). Some important information is also provided below. Please note that there are different versions of RV32I instructions, and referencing other documents or webpages may result in failing the test.

Instruction Formats

In the base RV32I ISA, there are four core instruction formats (R/I/S/U), as shown in the below figure. All are 32-bit long. The base ISA has IALIGN=32, meaning that instructions must be aligned on a four-byte boundary in memory.

Here are details about RV32I Base Instruction Set (MSB to LSB), you can also find this table in The RISC-V Instruction Set Manual Volume I: Unprivileged ISA, page 554 (may proxy needed):

How to get start

We provided the template in Github Classroom to get started. Please clone your repo first. Opening proj_2_1_top.circ with logisim-evolution, you will find several subcircuits inside it.

A single-cycle CPU through several stages,such as Instruction Fetch (IF), Instruction Decode (ID), Execute (EX), Memory Access (MEM), and Write Back (WB). And each stages may include multiple submodules. Here are some suggestions for your information:

The instruction memory module in testbench, provided as a pre-configured ROM by TAs, stores the target instruction sequence for execution.

The TOP circuit incorporates predefined input/output ports for testing purposes, where most output signals chould be treated as ''probes''. These diagnostic signals may not interfere with your circuit implementation, but you are required to show the correct values throughout operation (Somtimes you maydon't care some of them). Detailed specifications for these signals can be found in the TOP I/O section.

TOP I/O

The inputs and outputs of top level are fixed in TOP circuit. It's not allowed to add extra pins in TOP circuit in your submission.

Type signal bit width description
input clk 1 clock
input rst 1 reset
input inst 32 RV32I instruction from inst memory
output inst_addr 32 current instruction address
output mem_wen 1 memory write enable
output mem_din 32 data written to memory
output mem_dout 32 data from memory
output mem_addr 32 address of memory
output control_en 1 enable writing value to pc
output control_pc 32 value written to pc
output wb_en 1 regfile write enable
output wb_addr 5 address written to regfile
output wb_data 32 data written to regfile

Restriction

In order to reduce your workload and help you pass the test smoothly, some restrictions are stipulated as follows. Please note these requirements take precedence over any conflicting descriptions in the Instruction Set Manual.

Test

For the convenience of calibrating each cycle, an additional counter has been added to the testbench, which you can ignore in your own design.

Local test

TAs provides a comprehensive local test script containing all instruction patterns, but the reference output does not explicitly mark don't-care signals. In Project 2.1, you must independently analyze and determine which signals can be safely disregarded during your implementation verification.


    chmod +x test.sh 
    ./test.sh

This script is suitable for Linux systems. If you want to run it on other operating systems, you need to make some modifications.

Autograder test

The autograder will exclude validation of these don't-care portions through an internal filtering process. The testcase of Autograder is non-public, which means you need to consider all corners as much as possible. Please ensure that the local test passes when submitting a rating request to the Autograder. Notice: We will evaluate your final score based on which of your submissions is set as active.