Page 1 of 1
Enumerating PCI Devices
Posted: Sun Jun 13, 2010 11:50 pm
by Zerith
Hello, i'm trying to enumerate all class codes for existing pci devices.
All i seem to get are 4 devices whose class code is 0x00.. is this normal?
There's my code:
http://codepad.org/z05RIkvq
I'm running on bochs.
Re: Enumerating PCI Devices
Posted: Mon Jun 14, 2010 1:55 am
by Combuster
You are mixing up words (16 bits) and doublewords (32 bits) on many occasions. Fix that and you'll have a good chance to get rid of the spurious readings. If you end up getting no devices, you might need to enable PCI in the configuration.
Also, don't read functions beyond the first without checking they actually exist.
Re: Enumerating PCI Devices
Posted: Mon Jun 14, 2010 12:52 pm
by Zerith
Well i seem to have reduced the number of devices i find, but i still get 2 whose class code is 0x00.
http://pastebin.ca/1883085
And, if i do have to enable pci, how would i do that in bochs?
Re: Enumerating PCI Devices
Posted: Mon Jun 14, 2010 5:03 pm
by Combuster
There are still some doubleword-size issues (this time versus bytes) in place here. You pass offsets into byte-sized configuration space, while the code you grabbed off the internet treats offsets as entries into doubleword sized configuration space (which is how it works in reality). In the end you are not reading anything near the class code or header type. You may want to compare your version with
this.
As for the pci option, may I recommend reading
the manual first? (It's most likely on since you do seem to get the right number of devices given your current bug status)
Re: Enumerating PCI Devices
Posted: Tue Jun 15, 2010 5:36 am
by Zerith
Thank you very much for you help.
I seem to get 9 devices right now, 3 of which are "Bridge Devices" (according ot the Base Class code), 1 is a mass storage controller
and 5 are Class code 0xFF.
shouldn't i also be getting the Processor and several other devices?
http://codepad.org/hiKMbk5I
Re: Enumerating PCI Devices
Posted: Tue Jun 15, 2010 6:48 am
by Combuster
I see you copied random sources again (including mine) - It'd be best if learn to do your own debugging work instead of relying on copy-paste. Especially if you have to do the error-prone translation from language X to Y as well.
Also, why are you only interested in the class codes? The device-vendor pair is usually more interesting. (I only use the class codes to find out which PCI device maps to an ISA function - like whether the video card installed is PCI or ISA)
Also, PCI lists only the devices attached to the PCI bus. The link to the processor is there, only you fail to recognise it. (look up the various device IDs to find out).