-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
72 lines (56 loc) · 1.87 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
TOOLCHAIN=aarch64-none-elf-
CC=$(TOOLCHAIN)gcc
LD=$(TOOLCHAIN)ld
CFLAGS=-Wall -Wextra -pedantic -O0 -g
CFLAGS+=-static -ffreestanding -nostdlib -fno-exceptions -fno-omit-frame-pointer
CFLAGS+=-fno-pie -no-pie
CFLAGS+=-mgeneral-regs-only
USER_CFLAGS=-Wall -c -Wextra -static -ffreestanding -nostdlib -fno-exceptions -fno-omit-frame-pointer
ROOT_DIR=$(shell pwd)
KERNEL_DIR=$(ROOT_DIR)/kernel
SLIBC_DIR=$(ROOT_DIR)/slibc
USER_DIR=$(ROOT_DIR)/user
KERNEL_LINKER=$(KERNEL_DIR)/kernel.ld
ASM=$(wildcard $(KERNEL_DIR)/src/asm/*.S)
LIBS=$(KERNEL_DIR)/target/aarch64-unknown-none/debug
LIB=steinsos
USER_LIB_DIR=$(SLIBC_DIR)/target/aarch64-unknown-none/debug/
USER_SOURCE=$(wildcard $(USER_DIR)/*.c)
USER_BASE=0xffff000000000000
USER_PROG= \
sh \
ls \
cat \
pwd \
mkdir
CPUS=1
QEMUOPTS= -m 1G -smp $(CPUS) -semihosting -machine virt -cpu cortex-a57 -nographic -kernel steinsos.bin
QEMUOPTS+= -machine gic-version=2
QEMUOPTS+= -drive file=fs.img,if=none,format=raw,id=x0
QEMUOPTS+= -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
.PHONY: slibc all mkfs
crt.o: $(USER_DIR)/crt.S
$(CC) $(CFLAGS) $<
%: $(USER_DIR)/crt.o $(USER_DIR)/%.o $(USER_DIR)/libc.o $(USER_DIR)/malloc.o
cd $(USER_DIR) && \
$(LD) -z max-page-size=4096 -N --entry __start -Ttext $(USER_BASE) -o $@ $^
mkfs: $(USER_PROG)
cd mkfs && \
cargo run $(patsubst %, $(USER_DIR)/%, $^) $(ROOT_DIR)/README.md && \
rm $(patsubst %, $(USER_DIR)/%, $^)
steinsos: $(ASM)
cd $(KERNEL_DIR) && \
cargo build && \
$(CC) $(CFLAGS) -T$(KERNEL_LINKER) -L$(LIBS) $^ -l$(LIB) -o steinsos.bin && \
mv steinsos.bin ../
all: mkfs steinsos
qemu: all
qemu-system-aarch64 $(QEMUOPTS)
qemu-gdb: all
qemu-system-aarch64 -s -S $(QEMUOPTS)
objdump: steinsos
$(TOOLCHAIN)objdump -S steinsos.bin > steinsos.sym; \
clean:
cd $(KERNEL_DIR) && cargo clean; \
cd $(SLIBC_DIR) && cargo clean; \
rm $(ROOT_DIR)/steinsos*; \