]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
MdeModulePkg: Update PeiCore to pass XCODE tool chain
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dispatcher / Dispatcher.c
index e7e795d123d6caa9ff1881f00b99aa75c1dcaf4e..79f2e5cebcbeceed96c6e6e2bd515cf36706d403 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   EFI PEI Core dispatch services\r
   \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<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
@@ -14,11 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "PeiMain.h"\r
 \r
-///\r
-/// temporary memory is filled with this initial value during SEC phase\r
-///\r
-#define INIT_CAR_VALUE 0x5AA55AA5\r
-\r
 /**\r
 \r
   Discover all Peims and optional Apriori file in one FV. There is at most one\r
@@ -670,26 +666,39 @@ PeiCheckAndSwitchStack (
 \r
   if (Private->SwitchStackSignal) {\r
     //\r
-    // Before switch stack from temporary memory to permenent memory, calculate the heap and stack\r
-    // usage in temporary memory for debuging.\r
+    // Before switch stack from temporary memory to permanent memory, calculate the heap and stack\r
+    // usage in temporary memory for debugging.\r
     //\r
     DEBUG_CODE_BEGIN ();\r
-      UINT32  *StackPointer;\r
+      UINT32                *StackPointer;\r
+      EFI_PEI_HOB_POINTERS  Hob;\r
 \r
       for (StackPointer = (UINT32*)SecCoreData->StackBase;\r
            (StackPointer < (UINT32*)((UINTN)SecCoreData->StackBase + SecCoreData->StackSize)) \\r
-           && (*StackPointer == INIT_CAR_VALUE);\r
-           StackPointer ++);\r
-\r
-        DEBUG ((EFI_D_INFO, "Temp Stack : BaseAddress=0x%p Length=0x%X\n", SecCoreData->StackBase, (UINT32)SecCoreData->StackSize));\r
-        DEBUG ((EFI_D_INFO, "Temp Heap  : BaseAddress=0x%p Length=0x%X\n", Private->HobList.Raw, (UINT32)((UINTN) Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN) Private->HobList.Raw)));\r
-        DEBUG ((EFI_D_INFO, "Total temporary memory:    %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize));\r
-        DEBUG ((EFI_D_INFO, "  temporary memory stack ever used: %d bytes.\n",\r
-               (UINT32)(SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase))\r
-              ));\r
-        DEBUG ((EFI_D_INFO, "  temporary memory heap used:       %d bytes.\n",\r
-               (UINT32)((UINTN)Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN)Private->HobList.Raw)\r
-              ));\r
+           && (*StackPointer == PcdGet32 (PcdInitValueInTempStack));\r
+           StackPointer ++) {\r
+      }\r
+\r
+      DEBUG ((DEBUG_INFO, "Temp Stack : BaseAddress=0x%p Length=0x%X\n", SecCoreData->StackBase, (UINT32)SecCoreData->StackSize));\r
+      DEBUG ((DEBUG_INFO, "Temp Heap  : BaseAddress=0x%p Length=0x%X\n", SecCoreData->PeiTemporaryRamBase, (UINT32)SecCoreData->PeiTemporaryRamSize));\r
+      DEBUG ((DEBUG_INFO, "Total temporary memory:    %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize));\r
+      DEBUG ((DEBUG_INFO, "  temporary memory stack ever used:       %d bytes.\n",\r
+             (UINT32)(SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase))\r
+            ));\r
+      DEBUG ((DEBUG_INFO, "  temporary memory heap used for HobList: %d bytes.\n",\r
+             (UINT32)((UINTN)Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN)Private->HobList.Raw)\r
+            ));\r
+      DEBUG ((DEBUG_INFO, "  temporary memory heap occupied by memory pages: %d bytes.\n",\r
+             (UINT32)(UINTN)(Private->HobList.HandoffInformationTable->EfiMemoryTop - Private->HobList.HandoffInformationTable->EfiFreeMemoryTop)\r
+            ));\r
+      for (Hob.Raw = Private->HobList.Raw; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
+        if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) {\r
+          DEBUG ((DEBUG_INFO, "Memory Allocation 0x%08x 0x%0lx - 0x%0lx\n", \\r
+            Hob.MemoryAllocation->AllocDescriptor.MemoryType,               \\r
+            Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress,        \\r
+            Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength - 1));\r
+        }\r
+      }\r
     DEBUG_CODE_END ();\r
 \r
     if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
@@ -708,10 +717,10 @@ PeiCheckAndSwitchStack (
     //\r
     // Reserve the size of new stack at bottom of physical memory\r
     //\r
-    // The size of new stack in permenent memory must be the same size \r
+    // The size of new stack in permanent memory must be the same size\r
     // or larger than the size of old stack in temporary memory.\r
     // But if new stack is smaller than the size of old stack, we also reserve\r
-    // the size of old stack at bottom of permenent memory.\r
+    // the size of old stack at bottom of permanent memory.\r
     //\r
     NewStackSize = RShiftU64 (Private->PhysicalMemoryLength, 1);\r
     NewStackSize = ALIGN_VALUE (NewStackSize, EFI_PAGE_SIZE);\r
@@ -788,7 +797,7 @@ PeiCheckAndSwitchStack (
 \r
       //\r
       // Temporary Ram Support PPI is provided by platform, it will copy \r
-      // temporary memory to permenent memory and do stack switching.\r
+      // temporary memory to permanent memory and do stack switching.\r
       // After invoking Temporary Ram Support PPI, the following code's \r
       // stack is in permanent memory.\r
       //\r
@@ -799,16 +808,28 @@ PeiCheckAndSwitchStack (
                                 TemporaryRamSize\r
                                 );\r
 \r
+      //\r
+      // Migrate memory pages allocated in pre-memory phase.\r
+      // It could not be called before calling TemporaryRamSupportPpi->TemporaryRamMigration()\r
+      // as the migrated memory pages may be overridden by TemporaryRamSupportPpi->TemporaryRamMigration().\r
+      //\r
+      MigrateMemoryPages (Private, TRUE);\r
+\r
       //\r
       // Entry PEI Phase 2\r
       //\r
       PeiCore (SecCoreData, NULL, Private);\r
     } else {\r
+      //\r
+      // Migrate memory pages allocated in pre-memory phase.\r
+      //\r
+      MigrateMemoryPages (Private, FALSE);\r
+\r
       //\r
       // Migrate the PEI Services Table pointer from temporary RAM to permanent RAM.\r
       //\r
       MigratePeiServicesTablePointer ();\r
-                \r
+\r
       //\r
       // Heap Offset\r
       //\r
@@ -836,7 +857,7 @@ PeiCheckAndSwitchStack (
       //\r
       HeapTemporaryRamSize = (UINTN) (Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - Private->HobList.HandoffInformationTable->EfiMemoryBottom);\r
       ASSERT (BaseOfNewHeap + HeapTemporaryRamSize <= Private->FreePhysicalMemoryTop);\r
-      CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) PeiTemporaryRamBase, HeapTemporaryRamSize);\r
+      CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, PeiTemporaryRamBase, HeapTemporaryRamSize);\r
 \r
       //\r
       // Migrate Stack\r
@@ -845,7 +866,6 @@ PeiCheckAndSwitchStack (
 \r
       //\r
       // Copy Hole Range Data\r
-      // Convert PPI from Hole. \r
       //\r
       if (HoleMemSize != 0) {\r
         //\r
@@ -1110,6 +1130,13 @@ PeiDispatcher (
                   PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
                   PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
                   Private->PeimDispatchOnThisPass = TRUE;\r
+                } else {\r
+                  //\r
+                  // The related GuidedSectionExtraction PPI for the\r
+                  // signed PEIM image section may be installed in the rest\r
+                  // of this do-while loop, so need to make another pass.\r
+                  //\r
+                  Private->PeimNeedingDispatch = TRUE;\r
                 }\r
 \r
                 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
@@ -1141,7 +1168,7 @@ PeiDispatcher (
             if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) &&   \\r
                 (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
               //\r
-              // If memory is availble we shadow images by default for performance reasons.\r
+              // If memory is available we shadow images by default for performance reasons.\r
               // We call the entry point a 2nd time so the module knows it's shadowed.\r
               //\r
               //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r