From c5cc6a0d8da12be1ff69315920f1c3199206121c Mon Sep 17 00:00:00 2001 From: AfonsoCMSousa Date: Tue, 18 Nov 2025 20:59:45 +0000 Subject: [PATCH] Feat: First try at 64-bit long jmp --- boot.asm | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/boot.asm b/boot.asm index 4311289..a3b735b 100644 --- a/boot.asm +++ b/boot.asm @@ -70,7 +70,6 @@ gdt_data: ; Data Segment (0x10) db 10010010b ; Access Byte (0x92) db 11001111b ; Flags (0xC) + Limit db 0x0 - gdt_end: gdt_descriptor: @@ -95,6 +94,38 @@ init_pm: mov ebp, 0x90000 ; Update stack to a safe 32-bit area mov esp, ebp + ; 2. Set up Paging + mov eax, pml4_table + mov cr3, eax + + ; Link PML4 -> PDPT + mov dword [pml4_table], pdpt_table + 0x3 + mov dword [pml4_table + 4], 0x0 + + ; Link PDPT -> PD + mov dword [pdpt_table], pd_table + 0x3 + mov dword [pdpt_table + 4], 0x0 + + ; Link PD -> 2MB Physical Page 0 + mov dword [pd_table], 0x83 + mov dword [pd_table + 4], 0x0 + + ; 3. Enable PAE + mov eax, cr4 + or eax, 0x20 + mov cr4, eax + + ; 4. Enable Long Mode in EFER + mov ecx, 0xC0000080 + rdmsr + or eax, 0x00000100 + wrmsr + + ; 5. Enable Paging + mov eax, cr0 + or eax, 0x80000000 + mov cr0, eax + ; 6. Print "SoraOS Protected" directly to Video Memory ; We can't use BIOS interrupts anymore! We must write to 0xB8000. mov ebx, 0xb8000 @@ -120,3 +151,23 @@ init_pm: times 510-($-$$) db 0 ; The BIOS signature (must be at the very end) dw 0xAA55 + +section .bss +align 4096 +pml4_table: + resb 4096 +pdpt_table: + resb 4096 +pd_table: + resb 4096 + +section .data +gdt_ptr: + dw (gdt_end - gdt_start - 1) + dq gdt_start +gdt_start: + dq 0x0000000000000000 + dq 0x00AF9A000000FFFF ; Code + dq 0x00AF92000000FFFF ; Data +gdt_end: +