From ff664b06872a12f31e4452916e6189d505a7d306 Mon Sep 17 00:00:00 2001 From: nub31 Date: Sun, 24 Aug 2025 17:44:11 +0200 Subject: [PATCH] ... --- README.md | 4 ++-- makefile | 10 +++++----- src/boot.asm | 3 ++- src/boot.ld | 28 ++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/boot.ld diff --git a/README.md b/README.md index cb47ca1..8e2984e 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ - `make` - `grub` - `mtools` -- `gcc` -- `ld` +- `i386-elf-gcc` +- `i386-elf-ld` ## Building diff --git a/makefile b/makefile index 4bfb7b1..7e48c87 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,8 @@ -CC = gcc -LD = ld +CC = i386-elf-gcc +LD = i386-elf-ld -CFLAGS = -m32 -ffreestanding -fno-pie -fno-stack-protector -fno-builtin -Wall -Wextra -Werror -Wshadow -std=c23 -LDFLAGS = -m elf_i386 -Ttext 0x100000 -nostdlib +CFLAGS = -m32 -ffreestanding -fno-builtin -Wall -Wextra -Werror -Wshadow -std=c23 +LDFLAGS = -m elf_i386 all: .build/nub-os.iso @@ -19,7 +19,7 @@ build-dir: grub-mkrescue -o .build/nub-os.iso .build/iso/ .build/kernel: build-dir .build/boot.o .build/kernel.o .build/vga.o - $(LD) $(LDFLAGS) -Ttext 0x100000 -o .build/kernel .build/boot.o .build/kernel.o .build/vga.o + $(LD) $(LDFLAGS) -T src/boot.ld -o .build/kernel .build/boot.o .build/kernel.o .build/vga.o .build/kernel.o: build-dir src/kernel.c $(CC) $(CFLAGS) -c -o .build/kernel.o src/kernel.c diff --git a/src/boot.asm b/src/boot.asm index 908329a..132b362 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -3,6 +3,7 @@ %define LEN header_end - header_start %define CHECKSUM -(MAGIC + ARCH + LEN) +section .multiboot2 header_start: align 4 dd MAGIC @@ -25,7 +26,7 @@ global _start _start: mov esp, stack_top call kernel_main -hang: cli +hang: hlt jmp hang \ No newline at end of file diff --git a/src/boot.ld b/src/boot.ld new file mode 100644 index 0000000..66b9d81 --- /dev/null +++ b/src/boot.ld @@ -0,0 +1,28 @@ +ENTRY(_start) + +SECTIONS +{ + . = 2M; + + .text BLOCK(4K) : ALIGN(4K) + { + *(.multiboot2) + *(.text) + } + + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } +}