This commit is contained in:
2025-12-15 23:58:42 +01:00
commit 04d59fd6d2
14 changed files with 182 additions and 0 deletions

26
kernel/Makefile Normal file
View File

@@ -0,0 +1,26 @@
cc := clang
o :=
c :=
ldflags :=
cflags :=
buildtype ?= release
include $(platform)/src.mk
include $(platform)/flags.mk
include generic/flags.mk
all: build/kernel.elf
build/kernel.elf: $(o)
$(cc) -o $@ $(ldflags) -T $(platform)/link.ld $^
%.o: %.c
$(cc) -c -o $@ $(cflags) $<
%.o: %.S
$(cc) -c -o $@ $(cflags) $<
clean:
rm -f $(o) build/kernel.elf
.PHONY: all clean

1
kernel/amd64/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.o

4
kernel/amd64/bootmain.c Normal file
View File

@@ -0,0 +1,4 @@
void bootmain(void) {
for (;;);
}

3
kernel/amd64/flags.mk Normal file
View File

@@ -0,0 +1,3 @@
cflags += --target=x86_64-pc-none-elf
ldflags += --target=x86_64-pc-none-elf

51
kernel/amd64/link.ld Normal file
View File

@@ -0,0 +1,51 @@
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(bootmain)
PHDRS {
limine_requests PT_LOAD;
text PT_LOAD;
rodata PT_LOAD;
data PT_LOAD;
}
SECTIONS {
. = 0xffffffff80000000;
.limine_requests : {
KEEP(*(.limine_requests_start))
KEEP(*(.limine_requests))
KEEP(*(.limine_requests_end))
} :limine_requests
. = ALIGN(CONSTANT(MAXPAGESIZE));
.text : {
*(.text .text.*)
} :text
. = ALIGN(CONSTANT(MAXPAGESIZE));
.rodata : {
*(.rodata .rodata.*)
} :rodata
.note.gnu.build-id : {
*(.note.gnu.build-id)
} :rodata
. = ALIGN(CONSTANT(MAXPAGESIZE));
.data : {
*(.data .data.*)
} :data
.bss : {
*(.bss .bss.*)
} :data
/DISCARD/ : {
*(.eh_frame*)
*(.note .note.*)
}
}

3
kernel/amd64/src.mk Normal file
View File

@@ -0,0 +1,3 @@
c += amd64/bootmain.c
o += amd64/bootmain.o

32
kernel/generic/flags.mk Normal file
View File

@@ -0,0 +1,32 @@
cflags += -nostdinc \
-nostdlib \
-ffreestanding \
-fno-builtin \
-std=c11 \
-pedantic \
-Wall \
-Wextra
ifeq ($(buildtype),debug)
cflags += -O0 -g
endif
ifeq ($(buildtype),release)
cflags += -ffunction-sections -fdata-sections -Oz
endif
ldflags += -ffreestanding \
-nostdlib \
-fno-builtin \
-fuse-ld=lld \
-static
ifeq ($(buildtype),debug)
ldflags += -g
endif
ifeq ($(buildtype),release)
ldflags += -Wl,--gc-sections \
-Wl,--strip-all \
-flto
endif