If you're working with a built-in APIC, everything is actually very simple. All you need to do is to read a model-specific register which contains the APICBASE
. Here is a basic list of MSRs.
To read a MSR, use the rdmsr
instruction (privileged).
mov ecx, 0x1B ; ECX=register address
xor eax, eax ; value of unimplemented bits in MSR will turn undefined when moved to
xor edx, edx ; EDX:EAX, so I set everything to 0
rdmsr
; EDX:EAX now contains APICBASE
When speaking about the PIIX3 external APIC, from PIIX3 documentation:
APICBASE—APIC BASE ADDRESS RELOCATION REGISTER (Function 0)
Address Offset: 80h
Default Value: 00h
Attribute: Read/Write
This register provides the modifier for the APIC base address. APIC is
mapped in the memory space at the locations 0xFEC0xy00
and 0xFEC0xy10
(x=0-F
, y=0/4/8/C
). The value of y
is defined by bits [1,0] and
the value of x
is defined by bits [5:2]. Thus, the relocation
register provides 1-Kbyte address granularity (i.e., potentially up to
64 IOAPICs can be uniformly addresses in the memory space). The
default value of 00h provides mapping of the IOAPIC unit at the
addresses 0xFEC00000
and 0xFEC00010
.
A look on a driver actually interfacing PCI for this kind of data may be helpful.
Many of sources I've come through on internet used fixed 0xFEC00000
and didn't care about possibility of it being different. But as PIIX3 documentation says, 0xFEC00000
is guaranteed default value and you don't have to think about it further.