2021-12-16 20:07:50 +08:00
|
|
|
export RV_ROOT = ${PWD}/../..
|
2021-12-17 21:29:59 +08:00
|
|
|
LLVMINSTALL = /home/colin/develop/llvm-build/install
|
|
|
|
GCC_PREFIX = /opt/riscv/bin/riscv64-unknown-elf
|
|
|
|
|
2021-12-16 20:07:50 +08:00
|
|
|
|
|
|
|
TEST_CFLAGS = -g -O3 -funroll-all-loops
|
|
|
|
ABI = -mabi=ilp32 -march=rv32imc
|
|
|
|
|
|
|
|
# Allow snapshot override
|
|
|
|
target = default
|
|
|
|
|
|
|
|
# Allow tool override
|
|
|
|
VERILATOR = verilator
|
|
|
|
TESTDIR = ${PWD}
|
|
|
|
BUILD_DIR = ${TESTDIR}/build
|
|
|
|
SWERV_CONFIG = ${TESTDIR}/swerv.config
|
2021-12-17 21:29:59 +08:00
|
|
|
RV_DESIGN = ${RV_ROOT}/design
|
2021-12-16 20:07:50 +08:00
|
|
|
|
|
|
|
TEST = hello_world
|
|
|
|
|
|
|
|
ifdef debug
|
|
|
|
DEBUG_PLUS = +dumpon
|
|
|
|
VERILATOR_DEBUG = --trace
|
|
|
|
endif
|
|
|
|
|
|
|
|
LINK = $(TESTDIR)/link.ld
|
|
|
|
|
|
|
|
OFILES = $(TEST).o
|
|
|
|
|
|
|
|
VPATH = $(BUILD_DIR) $(TESTDIR)
|
|
|
|
TESTFILES = $(TESTDIR)/tb_top.sv $(TESTDIR)/ahb_sif.sv
|
|
|
|
|
|
|
|
defines = $(BUILD_DIR)/common_defines.vh ${RV_DESIGN}/include/swerv_types.sv
|
|
|
|
includes = -I${RV_DESIGN}/include -I${RV_DESIGN}/lib -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
|
|
|
|
all: clean verilator
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf build obj_dir
|
|
|
|
# *.log *.hex *.dis *.tbl simv* *.map snapshots \
|
|
|
|
# verilator* *.exe obj* *.o hello_world.cpp.s ucli.key vc_hdrs.h csrc *.csv \
|
|
|
|
# work dataset.asdb library.cfg hello_world.o
|
|
|
|
|
|
|
|
# If define files do not exist, then run swerv.config.
|
|
|
|
${BUILD_DIR}/defines.h :
|
|
|
|
BUILD_PATH=${BUILD_DIR} ${SWERV_CONFIG} -target=$(target) -set iccm_enable
|
|
|
|
|
|
|
|
##################### Verilog Builds #####################################
|
|
|
|
|
|
|
|
verilator-build: ${TESTFILES} ${BUILD_DIR}/defines.h test_tb_top.cpp
|
|
|
|
echo '`undef ASSERT_ON' >> ${BUILD_DIR}/common_defines.vh
|
|
|
|
$(VERILATOR) --cc -CFLAGS ${CFLAGS} $(defines) $(includes) \
|
|
|
|
-Wno-UNOPTFLAT \
|
|
|
|
-I${TESTDIR} \
|
|
|
|
-f ${TESTDIR}/flist \
|
|
|
|
${TESTFILES} \
|
|
|
|
--top-module tb_top -exe test_tb_top.cpp --autoflush $(VERILATOR_DEBUG)
|
|
|
|
cp ${TESTDIR}/test_tb_top.cpp obj_dir
|
|
|
|
$(MAKE) -j -C obj_dir/ -f Vtb_top.mk $(VERILATOR_MAKE_FLAGS)
|
|
|
|
|
|
|
|
##################### Simulation Runs #####################################
|
|
|
|
|
|
|
|
verilator: program.hex verilator-build
|
|
|
|
cd build && ../obj_dir/Vtb_top ${DEBUG_PLUS}
|
|
|
|
|
|
|
|
##################### Test Build #####################################
|
|
|
|
|
|
|
|
program.hex: $(OFILES) $(LINK)
|
|
|
|
@echo Building $(TEST)
|
|
|
|
$(GCC_PREFIX)-gcc $(ABI) -Wl,-Map=$(BUILD_DIR)/$(TEST).map -lgcc -T$(LINK) -o $(BUILD_DIR)/$(TEST).exe $(BUILD_DIR)/$(OFILES) -nostartfiles $(TEST_LIBS)
|
|
|
|
$(GCC_PREFIX)-objcopy -O verilog $(BUILD_DIR)/$(TEST).exe $(BUILD_DIR)/program.hex
|
|
|
|
$(GCC_PREFIX)-objdump -S $(BUILD_DIR)/$(TEST).exe > $(BUILD_DIR)/$(TEST).dis
|
|
|
|
@echo Completed building $(TEST)
|
|
|
|
|
|
|
|
%.o : %.s ${BUILD_DIR}/defines.h
|
|
|
|
$(GCC_PREFIX)-cpp -I${BUILD_DIR} $< > $(BUILD_DIR)/$*.cpp.s
|
|
|
|
$(GCC_PREFIX)-as $(ABI) $(BUILD_DIR)/$*.cpp.s -o $(BUILD_DIR)/$@
|
|
|
|
|
2021-12-17 21:29:59 +08:00
|
|
|
##################### llvm hex Build #####################################
|
|
|
|
|
2021-12-16 20:07:50 +08:00
|
|
|
%.o : %.c ${BUILD_DIR}/defines.h
|
2021-12-17 21:29:59 +08:00
|
|
|
$(LLVMINSTALL)/bin/clang --target=riscv32 -march=rv32gc $*.c -c -o $(BUILD_DIR)/$*.o -mno-relax
|
|
|
|
$(LLVMINSTALL)/bin/ld.lld $(BUILD_DIR)/$*.o -o $(BUILD_DIR)/$*
|
2021-12-16 20:07:50 +08:00
|
|
|
|
|
|
|
help:
|
|
|
|
@echo Possible targets: verilator help clean all verilator-build program.hex
|
|
|
|
|
2021-12-17 21:29:59 +08:00
|
|
|
.PHONY: help clean verilator
|