Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce basic Verilator support #48

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions hw/verilator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.tree
*.dot
Vtop*.cpp
Vtop*.h
Vtop*.mk
Vtop*.vpp
Vtop
Vtop.xml
Vtop*.a
Vtop__*.*
Vtop_061_order_edges.txt
33 changes: 33 additions & 0 deletions hw/verilator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include Vtop.mk

vpath %.v $(CURDIR)/../verilog
vpath %.v $(CURDIR)/../../3rdparty/wb_intercon/rtl/verilog

VFILES += top.v
VFILES += sim/simclocks.v
VFILES += tenyr.v
VFILES += ram.v
VFILES += seg7.v
VFILES += hex2segments.v
VFILES += gpio.v
VFILES += wb_mux.v

VFLAGS += -Wall
VFLAGS += -Wno-fatal
VFLAGS += -Wno-style

VFLAGS += -I$(CURDIR)/../verilog
VFLAGS += --cc --trace
VFLAGS += -DSIMCLK=tenyr_mainclock
VFLAGS += --Mdir $(CURDIR)
VFLAGS += --exe
# TODO drop --public-flat-rw
VFLAGS += --vpi --public-flat-rw

ifeq ($(DEBUG),1)
VFLAGS += --debug
CPPFLAGS += -DVL_DEBUG
endif

Vtop.mk: $(VFILES) sim_main.cpp
verilator $(VFLAGS) $^
67 changes: 67 additions & 0 deletions hw/verilator/sim_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "Vtop.h"

// If "verilator --trace" is used, include the tracing class
#if VM_TRACE
# include <verilated_vcd_c.h>
#endif

static const vluint64_t MAX_TIME = 1000000u;

// Current simulation time (64-bit unsigned)
vluint64_t main_time = 0;
// Called by $time in Verilog
double sc_time_stamp()
{
return static_cast< double >( main_time ); // Note does conversion to real, to match SystemC
}

static inline bool finished(const Vtop &top)
{
return main_time >= MAX_TIME
|| Verilated::gotFinish()
|| (top.reset == 0 && top.Tenyr__DOT__core__DOT__nextP == 0);
}

int main(int argc, char* argv[])
{
Verilated::commandArgs(argc, argv);

Vtop top;

#if VM_TRACE
// If verilator was invoked with --trace argument,
// and if at run time passed the +trace argument, turn on tracing
VerilatedVcdC* tfp = NULL;
const char* flag = Verilated::commandArgsPlusMatch("trace");
if (flag && 0==strcmp(flag, "+trace")) {
Verilated::traceEverOn(true); // Verilator must compute traced signals
VL_PRINTF("Enabling waves into logs/vlt_dump.vcd...\n");
tfp = new VerilatedVcdC;
top.trace(tfp, 99); // Trace 99 levels of hierarchy
Verilated::mkdir("logs");
tfp->open("logs/vlt_dump.vcd"); // Open the dump file
}
#endif

top.reset = 1;
top.clk = 0;

while (!finished(top)) {
top.clk = !top.clk;
if (main_time < 10)
top.Tenyr__DOT__core__DOT__nextP = 0x1000;
if (main_time > 10)
top.reset = 0;
top.eval();
printf("P = %08x\n", top.Tenyr__DOT__core__DOT__nextP);

#if VM_TRACE
// Dump trace data for this cycle
if (tfp) tfp->dump(main_time);
#endif

main_time++;
}

top.final();
}