Skip to content

Commit

Permalink
Merge branch 'chiplab'
Browse files Browse the repository at this point in the history
  • Loading branch information
eastonman committed May 11, 2022
2 parents e534b34 + 8402095 commit e706691
Show file tree
Hide file tree
Showing 78 changed files with 8,263 additions and 2,588 deletions.
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
vivado*

# VSCode configuration files
.vscode/
.vscode/*
!.vscode/extensions.json
!.vscode/settings.json

# Verilator output files
obj_dir/
Expand All @@ -28,6 +30,15 @@ src/emu-compile
src/emu
src/lock-emu
src/time.log
src/.history
la32-nemu-interpreter-so
test/*.bin
build/
test/*.s
build/

# Branch Predictor Test data
src/vsrc/branch_predictor/data

# System Verilog language server
.svlint.toml
.svls.toml
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"bmpenuelas.systemverilog-formatter-vscode",
"Gruntfuggly.todo-tree",
"mshr-h.veriloghdl",
"mhutchie.git-graph"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"verilog.linting.linter": "verilator",
"verilog.linting.iverilog.arguments": "",
"verilog.logging.enabled": true,
"verilog.linting.verilator.arguments": "-Isrc -Isrc/vsrc -Isrc/vsrc/pipeline/1_fetch -Wall -DCPU_2CMT",
"todo-tree.filtering.includeGlobs": [
"**/*.sv",
"**/*.v"
],
"todo-tree.regex.regex": "((\\s|^)($TAGS):)",
"todo-tree.regex.enableMultiLine": false,
"todo-tree.regex.regexCaseSensitive": true,
"todo-tree.general.debug": false,
"todo-tree.general.enableFileWatcher": true,
"todo-tree.filtering.includeHiddenFiles": true,
"todo-tree.filtering.includedWorkspaces": [
"**/*"
],
"todo-tree.filtering.useBuiltInExcludes": "file and search excludes",
"systemverilogFormatter.veribleBuild": "Ubuntu-20.04-focal-x86_64",
"systemverilogFormatter.commandLineArguments": "--indentation_spaces 4",
"editor.formatOnSave": true
}
39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,44 @@
## 目录结构

```
src/ CPU Verilog 源代码
SimTop.v 顶层Soc,用于连接核心和其他模块
SimTop_tb.v Vivado仿真testbench
ram.v 用于在仿真时读取inst_rom.data
inst_rom.data 存放内存初始内容
src/ CPU Verilog 源代码
SimTop.v 顶层Soc,用于连接核心和其他模块
SimTop_tb.v Vivado仿真testbench
ram.v 用于在仿真时读取inst_rom.data
inst_rom.data 存放内存初始内容
vsrc/ CPU 核心部分源码
pipeline/ 流水线部分
... 其他模块
vsrc/ CPU 核心部分源码
pipeline/ 流水线部分
AXI/ AXI 控制器
BPU/ 分支预测部件
frontend/ 流水线前端,负责取指并塞入Instruction Buffer
Makefile 用于自动化测试和Verilator仿真,无需关心
README.md 本文件
testbench.cpp 用于Verilator仿真,如果使用Vivado仿真,无需关心
cpu_top.sv CPU 内核顶层模块,目前含有ICache,Frontend,IB和流水线各级
同时是chiplab测试的入口,仅有AXI端口和外部中断端口
... 其他模块
Makefile 用于自动化测试和Verilator仿真,无需关心
README.md 本文件
testbench.cpp 用于Verilator仿真,如果使用Vivado仿真,无需关心
```

## 设计文档

- [前端设计](doc/frontend.md)
- [译码器设计](doc/instr_decode.md)
- [差分测试](doc/difftest.md)
- [AXI控制器](src/vsrc/AXI/README.md)
- [分支预测器](src/vsrc/BPU/README.md)
- [Chiplab对接](doc/chiplab.md)
- [Instruction Buffer设计](doc/instr_buffer.md)
- [每日一个 Verilog 小技巧](doc/verilog_tips.md)

## 代码规范

[代码规范](doc/coding_conventions.md)

## 开发流程

Expand Down
79 changes: 79 additions & 0 deletions doc/chiplab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 对接Chiplab文档

## CPU核模块
此处是指CPU内核部分的模块

一般来说包含:
- 流水线,ALU等核心部件
- AXI控制器
- 差分测试相关DPI

一般来说不包含:
- 仿真/综合/调试/chiplab等可能用到的各种RAM
- 各种AXI桥和AXI Slave

Chiplab要求的模块端口,接口均写死在Chiplab,如果要更改需要修改Chiplab的配置或源码

例外:双发射Chiplab有提供支持,参考最下面

