aboutsummaryrefslogtreecommitdiff
path: root/boot/boot.asm
diff options
context:
space:
mode:
Diffstat (limited to 'boot/boot.asm')
-rw-r--r--boot/boot.asm49
1 files changed, 24 insertions, 25 deletions
diff --git a/boot/boot.asm b/boot/boot.asm
index 645061c..d79c9a1 100644
--- a/boot/boot.asm
+++ b/boot/boot.asm
@@ -2,54 +2,53 @@
; get a prototype off the ground quickly without pissing around
; Declare constants used for creating a multiboot header.
-MBALIGN equ 1<<0 ; align loaded modules on page boundaries
-MEMINFO equ 1<<1 ; provide memory map
-FLAGS equ MBALIGN | MEMINFO ; this is the Multiboot 'flag' field
-MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
-CHECKSUM equ -(MAGIC + FLAGS) ; checksum of above, to prove we are multiboot
-
-; 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.
+MBALIGN equ 1<<0 ; align loaded modules on page boundaries
+MEMINFO equ 1<<1 ; Ask for memory map
+FLAGS equ MBALIGN | MEMINFO
+MAGIC equ 0x1BADB002
+CHECKSUM equ -(MAGIC + FLAGS)
+
+; Standard mutliboot header so GRUB and other bootloaders can boot the kernel
section .multiboot
align 4
dd MAGIC
dd FLAGS
dd CHECKSUM
-; 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.
+; Init our very own 16K stack
section .bootstrap_stack
align 4
stack_bottom:
times 16384 db 0
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
global _start
+global _kernel_exit
+
_start:
+ ; Functions in external objects
extern kernel_main
- extern console_print
- extern console_set_colors
+ extern console_print_string
+ extern console_set_color
+ ; Set stack up ready for C
mov esp, stack_top
+ push eax
+ push ebx
call kernel_main
; Let the user know that kernel_main() exited
- push word 0x0007
- call console_set_colors
- push mainexit
- call console_print
+ push 0x0A
+ call console_set_color ; Reset text colour
+ push exitmain
+ call console_print_string
+
+ ; Wake us not from our slumber
cli
+_kernel_exit:
.hang:
hlt
jmp .hang
-mainexit db 10,"asm: kernel_main() exited",0
+exitmain db 10,"boot: kernel_main() exited",0 \ No newline at end of file