-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
52 lines (43 loc) · 1.9 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
CC = gcc
AS = nasm
CFLAGS = -m64 -mcmodel=large -ffreestanding -fno-stack-protector -fno-pie -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -nostdlib -I./src/kernel -I./src/memory -I./src/interrupt -I./src/drivers -I./src/mm
LDFLAGS = -T scripts/linker.ld -nostdlib -no-pie -Wl,--build-id=none
ASFLAGS = -f elf64
SRC_DIR = src
KERNEL_SOURCES = $(wildcard $(SRC_DIR)/kernel/*.c)
MEMORY_SOURCES = $(wildcard $(SRC_DIR)/memory/*.c)
INTERRUPT_SOURCES = $(wildcard $(SRC_DIR)/interrupt/*.c)
DRIVER_SOURCES = $(wildcard $(SRC_DIR)/drivers/*.c)
MM_SOURCES = $(wildcard $(SRC_DIR)/mm/*.c)
FS_SOURCES = $(wildcard $(SRC_DIR)/fs/*.c)
VFS_SOURCES = $(wildcard $(SRC_DIR)/fs/vfs/*.c)
SOURCES = $(KERNEL_SOURCES) $(MEMORY_SOURCES) $(INTERRUPT_SOURCES) $(DRIVER_SOURCES) $(MM_SOURCES) $(FS_SOURCES) $(VFS_SOURCES)
OBJECTS = $(SOURCES:.c=.o)
OBJECTS += $(SRC_DIR)/memory/gdt_asm.o $(SRC_DIR)/interrupt/idt_asm.o
all: kernel.bin NextCore
@echo
@echo "NextCore Compiled Successfully!"
@echo
kernel.bin: $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
NextCore: kernel.bin
# Create a bzImage from the kernel ELF binary
# First, create a flat binary
objcopy -O binary kernel.bin kernel.raw
# Then, compress it using gzip and prepend the required header for bzImage
# Note: Adjust the size and other parameters as necessary
# The `--pad-to` option is used to specify the total size of the bzImage
# This is often set to 512 KiB or 1 MiB
dd if=/dev/zero bs=1 count=512 of=bzImage.img
cat kernel.raw | gzip -9 > kernel.gz
cat kernel.gz >> bzImage.img
# Add bzImage header
dd if=bzImage.img of=NextCore bs=512 conv=notrunc
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(SRC_DIR)/memory/gdt_asm.o: $(SRC_DIR)/memory/gdt.asm
$(AS) $(ASFLAGS) $< -o $@
$(SRC_DIR)/interrupt/idt_asm.o: $(SRC_DIR)/interrupt/idt.asm
$(AS) $(ASFLAGS) $< -o $@
clean:
rm -f $(SRC_DIR)/*/*/*.o kernel.bin NextCore kernel.raw kernel.gz $(SRC_DIR)/*/*.o $(SRC_DIR)/*.o bzImage.img