Initial Chisel core implementation

This commit is contained in:
abnerhexu
2026-06-26 08:20:25 +00:00
commit 502803c37f
47 changed files with 2342 additions and 0 deletions

98
sim/README.md Normal file
View File

@@ -0,0 +1,98 @@
# RISC-V Processor Simulation Environment
## 目录结构
```
sim/
├── verilator/ # Verilator仿真环境
│ ├── testbench.cpp # 主测试平台
│ ├── memory.cpp/h # 内存模型
│ └── Makefile # 构建脚本
├── scripts/ # 测试脚本
│ └── run_tests.sh # 批量测试运行器
└── waves/ # 波形文件输出目录
```
## 快速开始
### 1. 编译测试平台
```bash
cd sim/verilator
make compile
```
这会:
- 从Chisel生成Verilog代码
- 使用Verilator编译C++测试平台
### 2. 运行单个测试
```bash
make run TEST=../../riscv-tests/isa/rv64ui-p-add
```
或直接运行:
```bash
./obj_dir/VCore ../../riscv-tests/isa/rv64ui-p-add
```
### 3. 运行所有测试
```bash
cd ../scripts
./run_tests.sh
```
查看结果:
```bash
cat test_results.txt
```
## 测试结果说明
- **PASS**: 测试通过 (tohost写入1)
- **FAIL**: 测试失败 (tohost写入错误码)
- **TIMEOUT**: 测试超时 (超过100,000周期)
## tohost/fromhost 协议
- **tohost地址**: 0x80001000
- **fromhost地址**: 0x80001040
- **内存基址**: 0x80000000
- **内存大小**: 64MB
测试程序通过向tohost地址写入来报告结果
- `tohost = 1`: 测试通过
- `tohost = (error_code << 1) | 1`: 测试失败
## 依赖项
- Verilator (>= 4.0)
- Scala/SBT (Chisel编译)
- C++14编译器
- libelf-dev (ELF文件解析)
## 故障排查
### 编译错误
如果Verilator编译失败检查
1. Verilog是否正确生成在 `generated/` 目录
2. Core模块的IO接口定义
### 测试超时
如果测试一直超时:
1. 增加 `MAX_CYCLES` 在 testbench.cpp
2. 检查处理器是否正确执行指令
3. 验证内存接口握手逻辑
### 内存访问错误
检查:
1. ELF加载是否成功
2. 内存地址映射是否正确
3. 链接脚本中的地址与 `MEM_BASE` 一致