1
votes

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.

1
@Stewart I am rewriting my boot loader so I can test it. I will come back and accept as soon as I incorporate your new code into it. Don't worry :) - user99545

1 Answers

0
votes

You're checking for errors incorrectly. int 0x13 ah=0 for example indicates an error by setting the carry flag, not by reporting something in ah. Instead of or ah, ah jnz err, you should be jumping if carry is set using jc err.