寨亳 发表于 2025-9-3 11:45:52

Verilator手册:USER'S GUIDE (一)

本博客用于记录我在一生一芯学习中所在手册中使用的比较有用的tips,可以方便后人学习,后续可能会根据新找的慢慢更新。
我全部都看一遍并且翻译出比较有用且常用的内容列出来,方便大伙使用和学习。
1.Verilating

[*]With the --binary option, Verilator will translate the design into an executable, via generating C++ and compiling it.
[*]With the --cc or --sc options, Verilator will translate the design into C++ or SystemC code, respectively.
[*]With the --lint-only option, Verilator will lint the design to check for warnings but will not typically create any output files.
[*]使用--binary 选项,Verilator可以生成C++代码并进行编译,并生成可执行文件。
[*]使用--cc 或者 --sc选项,Verilator可以将设计转换为C++或者systemc代码。
[*]使用--lint-only选项,可以只用Verilator进行语法检查。我经常用这个检查RTL代码是否正确,但是逻辑检查还是用GDB和看波形比较合规。
2.Binary, C++ and SystemC Generation
可以使用--top-module来指定顶层模块。
3.Connecting to Verilated Models
Vysyx_25060170_top___024root.h 这个文件可以在gdb时候访问你RTL编译出来的变量,可以实时查看变量的值,方便你debug。

可以把他们的值p出来。
4.DPI Example
这个非常常用,用于Verilog调用C函数或者是C调用Verilog任务,常用于NPC获取指令、difftest、npc收到ebreak后正常退出等等。
如果要接收指令和当前指令的PC,可以使用下列的DPI-C,首先在仿真环境(c语言)中定义:
点击查看代码#include <verilated.h>
#include "Vysyx_25060170_top.h"   //包含top模块的顶层类

extern "C" void pc_inst_end(int thepc_data, int the_inst){
cpu.pc = thepc_data;
s.val = the_inst;
}然后要在Verilog那边使用这边的代码
点击查看代码import "DPI-C" function void pc_inst_end(input int thepc_data, input int the_inst);//引进来函数

always @(*) begin
    pmem_read(pc_i,inst_o,rlen);
    pc_inst_end(pc_i, inst_o);
end使用组合逻辑实时将当前的PC和指令传递给仿真环境。
DPI-C基本用法就这样,还有在C语言这边引用Verilog任务,这里大伙可以去查别的博客,也有写。
大概就是:先写一个task,然后extern出去,在C语言仿真环境那边需要定义一个作用域,然后就可以调用Verilog的task了。

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

栓汨渎 发表于 2025-12-19 07:34:22

感谢分享,下载保存了,貌似很强大

杆树 发表于 2025-12-22 03:19:45

很好很强大我过来先占个楼 待编辑

孓访懔 发表于 2026-1-14 01:49:23

喜欢鼓捣这些软件,现在用得少,谢谢分享!

炳裘垦 发表于 2026-1-19 11:29:22

热心回复!

坏级尹 发表于 2026-1-19 22:26:37

这个好,看起来很实用

告陕无 发表于 2026-1-23 10:08:28

谢谢分享,辛苦了

高小雨 发表于 2026-1-25 10:52:57

感谢分享

上官银柳 发表于 7 天前

懂技术并乐意极积无私分享的人越来越少。珍惜

周冰心 发表于 4 天前

前排留名,哈哈哈

方方仪 发表于 前天 13:17

感谢发布原创作品,程序园因你更精彩

眺愤 发表于 3 小时前

yyds。多谢分享
页: [1]
查看完整版本: Verilator手册:USER'S GUIDE (一)