Delete unused PrintLib and Move PeCoffLib into Common Library to clean up library...
authorlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 7 Aug 2007 07:44:51 +0000 (07:44 +0000)
committerlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 7 Aug 2007 07:44:51 +0000 (07:44 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@514 7335b38e-4728-0410-8992-fb3ffe349368

Source/C/PeCoffLoader/BasePeCoff.c [deleted file]
Source/C/PeCoffLoader/Makefile [deleted file]
Source/C/PeCoffLoader/PeCoffLoaderEx.c [deleted file]

diff --git a/Source/C/PeCoffLoader/BasePeCoff.c b/Source/C/PeCoffLoader/BasePeCoff.c
deleted file mode 100644 (file)
index fe48df0..0000000
+++ /dev/null
@@ -1,1170 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2004 - 2005, 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
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-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
-  PeCoffLoader.c\r
-\r
-Abstract:\r
-\r
-  Tiano PE/COFF loader \r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#include <Common/UefiBaseTypes.h>\r
-#include <IndustryStandard/PeImage.h>\r
-#include <Library/PeCoffLib.h>\r
-\r
-typedef union {\r
-  VOID                         *Header; \r
-  EFI_IMAGE_OPTIONAL_HEADER32  *Optional32;\r
-  EFI_IMAGE_OPTIONAL_HEADER64  *Optional64;\r
-} EFI_IMAGE_OPTIONAL_HEADER_POINTER;\r
-\r
-STATIC\r
-RETURN_STATUS\r
-PeCoffLoaderGetPeHeader (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext,\r
-  OUT    EFI_IMAGE_NT_HEADERS          **PeHdr,\r
-  OUT    EFI_TE_IMAGE_HEADER           **TeHdr\r
-  );\r
-\r
-STATIC\r
-RETURN_STATUS\r
-PeCoffLoaderCheckImageType (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext,\r
-  IN     EFI_IMAGE_NT_HEADERS          *PeHdr,\r
-  IN     EFI_TE_IMAGE_HEADER           *TeHdr\r
-  );\r
-\r
-STATIC\r
-void *\r
-PeCoffLoaderImageAddress (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext,\r
-  IN     UINTN                         Address\r
-  );\r
-\r
-RETURN_STATUS\r
-PeCoffLoaderRelocateIa32Image (\r
-  IN UINT16      *Reloc,\r
-  IN OUT CHAR8   *Fixup,\r
-  IN OUT CHAR8   **FixupData,\r
-  IN UINT64      Adjust\r
-  );\r
-\r
-RETURN_STATUS\r
-PeCoffLoaderRelocateX64Image (\r
-  IN UINT16      *Reloc,\r
-  IN OUT CHAR8   *Fixup,\r
-  IN OUT CHAR8   **FixupData,\r
-  IN UINT64      Adjust\r
-  );\r
-\r
-RETURN_STATUS\r
-PeCoffLoaderRelocateIpfImage (\r
-  IN UINT16      *Reloc,\r
-  IN OUT CHAR8   *Fixup,\r
-  IN OUT CHAR8   **FixupData,\r
-  IN UINT64      Adjust\r
-  );\r
-\r
-STATIC\r
-RETURN_STATUS\r
-PeCoffLoaderGetPeHeader (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext,\r
-  OUT    EFI_IMAGE_NT_HEADERS          **PeHdr,\r
-  OUT    EFI_TE_IMAGE_HEADER           **TeHdr\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Retrieves the PE or TE Header from a PE/COFF or TE image\r
-\r
-Arguments:\r
-\r
-  ImageContext  - The context of the image being loaded\r
-\r
-  PeHdr         - The buffer in which to return the PE header\r
-  \r
-  TeHdr         - The buffer in which to return the TE header\r
-\r
-Returns:\r
-\r
-  RETURN_SUCCESS if the PE or TE Header is read, \r
-  Otherwise, the error status from reading the PE/COFF or TE image using the ImageRead function.\r
-\r
---*/\r
-{\r
-  RETURN_STATUS         Status;\r
-  EFI_IMAGE_DOS_HEADER  DosHdr;\r
-  UINTN                 Size;\r
-\r
-  ImageContext->IsTeImage = FALSE;\r
-  //\r
-  // Read the DOS image headers\r
-  //\r
-  Size = sizeof (EFI_IMAGE_DOS_HEADER);\r
-  Status = ImageContext->ImageRead (\r
-                          ImageContext->Handle,\r
-                          0,\r
-                          &Size,\r
-                          &DosHdr\r
-                          );\r
-  if (RETURN_ERROR (Status)) {\r
-    ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-    return Status;\r
-  }\r
-\r
-  ImageContext->PeCoffHeaderOffset = 0;\r
-  if (DosHdr.e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
-    //\r
-    // DOS image header is present, so read the PE header after the DOS image header\r
-    //\r
-    ImageContext->PeCoffHeaderOffset = DosHdr.e_lfanew;\r
-  }\r
-  //\r
-  // Get the PE/COFF Header pointer\r
-  //\r
-  *PeHdr = (EFI_IMAGE_NT_HEADERS *) ((UINTN)ImageContext->Handle + ImageContext->PeCoffHeaderOffset);\r
-  if ((*PeHdr)->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
-    //\r
-    // Check the PE/COFF Header Signature. If not, then try to get a TE header\r
-    //\r
-    *TeHdr = (EFI_TE_IMAGE_HEADER *)*PeHdr; \r
-    if ((*TeHdr)->Signature != EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
-      return RETURN_UNSUPPORTED;\r
-    }\r
-    ImageContext->IsTeImage = TRUE;\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-STATIC\r
-RETURN_STATUS\r
-PeCoffLoaderCheckImageType (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT          *ImageContext,\r
-  IN     EFI_IMAGE_NT_HEADERS                  *PeHdr,\r
-  IN     EFI_TE_IMAGE_HEADER                   *TeHdr\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Checks the PE or TE header of a PE/COFF or TE image to determine if it supported\r
-\r
-Arguments:\r
-\r
-  ImageContext  - The context of the image being loaded\r
-\r
-  PeHdr         - The buffer in which to return the PE header\r
-  \r
-  TeHdr         - The buffer in which to return the TE header\r
-\r
-Returns:\r
-\r
-  RETURN_SUCCESS if the PE/COFF or TE image is supported\r
-  RETURN_UNSUPPORTED of the PE/COFF or TE image is not supported.\r
-\r
---*/\r
-{\r
-  //\r
-  // See if the machine type is supported. \r
-  // We support a native machine type (IA-32/Itanium-based)\r
-  //\r
-  if (ImageContext->IsTeImage == FALSE) {\r
-    ImageContext->Machine = PeHdr->FileHeader.Machine;\r
-  } else {\r
-    ImageContext->Machine = TeHdr->Machine;\r
-  }\r
-  \r
-  if (ImageContext->Machine != EFI_IMAGE_MACHINE_IA32 && \\r
-      ImageContext->Machine != EFI_IMAGE_MACHINE_IA64 && \\r
-      ImageContext->Machine != EFI_IMAGE_MACHINE_X64) {\r
-    //\r
-    // upsupported PeImage machine type \r
-    // \r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // See if the image type is supported.  We support EFI Applications,\r
-  // EFI Boot Service Drivers, EFI Runtime Drivers and EFI SAL Drivers.\r
-  //\r
-  if (ImageContext->IsTeImage == FALSE) {\r
-    ImageContext->ImageType = PeHdr->OptionalHeader.Subsystem;\r
-  } else {\r
-    ImageContext->ImageType = (UINT16) (TeHdr->Subsystem);\r
-  }\r
-\r
-  if (ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION && \\r
-      ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER && \\r
-      ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER && \\r
-      ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER) {\r
-    //\r
-    // upsupported PeImage subsystem type \r
-    // \r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-RETURN_STATUS\r
-EFIAPI\r
-PeCoffLoaderGetImageInfo (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT           *ImageContext\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Retrieves information on a PE/COFF image\r
-\r
-Arguments:\r
-\r
-  This         - Calling context\r
-  ImageContext - The context of the image being loaded\r
-\r
-Returns:\r
-\r
-  RETURN_SUCCESS           - The information on the PE/COFF image was collected.\r
-  RETURN_INVALID_PARAMETER - ImageContext is NULL.\r
-  RETURN_UNSUPPORTED       - The PE/COFF image is not supported.\r
-  Otherwise             - The error status from reading the PE/COFF image using the\r
-                          ImageContext->ImageRead() function\r
-\r
---*/\r
-{\r
-  RETURN_STATUS                   Status;\r
-  EFI_IMAGE_NT_HEADERS            *PeHdr;\r
-  EFI_TE_IMAGE_HEADER             *TeHdr;\r
-  EFI_IMAGE_DATA_DIRECTORY        *DebugDirectoryEntry;\r
-  UINTN                           Size;\r
-  UINTN                           Index;\r
-  UINTN                           DebugDirectoryEntryRva;\r
-  UINTN                           DebugDirectoryEntryFileOffset;\r
-  UINTN                           SectionHeaderOffset;\r
-  EFI_IMAGE_SECTION_HEADER        SectionHeader;\r
-  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY DebugEntry;\r
-  EFI_IMAGE_OPTIONAL_HEADER_POINTER OptionHeader;\r
-\r
-  PeHdr = NULL;\r
-  TeHdr = NULL;\r
-  DebugDirectoryEntry    = NULL;\r
-  DebugDirectoryEntryRva = 0;\r
-\r
-  if (NULL == ImageContext) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Assume success\r
-  //\r
-  ImageContext->ImageError  = IMAGE_ERROR_SUCCESS;\r
-\r
-  Status                    = PeCoffLoaderGetPeHeader (ImageContext, &PeHdr, &TeHdr);\r
-  if (RETURN_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Verify machine type\r
-  //\r
-  Status = PeCoffLoaderCheckImageType (ImageContext, PeHdr, TeHdr);\r
-  if (RETURN_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  OptionHeader.Header = (VOID *) &(PeHdr->OptionalHeader);\r
-\r
-  //\r
-  // Retrieve the base address of the image\r
-  //\r
-  if (!(ImageContext->IsTeImage)) {\r
-    if (ImageContext->Machine == EFI_IMAGE_MACHINE_IA32) {\r
-      ImageContext->ImageAddress = (PHYSICAL_ADDRESS) OptionHeader.Optional32->ImageBase;\r
-    } else {\r
-      ImageContext->ImageAddress = (PHYSICAL_ADDRESS) OptionHeader.Optional64->ImageBase;\r
-    }\r
-  } else {\r
-    ImageContext->ImageAddress = (PHYSICAL_ADDRESS) (TeHdr->ImageBase + TeHdr->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER));\r
-  }\r
-  //\r
-  // Initialize the alternate destination address to 0 indicating that it\r
-  // should not be used.\r
-  //\r
-  ImageContext->DestinationAddress = 0;\r
-\r
-  //\r
-  // Initialize the codeview pointer.\r
-  //\r
-  ImageContext->CodeView    = NULL;\r
-  ImageContext->PdbPointer  = NULL;\r
-\r
-  //\r
-  // Three cases with regards to relocations:\r
-  // - Image has base relocs, RELOCS_STRIPPED==0    => image is relocatable\r
-  // - Image has no base relocs, RELOCS_STRIPPED==1 => Image is not relocatable\r
-  // - Image has no base relocs, RELOCS_STRIPPED==0 => Image is relocatable but\r
-  //   has no base relocs to apply\r
-  // Obviously having base relocations with RELOCS_STRIPPED==1 is invalid.\r
-  //\r
-  // Look at the file header to determine if relocations have been stripped, and\r
-  // save this info in the image context for later use.\r
-  //\r
-  if ((!(ImageContext->IsTeImage)) && ((PeHdr->FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0)) {\r
-    ImageContext->RelocationsStripped = TRUE;\r
-  } else {\r
-    ImageContext->RelocationsStripped = FALSE;\r
-  }\r
-\r
-  if (!(ImageContext->IsTeImage)) {\r
-\r
-    if (ImageContext->Machine == EFI_IMAGE_MACHINE_IA32) {\r
-      ImageContext->ImageSize         = (UINT64) OptionHeader.Optional32->SizeOfImage;\r
-      ImageContext->SectionAlignment  = OptionHeader.Optional32->SectionAlignment;\r
-      ImageContext->SizeOfHeaders     = OptionHeader.Optional32->SizeOfHeaders;\r
-  \r
-      //\r
-      // Modify ImageSize to contain .PDB file name if required and initialize\r
-      // PdbRVA field...\r
-      //\r
-      if (OptionHeader.Optional32->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
-        DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionHeader.Optional32->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-        DebugDirectoryEntryRva = DebugDirectoryEntry->VirtualAddress;\r
-      }\r
-    } else {\r
-      ImageContext->ImageSize         = (UINT64) OptionHeader.Optional64->SizeOfImage;\r
-      ImageContext->SectionAlignment  = OptionHeader.Optional64->SectionAlignment;\r
-      ImageContext->SizeOfHeaders     = OptionHeader.Optional64->SizeOfHeaders;\r
-  \r
-      //\r
-      // Modify ImageSize to contain .PDB file name if required and initialize\r
-      // PdbRVA field...\r
-      //\r
-      if (OptionHeader.Optional64->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
-        DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionHeader.Optional64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-        DebugDirectoryEntryRva = DebugDirectoryEntry->VirtualAddress;\r
-      }\r
-    }\r
-    \r
-    if (DebugDirectoryEntryRva != 0) {\r
-      //\r
-      // Determine the file offset of the debug directory...  This means we walk\r
-      // the sections to find which section contains the RVA of the debug\r
-      // directory\r
-      //\r
-      DebugDirectoryEntryFileOffset = 0;\r
-\r
-      SectionHeaderOffset = (UINTN)(\r
-                               ImageContext->PeCoffHeaderOffset +\r
-                               sizeof (UINT32) + \r
-                               sizeof (EFI_IMAGE_FILE_HEADER) + \r
-                               PeHdr->FileHeader.SizeOfOptionalHeader\r
-                               );\r
-\r
-      for (Index = 0; Index < PeHdr->FileHeader.NumberOfSections; Index++) {\r
-        //\r
-        // Read section header from file\r
-        //\r
-        Size = sizeof (EFI_IMAGE_SECTION_HEADER);\r
-        Status = ImageContext->ImageRead (\r
-                                 ImageContext->Handle,\r
-                                 SectionHeaderOffset,\r
-                                 &Size,\r
-                                 &SectionHeader\r
-                                 );\r
-        if (RETURN_ERROR (Status)) {\r
-          ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-          return Status;\r
-        }\r
-\r
-        if (DebugDirectoryEntryRva >= SectionHeader.VirtualAddress &&\r
-            DebugDirectoryEntryRva < SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize) {\r
-            DebugDirectoryEntryFileOffset =\r
-            DebugDirectoryEntryRva - SectionHeader.VirtualAddress + SectionHeader.PointerToRawData;\r
-          break;\r
-        }\r
-\r
-        SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);\r
-      }\r
-\r
-      if (DebugDirectoryEntryFileOffset != 0) {    \r
-        for (Index = 0; Index < DebugDirectoryEntry->Size; Index += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) {\r
-          //\r
-          // Read next debug directory entry\r
-          //\r
-          Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);    \r
-          Status = ImageContext->ImageRead (\r
-                                   ImageContext->Handle,\r
-                                   DebugDirectoryEntryFileOffset + Index,\r
-                                   &Size,\r
-                                   &DebugEntry\r
-                                   );\r
-          if (RETURN_ERROR (Status)) {\r
-            ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-            return Status;\r
-          }\r
-\r
-          if (DebugEntry.Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
-            ImageContext->DebugDirectoryEntryRva = (UINT32) (DebugDirectoryEntryRva + Index);\r
-            if (DebugEntry.RVA == 0 && DebugEntry.FileOffset != 0) {\r
-              ImageContext->ImageSize += DebugEntry.SizeOfData;\r
-            }\r
-\r
-            return RETURN_SUCCESS;\r
-          }\r
-        }\r
-      }\r
-    }\r
-  } else {\r
-    ImageContext->ImageSize         = 0;\r
-    ImageContext->SectionAlignment  = 4096;\r
-    ImageContext->SizeOfHeaders     = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN) TeHdr->BaseOfCode - (UINTN) TeHdr->StrippedSize;\r
-\r
-    DebugDirectoryEntry             = &TeHdr->DataDirectory[1];\r
-    DebugDirectoryEntryRva          = DebugDirectoryEntry->VirtualAddress;\r
-    SectionHeaderOffset             = (UINTN) (sizeof (EFI_TE_IMAGE_HEADER));\r
-\r
-    DebugDirectoryEntryFileOffset   = 0;\r
-\r
-    for (Index = 0; Index < TeHdr->NumberOfSections;) {\r
-      //\r
-      // Read section header from file\r
-      //\r
-      Size = sizeof (EFI_IMAGE_SECTION_HEADER);\r
-      Status = ImageContext->ImageRead (\r
-                               ImageContext->Handle,\r
-                               SectionHeaderOffset,\r
-                               &Size,\r
-                               &SectionHeader\r
-                               );\r
-      if (RETURN_ERROR (Status)) {\r
-        ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-        return Status;\r
-      }\r
-\r
-      if (DebugDirectoryEntryRva >= SectionHeader.VirtualAddress &&\r
-          DebugDirectoryEntryRva < SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize) {\r
-        DebugDirectoryEntryFileOffset = DebugDirectoryEntryRva -\r
-          SectionHeader.VirtualAddress +\r
-          SectionHeader.PointerToRawData +\r
-          sizeof (EFI_TE_IMAGE_HEADER) -\r
-          TeHdr->StrippedSize;\r
-\r
-        //\r
-        // File offset of the debug directory was found, if this is not the last\r
-        // section, then skip to the last section for calculating the image size.\r
-        //\r
-        if (Index < (UINTN) TeHdr->NumberOfSections - 1) {\r
-          SectionHeaderOffset += (TeHdr->NumberOfSections - 1 - Index) * sizeof (EFI_IMAGE_SECTION_HEADER);\r
-          Index = TeHdr->NumberOfSections - 1;\r
-          continue;\r
-        }\r
-      }\r
-\r
-      //\r
-      // In Te image header there is not a field to describe the ImageSize.\r
-      // Actually, the ImageSize equals the RVA plus the VirtualSize of \r
-      // the last section mapped into memory (Must be rounded up to \r
-      // a mulitple of Section Alignment). Per the PE/COFF specification, the\r
-      // section headers in the Section Table must appear in order of the RVA\r
-      // values for the corresponding sections. So the ImageSize can be determined\r
-      // by the RVA and the VirtualSize of the last section header in the\r
-      // Section Table.\r
-      //\r
-      if ((++Index) == (UINTN) TeHdr->NumberOfSections) {\r
-        ImageContext->ImageSize = (SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize +\r
-                                   ImageContext->SectionAlignment - 1) & ~(ImageContext->SectionAlignment - 1);\r
-      }\r
-\r
-      SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);\r
-    }\r
-\r
-    if (DebugDirectoryEntryFileOffset != 0) {\r
-      for (Index = 0; Index < DebugDirectoryEntry->Size; Index += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) {\r
-        //\r
-        // Read next debug directory entry\r
-        //\r
-        Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
-        Status = ImageContext->ImageRead (\r
-                                 ImageContext->Handle,\r
-                                 DebugDirectoryEntryFileOffset,\r
-                                 &Size,\r
-                                 &DebugEntry\r
-                                 );\r
-        if (RETURN_ERROR (Status)) {\r
-          ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-          return Status;\r
-        }\r
-\r
-        if (DebugEntry.Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
-          ImageContext->DebugDirectoryEntryRva = (UINT32) (DebugDirectoryEntryRva + Index);\r
-          return RETURN_SUCCESS;\r
-        }\r
-      }\r
-    }\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-STATIC\r
-VOID *\r
-PeCoffLoaderImageAddress (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT          *ImageContext,\r
-  IN     UINTN                                 Address\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Converts an image address to the loaded address\r
-\r
-Arguments:\r
-\r
-  ImageContext  - The context of the image being loaded\r
-\r
-  Address       - The address to be converted to the loaded address\r
-\r
-Returns:\r
-\r
-  NULL if the address can not be converted, otherwise, the converted address\r
-\r
---*/\r
-{\r
-  if (Address >= ImageContext->ImageSize) {\r
-    ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_ADDRESS;\r
-    return NULL;\r
-  }\r
-\r
-  return (UINT8 *) ((UINTN) ImageContext->ImageAddress + Address);\r
-}\r
-\r
-RETURN_STATUS\r
-EFIAPI\r
-PeCoffLoaderRelocateImage (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Relocates a PE/COFF image in memory\r
-\r
-Arguments:\r
-\r
-  This         - Calling context\r
-\r
-  ImageContext - Contains information on the loaded image to relocate\r
-\r
-Returns:\r
-\r
-  RETURN_SUCCESS      if the PE/COFF image was relocated\r
-  RETURN_LOAD_ERROR   if the image is not a valid PE/COFF image\r
-  RETURN_UNSUPPORTED  not support\r
-\r
---*/\r
-{\r
-  RETURN_STATUS             Status;\r
-  EFI_IMAGE_NT_HEADERS      *PeHdr;\r
-  EFI_TE_IMAGE_HEADER       *TeHdr;\r
-  EFI_IMAGE_DATA_DIRECTORY  *RelocDir;\r
-  UINT64                     Adjust;\r
-  EFI_IMAGE_BASE_RELOCATION *RelocBase;\r
-  EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd;\r
-  UINT16                    *Reloc;\r
-  UINT16                    *RelocEnd;\r
-  CHAR8                     *Fixup;\r
-  CHAR8                     *FixupBase;\r
-  UINT16                    *F16;\r
-  UINT32                    *F32;\r
-  CHAR8                     *FixupData;\r
-  PHYSICAL_ADDRESS          BaseAddress;\r
-  UINT16                    MachineType;\r
-  EFI_IMAGE_OPTIONAL_HEADER_POINTER     OptionHeader;\r
-\r
-  PeHdr = NULL;\r
-  TeHdr = NULL;\r
-  //\r
-  // Assume success\r
-  //\r
-  ImageContext->ImageError = IMAGE_ERROR_SUCCESS;\r
-\r
-  //\r
-  // If there are no relocation entries, then we are done\r
-  //\r
-  if (ImageContext->RelocationsStripped) {\r
-    return RETURN_SUCCESS;\r
-  }\r
-\r
-  //\r
-  // If the destination address is not 0, use that rather than the\r
-  // image address as the relocation target.\r
-  //\r
-  if (ImageContext->DestinationAddress) {\r
-    BaseAddress = ImageContext->DestinationAddress;\r
-  } else {\r
-    BaseAddress = ImageContext->ImageAddress;\r
-  }\r
-\r
-  if (!(ImageContext->IsTeImage)) {\r
-    PeHdr = (EFI_IMAGE_NT_HEADERS *)((UINTN)ImageContext->ImageAddress + \r
-                                            ImageContext->PeCoffHeaderOffset);\r
-    OptionHeader.Header = (VOID *) &(PeHdr->OptionalHeader);\r
-    if (ImageContext->Machine == EFI_IMAGE_MACHINE_IA32) {\r
-      Adjust = (UINT64) BaseAddress - OptionHeader.Optional32->ImageBase;\r
-      OptionHeader.Optional32->ImageBase = (UINT32) BaseAddress;\r
-      MachineType = ImageContext->Machine;\r
-      //\r
-      // Find the relocation block\r
-      //\r
-      // Per the PE/COFF spec, you can't assume that a given data directory\r
-      // is present in the image. You have to check the NumberOfRvaAndSizes in\r
-      // the optional header to verify a desired directory entry is there.\r
-      //\r
-      if (OptionHeader.Optional32->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
-        RelocDir  = &OptionHeader.Optional32->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r
-        RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress);\r
-        RelocBaseEnd = PeCoffLoaderImageAddress (\r
-                        ImageContext,\r
-                        RelocDir->VirtualAddress + RelocDir->Size - 1\r
-                        );\r
-      } else {\r
-        //\r
-        // Set base and end to bypass processing below.\r
-        //\r
-        RelocBase = RelocBaseEnd = 0;\r
-      }\r
-    } else {\r
-      Adjust = (UINT64) BaseAddress - OptionHeader.Optional64->ImageBase;\r
-      OptionHeader.Optional64->ImageBase = BaseAddress;\r
-      MachineType = ImageContext->Machine;\r
-      //\r
-      // Find the relocation block\r
-      //\r
-      // Per the PE/COFF spec, you can't assume that a given data directory\r
-      // is present in the image. You have to check the NumberOfRvaAndSizes in\r
-      // the optional header to verify a desired directory entry is there.\r
-      //\r
-      if (OptionHeader.Optional64->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
-        RelocDir  = &OptionHeader.Optional64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r
-        RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress);\r
-        RelocBaseEnd = PeCoffLoaderImageAddress (\r
-                        ImageContext,\r
-                        RelocDir->VirtualAddress + RelocDir->Size - 1\r
-                        );\r
-      } else {\r
-        //\r
-        // Set base and end to bypass processing below.\r
-        //\r
-        RelocBase = RelocBaseEnd = 0;\r
-      }\r
-    }\r
-  } else {\r
-    TeHdr             = (EFI_TE_IMAGE_HEADER *) (UINTN) (ImageContext->ImageAddress);\r
-    Adjust            = (UINT64) (BaseAddress - TeHdr->ImageBase);\r
-    TeHdr->ImageBase  = (UINT64) (BaseAddress);\r
-    MachineType = TeHdr->Machine;\r
-    \r
-    //\r
-    // Find the relocation block\r
-    //\r
-    RelocDir = &TeHdr->DataDirectory[0];\r
-    RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(\r
-                                    ImageContext->ImageAddress + \r
-                                    RelocDir->VirtualAddress +\r
-                                    sizeof(EFI_TE_IMAGE_HEADER) - \r
-                                    TeHdr->StrippedSize\r
-                                    );\r
-    RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);\r
-  }\r
-  \r
-  //\r
-  // Run the relocation information and apply the fixups\r
-  //\r
-  FixupData = ImageContext->FixupData;\r
-  while (RelocBase < RelocBaseEnd) {\r
-\r
-    Reloc     = (UINT16 *) ((CHAR8 *) RelocBase + sizeof (EFI_IMAGE_BASE_RELOCATION));\r
-    RelocEnd  = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);\r
-    if (!(ImageContext->IsTeImage)) {\r
-      FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);\r
-    } else {\r
-      FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +\r
-                    RelocBase->VirtualAddress +\r
-                    sizeof(EFI_TE_IMAGE_HEADER) - \r
-                    TeHdr->StrippedSize\r
-                    );\r
-    }\r
-\r
-    if ((CHAR8 *) RelocEnd < (CHAR8 *) ((UINTN) ImageContext->ImageAddress) ||\r
-        (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + \r
-          (UINTN)ImageContext->ImageSize)) {\r
-      ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
-      return RETURN_LOAD_ERROR;\r
-    }\r
-\r
-    //\r
-    // Run this relocation record\r
-    //\r
-    while (Reloc < RelocEnd) {\r
-\r
-      Fixup = FixupBase + (*Reloc & 0xFFF);\r
-      switch ((*Reloc) >> 12) {\r
-      case EFI_IMAGE_REL_BASED_ABSOLUTE:\r
-        break;\r
-\r
-      case EFI_IMAGE_REL_BASED_HIGH:\r
-        F16   = (UINT16 *) Fixup;\r
-        *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
-        if (FixupData != NULL) {\r
-          *(UINT16 *) FixupData = *F16;\r
-          FixupData             = FixupData + sizeof (UINT16);\r
-        }\r
-        break;\r
-\r
-      case EFI_IMAGE_REL_BASED_LOW:\r
-        F16   = (UINT16 *) Fixup;\r
-        *F16  = (UINT16) (*F16 + (UINT16) Adjust);\r
-        if (FixupData != NULL) {\r
-          *(UINT16 *) FixupData = *F16;\r
-          FixupData             = FixupData + sizeof (UINT16);\r
-        }\r
-        break;\r
-\r
-      case EFI_IMAGE_REL_BASED_HIGHLOW:\r
-        F32   = (UINT32 *) Fixup;\r
-        *F32  = *F32 + (UINT32) Adjust;\r
-        if (FixupData != NULL) {\r
-          FixupData             = ALIGN_POINTER (FixupData, sizeof (UINT32));\r
-          *(UINT32 *) FixupData = *F32;\r
-          FixupData             = FixupData + sizeof (UINT32);\r
-        }\r
-        break;\r
-\r
-      case EFI_IMAGE_REL_BASED_HIGHADJ:\r
-        //\r
-        // Return the same EFI_UNSUPPORTED return code as\r
-        // PeCoffLoaderRelocateImageEx() returns if it does not recognize\r
-        // the relocation type.\r
-        //\r
-        ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
-        return RETURN_UNSUPPORTED;\r
-\r
-      default:\r
-        switch (MachineType) {\r
-        case EFI_IMAGE_MACHINE_IA32:\r
-          Status = PeCoffLoaderRelocateIa32Image (Reloc, Fixup, &FixupData, Adjust);\r
-          break;\r
-        case EFI_IMAGE_MACHINE_X64:\r
-          Status = PeCoffLoaderRelocateX64Image (Reloc, Fixup, &FixupData, Adjust);\r
-          break;\r
-        case EFI_IMAGE_MACHINE_IA64:\r
-          Status = PeCoffLoaderRelocateIpfImage (Reloc, Fixup, &FixupData, Adjust);\r
-          break;\r
-        default:\r
-          Status = RETURN_UNSUPPORTED;\r
-          break;\r
-        }\r
-        if (RETURN_ERROR (Status)) {\r
-          ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
-          return Status;\r
-        }\r
-      }\r
-\r
-      //\r
-      // Next relocation record\r
-      //\r
-      Reloc += 1;\r
-    }\r
-\r
-    //\r
-    // Next reloc block\r
-    //\r
-    RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd;\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-RETURN_STATUS\r
-EFIAPI\r
-PeCoffLoaderLoadImage (\r
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Loads a PE/COFF image into memory\r
-\r
-Arguments:\r
-\r
-  This         - Calling context\r
-\r
-  ImageContext - Contains information on image to load into memory\r
-\r
-Returns:\r
-\r
-  RETURN_SUCCESS            if the PE/COFF image was loaded\r
-  RETURN_BUFFER_TOO_SMALL   if the caller did not provide a large enough buffer\r
-  RETURN_LOAD_ERROR         if the image is a runtime driver with no relocations\r
-  RETURN_INVALID_PARAMETER  if the image address is invalid\r
-\r
---*/\r
-{\r
-  RETURN_STATUS                         Status;\r
-  EFI_IMAGE_NT_HEADERS                  *PeHdr;\r
-  EFI_TE_IMAGE_HEADER                   *TeHdr;\r
-  PE_COFF_LOADER_IMAGE_CONTEXT          CheckContext;\r
-  EFI_IMAGE_SECTION_HEADER              *FirstSection;\r
-  EFI_IMAGE_SECTION_HEADER              *Section;\r
-  UINTN                                 NumberOfSections;\r
-  UINTN                                 Index;\r
-  CHAR8                                 *Base;\r
-  CHAR8                                 *End;\r
-  CHAR8                                 *MaxEnd;\r
-  EFI_IMAGE_DATA_DIRECTORY              *DirectoryEntry;\r
-  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       *DebugEntry;\r
-  UINTN                                 Size;\r
-  UINT32                                TempDebugEntryRva;\r
-  EFI_IMAGE_OPTIONAL_HEADER_POINTER     OptionHeader;\r
-\r
-  PeHdr = NULL;\r
-  TeHdr = NULL;\r
-  //\r
-  // Assume success\r
-  //\r
-  ImageContext->ImageError = IMAGE_ERROR_SUCCESS;\r
-\r
-  //\r
-  // Copy the provided context info into our local version, get what we\r
-  // can from the original image, and then use that to make sure everything\r
-  // is legit.\r
-  //\r
-  CopyMem (&CheckContext, ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT));\r
-\r
-  Status = PeCoffLoaderGetImageInfo (&CheckContext);\r
-  if (RETURN_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Make sure there is enough allocated space for the image being loaded\r
-  //\r
-  if (ImageContext->ImageSize < CheckContext.ImageSize) {\r
-    ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_SIZE;\r
-    return RETURN_BUFFER_TOO_SMALL;\r
-  }\r
-\r
-  //\r
-  // If there's no relocations, then make sure it's not a runtime driver,\r
-  // and that it's being loaded at the linked address.\r
-  //\r
-  if (CheckContext.RelocationsStripped) {\r
-    //\r
-    // If the image does not contain relocations and it is a runtime driver\r
-    // then return an error.\r
-    //\r
-    if (CheckContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {\r
-      ImageContext->ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;\r
-      return RETURN_LOAD_ERROR;\r
-    }\r
-    //\r
-    // If the image does not contain relocations, and the requested load address\r
-    // is not the linked address, then return an error.\r
-    //\r
-    if (CheckContext.ImageAddress != ImageContext->ImageAddress) {\r
-      ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_ADDRESS;\r
-      return RETURN_INVALID_PARAMETER;\r
-    }\r
-  }\r
-  //\r
-  // Make sure the allocated space has the proper section alignment\r
-  //\r
-  if (!(ImageContext->IsTeImage)) {\r
-    if ((ImageContext->ImageAddress & (CheckContext.SectionAlignment - 1)) != 0) {\r
-      ImageContext->ImageError = IMAGE_ERROR_INVALID_SECTION_ALIGNMENT;\r
-      return RETURN_INVALID_PARAMETER;\r
-    }\r
-  }\r
-  //\r
-  // Read the entire PE/COFF or TE header into memory\r
-  //\r
-  if (!(ImageContext->IsTeImage)) {\r
-    Status = ImageContext->ImageRead (\r
-                            ImageContext->Handle,\r
-                            0,\r
-                            &ImageContext->SizeOfHeaders,\r
-                            (VOID *) (UINTN) ImageContext->ImageAddress\r
-                            );\r
-\r
-    PeHdr = (EFI_IMAGE_NT_HEADERS *)\r
-      ((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset);\r
-\r
-    OptionHeader.Header = (VOID *) &(PeHdr->OptionalHeader);\r
-    \r
-    FirstSection = (EFI_IMAGE_SECTION_HEADER *) (\r
-                      (UINTN)ImageContext->ImageAddress +\r
-                      ImageContext->PeCoffHeaderOffset +\r
-                      sizeof(UINT32) + \r
-                      sizeof(EFI_IMAGE_FILE_HEADER) + \r
-                      PeHdr->FileHeader.SizeOfOptionalHeader\r
-      );\r
-    NumberOfSections = (UINTN) (PeHdr->FileHeader.NumberOfSections);\r
-  } else {\r
-    Status = ImageContext->ImageRead (\r
-                            ImageContext->Handle,\r
-                            0,\r
-                            &ImageContext->SizeOfHeaders,\r
-                            (void *) (UINTN) ImageContext->ImageAddress\r
-                            );\r
-\r
-    TeHdr             = (EFI_TE_IMAGE_HEADER *) (UINTN) (ImageContext->ImageAddress);\r
-\r
-    FirstSection = (EFI_IMAGE_SECTION_HEADER *) (\r
-          (UINTN)ImageContext->ImageAddress +\r
-          sizeof(EFI_TE_IMAGE_HEADER)\r
-          );\r
-    NumberOfSections  = (UINTN) (TeHdr->NumberOfSections);\r
-\r
-  }\r
-\r
-  if (RETURN_ERROR (Status)) {\r
-    ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-    return RETURN_LOAD_ERROR;\r
-  }\r
-\r
-  //\r
-  // Load each section of the image\r
-  //\r
-  Section = FirstSection;\r
-  for (Index = 0, MaxEnd = NULL; Index < NumberOfSections; Index++) {\r
-\r
-    //\r
-    // Compute sections address\r
-    //\r
-    Base = PeCoffLoaderImageAddress (ImageContext, Section->VirtualAddress);\r
-    End = PeCoffLoaderImageAddress (\r
-            ImageContext,\r
-            Section->VirtualAddress + Section->Misc.VirtualSize - 1\r
-            );\r
-    if (ImageContext->IsTeImage) {\r
-      Base  = (CHAR8 *) ((UINTN) Base + sizeof (EFI_TE_IMAGE_HEADER) - (UINTN) TeHdr->StrippedSize);\r
-      End   = (CHAR8 *) ((UINTN) End + sizeof (EFI_TE_IMAGE_HEADER) - (UINTN) TeHdr->StrippedSize);\r
-    }\r
-\r
-    if (End > MaxEnd) {\r
-      MaxEnd = End;\r
-    }\r
-    //\r
-    // If the base start or end address resolved to 0, then fail.\r
-    //\r
-    if ((Base == NULL) || (End == NULL)) {\r
-      ImageContext->ImageError = IMAGE_ERROR_SECTION_NOT_LOADED;\r
-      return RETURN_LOAD_ERROR;\r
-    }\r
-\r
-    //\r
-    // Read the section\r
-    //\r
-    Size = (UINTN) Section->Misc.VirtualSize;\r
-    if ((Size == 0) || (Size > Section->SizeOfRawData)) {\r
-      Size = (UINTN) Section->SizeOfRawData;\r
-    }\r
-\r
-    if (Section->SizeOfRawData) {\r
-      if (!(ImageContext->IsTeImage)) {\r
-        Status = ImageContext->ImageRead (\r
-                                ImageContext->Handle,\r
-                                Section->PointerToRawData,\r
-                                &Size,\r
-                                Base\r
-                                );\r
-      } else {\r
-        Status = ImageContext->ImageRead (\r
-                                ImageContext->Handle,\r
-                                Section->PointerToRawData + sizeof (EFI_TE_IMAGE_HEADER) - (UINTN) TeHdr->StrippedSize,\r
-                                &Size,\r
-                                Base\r
-                                );\r
-      }\r
-\r
-      if (RETURN_ERROR (Status)) {\r
-        ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-        return Status;\r
-      }\r
-    }\r
-\r
-    //\r
-    // If raw size is less then virt size, zero fill the remaining\r
-    //\r
-\r
-    if (Size < Section->Misc.VirtualSize) {\r
-      ZeroMem (Base + Size, Section->Misc.VirtualSize - Size);\r
-    }\r
-\r
-    //\r
-    // Next Section\r
-    //\r
-    Section += 1;\r
-  }\r
-\r
-  //\r
-  // Get image's entry point\r
-  //\r
-  if (!(ImageContext->IsTeImage)) {\r
-    ImageContext->EntryPoint = (PHYSICAL_ADDRESS) (UINTN) PeCoffLoaderImageAddress (\r
-                                                                ImageContext,\r
-                                                                PeHdr->OptionalHeader.AddressOfEntryPoint\r
-                                                                );\r
-  } else {\r
-    ImageContext->EntryPoint =  (PHYSICAL_ADDRESS) (\r
-                       (UINTN)ImageContext->ImageAddress +\r
-                       (UINTN)TeHdr->AddressOfEntryPoint +\r
-                       (UINTN)sizeof(EFI_TE_IMAGE_HEADER) -\r
-          (UINTN) TeHdr->StrippedSize\r
-      );\r
-  }\r
-\r
-  //\r
-  // Determine the size of the fixup data\r
-  //\r
-  // Per the PE/COFF spec, you can't assume that a given data directory\r
-  // is present in the image. You have to check the NumberOfRvaAndSizes in\r
-  // the optional header to verify a desired directory entry is there.\r
-  //\r
-  if (!(ImageContext->IsTeImage)) {\r
-    if (ImageContext->Machine == EFI_IMAGE_MACHINE_IA32) {\r
-      if (OptionHeader.Optional32->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
-        DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)\r
-          &OptionHeader.Optional32->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r
-        ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN);\r
-      } else {\r
-        ImageContext->FixupDataSize = 0;\r
-      }\r
-    } else {\r
-      if (OptionHeader.Optional64->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
-        DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)\r
-          &OptionHeader.Optional64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r
-        ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN);\r
-      } else {\r
-        ImageContext->FixupDataSize = 0;\r
-      }\r
-    }\r
-  } else {\r
-    DirectoryEntry              = &TeHdr->DataDirectory[0];\r
-    ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN);\r
-  }\r
-  //\r
-  // Consumer must allocate a buffer for the relocation fixup log.\r
-  // Only used for runtime drivers.\r
-  //\r
-  ImageContext->FixupData = NULL;\r
-\r
-  //\r
-  // Load the Codeview info if present\r
-  //\r
-  if (ImageContext->DebugDirectoryEntryRva != 0) {\r
-    if (!(ImageContext->IsTeImage)) {\r
-      DebugEntry = PeCoffLoaderImageAddress (\r
-                    ImageContext,\r
-                    ImageContext->DebugDirectoryEntryRva\r
-                    );\r
-    } else {\r
-      DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)(UINTN)(\r
-                                               ImageContext->ImageAddress +\r
-                                               ImageContext->DebugDirectoryEntryRva +\r
-                                               sizeof(EFI_TE_IMAGE_HEADER) -\r
-                                               TeHdr->StrippedSize\r
-                                               );\r
-    }\r
-\r
-    if (DebugEntry != NULL) {\r
-      TempDebugEntryRva = DebugEntry->RVA;\r
-      if (DebugEntry->RVA == 0 && DebugEntry->FileOffset != 0) {\r
-        Section--;\r
-        if ((UINTN) Section->SizeOfRawData < Section->Misc.VirtualSize) {\r
-          TempDebugEntryRva = Section->VirtualAddress + Section->Misc.VirtualSize;\r
-        } else {\r
-          TempDebugEntryRva = Section->VirtualAddress + Section->SizeOfRawData;\r
-        }\r
-      }\r
-\r
-      if (TempDebugEntryRva != 0) {\r
-        if (!(ImageContext->IsTeImage)) {\r
-          ImageContext->CodeView = PeCoffLoaderImageAddress (ImageContext, TempDebugEntryRva);\r
-        } else {\r
-          ImageContext->CodeView = (VOID *)(\r
-                      (UINTN)ImageContext->ImageAddress +\r
-                      (UINTN)TempDebugEntryRva +\r
-                      (UINTN)sizeof(EFI_TE_IMAGE_HEADER) -\r
-                (UINTN) TeHdr->StrippedSize\r
-            );\r
-        }\r
-\r
-        if (ImageContext->CodeView == NULL) {\r
-          ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-          return RETURN_LOAD_ERROR;\r
-        }\r
-\r
-        if (DebugEntry->RVA == 0) {\r
-          Size = DebugEntry->SizeOfData;\r
-          if (!(ImageContext->IsTeImage)) {\r
-            Status = ImageContext->ImageRead (\r
-                                    ImageContext->Handle,\r
-                                    DebugEntry->FileOffset,\r
-                                    &Size,\r
-                                    ImageContext->CodeView\r
-                                    );\r
-          } else {\r
-            Status = ImageContext->ImageRead (\r
-                                    ImageContext->Handle,\r
-                                    DebugEntry->FileOffset + sizeof (EFI_TE_IMAGE_HEADER) - TeHdr->StrippedSize,\r
-                                    &Size,\r
-                                    ImageContext->CodeView\r
-                                    );\r
-            //\r
-            // Should we apply fix up to this field according to the size difference between PE and TE?\r
-            // Because now we maintain TE header fields unfixed, this field will also remain as they are\r
-            // in original PE image.\r
-            //\r
-          }\r
-\r
-          if (RETURN_ERROR (Status)) {\r
-            ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-            return RETURN_LOAD_ERROR;\r
-          }\r
-\r
-          DebugEntry->RVA = TempDebugEntryRva;\r
-        }\r
-\r
-        switch (*(UINT32 *) ImageContext->CodeView) {\r
-        case CODEVIEW_SIGNATURE_NB10:\r
-          ImageContext->PdbPointer = (CHAR8 *) ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);\r
-          break;\r
-\r
-        case CODEVIEW_SIGNATURE_RSDS:\r
-          ImageContext->PdbPointer = (CHAR8 *) ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);\r
-          break;\r
-\r
-        default:\r
-          break;\r
-        }\r
-      }\r
-    }\r
-  }\r
-\r
-  return Status;\r
-}\r
diff --git a/Source/C/PeCoffLoader/Makefile b/Source/C/PeCoffLoader/Makefile
deleted file mode 100644 (file)
index 1679cab..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-!INCLUDE ..\MSmakefile.common\r
-\r
-LIBNAME = PeCoffLoader\r
-\r
-OBJECTS = BasePeCoff.obj PeCoffLoaderEx.obj\r
-\r
-!INCLUDE ..\MSmakefile.lib\r
-\r
diff --git a/Source/C/PeCoffLoader/PeCoffLoaderEx.c b/Source/C/PeCoffLoader/PeCoffLoaderEx.c
deleted file mode 100644 (file)
index ea21e1d..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2004, 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
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-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
-    PeCoffLoaderEx.c\r
-\r
-Abstract:\r
-\r
-    IA32, X64 and IPF Specific relocation fixups\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#include <Common/UefiBaseTypes.h>\r
-#include <IndustryStandard/PeImage.h>\r
-#include <Library/PeCoffLib.h>\r
-\r
-#define EXT_IMM64(Value, Address, Size, InstPos, ValPos)  \\r
-    Value |= (((UINT64)((*(Address) >> InstPos) & (((UINT64)1 << Size) - 1))) << ValPos)\r
-\r
-#define INS_IMM64(Value, Address, Size, InstPos, ValPos)  \\r
-    *(UINT32*)Address = (*(UINT32*)Address & ~(((1 << Size) - 1) << InstPos)) | \\r
-          ((UINT32)((((UINT64)Value >> ValPos) & (((UINT64)1 << Size) - 1))) << InstPos)\r
-\r
-#define IMM64_IMM7B_INST_WORD_X         3  \r
-#define IMM64_IMM7B_SIZE_X              7  \r
-#define IMM64_IMM7B_INST_WORD_POS_X     4  \r
-#define IMM64_IMM7B_VAL_POS_X           0  \r
-\r
-#define IMM64_IMM9D_INST_WORD_X         3  \r
-#define IMM64_IMM9D_SIZE_X              9  \r
-#define IMM64_IMM9D_INST_WORD_POS_X     18  \r
-#define IMM64_IMM9D_VAL_POS_X           7  \r
-\r
-#define IMM64_IMM5C_INST_WORD_X         3  \r
-#define IMM64_IMM5C_SIZE_X              5  \r
-#define IMM64_IMM5C_INST_WORD_POS_X     13  \r
-#define IMM64_IMM5C_VAL_POS_X           16  \r
-\r
-#define IMM64_IC_INST_WORD_X            3  \r
-#define IMM64_IC_SIZE_X                 1  \r
-#define IMM64_IC_INST_WORD_POS_X        12  \r
-#define IMM64_IC_VAL_POS_X              21  \r
-\r
-#define IMM64_IMM41a_INST_WORD_X        1  \r
-#define IMM64_IMM41a_SIZE_X             10  \r
-#define IMM64_IMM41a_INST_WORD_POS_X    14  \r
-#define IMM64_IMM41a_VAL_POS_X          22  \r
-\r
-#define IMM64_IMM41b_INST_WORD_X        1  \r
-#define IMM64_IMM41b_SIZE_X             8  \r
-#define IMM64_IMM41b_INST_WORD_POS_X    24  \r
-#define IMM64_IMM41b_VAL_POS_X          32  \r
-\r
-#define IMM64_IMM41c_INST_WORD_X        2  \r
-#define IMM64_IMM41c_SIZE_X             23  \r
-#define IMM64_IMM41c_INST_WORD_POS_X    0  \r
-#define IMM64_IMM41c_VAL_POS_X          40  \r
-\r
-#define IMM64_SIGN_INST_WORD_X          3  \r
-#define IMM64_SIGN_SIZE_X               1  \r
-#define IMM64_SIGN_INST_WORD_POS_X      27  \r
-#define IMM64_SIGN_VAL_POS_X            63  \r
-\r
-RETURN_STATUS\r
-PeCoffLoaderRelocateIa32Image (\r
-  IN UINT16      *Reloc,\r
-  IN OUT CHAR8   *Fixup,\r
-  IN OUT CHAR8   **FixupData,\r
-  IN UINT64      Adjust\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Performs an IA-32 specific relocation fixup\r
-\r
-Arguments:\r
-\r
-  Reloc      - Pointer to the relocation record\r
-\r
-  Fixup      - Pointer to the address to fix up\r
-\r
-  FixupData  - Pointer to a buffer to log the fixups\r
-\r
-  Adjust     - The offset to adjust the fixup\r
-\r
-Returns:\r
-\r
-  EFI_UNSUPPORTED   - Unsupported now\r
-\r
---*/\r
-{\r
-  return RETURN_UNSUPPORTED;\r
-}\r
-\r
-RETURN_STATUS\r
-PeCoffLoaderRelocateIpfImage (\r
-  IN UINT16      *Reloc,\r
-  IN OUT CHAR8   *Fixup, \r
-  IN OUT CHAR8   **FixupData,\r
-  IN UINT64      Adjust\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Performs an Itanium-based specific relocation fixup\r
-\r
-Arguments:\r
-\r
-  Reloc      - Pointer to the relocation record\r
-\r
-  Fixup      - Pointer to the address to fix up\r
-\r
-  FixupData  - Pointer to a buffer to log the fixups\r
-\r
-  Adjust     - The offset to adjust the fixup\r
-\r
-Returns:\r
-\r
-  Status code\r
-\r
---*/\r
-{\r
-  UINT64      *F64;\r
-  UINT64      FixupVal;\r
-\r
-  switch ((*Reloc) >> 12) {\r
-\r
-    case EFI_IMAGE_REL_BASED_DIR64:\r
-      F64 = (UINT64 *) Fixup;\r
-      *F64 = *F64 + (UINT64) Adjust;\r
-      if (*FixupData != NULL) {\r
-        *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));\r
-        *(UINT64 *)(*FixupData) = *F64;\r
-        *FixupData = *FixupData + sizeof(UINT64);\r
-      }\r
-      break;\r
-\r
-    case EFI_IMAGE_REL_BASED_IA64_IMM64:\r
-\r
-      //\r
-      // Align it to bundle address before fixing up the\r
-      // 64-bit immediate value of the movl instruction.\r
-      //\r
-\r
-      Fixup = (CHAR8 *)((UINTN) Fixup & (UINTN) ~(15));\r
-      FixupVal = (UINT64)0;\r
-                       \r
-      // \r
-      // Extract the lower 32 bits of IMM64 from bundle\r
-      //\r
-      EXT_IMM64(FixupVal,\r
-                (UINT32 *)Fixup + IMM64_IMM7B_INST_WORD_X,\r
-                IMM64_IMM7B_SIZE_X,\r
-                IMM64_IMM7B_INST_WORD_POS_X,\r
-                IMM64_IMM7B_VAL_POS_X\r
-                );\r
-\r
-      EXT_IMM64(FixupVal,\r
-                (UINT32 *)Fixup + IMM64_IMM9D_INST_WORD_X,\r
-                IMM64_IMM9D_SIZE_X,\r
-                IMM64_IMM9D_INST_WORD_POS_X,\r
-                IMM64_IMM9D_VAL_POS_X\r
-                );\r
-\r
-      EXT_IMM64(FixupVal,\r
-                (UINT32 *)Fixup + IMM64_IMM5C_INST_WORD_X,\r
-                IMM64_IMM5C_SIZE_X,\r
-                IMM64_IMM5C_INST_WORD_POS_X,\r
-                IMM64_IMM5C_VAL_POS_X\r
-                );\r
-\r
-      EXT_IMM64(FixupVal,\r
-                (UINT32 *)Fixup + IMM64_IC_INST_WORD_X,\r
-                IMM64_IC_SIZE_X,\r
-                IMM64_IC_INST_WORD_POS_X,\r
-                IMM64_IC_VAL_POS_X\r
-                );\r
-\r
-      EXT_IMM64(FixupVal,\r
-                (UINT32 *)Fixup + IMM64_IMM41a_INST_WORD_X,\r
-                IMM64_IMM41a_SIZE_X,\r
-                IMM64_IMM41a_INST_WORD_POS_X,\r
-                IMM64_IMM41a_VAL_POS_X\r
-                );\r
-                       \r
-      // \r
-      // Update 64-bit address\r
-      //\r
-      FixupVal += Adjust;\r
-\r
-      // \r
-      // Insert IMM64 into bundle\r
-      //\r
-      INS_IMM64(FixupVal,\r
-                ((UINT32 *)Fixup + IMM64_IMM7B_INST_WORD_X),\r
-                IMM64_IMM7B_SIZE_X,\r
-                IMM64_IMM7B_INST_WORD_POS_X,\r
-                IMM64_IMM7B_VAL_POS_X\r
-                );\r
-\r
-      INS_IMM64(FixupVal,\r
-                ((UINT32 *)Fixup + IMM64_IMM9D_INST_WORD_X),\r
-                IMM64_IMM9D_SIZE_X,\r
-                IMM64_IMM9D_INST_WORD_POS_X,\r
-                IMM64_IMM9D_VAL_POS_X\r
-                );\r
-\r
-      INS_IMM64(FixupVal,\r
-                ((UINT32 *)Fixup + IMM64_IMM5C_INST_WORD_X),\r
-                IMM64_IMM5C_SIZE_X,\r
-                IMM64_IMM5C_INST_WORD_POS_X,\r
-                IMM64_IMM5C_VAL_POS_X\r
-                );\r
-\r
-      INS_IMM64(FixupVal,\r
-                ((UINT32 *)Fixup + IMM64_IC_INST_WORD_X),\r
-                IMM64_IC_SIZE_X,\r
-                IMM64_IC_INST_WORD_POS_X,\r
-                IMM64_IC_VAL_POS_X\r
-                );\r
-\r
-      INS_IMM64(FixupVal,\r
-                ((UINT32 *)Fixup + IMM64_IMM41a_INST_WORD_X),\r
-                IMM64_IMM41a_SIZE_X,\r
-                IMM64_IMM41a_INST_WORD_POS_X,\r
-                IMM64_IMM41a_VAL_POS_X\r
-                );\r
-\r
-      INS_IMM64(FixupVal,\r
-                ((UINT32 *)Fixup + IMM64_IMM41b_INST_WORD_X),\r
-                IMM64_IMM41b_SIZE_X,\r
-                IMM64_IMM41b_INST_WORD_POS_X,\r
-                IMM64_IMM41b_VAL_POS_X\r
-                );\r
-\r
-      INS_IMM64(FixupVal,\r
-                ((UINT32 *)Fixup + IMM64_IMM41c_INST_WORD_X),\r
-                IMM64_IMM41c_SIZE_X,\r
-                IMM64_IMM41c_INST_WORD_POS_X,\r
-                IMM64_IMM41c_VAL_POS_X\r
-                );\r
-\r
-      INS_IMM64(FixupVal,\r
-                ((UINT32 *)Fixup + IMM64_SIGN_INST_WORD_X),\r
-                IMM64_SIGN_SIZE_X,\r
-                IMM64_SIGN_INST_WORD_POS_X,\r
-                IMM64_SIGN_VAL_POS_X\r
-                );\r
-\r
-      F64 = (UINT64 *) Fixup;\r
-      if (*FixupData != NULL) {\r
-        *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));\r
-        *(UINT64 *)(*FixupData) = *F64;\r
-        *FixupData = *FixupData + sizeof(UINT64);\r
-      }\r
-      break;\r
-\r
-    default:\r
-      return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-RETURN_STATUS\r
-PeCoffLoaderRelocateX64Image (\r
-  IN     UINT16       *Reloc,\r
-  IN OUT CHAR8        *Fixup, \r
-  IN OUT CHAR8        **FixupData,\r
-  IN     UINT64       Adjust\r
-  )\r
-/**\r
-  Performs an x64 specific relocation fixup\r
-\r
-  @param Reloc        Pointer to the relocation record\r
-  @param Fixup        Pointer to the address to fix up\r
-  @param FixupData    Pointer to a buffer to log the fixups\r
-  @param Adjust       The offset to adjust the fixup\r
-  \r
-  @retval RETURN_SUCCESS      Success to perform relocation\r
-  @retval RETURN_UNSUPPORTED  Unsupported.\r
-**/\r
-{\r
-  UINT64      *F64;\r
-\r
-  switch ((*Reloc) >> 12) {\r
-\r
-    case EFI_IMAGE_REL_BASED_DIR64:\r
-      F64 = (UINT64 *) Fixup;\r
-      *F64 = *F64 + (UINT64) Adjust;\r
-      if (*FixupData != NULL) {\r
-        *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));\r
-        *(UINT64 *)(*FixupData) = *F64;\r
-        *FixupData = *FixupData + sizeof(UINT64);\r
-      }\r
-      break;\r
-\r
-    default:\r
-      return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r