-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
114 lines (90 loc) · 3.09 KB
/
Copy pathMakefile
File metadata and controls
114 lines (90 loc) · 3.09 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
arch ?= x86_64
kernel := build/kernel-$(arch).bin
iso := build/os-$(arch).iso
target ?= $(arch)-bubble-os
rust_os := target/$(target)/debug/libbubble_os.a
disk_path := build/disk.img
linker_script := src/arch/$(arch)/boot/linker.ld
grub_cfg := src/arch/$(arch)/boot/grub.cfg
assembly_source_files := $(wildcard src/arch/$(arch)/boot/*.s)
assembly_object_files := $(patsubst src/arch/$(arch)/boot/%.s, \
build/arch/$(arch)/boot/%.o, $(assembly_source_files))
resources := $(wildcard resources/*)
user_binaries := $(wildcard userspace/bin/*)
base_qemu := qemu-system-x86_64 \
-nographic -serial mon:stdio \
-m 256M \
-cdrom $(iso) \
-boot d \
-s \
-no-reboot \
-machine q35 \
-drive file=$(disk_path),if=none,id=disk0,format=raw \
-device ahci,id=ahci \
-device ide-hd,drive=disk0,bus=ahci.0 \
-netdev socket,id=n0,udp=127.0.0.1:1234,localaddr=127.0.0.1:1235 \
-device e1000,netdev=n0
grub_rescue := $(shell command -v grub2-mkrescue >/dev/null 2>&1 && echo grub2-mkrescue || echo grub-mkrescue)
.PHONY: all clean run iso kernel disk userspace
all: $(kernel)
full_build: init_build userspace disk kernel_start iso
init_build:
mkdir -p build
clean:
cargo clean
rm -r build
build_and_run: userspace disk kernel_start iso run
int_run: userspace disk kernel_start iso run_w_debug_interrupts
debug_run:
@echo "Starting QEMU and waiting for debugger..."
@$(base_qemu) -S & \
pid=$$!; \
until nc -z localhost 1234; do sleep 0.1; done; \
echo "Waiting for Debugger"; \
wait $$pid
run:
$(base_qemu)
run_w_debug_interrupts:
$(base_qemu) -d int
gdb:
gdb "$(kernel)" -ex "target remote :1234"
iso: $(iso)
disk:
qemu-img create -f raw $(disk_path) 128M
mkfs.vfat -F 32 -v $(disk_path)
mmd -i $(disk_path) ::res
mmd -i $(disk_path) ::res/dir
@for file in $(resources); do \
echo $$(basename $$file); \
mcopy -i $(disk_path) "$$file" ::res/$$(basename $$file); \
done
@for file in $(user_binaries); do \
echo $$(basename $$file); \
mcopy -i $(disk_path) "$$file" ::$$(basename $$file); \
done
userspace:
make -C userspace
$(iso): $(kernel) $(grub_cfg)
mkdir -p build/isofiles/boot/grub
cp $(kernel) build/isofiles/boot/kernel.bin
cp $(grub_cfg) build/isofiles/boot/grub
$(grub_rescue) -o $(iso) build/isofiles 2> /dev/null
# rm -r build/isofiles
$(kernel): kernel $(rust_os) $(assembly_object_files) $(linker_script)
ld -n --gc-sections -T $(linker_script) -o $(kernel) build/arch/$(arch)/boot/kernel_start.o $(assembly_object_files) $(rust_os)
kernel:
RUST_TARGET_PATH=$(shell pwd) xargo build --target $(target)
test: kernel_start_test $(iso) run_without_building
kernel_start:
mkdir -p build/arch/$(arch)/boot/
echo "building: kernel_start"
nasm -felf64 src/arch/$(arch)/boot/kernel_start.asm -o build/arch/$(arch)/boot/kernel_start.o
kernel_start_test:
mkdir -p build/arch/$(arch)/boot/
echo "building: kernel_start_test"
nasm -felf64 src/arch/$(arch)/boot/kernel_start_test.asm -o build/arch/$(arch)/boot/kernel_start.o
# compile assembly files
build/arch/$(arch)/boot/%.o: src/arch/$(arch)/boot/%.s
mkdir -p $(shell dirname $@)
echo $<
nasm -felf64 $< -o $@