aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/boot.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/boot.asm')
-rw-r--r--src/kernel/boot.asm70
1 files changed, 51 insertions, 19 deletions
diff --git a/src/kernel/boot.asm b/src/kernel/boot.asm
index 444b73a..6aa5c1a 100644
--- a/src/kernel/boot.asm
+++ b/src/kernel/boot.asm
@@ -1,4 +1,23 @@
-section .multiboot
+bits 32
+
+; Some variables
+kernel_virt_base equ 0xC0000000
+kernel_page_number equ (kernel_virt_base >> 22)
+kernel_stack equ 0x4000
+
+section .data
+ align 0x1000
+
+ boot_page_dir:
+ dd 0x00000083
+ times (kernel_page_number - 1) dd 0
+ dd 0x00000083
+ times (1024 - kernel_page_number - 1) dd 0
+
+section .text
+ align 4
+
+ multiboot:
header_start:
dd 0xe85250d6
dd 0
@@ -15,6 +34,12 @@ section .multiboot
dd 6 ; mmap
dd 13 ; smbios
+ ; Page-align tag
+ align 8
+ dw 6
+ dw 0
+ dd 8
+
; Empty tag
align 8
dw 0
@@ -22,29 +47,36 @@ section .multiboot
dd 8
header_end:
-section .start_section
- dd _start
+ global boot
+ extern kernel_main
+ boot:
+ mov ecx, (boot_page_dir - kernel_virt_base)
+ mov cr3, ecx
-; Initialize stack
-;section .bss
-; align 16
-;
-; STACK_BOTTOM:
-; resb 0x4000
-; STACK_TOP:
+ mov ecx, cr4
+ or ecx, 0x00000010
+ mov cr4, ecx
+
+ mov ecx, cr0
+ or ecx, 0x80000000
+ mov cr0, ecx
-section .text
- global _start
- extern kernel_main
- _start:
- ;mov esp, STACK_TOP
+ lea ecx, [higher_half]
+ jmp ecx
+
+ higher_half:
+ mov dword [boot_page_dir], 0
+ invlpg [0]
+
+ mov esp, stack + kernel_stack
push esp
push ebx
push eax
cli
call kernel_main
- jmp $
+ hlt
-section .end
- global KERNEL_END
- KERNEL_END: \ No newline at end of file
+section .bss
+ align 32
+ stack:
+ resb kernel_stack \ No newline at end of file