]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuDxe.c
UefiCpuPkg/CpuDxe: Add no-op InitializeMpSupport
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuDxe.c
index c5f3bb76f4a0bc2c21ad7bce8fd60e4c61e9a27e..c9df4e146ac37d9c1424e7a7e4becdb9381bc01a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU DXE Module.\r
 \r
-  Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 **/\r
 \r
 #include "CpuDxe.h"\r
+#include "CpuMp.h"\r
 \r
 //\r
 // Global Variables\r
 //\r
-IA32_IDT_GATE_DESCRIPTOR  gIdtTable[INTERRUPT_VECTOR_NUMBER] = { 0 };\r
-\r
-EFI_CPU_INTERRUPT_HANDLER ExternalVectorTable[0x100];\r
 BOOLEAN                   InterruptState = FALSE;\r
 EFI_HANDLE                mCpuHandle = NULL;\r
 BOOLEAN                   mIsFlushingGCD;\r
-UINT8                     mDefaultMemoryType    = MTRR_CACHE_WRITE_BACK;\r
 UINT64                    mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;\r
 UINT64                    mValidMtrrBitsMask    = MTRR_LIB_MSR_VALID_MASK;\r
 \r
@@ -99,259 +96,10 @@ EFI_CPU_ARCH_PROTOCOL  gCpu = {
   4                           // DmaBufferAlignment\r
 };\r
 \r
-//\r
-// Error code flag indicating whether or not an error code will be\r
-// pushed on the stack if an exception occurs.\r
-//\r
-// 1 means an error code will be pushed, otherwise 0\r
-//\r
-// bit 0 - exception 0\r
-// bit 1 - exception 1\r
-// etc.\r
-//\r
-UINT32 mErrorCodeFlag = 0x00027d00;\r
-\r
-//\r
-// Local function prototypes\r
-//\r
-\r
-/**\r
-  Set Interrupt Descriptor Table Handler Address.\r
-\r
-  @param Index        The Index of the interrupt descriptor table handle.\r
-  @param Handler      Handler address.\r
-\r
-**/\r
-VOID\r
-SetInterruptDescriptorTableHandlerAddress (\r
-  IN UINTN Index,\r
-  IN VOID  *Handler  OPTIONAL\r
-  );\r
-\r
 //\r
 // CPU Arch Protocol Functions\r
 //\r
 \r
-\r
-/**\r
-  Common exception handler.\r
-\r
-  @param  InterruptType  Exception type\r
-  @param  SystemContext  EFI_SYSTEM_CONTEXT\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-CommonExceptionHandler (\r
-  IN EFI_EXCEPTION_TYPE   InterruptType,\r
-  IN EFI_SYSTEM_CONTEXT   SystemContext\r
-  )\r
-{\r
-#if defined (MDE_CPU_IA32)\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "!!!! IA32 Exception Type - %08x !!!!\n",\r
-    InterruptType\r
-    ));\r
-  if ((mErrorCodeFlag & (1 << InterruptType)) != 0) {\r
-    DEBUG ((\r
-      EFI_D_ERROR,\r
-      "ExceptionData - %08x\n",\r
-      SystemContext.SystemContextIa32->ExceptionData\r
-      ));\r
-  }\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "CS  - %04x,     EIP - %08x, EFL - %08x, SS  - %04x\n",\r
-    SystemContext.SystemContextIa32->Cs,\r
-    SystemContext.SystemContextIa32->Eip,\r
-    SystemContext.SystemContextIa32->Eflags,\r
-    SystemContext.SystemContextIa32->Ss\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "DS  - %04x,     ES  - %04x,     FS  - %04x,     GS  - %04x\n",\r
-    SystemContext.SystemContextIa32->Ds,\r
-    SystemContext.SystemContextIa32->Es,\r
-    SystemContext.SystemContextIa32->Fs,\r
-    SystemContext.SystemContextIa32->Gs\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "EAX - %08x, EBX - %08x, ECX - %08x, EDX - %08x\n",\r
-    SystemContext.SystemContextIa32->Eax,\r
-    SystemContext.SystemContextIa32->Ebx,\r
-    SystemContext.SystemContextIa32->Ecx,\r
-    SystemContext.SystemContextIa32->Edx\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x\n",\r
-    SystemContext.SystemContextIa32->Esp,\r
-    SystemContext.SystemContextIa32->Ebp,\r
-    SystemContext.SystemContextIa32->Esi,\r
-    SystemContext.SystemContextIa32->Edi\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "GDT - %08x  LIM - %04x,     IDT - %08x  LIM - %04x\n",\r
-    SystemContext.SystemContextIa32->Gdtr[0],\r
-    SystemContext.SystemContextIa32->Gdtr[1],\r
-    SystemContext.SystemContextIa32->Idtr[0],\r
-    SystemContext.SystemContextIa32->Idtr[1]\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "LDT - %08x, TR  - %08x\n",\r
-    SystemContext.SystemContextIa32->Ldtr,\r
-    SystemContext.SystemContextIa32->Tr\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x\n",\r
-    SystemContext.SystemContextIa32->Cr0,\r
-    SystemContext.SystemContextIa32->Cr2,\r
-    SystemContext.SystemContextIa32->Cr3,\r
-    SystemContext.SystemContextIa32->Cr4\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x\n",\r
-    SystemContext.SystemContextIa32->Dr0,\r
-    SystemContext.SystemContextIa32->Dr1,\r
-    SystemContext.SystemContextIa32->Dr2,\r
-    SystemContext.SystemContextIa32->Dr3\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "DR6 - %08x, DR7 - %08x\n",\r
-    SystemContext.SystemContextIa32->Dr6,\r
-    SystemContext.SystemContextIa32->Dr7\r
-    ));\r
-#elif defined (MDE_CPU_X64)\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "!!!! X64 Exception Type - %016lx !!!!\n",\r
-    (UINT64)InterruptType\r
-    ));\r
-  if ((mErrorCodeFlag & (1 << InterruptType)) != 0) {\r
-    DEBUG ((\r
-      EFI_D_ERROR,\r
-      "ExceptionData - %016lx\n",\r
-      SystemContext.SystemContextX64->ExceptionData\r
-      ));\r
-  }\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "RIP - %016lx, RFL - %016lx\n",\r
-    SystemContext.SystemContextX64->Rip,\r
-    SystemContext.SystemContextX64->Rflags\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "RAX - %016lx, RCX - %016lx, RDX - %016lx\n",\r
-    SystemContext.SystemContextX64->Rax,\r
-    SystemContext.SystemContextX64->Rcx,\r
-    SystemContext.SystemContextX64->Rdx\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "RBX - %016lx, RSP - %016lx, RBP - %016lx\n",\r
-    SystemContext.SystemContextX64->Rbx,\r
-    SystemContext.SystemContextX64->Rsp,\r
-    SystemContext.SystemContextX64->Rbp\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "RSI - %016lx, RDI - %016lx\n",\r
-    SystemContext.SystemContextX64->Rsi,\r
-    SystemContext.SystemContextX64->Rdi\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "R8  - %016lx, R9  - %016lx, R10 - %016lx\n",\r
-    SystemContext.SystemContextX64->R8,\r
-    SystemContext.SystemContextX64->R9,\r
-    SystemContext.SystemContextX64->R10\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "R11 - %016lx, R12 - %016lx, R13 - %016lx\n",\r
-    SystemContext.SystemContextX64->R11,\r
-    SystemContext.SystemContextX64->R12,\r
-    SystemContext.SystemContextX64->R13\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "R14 - %016lx, R15 - %016lx\n",\r
-    SystemContext.SystemContextX64->R14,\r
-    SystemContext.SystemContextX64->R15\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "CS  - %04lx, DS  - %04lx, ES  - %04lx, FS  - %04lx, GS  - %04lx, SS  - %04lx\n",\r
-    SystemContext.SystemContextX64->Cs,\r
-    SystemContext.SystemContextX64->Ds,\r
-    SystemContext.SystemContextX64->Es,\r
-    SystemContext.SystemContextX64->Fs,\r
-    SystemContext.SystemContextX64->Gs,\r
-    SystemContext.SystemContextX64->Ss\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "GDT - %016lx; %04lx,                   IDT - %016lx; %04lx\n",\r
-    SystemContext.SystemContextX64->Gdtr[0],\r
-    SystemContext.SystemContextX64->Gdtr[1],\r
-    SystemContext.SystemContextX64->Idtr[0],\r
-    SystemContext.SystemContextX64->Idtr[1]\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "LDT - %016lx, TR  - %016lx\n",\r
-    SystemContext.SystemContextX64->Ldtr,\r
-    SystemContext.SystemContextX64->Tr\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "CR0 - %016lx, CR2 - %016lx, CR3 - %016lx\n",\r
-    SystemContext.SystemContextX64->Cr0,\r
-    SystemContext.SystemContextX64->Cr2,\r
-    SystemContext.SystemContextX64->Cr3\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "CR4 - %016lx, CR8 - %016lx\n",\r
-    SystemContext.SystemContextX64->Cr4,\r
-    SystemContext.SystemContextX64->Cr8\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "DR0 - %016lx, DR1 - %016lx, DR2 - %016lx\n",\r
-    SystemContext.SystemContextX64->Dr0,\r
-    SystemContext.SystemContextX64->Dr1,\r
-    SystemContext.SystemContextX64->Dr2\r
-    ));\r
-  DEBUG ((\r
-    EFI_D_ERROR,\r
-    "DR3 - %016lx, DR6 - %016lx, DR7 - %016lx\n",\r
-    SystemContext.SystemContextX64->Dr3,\r
-    SystemContext.SystemContextX64->Dr6,\r
-    SystemContext.SystemContextX64->Dr7\r
-    ));\r
-#else\r
-#error CPU type not supported for exception information dump!\r
-#endif\r
-\r
-  //\r
-  // Hang the system with CpuSleep so the processor will enter a lower power\r
-  // state.\r
-  //\r
-  while (TRUE) {\r
-    CpuSleep ();\r
-  };\r
-}\r
-\r
-\r
 /**\r
   Flush CPU data cache. If the instruction cache is fully coherent\r
   with all DMA operations then function can just return EFI_SUCCESS.\r
@@ -509,21 +257,7 @@ CpuRegisterInterruptHandler (
   IN EFI_CPU_INTERRUPT_HANDLER     InterruptHandler\r
   )\r
 {\r
-  if (InterruptType < 0 || InterruptType > 0xff) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  if (InterruptHandler == NULL && ExternalVectorTable[InterruptType] == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (InterruptHandler != NULL && ExternalVectorTable[InterruptType] != NULL) {\r
-    return EFI_ALREADY_STARTED;\r
-  }\r
-\r
-  SetInterruptDescriptorTableHandlerAddress ((UINTN)InterruptType, NULL);\r
-  ExternalVectorTable[InterruptType] = InterruptHandler;\r
-  return EFI_SUCCESS;\r
+  return RegisterCpuInterruptHandler (InterruptType, InterruptHandler);\r
 }\r
 \r
 \r
@@ -581,19 +315,28 @@ CpuGetTimerValue (
 \r
 \r
 /**\r
-  Set memory cacheability attributes for given range of memeory.\r
-\r
-  @param  This                   Protocol instance structure\r
-  @param  BaseAddress            Specifies the start address of the\r
-                                 memory range\r
-  @param  Length                 Specifies the length of the memory range\r
-  @param  Attributes             The memory cacheability for the memory range\r
-\r
-  @retval EFI_SUCCESS            If the cacheability of that memory range is\r
-                                 set successfully\r
-  @retval EFI_UNSUPPORTED        If the desired operation cannot be done\r
-  @retval EFI_INVALID_PARAMETER  The input parameter is not correct,\r
-                                 such as Length = 0\r
+  Implementation of SetMemoryAttributes() service of CPU Architecture Protocol.\r
+\r
+  This function modifies the attributes for the memory region specified by BaseAddress and\r
+  Length from their current attributes to the attributes specified by Attributes.\r
+\r
+  @param  This             The EFI_CPU_ARCH_PROTOCOL instance.\r
+  @param  BaseAddress      The physical address that is the start address of a memory region.\r
+  @param  Length           The size in bytes of the memory region.\r
+  @param  Attributes       The bit mask of attributes to set for the memory region.\r
+\r
+  @retval EFI_SUCCESS           The attributes were set for the memory region.\r
+  @retval EFI_ACCESS_DENIED     The attributes for the memory resource range specified by\r
+                                BaseAddress and Length cannot be modified.\r
+  @retval EFI_INVALID_PARAMETER Length is zero.\r
+                                Attributes specified an illegal combination of attributes that\r
+                                cannot be set together.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough system resources to modify the attributes of\r
+                                the memory resource range.\r
+  @retval EFI_UNSUPPORTED       The processor does not support one or more bytes of the memory\r
+                                resource range specified by BaseAddress and Length.\r
+                                The bit mask of attributes is not support for the memory resource\r
+                                range specified by BaseAddress and Length.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -612,8 +355,6 @@ CpuSetMemoryAttributes (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  DEBUG((EFI_D_ERROR, "CpuAp: SetMemorySpaceAttributes(BA=%08x, Len=%08x, Attr=%08x)\n", BaseAddress, Length, Attributes));\r
-\r
   //\r
   // If this function is called because GCD SetMemorySpaceAttributes () is called\r
   // by RefreshGcdMemoryAttributes (), then we are just synchronzing GCD memory\r
@@ -621,9 +362,9 @@ CpuSetMemoryAttributes (
   // to avoid unnecessary computing.\r
   //\r
   if (mIsFlushingGCD) {\r
-    DEBUG((EFI_D_ERROR, "  Flushing GCD\n"));\r
-      return EFI_SUCCESS;\r
-    }\r
+    DEBUG((EFI_D_INFO, "  Flushing GCD\n"));\r
+    return EFI_SUCCESS;\r
+  }\r
 \r
   switch (Attributes) {\r
   case EFI_MEMORY_UC:\r
@@ -646,21 +387,24 @@ CpuSetMemoryAttributes (
     CacheType = CacheWriteBack;\r
     break;\r
 \r
-  default:\r
+  case EFI_MEMORY_UCE:\r
+  case EFI_MEMORY_RP:\r
+  case EFI_MEMORY_XP:\r
+  case EFI_MEMORY_RUNTIME:\r
     return EFI_UNSUPPORTED;\r
+\r
+  default:\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
   //\r
   // call MTRR libary function\r
   //\r
-  DEBUG((EFI_D_ERROR, "  MtrrSetMemoryAttribute()\n"));\r
-  Status = MtrrSetMemoryAttribute(\r
+  Status = MtrrSetMemoryAttribute (\r
              BaseAddress,\r
              Length,\r
              CacheType\r
              );\r
 \r
-  MtrrDebugPrintAllMtrrs ();\r
-\r
   return (EFI_STATUS) Status;\r
 }\r
 \r
@@ -877,6 +621,7 @@ RefreshGcdMemoryAttributes (
   VARIABLE_MTRR                       VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
   MTRR_FIXED_SETTINGS                 MtrrFixedSettings;\r
   UINT32                              FirmwareVariableMtrrCount;\r
+  UINT8                               DefaultMemoryType;\r
 \r
   if (!IsMtrrSupported ()) {\r
     return;\r
@@ -885,8 +630,7 @@ RefreshGcdMemoryAttributes (
   FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
   ASSERT (FirmwareVariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
 \r
-//  mIsFlushingGCD = TRUE;\r
-  mIsFlushingGCD = FALSE;\r
+  mIsFlushingGCD = TRUE;\r
   MemorySpaceMap = NULL;\r
 \r
   //\r
@@ -912,7 +656,8 @@ RefreshGcdMemoryAttributes (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (mDefaultMemoryType);\r
+  DefaultMemoryType = (UINT8) MtrrGetDefaultMemoryType ();\r
+  DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (DefaultMemoryType);\r
 \r
   //\r
   // Set default attributes to all spaces.\r
@@ -944,12 +689,14 @@ RefreshGcdMemoryAttributes (
         );\r
     }\r
   }\r
+\r
   //\r
-  // Go for variable MTRRs with Non-WB attribute\r
+  // Go for variable MTRRs with the attribute except for WB and UC attributes\r
   //\r
   for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
     if (VariableMtrr[Index].Valid &&\r
-        VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK) {\r
+        VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK &&\r
+        VariableMtrr[Index].Type != MTRR_CACHE_UNCACHEABLE) {\r
       Attributes = GetMemorySpaceAttributeFromMtrrType ((UINT8) VariableMtrr[Index].Type);\r
       SetGcdMemorySpaceAttributes (\r
         MemorySpaceMap,\r
@@ -961,6 +708,22 @@ RefreshGcdMemoryAttributes (
     }\r
   }\r
 \r
+  //\r
+  // Go for variable MTRRs with UC attribute\r
+  //\r
+  for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
+    if (VariableMtrr[Index].Valid &&\r
+        VariableMtrr[Index].Type == MTRR_CACHE_UNCACHEABLE) {\r
+      SetGcdMemorySpaceAttributes (\r
+        MemorySpaceMap,\r
+        NumberOfDescriptors,\r
+        VariableMtrr[Index].BaseAddress,\r
+        VariableMtrr[Index].Length,\r
+        EFI_MEMORY_UC\r
+        );\r
+    }\r
+  }\r
+\r
   //\r
   // Go for fixed MTRRs\r
   //\r
@@ -1023,124 +786,44 @@ RefreshGcdMemoryAttributes (
 }\r
 \r
 /**\r
-  Set Interrupt Descriptor Table Handler Address.\r
-\r
-  @param Index        The Index of the interrupt descriptor table handle.\r
-  @param Handler      Handler address.\r
+  Initialize Interrupt Descriptor Table for interrupt handling.\r
 \r
 **/\r
 VOID\r
-SetInterruptDescriptorTableHandlerAddress (\r
-  IN UINTN Index,\r
-  IN VOID  *Handler  OPTIONAL\r
+InitInterruptDescriptorTable (\r
+  VOID\r
   )\r
 {\r
-  UINTN                     UintnHandler;\r
-\r
-  if (Handler != NULL) {\r
-    UintnHandler = (UINTN) Handler;\r
-  } else {\r
-    UintnHandler = ((UINTN) AsmIdtVector00) + (8 * Index);\r
+  EFI_STATUS                     Status;\r
+  EFI_VECTOR_HANDOFF_INFO        *VectorInfoList;\r
+  EFI_VECTOR_HANDOFF_INFO        *VectorInfo;\r
+\r
+  VectorInfo = NULL;\r
+  Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **) &VectorInfoList);\r
+  if (Status == EFI_SUCCESS && VectorInfoList != NULL) {\r
+    VectorInfo = VectorInfoList;\r
   }\r
-\r
-  gIdtTable[Index].Bits.OffsetLow   = (UINT16)UintnHandler;\r
-  gIdtTable[Index].Bits.Reserved_0  = 0;\r
-  gIdtTable[Index].Bits.GateType    = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
-  gIdtTable[Index].Bits.OffsetHigh  = (UINT16)(UintnHandler >> 16);\r
-#if defined (MDE_CPU_X64)\r
-  gIdtTable[Index].Bits.OffsetUpper = (UINT32)(UintnHandler >> 32);\r
-  gIdtTable[Index].Bits.Reserved_1  = 0;\r
-#endif\r
+  Status = InitializeCpuInterruptHandlers (VectorInfo);\r
+  ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
 \r
 /**\r
-  Initialize Interrupt Descriptor Table for interrupt handling.\r
+  Callback function for idle events.\r
+\r
+  @param  Event                 Event whose notification function is being invoked.\r
+  @param  Context               The pointer to the notification function's context,\r
+                                which is implementation-dependent.\r
 \r
 **/\r
 VOID\r
-InitInterruptDescriptorTable (\r
-  VOID\r
+EFIAPI\r
+IdleLoopEventCallback (\r
+  IN EFI_EVENT                Event,\r
+  IN VOID                     *Context\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  IA32_DESCRIPTOR           OldIdtPtr;\r
-  IA32_IDT_GATE_DESCRIPTOR  *OldIdt;\r
-  UINTN                     OldIdtSize;\r
-  VOID                      *IdtPtrAlignmentBuffer;\r
-  IA32_DESCRIPTOR           *IdtPtr;\r
-  UINTN                     Index;\r
-  UINT16                    CurrentCs;\r
-  VOID                      *IntHandler;\r
-\r
-  SetMem (ExternalVectorTable, sizeof(ExternalVectorTable), 0);\r
-\r
-  //\r
-  // Get original IDT address and size.\r
-  //\r
-  AsmReadIdtr ((IA32_DESCRIPTOR *) &OldIdtPtr);\r
-\r
-  if ((OldIdtPtr.Base != 0) && ((OldIdtPtr.Limit & 7) == 7)) {\r
-    OldIdt = (IA32_IDT_GATE_DESCRIPTOR*) OldIdtPtr.Base;\r
-    OldIdtSize = (OldIdtPtr.Limit + 1) / 8;\r
-  } else {\r
-    OldIdt = NULL;\r
-    OldIdtSize = 0;\r
-  }\r
-\r
-  //\r
-  // Intialize IDT\r
-  //\r
-  CurrentCs = AsmReadCs();\r
-  for (Index = 0; Index < INTERRUPT_VECTOR_NUMBER; Index ++) {\r
-    //\r
-    // If the old IDT had a handler for this interrupt, then\r
-    // preserve it.\r
-    //\r
-    if (Index < OldIdtSize) {\r
-      IntHandler = \r
-        (VOID*) (\r
-          OldIdt[Index].Bits.OffsetLow +\r
-          (OldIdt[Index].Bits.OffsetHigh << 16)\r
-#if defined (MDE_CPU_X64)\r
-            + (((UINTN) OldIdt[Index].Bits.OffsetUpper) << 32)\r
-#endif\r
-          );\r
-    } else {\r
-      IntHandler = NULL;\r
-    }\r
-\r
-    gIdtTable[Index].Bits.Selector    = CurrentCs;\r
-    gIdtTable[Index].Bits.Reserved_0  = 0;\r
-    gIdtTable[Index].Bits.GateType    = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
-    SetInterruptDescriptorTableHandlerAddress (Index, IntHandler);\r
-  }\r
-\r
-  //\r
-  // Load IDT Pointer\r
-  //\r
-  IdtPtrAlignmentBuffer = AllocatePool (sizeof (*IdtPtr) + 16);\r
-  IdtPtr = ALIGN_POINTER (IdtPtrAlignmentBuffer, 16);\r
-  IdtPtr->Base = (UINT32)(((UINTN)(VOID*) gIdtTable) & (BASE_4GB-1));\r
-  IdtPtr->Limit = (UINT16) (sizeof (gIdtTable) - 1);\r
-\r
-  AsmWriteIdtr (IdtPtr);\r
-\r
-  FreePool (IdtPtrAlignmentBuffer);\r
-\r
-  //\r
-  // Initialize Exception Handlers\r
-  //\r
-  for (Index = 0; Index < 32; Index++) {\r
-    Status = CpuRegisterInterruptHandler (&gCpu, Index, CommonExceptionHandler);\r
-    ASSERT_EFI_ERROR (Status);\r
-  }\r
-\r
-  //\r
-  // Set the pointer to the array of C based exception handling routines.\r
-  //\r
-  InitializeExternalVectorTablePtr (ExternalVectorTable);\r
-\r
+  CpuSleep ();\r
 }\r
 \r
 \r
@@ -1163,6 +846,9 @@ InitializeCpu (
   )\r
 {\r
   EFI_STATUS  Status;\r
+  EFI_EVENT   IdleLoopEvent;\r
+\r
+  InitializeFloatingPointUnits ();\r
 \r
   //\r
   // Make sure interrupts are disabled\r
@@ -1179,6 +865,11 @@ InitializeCpu (
   //\r
   InitInterruptDescriptorTable ();\r
 \r
+  //\r
+  // Enable the local APIC for Virtual Wire Mode.\r
+  //\r
+  ProgramVirtualWireMode ();\r
+\r
   //\r
   // Install CPU Architectural Protocol\r
   //\r
@@ -1194,6 +885,21 @@ InitializeCpu (
   //\r
   RefreshGcdMemoryAttributes ();\r
 \r
+  //\r
+  // Setup a callback for idle events\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  IdleLoopEventCallback,\r
+                  NULL,\r
+                  &gIdleLoopEventGuid,\r
+                  &IdleLoopEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  InitializeMpSupport ();\r
+\r
   return Status;\r
 }\r
 \r