Page 1 of 1

Detecting Hardware?

Posted: Fri Nov 07, 2008 9:07 pm
by Sam111
So for the PCI I guess this is where it all starts
first location (0xCF8) is named CONFIG_ADDRESS, and the second (0xCFC) is called CONFIG_DATA. But is this for all computer's? Their must be something fixed for all computers otherwise you could never find anything.

say you wanted to write an OS that would run on different chipset's.

Their must be a fix in/out port or a standard way to find out what hardware you have and where the port's for these devices are.
Or are the ports for devices always located at the same address for all computers?

Where does the device probing all start? It has to be universal for all computers. #-o

Re: Detecting Hardware?

Posted: Sat Nov 08, 2008 3:22 am
by AJ
Hi,

Device probing and i/o will need to be in an architecture-specific part of your source tree. The correct objects to include in your kernel build can be selected based on environment variables (such as $TARGET).

If you are planning portability, keep the architecture-independent part of your code as generalised as possible and use the architecture-dependent part to create a uniform interface for the rest of the kernel.

Cheers,
Adam

Re: Detecting Hardware?

Posted: Sat Nov 08, 2008 1:08 pm
by Sam111
I was just wondering how a windows installl cd or linux live cd can be installed on different machines. So does computers of the same architecture always have the same pci ports addresses regardless of the chipset.

(0xCF8) is named CONFIG_ADDRESS, and the second (0xCFC) is called CONFIG_DATA.

Because how would you start to figure out where the start address is for device probing?

Do you first use cpuid and based on that have an if statment that uses the correct ports based on that.

Also what happens if it is an old computer that does'nt use pci?

Re: Detecting Hardware?

Posted: Sat Nov 08, 2008 1:22 pm
by bewing
There is a BIOS call that tells you whether PCI exists (and the number of busses). You have to start by making an assumption somewhere. An x86 PC architecture will have a BIOS and the PCI ports will always be where you say. (And the bootloader will load at a particular address, and ....) A Mac architecture will not have either one. (And will load completely differently.) You need to support them both separately, if you want to support both with one boot medium.

Re: Detecting Hardware?

Posted: Sat Nov 08, 2008 1:30 pm
by Sam111
Ok , But what about old computers that don't use or have pci.
Or does all computer's use it now.

I can use the bios to get pci info like (0xCF8) is named CONFIG_ADDRESS, and the second (0xCFC) is called CONFIG_DATA.

Thru the bios int 13 how would you get pci info?

And is int 13 always for bios's regardless of the architecture?

Because their has to be a starting address or procedure to detect hardware univeriseal.
Else live cd and windows cd could only target one specific chipsets and architecture's.
And you would need downloads for each architecture along with each chipset.
It is like the chick or the egg. IS their not something fix for all machines so you know where to start.

Re: Detecting Hardware?

Posted: Sat Nov 08, 2008 5:18 pm
by bewing
No, nothing is completely universal. At each stage you always have to test whether some function exists or not, before you use it. You achieve architecture/chipset/platform independence by doing a lot of tests, and avoiding the functions that do not work.

The BIOS function call for PCI info is INT 0x1A, AX=0xB101. But, of course, it may not work.

Re: Detecting Hardware?

Posted: Sat Nov 08, 2008 6:53 pm
by Sam111
So what is the best way to start testing.
By going to the BIOS/CMOS stuff or by doing in/out port pci port stuff.

Could it ever happen that the bios doesn't support the function and pci address (0xCF8)
Don't work.

Then what would you do?

And PowerPC do they have a BIOS or equivalent int 13?

Also for PC is the only architecture's PowerPC(AMD) and x86(intel ...etc i836 ...) .
I am just trying to find out the best procedure.

Re: Detecting Hardware?

Posted: Sat Nov 08, 2008 7:46 pm
by bewing
For an x86 machine, always start by getting BIOS info.

For any other type of machine, it's best to start in the wiki, and see what their boot procedure is. I do not know about PowerPC, but I do not think it has anything that resembles a BIOS.

On an x86 machine, if IO port 0xCF8 and IO port 0xCFC do not report PCI info, then there is no PCI bus on that system. So you set a flag that the PCI bus does not exist, and you move on.

Re: Detecting Hardware?

Posted: Sun Nov 09, 2008 4:08 am
by Sam111
It seems to me all computers are using pci now.

Anyway I am wondering what where all the possible types for any Personal computer ever.
I look thru the wiki and I get the impression their is only AGP/PCI , or ISA or USB
So you set a flag that the PCI bus does not exist, and you move on.
To what? After checking for devices on AGP/PCI , ISA , USB have you enumerated all the possible device's ?

Is x86, x86 64, power pc the only architecture for PC computers? If that's the case then you really only need to create 2 different probing programs to cover everything.

Re: Detecting Hardware?

Posted: Sun Nov 09, 2008 11:58 am
by quok
bewing wrote:For an x86 machine, always start by getting BIOS info.
I suppose that's pretty safe, but ultimately one must consider EFI as well. The EFI spec does allow for a firmware vendor to provide for 16 bit "compatibility" firmware for "legacy operating systems". That is, your traditional BIOS. However an EFI based machines does NOT have to provide this compatibility either. In my opinion it's best to abstract away the details somehow and provide just a single interface for your kernel to use. Or go the way I, and several others, are going; we use a 'boot stub' (could be a full boot loader or a grub stub kernel) that gathers the appropriate information and passes it to your kernel in a common format. At least in my project the kernel then is not bothered with having to do all that low level probing.
For any other type of machine, it's best to start in the wiki, and see what their boot procedure is. I do not know about PowerPC, but I do not think it has anything that resembles a BIOS.
Just about any kind of PowerPC machine you'll have access to (ie, old Apple hardware) uses OpenFirmware to boot. There's plenty of documents on that floating around the net. GRUB2 sources can handle booting from OF I believe, and there's the yaboot boot loader that is (was?) used by linux. I'm not entirely certain about big IBM Power Architecture machines since it's been many years since I've had access to one, but I believe those use OpenFirmware to boot as well. (And are, for the most part, pretty similar to PowerPC.)

Don't forget that qemu can emulate powerpc (as well as sparc, mips, arm, and many others). Together with projects like coreboot, you can test booting from EFI and OpenFirmware on qemu.