]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
Store PeiServices** when updating IDT table in DxeIplPeim before transfer to long...
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / Ia32 / DxeLoadFunc.c
index 6898bd9c92a1a55189eaafb163513d411e0a99b2..b121e2439bb67e3547af74d1d07dec723b288722 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Ia32-specific functionality for DxeLoad.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, 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
@@ -17,6 +17,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define IDT_ENTRY_COUNT       32\r
 \r
+typedef struct _X64_IDT_TABLE {\r
+  //\r
+  // Reserved 4 bytes preceding PeiService and IdtTable,\r
+  // since IDT base address should be 8-byte alignment.\r
+  //\r
+  UINT32                   Reserved;\r
+  CONST EFI_PEI_SERVICES   **PeiService;\r
+  X64_IDT_GATE_DESCRIPTOR  IdtTable[IDT_ENTRY_COUNT];\r
+} X64_IDT_TABLE;\r
+\r
 //\r
 // Global Descriptor Table (GDT)\r
 //\r
@@ -72,6 +82,7 @@ HandOffToDxeCore (
   VOID                      *TemplateBase;\r
   EFI_PHYSICAL_ADDRESS      VectorAddress;\r
   UINT32                    Index;\r
+  X64_IDT_TABLE             *IdtTableForX64;\r
 \r
   Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);\r
   ASSERT_EFI_ERROR (Status);\r
@@ -120,12 +131,19 @@ HandOffToDxeCore (
 \r
     Status = PeiServicesAllocatePages (\r
                EfiBootServicesData,\r
-               EFI_SIZE_TO_PAGES((SizeOfTemplate + sizeof (X64_IDT_GATE_DESCRIPTOR)) * IDT_ENTRY_COUNT),\r
-               &VectorAddress\r
+               EFI_SIZE_TO_PAGES(sizeof (X64_IDT_TABLE) + SizeOfTemplate * IDT_ENTRY_COUNT),\r
+               (EFI_PHYSICAL_ADDRESS *) &IdtTableForX64\r
                );\r
     ASSERT_EFI_ERROR (Status);\r
 \r
-    IdtTable      = (X64_IDT_GATE_DESCRIPTOR *) (UINTN) (VectorAddress + SizeOfTemplate * IDT_ENTRY_COUNT);\r
+    //\r
+    // Store EFI_PEI_SERVICES** in the 4 bytes immediately preceding IDT to avoid that\r
+    // it may not be gotten correctly after IDT register is re-written.\r
+    //\r
+    IdtTableForX64->PeiService = GetPeiServicesTablePointer ();\r
+\r
+    VectorAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (IdtTableForX64 + 1);\r
+    IdtTable      = IdtTableForX64->IdtTable;\r
     for (Index = 0; Index < IDT_ENTRY_COUNT; Index++) {\r
       IdtTable[Index].Ia32IdtEntry.Bits.GateType    =  0x8e;\r
       IdtTable[Index].Ia32IdtEntry.Bits.Reserved_0  =  0;\r