This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
92 lines (73 loc) · 2.64 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
COMP = iverilog
SIM = vvp
SYN = yosys
PNR = arachne-pnr
PACK = icepack
PROG = iceprog
BIN32HEX = bin32hex.py
RISCV_TOOLS_PREFIX = third_party/riscv-toolchain/bin/riscv32-unknown-elf-
RISCV_GCC_LIB = third_party/riscv-toolchain/lib/gcc/riscv32-unknown-elf/7.2.0/libgcc.a
CC = $(RISCV_TOOLS_PREFIX)gcc
OBJCOPY = $(RISCV_TOOLS_PREFIX)objcopy
RISCV_TESTS_DIR = third_party/riscv-tests/isa/rv32ui
RISCV_TESTS_SRC = $(wildcard $(RISCV_TESTS_DIR)/*.S)
RISCV_TESTS = $(basename $(RISCV_TESTS_SRC))
RISCV_TESTS_ELF = $(addsuffix .elf,$(RISCV_TESTS))
RISCV_TESTS_HEX = $(addsuffix .hex,$(RISCV_TESTS))
RISCV_TEST_RESULT_OBJ = env/riscv_test_result.o
RISCV_TEST_DEFINES = test_defines.v
RISCV_TEST_INC = third_party/riscv-tests/isa/macros/scalar
RISCV_TEST_LINK_SCRIPT = third_party/riscv-tests/env/p/link.ld
RISCV_TEST_BENCH = riscv_test.v
RISCV_TEST_SIM = riscv_test.vvp
MEMSIZE = 8192
MEMWORDCOUNT = $(shell echo $(MEMSIZE) / 4 | bc)
OBJCOPYFLAGS = -O binary
PUTC_OBJ = env/putc.o
INC_DIR = env/inc
CCFLAGS = -Wall -fno-pic -fno-builtin -nostdlib -march=rv32i -mabi=ilp32 -O0 -DMEMSIZE=$(MEMSIZE)
COMP_FLAGS = -Wall -g2005
PCF = top.pcf
CORE = cpu
CORE_DEP = $(CORE).v alu.v mem.v regs.v uart-tx.v
TOP_TEST = top_test
FIRMWARE_NAME = firmware
FIRMWARE_SRC = firmware/start.s firmware/main.o
FIRMWWARE_LINK_SCRIPT = firmware/link.ld
all: $(TOP_TEST).vcd
$(CORE).blif: $(CORE_DEP) $(FIRMWARE_NAME).hex
$(SYN) -q -p "synth_ice40 -blif $@" $(CORE).v
%.txt: %.blif $(PCF)
$(PNR) -d 8k -p $(PCF) -o $@ $<
%.bin: %.txt
$(PACK) $< $@
$(TOP_TEST).vcd: $(TOP_TEST).vvp $(FIRMWARE_NAME).hex
$(SIM) $<
$(TOP_TEST).vvp: $(TOP_TEST).v $(CORE_DEP)
$(COMP) $(COMP_FLAGS) -o $@ $(TOP_TEST).v
flash: $(CORE).bin
$(PROG) -S $<$
%.hex: %.dump
./$(BIN32HEX) $< $@ $(MEMWORDCOUNT)
%.dump: %.elf
$(OBJCOPY) $(OBJCOPYFLAGS) $< $@
riscv_tests: $(RISCV_TESTS_HEX)
$(foreach t, $(RISCV_TESTS), $(call run_test, $(t)))
define run_test
$(file >$(RISCV_TEST_DEFINES),`define TEST_PROG "$(strip $(1)).hex")
$(file >>$(RISCV_TEST_DEFINES),`define TEST_NAME "$(basename $(notdir $(1)))")
$(shell $(COMP) $(COMP_FLAGS) -o $(RISCV_TEST_SIM) $(RISCV_TEST_BENCH))
@echo "$(shell $(SIM) $(RISCV_TEST_SIM))"
endef
%.o: %.c
$(CC) $(CCFLAGS) -I$(INC_DIR) -c -o $@ $<
%.elf: %.S | $(PUTC_OBJ) $(RISCV_TEST_RESULT_OBJ)
$(CC) $(CCFLAGS) -I$(INC_DIR) -I$(RISCV_TEST_INC) -T$(RISCV_TEST_LINK_SCRIPT) -o $@ $< \
$(RISCV_TEST_RESULT_OBJ) $(PUTC_OBJ)
$(FIRMWARE_NAME).elf: $(FIRMWARE_SRC)
$(CC) $(CCFLAGS) -T$(FIRMWWARE_LINK_SCRIPT) -o $@ $^ $(RISCV_GCC_LIB)
clean:
rm -f *.vvp *.vcd *.blif *.bin *.txt *.dump *.elf firmware/*.elf firmware/*.o \
$(RISCV_TEST_DEFINES) $(RISCV_TESTS_HEX)
.SILENT:
.PHONY: clean riscv_tests