aboutsummaryrefslogtreecommitdiff
path: root/i686/init.s
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-10-29 11:26:44 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-10-29 11:26:44 +0300
commitc4fcc92183c55db868d0d6ae53e6009fb2e53ee5 (patch)
treead5ef50aa07465e11f779c4482e20e6071182e9c /i686/init.s
parentmakefile: add libk target (diff)
downloadkernel-c4fcc92183c55db868d0d6ae53e6009fb2e53ee5.tar.xz
makefile: add i686/arch.a target
Diffstat (limited to 'i686/init.s')
-rw-r--r--i686/init.s42
1 files changed, 42 insertions, 0 deletions
diff --git a/i686/init.s b/i686/init.s
new file mode 100644
index 0000000..92710df
--- /dev/null
+++ b/i686/init.s
@@ -0,0 +1,42 @@
+.section .stack, "aw", @nobits
+.global k_stack
+.align 16 /* Stack on x86 must be 16-byte aligned according to System V ABI */
+k_stack_bottom:
+ .skip 16 * 1024 /* 16 kByte */
+k_stack:
+
+.section .pages, "aw", @nobits
+.align 4096
+.global k_pagedir
+k_pagedir: .skip 1024 * 4
+.global k_ptable0x300
+k_ptable0x300: .skip 1024 * 4
+
+.section .text
+.global k_init
+.extern kmain
+k_init:
+ # kernel entry point, higher half
+
+ # unmap the identity mapping as its no longer necessary
+ movl $0, k_pagedir + 0 * 4
+ mov %cr3, %ecx # reload cr3 to force a TLB flush
+ mov %ecx, %cr3
+
+ # zero out the stack
+ mov $4096, %ecx # loop counter
+ mov $k_stack_bottom, %edi # start from the bottom
+ xor %edx, %edx # clear %edx
+1: movl %edx, (%edi) # store %edx into address in %edi
+ addl $4, %edi # point to next address
+ loop 1b # loop according to %ecx
+
+ mov $k_stack, %esp # point stack pointer to the stack
+
+ call kmain
+
+ /* If the system has nothing more to do, put it in an infinite loop */
+ cli # disable interrupts
+h: hlt # wait for interrupt
+ jmp h # continue waiting for interrupt
+