Page 1 of 1

Accessing disk from bootloader

Posted: Mon Apr 10, 2017 6:14 am
by hemel7
Hi all,

I wrote a bootloader that can access the disk and read hex from it.
I've set the registers as:
mov dl, 0x80
mov ah, 0x02
mov al, 5
mov ch, 0x00
mov dh, 0x00
mov cl, 0x02
and int 0x13

It worked fine but there was one thing that I didn't get
I used qemu to run the code
qemu-system-x86_64 -fda boot_sect.bin
Why do I have to use "-fda" when boot_sect.bin is in the hard drive? Also I thought setting dl to 0x80 instructs the bios to access C drive not floppy.

Am I misunderstanding anything?

Thank you.

Re: Accessing disk from bootloader

Posted: Tue Apr 11, 2017 12:27 pm
by glauxosdever
Hi,


You shouldn't hardcode the value in DL - it's passed for you from the BIOS. All you have to do is to store it in a variable and then restore it when using the BIOS disk interrupts. This way you instruct the BIOS to read from whatever your bootloader has been booted from.

Hope this helps. :-)


Regards,
glauxosdever

Re: Accessing disk from bootloader

Posted: Tue Apr 11, 2017 7:24 pm
by Geri
bios puts the dl the boot drive by default. 0x80 first hdd, 0x81 is second hdd. small numbers like 0x01 means floppy

Re: Accessing disk from bootloader

Posted: Wed Apr 12, 2017 8:12 am
by hemel7
Ok.
I stored the value in dl to a variable:
mov [drive_type], dl
restored the value before int0x13:
mov dl, [drive_type].
It all worked fine but I when checked the hex value of dl at the start, it was 0x80.
This means it will load the data from the first hard drive right?
But why do I have to use -fda flag when using qemu when It is not using a floppy drive?
qemu-system-x86_64 -fda boot_sect.bin
If I omit the flag or use -hda flag instead, it will set the carry flag and throw an error
This is confusing.

Re: Accessing disk from bootloader

Posted: Wed Apr 12, 2017 8:31 am
by Geri
for me, if i put it into hda, i get the floppy flag, if to the hdd, i get the hdd flag. for you, something is wrong with something.

Re: Accessing disk from bootloader

Posted: Wed Apr 12, 2017 6:39 pm
by hemel7
That's just great.

Re: Accessing disk from bootloader

Posted: Thu Apr 13, 2017 12:13 am
by FusT
I agree that Geri's reply isn't very helpful. Have you tested what the value of DL looks like on a different emulator/simulator like Bochs or VirtualBox?