2

I want to program the IO-APIC & Local-APIC in my loader code, the code runs after BIOS.

I've read the i82093AA datasheet, and found that the register base is defined by PIIX3's APICBASE register. How can I read the "PIIX3 APICBASE" register?

As I know IO-APIC register base is 0xFEC00000 by default, but the BIOS may change it. So I want to find a way to get the base correctly.

Gary Yin
  • 525
  • 6
  • 17

1 Answers1

3

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.

user35443
  • 6,309
  • 12
  • 52
  • 75
  • why not to use local APIC? I think IO- and Local- APICs both need to be programmed. – Gary Yin Jul 19 '14 at 03:08
  • I am using built-in APIC. I've read the Intel64 & IA-32 software developer's manual chapter 10, vol 3A. Most of the text talk about Local APIC, I can't find anything to show how to config the IO-APIC! Also, I can't find any IO-APIC related registers in the chapter. – Gary Yin Jul 19 '14 at 13:54
  • I think for a built-in APIC, the IO-APIC should be also built-in logically. Right? Is the IO-APIC in built-in APIC exact the same as i82093AA? – Gary Yin Jul 19 '14 at 13:57
  • From wikipedia: *There are two components in the Intel APIC system, the local APIC (LAPIC) and the I/O APIC. There is one LAPIC in each CPU in the system. In the very first implementation, the LAPIC was a discrete circuit, the 82489DX, but thereafter it was integrated in Intel processors. There is typically one I/O APIC for each peripheral bus in the system.* You program one or another. – user35443 Jul 19 '14 at 15:40