92 lines
1.6 KiB
NASM
92 lines
1.6 KiB
NASM
format binary
|
|
use32
|
|
org 0x100000
|
|
|
|
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
|
|
MULTIBOOT_PAGE_ALIGN equ (1 shl 0)
|
|
MULTIBOOT_MEMORY_INFO equ (1 shl 1)
|
|
MULTIBOOT_VIDEO_REQUEST equ (0 shl 2)
|
|
MULTIBOOT_AOUT_KLUDGE equ (1 shl 16)
|
|
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFO or MULTIBOOT_VIDEO_REQUEST
|
|
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN or MULTIBOOT_MEMORY_INFO or MULTIBOOT_VIDEO_REQUEST or MULTIBOOT_AOUT_KLUDGE
|
|
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
|
|
|
multiboot:
|
|
dd MULTIBOOT_HEADER_MAGIC
|
|
dd MULTIBOOT_HEADER_FLAGS
|
|
dd MULTIBOOT_CHECKSUM
|
|
dd multiboot ; header address
|
|
dd 0x100000 ; load address
|
|
dd stack_bottom ; load end address
|
|
dd stack_top ; bss end address
|
|
dd start ; entry address
|
|
dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!)
|
|
dd 1024 ; video width
|
|
dd 768 ; video height
|
|
dd 32 ; video depth
|
|
|
|
start:
|
|
; Setup stack
|
|
mov ebp, stack_bottom
|
|
mov esp, stack_top
|
|
|
|
push ebx
|
|
push eax
|
|
|
|
cmp eax, 0x2badb002
|
|
jne multibootnomagic
|
|
|
|
mov byte [0xb8000], '!'
|
|
|
|
mov esi, stuff.bootmsg
|
|
call serialinit
|
|
call printbootmsg
|
|
call serialwrite
|
|
|
|
jmp hang
|
|
|
|
hang:
|
|
cli
|
|
hlt
|
|
jmp hang
|
|
|
|
multibootnomagic:
|
|
mov esi, .msg
|
|
mov edi, 0xb8000
|
|
mov ah, 64
|
|
cld
|
|
.loop:
|
|
lodsb
|
|
or al, al
|
|
jz .done
|
|
stosw
|
|
jmp .loop
|
|
.done:
|
|
jmp hang
|
|
.msg db "No multiboot magic", 0
|
|
|
|
printbootmsg:
|
|
pushad
|
|
mov edi, 0xb8000
|
|
cld
|
|
.loop:
|
|
lodsb
|
|
or al, al
|
|
jz .done
|
|
stosb
|
|
inc edi
|
|
jmp .loop
|
|
.done:
|
|
popad
|
|
ret
|
|
|
|
include "src/serial.asm"
|
|
|
|
stuff:
|
|
.bootmsg db "=== KoalemOS ===", 0
|
|
|
|
|
|
stack_bottom:
|
|
rb 16384
|
|
stack_top:
|