2021-09-14 15:48:57 +00:00
|
|
|
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
|
|
|
|
|
2021-09-14 15:54:59 +00:00
|
|
|
; setup initial stack
|
2021-09-14 15:48:57 +00:00
|
|
|
mov esp, stack+STACKSIZE
|
|
|
|
|
2021-09-14 15:54:59 +00:00
|
|
|
; Verify booted with multiboot compliant bootloader
|
2021-09-14 15:48:57 +00:00
|
|
|
cmp ecx, 0x2BADB002
|
|
|
|
jne .bad
|
|
|
|
|
2021-09-14 15:54:59 +00:00
|
|
|
push esp
|
2021-09-14 15:48:57 +00:00
|
|
|
push ebx
|
|
|
|
|
|
|
|
extern k_main
|
|
|
|
call k_main
|
|
|
|
|
2021-09-14 15:54:59 +00:00
|
|
|
cli
|
|
|
|
hlt
|
|
|
|
|
2021-09-14 15:48:57 +00:00
|
|
|
; 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:
|
2021-09-14 15:54:59 +00:00
|
|
|
resb STACKSIZE ; This reserves memory for stack
|