From 457a61341a3b62c9c99981bf2fa90a333aedc928 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 13 Aug 2015 13:15:37 +0200 Subject: [PATCH] Enable paging --- src/arch/x86_64/boot.asm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/arch/x86_64/boot.asm b/src/arch/x86_64/boot.asm index 2871f794..9c168bd5 100644 --- a/src/arch/x86_64/boot.asm +++ b/src/arch/x86_64/boot.asm @@ -24,6 +24,7 @@ start: call check_long_mode call setup_page_tables + call enable_paging ; print `OK` to screen mov dword [0xb8000], 0x2f4b2f4f @@ -40,6 +41,30 @@ setup_page_tables: ret +enable_paging: + ; load P4 to cr3 register (cpu uses this to access the P4 table) + mov eax, p4_table + mov cr3, eax + + ; enable PAE-flag in cr4 (Physical Address Extension) + mov eax, cr4 + or eax, 1 << 5 + mov cr4, eax + + ; set the long mode bit in the EFER MSR (model specific register) + mov ecx, 0xC0000080 + rdmsr + or eax, 1 << 8 + wrmsr + + ; enable paging in the cr0 register + mov eax, cr0 + or eax, 1 << 31 + or eax, 1 << 16 + mov cr0, eax + + ret + ; Prints `ERR: ` and the given error code to screen and hangs. ; parameter: error code (in ascii) in al error: