only identity map the start of the kernel

This commit is contained in:
nub31
2025-09-06 20:22:51 +02:00
parent 46bc977104
commit 130e271461
6 changed files with 35 additions and 34 deletions

View File

@@ -1,6 +1,7 @@
global _start
global pml4
extern x86_64_main
extern kernel_end
%define FLAGS 0b10
%define MAGIC 0x1BADB002
@@ -43,6 +44,8 @@ section .data
dd 0
multiboot_magic:
dd 0
kernel_page_count:
dd 0
section .text
bits 32
@@ -98,10 +101,18 @@ section .text
mov eax, pd
or eax, 0x03
mov [pdpt], eax
; Map first 32 2mb pages for the kernel for a total of 64mb
; Calculate how many 2mb pages we need to identity map
mov ecx, kernel_end
add ecx, 0x1FFFFF ; Page align end of kernel
shr ecx, 21 ; ecx now holds the required pages
; Save the page count so we can pass it to c later
mov [kernel_page_count], ecx
; Identity map the 0x0 to kernel_end
mov edi, pd
mov eax, 0x83
mov ecx, 32
.setup_pd:
mov [edi], eax
add eax, 0x200000
@@ -150,6 +161,7 @@ section .text
; Finally, we call in to c
mov edi, [multiboot_magic]
mov esi, [multiboot_info]
mov edx, [kernel_page_count]
call x86_64_main
.hang:
hlt