From 8fadee6baf2b6aeae7558692e9792f0d3791f53c Mon Sep 17 00:00:00 2001 From: lordtet Date: Tue, 10 Jun 2025 23:58:28 -0400 Subject: [PATCH] They're calling him "mr has a working custom GDT" ... ... ...I'm sorry they don't call me that. --- src/start.s | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/start.s b/src/start.s index 702df0b..8823c6e 100644 --- a/src/start.s +++ b/src/start.s @@ -90,9 +90,21 @@ section .text ;Here it is! start: ;We made a GDT! Let's use it! - lgdt [gdt] + lgdt [gdtr] + ;Now we start by setting the code segment (CS) with a far jump... + jmp 0x08:segment_be_gone - ;Lets set up the stack. Stack grows downward on x86. We did the work earlier of defining where the top of the stack is, so just tell esp. + + segment_be_gone: + ;Now we go ahead and dump our kernel mode data segment (0x10) into the rest of our segments. + ;Also preserving eax because it has the bootloader's multiboot magic in it and I want to check it in main. + mov cx, 0x10 + mov ds, cx + mov es, cx + mov ss, cx + mov fs, cx + mov gs, cx + ;Lets set up the stack. Stack grows downward on x86. We did the work earlier of defining where the top of the stack is, so just tell esp. mov esp, stack_top ;set the stack pointer push ebx push eax @@ -105,3 +117,5 @@ section .text hlt ;Halt! jmp hang ;just in case... + +