org 0x7C00 ;start address of the bootloder that will load the kernel
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, ax
mov [bootdrive], dl ;bootdrive stored by BIOS in DL.
;we save it to [bootdrive] to play for safety.
mov si, strLoad ;show loading message
call printStr
;-----------------------
loadKernel:
mov si, strDot ;show loading progress
call printStr
xor ax, ax ;mov ax, 0 => function "reset"
mov dl, [bootdrive] ;boot drive
int 0x13 ;reset floppy drivers
jc loadKernel ;CF set? try again
mov si, strDot
call printStr
;set parameters for reading function
mov ah, 0x2 ;read sectors
mov al, 10 ;read 10 sectors
mov ch, 0 ;cylinder = 0
mov cl, 2 ;sector = 2
mov dh, 0 ;head = 0
mov dl, [bootdrive] ;boot drive
mov bx, 0x8000 ;start address of kernel
int 0x13 ;read sectors
jc loadKernel ;CF set? try again
mov si, strDot
call printStr
mov si, strDone
call printStr
jmp 0x8000
;-----------------------
printStr:
mov ah, 0x0E ;teletype output
.loop:
lodsb ;grab a byte from SI
test al, al ;NULL?
jz .done ;if NULL exit
int 0x10 ;print out the character!
jmp .loop
.done:
ret
;-----------------------
bootdrive db 0 ;boot drive, 0 = floppy
strLoad db "Loading kernel", 0
strDot db ".", 0
strDone db "[DONE]", 13, 10, 0
times 510-($-$$) hlt
db 0x55
db 0xAA