This commit is contained in:
nub31
2025-08-24 17:44:11 +02:00
parent 56025d55f9
commit ff664b0687
4 changed files with 37 additions and 8 deletions

View File

@@ -5,8 +5,8 @@
- `make` - `make`
- `grub` - `grub`
- `mtools` - `mtools`
- `gcc` - `i386-elf-gcc`
- `ld` - `i386-elf-ld`
## Building ## Building

View File

@@ -1,8 +1,8 @@
CC = gcc CC = i386-elf-gcc
LD = ld LD = i386-elf-ld
CFLAGS = -m32 -ffreestanding -fno-pie -fno-stack-protector -fno-builtin -Wall -Wextra -Werror -Wshadow -std=c23 CFLAGS = -m32 -ffreestanding -fno-builtin -Wall -Wextra -Werror -Wshadow -std=c23
LDFLAGS = -m elf_i386 -Ttext 0x100000 -nostdlib LDFLAGS = -m elf_i386
all: .build/nub-os.iso all: .build/nub-os.iso
@@ -19,7 +19,7 @@ build-dir:
grub-mkrescue -o .build/nub-os.iso .build/iso/ grub-mkrescue -o .build/nub-os.iso .build/iso/
.build/kernel: build-dir .build/boot.o .build/kernel.o .build/vga.o .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 .build/kernel.o: build-dir src/kernel.c
$(CC) $(CFLAGS) -c -o .build/kernel.o src/kernel.c $(CC) $(CFLAGS) -c -o .build/kernel.o src/kernel.c

View File

@@ -3,6 +3,7 @@
%define LEN header_end - header_start %define LEN header_end - header_start
%define CHECKSUM -(MAGIC + ARCH + LEN) %define CHECKSUM -(MAGIC + ARCH + LEN)
section .multiboot2
header_start: header_start:
align 4 align 4
dd MAGIC dd MAGIC
@@ -25,7 +26,7 @@ global _start
_start: _start:
mov esp, stack_top mov esp, stack_top
call kernel_main call kernel_main
hang:
cli cli
hang:
hlt hlt
jmp hang jmp hang

28
src/boot.ld Normal file
View File

@@ -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)
}
}