From 8645441d004b0da57d5193315c94564d1ca7a083 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 3 Jul 2024 16:52:16 -0700 Subject: [PATCH] Testbench automatically creates memfile, label, addr files if they are out of date or missing --- testbench/Makefile | 12 ++++++++++++ testbench/testbench.sv | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 testbench/Makefile diff --git a/testbench/Makefile b/testbench/Makefile new file mode 100644 index 000000000..8ad71f522 --- /dev/null +++ b/testbench/Makefile @@ -0,0 +1,12 @@ +# Makefile for testbench to create .memfile, .objdump.addr, and .objdump.lab from an ELF +# David_Harris@hmc.edu 3 July 2024 +# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 + +%.elf.memfile: %.elf + riscv64-unknown-elf-elf2hex --bit-width 64 --input $< --output $@ + +%.elf.objdump.addr: %.elf.objdump + extractFunctionRadix.sh $< + +%.elf.objdump: %.elf + riscv64-unknown-elf-objdump -S -D $< > $@ \ No newline at end of file diff --git a/testbench/testbench.sv b/testbench/testbench.sv index f6087da1b..003d4d9ae 100644 --- a/testbench/testbench.sv +++ b/testbench/testbench.sv @@ -54,11 +54,14 @@ module testbench; `ifdef VERILATOR import "DPI-C" function string getenvval(input string env_name); string RISCV_DIR = getenvval("RISCV"); // "/opt/riscv"; + string WALLY_DIR = getenvval("WALLY"); // ~/cvw typical `elsif VCS import "DPI-C" function string getenv(input string env_name); string RISCV_DIR = getenv("RISCV"); // "/opt/riscv"; + string WALLY_DIR = getenv("WALLY"); `else string RISCV_DIR = "$RISCV"; // "/opt/riscv"; + string WALLY_DIR = "$WALLY"; `endif `include "parameter-defs.vh" @@ -382,7 +385,7 @@ module testbench; // declare memory labels that interest us, the updateProgramAddrLabelArray task will find // the addr of each label and fill the array. To expand, add more elements to this array // and initialize them to zero (also initilaize them to zero at the start of the next test) - updateProgramAddrLabelArray(ProgramAddrMapFile, ProgramLabelMapFile, ProgramAddrLabelArray); + updateProgramAddrLabelArray(ProgramAddrMapFile, ProgramLabelMapFile, memfilename, WALLY_DIR, ProgramAddrLabelArray); end `ifdef VERILATOR // this macro is defined when verilator is used // Simulator Verilator has an issue that the validate logic below slows runtime 110x if it is @@ -931,10 +934,15 @@ endmodule task automatic updateProgramAddrLabelArray; /* verilator lint_off WIDTHTRUNC */ /* verilator lint_off WIDTHEXPAND */ - input string ProgramAddrMapFile, ProgramLabelMapFile; + input string ProgramAddrMapFile, ProgramLabelMapFile, memfilename, WALLY_DIR; inout integer ProgramAddrLabelArray [string]; // Gets the memory location of begin_signature integer ProgramLabelMapFP, ProgramAddrMapFP; + string cmd; + + // if memfile, label, or addr files are out of date or don't exist, generate them + cmd = {"make -f ", WALLY_DIR, "/testbench/Makefile ", memfilename, " ", ProgramAddrMapFile}; + $system(cmd); ProgramLabelMapFP = $fopen(ProgramLabelMapFile, "r"); ProgramAddrMapFP = $fopen(ProgramAddrMapFile, "r");