-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (69 loc) · 3.19 KB
/
Makefile
File metadata and controls
89 lines (69 loc) · 3.19 KB
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
# Toolchain and tools
CC = riscv64-unknown-elf-gcc
OBJCOPY = riscv64-unknown-elf-objcopy
# Extension options - set to 1 to enable, 0 to disable
# Note: the toolchain might not support all combinations
RVM ?= 1 # Multiply/Divide (M extension)
RVA ?= 0 # Atomic Instructions (A extension)
RVC ?= 0 # Compressed Instructions (C extension)
# Build march string based on extensions enabled (canonical order: I, M, A, F, D, C)
MARCH_BASE = rv32i
MARCH_EXT = $(if $(filter 1,$(RVM)),m,)$(if $(filter 1,$(RVA)),a,)$(if $(filter 1,$(RVC)),c,)
MARCH = $(MARCH_BASE)$(MARCH_EXT)_zicsr
# Flags
CFLAGS_COMMON = -march=$(MARCH) -mabi=ilp32 -O2 -D_REENT_SMALL -I .
LDFLAGS_COMMON = -nostartfiles -static
LINKER_SCRIPT_NEWLIB = -Tlinker_newlib.ld
LINKER_SCRIPT_BARE = -Tlinker_bare.ld
NEWLIB_SPECS = --specs=nosys.specs
NEWLIB_NANO_SPECS = --specs=nano.specs
# Source file groups
ASM_TARGETS = test_asm1
BARE_TARGETS = test_bare1
NEWLIB_NANO_TARGETS = test_newlib_stdio test_newlib_primes test_newlib_malloc test_newlib_mandelbrot test_newlib_maze \
test_newlib_conway test_newlib_args test_newlib_fileio test_newlib_traps test_newlib_timer test_newlib_scheduler \
test_peripheral_uart test_peripheral_blkdev test_newlib_setjmp test_newlib_mext
NEWLIB_TARGETS = test_newlib_softfloat
ALL_ELF_TARGETS = $(addprefix build/,$(addsuffix .elf,$(ASM_TARGETS) $(BARE_TARGETS) $(NEWLIB_NANO_TARGETS) $(NEWLIB_TARGETS)))
ALL_BIN_TARGETS = $(addprefix build/,$(addsuffix .bin,$(ASM_TARGETS) $(BARE_TARGETS)))
# Object file suffixes (all compiled into build/)
STARTUP_NEWLIB = build/start_newlib.o
STARTUP_BARE = build/start_bare.o
SYSCALLS_NEWLIB = build/syscalls_newlib.o
# Default build
all: $(ALL_ELF_TARGETS) $(ALL_BIN_TARGETS)
# --- ASM-only targets ---
$(addprefix build/,$(ASM_TARGETS:%=%.elf)): build/%.elf: build/%.o
$(CC) $(CFLAGS_COMMON) $(LDFLAGS_COMMON) -Ttext=0 -nostdlib -o $@ $^
# --- Bare-metal C targets (no newlib) ---
$(addprefix build/,$(BARE_TARGETS:%=%.elf)): build/%.elf: $(STARTUP_BARE) build/%.o
$(CC) $(CFLAGS_COMMON) $(LDFLAGS_COMMON) $(LINKER_SCRIPT_BARE) -nostdlib -o $@ $^
# --- Newlib nano targets ---
$(addprefix build/,$(NEWLIB_NANO_TARGETS:%=%.elf)): build/%.elf: $(STARTUP_NEWLIB) $(SYSCALLS_NEWLIB) build/%.o
$(CC) $(CFLAGS_COMMON) $(LDFLAGS_COMMON) $(LINKER_SCRIPT_NEWLIB) $(NEWLIB_NANO_SPECS) -o $@ $^
# --- Newlib (full) + libm targets ---
$(addprefix build/,$(NEWLIB_TARGETS:%=%.elf)): build/%.elf: $(STARTUP_NEWLIB) $(SYSCALLS_NEWLIB) build/%.o
$(CC) $(CFLAGS_COMMON) $(LDFLAGS_COMMON) $(LINKER_SCRIPT_NEWLIB) $(NEWLIB_SPECS) -o $@ $^ -lm
# --- Generate .bin from .elf (only for asm and bare) ---
$(addprefix build/,$(ASM_TARGETS:%=%.bin)): build/%.bin: build/%.elf
$(OBJCOPY) -O binary $< $@
$(addprefix build/,$(BARE_TARGETS:%=%.bin)): build/%.bin: build/%.elf
$(OBJCOPY) -O binary $< $@
# --- Compile rules ---
# From tests/
build/%.o: tests/%.S | build
$(CC) $(CFLAGS_COMMON) -c -o $@ $<
build/%.o: tests/%.c | build
$(CC) $(CFLAGS_COMMON) -c -o $@ $<
# From root (startup/syscalls)
build/%.o: %.S | build
$(CC) $(CFLAGS_COMMON) -c -o $@ $<
build/%.o: %.c | build
$(CC) $(CFLAGS_COMMON) -c -o $@ $<
# Ensure build dir exists
build:
mkdir -p $@
# Clean
clean:
rm -rf build
.PHONY: all clean