Search code examples
assemblyx86intelpci

accessing pci configuration space in real mode


I'm trying to write assembly to access pci configuration space.

what I'm trying to do is basically what this article does.

https://sites.google.com/site/pinczakko/pinczakko-s-guide-to-award-bios-reverse-engineering

enter image description here

my question is, because I'm trying to do this in real mode, and pci configuration has to be accessed by 32 bits data... can I do this in real mode? the register like eax is accessible in real mode? or do I need to move to protected mode to do this?


Solution

  • pci configuration has to be accessed by 32 bits data... can I do this in real mode?

    Yes; "real mode" just means the default operand size is 16-bit, but you (the assembler) can change the default using a size override prefix.

    Of course this only works on 32-bit CPUs (80386 or later), but I doubt you'll care because computers that old won't support PCI anyway (but it's good practice to have an "does the CPU support 32 bit?" check to avoid crashing with no explanation on very old computers).

    For newer computers (with PCI express) "PCI config space" was increased to 4 KiB per function (from the original 256 bytes of PCI config space per function) and a new memory mapped PCI configuration space mechanism was added to make it much faster (without slow IO ports). You won't be able to use memory mapped PCI configuration space mechanism in real mode. Fortunately (for backward compatibility reasons); the old "IO ports" access mechanism is still supported (but only lets you access the first 256 bytes of each function's 4096 bytes) and the extra PCI configuration space for each function is mostly used by things that you won't be able to use anyway (e.g. message signaled interrupts, power management, ...).