This repository was archived by the owner on May 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (68 loc) · 2.28 KB
/
Copy pathMakefile
File metadata and controls
102 lines (68 loc) · 2.28 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
# Get all assembly and C sources
SOURCES = $(shell find kernel/ -type f -name '*.asm' -o -name '*.c')
# Get all C headers
C_HEADERS = $(shell find kernel/ -type f -name '*.h')
# Add all assembly and C files to list of OBJ files
OBJ_FILES = $(patsubst %.c,%.co.o,$(patsubst %.asm,%.o,$(SOURCES)))
# Various flags for command line programs
# Linker flags
LD_FLAGS = -z max-page-size=0x1000
# Compiler flags
C_FLAGS = -g -nostartfiles -ffreestanding -Wall -Wextra -fno-exceptions -I ./ -I ./kernel/lib -mno-red-zone -mcmodel=kernel
# Assembler flags
ASM_FLAGS = -f elf64
# Compiler
CC = x86_64-elf-gcc
# Linker
LD = x86_64-elf-ld
# Assembler
ASM = nasm
# Emulator
EMULATOR = qemu-system-x86_64
# GDB
GDB = x86_64-elf-gdb
# Rule to build the entire project
# Rule to build the kernel elf file
kernel.elf: kernel/boot/mboot.o ${OBJ_FILES}
${LD} ${LD_FLAGS} -S -o $@ -Tlink.ld $^
debug_kernel.elf: kernel/boot/mboot.o ${OBJ_FILES}
${LD} ${LD_FLAGS} -o kernel.elf -Tlink.ld $^
# Rule to build the grub iso
grub: kernel.elf
# Move the kernel elf file to the boot folder
mv kernel.elf image/boot/kernel.elf
# Create the iso
grub-mkrescue -o image.iso image/
# Builds grub with debug elf file
debug_grub: debug_kernel.elf
# Move the kernel elf file to the boot folder
mv kernel.elf image/boot/kernel.elf
# Create the iso
grub-mkrescue -o image.iso image/
# Rule to run the kernel
run: grub
${EMULATOR} -bios /usr/share/ovmf/OVMF.fd -hda image.iso -serial file:serial.txt -m 8G
# Run kernel in bios mode
bios: grub
${EMULATOR} -hda image.iso -serial file:serial.txt -m 8G
# Run the kernel in debug
debug: debug_grub
${EMULATOR} -S -s -no-shutdown -bios /usr/share/ovmf/OVMF.fd -hda image.iso -serial file:serial.txt -d int -no-reboot -m 8G
${GDB} -x debug/defaultqemu.gdb
# Here are rules for resolving object file translations
# We have two different object file extensions
# so that we can have conflicting filenames
# between assembly and C
# For example: idt.c and idt.asm
# First C object files
%.co.o: %.c ${C_HEADERS}
${CC} ${C_FLAGS} -c $< -o $@
# Then assembly object files
%.o: %.asm
${ASM} $< ${ASM_FLAGS} -o $@
# The clean rule removes all generated files
clean:
# Compiled kernel
rm -rf kernel.elf image/boot/kernel.elf image.iso
# All object files
find . -type f -name '*.o' -delete