Skip to content

Commit

Permalink
[Spike tandem] Revive spike tandem infrastructure
Browse files Browse the repository at this point in the history
* Makefile (defines): Fix comment.
  (spike-tandem): Set default to empty (= disabled).
  (spike tandem verification): Change guarding condition.  Adjust CFLAGS.
  Do not require definition of 'preload' (obsolete).
  (dpi): Change guarding condition.
  (CFLAGS): Use Spike headers from Spike installation dir.
  (src): Add mock_uart.
  (tbs): Add spike.sv when building in Spike tandem mode.  Break long line.
  (questa-cmd): Use Spike library from Spike installation dir.
  (vcs): Move +permissive to the start of arg list.  Add libriscv library
  when in Spike tandem mode.
  (dpi_build): New.
* core/decoder.sv: Always enable WFI.
* core/include/ariane_pkg.sv: Remove parameters ENABLE_CYCLE_COUNT and
  ENABLE_WFI.  Fix and update
* corev_apu/tb/ariane_tb.sv: Use RVFI to pass CVA6 state when in Spike
  tandem mode.  Reformat UVM message.
* corev_apu/tb/common/spike.sv: Use RFVI to pass CVA6 state.  Guard parts
  of code with "`ifdef SPIKE_MISSING_DATA" when no suitable Spike data is
  available.  Add progress messages.  Use extended ANSI coloring for
  mismatch messages.
* corev_apu/tb/ariane_tb.sv (spike): Add comment about parameterization
  of the CVA6 core.
* Disabling JTAG and its DPI module as it has
  dependencies with ariane_dpi. Ariane DPI
  has to be refactored
* Makefile:
  adding rvfi_pkg
  adding absolute paths to the incdir to avoid relative path issues
  move spike.sv from tbs to src
* core/cva6.sv:
  change tval for new instr field of the scoreboard_entry_t
  change trap to support all kinds of exceptions and interrupts
* core/decoder.sv:
  change tval for 0 and add the old tval value to instr field
* core/include/ariane_pkg.sv:
  add instr field on scoreboard_entry_t
* core/include/rvfi_pkg.sv:
  new file that has st_rvfi struct, compare function, spike init function
* corev_apu/tb/common/spike.sv
  change module to support rvfi_pkg
* verif/env/uvme/uvme_cva6_cfg.sv:
  rename scooreboarding_enable to scoreboard_enable
  rvfi_cfg.nret now properly set
* verif/env/uvme/uvme_cva6_constants.sv:
  delete RVFI_NRET to avoid misconfigurations
* verif/env/uvme/uvme_cva6_env.sv:
  rename scoreboarding
  unify rvfi_monitors into one
* verif/env/uvme/uvme_cva6_pkg.sv:
  add cva6_config_pkg to be available in the components
* verif/regress/install-spike.sh:
  change SPIKE_SRC_DIR to core-v-verif
 * verif/sim/Makefile:
  avoid reconfigure if a config.log exists
  add core_v_verif variable
  add spike-tandem variable
  add elfloader lib instead of ariane_dpi
* verif/sim/cva6.py:
  solve trailing issues
* verif/sim/cva6.yaml:
  delete steps variable #TODO add new timeout impl
* verif/sim/cva6_spike_log_to_trace_csv.py:
  adapt for new spike impl
* verif/tb/uvmt/cva6_tb_wrapper.sv:
  PRELOAD to elf_file
* verif/tb/uvmt/uvmt_cva6_pkg.sv:
  add rvfi_pkg
* verif/tb/uvmt/uvmt_cva6_tb.sv:
  add localparam RVFI_NRET
  add rvfi_cause
* verif/tests/uvmt/compliance-tests/uvmt_cva6_firmware_test.sv:
  add factory override for spike
* remove lib/dpi_dasm in favor of dpidasm of riscv-isa-sim
* change ariane_tb to use new spike libfesvr dpi functions
  • Loading branch information
MarioOpenHWGroup committed Oct 26, 2023
1 parent 53d3880 commit 3ad63b5
Show file tree
Hide file tree
Showing 30 changed files with 327 additions and 642 deletions.
18 changes: 18 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ smoke:
- source verif/regress/smoke-tests.sh
- !reference [.simu_after_script]

