commit 04d59fd6d25741569a51cb1db1f37bb123fbbebc Author: kamkow1 Date: Mon Dec 15 23:58:42 2025 +0100 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27aa2ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +iso_root +mop3.iso +bochs-log.txt +bochs-com1.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6c17167 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +platform ?= amd64 + +all_kernel: + make -C kernel platform=$(platform) all + +clean_kernel: + make -C kernel platform=$(platform) clean + +.PHONY: all_kernel clean_kernel diff --git a/aux/bochs_amd64.sh b/aux/bochs_amd64.sh new file mode 100755 index 0000000..a3e71a1 --- /dev/null +++ b/aux/bochs_amd64.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +bochs -f aux/bochsrc.txt -q diff --git a/aux/bochsrc.txt b/aux/bochsrc.txt new file mode 100644 index 0000000..3c238da --- /dev/null +++ b/aux/bochsrc.txt @@ -0,0 +1,21 @@ +cpu: model=p4_prescott_celeron_336 + +memory: guest=4096 host=2048 + +romimage: file=/usr/share/bochs/BIOS-bochs-latest, options=fastboot +vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest.bin + +ata0: enabled=1 +ata0-master: type=cdrom, path=mop3.iso, status=inserted +com1: enabled=1, mode=file, dev=bochs-com1.txt + +boot: cdrom + +error: action=report +panic: action=report +info: action=report +debug: action=ignore + +log: bochs-log.txt + +display_library: x diff --git a/aux/limine_iso_amd64.sh b/aux/limine_iso_amd64.sh new file mode 100755 index 0000000..e53e1ba --- /dev/null +++ b/aux/limine_iso_amd64.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +make -C boot/limine +mkdir -p iso_root/boot/limine +mkdir -p iso_root/EFI/BOOT + +cp -v kernel/build/kernel.elf iso_root/boot +cp -v boot/limine/limine-bios.sys boot/limine/limine-bios-cd.bin \ + boot/limine/limine-uefi-cd.bin boot/limine.conf iso_root/boot/limine + +cp -v boot/limine/BOOTX64.EFI boot/limine/BOOTIA32.EFI iso_root/EFI/BOOT + +xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin \ + -no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \ + -apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \ + -efi-boot-part --efi-boot-image --protective-msdos-label \ + iso_root -o mop3.iso + +boot/limine/limine bios-install mop3.iso diff --git a/boot/limine b/boot/limine new file mode 160000 index 0000000..f777d33 --- /dev/null +++ b/boot/limine @@ -0,0 +1 @@ +Subproject commit f777d332c66e674e37bd8f46fec9cb2b30f08628 diff --git a/boot/limine.conf b/boot/limine.conf new file mode 100644 index 0000000..bb18ea9 --- /dev/null +++ b/boot/limine.conf @@ -0,0 +1,5 @@ +timeout: 10 + +/mop3 + protocol: limine + path: boot():/boot/kernel.elf diff --git a/kernel/Makefile b/kernel/Makefile new file mode 100644 index 0000000..c085fa6 --- /dev/null +++ b/kernel/Makefile @@ -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 diff --git a/kernel/amd64/.gitignore b/kernel/amd64/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/kernel/amd64/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/kernel/amd64/bootmain.c b/kernel/amd64/bootmain.c new file mode 100644 index 0000000..85d73e0 --- /dev/null +++ b/kernel/amd64/bootmain.c @@ -0,0 +1,4 @@ + +void bootmain(void) { + for (;;); +} diff --git a/kernel/amd64/flags.mk b/kernel/amd64/flags.mk new file mode 100644 index 0000000..71e3de7 --- /dev/null +++ b/kernel/amd64/flags.mk @@ -0,0 +1,3 @@ +cflags += --target=x86_64-pc-none-elf + +ldflags += --target=x86_64-pc-none-elf diff --git a/kernel/amd64/link.ld b/kernel/amd64/link.ld new file mode 100644 index 0000000..c32e3c3 --- /dev/null +++ b/kernel/amd64/link.ld @@ -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.*) + } +} diff --git a/kernel/amd64/src.mk b/kernel/amd64/src.mk new file mode 100644 index 0000000..979860b --- /dev/null +++ b/kernel/amd64/src.mk @@ -0,0 +1,3 @@ +c += amd64/bootmain.c + +o += amd64/bootmain.o diff --git a/kernel/generic/flags.mk b/kernel/generic/flags.mk new file mode 100644 index 0000000..923fc0b --- /dev/null +++ b/kernel/generic/flags.mk @@ -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