```verilog
module cpu_top(
input aclk,
input aresetn,
input [ 7:0] intrpt,
//AXI interface
//read reqest
output [ 3:0] arid,
output [31:0] araddr,
output [ 7:0] arlen,
output [ 2:0] arsize,
output [ 1:0] arburst,
output [ 1:0] arlock,
output [ 3:0] arcache,
output [ 2:0] arprot,
output arvalid,
input arready,
//read back
input [ 3:0] rid,
input [31:0] rdata,
input [ 1:0] rresp,
input rlast,
input rvalid,
output rready,
//write request
output [ 3:0] awid,
output [31:0] awaddr,
output [ 7:0] awlen,
output [ 2:0] awsize,
output [ 1:0] awburst,
output [ 1:0] awlock,
output [ 3:0] awcache,
output [ 2:0] awprot,
output awvalid,
input awready,
//write data
output [ 3:0] wid,
output [31:0] wdata,
output [ 3:0] wstrb,
output wlast,
output wvalid,
input wready,
//write back
input [ 3:0] bid,
input [ 1:0] bresp,
input bvalid,
output bready,
//debug info
output [31:0] debug0_wb_pc,
output [ 3:0] debug0_wb_rf_wen,
output [ 4:0] debug0_wb_rf_wnum,
output [31:0] debug0_wb_rf_wdata
#ifdef CPU_2CMT
,
output [31:0] debug1_wb_pc,
output [ 3:0] debug1_wb_rf_wen,
output [ 4:0] debug1_wb_rf_wnum,
output [31:0] debug1_wb_rf_wdata
#endif
);
```
63 changes: 63 additions & 0 deletions doc/coding_conventions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 代码规范

## 缩进

统一使用 VS Code 插件 `bmpenuelas.systemverilog-formatter-vscode` 对代码进行自动格式化

注意使用`--indentation_spaces 4`

还应将`.v`文件关联到`SystemVerilog`以获得自动格式化,具体方法是点击VS Code右下角的`Verilog`,然后在弹出的窗口选择`Configure File Association for '.v'`

## 模块(module)

### 模块命名

使用蛇形命名,形如`aaa_bbb_ccc`

### 模块端口命名

一般来讲分为三个部分,每个部分之间通过下划线连接:
- 连接到的模块简称,如`icache`
- 信号线的含义,如`data`
- 信号的方向,`o``i`

全部连起来如`icache_data_o`

### 模块端口类型(SystemVerilog)

如果使用了SystemVerilog,那么尽量把意义相近的信号打包成struct,定义在头文件中,然后作为端口的类型

## 信号

### 信号命名

使用蛇形命名,在模块内部,不添加后缀`o``i`

### 状态机(SystemVerilog)

如果使用SystemVerilog,那么状态机的状态要求使用`enum`

如:
```verilog
enum int unsigned {
ACCEPT_ADDR = 0,
IN_TRANSACTION_1 = 1,
IN_TRANSACTION_2 = 2
}
```

### 模块间连线信号命名

约定实例化的模块间连接用的信号使用以下三部分命名:
- 起始模块名
- 到达模块名
- 信号含义

例如`frontend_icache_addr`

如果有多输出的信号,使用`multi`代替到达模块名

例如`ctrl_multi_stall`

注意无需`o``i`

9 changes: 9 additions & 0 deletions doc/frontend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 流水线前端设计

**目前实现的跳转不正确!!!**

## ICache 信号

## Instruction Buffer 信号

## 后端信号
46 changes: 46 additions & 0 deletions doc/instr_buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Instruction Buffer 设计

## 整体设计

使用类似状态机的写法,使用一个长度为`BUFFER_SIZE`的寄存器`buffer_queue`保存当前状态。
使用`read_ptr``write_ptr`记录后端和前端的读写位置。

更新逻辑:

根据后端当拍返回的可接受的指令,确定`read_ptr`的更新和`buffer_queue`对应位置的重置。

根据前端给出的指令更新`write_ptr`和对应位置的更新。

根据当前的两个ptr给出前端停顿的指令


## 前端信号

```verilog
// <-> Frontend
input instr_buffer_info_t frontend_instr_i[IF_WIDTH],
output logic frontend_stallreq_o, // Require frontend to stop
```
接受前端的两条指令,当拍给出`frontend_stallreq_o`

要求前端停顿时完全保持输入的两条指令不变

如果前端给出的两条指令不是都有效,那么要求有效的必须都在低位,而且保证指令的顺序关系,即低位对应指令流中靠前的指令。

## 后端信号

```verilog
// <-> Backend
input logic [ID_WIDTH-1:0] backend_accept_i, // Backend can accept 0 or more instructions, must return in current cycle!
input logic backend_flush_i, // Backend require flush, maybe branch miss
output instr_buffer_info_t backend_instr_o[ID_WIDTH]
```

`buffer_queue`的对应位置直接接到`backend_instr_o`,不保证两条指令都有效,甚至可能都无效(如初始时)

要求当拍返回`backend_accept_i`信号,如果接受指令,意思即这条指令会进入下一级,如果接受,返回的接受信号必须都在低位。

下一周期接受的指令将会被重置,然后顺序移动指令,即如果接受接受指令1,拒绝指令2,下一周期指令2将变为指令1,指令2为新的指令。

后端或ctrl 输入`backend_flush_i`的下一周期将全部`buffer_queue`刷空,因为`backend_instr_o`是直接接在`buffer_queue`上的,因此下一周期也变为空。

13 changes: 13 additions & 0 deletions doc/verilog_tips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 每日一个 Verilog 小技巧

## $clog2() 是可综合的

`$clog2()`是ceil(log2(x))的意思,2的对数的向上取整,常用于已知寻址范围,确定索引信号的位宽。

虽然看起来是一个系统调用,但是由于实在是过于好用,大部分的仿真和综合工具都支持处理这个函数。

## always块中最后一个赋值覆盖前面的

这很有用,如果想要实现带有优先级的组合逻辑,可以避免使用超级长的if-else判断,而是利用越后面的赋值优先级越高来代替if-else

当然,这可能带来高的延迟。
Binary file added inst_rom.bin
Binary file not shown.
Loading

0 comments on commit e706691

Please sign in to comment.