summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2019-10-25 02:53:43 +0200
committerDennis Kobert <dennis@kobert.dev>2019-10-25 02:53:43 +0200
commitf45b2e7c13b3c8821832374e3e8860eabaaae5d2 (patch)
tree013f78130b3d2b5fc62048db155597b0c8227d99
parent13f06d9ec0bf72cdacaba40719ff059366264cdf (diff)
Initialize paging
-rw-r--r--kernel/src/boot.asm38
1 files changed, 38 insertions, 0 deletions
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: