Kernel: We now identity map full GiB in boot.S

The paging structure is pre-built so no unnecessary calculations are done
This commit is contained in:
Bananymous 2023-05-30 00:08:52 +03:00
parent 3b9d60d7cb
commit 265fe9c62e
1 changed files with 25 additions and 28 deletions

View File

@ -37,28 +37,34 @@
g_kernel_cmdline: g_kernel_cmdline:
.skip 4096 .skip 4096
# Reserve memory for paging structures, .global g_multiboot_info
# we will identity map first 4 MiB g_multiboot_info:
.skip 8
# 0 MiB -> 1 MiB: bootloader stuff .global g_multiboot_magic
# 1 MiB -> : kernel g_multiboot_magic:
.align 4096 .skip 8
boot_pml4:
.skip 512 * 8
boot_pdpt1:
.skip 512 * 8
boot_pd1:
.skip 512 * 8
.global g_multiboot_info
g_multiboot_info:
.skip 8
.global g_multiboot_magic
g_multiboot_magic:
.skip 8
.section .text .section .text
# Identity map first GiB
.align 4096
boot_pml4:
.quad boot_pdpt + (PG_READ_WRITE | PG_PRESENT)
.rept 511
.quad 0
.endr
boot_pdpt:
.quad boot_pd + (PG_READ_WRITE | PG_PRESENT)
.rept 511
.quad 0
.endr
boot_pd:
.set i, 0
.rept 512
.quad i + (PG_PAGE_SIZE | PG_READ_WRITE | PG_PRESENT)
.set i, i + 0x00200000
.endr
boot_gdt: boot_gdt:
.quad 0x0000000000000000 # null descriptor .quad 0x0000000000000000 # null descriptor
.quad 0x00AF9A000000FFFF # kernel code .quad 0x00AF9A000000FFFF # kernel code
@ -125,15 +131,6 @@ enable_sse:
ret ret
initialize_paging: initialize_paging:
# identity map first 6 MiB
movl $(0x00000000 + PG_PAGE_SIZE + PG_READ_WRITE + PG_PRESENT), boot_pd1 + 0
movl $(0x00200000 + PG_PAGE_SIZE + PG_READ_WRITE + PG_PRESENT), boot_pd1 + 8
movl $(0x00400000 + PG_PAGE_SIZE + PG_READ_WRITE + PG_PRESENT), boot_pd1 + 16
# set pdpte1 and pml4e1
movl $(boot_pd1 + PG_READ_WRITE + PG_PRESENT), boot_pdpt1
movl $(boot_pdpt1 + PG_READ_WRITE + PG_PRESENT), boot_pml4
# enable PAE # enable PAE
movl %cr4, %ecx movl %cr4, %ecx
orl $0x20, %ecx orl $0x20, %ecx