Registers of PCI config space seem to be corrupted in Qemu

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
Armin
Posts: 10
Joined: Sun Nov 22, 2009 6:16 am

Registers of PCI config space seem to be corrupted in Qemu

Post by Armin »

Hello,

I don't know if "corrupted" is the proper word but nevertheless I got a curious problem while reading registers of the PCI configuration space in Qemu:
Compared to to what I get when I execute the same code in Bochs, it seems that the register values of PCI config space lack of the last byte when executed in Qemu.

Here is a short example:
In my PCI startup code I enumerate the PCI bus to determine the base/sub class of each PCI device. Therefore I read the register at offset 0x08 of each device (e.g. Host-PCI Bridge or PCI-ISA Bridge) and the content differs like the following:

Host-PCI Bridge
Bochs: I got a value like 0x6010000
Qemu: the value of the register is 0x60100

PCI-ISA Bridge
Bochs: I got a value like 0x6000000
Qemu: the value of the register is 0x60000

In both cases only Bochs provides register values that seem to be reasonably. As written before, when run in Qemu, it seems that the registers lack of one bte.

Does anyone have an idee or know what's the difference between Bochs and Qemu?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Registers of PCI config space seem to be corrupted in Qemu

Post by Combuster »

There is no obvious difference in class codes between Bochs and QEmu - in fact in both cases I get correct data returned.

What can matter is how hardware responds to various sized reads - You should always read doublewords and then perform the shifts manually. QEmu is known to differ from real hardware in this respect.

how it should be done
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Armin
Posts: 10
Joined: Sun Nov 22, 2009 6:16 am

Re: Registers of PCI config space seem to be corrupted in Qemu

Post by Armin »

Thank you very much!

Finally, when I read the link "how it should be done", I saw that I specified the wrong address type (bit 0 and 1) while assembling the pci configuration space address.

Cheers!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Registers of PCI config space seem to be corrupted in Qemu

Post by Combuster »

Glad it helped, even after all this time
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply