2021-03-03 14:35:11 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2021-03-29 13:09:22 +08:00
|
|
|
|
|
|
|
CONF_PARAMS = -set build_axi4
|
|
|
|
|
2021-03-03 14:35:11 +08:00
|
|
|
TEST_CFLAGS = -g -O3 -funroll-all-loops
|
|
|
|
ABI = -mabi=ilp32 -march=rv32imc
|
|
|
|
|
2021-03-29 13:09:22 +08:00
|
|
|
# Check for RV_ROOT
|
|
|
|
ifeq (,$(wildcard ${RV_ROOT}/configs/quasar.config))
|
|
|
|
$(error env var RV_ROOT does not point to a valid dir! Exiting!)
|
|
|
|
endif
|
|
|
|
|
2021-03-03 14:35:11 +08:00
|
|
|
# Allow snapshot override
|
|
|
|
target = default
|
|
|
|
snapshot = $(target)
|
|
|
|
|
|
|
|
# Allow tool override
|
|
|
|
QUASAR_CONFIG = ${RV_ROOT}/configs/quasar.config
|
|
|
|
VCS = vcs
|
|
|
|
VERILATOR = verilator
|
2021-03-29 13:09:22 +08:00
|
|
|
GCC_PREFIX = /home/users/cores/chipyard/riscv-tools-install/bin/riscv64-unknown-elf
|
2021-03-03 14:35:11 +08:00
|
|
|
BUILD_DIR = ${RV_ROOT}/design/snapshots/${snapshot}
|
|
|
|
TBDIR = ${RV_ROOT}/testbench
|
|
|
|
|
|
|
|
# Define test name
|
2021-03-29 13:15:57 +08:00
|
|
|
TEST = hello_world
|
2021-03-03 14:35:11 +08:00
|
|
|
|
|
|
|
# Define test name
|
2021-03-29 13:09:22 +08:00
|
|
|
ifneq (,$(wildcard $(TBDIR)/asm/$(TEST).s))
|
|
|
|
TEST_DIR = ${TBDIR}/asm
|
|
|
|
else
|
|
|
|
ifneq (,$(wildcard $(TBDIR)/asm/$(TEST).c))
|
|
|
|
TEST_DIR = ${TBDIR}/asm
|
|
|
|
else
|
|
|
|
ifneq (,$(wildcard $(TBDIR)/tests/$(TEST)))
|
|
|
|
TEST_DIR = $(TBDIR)/tests/$(TEST)
|
|
|
|
else
|
|
|
|
TEST_DIR = ${TBDIR}/asm
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
2021-03-29 21:34:16 +08:00
|
|
|
|
2021-03-03 14:35:11 +08:00
|
|
|
HEX_DIR = ${TBDIR}/hex
|
|
|
|
|
2021-03-29 13:09:22 +08:00
|
|
|
OFILES = $(TEST).o
|
2021-03-29 21:34:16 +08:00
|
|
|
OFILES_PATH = ${RV_ROOT}/verif/sim
|
2021-03-29 13:09:22 +08:00
|
|
|
|
2021-03-03 14:35:11 +08:00
|
|
|
ifdef debug
|
|
|
|
DEBUG_PLUS = +dumpon
|
2021-03-31 13:23:11 +08:00
|
|
|
IRUN_DEBUG = -access +rc
|
|
|
|
IRUN_DEBUG_RUN = -input ${RV_ROOT}/testbench/input.tcl
|
2021-03-29 13:09:22 +08:00
|
|
|
VCS_DEBUG = -debug_access
|
|
|
|
VERILATOR_DEBUG = --trace
|
2021-03-03 14:35:11 +08:00
|
|
|
endif
|
|
|
|
|
2021-03-31 13:23:11 +08:00
|
|
|
# provide specific link file
|
|
|
|
ifeq (,$(wildcard $(TEST_DIR)/$(TEST).ld))
|
|
|
|
LINK = $(BUILD_DIR)/link.ld
|
|
|
|
else
|
|
|
|
LINK = $(TEST_DIR)/$(TEST).ld
|
|
|
|
endif
|
|
|
|
|
2021-03-03 14:35:11 +08:00
|
|
|
VPATH = $(TEST_DIR) $(BUILD_DIR) $(TBDIR)
|
2021-03-29 13:09:22 +08:00
|
|
|
|
|
|
|
-include $(TEST_DIR)/$(TEST).mki
|
|
|
|
|
2021-03-03 14:35:11 +08:00
|
|
|
TBFILES = $(TBDIR)/tb_top.sv
|
|
|
|
|
|
|
|
defines = $(BUILD_DIR)/common_defines.vh
|
|
|
|
defines += $(BUILD_DIR)/pdef.vh
|
|
|
|
includes = -I${BUILD_DIR}
|
|
|
|
|
|
|
|
# CFLAGS for verilator generated Makefiles. Without -std=c++11 it
|
|
|
|
# complains for `auto` variables
|
|
|
|
CFLAGS += "-std=c++11"
|
|
|
|
|
|
|
|
# Optimization for better performance; alternative is nothing for
|
|
|
|
# slower runtime (faster compiles) -O2 for faster runtime (slower
|
|
|
|
# compiles), or -O for balance.
|
|
|
|
VERILATOR_MAKE_FLAGS = OPT_FAST="-Os"
|
|
|
|
#############Targets#######################################
|
2021-03-29 21:34:16 +08:00
|
|
|
all: clean sbt_ verilator
|
2021-03-03 14:35:11 +08:00
|
|
|
|
2021-03-29 21:34:16 +08:00
|
|
|
vcs_all: clean sbt_ vcs
|
2021-03-03 14:35:11 +08:00
|
|
|
############ Model Builds ###############################
|
2021-03-29 21:34:16 +08:00
|
|
|
conf:
|
2021-03-03 14:35:11 +08:00
|
|
|
BUILD_PATH=${BUILD_DIR} ${RV_ROOT}/configs/quasar.config -target=$(target) $(CONF_PARAMS)
|
|
|
|
|
2021-03-29 21:34:16 +08:00
|
|
|
sbt_: conf
|
2021-03-03 14:35:11 +08:00
|
|
|
cd ${RV_ROOT}/design/ && exec sbt "run"
|
|
|
|
python3 ${RV_ROOT}/design/reset_script.py
|
|
|
|
rm -rf ${RV_ROOT}/design/quasar_wrapper.v
|
|
|
|
mv ${RV_ROOT}/design/quasar_wrapper.sv ${RV_ROOT}/generated_rtl/quasar_wrapper.sv
|
|
|
|
|
|
|
|
verilator-build: ${TBFILES} conf test_tb_top.cpp
|
|
|
|
echo '`undef RV_ASSERT_ON' >> ${BUILD_DIR}/common_defines.vh
|
|
|
|
$(VERILATOR) --cc -CFLAGS ${CFLAGS} $(defines) \
|
|
|
|
$(includes) -I${RV_ROOT}/testbench -f ${RV_ROOT}/testbench/flist \
|
|
|
|
-Wno-WIDTH -Wno-UNOPTFLAT ${TBFILES} --top-module tb_top \
|
|
|
|
-exe test_tb_top.cpp --autoflush $(VERILATOR_DEBUG)
|
|
|
|
cp ${RV_ROOT}/testbench/test_tb_top.cpp obj_dir/
|
|
|
|
$(MAKE) -j -e -C obj_dir/ -f Vtb_top.mk $(VERILATOR_MAKE_FLAGS)
|
|
|
|
|
2021-03-29 13:09:22 +08:00
|
|
|
vcs-build: ${TBFILES} conf
|
|
|
|
$(VCS) -full64 -LDFLAGS '-Wl,--no-as-needed' -assert svaext -sverilog +define+RV_OPENSOURCE \
|
|
|
|
+error+500 -debug_access +lint=TFIPC-L \
|
|
|
|
${BUILD_DIR}/common_defines.vh \
|
|
|
|
+incdir+$(BUILD_DIR) +libext+.v $(defines) \
|
2021-03-29 21:34:16 +08:00
|
|
|
-f ${RV_ROOT}/testbench/flist ${TBFILES} -l $(OFILES_PATH)/vcs.log
|
|
|
|
|
2021-03-03 14:35:11 +08:00
|
|
|
|
|
|
|
############ TEST Simulation ###############################
|
|
|
|
|
2021-03-31 13:23:11 +08:00
|
|
|
vcs: program.hex vcs-build
|
2021-03-29 21:34:16 +08:00
|
|
|
./simv $(DEBUG_PLUS) +vcs+lic+wait -l $(OFILES_PATH)/vcs.log
|
2021-03-31 13:23:11 +08:00
|
|
|
@rm -rf program.hex $(addprefix $(OFILES_PATH)/,csrc simv* vc_hdrs.h ucli.key console.log *.csv obj_dir)
|
2021-03-29 21:34:16 +08:00
|
|
|
@mv csrc simv* vc_hdrs.h ucli.key console.log *.csv $(OFILES_PATH)
|
|
|
|
@mv *.log ${RV_ROOT}/tracer_logs
|
2021-03-03 14:35:11 +08:00
|
|
|
|
2021-03-29 21:34:16 +08:00
|
|
|
ifeq ($(shell which fm_shell 2> /dev/null),)
|
|
|
|
lec:
|
|
|
|
$(error Unable to locate the executable file for formality! Exiting!)
|
|
|
|
else
|
2021-03-29 13:09:22 +08:00
|
|
|
lec:
|
2021-03-29 21:34:16 +08:00
|
|
|
python3 ${RV_ROOT}/verif/LEC/config.py
|
2021-03-03 14:35:11 +08:00
|
|
|
fm_shell -f ${RV_ROOT}/verif/LEC/formality_work/run_me.fms
|
|
|
|
@mv *.log ${RV_ROOT}/verif/LEC/formality_work/formality_log
|
2021-03-29 21:34:16 +08:00
|
|
|
endif
|
2021-03-03 14:35:11 +08:00
|
|
|
|
|
|
|
verilator: program.hex verilator-build
|
|
|
|
./obj_dir/Vtb_top
|
2021-03-31 13:23:11 +08:00
|
|
|
@rm -rf program.hex $(addprefix $(OFILES_PATH)/,csrc simv* vc_hdrs.h ucli.key console.log *.csv obj_dir)
|
2021-03-29 21:34:16 +08:00
|
|
|
@mv console.log *.csv obj_dir $(OFILES_PATH)
|
|
|
|
@mv *.log ${RV_ROOT}/tracer_logs
|
2021-03-03 14:35:11 +08:00
|
|
|
|
2021-03-29 13:09:22 +08:00
|
|
|
############ TEST build ###############################
|
|
|
|
|
2021-03-29 21:34:16 +08:00
|
|
|
ifeq ($(shell which $(GCC_PREFIX)-gcc 2> /dev/null),)
|
|
|
|
program.hex: ${BUILD_DIR}/defines.h
|
|
|
|
@echo " !!! No $(GCC_PREFIX)-gcc in path, using canned hex files !!"
|
|
|
|
cp ${HEX_DIR}/$(TEST).hex program.hex
|
|
|
|
else
|
|
|
|
ifneq (,$(wildcard $(TEST_DIR)/$(TEST).makefile))
|
|
|
|
program.hex:
|
|
|
|
@echo Building $(TEST) via $(TEST_DIR)/$(TEST).makefile
|
|
|
|
$(MAKE) -f $(TEST_DIR)/$(TEST).makefile
|
2021-03-31 13:23:11 +08:00
|
|
|
else
|
2021-03-29 13:09:22 +08:00
|
|
|
program.hex: $(OFILES) $(LINK)
|
2021-03-03 14:35:11 +08:00
|
|
|
@echo Building $(TEST)
|
2021-03-31 13:23:11 +08:00
|
|
|
cd $(OFILES_PATH) && $(GCC_PREFIX)-gcc -Wl,-m,elf32lriscv -Wl,--discard-none -T$(LINK) -o $(TEST).exe $(OFILES) \
|
|
|
|
-nostartfiles -nostdlib $(TEST_LIBS)
|
2021-03-29 13:09:22 +08:00
|
|
|
$(GCC_PREFIX)-objcopy -O verilog $(OFILES_PATH)/$(TEST).exe program.hex
|
|
|
|
$(GCC_PREFIX)-objdump -S $(OFILES_PATH)/$(TEST).exe > $(OFILES_PATH)/$(TEST).dis
|
2021-03-03 14:35:11 +08:00
|
|
|
@echo Completed building $(TEST)
|
2021-03-29 21:34:16 +08:00
|
|
|
endif
|
|
|
|
endif
|
2021-03-03 14:35:11 +08:00
|
|
|
|
|
|
|
%.o : %.s conf
|
2021-03-29 13:09:22 +08:00
|
|
|
$(GCC_PREFIX)-cpp -I${BUILD_DIR} $< > $(OFILES_PATH)/$*.cpp.s
|
|
|
|
$(GCC_PREFIX)-as ${ABI} $(OFILES_PATH)/$*.cpp.s -o $(OFILES_PATH)/$(@F)
|
2021-03-03 14:35:11 +08:00
|
|
|
|
2021-03-29 13:09:22 +08:00
|
|
|
%.o : %.c conf
|
|
|
|
$(GCC_PREFIX)-gcc ${includes} ${TEST_CFLAGS} -DCOMPILER_FLAGS="\"${TEST_CFLAGS}\"" ${ABI} -nostdlib -c $< -o $(OFILES_PATH)/$(@F)
|
2021-03-03 14:35:11 +08:00
|
|
|
|
|
|
|
help:
|
|
|
|
@echo Make sure the environment variable RV_ROOT is set.
|
|
|
|
@echo Possible targets: vcs verilator help clean conf sbt_ vcs-build verilator-build program.hex
|
|
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf ${RV_ROOT}/design/*.v
|
|
|
|
rm -rf ${RV_ROOT}/design/*.sv
|
|
|
|
rm -rf ${RV_ROOT}/design/*.f
|
|
|
|
rm -rf ${RV_ROOT}/design/*.json
|
|
|
|
rm -rf ${RV_ROOT}/design/*.fir
|
|
|
|
rm -rf ${RV_ROOT}/generated_rtl/*.sv
|
2021-03-29 21:34:16 +08:00
|
|
|
rm -rf $(OFILES_PATH)/*.log
|
|
|
|
rm -rf $(OFILES_PATH)/*.s
|
|
|
|
rm -rf $(OFILES_PATH)/*.hex
|
|
|
|
rm -rf $(OFILES_PATH)/*.dis
|
|
|
|
rm -rf $(OFILES_PATH)/*.tbl
|
|
|
|
rm -rf $(OFILES_PATH)/vcs*
|
|
|
|
rm -rf $(OFILES_PATH)/simv*
|
2021-03-03 14:35:11 +08:00
|
|
|
rm -rf ${RV_ROOT}/design/src/main/scala/lib/param.scala
|
|
|
|
rm -rf ${RV_ROOT}/design/snapshots
|
2021-03-29 21:34:16 +08:00
|
|
|
rm -rf $(OFILES_PATH)/quasar*
|
|
|
|
rm -rf $(OFILES_PATH)/*.exe
|
|
|
|
rm -rf $(OFILES_PATH)/obj*
|
|
|
|
rm -rf $(OFILES_PATH)/*.o
|
|
|
|
rm -rf $(OFILES_PATH)/ucli.key
|
|
|
|
rm -rf $(OFILES_PATH)/vc_hdrs.h
|
|
|
|
rm -rf $(OFILES_PATH)/csrc
|
|
|
|
rm -rf $(OFILES_PATH)/*.csv
|
|
|
|
rm -rf $(OFILES_PATH)/work
|
|
|
|
rm -rf $(OFILES_PATH)/*.dump
|
|
|
|
rm -rf $(OFILES_PATH)/*.fsdb
|
|
|
|
rm -rf ${RV_ROOT}/FM_WORK
|
|
|
|
rm -rf ${RV_ROOT}/tracer_logs/*.log
|
|
|
|
rm -rf *.log *.lck *.s *.hex *.dis *.tbl vcs* simv* quasar* *.exe obj* *.o ucli.key vc_hdrs.h csrc *.csv work *.dump *.fsdb
|
2021-03-03 14:35:11 +08:00
|
|
|
|