-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
177 lines (131 loc) · 6.28 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
TOOL_PREFIX=aarch64-linux-musl-
BUILD_DIR=build
INCLUDE = -I ./include \
-I /home/ajax/rust/usb/first_state/aarch64-linux-musl-cross/aarch64-linux-musl/include
n = -nostdlib -nostdinc -fno-stack-protector
SMP = 1
HV = n
CFLAGS = -g -c -O0 -fno-pie -mgeneral-regs-only -fno-builtin-getc -fno-builtin-putc\
-fno-builtin-vsnprintf -fno-builtin-snprintf -fno-builtin-printf -DSMP_NUM=$(SMP)
QEMU_ARGS = -m 4G -smp $(SMP) -cpu cortex-a72 -nographic
QEMU_ARGS += -M virt,gic_version=2
# QEMU_ARGS += -M secure=on
ifeq ($(HV),y)
QEMU_ARGS += -M virtualization=on
endif
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# kernel main
$(BUILD_DIR)/main.o: main.c
$(TOOL_PREFIX)gcc $(CFLAGS) main.c $(INCLUDE) -o $(BUILD_DIR)/main.o
# kernel smp
$(BUILD_DIR)/smp.o: smp.c
$(TOOL_PREFIX)gcc $(CFLAGS) smp.c $(INCLUDE) -o $(BUILD_DIR)/smp.o
# kernel main hyper
$(BUILD_DIR)/main_hyper.o: main_hyper.c
$(TOOL_PREFIX)gcc $(CFLAGS) main_hyper.c $(INCLUDE) -o $(BUILD_DIR)/main_hyper.o
# boot
$(BUILD_DIR)/boot.s.o: boot/boot.S
$(TOOL_PREFIX)gcc $(CFLAGS) boot/boot.S $(INCLUDE) -o $(BUILD_DIR)/boot.s.o
# exception
$(BUILD_DIR)/exception.o: exception/exception.c
$(TOOL_PREFIX)gcc $(CFLAGS) exception/exception.c $(INCLUDE) -o $(BUILD_DIR)/exception.o
$(BUILD_DIR)/exception_el3.o: exception/exception_el3.c
$(TOOL_PREFIX)gcc $(CFLAGS) exception/exception_el3.c $(INCLUDE) -o $(BUILD_DIR)/exception_el3.o
$(BUILD_DIR)/exception_el2.o: exception/exception_el2.c
$(TOOL_PREFIX)gcc $(CFLAGS) exception/exception_el2.c $(INCLUDE) -o $(BUILD_DIR)/exception_el2.o
$(BUILD_DIR)/exception.s.o: exception/exception.S
$(TOOL_PREFIX)gcc $(CFLAGS) exception/exception.S $(INCLUDE) -o $(BUILD_DIR)/exception.s.o
$(BUILD_DIR)/exception_el3.s.o: exception/exception_el3.S
$(TOOL_PREFIX)gcc $(CFLAGS) exception/exception_el3.S $(INCLUDE) -o $(BUILD_DIR)/exception_el3.s.o
$(BUILD_DIR)/exception_el2.s.o: exception/exception_el2.S
$(TOOL_PREFIX)gcc $(CFLAGS) exception/exception_el2.S $(INCLUDE) -o $(BUILD_DIR)/exception_el2.s.o
$(BUILD_DIR)/gic.o: exception/gic/gic.c
$(TOOL_PREFIX)gcc $(CFLAGS) exception/gic/gic.c $(INCLUDE) -o $(BUILD_DIR)/gic.o
# io
$(BUILD_DIR)/io.o: io/io.c
$(TOOL_PREFIX)gcc $(CFLAGS) io/io.c $(INCLUDE) -o $(BUILD_DIR)/io.o
$(BUILD_DIR)/printf.o: io/printf.c
$(TOOL_PREFIX)gcc $(CFLAGS) io/printf.c $(INCLUDE) -o $(BUILD_DIR)/printf.o
$(BUILD_DIR)/uart_pl011.o: io/uart_pl011.c
$(TOOL_PREFIX)gcc $(CFLAGS) io/uart_pl011.c $(INCLUDE) -o $(BUILD_DIR)/uart_pl011.o
$(BUILD_DIR)/uart_pl011_early.o: io/uart_pl011_early.c
$(TOOL_PREFIX)gcc $(CFLAGS) io/uart_pl011_early.c $(INCLUDE) -o $(BUILD_DIR)/uart_pl011_early.o
# mem
$(BUILD_DIR)/mmu.s.o: mem/mmu.S
$(TOOL_PREFIX)gcc $(CFLAGS) mem/mmu.S $(INCLUDE) -o $(BUILD_DIR)/mmu.s.o
$(BUILD_DIR)/page.o: mem/page.c
$(TOOL_PREFIX)gcc $(CFLAGS) mem/page.c $(INCLUDE) -o $(BUILD_DIR)/page.o
$(BUILD_DIR)/string.o: mem/string.c
$(TOOL_PREFIX)gcc $(CFLAGS) mem/string.c $(INCLUDE) -o $(BUILD_DIR)/string.o
$(BUILD_DIR)/ept.o: mem/ept.c
$(TOOL_PREFIX)gcc $(CFLAGS) mem/ept.c $(INCLUDE) -o $(BUILD_DIR)/ept.o
# timer
$(BUILD_DIR)/timer.o: timer/timer.c
$(TOOL_PREFIX)gcc $(CFLAGS) timer/timer.c $(INCLUDE) -o $(BUILD_DIR)/timer.o
# schedule
$(BUILD_DIR)/task.o: schedule/task.c
$(TOOL_PREFIX)gcc $(CFLAGS) schedule/task.c $(INCLUDE) -o $(BUILD_DIR)/task.o
$(BUILD_DIR)/context.s.o: schedule/context.S
$(TOOL_PREFIX)gcc $(CFLAGS) schedule/context.S $(INCLUDE) -o $(BUILD_DIR)/context.s.o
# spinlock
$(BUILD_DIR)/spinlock.s.o: spinlock/spinlock.S
$(TOOL_PREFIX)gcc $(CFLAGS) spinlock/spinlock.S $(INCLUDE) -o $(BUILD_DIR)/spinlock.s.o
# hyper
$(BUILD_DIR)/vcpu.o: hyper/vcpu.c
$(TOOL_PREFIX)gcc $(CFLAGS) hyper/vcpu.c $(INCLUDE) -o $(BUILD_DIR)/vcpu.o
$(BUILD_DIR)/hyper_ctx.s.o: hyper/hyper_ctx.S
$(TOOL_PREFIX)gcc $(CFLAGS) hyper/hyper_ctx.S $(INCLUDE) -o $(BUILD_DIR)/hyper_ctx.s.o
$(BUILD_DIR)/vgic.o: hyper/vgic.c
$(TOOL_PREFIX)gcc $(CFLAGS) hyper/vgic.c $(INCLUDE) -o $(BUILD_DIR)/vgic.o
$(BUILD_DIR)/vm.o: hyper/vm.c
$(TOOL_PREFIX)gcc $(CFLAGS) hyper/vm.c $(INCLUDE) -o $(BUILD_DIR)/vm.o
# guest
$(BUILD_DIR)/guest.s.o: guest/guest.S
$(TOOL_PREFIX)gcc $(CFLAGS) guest/guest.S $(INCLUDE) -o $(BUILD_DIR)/guest.s.o
$(BUILD_DIR)/kernel.elf: $(BUILD_DIR) $(BUILD_DIR)/main.o $(BUILD_DIR)/smp.o $(BUILD_DIR)/main_hyper.o $(BUILD_DIR)/boot.s.o $(BUILD_DIR)/guest.s.o $(BUILD_DIR)/exception.s.o $(BUILD_DIR)/exception.o $(BUILD_DIR)/io.o $(BUILD_DIR)/uart_pl011.o $(BUILD_DIR)/uart_pl011_early.o $(BUILD_DIR)/printf.o $(BUILD_DIR)/mmu.s.o $(BUILD_DIR)/page.o $(BUILD_DIR)/ept.o $(BUILD_DIR)/string.o $(BUILD_DIR)/exception_el3.s.o $(BUILD_DIR)/exception_el3.o $(BUILD_DIR)/exception_el2.o $(BUILD_DIR)/exception_el2.s.o $(BUILD_DIR)/gic.o $(BUILD_DIR)/timer.o $(BUILD_DIR)/task.o $(BUILD_DIR)/context.s.o $(BUILD_DIR)/spinlock.s.o $(BUILD_DIR)/vcpu.o $(BUILD_DIR)/hyper_ctx.s.o $(BUILD_DIR)/vgic.o $(BUILD_DIR)/vm.o
$(TOOL_PREFIX)ld -T link.lds -o $(BUILD_DIR)/kernel.elf \
$(BUILD_DIR)/boot.s.o \
$(BUILD_DIR)/guest.s.o \
$(BUILD_DIR)/main.o \
$(BUILD_DIR)/smp.o \
$(BUILD_DIR)/main_hyper.o \
$(BUILD_DIR)/exception.s.o \
$(BUILD_DIR)/exception_el3.s.o \
$(BUILD_DIR)/exception.o \
$(BUILD_DIR)/exception_el3.o \
$(BUILD_DIR)/exception_el2.o \
$(BUILD_DIR)/exception_el2.s.o \
$(BUILD_DIR)/gic.o \
$(BUILD_DIR)/io.o \
$(BUILD_DIR)/uart_pl011.o \
$(BUILD_DIR)/uart_pl011_early.o \
$(BUILD_DIR)/printf.o \
$(BUILD_DIR)/mmu.s.o \
$(BUILD_DIR)/page.o \
$(BUILD_DIR)/ept.o \
$(BUILD_DIR)/string.o \
$(BUILD_DIR)/timer.o \
$(BUILD_DIR)/task.o \
$(BUILD_DIR)/context.s.o \
$(BUILD_DIR)/spinlock.s.o \
$(BUILD_DIR)/vcpu.o \
$(BUILD_DIR)/vgic.o \
$(BUILD_DIR)/vm.o \
$(BUILD_DIR)/hyper_ctx.s.o
# makefile 命令
deasm:
$(TOOL_PREFIX)objdump -x -d -S $(BUILD_DIR)/kernel.elf > $(BUILD_DIR)/dis.txt
$(TOOL_PREFIX)readelf -a $(BUILD_DIR)/kernel.elf > $(BUILD_DIR)/elf.txt
$(TOOL_PREFIX)objcopy -O binary $(BUILD_DIR)/kernel.elf $(BUILD_DIR)/kernel.bin
debug: $(BUILD_DIR)/kernel.elf deasm
qemu-system-aarch64 $(QEMU_ARGS) -kernel $(BUILD_DIR)/kernel.elf -s -S
gdb:
gdb-multiarch
run: $(BUILD_DIR)/kernel.elf
qemu-system-aarch64 $(QEMU_ARGS) -kernel $(BUILD_DIR)/kernel.elf
clean:
rm -f build/*.o
rm -f build/*.bin
rm -f build/*.txt
rm -f build/*.elf