-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
66 lines (50 loc) · 1.61 KB
/
Makefile
File metadata and controls
66 lines (50 loc) · 1.61 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
# ===== Toolchain =====
CROSS ?= aarch64-linux-gnu-
CC := $(CROSS)gcc
LD := $(CROSS)ld
OBJCOPY := $(CROSS)objcopy
OBJDUMP := $(CROSS)objdump
QEMU ?= qemu-system-aarch64
PLATFORM ?= qemu
INC_DIRS := include
DEBUG ?= 1
# ===== Flags =====
CFLAGS := -Wall -Wextra -O0 -g -ffreestanding -fno-builtin -fno-stack-protector \
-nostdlib -mcmodel=small -march=armv8-a -fno-omit-frame-pointer
ASFLAGS := $(CFLAGS) -x assembler-with-cpp
ASFLAGS += -DPLATFORM_$(PLATFORM)
LDFLAGS := -T linker.ld
# Set DEBUG=1 on the make command line to enable logging
ifeq ($(DEBUG),1)
CFLAGS += -DDEBUG
endif
CFLAGS += -DPLATFORM_$(PLATFORM)
CPPFLAGS += $(addprefix -I, $(INC_DIRS))
# ===== Files =====
OBJS = boot/head.o boot/vector_el1.o \
kernel/kmain.o kernel/uart.o kernel/mmu.o kernel/exception.o \
kernel/generic_timer.o kernel/gic.o kernel/debug.o \
kernel/mm/mem.o kernel/mm/buddy.o
# ===== Targets =====
.PHONY: all clean run runbin dump
all: k.elf k.bin
k.elf: $(OBJS) linker.ld
$(LD) $(LDFLAGS) -o $@ $(OBJS)
k.bin: k.elf
$(OBJCOPY) -O binary $< $@
%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
%.o: %.S
$(CC) $(ASFLAGS) -c $< -o $@
# Run using ELF as kernel (some QEMU builds accept this)
run: k.elf
$(QEMU) -machine virt,gic-version=3 -cpu cortex-a53 -nographic \
-serial mon:stdio -kernel k.elf -smp 1
# Fallback: load raw binary at our link address (matches linker.ld)
runbin: k.bin
$(QEMU) -machine virt -cpu cortex-a53 -nographic \
-device loader,file=k.bin,addr=0x40200000 -serial mon:stdio
dump: k.elf
$(OBJDUMP) -d k.elf | less
clean:
rm -f $(OBJS) k.elf k.bin