bits 32
section start alloc exec write progbits align=16
mov ecx, 0x400000 ; Set up stack to top of multiboot's
mov esp, ecx ; reserved bss area, we can use the stack
; freely without worry of overwriting
; the multiboot structure
cmp eax, 0x2BADB002 ; Check magic signature in eax
jne bad_magic
mov eax, 0 ; Replace multiboot header, temporarily
mov edi, 0x100400 ; stored in the gdt, with zero's, so that
mov ecx, 15 ; there will not be random segments defined
cld ; eax = replacement value, edi = location
rep stosd ; of header, ecx = length to replace / 4
mov eax, [ebx]
bt eax, 1
jc boot_device_ok ; If neither boot_device nor cmdline is
bt eax, 2 ; specified, we dont know where to boot from.
jnc no_boot_device ; It's still possible there is a cmdline but
boot_device_ok: ; with no boot device specified
bt eax, 3 ; The root filesystem driver has to be loaded
jnc no_mods ; as a module, along with supporting drivers
bt eax, 0
jc mem_map_ok
bt eax, 6
jnc no_mem_map
mem_map_ok:
mov esi, test_string
jmp print_msg
no_boot_device:
mov esi, no_boot_device_string
jmp print_msg
no_mods:
mov esi, no_mods_string
jmp print_msg
no_mem_map:
mov esi, no_mem_map_string
jmp print_msg
bad_magic:
mov esi, bad_magic_string
jmp print_msg
print_msg:
mov edi, 0xb8000
print_msg_loop:
lodsb
cmp al, 0
je halt
stosb
mov al, 0xF ; White on black, non-blinking
stosb
jmp print_msg_loop
halt:
jmp halt
bad_magic_string db 'The boot loader is incompatible with this OS (Bad signature)', 0
no_mem_map_string db 'The boot loader is incompatible with this OS (No memory map)', 0
no_mods_string db 'Unable to boot; no filesystem driver loaded', 0
no_boot_device_string db 'Unable to boot; no boot device specified', 0
test_string db 'Testing...', 0
section initsys alloc noexec write progbits align=4096