I am in the process of writing a toy OS on x86-64. I wrote the master boot code which load the boot code using BIOS,
switches to protected mode, and branch to the boot code.
The boot code scans the PCI devices and is ready to load the kernel (just a stub right now).
The problem is that I have no idea how to detect which PCI drive is the boot drive when multiple drives
are available.
So the question is: how do you use information from BIOS to detect the boot drive via PCI????
Thanks in advance.....PaoloR
Detecting Boot Drive while scanning PCI devices
Re: Detecting Boot Drive while scanning PCI devices
There are two scenarios.
If you let the BIOS choose the boot disk, then the answer is that there is no good answer. Deciding which disk is the BIOS boot disk is one of the most difficult tasks faced by a kernel during boot phase. Dex says that there is a complicated series of BIOS functions that you can run to almost always determine the boot hardware. Otherwise, you are stuck using BIOS disk reading functions, and comparing the output to reading each device with your own drivers.
Alternately, it is possible to make/use a pmode bootloader that ignores the BIOS' choice for the boot disk, and selects a "new" boot disk itself. A pmode bootloader will know precisely which driver, on which subsystem, were selected for the boot disk -- and will have some format for passing that information on to the kernel.
But no matter what, you cannot determine the boot disk by scanning PCI.
If you let the BIOS choose the boot disk, then the answer is that there is no good answer. Deciding which disk is the BIOS boot disk is one of the most difficult tasks faced by a kernel during boot phase. Dex says that there is a complicated series of BIOS functions that you can run to almost always determine the boot hardware. Otherwise, you are stuck using BIOS disk reading functions, and comparing the output to reading each device with your own drivers.
Alternately, it is possible to make/use a pmode bootloader that ignores the BIOS' choice for the boot disk, and selects a "new" boot disk itself. A pmode bootloader will know precisely which driver, on which subsystem, were selected for the boot disk -- and will have some format for passing that information on to the kernel.
But no matter what, you cannot determine the boot disk by scanning PCI.
Re: Detecting Boot Drive while scanning PCI devices
Some EDD structures hold port numbers and other useful info.
>>
>>
If you have seen bad English in my words, tell me what's wrong, please.
Re: Detecting Boot Drive while scanning PCI devices
Hi,
If that fails (e.g. "Device Path information" not supported) you have to use guess-work. For example, you could use IBM/MS INT 13 Extensions - GET DRIVE PARAMETERS (and if that isn't supported, use the much older GET DRIVE PARAMETERS function instead) and then search for a disk drive that most closely matches the (total cylinders, heads, sectors) information you have, and hope there isn't 2 or more drives with similar information. You could/should also check to see if the drive contains your OS's boot code (or not).
Also, in case someone has 2 copies of your OS's boot code in different partitions on the same drive; you'd need to pass something (e.g. "LBA of the first sector of something") from the boot code to the rest of the OS. This means that for worst case (lots of drives with similar information, and no "Device Path information") you'd need to check one sector on every drive to see if it matches.
Of course it's still not fool-proof. For example, the computer I'm using now has 2 identical disk drives that are setup for "software RAID1" (without the "Device Path information" you wouldn't be able to determine which is the boot drive and which is the copy). Even if your OS supports software RAID, something like full disk imaging (used by some people for backing up whole disk drives) could make a mess of it.
Cheers,
Brendan
The only reliable way is to use IBM/MS INT 13 Extensions - GET DRIVE PARAMETERS. If the "Device Path information" is supported, you can use that (for a PCI controller) to find the controller's "bus:device:function", and which device on that controller the drive is.PaoloR wrote:So the question is: how do you use information from BIOS to detect the boot drive via PCI????
If that fails (e.g. "Device Path information" not supported) you have to use guess-work. For example, you could use IBM/MS INT 13 Extensions - GET DRIVE PARAMETERS (and if that isn't supported, use the much older GET DRIVE PARAMETERS function instead) and then search for a disk drive that most closely matches the (total cylinders, heads, sectors) information you have, and hope there isn't 2 or more drives with similar information. You could/should also check to see if the drive contains your OS's boot code (or not).
Also, in case someone has 2 copies of your OS's boot code in different partitions on the same drive; you'd need to pass something (e.g. "LBA of the first sector of something") from the boot code to the rest of the OS. This means that for worst case (lots of drives with similar information, and no "Device Path information") you'd need to check one sector on every drive to see if it matches.
Of course it's still not fool-proof. For example, the computer I'm using now has 2 identical disk drives that are setup for "software RAID1" (without the "Device Path information" you wouldn't be able to determine which is the boot drive and which is the copy). Even if your OS supports software RAID, something like full disk imaging (used by some people for backing up whole disk drives) could make a mess of it.
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.
Re: Detecting Boot Drive while scanning PCI devices
Thanks for the competent and right to the point answers. I will give it a try using the BIOS extensions
and I will let you know how it works.
However do not hold your breath. My experience is 100% z/OS (IBM Mainframe) and learning the x86 architecture
is like culture shock. So it will take some time.
and I will let you know how it works.
However do not hold your breath. My experience is 100% z/OS (IBM Mainframe) and learning the x86 architecture
is like culture shock. So it will take some time.
Re: Detecting Boot Drive while scanning PCI devices
Brendan:
I added some code to the master boot code to use INT_13 function 48. I tried first on BOCHS and it works fine giving me the information path (it happens to be ISA bus since I have not been able to use PCI on BOCHS yet, but that is another story).
I also tried on a DELL PowerEdge T300 with two disks. No information path here, but as expected a pointer to EDD DPTE. The first two fields in the DPTE are the I/O port base address and control port address.
Do you happen to know if these ports are unique or they are shared by more than one disk (e.g. when sharing the same controller). There is no information in the DPTE of any "disk number". So I assume they are unique. Still I would rather ask first, before going on wild goose chase.
If they are unique, it should be possible to use them to identify the boot disk while scanning the PCI devices, since the same information is available via PCI device query (unless I am totally confused).
Thanks in advance..... PaoloR
I added some code to the master boot code to use INT_13 function 48. I tried first on BOCHS and it works fine giving me the information path (it happens to be ISA bus since I have not been able to use PCI on BOCHS yet, but that is another story).
I also tried on a DELL PowerEdge T300 with two disks. No information path here, but as expected a pointer to EDD DPTE. The first two fields in the DPTE are the I/O port base address and control port address.
Do you happen to know if these ports are unique or they are shared by more than one disk (e.g. when sharing the same controller). There is no information in the DPTE of any "disk number". So I assume they are unique. Still I would rather ask first, before going on wild goose chase.
If they are unique, it should be possible to use them to identify the boot disk while scanning the PCI devices, since the same information is available via PCI device query (unless I am totally confused).
Thanks in advance..... PaoloR
Re: Detecting Boot Drive while scanning PCI devices
They are unique for the channel.
If you have seen bad English in my words, tell me what's wrong, please.
Re: Detecting Boot Drive while scanning PCI devices
But the channel has *two* disks on it.