Add dhry.hex build in the top makefile.

This commit is contained in:
colin.liang 2023-01-13 15:32:58 +08:00
parent 2cf0e04e02
commit e345620054
2 changed files with 52 additions and 23 deletions

1
.gitignore vendored
View File

@ -37,3 +37,4 @@
/synth.v
.*.swp
.vscode
build

View File

@ -12,29 +12,24 @@ IVERILOG = iverilog$(ICARUS_SUFFIX)
VVP = vvp$(ICARUS_SUFFIX)
TEST_OBJS = $(addsuffix .o,$(basename $(wildcard tests/*.S)))
FIRMWARE_OBJS = firmware/start.o firmware/irq.o firmware/print.o firmware/hello.o firmware/sieve.o firmware/multest.o firmware/stats.o
FIRMWARE_OBJS = build/start.o build/irq.o build/print.o build/hello.o build/sieve.o build/multest.o build/stats.o
GCC_WARNS = -Werror -Wall -Wextra -Wshadow -Wundef -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings
GCC_WARNS += -Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes -pedantic # -Wconversion
TOOLCHAIN_PREFIX = $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)/bin/riscv32-unknown-elf-
# Add things like "export http_proxy=... https_proxy=..." here
CFLAGS = -MD -O3 -mabi=ilp32 -march=rv32im -DTIME -DRISCV
GIT_ENV = true
test_wb: testbench_wb.vvp firmware/firmware.hex
$(VVP) -N $<
test_verilator: build/testbench_verilator build/firmware.hex build/dhry.hex
./build/testbench_verilator build/firmware.hex
./build/testbench_verilator build/dhry.hex
test_wb_vcd: testbench_wb.vvp firmware/firmware.hex
$(VVP) -N $< +vcd +trace +noerror
test_verilator: testbench_verilator firmware/firmware.hex
./testbench_verilator firmware/firmware.hex
./testbench_verilator dhrystone/dhry.hex
testbench_verilator: testbench_wb.v picorv32.v testbench.cc
build/testbench_verilator: testbench_wb.v picorv32.v testbench.cc
$(VERILATOR) --cc --exe -Wno-lint -trace --top-module picorv32_wrapper testbench_wb.v picorv32.v testbench.cc \
--Mdir testbench_verilator_dir
$(MAKE) -C testbench_verilator_dir -f Vpicorv32_wrapper.mk
cp testbench_verilator_dir/Vpicorv32_wrapper testbench_verilator
cp testbench_verilator_dir/Vpicorv32_wrapper build/testbench_verilator
check: check-yices
@ -51,26 +46,57 @@ check.smt2: picorv32.v
synth.v: picorv32.v scripts/yosys/synth_sim.ys
yosys -qv3 -l synth.log scripts/yosys/synth_sim.ys
firmware/firmware.hex: firmware/firmware.elf
# firmware.hex
build/firmware.hex: build/firmware.elf
$(TOOLCHAIN_PREFIX)objcopy -O verilog $< $@
firmware/firmware.elf: $(FIRMWARE_OBJS) $(TEST_OBJS) firmware/sections.lds
build/firmware.elf: $(FIRMWARE_OBJS) $(TEST_OBJS) firmware/sections.lds
$(TOOLCHAIN_PREFIX)gcc -Os -mabi=ilp32 -march=rv32im -ffreestanding -nostdlib -o $@ \
-Wl,--build-id=none,-Bstatic,-T,firmware/sections.lds,-Map,firmware/firmware.map,--strip-debug \
-Wl,--build-id=none,-Bstatic,-T,firmware/sections.lds,-Map,build/firmware.map,--strip-debug \
$(FIRMWARE_OBJS) $(TEST_OBJS) -lgcc
$(TOOLCHAIN_PREFIX)objdump -S $@ > firmware/firmware.dis
$(TOOLCHAIN_PREFIX)objdump -S $@ > build/firmware.dis
chmod -x $@
firmware/start.o: firmware/start.S
build/start.o: firmware/start.S
$(TOOLCHAIN_PREFIX)gcc -c -mabi=ilp32 -march=rv32im -o $@ $<
firmware/%.o: firmware/%.c
build/%.o: firmware/%.c
$(TOOLCHAIN_PREFIX)gcc -c -mabi=ilp32 -march=rv32i -Os --std=c99 $(GCC_WARNS) -ffreestanding -nostdlib -o $@ $<
tests/%.o: tests/%.S tests/riscv_test.h tests/test_macros.h
$(TOOLCHAIN_PREFIX)gcc -c -mabi=ilp32 -march=rv32im -o $@ -DTEST_FUNC_NAME=$(notdir $(basename $<)) \
-DTEST_FUNC_TXT='"$(notdir $(basename $<))"' -DTEST_FUNC_RET=$(notdir $(basename $<))_ret $<
# dhry.hex
DHRY_OBJS = build/dhry_1.o build/dhry_2.o build/syscalls.o build/stdlib.o
build/dhry.hex: build/dhry.elf
$(TOOLCHAIN_PREFIX)objcopy -O verilog $< $@
build/dhry.elf: $(DHRY_OBJS)
$(TOOLCHAIN_PREFIX)gcc $(CFLAGS) -Wl,-Bstatic,-T,firmware/riscv.ld,-Map,build/dhry.map,--strip-debug -o $@ $(DHRY_OBJS) -lgcc -lc
chmod -x $@
build/dhry_1.o: dhrystone/dhry_1.c
$(TOOLCHAIN_PREFIX)gcc -c $(CFLAGS) $< -o $@
build/dhry_2.o: dhrystone/dhry_2.c
$(TOOLCHAIN_PREFIX)gcc -c $(CFLAGS) $< -o $@
build/syscalls.o: dhrystone/syscalls.c
$(TOOLCHAIN_PREFIX)gcc -c $(CFLAGS) $< -o $@
build/stdlib.o: dhrystone/stdlib.c
$(TOOLCHAIN_PREFIX)gcc -c $(CFLAGS) $< -o $@
build/dhry_1.o build/dhry_2.o: CFLAGS += -Wno-implicit-int -Wno-implicit-function-declaration
download-tools:
sudo bash -c 'set -ex; mkdir -p /var/cache/distfiles; $(GIT_ENV); \
$(foreach REPO,riscv-gnu-toolchain riscv-binutils-gdb riscv-gcc riscv-glibc riscv-newlib, \
@ -122,11 +148,13 @@ toc:
gawk '/^-+$$/ { y=tolower(x); gsub("[^a-z0-9]+", "-", y); gsub("-$$", "", y); printf("- [%s](#%s)\n", x, y); } { x=$$0; }' README.md
clean:
rm -rf build || true
mkdir -p build
rm -rf riscv-gnu-toolchain-riscv32i riscv-gnu-toolchain-riscv32ic \
riscv-gnu-toolchain-riscv32im riscv-gnu-toolchain-riscv32imc
rm -vrf $(FIRMWARE_OBJS) $(TEST_OBJS) check.smt2 check.vcd synth.v synth.log \
firmware/firmware.elf firmware/firmware.bin firmware/firmware.dis firmware/firmware.hex firmware/firmware.map \
testbench_wb.vvp testbench.vcd testbench.trace \
testbench_verilator testbench_verilator_dir
rm -vrf $(TEST_OBJS) check.smt2 check.vcd synth.v synth.log \
testbench_verilator_dir
.PHONY: test_wb test_wb_vcd download-tools build-tools toc clean