luxos/Kernel/loader.asm

73 lines
1.1 KiB
NASM
Raw Normal View History

bits 32
global start
; multiboot header
MODULEALIGN equ 1<<0
MEMINFO equ 1<<1
VIDEOINFO equ 1<<2
FLAGS equ MODULEALIGN | MEMINFO | VIDEOINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
align 4
section .__mbHeader
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
section .text
STACKSIZE equ 0x4000 ; that's 16k.
start:
XCHG BX, BX ; magic breakpoint
mov ecx, eax
; setup initial stack
mov esp, stack+STACKSIZE
; Verify booted with multiboot compliant bootloader
cmp ecx, 0x2BADB002
jne .bad
push esp
push ebx
extern k_main
call k_main
cli
hlt
; Show error message, and halt system
.bad:
extern ConsoleClear
extern ConsoleWrite
extern CommandOsver
call ConsoleClear
call CommandOsver
mov eax, [ErrorColor]
push eax
push ErrorString
call ConsoleWrite
cli
hlt
; some variables
ErrorString db 0xA, "%#! Fatal error: Not booted with multiboot compliant bootloader (e.g. GRUB).", 0x0
ErrorColor db 0x0C
; stack
section .bss
align 32
stack:
resb STACKSIZE ; This reserves memory for stack