99 lines
3.4 KiB
Makefile
99 lines
3.4 KiB
Makefile
export RV_ROOT = ${PWD}/../..
|
|
LLVMINSTALL = /home/colin/develop/llvm-build/install
|
|
GCC_PREFIX = /opt/riscv/bin/riscv64-unknown-elf
|
|
|
|
|
|
TEST_CFLAGS = -g -O3 -funroll-all-loops
|
|
ABI = -mabi=ilp32 -march=rv32imc
|
|
|
|
# Allow tool override
|
|
VERILATOR = verilator
|
|
DEMODIR = ${PWD}
|
|
BUILD_DIR = ${DEMODIR}/build
|
|
RV_DESIGN = ${RV_ROOT}/design
|
|
RV_SOC = ${RV_ROOT}/soc
|
|
|
|
TEST = hello_world
|
|
|
|
ifdef debug
|
|
DEBUG_PLUS = +dumpon
|
|
VERILATOR_DEBUG = --trace
|
|
endif
|
|
|
|
LINK = $(DEMODIR)/link.ld
|
|
|
|
OFILES = $(TEST).o
|
|
OUTFILES = $(TEST).out
|
|
|
|
SOCFILES = $(RV_SOC)/soc_top.sv $(RV_SOC)/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
|
|
|
|
${BUILD_DIR}/defines.h :
|
|
BUILD_PATH=${BUILD_DIR} PERLLIB=${RV_SOC} ${RV_SOC}/swerv.config -target=default -set iccm_enable
|
|
|
|
##################### Verilog Builds #####################################
|
|
|
|
verilator-build: ${SOCFILES} ${BUILD_DIR}/defines.h test_soc_top.cpp
|
|
echo '`undef ASSERT_ON' >> ${BUILD_DIR}/common_defines.vh
|
|
$(VERILATOR) --cc -CFLAGS ${CFLAGS} $(defines) $(includes) \
|
|
-Wno-UNOPTFLAT \
|
|
-I${DEMODIR} \
|
|
-I${RV_SOC} \
|
|
-f ${RV_SOC}/flist \
|
|
${SOCFILES} \
|
|
--top-module soc_top -exe test_soc_top.cpp --autoflush $(VERILATOR_DEBUG)
|
|
cp ${DEMODIR}/test_soc_top.cpp obj_dir
|
|
$(MAKE) -j -C obj_dir/ -f Vsoc_top.mk $(VERILATOR_MAKE_FLAGS)
|
|
|
|
##################### Simulation Runs #####################################
|
|
|
|
verilator: program.hex verilator-build
|
|
cd build && ../obj_dir/Vsoc_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).bin $(BUILD_DIR)/$(OFILES) -nostartfiles $(TEST_LIBS)
|
|
# $(GCC_PREFIX)-objcopy -O verilog $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/program.hex
|
|
# $(GCC_PREFIX)-objdump -S $(BUILD_DIR)/$(TEST).bin > $(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)/$@
|
|
|
|
program.hex: $(OUTFILES)
|
|
@echo Building $(TEST)
|
|
$(GCC_PREFIX)-objcopy -O verilog $(BUILD_DIR)/$(TEST).out $(BUILD_DIR)/program.hex
|
|
$(GCC_PREFIX)-objdump -S $(BUILD_DIR)/$(TEST).out > $(BUILD_DIR)/$(TEST).dis
|
|
|
|
##################### llvm hex Build #####################################
|
|
|
|
build: $(OUTFILES)
|
|
@echo Completed building $(TEST)
|
|
|
|
%.out : %.c ${BUILD_DIR}/defines.h
|
|
$(LLVMINSTALL)/bin/clang --target=riscv32 -march=rv32gc $*.c -S -o $(BUILD_DIR)/$*.s -mno-relax
|
|
$(LLVMINSTALL)/bin/clang --target=riscv32 -march=rv32gc $*.c -c -o $(BUILD_DIR)/$*.o -mno-relax
|
|
$(LLVMINSTALL)/bin/ld.lld $(BUILD_DIR)/$*.o -Map=$(BUILD_DIR)/$(TEST).map -T$(LINK) -o $(BUILD_DIR)/$*.out
|
|
@echo Completed building $(TEST)
|
|
|
|
help:
|
|
@echo Possible targets: verilator help clean all verilator-build program.hex
|
|
|
|
.PHONY: help clean verilator |