forked from GrassLab/osdi2020
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
96 lines (68 loc) · 2.69 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
93
94
95
96
TOOLCHAIN_PREFIX = aarch64-linux-gnu-
CC = $(TOOLCHAIN_PREFIX)gcc
LD = $(TOOLCHAIN_PREFIX)ld
OBJCPY = $(TOOLCHAIN_PREFIX)objcopy
BUILD_DIR = build
SRC_DIR = src
LIB_DIR = lib
USER_DIR = user
LIB_C = $(wildcard $(LIB_DIR)/*.c)
LIB_OBJS_FILES = $(LIB_C:$(LIB_DIR)/%.c=$(BUILD_DIR)/lib/%_c.o)
SRC_C = $(wildcard $(SRC_DIR)/*.c)
SRC_ASM = $(wildcard $(SRC_DIR)/*.S)
SRC_OBJS_FILES = $(SRC_C:$(SRC_DIR)/%.c=$(BUILD_DIR)/src/%_c.o)
SRC_OBJS_FILES += $(SRC_ASM:$(SRC_DIR)/%.S=$(BUILD_DIR)/src/%_asm.o)
USER_C = $(wildcard $(USER_DIR)/*.c)
USER_ASM = $(wildcard $(USER_DIR)/*.S)
USER_OBJS_FILES = $(USER_C:$(USER_DIR)/%.c=$(BUILD_DIR)/user/%_c.o)
USER_OBJS_FILES += $(USER_ASM:$(USER_DIR)/%.S=$(BUILD_DIR)/user/%_asm.o)
NO_BUILT_IN = -fno-builtin-printf -fno-builtin-memcpy -fno-builtin-strcpy -fno-builtin-strlen
CFLAGS = -Wall -Wextra -nostdlib -nostdinc $(NO_BUILT_IN) -Iinclude -Ilib -c #-Werror
USER_CFLAGS = -Wall -Wextra -nostdlib -nostdinc -fno-zero-initialized-in-bss $(NO_BUILT_IN) -Ilib -c #-Werror
.PHONY: all clean
all: build_dir kernel8.img
# build library
$(BUILD_DIR)/lib/%_c.o: $(LIB_DIR)/%.c
mkdir -p $(@D)
$(CC) $(CFLAGS) $< -o $@
# build kernel
$(BUILD_DIR)/src/%_c.o: $(SRC_DIR)/%.c
mkdir -p $(@D)
$(CC) $(CFLAGS) $< -o $@
$(BUILD_DIR)/src/%_asm.o: $(SRC_DIR)/%.S
mkdir -p $(@D)
$(CC) $(CFLAGS) $< -o $@
kernel8.img: $(SRC_OBJS_FILES) $(LIB_OBJS_FILES) user_embed.elf
$(LD) $(SRC_OBJS_FILES) $(LIB_OBJS_FILES) user_embed.elf -T $(SRC_DIR)/linker.ld -o kernel8.elf
$(OBJCPY) -O binary kernel8.elf kernel8.img
# build user library
$(BUILD_DIR)/user/%_c.o: $(USER_DIR)/%.c
mkdir -p $(@D)
$(CC) $(USER_CFLAGS) $< -o $@
$(BUILD_DIR)/user/%_asm.o: $(USER_DIR)/%.S
mkdir -p $(@D)
$(CC) $(USER_CFLAGS) $< -o $@
user_embed.elf: $(USER_OBJS_FILES) $(LIB_OBJS_FILES)
$(LD) $(USER_OBJS_FILES) $(LIB_OBJS_FILES) -T $(USER_DIR)/linker.ld -o user.elf
$(OBJCPY) -O binary user.elf user.img
$(LD) -r -b binary user.img -o user_embed.elf
# run emulator
run: $(BUILD_DIR) kernel8.img
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -display none -serial stdio
sdrun: $(BUILD_DIR) kernel8.img
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -display none -serial stdio -drive if=sd,file=./ta_img/sfn_nctuos.img,format=raw
display: $(BUILD_DIR) kernel8.img
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -serial stdio
tty: $(BUILD_DIR) kernel8.img
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -serial pty
asm:
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -display none -d in_asm
debug: all
qemu-system-aarch64 -M raspi3 -kernel kernel8.img -serial stdio -display none -S -s
# utility
build_dir: $(BUILD_DIR)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
clean:
rm -rf $(BUILD_DIR)/*
rm -f *.elf *.img