BIOS drive number & ATA primary/secondary master/slave

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
Archil
Posts: 24
Joined: Tue Jul 15, 2008 7:54 am
Location: Tbilisi, Georgia.
Contact:

BIOS drive number & ATA primary/secondary master/slave

Post by Archil »

Currently all my code can do is to print what devices are on primary/secondary master/slave. It works using I/O ports (thanks to Osdev Wiki). But I seem to be unable to find a way how i can match BIOS drive number and a hard disk. Can anyone tell me what device contains the needed information? Maybe CMOS, but I've not found any useful thing for my case yet in it.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: BIOS drive number & ATA primary/secondary master/slave

Post by egos »

See EDD Specification for modern drives. For legacy drives BIOS sets the drive numbers in detection order, but you can do additional checking of correspondence.
If you have seen bad English in my words, tell me what's wrong, please.
Archil
Posts: 24
Joined: Tue Jul 15, 2008 7:54 am
Location: Tbilisi, Georgia.
Contact:

Re: BIOS drive number & ATA primary/secondary master/slave

Post by Archil »

I guess my kernel should have knowledge of how BIOS detects drives and act respectively. I've come to such a foolsh question :D What if user chooses the device? Has anyone done so? :P
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: BIOS drive number & ATA primary/secondary master/slave

Post by bewing »

Unfortunately, there is no very good way to do this for BIOS. This is one of the biggest failures of BIOS.

The best thing to do is to have your bootloader detect the drives, and select the boot drive in Pmode -- and not use the BIOS for this at all.
Archil
Posts: 24
Joined: Tue Jul 15, 2008 7:54 am
Location: Tbilisi, Georgia.
Contact:

Re: BIOS drive number & ATA primary/secondary master/slave

Post by Archil »

bewing wrote: The best thing to do is to have your bootloader detect the drives, and select the boot drive in Pmode -- and not use the BIOS for this at all.
It helps only when a loader uses multi-drive booting, asking the user which drive to boot. And so in other cases I remember Windowses and Linuxes fail at boot time. Too bad :-(
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: BIOS drive number & ATA primary/secondary master/slave

Post by Brendan »

Hi,
egos wrote:See EDD Specification for modern drives. For legacy drives BIOS sets the drive numbers in detection order, but you can do additional checking of correspondence.
Yes.

More specifically, while you're in real mode (e.g. during boot), use the INT 13 Extensions - GET DRIVE PARAMETERS function to find out what all of the BIOS disk devices actually are, and use this information when you're in protected mode to figure out which device/s correspond to which BIOS numbers. Note: if that function doesn't work, then use DISK - GET DRIVE PARAMETERS (PC,XT286,CONV,PS,ESDI,SCSI) instead, and maybe consider getting a checksum of the first few sectors (in case there's 2 or more identical drives).

There is one thing you need to be careful of though - if you boot from an emulated device. For example, maybe the OS booted from a CD that used hard disk emulation. If you're not careful your OS can be mislead; and (depending on what you're doing) it may be a good idea to disable emulation beforehand.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply