2024-08-11 17:44:53 +00:00
# wally.do
2023-02-04 12:38:41 +00:00
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
2021-01-15 04:37:51 +00:00
#
# Modification by Oklahoma State University & Harvey Mudd College
2024-08-10 19:16:46 +00:00
# Use with Testbench
2021-01-15 04:37:51 +00:00
# James Stine, 2008; David Harris 2021
# Go Cowboys!!!!!!
#
# Takes 1:10 to run RV64IC tests using gui
2024-08-11 20:08:16 +00:00
# Usage: do wally.do <config> <testcases> <testbench> [--ccov] [--fcov] [+acc] [--args "any number of +value"] [--params "any number of VAR=VAL parameter overrides"]
# Example: do wally.do rv64gc arch64i testbench
2021-10-10 22:07:51 +00:00
2024-08-11 17:44:53 +00:00
# Use this wally.do file to run this example.
2021-01-15 04:37:51 +00:00
# Either bring up ModelSim and type the following at the "ModelSim>" prompt:
2024-08-11 17:44:53 +00:00
# do wally.do
2021-01-15 04:37:51 +00:00
# or, to run from a shell, type the following at the shell prompt:
2024-08-11 17:44:53 +00:00
# vsim -do wally.do -c
2021-01-15 04:37:51 +00:00
# (omit the "-c" to see the GUI while running from the shell)
2024-08-11 17:44:53 +00:00
# lcheck - return 1 if value is in list and remove it from list
proc lcheck {listVariable value} {
upvar 1 $listVariable list
set index [lsearch -exact $list $value]
if {$index >= 0} {
set list [lreplace $list $index $index]
return 1
} else {
return 0
}
}
2024-05-14 17:38:19 +00:00
2024-08-11 17:44:53 +00:00
set DEBUG 1
2021-01-15 04:37:51 +00:00
onbreak {resume}
2024-05-06 18:28:00 +00:00
onerror {quit -f}
2021-01-15 04:37:51 +00:00
2024-08-11 17:44:53 +00:00
# Initialize variables
2024-04-06 17:34:21 +00:00
set CFG ${1}
set TESTSUITE ${2}
set TESTBENCH ${3}
set WKDIR wkdir/${CFG}_${TESTSUITE}
set WALLY $::env(WALLY)
2024-08-11 17:44:53 +00:00
set IMPERAS_HOME $::env(IMPERAS_HOME)
2024-04-06 17:34:21 +00:00
set CONFIG ${WALLY}/config
set SRC ${WALLY}/src
set TB ${WALLY}/testbench
2024-08-07 09:19:05 +00:00
set FCRVVI ${WALLY}/addins/cvw-arch-verif/fcov
2024-04-06 17:34:21 +00:00
2021-01-15 04:37:51 +00:00
# create library
2024-04-06 17:34:21 +00:00
if [file exists ${WKDIR}] {
vdel -lib ${WKDIR} -all
}
vlib ${WKDIR}
2024-08-11 20:08:16 +00:00
set PlusArgs ""
set ParamArgs ""
set ExpandedParamArgs {}
2024-07-15 12:32:16 +00:00
set ccov 0
2024-04-06 17:34:21 +00:00
set CoverageVoptArg ""
set CoverageVsimArg ""
2024-05-27 16:59:13 +00:00
set FunctCoverage 0
2024-08-11 17:44:53 +00:00
set FCvlog ""
set FCvopt ""
set FCdefineCOVER_EXTS {}
2024-05-14 17:38:19 +00:00
set lockstep 0
2024-08-11 17:44:53 +00:00
set lockstepvlog ""
2024-05-14 17:38:19 +00:00
set SVLib ""
set GUI 0
set accFlag ""
2024-04-06 17:34:21 +00:00
# Need to be able to pass arguments to vopt. Unforunately argv does not work because
# it takes on different values if vsim and the do file are called from the command line or
2024-08-11 17:44:53 +00:00
# if the do file is called from questa sim directly. This chunk of code uses the $4 through $n
2024-04-06 17:34:21 +00:00
# variables and compacts into a single list for passing to vopt.
set from 4
set step 1
set lst {}
2024-05-14 17:38:19 +00:00
2024-04-06 17:34:21 +00:00
for {set i 0} true {incr i} {
set x [expr {$i*$step + $from}]
if {$x > $argc} break
set arg [expr "$$x"]
lappend lst $arg
}
2024-05-14 17:38:19 +00:00
echo "number of args = $argc"
echo "lst = $lst"
# if +acc found set flag and remove from list
2024-08-11 17:44:53 +00:00
if {[lcheck lst "+acc"]} {
2024-05-14 17:38:19 +00:00
set GUI 1
set accFlag "+acc"
}
2024-08-11 17:44:53 +00:00
# if --ccov found set flag and remove from list
if {[lcheck lst "--ccov"]} {
2024-07-15 12:32:16 +00:00
set ccov 1
2024-05-14 17:38:19 +00:00
set CoverageVoptArg "+cover=sbecf"
set CoverageVsimArg "-coverage"
}
2024-09-05 23:32:45 +00:00
# if --fcovimp found set flag and remove from list
if {[lcheck lst "--fcovimp"]} {
2024-05-27 16:59:13 +00:00
set FunctCoverage 1
2024-08-11 17:44:53 +00:00
set FCvlog "+define+INCLUDE_TRACE2COV \
+define+IDV_INCLUDE_TRACE2COV \
+define+COVER_BASE_RV64I \
+define+COVER_LEVEL_DV_PR_EXT \
+incdir+${IMPERAS_HOME}/ImpProprietary/source/host/riscvISACOV/source"
set FCvopt "+TRACE2COV_ENABLE=1 +IDV_TRACE2COV=1"
2024-07-22 15:52:19 +00:00
# Uncomment various cover statements below to control which extensions get functional coverage
2024-08-11 17:44:53 +00:00
lappend FCdefineCOVER_EXTS "+define+COVER_RV64I"
#lappend FCdefineCOVER_EXTS "+define+COVER_RV64M"
#lappend FCdefineCOVER_EXTS "+define+COVER_RV64A"
#lappend FCdefineCOVER_EXTS "+define+COVER_RV64F"
#lappend FCdefineCOVER_EXTS "+define+COVER_RV64D"
#lappend FCdefineCOVER_EXTS "+define+COVER_RV64ZICSR"
#lappend FCdefineCOVER_EXTS "+define+COVER_RV64C"
2024-05-14 18:41:20 +00:00
2024-05-14 17:38:19 +00:00
}
2024-09-05 23:32:45 +00:00
# if --fcov found set flag and remove from list
if {[lcheck lst "--fcov"]} {
2024-08-29 22:55:54 +00:00
set FunctCoverage 1
2024-09-10 01:06:08 +00:00
# COVER_BASE_RV32I is just needed to keep riscvISACOV happy, but no longer affects tests
2024-10-16 14:14:11 +00:00
set FCvlog "+define+INCLUDE_TRACE2COV \
2024-08-29 22:55:54 +00:00
+define+IDV_INCLUDE_TRACE2COV \
+define+COVER_BASE_RV32I \
2024-08-30 19:31:26 +00:00
+incdir+$env(WALLY)/addins/riscvISACOV/source \
2024-09-05 23:32:45 +00:00
"
2024-10-16 14:14:11 +00:00
2024-08-29 22:55:54 +00:00
set FCvopt "+TRACE2COV_ENABLE=1 +IDV_TRACE2COV=1"
2024-09-07 14:00:52 +00:00
2024-08-30 18:57:31 +00:00
}
2024-05-14 17:38:19 +00:00
2024-08-11 17:44:53 +00:00
# if --lockstep or --fcov found set flag and remove from list
if {[lcheck lst "--lockstep"] || $FunctCoverage == 1} {
set lockstep 1
set lockstepvlog "+define+USE_IMPERAS_DV \
+incdir+${IMPERAS_HOME}/ImpPublic/include/host \
+incdir+${IMPERAS_HOME}/ImpProprietary/include/host \
${IMPERAS_HOME}/ImpPublic/source/host/rvvi/*.sv \
${IMPERAS_HOME}/ImpProprietary/source/host/idv/*.sv"
set SVLib "-sv_lib ${IMPERAS_HOME}/lib/Linux64/ImperasLib/imperas.com/verification/riscv/1.0/model"
}
2024-07-15 21:20:48 +00:00
2024-08-11 20:08:16 +00:00
# Set PlusArgs passed using the --args flag
set PlusArgsIndex [lsearch -exact $lst "--args"]
if {$PlusArgsIndex >= 0} {
set PlusArgs [lindex $lst [expr {$PlusArgsIndex + 1}]]
set lst [lreplace $lst $PlusArgsIndex [expr {$PlusArgsIndex + 1}]]
}
# Set ParamArgs passed using the --params flag and expand into a list of -G<param> arguments
set ParamArgsIndex [lsearch -exact $lst "--params"]
if {$ParamArgsIndex >= 0} {
set ParamArgs [lindex $lst [expr {$ParamArgsIndex + 1}]]
set ParamArgs [regexp -all -inline {\S+} $ParamArgs]
foreach param $ParamArgs {
lappend ExpandedParamArgs -G$param
2024-04-06 23:04:48 +00:00
}
2024-08-11 20:08:16 +00:00
set lst [lreplace $lst $ParamArgsIndex [expr {$ParamArgsIndex + 1}]]
2021-01-15 04:37:51 +00:00
}
2024-05-14 17:38:19 +00:00
2024-08-11 17:44:53 +00:00
# Debug print statements
2024-05-14 17:38:19 +00:00
if {$DEBUG > 0} {
echo "GUI = $GUI"
2024-07-15 12:32:16 +00:00
echo "ccov = $ccov"
2024-05-14 17:38:19 +00:00
echo "lockstep = $lockstep"
2024-05-28 18:54:48 +00:00
echo "FunctCoverage = $FunctCoverage"
echo "remaining list = $lst"
echo "Extra +args = $PlusArgs"
2024-08-11 20:08:16 +00:00
echo "Extra -args = $ExpandedParamArgs"
2024-05-28 18:54:48 +00:00
}
2021-01-15 04:37:51 +00:00
# compile source files
2024-08-10 19:16:46 +00:00
# suppress spurious warnngs about
2021-01-15 04:37:51 +00:00
# "Extra checking for conflicts with always_comb done at vopt time"
# because vsim will run vopt
2024-10-16 14:14:11 +00:00
set INC_DIRS "+incdir+${CONFIG}/${CFG} +incdir+${CONFIG}/deriv/${CFG} +incdir+${CONFIG}/shared +incdir+${FCRVVI} +incdir+${FCRVVI}/rv32 +incdir+${FCRVVI}/rv64 +incdir+${FCRVVI}/rv64_priv +incdir+${FCRVVI}/common"
2024-08-11 17:44:53 +00:00
set SOURCES "${SRC}/cvw.sv ${TB}/${TESTBENCH}.sv ${TB}/common/*.sv ${SRC}/*/*.sv ${SRC}/*/*/*.sv ${WALLY}/addins/verilog-ethernet/*/*.sv ${WALLY}/addins/verilog-ethernet/*/*/*/*.sv"
2024-10-16 14:14:11 +00:00
vlog -permissive -lint -work ${WKDIR} {*}${INC_DIRS} {*}${FCvlog} {*}${FCdefineCOVER_EXTS} {*}${lockstepvlog} {*}${SOURCES} -suppress 2282,2583,7053,7063,2596,13286
2024-04-06 17:34:21 +00:00
2021-01-15 04:37:51 +00:00
# start and run simulation
# remove +acc flag for faster sim during regressions if there is no need to access internal signals
2024-08-11 20:08:16 +00:00
vopt $accFlag wkdir/${CFG}_${TESTSUITE}.${TESTBENCH} -work ${WKDIR} {*}${ExpandedParamArgs} -o testbenchopt ${CoverageVoptArg}
2024-05-06 18:28:00 +00:00
2024-08-30 19:32:41 +00:00
vsim -lib ${WKDIR} testbenchopt +TEST=${TESTSUITE} {*}${PlusArgs} -fatal 7 {*}${SVLib} {*}${FCvopt} -suppress 3829 ${CoverageVsimArg}
2024-04-06 17:34:21 +00:00
2024-08-09 13:18:38 +00:00
# power add generates the logging necessary for saif generation.
2024-04-06 17:34:21 +00:00
# power add -r /dut/core/*
2024-08-11 17:44:53 +00:00
# add waveforms if GUI is enabled
2024-04-06 20:43:06 +00:00
if { ${GUI} } {
add log -recursive /*
if { ${TESTBENCH} eq "testbench_fp" } {
do wave-fpu.do
} else {
do wave.do
}
}
2024-07-15 21:20:48 +00:00
if {$FunctCoverage} {
2024-10-16 16:44:34 +00:00
set UCDB ${WALLY}/sim/questa/fcov_ucdb/${CFG}_${TESTSUITE}.ucdb
coverage save -onexit ${UCDB}
2024-08-07 09:19:05 +00:00
}
2024-04-06 17:34:21 +00:00
run -all
2024-07-15 12:32:16 +00:00
if {$ccov} {
2024-07-15 22:34:44 +00:00
set UCDB ${WALLY}/sim/questa/ucdb/${CFG}_${TESTSUITE}.ucdb
echo "Saving coverage to ${UCDB}"
2024-04-06 17:34:21 +00:00
do coverage-exclusions-rv64gc.do # beware: this assumes testing the rv64gc configuration
2024-07-15 22:34:44 +00:00
coverage save -instance /testbench/dut/core ${UCDB}
2022-02-05 05:28:40 +00:00
}
2024-07-15 22:34:44 +00:00
# power off -r /dut/core/*
2024-04-06 17:34:21 +00:00
# These aren't doing anything helpful
#profile report -calltree -file wally-calltree.rpt -cutoff 2
#power report -all -bsaif power.saif
2024-04-06 20:43:06 +00:00
# terminate simulation unless we need to keep the GUI running
if { ${GUI} == 0} {
quit
}