From 936e2073a92ec1ca49543b932444cdacd7fbe8fc Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 11 Apr 2017 14:55:41 +0200 Subject: [PATCH] Enable paging --- src/arch/x86_64/boot.asm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/arch/x86_64/boot.asm b/src/arch/x86_64/boot.asm index 71703ee..3e8e594 100644 --- a/src/arch/x86_64/boot.asm +++ b/src/arch/x86_64/boot.asm @@ -10,6 +10,7 @@ start: call check_long_mode call set_up_page_tables + call enable_paging ; print `OK` to screen mov dword [0xb8000], 0x2f4b2f4f @@ -103,6 +104,29 @@ set_up_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 + mov cr0, eax + + ret + ; Prints `ERR: ` and the given error code to screen and hangs. ; parameter: error code (in ascii) in al error: