From 6135c121ced6d4879a30cc7a6a5bed1a2d0975cd Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Tue, 17 Mar 2026 19:44:27 +1300 Subject: Create Makefile (yes i know it doesnt work yet) and boot.s --- Makefile | 27 +++++++++++++++++++++++++++ boot.o | Bin 0 -> 17252 bytes boot.s | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel.c | 0 4 files changed, 84 insertions(+) create mode 100644 Makefile create mode 100644 boot.o create mode 100644 boot.s create mode 100644 kernel.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dee9099 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +CC = i686-elf-gcc +AS = nasm +CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra + +SRCS = src/kernel.c +OBJS = src/boot.o src/kernel.o + +all: FrenchToastOS.iso + +src/boot.o: src/boot.asm + $(AS) -f elf32 src/boot.asm -o src/boot.o + +src/kernel.o: src/kernel.c + $(CC) $(CFLAGS) -c src/kernel.c -o src/kernel.o + +FrenchToastOS.bin: $(OBJS) + $(CC) -T linker.ld -o FrenchToastOS.bin -ffreestanding -O2 -nostdlib $(OBJS) -lgcc + +FrenchToastOS.iso: FrenchToastOS.bin + mkdir -p isodir/boot/grub + cp FrenchToastOS.bin isodir/boot/ + cp boot/grub.cfg isodir/boot/grub/ + grub-mkrescue -o FrenchToastOS.iso isodir + +clean: + rm -f $(OBJS) FrenchToastOS.bin FrenchToastOS.iso + rm -rf isodir diff --git a/boot.o b/boot.o new file mode 100644 index 0000000..dc86509 Binary files /dev/null and b/boot.o differ diff --git a/boot.s b/boot.s new file mode 100644 index 0000000..592ba46 --- /dev/null +++ b/boot.s @@ -0,0 +1,57 @@ +/* Multiboot header dark magic, do not touch */ +.set ALIGN, 1<<0 +.set MEMINFO, 1<<1 +.set FLAGS, ALIGN | MEMINFO +.set MAGIC, 0x1BADB002 +.set CHECKSUM, -(MAGIC + FLAGS) + +.section .multiboot +.align 4 +.long MAGIC +.long FLAGS +.long CHECKSUM + +/* Multiboot does not define the esp/stack, create the stack ourselves */ +.section bss +/* Stack on x86 must be 16-byte aligned by the System V ABI standard */ +.align 16 +/* Create a symbol at the bottom, allocate 16KiB, then finally create a symbol at the top */ +stack_bottom: +.skip 16384 +stack_top: + +/* _start is the entrypoint */ +.section text +.global _start +.type _start, @function +_start: + /* we are in 32bit protected mode + interrupts disabled, paging disabled + kernel has full control over cpu */ + + /* setup the stack, point to the top becausei t grows downwrad on x86 for som e reason */ + mov $stack_top, %esp + + /* here we need to init crucial processor state. + load the gdt, enable pages, init isa extensions/floating point instructions and stuff + for now just dont do anything we'll add that later */ + + /* enter the high level kernel + ABI says we need 16-byte alignment here, we aligned that before and pushed a multiple of 16 bits (zero) so we fine + but i will realign for good measure anyway */ + .align 16 + call kernel_main + + /* if nothing left then just infinite loop */ + /* + 1. disable interrupts with cli/clear interrupts + 2. wait for next interrupt with hlt. because they disabled this will just lockup the ocmputer + 3. justincase it wakes up just jmp back to the hlt instruction + */ + cli +1: hlt + jmp 1b + +/* set the size of the _start symbol to the current location (.) minus it's _start +for debugging stuff */ +.size _start, . - _start diff --git a/kernel.c b/kernel.c new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3