smoke-tandem:
extends:
- .fe_smoke_test
variables:
DASHBOARD_JOB_TITLE: "Smoke test $DV_SIMULATORS with tandem"
DASHBOARD_JOB_DESCRIPTION: "Short tests to challenge most architectures with most testbenchs configurations"
DASHBOARD_SORT_INDEX: 0
DASHBOARD_JOB_CATEGORY: "Basic"
SPIKE_TANDEM: 1
parallel:
matrix:
- DV_SIMULATORS:
- "vcs-testharness,spike"
- "vcs-uvm,spike"
script:
- source verif/regress/smoke-tests.sh
- !reference [.simu_after_script]

gen_smoke:
extends:
- .fe_smoke_test
Expand Down
50 changes: 28 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ VMAP ?= vmap$(questa_version)
verilator ?= $(PWD)/tmp/verilator-v5.008/verilator/bin/verilator
# traget option
target-options ?=
# additional definess
# additional defines
defines ?=
# test name for torture runs (binary name)
test-location ?= output/test
Expand Down Expand Up @@ -58,7 +58,9 @@ ifndef RISCV
$(error RISCV not set - please point your RISCV variable to your RISCV installation)
endif

# By default assume spike resides at $(root-dir)/tools/spike prefix.
# Spike tandem mode: default to environment setting (DISABLED if envariable SPIKE_TANDEM is not set).
spike-tandem ?= $(SPIKE_TANDEM)

SPIKE_INSTALL_DIR ?= $(root-dir)/tools/spike

# setting additional xilinx board parameters for the selected board
Expand All @@ -79,11 +81,10 @@ $(error Unknown board - please specify a supported FPGA board)
endif

# spike tandem verification
ifdef spike-tandem
ifneq ($(spike-tandem),)
compile_flag += -define SPIKE_TANDEM
ifndef preload
$(error Tandem verification requires preloading)
endif
CFLAGS += -I. -I$(SPIKE_INSTALL_DIR)/include/riscv
defines += +SPIKE_TANDEM=1
endif

