From 265fe9c62e9edaa9b7aee66c0022c0599d0d3cb9 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 30 May 2023 00:08:52 +0300 Subject: [PATCH] Kernel: We now identity map full GiB in boot.S The paging structure is pre-built so no unnecessary calculations are done --- kernel/arch/x86_64/boot.S | 53 ++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/kernel/arch/x86_64/boot.S b/kernel/arch/x86_64/boot.S index 25e6f4f8..2a6cfa68 100644 --- a/kernel/arch/x86_64/boot.S +++ b/kernel/arch/x86_64/boot.S @@ -37,28 +37,34 @@ g_kernel_cmdline: .skip 4096 - # Reserve memory for paging structures, - # we will identity map first 4 MiB - - # 0 MiB -> 1 MiB: bootloader stuff - # 1 MiB -> : kernel - .align 4096 - 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 + .global g_multiboot_info + g_multiboot_info: + .skip 8 + .global g_multiboot_magic + g_multiboot_magic: + .skip 8 .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: .quad 0x0000000000000000 # null descriptor .quad 0x00AF9A000000FFFF # kernel code @@ -125,15 +131,6 @@ enable_sse: ret 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 movl %cr4, %ecx orl $0x20, %ecx