]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Image/Image.c
MdeModulePkg/Core/Pei: fix REGISITER -> REGISTER typo
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Image / Image.c
index c75ef35eee2d0ee15dad367344c03992a3dcd422..f07f48823117aa0373f7f6fb9f8abdac7819340e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Pei Core Load Image Support\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -112,22 +112,23 @@ GetImageReadFunction (
   IN      PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
   )\r
 {\r
-  PEI_CORE_INSTANCE  *Private;\r
-  VOID*  MemoryBuffer;\r
+#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
+  PEI_CORE_INSTANCE     *Private;\r
+  EFI_PHYSICAL_ADDRESS  MemoryBuffer;\r
 \r
   Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
-  \r
+  MemoryBuffer = 0;\r
+\r
   if (Private->PeiMemoryInstalled  && (((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnBoot)) || \r
-      ((Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot))) &&\r
-      (EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_X64) || EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_IA32))) {\r
+      ((Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot)))) {\r
     // \r
     // Shadow algorithm makes lots of non ANSI C assumptions and only works for IA32 and X64 \r
     //  compilers that have been tested\r
     //\r
     if (Private->ShadowedImageRead == NULL) {\r
-      MemoryBuffer = AllocatePages (0x400 / EFI_PAGE_SIZE + 1);\r
-      ASSERT (MemoryBuffer != NULL);\r
-      CopyMem (MemoryBuffer, (CONST VOID *) (UINTN) PeiImageReadForShadow, 0x400);\r
+      PeiServicesAllocatePages (EfiBootServicesCode, 0x400 / EFI_PAGE_SIZE + 1, &MemoryBuffer);\r
+      ASSERT (MemoryBuffer != 0);\r
+      CopyMem ((VOID *)(UINTN)MemoryBuffer, (CONST VOID *) (UINTN) PeiImageReadForShadow, 0x400);\r
       Private->ShadowedImageRead = (PE_COFF_LOADER_READ_FILE) (UINTN) MemoryBuffer;\r
     }\r
 \r
@@ -135,16 +136,18 @@ GetImageReadFunction (
   } else {\r
     ImageContext->ImageRead = PeiImageRead;\r
   }\r
-\r
+#else\r
+  ImageContext->ImageRead = PeiImageRead;\r
+#endif\r
   return EFI_SUCCESS;\r
 }\r
 /**\r
-  To check memory usage bit map arry to figure out if the memory range the image will be loaded in is available or not. If \r
-  memory range is avaliable, the function will mark the correponding bits to 1 which indicates the memory range is used.\r
+  To check memory usage bit map array to figure out if the memory range the image will be loaded in is available or not. If\r
+  memory range is available, the function will mark the corresponding bits to 1 which indicates the memory range is used.\r
   The function is only invoked when load modules at fixed address feature is enabled. \r
   \r
   @param  Private                  Pointer to the private data passed in from caller\r
-  @param  ImageBase                The base addres the image will be loaded at.\r
+  @param  ImageBase                The base address the image will be loaded at.\r
   @param  ImageSize                The size of the image\r
   \r
   @retval EFI_SUCCESS              The memory range the image will be loaded in is available\r
@@ -207,7 +210,7 @@ CheckAndMarkFixLoadingMemoryUsageBitMap (
 }\r
 /**\r
 \r
-  Get the fixed loadding address from image header assigned by build tool. This function only be called\r
+  Get the fixed loading address from image header assigned by build tool. This function only be called\r
   when Loading module at Fixed address feature enabled.\r
 \r
   @param ImageContext              Pointer to the image context structure that describes the PE/COFF\r
@@ -215,7 +218,7 @@ CheckAndMarkFixLoadingMemoryUsageBitMap (
   @param Private                    Pointer to the private data passed in from caller\r
 \r
   @retval EFI_SUCCESS               An fixed loading address is assigned to this image by build tools .\r
-  @retval EFI_NOT_FOUND             The image has no assigned fixed loadding address.\r
+  @retval EFI_NOT_FOUND             The image has no assigned fixed loading address.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -228,14 +231,14 @@ GetPeCoffImageFixLoadingAssignedAddress(
    EFI_STATUS                         Status;\r
    EFI_IMAGE_SECTION_HEADER           SectionHeader;\r
    EFI_IMAGE_OPTIONAL_HEADER_UNION    *ImgHdr;\r
-   EFI_PHYSICAL_ADDRESS               FixLoaddingAddress;\r
+   EFI_PHYSICAL_ADDRESS               FixLoadingAddress;\r
    UINT16                             Index;\r
    UINTN                              Size;\r
    UINT16                             NumberOfSections;\r
    UINT64                             ValueInSectionHeader;\r
  \r
 \r
-   FixLoaddingAddress = 0;\r
+   FixLoadingAddress = 0;\r
    Status = EFI_NOT_FOUND;\r
 \r
    //\r
@@ -244,18 +247,16 @@ GetPeCoffImageFixLoadingAssignedAddress(
    ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset);\r
    if (ImageContext->IsTeImage) {\r
      //\r
-     // for TE image, the fix loadding address is saved in first section header that doesn't point\r
+     // for TE image, the fix loading address is saved in first section header that doesn't point\r
      // to code section.\r
      //\r
      SectionHeaderOffset = sizeof (EFI_TE_IMAGE_HEADER);\r
      NumberOfSections = ImgHdr->Te.NumberOfSections;\r
    } else {\r
-     SectionHeaderOffset = (UINTN)(\r
-                                 ImageContext->PeCoffHeaderOffset +\r
-                                 sizeof (UINT32) +\r
-                                 sizeof (EFI_IMAGE_FILE_HEADER) +\r
-                                 ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader\r
-                                 );\r
+     SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +\r
+                           sizeof (UINT32) +\r
+                           sizeof (EFI_IMAGE_FILE_HEADER) +\r
+                           ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;\r
       NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;\r
    }\r
    //\r
@@ -286,7 +287,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
        // for XIP PEIM, ImageBase field holds the image base address running on the Flash. And PointerToRelocations & PointerToLineNumbers\r
        // hold the image base address when it is shadow to the memory. And there is an assumption that when the feature is enabled, if a\r
        // module is assigned a loading address by tools, PointerToRelocations & PointerToLineNumbers fields should NOT be Zero, or\r
-       // else, these 2 fileds should be set to Zero\r
+       // else, these 2 fields should be set to Zero\r
        //\r
        ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);\r
        if (ValueInSectionHeader != 0) {\r
@@ -296,32 +297,32 @@ GetPeCoffImageFixLoadingAssignedAddress(
          if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) > 0) {\r
            //\r
            // When LMFA feature is configured as Load Module at Fixed Absolute Address mode, PointerToRelocations & PointerToLineNumbers field\r
-           // hold the absolute address of image base runing in memory\r
+           // hold the absolute address of image base running in memory\r
            //\r
-           FixLoaddingAddress = ValueInSectionHeader;\r
+           FixLoadingAddress = ValueInSectionHeader;\r
          } else {\r
            //\r
            // When LMFA feature is configured as Load Module at Fixed offset mode, PointerToRelocations & PointerToLineNumbers field\r
            // hold the offset relative to a platform-specific top address.\r
            //\r
-           FixLoaddingAddress = (EFI_PHYSICAL_ADDRESS)(Private->LoadModuleAtFixAddressTopAddress + (INT64)ValueInSectionHeader);\r
+           FixLoadingAddress = (EFI_PHYSICAL_ADDRESS)(Private->LoadModuleAtFixAddressTopAddress + (INT64)ValueInSectionHeader);\r
          }\r
          //\r
-         // Check if the memory range is avaliable.\r
+         // Check if the memory range is available.\r
          //\r
-         Status = CheckAndMarkFixLoadingMemoryUsageBitMap (Private, FixLoaddingAddress, (UINT32) ImageContext->ImageSize);\r
+         Status = CheckAndMarkFixLoadingMemoryUsageBitMap (Private, FixLoadingAddress, (UINT32) ImageContext->ImageSize);\r
          if (!EFI_ERROR(Status)) {\r
            //\r
-           // The assigned address is valid. Return the specified loadding address\r
+           // The assigned address is valid. Return the specified loading address\r
            //\r
-           ImageContext->ImageAddress = FixLoaddingAddress;\r
+           ImageContext->ImageAddress = FixLoadingAddress;\r
          }\r
        }\r
        break;\r
      }\r
      SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);\r
    }\r
-   DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status= %r \n", (VOID *)(UINTN)FixLoaddingAddress, Status));\r
+   DEBUG ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status= %r \n", (VOID *)(UINTN)FixLoadingAddress, Status));\r
    return Status;\r
 }\r
 /**\r
@@ -386,7 +387,7 @@ LoadAndRelocatePeCoffImage (
   }\r
   IsRegisterForShadow = FALSE;\r
   if ((Private->CurrentFileHandle == FileHandle) \r
-    && (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW)) {\r
+    && (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] == PEIM_STATE_REGISTER_FOR_SHADOW)) {\r
     IsRegisterForShadow = TRUE;\r
   }\r
 \r
@@ -453,12 +454,16 @@ LoadAndRelocatePeCoffImage (
         //\r
         // The PEIM is not assiged valid address, try to allocate page to load it.\r
         //\r
-        ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize));\r
+        Status = PeiServicesAllocatePages (EfiBootServicesCode,\r
+                                           EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize),\r
+                                           &ImageContext.ImageAddress);\r
       }\r
     } else {\r
-      ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize));\r
+      Status = PeiServicesAllocatePages (EfiBootServicesCode,\r
+                                         EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize),\r
+                                         &ImageContext.ImageAddress);\r
     }\r
-    if (ImageContext.ImageAddress != 0) {\r
+    if (!EFI_ERROR (Status)) {\r
       //\r
       // Adjust the Image Address to make sure it is section alignment.\r
       //\r
@@ -501,6 +506,9 @@ LoadAndRelocatePeCoffImage (
   //\r
   Status = PeCoffLoaderLoadImage (&ImageContext);\r
   if (EFI_ERROR (Status)) {\r
+    if (ImageContext.ImageError == IMAGE_ERROR_INVALID_SECTION_ALIGNMENT) {\r
+      DEBUG ((DEBUG_ERROR, "PEIM Image Address 0x%11p doesn't meet with section alignment 0x%x.\n", (VOID*)(UINTN)ImageContext.ImageAddress, ImageContext.SectionAlignment));\r
+    }\r
     return Status;\r
   }\r
   //\r
@@ -607,6 +615,8 @@ PeiLoadImageLoadImage (
     }\r
   }\r
 \r
+  DEBUG ((DEBUG_INFO, "Loading PEIM %g\n", FileHandle));\r
+\r
   //\r
   // If memory is installed, perform the shadow operations\r
   //\r
@@ -866,7 +876,7 @@ PeiLoadImage (
         //\r
         // The shadowed PEIM must be relocatable.\r
         //\r
-        if (PeimState == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
+        if (PeimState == PEIM_STATE_REGISTER_FOR_SHADOW) {\r
           IsStrip = RelocationIsStrip ((VOID *) (UINTN) ImageAddress);\r
           ASSERT (!IsStrip);\r
           if (IsStrip) {\r