From 982ce17927a31626b24828726ba23b9fc462a95b Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Sat, 22 Jul 2023 16:51:44 +0200 Subject: [PATCH] Prekernel: Map entire 4GiB space Prekernel code currently assumes that mapping until MAX_KERNEL_SIZE is enough to make the modules accessible. GRUB tries to load as low as possible but higher than 1 MiB. Hence this is usually true. However on EFI some ranges may already be used by boot services and GRUB tries to avoid them if possible. This pushes modules higher. The simplest solution is to map entire 4 GiB space. As an additional benefit it makes the framebuffer accessible that can be used for the debugging. --- Kernel/Prekernel/boot.S | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Kernel/Prekernel/boot.S b/Kernel/Prekernel/boot.S index a5fa487a5f..75eed5c1d3 100644 --- a/Kernel/Prekernel/boot.S +++ b/Kernel/Prekernel/boot.S @@ -24,7 +24,7 @@ boot_pdpt: .skip 4096 .global boot_pd0 boot_pd0: -.skip 4096 +.skip (4096 * 4) .global boot_pd0_pts boot_pd0_pts: .skip 4096 * (MAX_KERNEL_SIZE >> 21) @@ -65,10 +65,10 @@ pml4t: pdpt - 0: boot_pd0 (0-1GB) - 1: n/a (1-2GB) - 2: n/a (2-3GB) - 3: n/a (3-4GB) + 0: boot_pd0 (0-1GB) + 1: boot_pd0 + 4096 (1-2GB) + 2: boot_pd0 + 4096 * 2 (2-3GB) + 3: boot_pd0 + 4096 * 3 (3-4GB) boot_pd0 : 512 PDEs @@ -421,13 +421,16 @@ long_mode_supported: xorl %eax, %eax rep stosl - /* set up pdpt[0] and pdpt[3] */ + /* set up pdpt[0]..pdpt[3] */ movl $boot_pdpt, %edi movl $(boot_pd0 + 3), 0(%edi) + movl $(boot_pd0 + 4096 + 3), 8(%edi) + movl $(boot_pd0 + 4096 * 2 + 3), 16(%edi) + movl $(boot_pd0 + 4096 * 3 + 3), 24(%edi) /* clear pd0 */ movl $boot_pd0, %edi - movl $1024, %ecx + movl $4096, %ecx xorl %eax, %eax rep stosl @@ -463,6 +466,19 @@ long_mode_supported: addl $4096, %eax loop 1b + /* Map the rest with 2MiB pages */ + /* add boot_pd0_pts to boot_pd0 */ + movl $(2048 - (MAX_KERNEL_SIZE >> 21)), %ecx + movl $(boot_pd0 + (MAX_KERNEL_SIZE >> 21) * 8), %edi + /* R/W + Present + 2 MiB */ + movl $(MAX_KERNEL_SIZE | 0x83), %eax + +1: + movl %eax, 0(%edi) + addl $8, %edi + addl $(1 << 21), %eax + loop 1b + /* point CR3 to PML4T */ movl $boot_pml4t, %eax