Finding Storage Devices

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
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Finding Storage Devices

Post by Masterkiller »

Is there a way that BIOS could give me information what storage devices are installed at boot time in the computer. The idea is to get all possible devices from where user can load files. It is 100% suer that there is boot device from where operationg system has started, but in my case it is a CD-ROM so it is read-only (or possible writing could damage CD :) ). It is not effective to assume that you HDD is on IDE drive and try IDE controller. I still can test one by one controllers to find where device, but what if you motherboard don't have an IDE controller and I test it? So is there a wayto find all storage devices installed with BIOS and if it is possible, what controller to use to access to the device?
User avatar
t6q4
Member
Member
Posts: 25
Joined: Thu Feb 14, 2008 3:56 pm

Post by t6q4 »

Well, there's the CMOS - theres a tutorial on how to use it to detect floppy drives on osdever.net - http://www.osdever.net/tutorials/detect ... drives.php

Hope it helped,
t6q4
Last edited by t6q4 on Fri Nov 07, 2008 1:48 pm, edited 1 time in total.
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: Finding Storage Devices

Post by Ready4Dis »

Masterkiller wrote:Is there a way that BIOS could give me information what storage devices are installed at boot time in the computer. The idea is to get all possible devices from where user can load files. It is 100% suer that there is boot device from where operationg system has started, but in my case it is a CD-ROM so it is read-only (or possible writing could damage CD :) ). It is not effective to assume that you HDD is on IDE drive and try IDE controller. I still can test one by one controllers to find where device, but what if you motherboard don't have an IDE controller and I test it? So is there a wayto find all storage devices installed with BIOS and if it is possible, what controller to use to access to the device?
A few things to do. On bootup, the bios will give you which device it booted from in dx. 0x80 is first hd, 0x81 is second hd, 0x01 is first floppy, etc. I don't know if there is a function to check installed devices without a driver, but you can use the info from DX with int 13h to load the OS from the boot device, which has drivers to determine other storage devices. This method works fine for just about anything. And of course, your boot code on your floppy disk will have code to read a floppy, while your boot code on a hdd will have code to read a hdd, etc. I don't do my device detection until after my OS is loaded (well, in the process of loading), even though my OS can boot from just about any boot media (including USB devives if supported by bios).
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Finding Storage Devices

Post by Dex »

Ready4Dis wrote: A few things to do. On bootup, the bios will give you which device it booted from in dx. 0x80 is first hd, 0x81 is second hd, 0x01 is first floppy, etc.
0x00 = first floppy
0x01 = second floppy
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Post by Masterkiller »

t6q4 wrote:Well, there's the CMOS - theres a tutorial on how to use it to detect floppy drives on osdever.net - http://www.osdever.net/tutorials/detect ... drives.php
Thanks a lot! :) There is a lot of useful information in CMOS I can use (and now I can display a clock on a screen :D )
Ready4Dis wrote:...to load the OS from the boot device, which has drivers to determine other storage devices...
That is a good point, but what if the OS still has no drivers loaded :) Well that was the point. I always could load drivers from CD (from where OS boots) but the idea is to know what drivers to load. IDE? SCSI? USB? Where you are planing to read/write when the system goes into protected mode and there is no BIOS? :)
Last edited by Masterkiller on Wed Jul 15, 2009 3:51 pm, edited 1 time in total.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

Masterkiller wrote:the idea is to know what drivers to load. IDE? SCSI? USB? Where you are planing to read/write when the system goes into protected mode and there is no BIOS?
You can use the PCI bus to enumerate all devices present. It will present you with a list of all devices, including the storage ones.


JAL
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
jal wrote:
Masterkiller wrote:the idea is to know what drivers to load. IDE? SCSI? USB? Where you are planing to read/write when the system goes into protected mode and there is no BIOS?
You can use the PCI bus to enumerate all devices present. It will present you with a list of all devices, including the storage ones.
You can scan the PCI bus and enumerate all PCI devices (which doesn't include ISA devices, like floppy).

Once you have detected all devices, you'll have no way to map between PCI devices and BIOS device numbers (except guessing). For example, the BIOS may tell you that your boot loader was started from device "0x00", which could be the first floppy, or could be the second floppy (with the "swap floppy drives" BIOS option enabled), or a CD-ROM, or a USB flash device, or a USB floppy drive, or some strange netboot/RAMdisk arrangement, or....

If it helps, I just use the BIOS (and the BIOS's drive numbers) to load everything I'll need into RAM while the BIOS is still usable; so that once I'm in protected mode I can "load" stuff from RAM instead of caring what the boot device was. ;)


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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
Brendan wrote:Once you have detected all devices, you'll have no way to map between PCI devices and BIOS device numbers (except guessing). For example, the BIOS may tell you that your boot loader was started from device "0x00", which could be the first floppy, or could be the second floppy (with the "swap floppy drives" BIOS option enabled), or a CD-ROM, or a USB flash device, or a USB floppy drive, or some strange netboot/RAMdisk arrangement, or....
My apologies - I think I'm wrong!

In the "Enhanced Disk Drive Specification", see section 5.8.1 (Interface Path) and section 5.8.2 (device path). They describe 2 of the fields in the data structure returned by a "Get drive parameters" function. It should be possible to use this (if supported) to correctly identify the actual device the BIOS used to load your boot loader from; including things like (where appropriate) the base I/O port, bus, device, function, interface type, master/slave, logical unit number, GUID, WWN, etc. :)

It's late at night here, so I'm printing the "Enhanced Disk Drive Specification" so I can actually read it properly tommorrow - I can't remember reading this specification before (not sure if this means I've never read any of it, or if I read parts of it ages ago and forgot)... :oops:


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.
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: Finding Storage Devices

Post by Ready4Dis »

Dex wrote:
Ready4Dis wrote: A few things to do. On bootup, the bios will give you which device it booted from in dx. 0x80 is first hd, 0x81 is second hd, 0x01 is first floppy, etc.
0x00 = first floppy
0x01 = second floppy
oops, that was a typo, you are correct.
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Post by Masterkiller »

Brendan wrote:In the "Enhanced Disk Drive Specification", see section 5.8.1 (Interface Path) and section 5.8.2 (device path). They describe 2 of the fields in the data structure returned by a "Get drive parameters" function. It should be possible to use this (if supported) to correctly identify the actual device the BIOS used to load your boot loader from; including things like (where appropriate) the base I/O port, bus, device, function, interface type, master/slave, logical unit number, GUID, WWN, etc. :)
Well, it seems that the BIOS comes in action again. So Ah=48h/INT 13h Get Drive Parametes BIOS extension (I'm absolutely sure that there will such function, because booting from CD requires these extension) check for the pointer to Enchanced Drive Parameters Structure. First word is the I/O address, second word is control address of the ports, so I don't have to know actually what interface use the "misterious" storage device, I just read/write to those ports. I am unsure about that :roll:
According to the Ralf Brawn Interrupt Table site there is version 3.0 that also displays ASCIZ name of interface type, but it seems my computer don't support it, neither is supported by MSVPC or Bochs.
Post Reply