I am trying to build my own boot loader that loads then switches from real mode to protected mode, loads the GDT descriptor and then calls some stage 2 code. Since I cannot figure out a good way of debugging my programs, it has been an uphill battle to get things to work. For some odd reason, my code fails at reading the second sector of my bootloader into memory at 0x1000 address. I have tried using the int 0x13 with al = 0x01 which is a Get Status of Last Drive Operation interupt. It returns 0x01 which means Invalid Command which confuses me further.
mov ah, 0 ;reset drive
int 0x13
or ah, ah ;check for error
jnz err ;error handling function (prints ASCII A)
mov ax, 0
mov es, ax
mov bx, 0x1000 ;read sector into 0000:0x1000
mov ah, 0x02 ;read sector
mov al, 1 ;# of sectors to read = 1
mov ch, 0 ;Cylinder = 0
mov cl, 0x02 ;Sector to read = 2 (second as first sector is this code)
mov dh, 0 ;head = 0
;dl should equal the drive number as BIOS automatically detects it
int 0x13
or ah, ah
jnz err ;check for error again (this is where the error occurs)
When the computer is booted, I am told that BIOS places the drive letter into the dl register so all my interrupts should be performed on the correct drive. I even tried setting dl to 0x00 which would be equal to floppy drive A: and in BOCHS (CPU emulator) I set the floppy drive A: to my boot image and still it would not boot. Is there some reason why QEMU and BOCHS won't emulate the code correctly? I have yet to try burning this to a USB and booting it from a live BIOS. I will post my complete code here so you can review it if necessary. I apologize if I am not clear enough, I am beginner at OS development. Many thanks!
Edit: OS: Windows 7 x64 (developing x32 OS) Emulation: BOCHS running boot.img created by NASM compiler.