Bootloader
Code: Select all
bits 16
org 0x7C00
;Jumping to main
jmp main
;Main
main:
call ResetFloppy
call LoadKernel
jmp hang
;Reset floppy drive
ResetFloppy:
mov ah, 0x00 ;Reset function
mov dl, 0x00 ;Floppy
int 0x13 ;Calling interupt
;If there is no error then return
jnc Return
;If there is a error display it
mov si, FloppyError
call PrintString
ret
;Loading kernel from floppy
LoadKernel:
mov ah, 0x02 ;Read from drive
mov al, 0x01 ;Sectors(512 bytes) to read
mov ch, 0x02 ;Track
mov cl, 0x0f ;Sector
mov dh, 0x01 ;Head AKA side of floppy
mov dl, 0x00 ;Drive, 0 is floppy A:
mov bx, 0x1000 ;Moving adress 0x1000 into bx
mov es, bx ;Moving bx into es
mov bx, 0 ;Resetting bx
int 0x13 ;Calling interrupt
jnc JumpToKernel
mov si, ErrorLoadingKernel
jc PrintString
jc Return
;Jumps to kernel
JumpToKernel:
jmp 0x1000:0x0000
;Print string in si
PrintString:
mov al, [si] ;Loading si into al
cmp al, 0 ;If the current character = 0 AKA end of string, then return
je Return
mov ah, 0x0e ;Print character function
int 0x10 ;Calling the interrupt
inc si ;Going to the next letter
jmp PrintString ;Looping back
;Return
Return:
ret
hang:
mov si, Hanging
call PrintString
jmp hang
FloppyError db "Error resetting drive.", 0
Hanging db "Hanging...", 0
ErrorLoadingKernel db "Error loading kernel from floppy.", 0
;Filling the rest of the file with zeros to make 512 bytes
times 512 - ($-$$) db 0
Code: Select all
bits 16
org 0
jmp main
main:
mov ax, 0
mov ah, 0x0e
mov al, 'A'
int 0x10
EDIT, I should also mention that my kernel is at sector 33 of the floppy, i found that using WinHex, Also i should mention i am loading the bootloader from an ISO and i am using VirtualBox for testing.