# target takes one of the following cva6 hardware configuration:
Expand Down Expand Up @@ -123,14 +124,15 @@ test_pkg := $(wildcard tb/test/*/*sequence_pkg.sv*) \
dpi := $(patsubst corev_apu/tb/dpi/%.cc, ${dpi-library}/%.o, $(wildcard corev_apu/tb/dpi/*.cc))

# filter spike stuff if tandem is not activated
ifndef spike-tandem
ifeq ($(spike-tandem),)
dpi := $(filter-out ${dpi-library}/spike.o ${dpi-library}/sim_spike.o, $(dpi))
endif

dpi_hdr := $(wildcard corev_apu/tb/dpi/*.h)
dpi_hdr := $(addprefix $(root-dir), $(dpi_hdr))
CFLAGS += -I$(QUESTASIM_HOME)/include \
-I$(VCS_HOME)/include \
-I$(VL_INC_DIR)/vltstd \
-I$(RISCV)/include \
-I$(SPIKE_INSTALL_DIR)/include \
-std=c++17 -I../corev_apu/tb/dpi -O3
Expand All @@ -141,13 +143,10 @@ else
$(warning XCELIUM_HOME not set which is necessary for compiling DPIs when using XCELIUM)
endif

ifdef spike-tandem
CFLAGS += -Itb/riscv-isa-sim/install/include/spike
endif


# this list contains the standalone components
src := core/include/$(target)_config_pkg.sv \
$(if $(spike-tandem),core/include/rvfi_pkg.sv) \
$(if $(spike-tandem),corev_apu/tb/common/spike.sv) \
corev_apu/src/ariane.sv \
$(wildcard corev_apu/bootrom/*.sv) \
$(wildcard corev_apu/clint/*.sv) \
Expand Down Expand Up @@ -198,6 +197,7 @@ src := core/include/$(target)_config_pkg.sv
corev_apu/tb/ariane_peripherals.sv \
corev_apu/tb/rvfi_tracer.sv \
corev_apu/tb/common/uart.sv \
corev_apu/tb/common/mock_uart.sv \
corev_apu/tb/common/SimDTM.sv \
corev_apu/tb/common/SimJTAG.sv

Expand All @@ -215,6 +215,7 @@ fpga_src := $(addprefix $(root-dir), $(fpga_src))

# look for testbenches
tbs := core/include/$(target)_config_pkg.sv corev_apu/tb/ariane_tb.sv corev_apu/tb/ariane_testharness.sv

tbs := $(addprefix $(root-dir), $(tbs))

# RISCV asm tests and benchmark setup (used for CI)
Expand All @@ -233,7 +234,9 @@ riscv-fp-tests := $(shell xargs printf '\n%s' < $(riscv-fp-tests-list
riscv-benchmarks := $(shell xargs printf '\n%s' < $(riscv-benchmarks-list) | cut -b 1-)

# Search here for include files (e.g.: non-standalone components)
incdir := vendor/pulp-platform/common_cells/include/ vendor/pulp-platform/axi/include/ corev_apu/register_interface/include/
incdir := $(CVA6_REPO_DIR)/vendor/pulp-platform/common_cells/include/ $(CVA6_REPO_DIR)/vendor/pulp-platform/axi/include/ \
$(CVA6_REPO_DIR)/corev_apu/register_interface/include/ $(CVA6_REPO_DIR)/corev_apu/tb/common/ \
$(CVA6_REPO_DIR)/vendor/pulp-platform/axi/include/ $(CVA6_REPO_DIR)/verif/core-v-verif/lib/uvm_agents/uvma_rvfi/

# Compile and sim flags
compile_flag += +cover=bcfst+/dut -incr -64 -nologo -quiet -suppress 13262 -permissive -svinputport=compat +define+$(defines)
Expand Down Expand Up @@ -267,7 +270,7 @@ ifdef preload
endif

ifdef spike-tandem
questa-cmd += -gblso tb/riscv-isa-sim/install/lib/libriscv.so
questa-cmd += -gblso $(SPIKE_INSTALL_DIR)/lib/libriscv.so
endif

# remote bitbang is enabled
Expand All @@ -280,16 +283,19 @@ endif
vcs_build: $(dpi-library)/ariane_dpi.so
mkdir -p $(vcs-library)
cd $(vcs-library) &&\
vlogan $(if $(VERDI), -kdb,) -full64 -nc -sverilog +define+$(defines) -assert svaext -f ../core/Flist.cva6 &&\
vlogan $(if $(VERDI), -kdb,) -full64 -nc -sverilog +define+$(defines) -assert svaext -f ../core/Flist.cva6 $(list_incdir) &&\
vlogan $(if $(VERDI), -kdb,) -full64 -nc -sverilog +define+$(defines) $(filter %.sv,$(ariane_pkg)) +incdir+core/include/+$(VCS_HOME)/etc/uvm-1.2/dpi &&\
vhdlan $(if $(VERDI), -kdb,) -full64 -nc $(filter %.vhd,$(uart_src)) &&\
vlogan $(if $(VERDI), -kdb,) -full64 -nc -sverilog -assert svaext +define+$(defines) $(filter %.sv,$(src)) +incdir+../vendor/pulp-platform/common_cells/include/+../vendor/pulp-platform/axi/include/+../corev_apu/register_interface/include/ &&\
vlogan $(if $(VERDI), -kdb,) -full64 -nc -sverilog -assert svaext +define+$(defines) +incdir+$(VCS_HOME)/etc/uvm/src $(VCS_HOME)/etc/uvm/src/uvm_pkg.sv $(filter %.sv,$(src)) $(list_incdir) &&\
vlogan $(if $(VERDI), -kdb,) -full64 -nc -sverilog -ntb_opts uvm-1.2 &&\
vlogan $(if $(VERDI), -kdb,) -full64 -nc -sverilog -ntb_opts uvm-1.2 $(tbs) +define+$(defines) +incdir+../vendor/pulp-platform/axi/include/ &&\
vlogan $(if $(VERDI), -kdb,) -full64 -nc -sverilog -ntb_opts uvm-1.2 $(tbs) +define+$(defines) $(list_incdir) &&\
vcs $(if $(VERDI), -kdb -debug_access+all -lca,) -full64 -timescale=1ns/1ns -ntb_opts uvm-1.2 work.ariane_tb -error="IWNF"

vcs: vcs_build
cd $(vcs-library) && ./simv $(if $(VERDI), -verdi -do $(root-dir)/util/init_testharness.do,) +permissive -sv_lib ../work-dpi/ariane_dpi +PRELOAD=$(elf-bin) +permissive-off ++$(elf-bin)| tee vcs.log
cd $(vcs-library) && \
./simv +permissive $(if $(VERDI), -verdi -do $(root-dir)/init_testharness.do,) \
+PRELOAD=$(elf-bin) ++$(elf-bin) $(if $(spike-tandem),-sv_lib $(SPIKE_INSTALL_DIR)/libriscv) \
-sv_lib ../work-dpi/ariane_dpi | tee vcs.log

# Build the TB and module using QuestaSim
build: $(library) $(library)/.build-srcs $(library)/.build-tb $(dpi-library)/ariane_dpi.so
Expand Down Expand Up @@ -322,7 +328,7 @@ $(dpi-library)/%.o: corev_apu/tb/dpi/%.cc $(dpi_hdr)
$(dpi-library)/ariane_dpi.so: $(dpi)
mkdir -p $(dpi-library)
# Compile C-code and generate .so file
$(CXX) -shared -m64 -o $(dpi-library)/ariane_dpi.so $? -L$(RISCV)/lib -L$(SPIKE_INSTALL_DIR)/lib -Wl,-rpath,$(RISCV)/lib -Wl,-rpath,$(SPIKE_INSTALL_DIR)/lib -lfesvr
$(CXX) -shared -m64 -o $(dpi-library)/ariane_dpi.so $? -L$(RISCV)/lib -L$(SPIKE_INSTALL_DIR)/lib -Wl,-rpath,$(RISCV)/lib -Wl,-rpath,$(SPIKE_INSTALL_DIR)/lib -lfesvr -lriscv

# single test runs on Questa can be started by calling make <testname>, e.g. make towers.riscv
# the test names are defined in ci/riscv-asm-tests.list, and in ci/riscv-benchmarks.list
Expand All @@ -335,7 +341,7 @@ generate-trace-vsim:
sim: build
$(VSIM) +permissive $(questa-flags) $(questa-cmd) -lib $(library) +MAX_CYCLES=$(max_cycles) +UVM_TESTNAME=$(test_case) \
+BASEDIR=$(riscv-test-dir) $(uvm-flags) $(QUESTASIM_FLAGS) -gblso $(SPIKE_INSTALL_DIR)/lib/libfesvr.so -sv_lib $(dpi-library)/ariane_dpi \
${top_level}_optimized +permissive-off ++$(elf-bin) ++$(target-options) | tee sim.log
${top_level}_optimized +permissive-off +PRELOAD=$(elf-bin) ++$(target-options) | tee sim.log

$(riscv-asm-tests): build
$(VSIM) +permissive $(questa-flags) $(questa-cmd) -lib $(library) +max-cycles=$(max_cycles) +UVM_TESTNAME=$(test_case) \
Expand Down Expand Up @@ -561,16 +567,16 @@ verilate_command := $(verilator) --no-timing verilator_config.vlt
$(if $(DEBUG), --trace-structs,) \
$(if $(TRACE_COMPACT), --trace-fst $(VL_INC_DIR)/verilated_fst_c.cpp) \
$(if $(TRACE_FAST), --trace $(VL_INC_DIR)/verilated_vcd_c.cpp) \
-LDFLAGS "-L$(RISCV)/lib -L$(SPIKE_INSTALL_DIR)/lib -Wl,-rpath,$(RISCV)/lib -Wl,-rpath,$(SPIKE_INSTALL_DIR)/lib -lfesvr$(if $(PROFILE), -g -pg,) -lpthread $(if $(TRACE_COMPACT), -lz,)" \
-LDFLAGS "-L$(RISCV)/lib -L$(SPIKE_INSTALL_DIR)/lib -Wl,-rpath,$(RISCV)/lib -Wl,-rpath,$(SPIKE_INSTALL_DIR)/lib -lfesvr -lriscv $(if $(PROFILE), -g -pg,) -lpthread $(if $(TRACE_COMPACT), -lz,)" \
-CFLAGS "$(CFLAGS)$(if $(PROFILE), -g -pg,) -DVL_DEBUG" \
$(if $(SPIKE_TANDEM), +define+SPIKE_TANDEM, ) \
--cc --vpi \
$(list_incdir) --top-module ariane_testharness \
--threads-dpi none \
--Mdir $(ver-library) -O3 \
--exe corev_apu/tb/ariane_tb.cpp corev_apu/tb/dpi/SimDTM.cc corev_apu/tb/dpi/SimJTAG.cc \
corev_apu/tb/dpi/remote_bitbang.cc corev_apu/tb/dpi/msim_helper.cc


# User Verilator, at some point in the future this will be auto-generated
verilate:
@echo "[Verilator] Building Model$(if $(PROFILE), for Profiling,)"
Expand Down
2 changes: 1 addition & 1 deletion core/csr_regfile.sv
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ module csr_regfile
end
instret_d = instret;
// increment the cycle count
if (ENABLE_CYCLE_COUNT && !mcountinhibit_q[0]) cycle_d = cycle_q + 1'b1;
if (!mcountinhibit_q[0]) cycle_d = cycle_q + 1'b1;
else cycle_d = instret;
end

Expand Down
28 changes: 8 additions & 20 deletions core/cva6.sv
Original file line number Diff line number Diff line change
Expand Up @@ -1314,19 +1314,19 @@ module cva6
for (int i = 0; i < CVA6ExtendCfg.NrCommitPorts; i++) begin
if (commit_ack[i] && !commit_instr_id_commit[i].ex.valid) begin
$fwrite(f, "%d 0x%0h %s (0x%h) DASM(%h)\n", cycles, commit_instr_id_commit[i].pc, mode,
commit_instr_id_commit[i].ex.tval[31:0], commit_instr_id_commit[i].ex.tval[31:0]);
commit_instr_id_commit[i].ex.tval[31:0], commit_instr_id_commit[i].instr[31:0]);
end else if (commit_ack[i] && commit_instr_id_commit[i].ex.valid) begin
if (commit_instr_id_commit[i].ex.cause == 2) begin
$fwrite(f, "Exception Cause: Illegal Instructions, DASM(%h) PC=%h\n",
commit_instr_id_commit[i].ex.tval[31:0], commit_instr_id_commit[i].pc);
commit_instr_id_commit[i].instr[31:0], commit_instr_id_commit[i].pc);
end else begin
if (debug_mode) begin
$fwrite(f, "%d 0x%0h %s (0x%h) DASM(%h)\n", cycles, commit_instr_id_commit[i].pc,
mode, commit_instr_id_commit[i].ex.tval[31:0],
mode, commit_instr_id_commit[i].instr[31:0],
commit_instr_id_commit[i].ex.tval[31:0]);
end else begin
$fwrite(f, "Exception Cause: %5d, DASM(%h) PC=%h\n",
commit_instr_id_commit[i].ex.cause, commit_instr_id_commit[i].ex.tval[31:0],
commit_instr_id_commit[i].ex.cause, commit_instr_id_commit[i].instr[31:0],
commit_instr_id_commit[i].pc);
end
end
Expand All @@ -1345,28 +1345,16 @@ module cva6
if (IsRVFI) begin
always_comb begin
for (int i = 0; i < CVA6ExtendCfg.NrCommitPorts; i++) begin
logic exception, mem_exception;
logic exception;
exception = commit_instr_id_commit[i].valid && ex_commit.valid;
mem_exception = exception &&
(ex_commit.cause == riscv::INSTR_ADDR_MISALIGNED ||
ex_commit.cause == riscv::INSTR_ACCESS_FAULT ||
ex_commit.cause == riscv::ILLEGAL_INSTR ||
ex_commit.cause == riscv::LD_ADDR_MISALIGNED ||
ex_commit.cause == riscv::LD_ACCESS_FAULT ||
ex_commit.cause == riscv::ST_ADDR_MISALIGNED ||
ex_commit.cause == riscv::ST_ACCESS_FAULT ||
ex_commit.cause == riscv::INSTR_PAGE_FAULT ||
ex_commit.cause == riscv::LOAD_PAGE_FAULT ||
ex_commit.cause == riscv::STORE_PAGE_FAULT);
// when rvfi_valid, the instruction is executed
rvfi_o[i].valid = (commit_ack[i] && !ex_commit.valid) ||
(exception && (ex_commit.cause == riscv::ENV_CALL_MMODE ||
ex_commit.cause == riscv::ENV_CALL_SMODE ||
ex_commit.cause == riscv::ENV_CALL_UMODE));
rvfi_o[i].insn = ex_commit.valid ? ex_commit.tval[31:0] : commit_instr_id_commit[i].ex.tval[31:0];
rvfi_o[i].insn = commit_instr_id_commit[i].instr[31:0];
// when trap, the instruction is not executed
rvfi_o[i].trap = mem_exception;
rvfi_o[i].cause = ex_commit.cause;
rvfi_o[i].trap = exception;
rvfi_o[i].cause = commit_instr_id_commit[i].ex.cause;
rvfi_o[i].mode = debug_mode ? 2'b10 : priv_lvl;
rvfi_o[i].ixl = riscv::XLEN == 64 ? 2 : 1;
rvfi_o[i].rs1_addr = commit_instr_id_commit[i].rs1[4:0];
Expand Down
3 changes: 2 additions & 1 deletion core/decoder.sv
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ module decoder
end
// WFI
12'b1_0000_0101: begin
if (ENABLE_WFI) instruction_o.op = ariane_pkg::WFI;
instruction_o.op = ariane_pkg::WFI;
// if timeout wait is set, trap on an illegal instruction in S Mode
// (after 0 cycles timeout)
if (priv_lvl_i == riscv::PRIV_LVL_S && tw_i) begin
Expand Down Expand Up @@ -1301,6 +1301,7 @@ module decoder
if (~ex_i.valid) begin
// if we didn't already get an exception save the instruction here as we may need it
// in the commit stage if we got a access exception to one of the CSR registers
instruction_o.instr = (is_compressed_i) ? {{riscv::XLEN-16{1'b0}}, compressed_instr_i} : {{riscv::XLEN-32{1'b0}}, instruction_i};
instruction_o.ex.tval = (is_compressed_i) ? {{riscv::XLEN-16{1'b0}}, compressed_instr_i} : {{riscv::XLEN-32{1'b0}}, instruction_i};
// instructions which will throw an exception are marked as valid
// e.g.: they can be committed anytime and do not need to wait for any functional unit
Expand Down
14 changes: 5 additions & 9 deletions core/include/ariane_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,17 @@ package ariane_pkg;
// enables a commit log which matches spikes commit log format for easier trace comparison
localparam bit ENABLE_SPIKE_COMMIT_LOG = 1'b1;

// ------------- Dangerouse -------------
// ------------- Dangerous -------------
// if set to zero a flush will not invalidate the cache-lines, in a single core environment
// where coherence is not necessary this can improve performance. This needs to be switched on
// when more than one core is in a system
localparam logic INVALIDATE_ON_FLUSH = 1'b1;

`ifdef SPIKE_TANDEM
// enable performance cycle counter, if set to zero mcycle will be incremented
// with instret (non RISC-V conformal)
localparam bit ENABLE_CYCLE_COUNT = 1'b0;
// mark WIF as nop
localparam bit ENABLE_WFI = 1'b0;
// Spike zeros tval on all exception except memory faults
// Spike still places 0 in TVAL for ENV_CALL_* exceptions.
// This may eventually go away when Spike starts to handle TVAL for *all* exceptions.
localparam bit ZERO_TVAL = 1'b1;
`else
localparam bit ENABLE_CYCLE_COUNT = 1'b1;
localparam bit ENABLE_WFI = 1'b1;
localparam bit ZERO_TVAL = 1'b0;
`endif
// read mask for SSTATUS over MMSTATUS
Expand Down Expand Up @@ -689,6 +684,7 @@ package ariane_pkg;

typedef struct packed {
logic [riscv::VLEN-1:0] pc; // PC of instruction
riscv::xlen_t instr; // Instruction value
logic [TRANS_ID_BITS-1:0] trans_id; // this can potentially be simplified, we could index the scoreboard entry
// with the transaction id in any case make the width more generic
fu_t fu; // functional unit to use
Expand Down
22 changes: 22 additions & 0 deletions core/include/rvfi_pkg.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
`ifndef __UVMA_RVFI_PKG_SV__
`define __UVMA_RVFI_PKG_SV__

// Pre-processor macros
`ifdef VERILATOR
`define uvm_info(TOP,MSG,LVL) \
$display(TOP + ":" + MSG);
`define uvm_fatal(TOP,MSG) \
$display(TOP + ":" + MSG); $finish();
`else
`include "uvm_macros.svh"
`endif

package rvfi_pkg;

`include "uvma_rvfi_constants.sv"
`include "uvma_rvfi_tdefs.sv"
`include "uvma_rvfi_utils.sv"

endpackage

`endif
27 changes: 18 additions & 9 deletions corev_apu/tb/ariane_tb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ void handle_sigterm(int sig) {
dtm->stop();
}


extern "C" void read_elf(const char* filename);
extern "C" int64_t read_symbol(const char* symbol, uint64_t* address);
extern "C" char get_section (long long* address, long long* len);
extern "C" void read_section_void(long long address, void * buffer, uint64_t size = 0);

// Called by $time in Verilog converts to double, to match what SystemC does
double sc_time_stamp () {
return main_time;
Expand Down Expand Up @@ -285,11 +291,7 @@ int main(int argc, char **argv) {

std::unique_ptr<Variane_testharness> top(new Variane_testharness);

// Use an hitf hexwriter to read the binary data.
htif_hexwriter_t htif(0x0, 1, -1);
memif_t memif(&htif);
reg_t entry;
load_elf(htif_argv[1], &memif, &entry);
read_elf(htif_argv[1]);

#if VM_TRACE
Verilated::traceEverOn(true); // Verilator must compute traced signals
Expand Down Expand Up @@ -335,15 +337,22 @@ int main(int argc, char **argv) {
top->rst_ni = 1;

// Preload memory.
size_t mem_size = 0xFFFFFF;
#if (VERILATOR_VERSION_INTEGER >= 5000000)
// Verilator v5: Use rootp pointer and .data() accessor.
memif.read(0x80000000, mem_size, (void *)top->rootp->ariane_testharness__DOT__i_sram__DOT__gen_cut__BRA__0__KET____DOT__i_tc_sram_wrapper__DOT__i_tc_sram__DOT__sram.m_storage);
#define MEM top->rootp->ariane_testharness__DOT__i_sram__DOT__gen_cut__BRA__0__KET____DOT__i_tc_sram_wrapper__DOT__i_tc_sram__DOT__sram.m_storage
#else
// Verilator v4
memif.read(0x80000000, mem_size, (void *)top->ariane_testharness__DOT__i_sram__DOT__gen_cut__BRA__0__KET____DOT__i_tc_sram_wrapper__DOT__i_tc_sram__DOT__sram);
#define MEM top->ariane_testharness__DOT__i_sram__DOT__gen_cut__BRA__0__KET____DOT__i_tc_sram_wrapper__DOT__i_tc_sram__DOT__sram
#endif
// memif.read(0x84000000, mem_size, (void *)top->ariane_testharness__DOT__i_sram__DOT__gen_cut__BRA__0__KET____DOT__gen_mem__DOT__gen_mem_user__DOT__i_tc_sram_wrapper_user__DOT__i_tc_sram__DOT__sram);
long long addr;
long long len;

size_t mem_size = 0xFFFFFF;
while(get_section(&addr, &len))
{
if (addr == 0x80000000)
read_section_void(addr, (void *) MEM , mem_size);
}

while (!dtm->done() && !jtag->done() && !(top->exit_o & 0x1)) {
top->clk_i = 0;
Expand Down
Loading

0 comments on commit 3ad63b5

Please sign in to comment.