All Projects → Michaelvll → RISCV_CPU

Michaelvll / RISCV_CPU

Licence: MIT license
A FPGA supported RISC-V CPU with 5-stage pipeline implemented in Verilog HDL

Programming Languages

c
50402 projects - #5 most used programming language
Verilog
626 projects
C++
36643 projects - #6 most used programming language
assembly
5116 projects
Coq
218 projects
SystemVerilog
227 projects

Projects that are alternatives of or similar to RISCV CPU

yarvi
Yet Another RISC-V Implementation
Stars: ✭ 59 (+22.92%)
Mutual labels:  risc-v
aes
Fast constant-time AES implementations on 32-bit architectures
Stars: ✭ 44 (-8.33%)
Mutual labels:  risc-v
mdepx
MDEPX — A BSD-style RTOS
Stars: ✭ 17 (-64.58%)
Mutual labels:  risc-v
WebRISC-V
WebRISC-V: A Web-Based Education-Oriented RISC-V Pipeline Simulation Environment [PHP]
Stars: ✭ 74 (+54.17%)
Mutual labels:  risc-v
riscv em
Simple risc-v emulator, able to run linux, written in C.
Stars: ✭ 51 (+6.25%)
Mutual labels:  risc-v
bx-github-ci
This tutorial provides one example on how a CI (Continuous Integration) workflow with the IAR Build Tools for Linux can be set up on GitHub. The IAR Build Tools on Linux are available for Arm, RISC-V and Renesas (RH850, RL78 and RX).
Stars: ✭ 20 (-58.33%)
Mutual labels:  risc-v
vega-lite
Software, tools, and documentation for RV32-VEGA-Lite platform
Stars: ✭ 61 (+27.08%)
Mutual labels:  risc-v
ria-jit
Lightweight and performant dynamic binary translation for RISC–V code on x86–64
Stars: ✭ 38 (-20.83%)
Mutual labels:  risc-v
K210
Kendryte K210 BSP for RT-Thread
Stars: ✭ 15 (-68.75%)
Mutual labels:  risc-v
rv32emu
RISC-V RV32I[MAC] emulator with ELF support
Stars: ✭ 61 (+27.08%)
Mutual labels:  risc-v
sedna
Sedna - a pure Java RISC-V emulator.
Stars: ✭ 52 (+8.33%)
Mutual labels:  risc-v
KyogenRV
The Simple 5-staged pipeline RISC-V written in chisel3 for intel FPGA.
Stars: ✭ 37 (-22.92%)
Mutual labels:  risc-v
BUAA CO
2017级北航计算机学院计算机组成原理课程设计(MIPS CPU)
Stars: ✭ 66 (+37.5%)
Mutual labels:  verilog-hdl
ravel
A RISC-V simulator
Stars: ✭ 24 (-50%)
Mutual labels:  risc-v
arv
ARV: Asynchronous RISC-V Go High-level Functional Model
Stars: ✭ 18 (-62.5%)
Mutual labels:  risc-v
fos
Interesting project,the Fast Real Time Operating Systems( FOS-RTOS)
Stars: ✭ 22 (-54.17%)
Mutual labels:  risc-v
bl iot sdk
BL602 SDK (Pine64 fork)
Stars: ✭ 115 (+139.58%)
Mutual labels:  risc-v
rustsbi-qemu
QEMU platform SBI support implementation, using RustSBI
Stars: ✭ 39 (-18.75%)
Mutual labels:  risc-v
FT800-FT813
Multi-Platform C code Library for EVE graphics controllers from FTDI / Bridgetek (FT810, FT811, FT812, FT813, BT815, BT816, BT817, BT818)
Stars: ✭ 80 (+66.67%)
Mutual labels:  risc-v
Verugent
Verilog generation tool written in Rust
Stars: ✭ 39 (-18.75%)
Mutual labels:  verilog-hdl

RISCV-CPU

This project is a FPGA supported RISC-V CPU with 5-stage pipeline implemented in Verilog HDL, a course project of Computer Architecture(MS108), ACM honor class @ SJTU.

Copyright (c) 2017 Zhanghao Wu

Abstract

This project is a simple five stage pipelined cpu for risc-v (rv32i) written in verilog HDL.

It has features as follows:

  1. It can behave correctly for the instructions in rv32i, except ECALL, EBREAK, CSRRW, CSRRS, CSRRC, CSRRWI, CSRRSI, CSRRCI

  2. It can generate a CPU on FPGA, simulate a memory on PC, and connect two of them by using uart.

  3. It has exciting light and status indicator. RGB!!!

Introduction

