From f45b2e7c13b3c8821832374e3e8860eabaaae5d2 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Fri, 25 Oct 2019 02:53:43 +0200 Subject: Initialize paging --- kernel/src/boot.asm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/kernel/src/boot.asm b/kernel/src/boot.asm index de832f8..3d79096 100644 --- a/kernel/src/boot.asm +++ b/kernel/src/boot.asm @@ -74,6 +74,37 @@ check_long_mode: mov al, "2" jmp error +setup_page_tables: + ; map first P4 entry to P3 table + mov eax, p3_table + or eax, 0b11 ; present + writable + mov [p4_table], eax + + ; map first P3 entry to P2 table + mov eax, p2_table + or eax, 0b11 ; present + writable + mov [p3_table], eax + + ; map each P2 entry to a huge 2MiB page + mov ecx, 0 ; counter variable + mov eax, 0b10000011 ; present + writable + huge + +.map_p2_table: + ; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx + mov [p2_table + ecx ], eax ; map ecx-th entry + add eax, 0x200000 ; 2MiB + mov [p2_table + ecx + 8 ], eax ; map ecx-th entry + add eax, 0x200000 ; 2MiB + mov [p2_table + ecx + 16], eax ; map ecx-th entry + add eax, 0x200000 ; 2MiB + mov [p2_table + ecx + 24], eax ; map ecx-th entry + add eax, 0x200000 ; 2MiB + + add ecx, 32 + cmp ecx, 4096 ; if counter == 512, the whole P2 table is mapped + jne .map_p2_table ; else map the next entry + + ret ; Prints 'ERR: ' and the given error code to the screen and halts ; parameter: error code letter (ascii) in al error: @@ -84,6 +115,13 @@ error: hlt section .bss +align 4096 +p4_table: + resb 4096 +p3_table: + resb 4096 +p2_table: + resb 4096 stack_bottom: resb 64 stack_top: -- cgit v1.2.3-54-g00ecf