]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
Patch from open source community for CryptoPkg to allow it to build for ARM using...
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / DxeLoad.c
index e756f0ba584d6322ea0bd6d3ea6f1316a761c1f0..1fabb53839880a53dc97362339beab7a7cd10a7a 100644 (file)
@@ -2,8 +2,8 @@
   Last PEIM.\r
   Responsibility of this module is to load the DXE Core from a Firmware Volume.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2010, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -154,7 +154,12 @@ DxeLoadCore (
   EFI_BOOT_MODE                             BootMode;\r
   EFI_PEI_FILE_HANDLE                       FileHandle;\r
   EFI_PEI_READ_ONLY_VARIABLE2_PPI           *Variable;\r
+  EFI_PEI_LOAD_FILE_PPI                     *LoadFile;\r
+  UINTN                                     Instance;\r
+  UINT32                                    AuthenticationState;\r
   UINTN                                     DataSize;\r
+  EFI_PEI_S3_RESUME2_PPI                    *S3Resume;\r
+  EFI_PEI_RECOVERY_MODULE_PPI               *PeiRecovery;\r
   EFI_MEMORY_TYPE_INFORMATION               MemoryData[EfiMaxMemoryType + 1];\r
 \r
   //\r
@@ -163,10 +168,26 @@ DxeLoadCore (
   BootMode = GetBootModeHob ();\r
 \r
   if (BootMode == BOOT_ON_S3_RESUME) {\r
-    Status = AcpiS3ResumeOs();\r
+    Status = PeiServicesLocatePpi (\r
+               &gEfiPeiS3Resume2PpiGuid,\r
+               0,\r
+               NULL,\r
+               (VOID **) &S3Resume\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    Status = S3Resume->S3RestoreConfig2 (S3Resume);\r
     ASSERT_EFI_ERROR (Status);\r
   } else if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
-    Status = PeiRecoverFirmware ();\r
+    Status = PeiServicesLocatePpi (\r
+               &gEfiPeiRecoveryModulePpiGuid,\r
+               0,\r
+               NULL,\r
+               (VOID **) &PeiRecovery\r
+               );\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    Status = PeiRecovery->LoadRecoveryCapsule (PeiServices, PeiRecovery);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((DEBUG_ERROR, "Load Recovery Capsule Failed.(Status = %r)\n", Status));\r
       CpuDeadLoop ();\r
@@ -211,15 +232,25 @@ DxeLoadCore (
   FileHandle = DxeIplFindDxeCore ();\r
 \r
   //\r
-  // Load the DXE Core from a Firmware Volume, may use LoadFile PPI to do this to save code size.\r
+  // Load the DXE Core from a Firmware Volume.\r
   //\r
-  Status = PeiLoadFile (\r
-             FileHandle,\r
-             &DxeCoreAddress,\r
-             &DxeCoreSize,\r
-             &DxeCoreEntryPoint\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
+  Instance = 0;\r
+  do {\r
+    Status = PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid, Instance++, NULL, (VOID **) &LoadFile);\r
+    //\r
+    // These must exist an instance of EFI_PEI_LOAD_FILE_PPI to support to load DxeCore file handle successfully.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    Status = LoadFile->LoadFile (\r
+                         LoadFile,\r
+                         FileHandle,\r
+                         &DxeCoreAddress,\r
+                         &DxeCoreSize,\r
+                         &DxeCoreEntryPoint,\r
+                         &AuthenticationState\r
+                         );\r
+  } while (EFI_ERROR (Status));\r
 \r
   //\r
   // Get the DxeCore File Info from the FileHandle for the DxeCore GUID file name.\r
@@ -240,7 +271,7 @@ DxeLoadCore (
   //\r
   // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r
   //\r
-  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValuePeiHandoffToDxe));\r
+  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT));\r
 \r
   DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)DxeCoreAddress, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint)));\r
 \r
@@ -309,95 +340,6 @@ DxeIplFindDxeCore (
 }\r
 \r
 \r
