2024-04-20 21:12:55 +00:00
|
|
|
# Verilator Makefile for WALLY
|
|
|
|
# Kunlin Han, Rose Thompson, David Harris 2024
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
|
|
|
|
2024-04-17 01:54:11 +00:00
|
|
|
SHELL := /bin/bash
|
2024-04-12 03:02:20 +00:00
|
|
|
.PHONY: profile run questa clean
|
|
|
|
|
2024-04-17 01:54:11 +00:00
|
|
|
# verilator configurations
|
2024-04-12 03:02:20 +00:00
|
|
|
OPT=
|
2024-08-11 20:08:16 +00:00
|
|
|
PARAMS?=--no-trace-top
|
2024-04-12 03:02:20 +00:00
|
|
|
NONPROF?=--stats
|
2024-04-22 18:32:46 +00:00
|
|
|
VERILATOR_DIR=${WALLY}/sim/verilator
|
2024-04-23 17:19:08 +00:00
|
|
|
SOURCE=${WALLY}/config/shared/*.vh ${WALLY}/config/${WALLYCONF} ${WALLY}/config/deriv/${WALLYCONF} ${WALLY}/src/cvw.sv ${WALLY}/testbench/*.sv ${WALLY}/testbench/common/*.sv ${WALLY}/src/*/*.sv ${WALLY}/src/*/*/*.sv
|
2024-08-11 20:08:16 +00:00
|
|
|
PLUS_ARGS=
|
|
|
|
PARAM_ARGS=
|
|
|
|
EXPANDED_PARAM_ARGS:=$(patsubst %,-G%,$(PARAM_ARGS))
|
2024-04-22 18:35:18 +00:00
|
|
|
|
2024-04-12 03:02:20 +00:00
|
|
|
WALLYCONF?=rv64gc
|
|
|
|
TEST?=arch64i
|
2024-05-10 01:56:59 +00:00
|
|
|
TESTBENCH?=testbench
|
2024-04-12 03:02:20 +00:00
|
|
|
|
2024-04-17 01:54:11 +00:00
|
|
|
# constants
|
2024-04-17 16:52:54 +00:00
|
|
|
# assume WALLY variable is correctly configured in the shell environment
|
2024-04-17 01:54:11 +00:00
|
|
|
WORKING_DIR=${WALLY}/sim/verilator
|
|
|
|
TARGET=$(WORKING_DIR)/target
|
2024-04-17 16:52:54 +00:00
|
|
|
# INCLUDE_PATH are pathes that Verilator should search for files it needs
|
2024-04-17 01:54:11 +00:00
|
|
|
INCLUDE_PATH="-I${WALLY}/config/shared" "-I${WALLY}/config/$(WALLYCONF)" "-I${WALLY}/config/deriv/$(WALLYCONF)"
|
2024-04-17 16:52:54 +00:00
|
|
|
# SOURCES are source files
|
2024-07-19 22:08:47 +00:00
|
|
|
SOURCES=${WALLY}/src/cvw.sv ${WALLY}/testbench/${TESTBENCH}.sv ${WALLY}/testbench/common/*.sv ${WALLY}/src/*/*.sv ${WALLY}/src/*/*/*.sv ${WALLY}/addins/verilog-ethernet/*/*.sv ${WALLY}/addins/verilog-ethernet/*/*/*/*.sv
|
2024-04-17 16:52:54 +00:00
|
|
|
# DEPENDENCIES are configuration files and source files, which leads to recompilation of executables
|
|
|
|
DEPENDENCIES=${WALLY}/config/shared/*.vh $(SOURCES)
|
2024-04-17 01:54:11 +00:00
|
|
|
|
2024-05-10 01:56:59 +00:00
|
|
|
# regular testbench requires a wrapper defining getenvval
|
|
|
|
ifeq ($(TESTBENCH), testbench)
|
|
|
|
WRAPPER=${WALLY}/sim/verilator/wrapper.c
|
|
|
|
ARGTEST=+TEST=$(TEST)
|
|
|
|
else
|
|
|
|
WRAPPER=
|
|
|
|
ARGTEST=
|
|
|
|
endif
|
|
|
|
|
2024-04-12 03:02:20 +00:00
|
|
|
default: run
|
|
|
|
|
2024-05-10 01:56:59 +00:00
|
|
|
run: wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH}
|
2024-04-29 05:08:00 +00:00
|
|
|
mkdir -p $(VERILATOR_DIR)/logs
|
2024-08-10 19:18:54 +00:00
|
|
|
wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH} ${ARGTEST} $(PLUS_ARGS)
|
2024-06-19 21:25:31 +00:00
|
|
|
|
2024-05-10 01:56:59 +00:00
|
|
|
profile: obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF)
|
|
|
|
$(VERILATOR_DIR)/obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF) ${ARGTEST}
|
2024-04-12 03:02:20 +00:00
|
|
|
mv gmon.out gmon_$(WALLYCONF).out
|
2024-05-10 01:56:59 +00:00
|
|
|
gprof $(VERILATOR_DIR)/obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF) gmon_$(WALLYCONF).out > gmon_$(WALLYCONF).log
|
2024-04-12 03:02:20 +00:00
|
|
|
verilator_profcfunc gmon_$(WALLYCONF).log > gmon_$(WALLYCONF).log2
|
2024-04-22 18:32:46 +00:00
|
|
|
mkdir -p $(VERILATOR_DIR)/logs_profiling
|
|
|
|
mv gmon_$(WALLYCONF)* $(VERILATOR_DIR)/logs_profiling
|
|
|
|
echo "Please check $(VERILATOR_DIR)/logs_profiling/gmon_$(WALLYCONF)* for logs and output files."
|
2024-04-12 03:02:20 +00:00
|
|
|
|
2024-05-10 01:56:59 +00:00
|
|
|
wkdir/$(WALLYCONF)_$(TEST)/V${TESTBENCH}: $(DEPENDENCIES)
|
2024-04-30 17:48:42 +00:00
|
|
|
mkdir -p wkdir/$(WALLYCONF)_$(TEST)
|
2024-04-22 18:32:46 +00:00
|
|
|
verilator \
|
2024-05-10 01:56:59 +00:00
|
|
|
--Mdir wkdir/$(WALLYCONF)_$(TEST) -o V${TESTBENCH} \
|
2024-04-22 20:03:51 +00:00
|
|
|
--binary --trace \
|
2024-04-12 03:02:20 +00:00
|
|
|
$(OPT) $(PARAMS) $(NONPROF) \
|
2024-05-10 01:56:59 +00:00
|
|
|
--top-module ${TESTBENCH} --relative-includes \
|
2024-04-23 17:19:08 +00:00
|
|
|
$(INCLUDE_PATH) \
|
2024-05-10 01:56:59 +00:00
|
|
|
${WRAPPER} \
|
2024-08-11 20:08:16 +00:00
|
|
|
${EXPANDED_PARAM_ARGS} \
|
2024-04-23 17:19:08 +00:00
|
|
|
$(SOURCES)
|
2024-04-22 18:35:18 +00:00
|
|
|
|
2024-05-10 01:56:59 +00:00
|
|
|
obj_dir_profiling/V${TESTBENCH}_$(WALLYCONF): $(DEPENDENCIES)
|
2024-04-12 03:02:20 +00:00
|
|
|
mkdir -p obj_dir_profiling
|
2024-04-22 18:32:46 +00:00
|
|
|
verilator \
|
2024-05-10 01:56:59 +00:00
|
|
|
--Mdir obj_dir_profiling -o V${TESTBENCH}_$(WALLYCONF) \
|
2024-04-22 18:32:46 +00:00
|
|
|
--binary \
|
2024-04-12 03:02:20 +00:00
|
|
|
--prof-cfuncs $(OPT) $(PARAMS) \
|
2024-05-10 01:56:59 +00:00
|
|
|
--top-module ${TESTBENCH} --relative-includes \
|
2024-04-17 01:54:11 +00:00
|
|
|
$(INCLUDE_PATH) \
|
2024-05-10 01:56:59 +00:00
|
|
|
${WRAPPER} \
|
2024-08-11 20:08:16 +00:00
|
|
|
${EXPANDED_PARAM_ARGS} \
|
2024-04-17 16:52:54 +00:00
|
|
|
$(SOURCES)
|
2024-04-12 03:02:20 +00:00
|
|
|
|
|
|
|
clean:
|
2024-06-19 21:25:31 +00:00
|
|
|
rm -rf $(VERILATOR_DIR)/wkdir $(VERILATOR_DIR)/obj_dir_profiling $(VERILATOR_DIR)/logs $(VERILATOR_DIR)/logs_profiling
|