-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
50 lines (33 loc) · 1.08 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
SRC_DIR := src
BOOT_BIN := boot.bin
VESA_BIN := vesa.bin
KERNEL_BIN := kernel.bin
BOOT_IMG := boot.img
QEMU := qemu-system-i386
BOOT_FLAGS := -f bin
NASM_FLAGS := -f elf
GCC_FLAGS := -m32 -ffreestanding -fno-pic -O0 -mno-sse -fno-stack-protector
LD_FLAGS_KERNEL := -m elf_i386 -T link.lds
DD_FLAGS := conv=notrunc
all: clean run
$(BOOT_IMG): $(BOOT_BIN) $(VESA_BIN) $(KERNEL_BIN)
dd if=/dev/zero of=$@ bs=1024 count=1440
dd if=$(BOOT_BIN) of=$@ $(DD_FLAGS)
dd if=$(VESA_BIN) of=$@ $(DD_FLAGS) seek=1
dd if=$(KERNEL_BIN) of=$@ $(DD_FLAGS) seek=2
$(BOOT_BIN): boot/boot.asm
nasm $(BOOT_FLAGS) $< -o $@
$(VESA_BIN): $(SRC_DIR)/vesa.asm
nasm $(BOOT_FLAGS) $< -o $@
$(KERNEL_BIN): $(SRC_DIR)/kernel.c utils
gcc $(GCC_FLAGS) -c $< -o kernel.o
ld $(LD_FLAGS_KERNEL) *.o -o $@
utils:
nasm $(NASM_FLAGS) $(SRC_DIR)/utils.asm -o utils.o
run: $(BOOT_IMG)
$(QEMU) -drive file=$(BOOT_IMG),if=floppy,format=raw -monitor stdio
gdb: $(BOOT_IMG)
$(QEMU) -fda $(BOOT_IMG) -monitor stdio -s -S
clean:
rm -f $(BOOT_BIN) $(KERNEL_BIN) *.o $(BOOT_IMG) vesa.bin boot.bin kernel.bin
.PHONY: all clean run