I am writing a bootloader in assembly and it seems to work fine on qemu, bochs and virtualbox. However, it is not loading the kernel on real hardware (it seems).
The
If your hardware is using floppy disk emulation for the USB drive it may be possible that without a proper BIOS Parameter Block (BPB) in your MBR that it is failing to boot properly. Many BIOSes will attempt to detect a BPB at the start of the bootloader and may even update the values with proper drive geometry after the bootloader is loaded into memory. It is possible your bootloader was not being detected as a proper bootable drive or it was but the BIOS overwrote some of your code with drive geometry information before executing it.
The following adds a BPB that happens to look like a 2.88MB floppy.
.global _start
.code16
.text
_start:
jmp main
.space 3 - (.-_start)
/* Configuration for a 2.88MB floppy using FAT 12 */
OEMname: .ascii "MYBOOT "
bytesPerSector: .word 512
sectPerCluster: .byte 1
reservedSectors: .word 1
numFAT: .byte 2
numRootDirEntries: .word 240
numSectors: .word 5760
mediaType: .byte 0xf0
numFATsectors: .word 9
sectorsPerTrack: .word 36
numHeads: .word 2
numHiddenSectors: .long 0
numSectorsHuge: .long 0
driveNum: .byte 0
reserved: .byte 0x00
signature: .byte 0x29
volumeID: .long 0x54428E71
volumeLabel: .ascii "NO NAME "
fileSysType: .ascii "FAT12 "
main:
movw $0xb800, %ax
movw %ax, %ds
movw $0x0741, (0x0)
xorw %ax, %ax
movw %ax, %ds
movw %ax, %si
movw %ax, %es
movw $0x8000, %ax
movw %ax, %ss
movw $0, %sp
movb $2, %ah
movb $1, %al
movw $0x02, %cx
movb $0x00, %dh
movw $0x5000, %bx
movw %bx, %es
movw $0x0, %bx
int $0x13
ljmpw $0x5000, $0x0000
.space 510-(.-_start)
.word 0xaa55