Skip to content

Commit c322c6e

Browse files
committed
first serious post
Signed-off-by: Piyush Itankar <pitankar@gmail.com>
1 parent 0bbd9e0 commit c322c6e

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed
559 KB
Loading
529 KB
Loading
50.1 KB
Loading
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
+++
2+
date = "2025-01-04T11:55:09+05:30"
3+
title = 'Writing a RISC-V CPU!'
4+
5+
tags = [
6+
"cpu", "risc-v"
7+
]
8+
9+
categories = [
10+
"hardware"
11+
]
12+
13+
series = ["risc-v"]
14+
images = ["cover.jpeg"]
15+
+++
16+
17+
Few days back I decided to implement a RISC-V rv32i CPU and deploy it on an FPGA. Here are some initial thoughts on how I will go about doing this (and potentially you can follow).
18+
19+
<!--more-->
20+
21+
As part of the journey. I am going to journal the ideas and execution in a series of blog posts. This is not the first time I am venturing into writing a CPU from scratch. I have written a MIPS[^1] and RISC-V[^2] CPUs in the past. The MIPS CPU implemented a very minimal subset and the RISC-V one... that's just a skeleton for a project.
22+
23+
![](cpu.png "MIPS Single Cycle CPU.")
24+
25+
In both cases, I had only attempted a Single cycle CPU with a subset of instructions. While I could deploy the MIPS CPU on a Cyclone V FPGA based DE1SoC, the RISC-V project was abandoned. I wanted to base RISC-V project on verilator based simulation.
26+
27+
![](cover.jpeg "Harris and Harris.")
28+
29+
The book by **Harris and Harris** is a great reference. I am going to read that again and this time around implement the Multi Cycle CPU.
30+
31+
![](book.jpeg "Single Cycle CPU.")
32+
33+
The book goes into explaining the details of implementation and provides sample code. The reference code serves as training wheels and greatly reduces the distraction resulted from the HDL[^3] related errors.
34+
35+
## Plan
36+
37+
Here is the rough plan -
38+
39+
### Language
40+
41+
I am going to implement the CPU either in `Verilog` or `System Verilog`. I have prior experience with these. This time around I am hoping to be less distracted by the language/debugging and be able to focus on the design/implementation.
42+
43+
### Deployment
44+
45+
While I want the CPU to be deployed on the FPGA. It would make sense that I first get it going in a simulator and test it thoroughly. I wouldn't want the logic errors to seep into and mix with the signal level debugging that'll need to be done on the FPGA. The choice of FPGA is not clear at the moment, I do have some FPGAs from `Lattice`. May be I'll just use one of those.
46+
47+
### Instruction Set
48+
49+
`rv32i` is open source instruction set[^5]. I will just use that. I am not clear on what instructions to implement first. Most likely the ones needed to make the CPU turing complete. Something like - `load`, `store`, `add`, `subtract` and `branching` related.
50+
51+
[^1]: Verilog implementation of a subset of MIPS 32 Bit Processor Instructions, ISA design, Assembler Design and Compiler design - [repository](https://github.com/streetdogg/mips-cpu).
52+
53+
[^2]: Implements a RISC-V CPU (rv32i) with base ISA - [repository](https://github.com/streetdogg/riscv-cpu-rtl).
54+
55+
[^3]: Hardware Definition Language(s). `VHDL` and `Verilog` are examples and they let the designer describe the digital circuit as a text file.
56+
57+
[^4]: This means that I will be describing the CPU state machine as text.
58+
59+
[^5]: The instruction set is listed in the [RISC-V Card](https://github.com/jameslzhu/riscv-card/releases/download/latest/riscv-card.pdf).

hugo.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ params:
3232
abbrDateFmt: "Jan 2"
3333
author: "Piyush Itankar"
3434
brandIconFile: "images/brah.svg"
35-
dateFmt: "2006-01-02"
35+
dateFmt: "2 Jan, 2006"
3636
##
3737
## Options for overriding theme or page defaults
3838
##
@@ -52,4 +52,4 @@ params:
5252
url: mailto:piyush@pyjamabrah.com
5353
- name: GitHub
5454
url: https://github.com/streetdogg
55-
subtitle: "Software. Electronics. Insights."
55+
subtitle: "Hardware/Software Abstraction layers and Insights."

layouts/partials/header.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<div class="text">
1010
<a href="{{ .Site.BaseURL }}"><h1>{{ .Site.Title }}</h1></a>
1111
<h3>{{ default "Description about Blog Author" .Site.Params.subtitle }}</h3>
12+
<h3>From Transistor to AI.</h3>
1213
</div>
1314
</div>
1415
<nav class="navbar">

0 commit comments

Comments
 (0)