picorv32/Makefile

167 lines
7.8 KiB
Makefile
Raw Normal View History

2015-06-06 20:01:37 +08:00
RISCV_GNU_TOOLCHAIN_GIT_REVISION = 411d134
2023-01-07 19:37:25 +08:00
RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX = /opt/riscv
# Give the user some easy overrides for local configuration quirks.
# If you change one of these and it breaks, then you get to keep both pieces.
SHELL = bash
PYTHON = python3
VERILATOR = verilator
ICARUS_SUFFIX =
IVERILOG = iverilog$(ICARUS_SUFFIX)
VVP = vvp$(ICARUS_SUFFIX)
2015-06-27 04:02:22 +08:00
TEST_OBJS = $(addsuffix .o,$(basename $(wildcard tests/*.S)))
2023-01-16 20:41:28 +08:00
FIRMWARE_OBJS = build/start.o build/print.o build/hello.o build/sieve.o build/multest.o build/stats.o
2015-07-04 22:31:26 +08:00
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
2023-01-07 19:37:25 +08:00
TOOLCHAIN_PREFIX = $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)/bin/riscv32-unknown-elf-
2015-06-06 20:01:37 +08:00
CFLAGS = -MD -O3 -mabi=ilp32 -march=rv32im -DTIME -DRISCV
GIT_ENV = true
test_verilator: build/testbench_verilator build/firmware.hex build/dhry.hex
2023-01-13 15:44:41 +08:00
cd build && ./testbench_verilator firmware.hex
cd build && ./testbench_verilator dhry.hex
2023-01-16 20:41:28 +08:00
firmware: build/testbench_verilator build/firmware.hex
2023-01-13 15:44:41 +08:00
cd build && ./testbench_verilator firmware.hex
dhry: build/firmware.hex build/dhry.hex
cd build && ./testbench_verilator dhry.hex
build/testbench_verilator: testbench_wb.v picorv32.v testbench.cc
2023-01-09 15:33:37 +08:00
$(VERILATOR) --cc --exe -Wno-lint -trace --top-module picorv32_wrapper testbench_wb.v picorv32.v testbench.cc \
2023-01-12 15:58:11 +08:00
--Mdir testbench_verilator_dir
$(MAKE) -C testbench_verilator_dir -f Vpicorv32_wrapper.mk
cp testbench_verilator_dir/Vpicorv32_wrapper build/testbench_verilator
2017-09-14 00:45:57 +08:00
check: check-yices
check-%: check.smt2
yosys-smtbmc -s $(subst check-,,$@) -t 30 --dump-vcd check.vcd check.smt2
yosys-smtbmc -s $(subst check-,,$@) -t 25 --dump-vcd check.vcd -i check.smt2
check.smt2: picorv32.v
yosys -v2 -p 'read_verilog -formal picorv32.v' \
-p 'prep -top picorv32 -nordff' \
2021-12-27 17:52:12 +08:00
-p 'assertpmux -noinit; opt -fast; dffunmap' \
2017-09-14 00:45:57 +08:00
-p 'write_smt2 -wires check.smt2'
2015-06-30 07:46:25 +08:00
synth.v: picorv32.v scripts/yosys/synth_sim.ys
yosys -qv3 -l synth.log scripts/yosys/synth_sim.ys
# firmware.hex
build/firmware.hex: build/firmware.elf
2023-01-09 20:05:40 +08:00
$(TOOLCHAIN_PREFIX)objcopy -O verilog $< $@
build/firmware.elf: $(FIRMWARE_OBJS) $(TEST_OBJS) firmware/sections.lds
2023-01-10 19:56:05 +08:00
$(TOOLCHAIN_PREFIX)gcc -Os -mabi=ilp32 -march=rv32im -ffreestanding -nostdlib -o $@ \
-Wl,--build-id=none,-Bstatic,-T,firmware/sections.lds,-Map,build/firmware.map,--strip-debug \
2015-06-27 04:02:22 +08:00
$(FIRMWARE_OBJS) $(TEST_OBJS) -lgcc
$(TOOLCHAIN_PREFIX)objdump -S $@ > build/firmware.dis
2015-06-06 20:01:37 +08:00
chmod -x $@
build/start.o: firmware/start.S
2023-01-10 19:56:05 +08:00
$(TOOLCHAIN_PREFIX)gcc -c -mabi=ilp32 -march=rv32im -o $@ $<
2015-06-25 20:08:39 +08:00
build/%.o: firmware/%.c
2023-01-10 19:56:05 +08:00
$(TOOLCHAIN_PREFIX)gcc -c -mabi=ilp32 -march=rv32i -Os --std=c99 $(GCC_WARNS) -ffreestanding -nostdlib -o $@ $<
2015-06-27 04:02:22 +08:00
2015-06-06 20:01:37 +08:00
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 $<)) \
2015-06-06 20:01:37 +08:00
-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, \
if ! test -d /var/cache/distfiles/$(REPO).git; then rm -rf /var/cache/distfiles/$(REPO).git.part; \
git clone --bare https://github.com/riscv/$(REPO) /var/cache/distfiles/$(REPO).git.part; \
mv /var/cache/distfiles/$(REPO).git.part /var/cache/distfiles/$(REPO).git; else \
(cd /var/cache/distfiles/$(REPO).git; git fetch https://github.com/riscv/$(REPO)); fi;)'
define build_tools_template
build-$(1)-tools:
@read -p "This will remove all existing data from $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)$(subst riscv32,,$(1)). Type YES to continue: " reply && [[ "$$$$reply" == [Yy][Ee][Ss] || "$$$$reply" == [Yy] ]]
sudo bash -c "set -ex; rm -rf $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)$(subst riscv32,,$(1)); mkdir -p $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)$(subst riscv32,,$(1)); chown $$$${USER}: $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)$(subst riscv32,,$(1))"
+$(MAKE) build-$(1)-tools-bh
2016-04-11 18:46:29 +08:00
build-$(1)-tools-bh:
+set -ex; $(GIT_ENV); \
if [ -d /var/cache/distfiles/riscv-gnu-toolchain.git ]; then reference_riscv_gnu_toolchain="--reference /var/cache/distfiles/riscv-gnu-toolchain.git"; else reference_riscv_gnu_toolchain=""; fi; \
if [ -d /var/cache/distfiles/riscv-binutils-gdb.git ]; then reference_riscv_binutils_gdb="--reference /var/cache/distfiles/riscv-binutils-gdb.git"; else reference_riscv_binutils_gdb=""; fi; \
if [ -d /var/cache/distfiles/riscv-gcc.git ]; then reference_riscv_gcc="--reference /var/cache/distfiles/riscv-gcc.git"; else reference_riscv_gcc=""; fi; \
if [ -d /var/cache/distfiles/riscv-glibc.git ]; then reference_riscv_glibc="--reference /var/cache/distfiles/riscv-glibc.git"; else reference_riscv_glibc=""; fi; \
2016-12-08 21:09:09 +08:00
if [ -d /var/cache/distfiles/riscv-newlib.git ]; then reference_riscv_newlib="--reference /var/cache/distfiles/riscv-newlib.git"; else reference_riscv_newlib=""; fi; \
rm -rf riscv-gnu-toolchain-$(1); git clone $$$$reference_riscv_gnu_toolchain https://github.com/riscv/riscv-gnu-toolchain riscv-gnu-toolchain-$(1); \
cd riscv-gnu-toolchain-$(1); git checkout $(RISCV_GNU_TOOLCHAIN_GIT_REVISION); \
git submodule update --init $$$$reference_riscv_binutils_gdb riscv-binutils; \
git submodule update --init $$$$reference_riscv_binutils_gdb riscv-gdb; \
git submodule update --init $$$$reference_riscv_gcc riscv-gcc; \
git submodule update --init $$$$reference_riscv_glibc riscv-glibc; \
2016-12-08 21:09:09 +08:00
git submodule update --init $$$$reference_riscv_newlib riscv-newlib; \
mkdir build; cd build; ../configure --with-arch=$(2) --prefix=$(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)$(subst riscv32,,$(1)); make
.PHONY: build-$(1)-tools
endef
$(eval $(call build_tools_template,riscv32i,rv32i))
$(eval $(call build_tools_template,riscv32ic,rv32ic))
$(eval $(call build_tools_template,riscv32im,rv32im))
$(eval $(call build_tools_template,riscv32imc,rv32imc))
2016-04-11 18:46:29 +08:00
build-tools:
@echo "This will remove all existing data from $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)i, $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)ic, $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)im, and $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX)imc."
2016-04-11 18:46:29 +08:00
@read -p "Type YES to continue: " reply && [[ "$$reply" == [Yy][Ee][Ss] || "$$reply" == [Yy] ]]
sudo bash -c "set -ex; rm -rf $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX){i,ic,im,imc}; mkdir -p $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX){i,ic,im,imc}; chown $${USER}: $(RISCV_GNU_TOOLCHAIN_INSTALL_PREFIX){i,ic,im,imc}"
+$(MAKE) build-riscv32i-tools-bh
+$(MAKE) build-riscv32ic-tools-bh
+$(MAKE) build-riscv32im-tools-bh
+$(MAKE) build-riscv32imc-tools-bh
2016-04-11 18:46:29 +08:00
2015-06-30 18:25:05 +08:00
toc:
gawk '/^-+$$/ { y=tolower(x); gsub("[^a-z0-9]+", "-", y); gsub("-$$", "", y); printf("- [%s](#%s)\n", x, y); } { x=$$0; }' README.md
2015-06-06 20:01:37 +08:00
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 $(TEST_OBJS) check.smt2 check.vcd synth.v synth.log \
testbench_verilator_dir
2015-06-06 20:01:37 +08:00
2023-01-09 15:33:37 +08:00
.PHONY: test_wb test_wb_vcd download-tools build-tools toc clean