summaryrefslogtreecommitdiff
path: root/kernel/src/boot.asm
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/boot.asm')
-rw-r--r--kernel/src/boot.asm33
1 files changed, 23 insertions, 10 deletions
diff --git a/kernel/src/boot.asm b/kernel/src/boot.asm
index 95b699a..1c0b3da 100644
--- a/kernel/src/boot.asm
+++ b/kernel/src/boot.asm
@@ -5,14 +5,16 @@ section .text
bits 32
start:
mov esp, stack_top
-
+
call check_multiboot
call check_cpuid
call check_long_mode
call setup_page_tables
call enable_paging
- ; load the 64-bit GDT
+
+
+ ; load the 64-bit GDT
lgdt [gdt64.pointer]
jmp gdt64.code:long_mode_start
@@ -96,21 +98,27 @@ setup_page_tables:
.map_p2_table:
; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx
+ mov ebx, eax
+ cmp eax, stack_bottom + 0b10000011 - 0x400000
+ jne .hit_stack
+ and ebx, ~1
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 ecx, 8
+
+.hit_stack:
+ mov [p2_table + ecx ], ebx ; map ecx-th entry
add eax, 0x200000 ; 2MiB
- add ecx, 32
+ add ecx, 8
+ ;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
+
+
+
enable_paging:
mov eax, p4_table
mov cr3, eax
@@ -131,6 +139,10 @@ enable_paging:
or eax, 1 << 31
mov cr0, eax
+ ; move stack pointer to accommodate for the guard page
+ add esp, 0x200000
+
+
ret
section .rodata
@@ -159,6 +171,7 @@ p3_table:
resb 4096
p2_table:
resb 4096
+alignb 4096 * 512
stack_bottom:
- resb 4096 * 8
+ resb 4096 * 4
stack_top: