/* In xAPIC mode, the initial local APIC ID may be different from current APIC ID. In x2APIC mode, the local APIC ID can't be changed and there is no concept of initial APIC ID. In this case, the 32-bit local APIC ID is returned as initial APIC ID. */
UINT32 EFIAPI GetInitialApicId(VOID)
/* In xAPIC mode, the initial local APIC ID may be different from current APIC ID. In x2APIC mode, the local APIC ID can't be changed and there is no concept of initial APIC ID. In this case, the 32-bit local APIC ID is returned as initial APIC ID. */
UINT32 EFIAPI GetInitialApicId(VOID)
{
  UINT32  ApicId;
  UINT32  MaxCpuIdIndex;
  UINT32  RegEbx;
  if (GetApicMode () == LOCAL_APIC_MODE_XAPIC) {
    AsmCpuid (CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL);
    if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) {
      AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, 0, NULL, &RegEbx, NULL, &ApicId);
      if ((RegEbx & (BIT16 - 1)) != 0) {
        return ApicId;
      }
    }
    AsmCpuid (CPUID_VERSION_INFO, NULL, &RegEbx, NULL, NULL);
    return RegEbx >> 24;
  } else {
    return GetApicId ();
  }
}