-/**\r
-   Loads and relocates a PE/COFF image into memory.\r
-\r
-   @param FileHandle        The image file handle\r
-   @param ImageAddress      The base address of the relocated PE/COFF image\r
-   @param ImageSize         The size of the relocated PE/COFF image\r
-   @param EntryPoint        The entry point of the relocated PE/COFF image\r
-   \r
-   @return EFI_SUCCESS           The file was loaded and relocated\r
-   @return EFI_OUT_OF_RESOURCES  There was not enough memory to load and relocate the PE/COFF file\r
-\r
-**/\r
-EFI_STATUS\r
-PeiLoadFile (\r
-  IN  EFI_PEI_FILE_HANDLE                       FileHandle,\r
-  OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
-  OUT UINT64                                    *ImageSize,\r
-  OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint\r
-  )\r
-{\r
-\r
-  EFI_STATUS                        Status;\r
-  PE_COFF_LOADER_IMAGE_CONTEXT      ImageContext;\r
-  VOID                              *Pe32Data;\r
-\r
-  //\r
-  // First try to find the PE32 section in this ffs file.\r
-  //\r
-  Status = PeiServicesFfsFindSectionData (\r
-             EFI_SECTION_PE32,\r
-             FileHandle,\r
-             &Pe32Data\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // NO image types we support so exit.\r
-    //\r
-    return Status;\r
-  }\r
-\r
-  ZeroMem (&ImageContext, sizeof (ImageContext));\r
-  ImageContext.Handle = Pe32Data;\r
-  ImageContext.ImageRead = PeiImageRead;\r
-\r
-\r
-  Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  //\r
-  // Allocate Memory for the image\r
-  //\r
-  Status = PeiServicesAllocatePages (\r
-             EfiBootServicesCode, \r
-             EFI_SIZE_TO_PAGES ((UINT32) ImageContext.ImageSize), \r
-             &ImageContext.ImageAddress\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-  ASSERT (ImageContext.ImageAddress != 0);\r
-\r
-  //\r
-  // Load the image to our new buffer\r
-  //\r
-  Status = PeCoffLoaderLoadImage (&ImageContext);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  //\r
-  // Relocate the image in our new buffer\r
-  //\r
-  Status = PeCoffLoaderRelocateImage (&ImageContext);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Flush the instruction cache so the image data are written before we execute it\r
-  //\r
-  InvalidateInstructionCacheRange ((VOID *)(UINTN) ImageContext.ImageAddress, (UINTN) ImageContext.ImageSize);\r
-\r
-  *ImageAddress = ImageContext.ImageAddress;\r
-  *ImageSize    = ImageContext.ImageSize;\r
-  *EntryPoint   = ImageContext.EntryPoint;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-\r
 \r
 /**\r
   The ExtractSection() function processes the input section and\r
@@ -568,10 +510,10 @@ Decompress (
   EFI_STATUS                      Status;\r
   UINT8                           *DstBuffer;\r
   UINT8                           *ScratchBuffer;\r
-  UINT                          DstBufferSize;\r
+  UINT32                          DstBufferSize;\r
   UINT32                          ScratchBufferSize;\r
   EFI_COMMON_SECTION_HEADER       *Section;\r
-  UINT                          SectionLength;\r
+  UINT32                          SectionLength;\r
 \r
   if (CompressionSection->CommonHeader.Type != EFI_SECTION_COMPRESSION) {\r
     ASSERT (FALSE);\r
@@ -593,8 +535,8 @@ Decompress (
       //\r
       Status = UefiDecompressGetInfo (\r
                  (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1),\r
-                 (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
-                 (UINT32 *) &DstBufferSize,\r
+                 SectionLength - sizeof (EFI_COMPRESSION_SECTION),\r
+                 &DstBufferSize,\r
                  &ScratchBufferSize\r
                  );\r
       if (EFI_ERROR (Status)) {\r
@@ -640,6 +582,11 @@ Decompress (
       }\r
       break;\r
     } else {\r
+      //\r
+      // PcdDxeIplSupportUefiDecompress is FALSE\r
+      // Don't support UEFI decompression algorithm.\r
+      //\r
+      ASSERT (FALSE);\r
       return EFI_NOT_FOUND;\r
     }\r
 \r
@@ -700,13 +647,14 @@ UpdateStackHob (
   while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {\r
     if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {\r
       //\r
-      // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type\r
-      // to be reclaimed by DXE core.\r
+      // Build a new memory allocation HOB with old stack info with EfiBootServicesData type. Need to \r
+      // avoid this region be reclaimed by DXE core as the IDT built in SEC might be on stack, and some \r
+      // PEIMs may also keep key information on stack\r
       //\r
       BuildMemoryAllocationHob (\r
         Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,\r
         Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,\r
-        EfiConventionalMemory\r
+        EfiBootServicesData\r
         );\r
       //\r
       // Update the BSP Stack Hob to reflect the new stack info.\r