]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Image/Image.c
clean up the un-suitable ';' location when declaring the functions.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Image / Image.c
index c38fa56705d98f8ad2073fca42a629c97dad99cb..efe8c83b101b8a7a4679dc5f39861b8abcfbe9e0 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
+/** @file\r
+  Pei Core Load Image Support\r
+  \r
+Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -9,70 +10,23 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
 \r
-Module Name:\r
-\r
-  Image.c\r
-\r
-Abstract:\r
-\r
-  Pei Core Load Image Support\r
-\r
---*/\r
+**/\r
 \r
 #include <PeiMain.h>\r
 \r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r
-\r
-Arguments:\r
-\r
-  FileHandle - The handle to the PE/COFF file\r
-  FileOffset - The offset, in bytes, into the file to read\r
-  ReadSize   - The number of bytes to read from the file starting at FileOffset\r
-  Buffer     - A pointer to the buffer to read the data into.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
-\r
---*/  \r
-\r
-EFI_STATUS\r
-PeiLoadImageLoadImage (\r
-  IN     EFI_PEI_SERVICES             **PeiServices,\r
-  IN     EFI_PEI_FILE_HANDLE          FileHandle,\r
-  OUT    EFI_PHYSICAL_ADDRESS         *ImageAddressArg,  OPTIONAL\r
-  OUT    UINT64                       *ImageSizeArg,     OPTIONAL\r
-  OUT    EFI_PHYSICAL_ADDRESS         *EntryPoint,\r
-  OUT    UINT32                       *AuthenticationState\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Routine for loading file image.\r
-\r
-Arguments:\r
-\r
-  PeiServices          - The PEI core services table.\r
-  FileHandle           - Pointer to the FFS file header of the image.\r
-  ImageAddressArg      - Pointer to PE/TE image.\r
-  ImageSizeArg         - Size of PE/TE image.\r
-  EntryPoint           - Pointer to entry point of specified image file for output.\r
-  AuthenticationState  - Pointer to attestation authentication state of image.\r
-\r
-Returns:\r
+/**\r
+  The wrapper function of PeiLoadImageLoadImage().\r
 \r
-  Status - EFI_SUCCESS    - Image is successfully loaded.\r
-           EFI_NOT_FOUND  - Fail to locate necessary PPI\r
-           Others         - Fail to load file.\r
+  @param This            - Pointer to EFI_PEI_LOAD_FILE_PPI.\r
+  @param FileHandle      - Pointer to the FFS file header of the image.\r
+  @param ImageAddressArg - Pointer to PE/TE image.\r
+  @param ImageSizeArg    - Size of PE/TE image.\r
+  @param EntryPoint      - Pointer to entry point of specified image file for output.\r
+  @param AuthenticationState - Pointer to attestation authentication state of image.\r
 \r
---*/\r
-;\r
+  @return Status of PeiLoadImageLoadImage().\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiLoadImageLoadImageWrapper (\r
@@ -82,29 +36,7 @@ PeiLoadImageLoadImageWrapper (
   OUT    UINT64                       *ImageSizeArg,     OPTIONAL\r
   OUT    EFI_PHYSICAL_ADDRESS         *EntryPoint,\r
   OUT    UINT32                       *AuthenticationState\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  The wrapper function of PeiLoadImageLoadImage().\r
-\r
-Arguments:\r
-\r
-  This                 - Pointer to EFI_PEI_LOAD_FILE_PPI.\r
-  PeiServices          - The PEI core services table.\r
-  FileHandle           - Pointer to the FFS file header of the image.\r
-  ImageAddressArg      - Pointer to PE/TE image.\r
-  ImageSizeArg         - Size of PE/TE image.\r
-  EntryPoint           - Pointer to entry point of specified image file for output.\r
-  AuthenticationState  - Pointer to attestation authentication state of image.\r
-\r
-Returns:\r
-\r
-  EFI_STATUS.\r
-  \r
---*/ \r
-;\r
+  );\r
 \r
 STATIC EFI_PEI_LOAD_FILE_PPI   mPeiLoadImagePpi = {\r
   PeiLoadImageLoadImageWrapper\r
@@ -117,32 +49,27 @@ STATIC EFI_PEI_PPI_DESCRIPTOR     gPpiLoadFilePpiList = {
   &mPeiLoadImagePpi\r
 };\r
 \r
+/**\r
+\r
+  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r
+\r
+\r
+  @param FileHandle      - The handle to the PE/COFF file\r
+  @param FileOffset      - The offset, in bytes, into the file to read\r
+  @param ReadSize        - The number of bytes to read from the file starting at FileOffset\r
+  @param Buffer          - A pointer to the buffer to read the data into.\r
+\r
+  @return EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiImageRead (\r
   IN     VOID    *FileHandle,\r
   IN     UINTN   FileOffset,\r
-  IN OUT UINTN   *ReadSize,\r
+  IN     UINTN   *ReadSize,\r
   OUT    VOID    *Buffer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file\r
-\r
-Arguments:\r
-\r
-  FileHandle - The handle to the PE/COFF file\r
-  FileOffset - The offset, in bytes, into the file to read\r
-  ReadSize   - The number of bytes to read from the file starting at FileOffset\r
-  Buffer     - A pointer to the buffer to read the data into.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset\r
-\r
---*/\r
 {\r
   CHAR8 *Destination8;\r
   CHAR8 *Source8;\r
@@ -158,27 +85,19 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-EFI_STATUS\r
-GetImageReadFunction (\r
-  IN      PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Support routine to return the Image Read\r
-\r
-Arguments:\r
-\r
-  PeiServices   - PEI Services Table\r
+/**\r
 \r
-  ImageContext  - The context of the image being loaded\r
+  Support routine to get the Image read file function.\r
 \r
-Returns:\r
+  @param ImageContext    - The context of the image being loaded\r
 \r
-  EFI_SUCCESS - If Image function location is found\r
+  @retval EFI_SUCCESS - If Image function location is found\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+GetImageReadFunction (\r
+  IN      PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
 {\r
   VOID*  MemoryBuffer;\r
 \r
@@ -192,7 +111,21 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+/**\r
+\r
+  Loads and relocates a PE/COFF image into memory.\r
+\r
+\r
+  @param Pe32Data        - The base address of the PE/COFF file that is to be loaded and relocated\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
+  @retval EFI_SUCCESS           The file was loaded and relocated\r
+  @retval EFI_OUT_OF_RESOURCES  There was not enough memory to load and relocate the PE/COFF file\r
+  @retval EFI_INVALID_PARAMETER The image withou .reloc section can't be relocated.\r
+\r
+**/\r
 EFI_STATUS\r
 LoadAndRelocatePeCoffImage (\r
   IN  VOID                                      *Pe32Data,\r
@@ -200,29 +133,6 @@ LoadAndRelocatePeCoffImage (
   OUT UINT64                                    *ImageSize,\r
   OUT EFI_PHYSICAL_ADDRESS                      *EntryPoint\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Loads and relocates a PE/COFF image into memory.\r
-\r
-Arguments:\r
-\r
-  Pe32Data         - The base address of the PE/COFF file that is to be loaded and relocated\r
-\r
-  ImageAddress     - The base address of the relocated PE/COFF image\r
-\r
-  ImageSize        - The size of the relocated PE/COFF image\r
-\r
-  EntryPoint       - The entry point of the relocated PE/COFF image\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS   - The file was loaded and relocated\r
-\r
-  EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r
-\r
---*/\r
 {\r
   EFI_STATUS                            Status;\r
   PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;\r
@@ -241,7 +151,7 @@ Returns:
   // When Image has no reloc section, it can't be relocated into memory.\r
   //\r
   if (ImageContext.RelocationsStripped) {\r
-    DEBUG ((EFI_D_ERROR, "The image at 0x%08x without reloc section can't be loaded into memory", (UINTN) Pe32Data));\r
+    DEBUG ((EFI_D_ERROR, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data));\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   //\r
@@ -286,6 +196,23 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Loads a PEIM into memory for subsequent execution. If there are compressed \r
+  images or images that need to be relocated into memory for performance reasons, \r
+  this service performs that transformation.\r
+\r
+  @param PeiServices      An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
+  @param FileHandle       Pointer to the FFS file header of the image.\r
+  @param ImageAddressArg  Pointer to PE/TE image.\r
+  @param ImageSizeArg     Size of PE/TE image.\r
+  @param EntryPoint       Pointer to entry point of specified image file for output.\r
+  @param AuthenticationState - Pointer to attestation authentication state of image.\r
+\r
+  @retval EFI_SUCCESS      Image is successfully loaded.\r
+  @retval EFI_NOT_FOUND    Fail to locate necessary PPI.\r
+  @retval EFI_UNSUPPORTED  Image Machine Type is not supported.\r
+\r
+**/\r
 EFI_STATUS\r
 PeiLoadImageLoadImage (\r
   IN     EFI_PEI_SERVICES             **PeiServices,\r
@@ -295,28 +222,6 @@ PeiLoadImageLoadImage (
   OUT    EFI_PHYSICAL_ADDRESS         *EntryPoint,\r
   OUT    UINT32                       *AuthenticationState\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Routine for loading file image.\r
-\r
-Arguments:\r
-\r
-  PeiServices          - The PEI core services table.\r
-  FileHandle           - Pointer to the FFS file header of the image.\r
-  ImageAddressArg      - Pointer to PE/TE image.\r
-  ImageSizeArg         - Size of PE/TE image.\r
-  EntryPoint           - Pointer to entry point of specified image file for output.\r
-  AuthenticationState  - Pointer to attestation authentication state of image.\r
-\r
-Returns:\r
-\r
-  Status - EFI_SUCCESS    - Image is successfully loaded.\r
-           EFI_NOT_FOUND  - Fail to locate necessary PPI\r
-           Others         - Fail to load file.\r
-\r
---*/\r
 {\r
   EFI_STATUS                  Status;\r
   VOID                        *Pe32Data;\r
@@ -326,25 +231,35 @@ Returns:
   UINT16                      Machine;\r
   PEI_CORE_INSTANCE           *Private;\r
   VOID                        *EntryPointArg;\r
+  EFI_SECTION_TYPE            SearchType1;\r
+  EFI_SECTION_TYPE            SearchType2;\r
 \r
   *EntryPoint          = 0;\r
   ImageSize            = 0;\r
   *AuthenticationState = 0;\r
 \r
+  if (FeaturePcdGet (PcdPeiCoreImageLoaderSearchTeSectionFirst)) {\r
+    SearchType1 = EFI_SECTION_TE;\r
+    SearchType2 = EFI_SECTION_PE32;\r
+  } else {\r
+    SearchType1 = EFI_SECTION_PE32;\r
+    SearchType2 = EFI_SECTION_TE;\r
+  }\r
   //\r
-  // Try to find a TE section.\r
+  // Try to find a first exe section (if PcdPeiCoreImageLoaderSearchTeSectionFirst \r
+  // is true, TE will be searched first).\r
   //\r
   Status = PeiServicesFfsFindSectionData (\r
-             EFI_SECTION_TE,\r
+             SearchType1,\r
              FileHandle,\r
              &Pe32Data\r
              );\r
   //\r
-  // If we didn't find a TE section, try to find a PE32 section.\r
+  // If we didn't find a first exe section, try to find the second exe section.\r
   //\r
   if (EFI_ERROR (Status)) {\r
     Status = PeiServicesFfsFindSectionData (\r
-               EFI_SECTION_PE32,\r
+               SearchType2,\r
                FileHandle,\r
                &Pe32Data\r
                );\r
@@ -406,16 +321,27 @@ Returns:
     *ImageSizeArg = ImageSize;\r
   }\r
   \r
-  //\r
-  // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi\r
-  //\r
-  DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", (UINTN) ImageAddress, *EntryPoint));\r
   DEBUG_CODE_BEGIN ();\r
     CHAR8                              *AsciiString;\r
     CHAR8                              AsciiBuffer[512];\r
     INT32                              Index;\r
     INT32                              Index1;\r
+\r
+    //\r
+    // Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi\r
+    //\r
+    if (Machine != IMAGE_FILE_MACHINE_IA64) {\r
+      DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)*EntryPoint));\r
+    } else {\r
+      //\r
+      // For IPF Image, the real entry point should be print.\r
+      //\r
+      DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%11p EntryPoint=0x%11p ", (VOID *)(UINTN)ImageAddress, (VOID *)(UINTN)(*(UINT64 *)(UINTN)*EntryPoint)));\r
+    }\r
     \r
+    //\r
+    // Print Module Name by PeImage PDB file name.\r
+    //\r
     AsciiString = PeCoffLoaderGetPdbPointer (Pe32Data);\r
     \r
     if (AsciiString != NULL) {\r
@@ -443,6 +369,19 @@ Returns:
 }\r
 \r
 \r
+/**\r
+  The wrapper function of PeiLoadImageLoadImage().\r
+\r
+  @param This            - Pointer to EFI_PEI_LOAD_FILE_PPI.\r
+  @param FileHandle      - Pointer to the FFS file header of the image.\r
+  @param ImageAddressArg - Pointer to PE/TE image.\r
+  @param ImageSizeArg    - Size of PE/TE image.\r
+  @param EntryPoint      - Pointer to entry point of specified image file for output.\r
+  @param AuthenticationState - Pointer to attestation authentication state of image.\r
+\r
+  @return Status of PeiLoadImageLoadImage().\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PeiLoadImageLoadImageWrapper (\r
@@ -453,27 +392,6 @@ PeiLoadImageLoadImageWrapper (
   OUT    EFI_PHYSICAL_ADDRESS         *EntryPoint,\r
   OUT    UINT32                       *AuthenticationState\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  The wrapper function of PeiLoadImageLoadImage().\r
-\r
-Arguments:\r
-\r
-  This                 - Pointer to EFI_PEI_LOAD_FILE_PPI.\r
-  PeiServices          - The PEI core services table.\r
-  FileHandle           - Pointer to the FFS file header of the image.\r
-  ImageAddressArg      - Pointer to PE/TE image.\r
-  ImageSizeArg         - Size of PE/TE image.\r
-  EntryPoint           - Pointer to entry point of specified image file for output.\r
-  AuthenticationState  - Pointer to attestation authentication state of image.\r
-\r
-Returns:\r
-\r
-  EFI_STATUS.\r
-  \r
---*/      \r
 {\r
   return PeiLoadImageLoadImage (\r
            GetPeiServicesTablePointer (),\r
@@ -485,6 +403,21 @@ Returns:
            );\r
 }\r
 \r
+/**\r
+  Routine to load image file for subsequent execution by LoadFile Ppi.\r
+  If any LoadFile Ppi is not found, the build-in support function for the PE32+/TE \r
+  XIP image format is used.\r
+\r
+  @param PeiServices     - An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r
+  @param FileHandle      - Pointer to the FFS file header of the image.\r
+  @param EntryPoint      - Pointer to entry point of specified image file for output.\r
+  @param AuthenticationState - Pointer to attestation authentication state of image.\r
+\r
+  @retval EFI_SUCCESS    - Image is successfully loaded.\r
+  @retval EFI_NOT_FOUND  - Fail to locate necessary PPI\r
+  @retval Others         - Fail to load file.\r
+\r
+**/\r
 EFI_STATUS\r
 PeiLoadImage (\r
   IN     EFI_PEI_SERVICES             **PeiServices,\r
@@ -492,26 +425,6 @@ PeiLoadImage (
   OUT    EFI_PHYSICAL_ADDRESS         *EntryPoint,\r
   OUT    UINT32                       *AuthenticationState\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Routine for load image file.\r
-\r
-Arguments:\r
-\r
-  PeiServices          - The PEI core services table.\r
-  FileHandle           - Pointer to the FFS file header of the image.\r
-  EntryPoint           - Pointer to entry point of specified image file for output.\r
-  AuthenticationState  - Pointer to attestation authentication state of image.\r
-\r
-Returns:\r
-\r
-  Status - EFI_SUCCESS    - Image is successfully loaded.\r
-           EFI_NOT_FOUND  - Fail to locate necessary PPI\r
-           Others         - Fail to load file.\r
-  \r
---*/    \r
 {\r
   EFI_STATUS              PpiStatus;\r
   EFI_STATUS              Status;\r
@@ -564,27 +477,20 @@ Returns:
 }\r
 \r
 \r
-VOID\r
-InitializeImageServices (\r
-  IN  PEI_CORE_INSTANCE   *PrivateData,\r
-  IN  PEI_CORE_INSTANCE   *OldCoreData\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Install Pei Load File PPI.\r
 \r
-Arguments:\r
-\r
-  PrivateData    - Pointer to PEI_CORE_INSTANCE.\r
-  OldCoreData    - Pointer to PEI_CORE_INSTANCE.\r
 \r
-Returns:\r
+  @param PrivateData     - Pointer to PEI_CORE_INSTANCE.\r
+  @param OldCoreData     - Pointer to PEI_CORE_INSTANCE.\r
 \r
-  NONE.\r
-  \r
---*/      \r
+**/\r
+VOID\r
+InitializeImageServices (\r
+  IN  PEI_CORE_INSTANCE   *PrivateData,\r
+  IN  PEI_CORE_INSTANCE   *OldCoreData\r
+  )\r
 {\r
   if (OldCoreData == NULL) {\r
     //\r