diff --git a/tools/make/viv_simulator.mak b/tools/make/viv_simulator.mak index c49c05c..d4ceb8d 100644 --- a/tools/make/viv_simulator.mak +++ b/tools/make/viv_simulator.mak @@ -56,24 +56,24 @@ SETUP_AND_LAUNCH_SIMULATION = \ $(TOOLS_DIR)/scripts/launch_vivado.sh -mode $(VIVADO_MODE) -source $(call RESOLVE_PATH,$(TOOLS_DIR)/scripts/viv_sim_project.tcl) -log xsim.log -nojournal # ------------------------------------------------------------------- -# Usage: SETUP_AND_LAUNCH_VLINT +# Usage: SETUP_AND_LAUNCH_VCOM # Args: N/A # ------------------------------------------------------------------- -SETUP_AND_LAUNCH_VLINT = \ +SETUP_AND_LAUNCH_VCOM = \ @ \ - export VLINT_PROJ_DIR=$(MODELSIM_PROJ_DIR); \ - export VLINT_DESIGN_SRCS=$(EXP_DESIGN_SRCS); \ - export VLINT_SIM_SRCS=$(EXP_SIM_SRCS); \ - export VLINT_INC_SRCS=$(EXP_INC_SRCS); \ - export VLINT_SVLOG_ARGS="$(SVLOG_ARGS) +define+UHD_FPGA_DIR=$(BASE_DIR)/../.."; \ - export VLINT_VLOG_ARGS="$(VLOG_ARGS) +define+UHD_FPGA_DIR=$(BASE_DIR)/../.."; \ - export VLINT_VHDL_ARGS="$(VHDL_ARGS)"; \ - export VLINT_MODELSIM_INI="$(MODELSIM_INI)"; \ - $(TOOLS_DIR)/scripts/launch_vlint.sh + export VCOM_PROJ_DIR=$(MODELSIM_PROJ_DIR); \ + export VCOM_DESIGN_SRCS=$(EXP_DESIGN_SRCS); \ + export VCOM_SIM_SRCS=$(EXP_SIM_SRCS); \ + export VCOM_INC_SRCS=$(EXP_INC_SRCS); \ + export VCOM_SVLOG_ARGS="$(SVLOG_ARGS) +define+UHD_FPGA_DIR=$(BASE_DIR)/../.."; \ + export VCOM_VLOG_ARGS="$(VLOG_ARGS) +define+UHD_FPGA_DIR=$(BASE_DIR)/../.."; \ + export VCOM_VHDL_ARGS="$(VHDL_ARGS)"; \ + export VCOM_MODELSIM_INI="$(MODELSIM_INI)"; \ + $(TOOLS_DIR)/scripts/launch_vcom.sh # ------------------------------------------------------------------- -# Usage: SETUP_AND_LAUNCH_VLINT +# Usage: SETUP_AND_LAUNCH_MODELSIM # Args: N/A # ------------------------------------------------------------------- @@ -85,6 +85,24 @@ SETUP_AND_LAUNCH_MODELSIM = \ export MSIM_LIBS="$(MODELSIM_LIBS)"; \ export MSIM_MODE=$(VIVADO_MODE); \ export MSIM_MODELSIM_INI="$(MODELSIM_INI)"; \ + export MSIM_VARIANT=legacy; \ + $(TOOLS_DIR)/scripts/launch_modelsim.sh + +# ------------------------------------------------------------------- +# Usage: SETUP_AND_LAUNCH_QUESTASIM +# Args: N/A +# ------------------------------------------------------------------- + +SETUP_AND_LAUNCH_QUESTASIM = \ + @ \ + export MSIM_GUI=visualizer; \ + export MSIM_PROJ_DIR=$(MODELSIM_PROJ_DIR); \ + export MSIM_SIM_TOP="$(SIM_TOP)"; \ + export MSIM_ARGS="$(MODELSIM_ARGS)"; \ + export MSIM_LIBS="$(MODELSIM_LIBS)"; \ + export MSIM_MODE=$(VIVADO_MODE); \ + export MSIM_MODELSIM_INI="$(MODELSIM_INI)"; \ + export MSIM_VARIANT=questa; \ $(TOOLS_DIR)/scripts/launch_modelsim.sh .SECONDEXPANSION: @@ -106,22 +124,32 @@ xclean: @rm -f xvlog.pb @rm -f vivado_pid*.str -##vsim: Run the simulation using ModelSim (via vivado) +##vsim: Run the simulation using ModelSim from inside Vivado vsim: .check_tool $(COMPLIBDIR) $(DESIGN_SRCS) $(SIM_SRCS) $(INC_SRCS) $(call SETUP_AND_LAUNCH_SIMULATION,Modelsim) -##modelsim: Run the simulation using Modelsim (natively) -modelsim: .check_tool vlint +##qsim: Run the simulation using Questa +qsim: .check_tool vlint + $(call SETUP_AND_LAUNCH_QUESTASIM) + +##msim: Run the simulation using ModelSim +msim: .check_tool vlint $(call SETUP_AND_LAUNCH_MODELSIM) +# Alias for msim (for backwards compatibility) +modelsim: msim + # NOTE: VHDL files require a correct compile order. This script compiles files # in the order they are defined in $(DESIGN_SRC), then $SIM_SRC) -##vlint: Run ModelSim compiler to lint files -vlint: .check_tool $(COMPLIBDIR) $(DESIGN_SRCS) $(SIM_SRCS) $(INC_SRCS) - $(call SETUP_AND_LAUNCH_VLINT) - -##vclean: Cleanup ModelSim intermediate files +##vcom: Run ModelSim/Questa compiler to compile HDL files +vcom: .check_tool $(DESIGN_SRCS) $(SIM_SRCS) $(INC_SRCS) + $(call SETUP_AND_LAUNCH_VCOM) + +# Alias for vcom (for backwards compatibility) +vlint: vcom + +##vclean: Cleanup ModelSim/Questa intermediate files vclean: @rm -f modelsim*.log @rm -rf $(MODELSIM_PROJ_DIR) diff --git a/tools/scripts/launch_modelsim.sh b/tools/scripts/launch_modelsim.sh index 2cc5dbd..a240d13 100755 --- a/tools/scripts/launch_modelsim.sh +++ b/tools/scripts/launch_modelsim.sh @@ -45,12 +45,10 @@ function print_color { SCRIPT_DIR=$(dirname "$(realpath "$0")") -# Using -voptargs=+acc makes everything visible in the simulator for GUI mode -# and avoids some cases where simulation mismatch could otherwise occur. # Setting -onfinish to "stop" prevents the simulator from immediately trying to # exit when finish() is called. This is annoying in the GUI and important for # error detection in batch mode. -MSIM_DEFAULT="-voptargs=+acc -quiet -L unisims_ver -onfinish stop" +MSIM_DEFAULT="-quiet -L unisims_ver -onfinish stop" # Use specified modelsim.ini, if set if [[ -z $MSIM_MODELSIM_INI ]]; then @@ -69,15 +67,30 @@ do done if [ $MSIM_MODE == "gui" ]; then - echo "* Launching ModelSim" - vsim $MSIM_DEFAULT $MODELSIMINI_ARG $MSIM_ARGS $MSIM_LIB_ARGS $MSIM_SIM_TOP 2>&1 | while IFS= read -r line; do + if [ $MSIM_VARIANT == "questa" ]; then + echo "* Launching Visualizer GUI" + MSIM_DEFAULT+=" -voptargs=\"-debug,events,livesim +designfile\" -visualizer -qwavedb=+signal+memory+vhdlvariable+class" + else + echo "* Launching classic GUI" + MSIM_DEFAULT+=" -voptargs=+acc" + fi + # Use stdbuf to line buffer the pipe and avoid long block buffering delays + stdbuf -oL -eL vsim $MSIM_DEFAULT $MODELSIMINI_ARG $MSIM_ARGS $MSIM_LIB_ARGS $MSIM_SIM_TOP 2>&1 | while IFS= read -r line; do print_color $line done exit_status=${PIPESTATUS[0]} if [ ${exit_status} -ne 0 ]; then exit ${exit_status}; fi elif [ $MSIM_MODE == "batch" ]; then - echo "* Launching ModelSim" - vsim -batch -do $SCRIPT_DIR/modelsim.do $MODELSIMINI_ARG $MSIM_DEFAULT $MSIM_ARGS $MSIM_LIB_ARGS $MSIM_SIM_TOP 2>&1 | while IFS= read -r line; do + if [ $MSIM_VARIANT == "questa" ]; then + echo "* Launching Questa batch mode" + else + echo "* Launching ModelSim batch mode" + # Using +acc for GUI and batch sim ensures we get the same behavior in + # both, with the downside that simulation might be slower. + MSIM_DEFAULT+=" -voptargs=+acc" + fi + # Use stdbuf to line buffer the pipe and avoid long block buffering delays + stdbuf -oL -eL vsim -batch -do $SCRIPT_DIR/modelsim.do $MODELSIMINI_ARG $MSIM_DEFAULT $MSIM_ARGS $MSIM_LIB_ARGS $MSIM_SIM_TOP 2>&1 | while IFS= read -r line; do print_color $line done exit_status=${PIPESTATUS[0]} diff --git a/tools/scripts/launch_vlint.sh b/tools/scripts/launch_vcom.sh similarity index 88% rename from tools/scripts/launch_vlint.sh rename to tools/scripts/launch_vcom.sh index 4deb48a..61b7cb5 100755 --- a/tools/scripts/launch_vlint.sh +++ b/tools/scripts/launch_vcom.sh @@ -59,16 +59,16 @@ function replace_dirs_with_source { WORKING_DIR=$(pwd) # Use specified modelsim.ini, if set -if [[ -z $VLINT_MODELSIM_INI ]]; then +if [[ -z $VCOM_MODELSIM_INI ]]; then MODELSIMINI_ARG="" else - MODELSIMINI_ARG="-modelsimini $VLINT_MODELSIM_INI" + MODELSIMINI_ARG="-modelsimini $VCOM_MODELSIM_INI" fi # Define arguments to pass to the compile -SVLOG_ARGS="$VLINT_SVLOG_ARGS $MODELSIMINI_ARG -quiet +define+WORKING_DIR=$WORKING_DIR" -VLOG_ARGS="$VLINT_VLOG_ARGS $MODELSIMINI_ARG -quiet +define+WORKING_DIR=$WORKING_DIR" -VHDL_ARGS="$VLINT_VHDL_ARGS $MODELSIMINI_ARG -quiet" +SVLOG_ARGS="$VCOM_SVLOG_ARGS $MODELSIMINI_ARG -quiet +define+WORKING_DIR=$WORKING_DIR" +VLOG_ARGS="$VCOM_VLOG_ARGS $MODELSIMINI_ARG -quiet +define+WORKING_DIR=$WORKING_DIR" +VHDL_ARGS="$VCOM_VHDL_ARGS $MODELSIMINI_ARG -quiet" # Define files in which to store all the compiler arguments SV_ARGS_FILE=svlogarglist.txt @@ -77,9 +77,9 @@ VHD_ARGS_FILE=vcomarglist.txt # Replace any directories with the sources they contain SOURCES= -SOURCES+=$(replace_dirs_with_source $VLINT_INC_SRCS) -SOURCES+=$(replace_dirs_with_source $VLINT_DESIGN_SRCS) -SOURCES+=$(replace_dirs_with_source $VLINT_SIM_SRCS) +SOURCES+=$(replace_dirs_with_source $VCOM_INC_SRCS) +SOURCES+=$(replace_dirs_with_source $VCOM_DESIGN_SRCS) +SOURCES+=$(replace_dirs_with_source $VCOM_SIM_SRCS) # Separate the files by type and determine include directories to use V_FILES= @@ -112,8 +112,8 @@ V_INC=$(printf '%s\n' $V_INC | awk '!a[$0]++') #------------------------------------------ # Generate argument files -mkdir -p ./$VLINT_PROJ_DIR -cd ./$VLINT_PROJ_DIR +mkdir -p ./$VCOM_PROJ_DIR +cd ./$VCOM_PROJ_DIR echo "/* Auto generated argument file for vlog -sv */" > $SV_ARGS_FILE echo "-sv" >> $SV_ARGS_FILE diff --git a/tools/scripts/setupenv_base.sh b/tools/scripts/setupenv_base.sh index ae66915..8dc356e 100644 --- a/tools/scripts/setupenv_base.sh +++ b/tools/scripts/setupenv_base.sh @@ -26,7 +26,15 @@ else else VIVADO_BASE_PATH="/opt/Xilinx/Vivado" fi - MODELSIM_BASE_PATH="/opt/mentor/modelsim" + if [[ -d "/opt/mentor/questasim" ]]; then + MODELSIM_BASE_PATH="/opt/mentor/questasim" + elif [[ -d "/opt/local/mentor/questasim" ]]; then + MODELSIM_BASE_PATH="/opt/local/mentor/questasim" + elif [[ -d "/opt/local/mentor/modelsim" ]]; then + MODELSIM_BASE_PATH="/opt/local/mentor/modelsim" + else + MODELSIM_BASE_PATH="/opt/mentor/modelsim" + fi fi function resolve_viv_path { @@ -45,20 +53,23 @@ function setupenv_help { Usage: source setupenv.sh [--help|-h] [--vivado-path=] [--modelsim-path=] ---vivado-path : Path to the base install directory for Xilinx Vivado if it is - not installed in one of the default search locations (e.g., - /opt/Xilinx/Vivado). ---modelsim-path : Path to the base install directory for ModelSim if it is not - installed in one of the default search locations (e.g., - /opt/mentor/modelsim). This simulation tool is optional. ---help -h : Shows this message. +--vivado-path : Path to the directory for Xilinx Vivado where settings64.sh + is located, if Vivado is not installed in one of the default + search locations (e.g., /opt/Xilinx/Vivado). +--modelsim-path : Path to the base install directory for ModelSim if it is not + installed in one of the default search locations (e.g., + /opt/mentor/modelsim). This simulation tool is optional. +--questasim-path : Path to the base install directory for QuestaSim if it is + not installed in one of the default search locations (e.g., + /opt/mentor/questasim). This simulation tool is optional. +--help -h : Shows this message. -This script sets up the environment required to build FPGA images for the Ettus Research -${DISPLAY_NAME}. It will also optionally set up the the environment to run the -Modelsim simulator (although this tool is not required). +This script sets up the environment required to build FPGA images for the Ettus +Research ${DISPLAY_NAME}. It will also optionally set up the the environment to +run the ModelSim simulator (although this tool is not required). Required tools: Xilinx Vivado $VIVADO_VER (Synthesis and Simulation) -Optional tools: Mentor Graphics Modelsim (Simulation) +Optional tools: Siemens ModelSim or Questa (Simulation) EOHELP } @@ -127,12 +138,12 @@ for i in "$@"; do --vivado-version) PARSE_STATE="vivado-version" ;; - --modelsim-path=*) + --modelsim-path=*|--questasim-path=*) MODELSIM_BASE_PATH="${i#*=}" MODELSIM_REQUESTED=1 PARSE_STATE="" ;; - --modelsim-path) + --modelsim-path|--questasim-path) PARSE_STATE="modelsim-path" ;; *) @@ -173,6 +184,7 @@ export VIVADO_PATH=$VIVADO_BASE_PATH/$VIVADO_VER export VIVADO_HLS_PATH=$VIVADO_BASE_PATH/../Vitis_HLS/$VIVADO_VER echo "Setting up a ${BITNESS}-bit FPGA build environment for the ${DISPLAY_NAME}..." + #---------------------------------------------------------------------------- # Prepare Vivado environment #---------------------------------------------------------------------------- @@ -228,7 +240,7 @@ if [[ -n $VIVADO_VER_FULL ]]; then fi #---------------------------------------------------------------------------- -# Prepare Modelsim environment +# Prepare ModelSim environment #---------------------------------------------------------------------------- if [[ -d $MODELSIM_BASE_PATH ]]; then if [[ $VIV_PLATFORM = "Cygwin" ]]; then @@ -238,63 +250,116 @@ if [[ -d $MODELSIM_BASE_PATH ]]; then fi fi if [[ $VSIM_PATH ]]; then + # ModelSim prints a string like "Model Technology ModelSim SE-64 vsim ..." + # or "Model Technology ModelSim DE vsim ..." for 32-bit. if [[ $($VSIM_PATH -version) =~ .*ModelSim[[:space:]](.+)[[:space:]]vsim.* ]]; then MODELSIM_VER=${BASH_REMATCH[1]} MODELSIM_PATH=$(dirname $VSIM_PATH) + # Questa Core/Prime prints "Questa Sim-64 vsim ..."" + elif [[ $($VSIM_PATH -version) =~ .*Questa[[:space:]]Sim-64[[:space:]]vsim.* ]]; then + MODELSIM_VER=QuestaSim-64 + MODELSIM_PATH=$(dirname $VSIM_PATH) + # Questa Base prints "QuestaSim Base Edition-64 vsim ..." + elif [[ $($VSIM_PATH -version) =~ .*QuestaSim[[:space:]]Base[[:space:]]Edition-64[[:space:]]vsim.* ]]; then + MODELSIM_VER=QuestaSim-64 + MODELSIM_PATH=$(dirname $VSIM_PATH) fi case $MODELSIM_VER in + QuestaSim-64) + export MODELSIM_64BIT=1 + if [[ -z $SIM_COMPLIBDIR ]]; then + export SIM_COMPLIBDIR=$VIVADO_PATH/questasim64 + fi + ;; DE-64|SE-64) export MODELSIM_64BIT=1 - if [[ -z $MSIM_VIV_COMPLIBDIR ]]; then + if [[ -z $SIM_COMPLIBDIR ]]; then export SIM_COMPLIBDIR=$VIVADO_PATH/modelsim64 - else - export SIM_COMPLIBDIR=$MSIM_VIV_COMPLIBDIR fi ;; DE|SE|PE) export MODELSIM_64BIT=0 - if [[ -z $MSIM_VIV_COMPLIBDIR ]]; then + if [[ -z $SIM_COMPLIBDIR ]]; then export SIM_COMPLIBDIR=$VIVADO_PATH/modelsim32 - else - export SIM_COMPLIBDIR=$MSIM_VIV_COMPLIBDIR fi ;; *) ;; esac - # If MSIM_MODELSIM_INI is not defined, use the modelsim.ini in the compiled - # libraries directory. Otherwise use the one defined by MSIM_MODELSIM_INI. - # Set MSIM_MODELSIM_INI to an empty string to use the modelsim.ini in the - # ModelSim installation folder. - if [[ ! -v MSIM_MODELSIM_INI ]]; then + # Make it an absolute path + export SIM_COMPLIBDIR=$(resolve_viv_path $SIM_COMPLIBDIR) + # If there's a modelsim.ini in the simulation library directory, use that. + # Otherwise, don't set the variable so ModelSim's default location is used. + if [[ -f $(resolve_viv_path $SIM_COMPLIBDIR/modelsim.ini) ]]; then export MODELSIM_INI=$(resolve_viv_path $SIM_COMPLIBDIR/modelsim.ini) fi fi function build_simlibs { - mkdir -p $SIM_COMPLIBDIR - pushd $SIM_COMPLIBDIR + while [[ "$#" -gt 0 ]]; do + arg="$1" + case $arg in + --path=*) + export SIM_COMPLIBDIR=$(resolve_viv_path "${arg#*=}") + echo "Setting SIM_COMPLIBDIR to $SIM_COMPLIBDIR" + shift + ;; + --path) + # Grab the next argument as the path + export SIM_COMPLIBDIR=$(resolve_viv_path "${2#*=}") + echo "Setting SIM_COMPLIBDIR to $SIM_COMPLIBDIR" + shift 2 + ;; + --help) + echo "Builds the Xilinx simulation libraries. By default, the SIM_COMPLIBDIR" + echo "environment variable is used as the location for the libraries. The" + echo "current setting is:" + echo "SIM_COMPLIBDIR=$SIM_COMPLIBDIR" + echo "" + echo "Usage: build_simlibs [--path=/path/to/folder] [--help]" + echo + echo "Options:" + echo " --path=PATH : Specify a different path to use." + echo " --help : Display this help message." + return 0 + ;; + *) + echo "Unknown option: $arg" + echo "Try running: build_simlibs --help" + return 1 + ;; + esac + done + # Update the MODELSIM_INI location in case the SIM_COMPLIBDIR changed + export MODELSIM_INI=$(resolve_viv_path $SIM_COMPLIBDIR/modelsim.ini) CMD_PATH=`mktemp XXXXXXXX.vivado_simgen.tcl` - if [[ $MODELSIM_64BIT -eq 1 ]]; then - echo "compile_simlib -force -simulator modelsim -family all -language all -library all -directory ." > $CMD_PATH + if [[ $MODELSIM_64BIT -eq 0 ]]; then + CSL_BITNESS="-32bit" + CSL_SIMULATOR="modelsim" else - echo "compile_simlib -force -simulator modelsim -family all -language all -library all -32bit -directory ." > $CMD_PATH + CSL_BITNESS="" + if [[ $MODELSIM_VER = "QuestaSim-64" ]]; then + CSL_SIMULATOR="questasim" + else + CSL_SIMULATOR="modelsim" + fi fi + echo "compile_simlib -force -simulator $CSL_SIMULATOR -simulator_exec_path $(dirname $VSIM_PATH) -family all -language all -library all $CSL_BITNESS -directory $SIM_COMPLIBDIR" > $CMD_PATH $VIVADO_EXEC -mode batch -source $(resolve_viv_path $CMD_PATH) -nolog -nojournal rm -f $CMD_PATH - popd + echo "Simulation libraries were compiled in: $SIM_COMPLIBDIR" } if [[ $MODELSIM_VER ]]; then - echo "- Modelsim: Found ($MODELSIM_VER, $MODELSIM_PATH)" + echo "- ModelSim/Questa: Found ($MODELSIM_VER, $MODELSIM_PATH)" if [[ -e "$SIM_COMPLIBDIR/modelsim.ini" ]]; then - echo "- Modelsim Compiled Libs: Found ($SIM_COMPLIBDIR)" + echo "- ModelSim/Questa Compiled Libs: Found ($SIM_COMPLIBDIR)" else - echo "- Modelsim Compiled Libs: Not found! (Run build_simlibs to generate them.)" + echo "- ModelSim/Questa Compiled Libs: Not found! (Run build_simlibs to generate them.)" fi else if [[ $MODELSIM_REQUESTED -eq 1 ]]; then - echo "- Modelsim: Not found in $MODELSIM_BASE_PATH (WARNING.. Simulations with vsim will not work)" + echo "- ModelSim/Questa: Not found in $MODELSIM_BASE_PATH (WARNING: Simulations with ModelSim/Questa might not work!)" fi fi