summaryrefslogtreecommitdiff
path: root/asm/asm_start.s
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-03 15:18:16 +0200
committerMiguel <m.i@gmx.at>2018-09-03 15:18:16 +0200
commit7eb87bf3f3fa6226657a7106eb255cbfa97758d2 (patch)
tree2d7d2280d32180d18796999bf7687ebe5bf208df /asm/asm_start.s
parent76b3da6022310dd8edbbbfdf4f73f1696a559853 (diff)
big renaming
Diffstat (limited to 'asm/asm_start.s')
-rw-r--r--asm/asm_start.s87
1 files changed, 87 insertions, 0 deletions
diff --git a/asm/asm_start.s b/asm/asm_start.s
new file mode 100644
index 0000000..ca99c20
--- /dev/null
+++ b/asm/asm_start.s
@@ -0,0 +1,87 @@
+.global _start
+.global _start_smp
+.global stack_top
+.global stack_bottom
+
+# Fill Multiboot Haeder, init stack and call kernel_main passing two params:
+# eax - magic number
+# ebx - multiboot structure
+
+# Declare constants used for creating a multiboot header.
+.set ALIGN, 1<<0 # align loaded modules on page boundaries
+.set MEMINFO, 1<<1 # provide memory map
+.set GFXINFO, 1<<2 # provide gfx info
+.set FLAGS, ALIGN | MEMINFO | GFXINFO # this is the Multiboot 'flag' field
+.set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header
+.set CHECKSUM, -(MAGIC + FLAGS) # checksum of above, to prove we are multiboot
+
+# entry point for application processors we will copy this to 0x7000 later
+
+.section .smp
+.code16
+_start_smp:
+call smp_start # TODO: align later before going C
+
+
+# Declare a header as in the Multiboot Standard. We put this into a special
+# section so we can force the header to be in the start of the final program.
+# You don't need to understand all these details as it is just magic values that
+# is documented in the multiboot standard. The bootloader will search for this
+# magic sequence and recognize us as a multiboot kernel.
+
+.section .multiboot
+.code32
+.align 4
+.long MAGIC
+.long FLAGS
+.long CHECKSUM
+
+.long 0 # we dont need this for ELF
+.long 0
+.long 0
+.long 0
+.long 0
+
+# we override this from grub anyway
+.long 0 #gfx_stuff 0=enable!
+.long 640
+.long 480
+.long 32
+
+# Currently the stack pointer register (esp) points at anything and using it may
+# cause massive harm. Instead, we'll provide our own stack. We will allocate
+# room for a small temporary stack by creating a symbol at the bottom of it,
+# then allocating 16384 bytes for it, and finally creating a symbol at the top.
+.section .bootstrap_stack, "aw", @nobits
+stack_bottom:
+.skip 16384 # 16 KiB
+stack_top:
+
+# The linker script specifies _start as the entry point to the kernel and the
+# bootloader will jump to this position once the kernel has been loaded. It
+# doesn't make sense to return from this function as the bootloader is gone.
+.section .text
+
+_start:
+
+ # To set up a stack, we simply set the esp register to point to the top of
+ # our stack (as it grows downwards).
+ movl $stack_top, %esp
+
+ sub $8, %esp #to align on 16byte before calling C
+ push %ebx #pass address of the multiboot information data structure
+ push %eax #pass eax, so kernel can check for magic number
+
+ call kernel_main
+
+ # turn off interrupts and halt.
+ # this should never be reached
+ cli
+ hlt
+
+.Lhang:
+ jmp .Lhang
+
+# Set the size of the _start symbol to the current location '.' minus its start.
+# This is useful when debugging or when you implement call tracing.
+.size _start, . - _start