-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
144 lines (131 loc) · 5.03 KB
/
Makefile
File metadata and controls
144 lines (131 loc) · 5.03 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
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
# === Variables ===
ASM=nasm
CC=gcc
LD=ld
BUILD_DIR=build
CFLAGS = -ffreestanding -m64 -nostdlib -O0 -Wall -g -Iinclude \
-fno-stack-protector -fno-stack-check
# -fno-stack-protector -fno-stack-check prevent GCC inserting hidden runtime
# dependencies into a freestanding kernel.
# Note! -O0 removes optimisations to easier debug
# Commit a4214a854972e04ffb38ac2af53b898a47688990: code breaks with "-O2" flag
# (i.e., when compiler starts to optimise the code)
LDFLAGS=-T kernel.ld -nostdlib -z max-page-size=0x200000
# === Phony targets ===
.PHONY: all floppy_image stage0 stage1 kernel run debug clean
# === Floppy disk ===
floppy_image: $(BUILD_DIR)/main.img
$(BUILD_DIR)/main.img: stage0 stage1 kernel
dd if=/dev/zero of=$(BUILD_DIR)/main.img bs=512 count=2880
mkfs.fat -F 12 -n "SNAKEOS" $(BUILD_DIR)/main.img
dd if=$(BUILD_DIR)/stage0.bin of=$(BUILD_DIR)/main.img conv=notrunc
mcopy -i $(BUILD_DIR)/main.img $(BUILD_DIR)/stage1.bin "::stage1.bin"
mcopy -i $(BUILD_DIR)/main.img $(BUILD_DIR)/kernel.bin "::kernel.bin"
# === Bootloader ===
stage0: $(BUILD_DIR)/stage0.bin
$(BUILD_DIR)/stage0.bin:
$(ASM) boot/x86/stage0/stage0.asm -f bin -o $(BUILD_DIR)/stage0.bin
# === Stage 1 ===
stage1: $(BUILD_DIR)/stage1.bin
$(BUILD_DIR)/stage1.bin:
$(ASM) boot/x86/stage1/stage1.asm -f bin -o $(BUILD_DIR)/stage1.bin
# === Kernel ===
kernel: $(BUILD_DIR)/kernel.elf $(BUILD_DIR)/kernel.bin
$(BUILD_DIR)/kernel.elf: $(BUILD_DIR)/kernel_entry.o $(BUILD_DIR)/kmain.o \
$(BUILD_DIR)/kprint.o $(BUILD_DIR)/gdt.o \
$(BUILD_DIR)/gdt_asm.o $(BUILD_DIR)/util.o \
$(BUILD_DIR)/idt.o $(BUILD_DIR)/idt_asm.o \
$(BUILD_DIR)/keyboard.o \
$(BUILD_DIR)/init_ram.o $(BUILD_DIR)/timer.o \
$(BUILD_DIR)/irq.o $(BUILD_DIR)/irq.o \
$(BUILD_DIR)/exception.o $(BUILD_DIR)/i8259.o \
$(BUILD_DIR)/cdev.o \
$(BUILD_DIR)/console.o \
$(BUILD_DIR)/vga.o \
$(BUILD_DIR)/i8042.o \
$(BUILD_DIR)/i8253.o \
$(BUILD_DIR)/tty.o \
$(BUILD_DIR)/spinlock.o \
$(BUILD_DIR)/panic.o \
$(BUILD_DIR)/tests.o
-T kernel.ld
$(LD) $(LDFLAGS) -o $@ $(BUILD_DIR)/kernel_entry.o \
$(BUILD_DIR)/kmain.o \
$(BUILD_DIR)/kprint.o \
$(BUILD_DIR)/gdt.o \
$(BUILD_DIR)/gdt_asm.o \
$(BUILD_DIR)/util.o \
$(BUILD_DIR)/idt.o \
$(BUILD_DIR)/idt_asm.o \
$(BUILD_DIR)/keyboard.o \
$(BUILD_DIR)/init_ram.o \
$(BUILD_DIR)/irq.o \
$(BUILD_DIR)/exception.o \
$(BUILD_DIR)/i8259.o \
$(BUILD_DIR)/timer.o \
$(BUILD_DIR)/cdev.o \
$(BUILD_DIR)/console.o \
$(BUILD_DIR)/vga.o \
$(BUILD_DIR)/i8042.o \
$(BUILD_DIR)/i8253.o \
$(BUILD_DIR)/tty.o \
$(BUILD_DIR)/spinlock.o \
$(BUILD_DIR)/panic.o \
$(BUILD_DIR)/tests.o
$(BUILD_DIR)/kernel.bin: $(BUILD_DIR)/kernel.elf
objcopy -O binary $< $@
$(BUILD_DIR)/kernel_entry.o: boot/x86/kernel_entry.asm
$(ASM) -f elf64 $< -o $@
$(BUILD_DIR)/gdt_asm.o: arch/x86/gdt.asm
$(ASM) -f elf64 $< -o $@
$(BUILD_DIR)/idt_asm.o: arch/x86/idt.asm
$(ASM) -f elf64 $< -o $@
$(BUILD_DIR)/kmain.o: init/kmain.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/kprint.o: kernel/kprint.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/gdt.o: arch/x86/gdt.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/util.o: lib/util.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/idt.o: arch/x86/idt.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/keyboard.o: drivers/keyboard.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/init_ram.o: drivers/init_ram.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/timer.o: kernel/timer.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/irq.o: kernel/irq.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/i8259.o: arch/x86/i8259.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/exception.o: kernel/exception.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/cdev.o: drivers/cdev.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/console.o: drivers/console.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/vga.o: drivers/vga.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/i8042.o: drivers/i8042.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/i8253.o: drivers/i8253.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/spinlock.o: kernel/spinlock.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/panic.o: kernel/panic.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/tests.o: debugging/tests/tests.c
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/tty.o: kernel/tty.c
$(CC) $(CFLAGS) -c $< -o $@
# === Run ===
run:
qemu-system-x86_64 -fda $(BUILD_DIR)/main.img
# === Debug ===
debug:
./debugging/debug.sh
# === Clean ===
clean:
rm -rf $(BUILD_DIR)/*.bin $(BUILD_DIR)/*.img $(BUILD_DIR)/*.o