Page 1 of 1

BIOS drive number & ATA primary/secondary master/slave

Posted: Mon Aug 17, 2009 5:27 am
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.

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

Posted: Mon Aug 17, 2009 5:55 am
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.

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

Posted: Tue Aug 18, 2009 7:17 am
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

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

Posted: Tue Aug 18, 2009 10:36 am
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.

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

Posted: Tue Aug 18, 2009 11:39 pm
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 :-(

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

Posted: Wed Aug 19, 2009 12:26 am
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