-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
97 lines (75 loc) · 2.3 KB
/
Makefile
File metadata and controls
97 lines (75 loc) · 2.3 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
90
91
92
93
94
95
96
97
ARCH := aarch64
PREFIX := $(ARCH)-linux-gnu-
CC := $(PREFIX)gcc
ALL_C_FILES := $(shell find . -name *.c -not -path './arch/*' | sed 's|^\./||') \
$(shell find arch/${ARCH} -name *.c)
ALL_ASM_FILES := $(shell find . -name *.S -not -path './arch/*' | sed 's|^\./||') \
$(shell find arch/${ARCH} -name *.S)
O_FILES := $(patsubst %.S,build/%.o,$(ALL_ASM_FILES)) $(patsubst %.c,build/%.o,$(ALL_C_FILES))
CFLAGS := -mgeneral-regs-only -Tlinker/linker-$(ARCH).ld
CFLAGS += -std=c23 -O2 -fno-builtin -ffreestanding -Wundef \
-Wpointer-arith \
-Wno-nonnull \
-nostdlib \
-nostartfiles
# Add includes folders to compiler flags
INCLUDE_DIRS := $(shell find . -name includes | sed 's|^\./||')
INCLUDE_FLAGS := $(addprefix -I,$(INCLUDE_DIRS))
CFLAGS += $(INCLUDE_FLAGS)
# Find files for fmt
CLANG_FORMAT := clang-format
all: build
build: build/byteos.bin
build/byteos.bin: build/byteos
@llvm-objcopy -O binary $< $@
build/byteos: $(O_FILES)
@$(CC) $(CFLAGS) -static -o $@ $^
build/%.o: ./%.c
@mkdir -p $(shell dirname $@)
@echo "CC $<"
@$(CC) $(CFLAGS) -c -o $@ $<
build/%.o: ./%.S
@mkdir -p $(shell dirname $@)
@echo "CC $<"
@$(CC) $(CFLAGS) -c -o $@ $<
# format all code *.cpp *.h
fmt: $(shell find . -name '*.c' -or -name '*.h' -not -path './build/*')
@$(CLANG_FORMAT) -i -style=file $^
@echo "All files have been formatted."
fdt:
@qemu-system-$(ARCH) -M 128m -machine virt,dumpdtb=virt.out
fdtdump virt.out
clean:
@rm $(O_FILES)
@rm build/byteos.bin
@rm build/byteos
run: build
qemu-system-$(ARCH) \
-machine virt \
-cpu cortex-a72 \
-kernel build/byteos.bin \
-nographic \
-D qemu.log \
-d in_asm,int,pcall,cpu_reset,guest_errors
gdb_server:
qemu-system-$(ARCH) \
-cpu cortex-a72 \
-machine virt \
-kernel build/byteos.bin \
-nographic \
-D qemu.log \
-d in_asm,int,pcall,cpu_reset,guest_errors -s -S
debug: build
@tmux new-session -d \
"ninja -C build run && echo '按任意键继续' && read -n 1" && \
tmux split-window -h "gdb build/byteos -ex 'target remote localhost:1234' -ex 'disp /16i $pc' " && \
tmux -2 attach-session -d
QEMU_LOG=n
qemu: build/byteos.bin
qemu-system-$(ARCH) \
-cpu cortex-a72 \
-M virt -nographic \
-D qemu.log \
-d in_asm,int,pcall,cpu_reset,guest_errors \
-kernel build/byteos.bin
.PHONY: all fmt show-files clean run cmake gdb_server debug