2022-05-10 20:50:30 +08:00
|
|
|
export RV_ROOT = ${PWD}/..
|
|
|
|
GCC_PREFIX = /opt/riscv/bin/riscv32-unknown-elf
|
|
|
|
GDB_PREFIX = /opt/riscv/bin/riscv32-unknown-elf-gdb
|
|
|
|
|
|
|
|
ABI = -mabi=ilp32 -march=rv32imc
|
|
|
|
|
|
|
|
DEMODIR = ${PWD}
|
|
|
|
BUILD_DIR = ${DEMODIR}/build
|
|
|
|
|
|
|
|
RV_SOC = ${RV_ROOT}/soc
|
|
|
|
|
|
|
|
TEST = demo
|
|
|
|
|
|
|
|
ifdef debug
|
|
|
|
DEBUG_PLUS = +dumpon
|
|
|
|
VERILATOR_DEBUG = --trace
|
|
|
|
endif
|
|
|
|
|
|
|
|
LINK = $(DEMODIR)/link.ld
|
|
|
|
LINKPRO = $(DEMODIR)/link.ld
|
|
|
|
|
|
|
|
# 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
|
2023-01-07 16:15:54 +08:00
|
|
|
mkdir -p build
|
2022-05-10 20:50:30 +08:00
|
|
|
|
|
|
|
##################### Verilog Builds #####################################
|
2023-01-05 21:28:53 +08:00
|
|
|
top.v:
|
|
|
|
./ivlpp -F include.f -f soc.mk -o top.v
|
2022-05-10 20:50:30 +08:00
|
|
|
|
2023-01-05 21:28:53 +08:00
|
|
|
verilator-build: top.v
|
2022-05-10 20:50:30 +08:00
|
|
|
verilator --cc -CFLAGS ${CFLAGS} \
|
|
|
|
-Wno-WIDTH \
|
|
|
|
-Wno-UNOPTFLAT \
|
2023-01-06 21:19:54 +08:00
|
|
|
-I../src \
|
|
|
|
-F ./soc.mk \
|
2022-05-10 20:50:30 +08:00
|
|
|
--top-module soc_sim -exe test_soc_sim.cpp --autoflush $(VERILATOR_DEBUG)
|
|
|
|
cp ${DEMODIR}/test_soc_sim.cpp obj_dir
|
|
|
|
$(MAKE) -j -e -C obj_dir/ -f Vsoc_sim.mk $(VERILATOR_MAKE_FLAGS)
|
|
|
|
|
|
|
|
##################### Simulation Runs #####################################
|
|
|
|
|
2023-01-07 16:15:54 +08:00
|
|
|
verilator: program verilator-build bin
|
2022-05-10 20:50:30 +08:00
|
|
|
cd build && ../obj_dir/Vsoc_sim ${DEBUG_PLUS}
|
|
|
|
|
|
|
|
sim:
|
|
|
|
cd build && ../obj_dir/Vsoc_sim ${DEBUG_PLUS}
|
|
|
|
|
|
|
|
##################### Test hex Build #####################################
|
|
|
|
|
2023-01-07 16:15:54 +08:00
|
|
|
program: $(TEST).o $(LINK)
|
2022-05-10 20:50:30 +08:00
|
|
|
@echo Building $(TEST)
|
|
|
|
$(GCC_PREFIX)-gcc $(ABI) -Wl,-Map=$(BUILD_DIR)/$(TEST).map -lgcc -T$(LINKPRO) -o $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/$(TEST).o -nostartfiles $(TEST_LIBS)
|
|
|
|
$(GCC_PREFIX)-objcopy -O verilog $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/program.hex
|
|
|
|
$(GCC_PREFIX)-gcc $(ABI) -Wl,-Map=$(BUILD_DIR)/$(TEST).map -lgcc -T$(LINK) -o $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/$(TEST).o -nostartfiles $(TEST_LIBS)
|
|
|
|
$(GCC_PREFIX)-objdump -S $(BUILD_DIR)/$(TEST).bin > $(BUILD_DIR)/$(TEST).dis
|
|
|
|
@echo Completed building $(TEST)
|
|
|
|
|
2023-01-07 16:15:54 +08:00
|
|
|
# program:
|
|
|
|
# cp ${DEMODIR}/program.hex ./build/
|
|
|
|
|
2022-05-10 20:50:30 +08:00
|
|
|
%.o : %.s
|
|
|
|
@mkdir -p $(BUILD_DIR)
|
|
|
|
$(GCC_PREFIX)-cpp -g $< > $(BUILD_DIR)/$*.cpp.s
|
|
|
|
$(GCC_PREFIX)-as -g $(ABI) $(BUILD_DIR)/$*.cpp.s -o $(BUILD_DIR)/$@
|
|
|
|
|
|
|
|
##################### openocd #####################################
|
|
|
|
|
|
|
|
|
|
|
|
bin: $(ELF_FILE)
|
|
|
|
$(GCC_PREFIX)-objcopy -O verilog test.elf $(BUILD_DIR)/test.hex
|
|
|
|
|
|
|
|
help:
|
|
|
|
@echo Possible targets: verilator help clean all verilator-build program.hex
|
|
|
|
|
|
|
|
.PHONY: help clean verilator
|