Over the past few days I have been writing a bootloader/kernel in NASM... It loads perfectly fine when I write it to a virtual floppy using PARTCOPY, and then boot to it from Oracle VM VirtualBox. However, when I write it to a physical floppy and try to boot to it from startup, nothing appears and it hangs. Any ideas as to why?
Bootloader code-
[bits 16]
[org 0x7C00]
jmp reset
reset: ;Resets floppy drive
xor ax,ax ;0 = Reset floppy disk
mov dl,0 ;Drive 0 is floppy
int 0x13
jc reset ;If carry flag was set, try again
mov ax,0x1000 ;When we read the sector, we are going to read address 0x1000
mov es,ax ;Set ES with 0x1000
floppy:
mov ah,0x2 ;2 = Read floppy
mov al,0x1 ;Reading one sector
mov ch,0x0 ;Track 1 *0 = 1*
mov cl,0x2 ;Sector 2, track 1
mov dh,0x0 ;Head 1
mov dl,0x0 ;Drive = 0 (Floppy)
int 0x13
jc floppy ;If carry flag was set, try again
jmp 0x1000:0000 ;Jump to 0x1000, start of second program
times 510 - ($ - $$) db 0 ;Fill the rest of sector with 0 (nil) to make the file end up as 512 bytes
dw 0xAA55 ;This is the boot signiture, it tells the BIOS that this is a valid bootloader
Program that is loaded from bootloader-
[bits 16]
[org 0] ;0x1000
jmp main
main:
push cs ;Push Code Segment
pop ds ;Pop Data Segment
;Code starts here
mov cx,welcomeLength
mov si,welcome
call print_
mov cx,welcomeOSLength
mov si,welcomeOS
call print_
mov cx,dwarfl
mov si,dwarf
call print_
cli ;Disable interrupts
hlt ;Halt the CPU - Hang
print_:
lodsb ;Grab color attribute from front of string
mov bl,al ;Place it into BL
call color ;Note that CX must have the string length
printstr_:
lodsb ;Load next byte from SI into AL
or al,al ;Is it 0?
jz exit ;If yes, we're done
call print ;Display the char in AL
jmp printstr_
print:
mov ah,0x0E ;0x0E = Display character in AL with attribute in BL
xor bh,bh ;Set BH to 0; Page 0
mov bl,0xC ;Color = Bright Red
int 0x10
ret ;Return and keep loading/displaying our string
color: ;AL = char, BL = attribute, CX = amount of char
mov ah,0x9 ;0x9 = Write character attribute
mov al,0 ;Nil characters
int 0x10
ret
exit:
ret ;Return to main code
;Data section
welcome db 0xC,"Boot Successful . . .",13,10,0
welcomeLength EQU ($-welcome)-3
welcomeOS db 0xA,"Welcome to ",0
welcomeOSLength EQU ($-welcomeOS)-1
dwarf db 0xB,"DwarfOS!",13,10,0
dwarfl EQU ($-dwarf)-3
Written to floppy A using:
partcopy dwarf.bin 0 200 -f0
partcopy kernel.bin 0 2000 -f0 200