【一生一芯03】verilator仿真框架搭建

目录

1 verilator介绍

1.1 简介

1.2 安装

1.3 hello,world

2 npc仿真框架搭建

2.1 sim_main.cpp

2.1.1 头文件引用

2.1.2 仿真环境

2.1.3 主函数

2.1.4 执行函数

 2.1.5 内存初始化

2.1.6 基础设施

2.2 Makefile文件构建

3 Dpi-C机制

3.1 ebreak

3.2 env

3.3 访存

3.4 寄存器


1 verilator介绍

verilator详细内容可以查看官方手册Overview — Verilator 5.003 documentation

1.1 简介

Verilator是一种开源的Verilog/SystemVerilog仿真器,可用于编译代码以及代码在线检查,Verilator能够读取Verilog或者SystemVerilog文件,并进行lint checks(基于lint工具的语法检测),并最终将其转换成C++的源文件.cpp和.h。

Verilator不直接将Verilog HDL转换为C++或者SystemC,反之Verilator将代码编译成更快的优化过的并且支持多线程的模型,该模型被依次包装在(wrapped)在C++/SystemC模型中。这样就生成一个编译的Verilog模型,其功能和Verilog是一致的,但效率由于基于C++即使是单线程模型也可以10倍快于SystemC,100倍快于基于解释Verilog的仿真器,并且通过多线程可以进一步加速。

1.2 安装

# Prerequisites:
#sudo apt-get install git perl python3 make autoconf g++ flex bison ccache
#sudo apt-get install libgoogle-perftools-dev numactl perl-doc
#sudo apt-get install libfl2  # Ubuntu only (ignore if gives error)
#sudo apt-get install libfl-dev  # Ubuntu only (ignore if gives error)
#sudo apt-get install zlibc zlib1g zlib1g-dev  # Ubuntu only (ignore if gives error)

git clone https://github.com/verilator/verilator   # Only first time

# Every time you need to build:
unsetenv VERILATOR_ROOT  # For csh; ignore error if on bash
unset VERILATOR_ROOT  # For bash
cd verilator
git pull         # Make sure git repository is up-to-date
git tag          # See what versions exist
#git checkout master      # Use development branch (e.g. recent bug fixes)
#git checkout stable      # Use most recent stable release
#git checkout v{version}  # Switch to specified release version

autoconf         # Create ./configure script
./configure      # Configure and create Makefile
make -j `nproc`  # Build Verilator itself (if error, try just 'make')
sudo make install

1.3 hello,world

安装好verilator后可以在文件目录下找到官方提供的example。以make_hello_c为例

top.v文件

module top;
   initial begin
      $display("Hello World!");
      $finish;
   end
endmodule

sim_main.cpp文件

#include <verilated.h>// verilator官方库
#include "Vtop.h"//top.v会被封装为头文件供c++调用

int main(int argc, char** argv, char** env) {
    if (false && argc && argv && env) {}    
    Vtop* top = new Vtop;// 构建verilator模型,可以通过类型调用top中的参数
    while (!Verilated::gotFinish()) {// 开始仿真直到$finish 
        top->eval();// Evaluate model
    }
    top->final();//结束仿真    
    delete top;// 清除模型   
    return 0;// Return good completion status
}

 Makefile文件

ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
endif

default:
	@echo "-- Verilator hello-world simple example"
	@echo "-- VERILATE & BUILD --------"
	$(VERILATOR) -Wall -cc --exe --build -j top.v sim_main.cpp
	@echo "-- RUN ---------------------"
	obj_dir/Vtop
	@echo "-- DONE --------------------"
	@echo "Note: Once this example is understood, see examples/make_tracing_c."
	@echo "Note: Also see the EXAMPLE section in the verilator manpage/document."

Makefile用于文件构建,主要的语句只有

$(VERILATOR) -cc --exe --build -j top.v sim_main.cpp
  • -Wall:让verilator执行强类型警告
  • --cc<
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值