;; This is the BIOS boot. Its goal is to jump to the second stage bootloader ;; with minimal setup. (asm (:start) ; Clear Registers (u8 0h31 0hC0) ; xor ax, ax (u8 0h8E 0hC0) ; mov es, ax (u8 0h8E 0hD0) ; mov ss, ax (u8 0h8E 0hD8) ; mov ds, ax ; Stack Setup (u8 0hBC) (u16 0h7c00) ; mov sp, 0h7c00 (u8 0h88 0h16) (u16 boot_drive) ; mov [boot_drive], dl (mov ah 0h41) (u8 0hBB) (u16 0h55aa) ; mov bx, 0h55aa (int 0h13) (u8 0h0F 0h82) (u16 :ldns) ; jc ldns (u8 0hE8) (u16 :ldb2) ; call ldb2 (u8 0h8A 0h16) (u16 boot_drive) ; mov dl, [boot_drive] (u8 0hEA) (u32 0h8000)) ; jmp 0h8000:0 ; This section loads the stage 2 bootloader based on information provided ; from the b2dap. (asm (:ldb2) (u8 0hBE) (u16 b2dap) ; mov si, b2dap (u8 0h8A 0h16) (u16 boot_drive) ; mov dl, [boot_drive] (mov ah 0h42) (int 0h13) (u8 0h0F 0h82) (u16 :ldfail) ; jc ldfail (ret)) ;; Debug functions (asm (:ldns) (u8 0hBE) (u16 ldnsmsg) ; mov si, ldnsmsg (u8 0hE8) (u16 :print) ; call :print (u8 0hEB 0hFE)) ; jmp $ (asm (:ldfail) (u8 0hBE) (u16 ldfailmsg) ; mov si, ldfailmsg (u8 0hE8) (u16 :print) ; call :print (u8 0hEB 0hFE)) ; jmp $ (asm (:print) (mov ah 0h0E) (:print_loop) (u8 0h8A 0h04) ; mov al, [si] (cmp al 0h00) (u8 0h0F 0h84) (u16 :print_done) ; jz :print_done (int 0h10) (u8 0hFF 0hC6) ; inc si (u8 0hE9) (u16 :print_loop) ; jmp :print_loop (:print_done) (ret)) ;; This is more of a data ump that is forward referenced in this source file. ;; This is to avoid it colliding with dissassembly output. ; Stage2 DAP (asm (:b2dap) (u8 0h10) (u8 0) (u16 1) (u16 0h8000) (u16 0) (u64 1)) (asm (:ldfailmsg) (u8 "Boot failed! Can't load b2dap" 13 10 0)) (asm (:ldnsmsg) (u8 "Boot failed! LBA not supported." 13 10 0)) (asm (:boot_drive) (u8 0))