From 19c0498ccc635ae9e9cc9f574588f12c5636738a Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 24 Jun 2021 12:58:57 +0200 Subject: [PATCH] Kernel: Update the x86_64 boot code to match i386's code --- Kernel/Arch/x86/x86_64/Boot/boot.S | 46 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/Kernel/Arch/x86/x86_64/Boot/boot.S b/Kernel/Arch/x86/x86_64/Boot/boot.S index 3a6f624dba9920..1716536df47c7c 100644 --- a/Kernel/Arch/x86/x86_64/Boot/boot.S +++ b/Kernel/Arch/x86/x86_64/Boot/boot.S @@ -52,17 +52,17 @@ boot_pd0_pt0: .skip 4096 * 4 .global boot_pd3_pts boot_pd3_pts: -.skip 4096 * 8 +.skip 4096 * 16 .global boot_pd3_pt1023 boot_pd3_pt1023: .skip 4096 -.section .text +.section .boot_text, "ax" .global start .type start, @function -.extern init +.extern init .type init, @function .extern multiboot_info_ptr @@ -92,7 +92,17 @@ boot_pd3 : 512 pde's 5: boot_pd3_pts[5] (3082-3084MB) (pseudo 512 4KB pages) 6: boot_pd3_pts[6] (3084-3086MB) (pseudo 512 4KB pages) 7: boot_pd3_pts[7] (3086-3088MB) (pseudo 512 4KB pages) - 8: boot_pd3_pt1023 (4094-4096MB) (for page table mappings) + + 8: boot_pd3_pts[8] (3088-3090MB) (pseudo 512 4KB pages) + 9: boot_pd3_pts[9] (3090-3076MB) (pseudo 512 4KB pages) + 10: boot_pd3_pts[10] (3092-3094MB) (pseudo 512 4KB pages) + 11: boot_pd3_pts[11] (3094-3096MB) (pseudo 512 4KB pages) + 12: boot_pd3_pts[12] (3096-3098MB) (pseudo 512 4KB pages) + 13: boot_pd3_pts[13] (3098-3100MB) (pseudo 512 4KB pages) + 14: boot_pd3_pts[14] (3100-3102MB) (pseudo 512 4KB pages) + 15: boot_pd3_pts[15] (3102-3104MB) (pseudo 512 4KB pages) + + 16: boot_pd3_pt1023 (4094-4096MB) (for page table mappings) the 9 page tables each contain 512 pte's that map individual 4KB pages @@ -146,7 +156,7 @@ start: /* clear pd3's pt's */ movl $(boot_pd3_pts - 0xc0000000), %edi - movl $(1024 * 9), %ecx + movl $(1024 * 17), %ecx xorl %eax, %eax rep stosl @@ -158,7 +168,7 @@ start: orl $0x3, 0(%edi) /* add boot_pd3_pts to boot_pd3 */ - movl $8, %ecx + movl $16, %ecx movl $(boot_pd3 - 0xc0000000), %edi movl $(boot_pd3_pts - 0xc0000000), %eax @@ -183,8 +193,8 @@ start: addl $4096, %eax loop 1b - /* pseudo identity map the 3072-3090MB range */ - movl $(512 * 8), %ecx + /* pseudo identity map the 3072-3102MB range */ + movl $(512 * 16), %ecx movl $(boot_pd3_pts - 0xc0000000), %edi xorl %eax, %eax @@ -239,6 +249,7 @@ start: movl $256, %ecx movl $(boot_pd0_pt0 - 0xc0000000), %edi xorl %eax, %eax + 1: movl %eax, 0(%edi) addl $8, %edi @@ -317,19 +328,18 @@ apic_ap_start32: movl $0x80000001, %eax cpuid testl $0x100000, %edx - // TODO: Uncomment this - //je (1f - apic_ap_start + 0x8000) + je (1f - apic_ap_start + 0x8000) /* turn on IA32_EFER.NXE */ movl $0xc0000080, %ecx rdmsr orl $0x800, %eax wrmsr 1: - + /* load the bsp's cr3 value */ movl (ap_cpu_init_cr3 - apic_ap_start)(%ebp), %eax movl %eax, %cr3 - + /* enable PAE + PSE */ movl %cr4, %eax orl $0x60, %eax @@ -349,9 +359,9 @@ apic_ap_start32_2: /* flush the TLB */ movl %cr3, %eax movl %eax, %cr3 - + movl $0xc0008000, %ebp - + /* now load the final gdt and idt from the identity mapped area */ movl (ap_cpu_gdtr - apic_ap_start)(%ebp), %eax lgdt (%eax) @@ -363,20 +373,20 @@ apic_ap_start32_2: movl %eax, %cr0 movl (ap_cpu_init_cr4 - apic_ap_start)(%ebp), %eax movl %eax, %cr4 - + /* push the Processor pointer this CPU is going to use */ movl (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %eax addl $0xc0000000, %eax movl 0(%eax, %esi, 4), %eax push %eax - + /* push the cpu id, 0 representing the bsp and call into c++ */ incl %esi push %esi - + xor %ebp, %ebp cld - + /* We are in identity mapped P0x8000 and the BSP will unload this code once all APs are initialized, so call init_ap but return to our infinite loop */