Accessing disk from bootloader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
hemel7
Posts: 3
Joined: Mon Apr 10, 2017 6:01 am
Libera.chat IRC: hemel7

Accessing disk from bootloader

Post 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.
glauxosdever
Member
Member
Posts: 501
Joined: Wed Jun 17, 2015 9:40 am
Libera.chat IRC: glauxosdever
Location: Athens, Greece

Re: Accessing disk from bootloader

Post 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
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: Accessing disk from bootloader

Post by Geri »

bios puts the dl the boot drive by default. 0x80 first hdd, 0x81 is second hdd. small numbers like 0x01 means floppy
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
hemel7
Posts: 3
Joined: Mon Apr 10, 2017 6:01 am
Libera.chat IRC: hemel7

Re: Accessing disk from bootloader

Post 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.
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: Accessing disk from bootloader

Post 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.
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
hemel7
Posts: 3
Joined: Mon Apr 10, 2017 6:01 am
Libera.chat IRC: hemel7

Re: Accessing disk from bootloader

Post by hemel7 »

That's just great.
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Re: Accessing disk from bootloader

Post 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?
Post Reply