The design of this cpu is based on the standard mips five stage pipeline. And the cache and UART is based on the repo of Zhekai Zhang.

The Data flow of the CPU is shown below: Data Flow

Five stge pipline

The pipeline is similar to the standard mips five stage pipeline with forwardings. For more information, you can read the Reference [1].

Forwarding

Just as the graph above shows, each stage after ID has a wire connecting to it, to forward the data back. And in this design, ID stage can get the data in the same cpu cycle.

Jumps and Branches

To get a better trade off of jumps and the clock rate, I tried a lot methods. And my work can be divided into 2 stages, no-memory-delay and great-memory-delay.

  1. In my design, there are some wires from ID and EX to pc_reg and mid stage -- IF_ID and ID_EX, in order to set new address and clear the former instruction ( precise interrupt ).

    • no-memory-delay: PC_reg and mid stage update their status as soon as the signal reach, which works well when the IF stage never stall.
    • great-memory-delay: In this case the pc_reg and mid stages are disgned as state machine, when they get a signal for jump, they get into another state to save the signal.
  2. I add switches for ID_BRANCHES and ID_JALR, indicating that the in which state the branches and jalr should be executed.

    • Firstly, the JAL can be safely executed at ID stage. And the other branches and jumps can be set at ID stage, when the IF stage will never stall.
    • However, as the branch instruction needs data from regeisters which may be forwarded from the stage after ID. Comparation and addition will make ID take more time, and that can be a bottle neck that make the CPU clock rate much slower.
    • Another reason I put the all of the execution of branches, execpt jal, to EX stage is that, when the IF and ME should stall for some cycles, and the pc_reg and mid stage should save the signal. The time for ID to get the forwarding data will be much longer, ID may give wrong branch signal before the needed data reach.
    • Further more, when the branches are set in EX, we can use branch prediction in ID, to speed up our pipeline (uncompleted).

    PS: Branches in EX, without branch prediction can be regarded as always predict not jump, when the instruction is recogonized by ID.

IF and ME

The logic to wait data to be ready can be quite hard to implement in hardware, as sequential logic is needed in ME. I have tried to make the store instruction just go through the ME stage. If another memory instruction arrive, it wait the cache to be not busy and start its own work. However, my first design will generate latches, which are strongly not recommanded. ( Reference [3] )

As the cache will give a done signal when the data is ready and the signal only last for one cycle, the logical to wait for the cache to be done can be quite simple and amazing. ( In IF.v and ME.v you can see the code ). In this case, I tried to make store not stall in ME, but the cache will give me a done signal, when the memory access finished, and that will make the logic wrong if another memory instruction come as soon as the memory access done. It can be great to change the cache behavior, in the future.

Cache and Memory

The cache and memory control of my design is from Zhekai Zhang's design ( Referece [2] ). And the cache is modified by me to make it able to uncache the address 0x100.

The cpp sources are written in order to simulate the memory behavior, which inter-act with the CPU by UART.

Makefile for test generation

I write a makefile for make, which can make both .s and .cpp/.c files by using the riscv-tool-chain. The guidance for using it is in Makefile for risc v tool chain.

Some details

  1. The imm in sltiu command is signed extended, and unsigned compared.

  2. The aluop is firstly numbered by the opcode+funct3+(funct7?), then it is renumbered by the sequence: 0x1,0x2,..., to make the number shorter for better performance.

Reference

  1. 《自己动手写CPU》雷思磊
  2. A Mips CPU written in verilog by sxtyzhangzk
  3. Always@
  4. A MIPS CPU written in Verilog by jmahler

Appendix

A. Figures of the CPU

  1. CPU circuit diagram

    CPU circuit diagram

  2. CPU running on fpga

    Running on FPGA

B. Suppoted commands

Command Support
LUI [O]
AUIPC [O]
JAL [O]
JALR [O]
BEQ [O]
BNE [O]
BLT [O]
BGE [O]
BLTU [O]
BGEU [O]
LB [O]
LH [O]
LW [O]
LBU [O]
LHU [O]
SB [O]
SH [O]
SW [O]
ADDI [O]
SLTI [O]
SLTIU [O]
XORI [O]
ORI [O]
ANDI [O]
SLLI [O]
SRLI [O]
SRAI [O]
ADD [O]
SUB [O]
SLL [O]
SLT [O]
SLTU [O]
XOR [O]
SRL [O]
SRA [O]
OR [O]
AND [O]
Fence [X]
Fence.I [X]
ECALL [X]
EBREAK [X]
CSRRW [X]
CSRRS [X]
CSRRC [X]
CSRRWI [X]
CSRRSI [X]
CSRRCI [X]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].