Refactor the PeCoffLoader into a library. Add PeiRebase Tool.
authorbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 23 May 2006 22:00:58 +0000 (22:00 +0000)
committerbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 23 May 2006 22:00:58 +0000 (22:00 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@247 6f19259b-4bc3-4df7-8a09-765794883524

15 files changed:
Tools/Source/TianoTools/GenFvImage/BasePeCoff.c [deleted file]
Tools/Source/TianoTools/GenFvImage/Common/EfiImage.h [deleted file]
Tools/Source/TianoTools/GenFvImage/Ia32/PeCoffLoaderEx.c [deleted file]
Tools/Source/TianoTools/GenFvImage/Ipf/PeCoffLoaderEx.c [deleted file]
Tools/Source/TianoTools/GenFvImage/X64/PeCoffLoaderEx.c [deleted file]
Tools/Source/TianoTools/GenFvImage/build.xml
Tools/Source/TianoTools/PeCoffLoader/BasePeCoff.c [new file with mode: 0644]
Tools/Source/TianoTools/PeCoffLoader/Common/EfiImage.h [new file with mode: 0644]
Tools/Source/TianoTools/PeCoffLoader/Ia32/PeCoffLoaderEx.c [new file with mode: 0644]
Tools/Source/TianoTools/PeCoffLoader/Ipf/PeCoffLoaderEx.c [new file with mode: 0644]
Tools/Source/TianoTools/PeCoffLoader/X64/PeCoffLoaderEx.c [new file with mode: 0644]
Tools/Source/TianoTools/PeCoffLoader/build.xml [new file with mode: 0644]
Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c
Tools/Source/TianoTools/PeiRebase/build.xml [new file with mode: 0644]
Tools/Source/TianoTools/build.xml

diff --git a/Tools/Source/TianoTools/GenFvImage/BasePeCoff.c b/Tools/Source/TianoTools/GenFvImage/BasePeCoff.c
deleted file mode 100644 (file)
index b41a3a0..0000000
+++ /dev/null
@@ -1,1062 +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
-\r
-#define EFI_SPECIFICATION_VERSION    0x00000000\r
-#define EDK_RELEASE_VERSION          0x00020000\r
-#include <Base.h>\r
-#include <Library/PeCoffLib.h>\r
-#include <Library/BaseMemoryLib.h>\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
-\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
-  // Read the PE/COFF Header\r
-  //\r
-  Size = sizeof (EFI_IMAGE_NT_HEADERS);\r
-  Status = ImageContext->ImageRead (\r
-                          ImageContext->Handle,\r
-                          ImageContext->PeCoffHeaderOffset,\r
-                          &Size,\r
-                          PeHdr\r
-                          );\r
-  if (RETURN_ERROR (Status)) {\r
-    ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
-    return Status;\r
-  }\r
-  //\r
-  // Check the PE/COFF Header Signature. If not, then try to read a TE header\r
-  //\r
-  if (PeHdr->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
-    Size = sizeof (EFI_TE_IMAGE_HEADER);\r
-    Status = ImageContext->ImageRead (\r
-                            ImageContext->Handle,\r
-                            0,\r
-                            &Size,\r
-                            TeHdr\r
-                            );\r
-    if (TeHdr->Signature != EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
-      return RETURN_UNSUPPORTED;\r
-    }\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.  We support a native machine type (IA-32/Itanium-based)\r
-  // and the machine type for the Virtual Machine.\r
-  //\r
-  if (ImageContext->IsTeImage == FALSE) {\r
-    ImageContext->Machine = PeHdr->FileHeader.Machine;\r
-  } else {\r
-    ImageContext->Machine = TeHdr->Machine;\r
-  }\r
-\r
-  if (!(EFI_IMAGE_MACHINE_TYPE_SUPPORTED (ImageContext->Machine))) {\r
-    ImageContext->ImageError = IMAGE_ERROR_INVALID_MACHINE_TYPE;\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // See if the image type is supported.  We support EFI Applications,\r
-  // EFI Boot Service Drivers, and EFI Runtime Drivers.\r
-  //\r
-  if (ImageContext->IsTeImage == FALSE) {\r
-    ImageContext->ImageType = PeHdr->OptionalHeader.Subsystem;\r
-  } else {\r
-    ImageContext->ImageType = (UINT16) (TeHdr->Subsystem);\r
-  }\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
-\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
-  // Verify machine type\r
-  //\r
-  Status = PeCoffLoaderCheckImageType (ImageContext, &PeHdr, &TeHdr);\r
-  if (RETURN_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  //\r
-  // Retrieve the base address of the image\r
-  //\r
-  if (!(ImageContext->IsTeImage)) {\r
-    ImageContext->ImageAddress = PeHdr.OptionalHeader.ImageBase;\r
-  } else {\r
-    ImageContext->ImageAddress = (PHYSICAL_ADDRESS) (TeHdr.ImageBase);\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
-    ImageContext->ImageSize         = (UINT64) PeHdr.OptionalHeader.SizeOfImage;\r
-    ImageContext->SectionAlignment  = PeHdr.OptionalHeader.SectionAlignment;\r
-    ImageContext->SizeOfHeaders     = PeHdr.OptionalHeader.SizeOfHeaders;\r
-\r
-    //\r
-    // Modify ImageSize to contain .PDB file name if required and initialize\r
-    // PdbRVA field...\r
-    //\r
-    if (PeHdr.OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
-      DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(PeHdr.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-\r
-      DebugDirectoryEntryRva = DebugDirectoryEntry->VirtualAddress;\r
-\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++) {\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 * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY));\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++) {\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 * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY));\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 (CHAR8 *) ((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
-\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
-    Adjust = (UINT64) BaseAddress - PeHdr->OptionalHeader.ImageBase;\r
-    PeHdr->OptionalHeader.ImageBase = (UINTN) BaseAddress;\r
-\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 (PeHdr->OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
-      RelocDir  = &PeHdr->OptionalHeader.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
-    TeHdr             = (EFI_TE_IMAGE_HEADER *) (UINTN) (ImageContext->ImageAddress);\r
-    Adjust            = (UINT64) (BaseAddress - TeHdr->ImageBase);\r
-    TeHdr->ImageBase  = (UINT64) (BaseAddress);\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 << 16) + (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_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
-        Status = PeCoffLoaderRelocateImageEx (Reloc, Fixup, &FixupData, Adjust);\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
-\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
-    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 (PeHdr->OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
-      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)\r
-        &PeHdr->OptionalHeader.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
-    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/Tools/Source/TianoTools/GenFvImage/Common/EfiImage.h b/Tools/Source/TianoTools/GenFvImage/Common/EfiImage.h
deleted file mode 100644 (file)
index 0ad71d3..0000000
+++ /dev/null
@@ -1,701 +0,0 @@
-/** @file\r
-       EFI image format for PE32+. Please note some data structures are different\r
-       for IA-32 and Itanium-based images, look for UINTN and the #ifdef EFI_IA64\r
-\r
-       @bug Fix text - doc as defined in MSFT EFI specification.\r
-\r
-       Copyright (c) 2006, 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:    EfiImage.h\r
-\r
-**/\r
-\r
-#ifndef __EFI_IMAGE_H__\r
-#define __EFI_IMAGE_H__\r
-\r
-//\r
-// PE32+ Subsystem type for EFI images\r
-//\r
-#define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION         10\r
-#define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11\r
-#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER      12\r
-#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER      13\r
-\r
-//\r
-// BugBug: Need to get a real answer for this problem. This is not in the\r
-//         PE specification.\r
-//\r
-//         A SAL runtime driver does not get fixed up when a transition to\r
-//         virtual mode is made. In all other cases it should be treated\r
-//         like a EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER image\r
-//\r
-#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER  13\r
-\r
-//\r
-// PE32+ Machine type for EFI images\r
-//\r
-#define IMAGE_FILE_MACHINE_I386     0x014c\r
-#define IMAGE_FILE_MACHINE_IA64     0x0200\r
-#define IMAGE_FILE_MACHINE_EBC      0x0EBC\r
-#define IMAGE_FILE_MACHINE_X64      0x8664\r
-//\r
-// Support old names for backward compatible\r
-//\r
-#define EFI_IMAGE_MACHINE_IA32      IMAGE_FILE_MACHINE_I386 \r
-#define EFI_IMAGE_MACHINE_IA64      IMAGE_FILE_MACHINE_IA64  \r
-#define EFI_IMAGE_MACHINE_IPF       IMAGE_FILE_MACHINE_IA64  \r
-#define EFI_IMAGE_MACHINE_EBC       IMAGE_FILE_MACHINE_EBC  \r
-#define EFI_IMAGE_MACHINE_X64       IMAGE_FILE_MACHINE_X64\r
-\r
-#define EFI_IMAGE_DOS_SIGNATURE     0x5A4D      // MZ\r
-#define EFI_IMAGE_OS2_SIGNATURE     0x454E      // NE\r
-#define EFI_IMAGE_OS2_SIGNATURE_LE  0x454C      // LE\r
-#define EFI_IMAGE_NT_SIGNATURE      0x00004550  // PE00\r
-#define EFI_IMAGE_EDOS_SIGNATURE    0x44454550  // PEED\r
-\r
-///\r
-/// PE images can start with an optional DOS header, so if an image is run\r
-///  under DOS it can print an error message.\r
-///\r
-typedef struct {\r
-  UINT16  e_magic;    // Magic number\r
-  UINT16  e_cblp;     // Bytes on last page of file\r
-  UINT16  e_cp;       // Pages in file\r
-  UINT16  e_crlc;     // Relocations\r
-  UINT16  e_cparhdr;  // Size of header in paragraphs\r
-  UINT16  e_minalloc; // Minimum extra paragraphs needed\r
-  UINT16  e_maxalloc; // Maximum extra paragraphs needed\r
-  UINT16  e_ss;       // Initial (relative) SS value\r
-  UINT16  e_sp;       // Initial SP value\r
-  UINT16  e_csum;     // Checksum\r
-  UINT16  e_ip;       // Initial IP value\r
-  UINT16  e_cs;       // Initial (relative) CS value\r
-  UINT16  e_lfarlc;   // File address of relocation table\r
-  UINT16  e_ovno;     // Overlay number\r
-  UINT16  e_res[4];   // Reserved words\r
-  UINT16  e_oemid;    // OEM identifier (for e_oeminfo)\r
-  UINT16  e_oeminfo;  // OEM information; e_oemid specific\r
-  UINT16  e_res2[10]; // Reserved words\r
-  UINT32  e_lfanew;   // File address of new exe header\r
-} EFI_IMAGE_DOS_HEADER;\r
-\r
-///\r
-/// File header format.\r
-///\r
-typedef struct {\r
-  UINT16  Machine;\r
-  UINT16  NumberOfSections;\r
-  UINT32  TimeDateStamp;\r
-  UINT32  PointerToSymbolTable;\r
-  UINT32  NumberOfSymbols;\r
-  UINT16  SizeOfOptionalHeader;\r
-  UINT16  Characteristics;\r
-} EFI_IMAGE_FILE_HEADER;\r
-\r
-#define EFI_IMAGE_SIZEOF_FILE_HEADER        20\r
-\r
-#define EFI_IMAGE_FILE_RELOCS_STRIPPED      0x0001  // Relocation info stripped from file.\r
-#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE     0x0002  // File is executable  (i.e. no unresolved externel references).\r
-#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED   0x0004  // Line nunbers stripped from file.\r
-#define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008  // Local symbols stripped from file.\r
-#define EFI_IMAGE_FILE_BYTES_REVERSED_LO    0x0080  // Bytes of machine word are reversed.\r
-#define EFI_IMAGE_FILE_32BIT_MACHINE        0x0100  // 32 bit word machine.\r
-#define EFI_IMAGE_FILE_DEBUG_STRIPPED       0x0200  // Debugging info stripped from file in .DBG file\r
-#define EFI_IMAGE_FILE_SYSTEM               0x1000  // System File.\r
-#define EFI_IMAGE_FILE_DLL                  0x2000  // File is a DLL.\r
-#define EFI_IMAGE_FILE_BYTES_REVERSED_HI    0x8000  // Bytes of machine word are reversed.\r
-#define EFI_IMAGE_FILE_MACHINE_UNKNOWN      0\r
-#define EFI_IMAGE_FILE_MACHINE_I386         0x14c   // Intel 386.\r
-#define EFI_IMAGE_FILE_MACHINE_R3000        0x162   // MIPS* little-endian, 0540 big-endian\r
-#define EFI_IMAGE_FILE_MACHINE_R4000        0x166   // MIPS* little-endian\r
-#define EFI_IMAGE_FILE_MACHINE_ALPHA        0x184   // Alpha_AXP*\r
-#define EFI_IMAGE_FILE_MACHINE_POWERPC      0x1F0   // IBM* PowerPC Little-Endian\r
-#define EFI_IMAGE_FILE_MACHINE_TAHOE        0x7cc   // Intel EM machine\r
-//\r
-// * Other names and brands may be claimed as the property of others.\r
-//\r
-\r
-///\r
-/// Directory format.\r
-///\r
-typedef struct {\r
-  UINT32  VirtualAddress;\r
-  UINT32  Size;\r
-} EFI_IMAGE_DATA_DIRECTORY;\r
-\r
-#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16\r
-\r
-typedef struct {\r
-  UINT16  Magic;\r
-  UINT8   MajorLinkerVersion;\r
-  UINT8   MinorLinkerVersion;\r
-  UINT32  SizeOfCode;\r
-  UINT32  SizeOfInitializedData;\r
-  UINT32  SizeOfUninitializedData;\r
-  UINT32  AddressOfEntryPoint;\r
-  UINT32  BaseOfCode;\r
-  UINT32  BaseOfData;\r
-  UINT32  BaseOfBss;\r
-  UINT32  GprMask;\r
-  UINT32  CprMask[4];\r
-  UINT32  GpValue;\r
-} EFI_IMAGE_ROM_OPTIONAL_HEADER;\r
-\r
-#define EFI_IMAGE_ROM_OPTIONAL_HDR_MAGIC      0x107\r
-#define EFI_IMAGE_SIZEOF_ROM_OPTIONAL_HEADER  sizeof (EFI_IMAGE_ROM_OPTIONAL_HEADER)\r
-\r
-typedef struct {\r
-  EFI_IMAGE_FILE_HEADER         FileHeader;\r
-  EFI_IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;\r
-} EFI_IMAGE_ROM_HEADERS;\r
-\r
-///\r
-/// @attention\r
-/// EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64\r
-/// are for use ONLY by tools.  All proper EFI code MUST use\r
-/// EFI_IMAGE_OPTIONAL_HEADER ONLY!!!\r
-///\r
-#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b\r
-\r
-typedef struct {\r
-  //\r
-  // Standard fields.\r
-  //\r
-  UINT16                    Magic;\r
-  UINT8                     MajorLinkerVersion;\r
-  UINT8                     MinorLinkerVersion;\r
-  UINT32                    SizeOfCode;\r
-  UINT32                    SizeOfInitializedData;\r
-  UINT32                    SizeOfUninitializedData;\r
-  UINT32                    AddressOfEntryPoint;\r
-  UINT32                    BaseOfCode;\r
-  UINT32                    BaseOfData;\r
-  //\r
-  // NT additional fields.\r
-  //\r
-  UINT32                    ImageBase;\r
-  UINT32                    SectionAlignment;\r
-  UINT32                    FileAlignment;\r
-  UINT16                    MajorOperatingSystemVersion;\r
-  UINT16                    MinorOperatingSystemVersion;\r
-  UINT16                    MajorImageVersion;\r
-  UINT16                    MinorImageVersion;\r
-  UINT16                    MajorSubsystemVersion;\r
-  UINT16                    MinorSubsystemVersion;\r
-  UINT32                    Win32VersionValue;\r
-  UINT32                    SizeOfImage;\r
-  UINT32                    SizeOfHeaders;\r
-  UINT32                    CheckSum;\r
-  UINT16                    Subsystem;\r
-  UINT16                    DllCharacteristics;\r
-  UINT32                    SizeOfStackReserve;\r
-  UINT32                    SizeOfStackCommit;\r
-  UINT32                    SizeOfHeapReserve;\r
-  UINT32                    SizeOfHeapCommit;\r
-  UINT32                    LoaderFlags;\r
-  UINT32                    NumberOfRvaAndSizes;\r
-  EFI_IMAGE_DATA_DIRECTORY  DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];\r
-} EFI_IMAGE_OPTIONAL_HEADER32;\r
-\r
-///\r
-/// @attention\r
-/// EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64\r
-/// are for use ONLY by tools.  All proper EFI code MUST use\r
-/// EFI_IMAGE_OPTIONAL_HEADER ONLY!!!\r
-///\r
-#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b\r
-\r
-typedef struct {\r
-  //\r
-  // Standard fields.\r
-  //\r
-  UINT16                    Magic;\r
-  UINT8                     MajorLinkerVersion;\r
-  UINT8                     MinorLinkerVersion;\r
-  UINT32                    SizeOfCode;\r
-  UINT32                    SizeOfInitializedData;\r
-  UINT32                    SizeOfUninitializedData;\r
-  UINT32                    AddressOfEntryPoint;\r
-  UINT32                    BaseOfCode;\r
-  //\r
-  // NT additional fields.\r
-  //\r
-  UINT64                    ImageBase;\r
-  UINT32                    SectionAlignment;\r
-  UINT32                    FileAlignment;\r
-  UINT16                    MajorOperatingSystemVersion;\r
-  UINT16                    MinorOperatingSystemVersion;\r
-  UINT16                    MajorImageVersion;\r
-  UINT16                    MinorImageVersion;\r
-  UINT16                    MajorSubsystemVersion;\r
-  UINT16                    MinorSubsystemVersion;\r
-  UINT32                    Win32VersionValue;\r
-  UINT32                    SizeOfImage;\r
-  UINT32                    SizeOfHeaders;\r
-  UINT32                    CheckSum;\r
-  UINT16                    Subsystem;\r
-  UINT16                    DllCharacteristics;\r
-  UINT64                    SizeOfStackReserve;\r
-  UINT64                    SizeOfStackCommit;\r
-  UINT64                    SizeOfHeapReserve;\r
-  UINT64                    SizeOfHeapCommit;\r
-  UINT32                    LoaderFlags;\r
-  UINT32                    NumberOfRvaAndSizes;\r
-  EFI_IMAGE_DATA_DIRECTORY  DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];\r
-} EFI_IMAGE_OPTIONAL_HEADER64;\r
-\r
-///\r
-/// @attention\r
-/// EFI_IMAGE_NT_HEADERS32 and EFI_IMAGE_HEADERS64 are for use ONLY\r
-/// by tools.  All proper EFI code MUST use EFI_IMAGE_NT_HEADERS ONLY!!!\r
-///\r
-typedef struct {\r
-  UINT32                      Signature;\r
-  EFI_IMAGE_FILE_HEADER       FileHeader;\r
-  EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader;\r
-} EFI_IMAGE_NT_HEADERS32;\r
-\r
-#define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof (EFI_IMAGE_NT_HEADERS32)\r
-\r
-typedef struct {\r
-  UINT32                      Signature;\r
-  EFI_IMAGE_FILE_HEADER       FileHeader;\r
-  EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader;\r
-} EFI_IMAGE_NT_HEADERS64;\r
-\r
-#define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof (EFI_IMAGE_NT_HEADERS64)\r
-\r
-//\r
-// Processor specific definition of EFI_IMAGE_OPTIONAL_HEADER so the\r
-// type name EFI_IMAGE_OPTIONAL_HEADER is appropriate to the build.  Same for\r
-// EFI_IMAGE_NT_HEADERS.  These definitions MUST be used by ALL EFI code.\r
-//\r
-#if   defined (MDE_CPU_IA32) && !defined (BUILDING_TOOLS) || \\r
-      defined (BUILDING_TOOLS) && defined (TOOL_BUILD_IA32_TARGET)\r
-\r
-// typedef EFI_IMAGE_OPTIONAL_HEADER32     EFI_IMAGE_OPTIONAL_HEADER;\r
-typedef EFI_IMAGE_NT_HEADERS32          EFI_IMAGE_NT_HEADERS;\r
-\r
-#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC\r
-#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \\r
-  (((Machine) == EFI_IMAGE_MACHINE_IA32) || ((Machine) == EFI_IMAGE_MACHINE_EBC))\r
-\r
-#elif defined (MDE_CPU_IPF) && !defined (BUILDING_TOOLS) || \\r
-      defined (BUILDING_TOOLS) && defined (TOOL_BUILD_IPF_TARGET)\r
-\r
-typedef EFI_IMAGE_OPTIONAL_HEADER64     EFI_IMAGE_OPTIONAL_HEADER;\r
-typedef EFI_IMAGE_NT_HEADERS64          EFI_IMAGE_NT_HEADERS;\r
-\r
-#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
-#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \\r
-  (((Machine) == EFI_IMAGE_MACHINE_IPF) || ((Machine) == EFI_IMAGE_MACHINE_EBC))\r
-\r
-#elif defined (MDE_CPU_X64) && !defined (BUILDING_TOOLS) || \\r
-      defined (BUILDING_TOOLS) && defined (TOOL_BUILD_X64_TARGET)\r
-\r
-typedef EFI_IMAGE_OPTIONAL_HEADER64     EFI_IMAGE_OPTIONAL_HEADER;\r
-typedef EFI_IMAGE_NT_HEADERS64          EFI_IMAGE_NT_HEADERS;\r
-\r
-#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
-#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \\r
-  (((Machine) == EFI_IMAGE_MACHINE_X64) || ((Machine) == EFI_IMAGE_MACHINE_EBC))\r
-\r
-#elif defined (MDE_CPU_EBC)\r
-\r
-//\r
-// This is just to make sure you can cross compile with the EBC compiiler.\r
-// It does not make sense to have a PE loader coded in EBC. You need to \r
-// understand the basic \r
-//\r
-typedef EFI_IMAGE_OPTIONAL_HEADER64     EFI_IMAGE_OPTIONAL_HEADER;\r
-typedef EFI_IMAGE_NT_HEADERS64          EFI_IMAGE_NT_HEADERS;\r
-\r
-#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
-#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) ((Machine) == EFI_IMAGE_MACHINE_EBC)\r
-\r
-#else\r
-#error Unknown Processor Type\r
-#endif\r
-\r
-\r
-#define EFI_IMAGE_FIRST_SECTION(ntheader) \\r
-    ( \\r
-      (EFI_IMAGE_SECTION_HEADER *) \\r
-        ( \\r
-          (UINT32) ntheader + \\r
-          FIELD_OFFSET (EFI_IMAGE_NT_HEADERS, OptionalHeader) + \\r
-          ((EFI_IMAGE_NT_HEADERS *) (ntheader))->FileHeader.SizeOfOptionalHeader \\r
-        ) \\r
-    )\r
-\r
-//\r
-// Subsystem Values\r
-//\r
-#define EFI_IMAGE_SUBSYSTEM_UNKNOWN     0\r
-#define EFI_IMAGE_SUBSYSTEM_NATIVE      1\r
-#define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2\r
-#define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3.\r
-#define EFI_IMAGE_SUBSYSTEM_OS2_CUI     5\r
-#define EFI_IMAGE_SUBSYSTEM_POSIX_CUI   7\r
-\r
-//\r
-// Directory Entries\r
-//\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT      0\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT      1\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE    2\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION   3\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY    4\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC   5\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG       6\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT   7\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR   8\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_TLS         9\r
-#define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10\r
-\r
-//\r
-// Section header format.\r
-//\r
-#define EFI_IMAGE_SIZEOF_SHORT_NAME 8\r
-\r
-typedef struct {\r
-  UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];\r
-  union {\r
-    UINT32  PhysicalAddress;\r
-    UINT32  VirtualSize;\r
-  } Misc;\r
-  UINT32  VirtualAddress;\r
-  UINT32  SizeOfRawData;\r
-  UINT32  PointerToRawData;\r
-  UINT32  PointerToRelocations;\r
-  UINT32  PointerToLinenumbers;\r
-  UINT16  NumberOfRelocations;\r
-  UINT16  NumberOfLinenumbers;\r
-  UINT32  Characteristics;\r
-} EFI_IMAGE_SECTION_HEADER;\r
-\r
-#define EFI_IMAGE_SIZEOF_SECTION_HEADER       40\r
-\r
-#define EFI_IMAGE_SCN_TYPE_NO_PAD             0x00000008  // Reserved.\r
-#define EFI_IMAGE_SCN_CNT_CODE                0x00000020\r
-#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA    0x00000040\r
-#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA  0x00000080\r
-\r
-#define EFI_IMAGE_SCN_LNK_OTHER               0x00000100  // Reserved.\r
-#define EFI_IMAGE_SCN_LNK_INFO                0x00000200  // Section contains comments or some other type of information.\r
-#define EFI_IMAGE_SCN_LNK_REMOVE              0x00000800  // Section contents will not become part of image.\r
-#define EFI_IMAGE_SCN_LNK_COMDAT              0x00001000\r
-\r
-#define EFI_IMAGE_SCN_ALIGN_1BYTES            0x00100000\r
-#define EFI_IMAGE_SCN_ALIGN_2BYTES            0x00200000\r
-#define EFI_IMAGE_SCN_ALIGN_4BYTES            0x00300000\r
-#define EFI_IMAGE_SCN_ALIGN_8BYTES            0x00400000\r
-#define EFI_IMAGE_SCN_ALIGN_16BYTES           0x00500000\r
-#define EFI_IMAGE_SCN_ALIGN_32BYTES           0x00600000\r
-#define EFI_IMAGE_SCN_ALIGN_64BYTES           0x00700000\r
-\r
-#define EFI_IMAGE_SCN_MEM_DISCARDABLE         0x02000000\r
-#define EFI_IMAGE_SCN_MEM_NOT_CACHED          0x04000000\r
-#define EFI_IMAGE_SCN_MEM_NOT_PAGED           0x08000000\r
-#define EFI_IMAGE_SCN_MEM_SHARED              0x10000000\r
-#define EFI_IMAGE_SCN_MEM_EXECUTE             0x20000000\r
-#define EFI_IMAGE_SCN_MEM_READ                0x40000000\r
-#define EFI_IMAGE_SCN_MEM_WRITE               0x80000000\r
-\r
-///\r
-/// Symbol format.\r
-///\r
-#define EFI_IMAGE_SIZEOF_SYMBOL 18\r
-\r
-//\r
-// Section values.\r
-//\r
-// Symbols have a section number of the section in which they are\r
-// defined. Otherwise, section numbers have the following meanings:\r
-//\r
-#define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0  // Symbol is undefined or is common.\r
-#define EFI_IMAGE_SYM_ABSOLUTE  (UINT16) -1 // Symbol is an absolute value.\r
-#define EFI_IMAGE_SYM_DEBUG     (UINT16) -2 // Symbol is a special debug item.\r
-//\r
-// Type (fundamental) values.\r
-//\r
-#define EFI_IMAGE_SYM_TYPE_NULL   0   // no type.\r
-#define EFI_IMAGE_SYM_TYPE_VOID   1   //\r
-#define EFI_IMAGE_SYM_TYPE_CHAR   2   // type character.\r
-#define EFI_IMAGE_SYM_TYPE_SHORT  3   // type short integer.\r
-#define EFI_IMAGE_SYM_TYPE_INT    4\r
-#define EFI_IMAGE_SYM_TYPE_LONG   5\r
-#define EFI_IMAGE_SYM_TYPE_FLOAT  6\r
-#define EFI_IMAGE_SYM_TYPE_DOUBLE 7\r
-#define EFI_IMAGE_SYM_TYPE_STRUCT 8\r
-#define EFI_IMAGE_SYM_TYPE_UNION  9\r
-#define EFI_IMAGE_SYM_TYPE_ENUM   10  // enumeration.\r
-#define EFI_IMAGE_SYM_TYPE_MOE    11  // member of enumeration.\r
-#define EFI_IMAGE_SYM_TYPE_BYTE   12\r
-#define EFI_IMAGE_SYM_TYPE_WORD   13\r
-#define EFI_IMAGE_SYM_TYPE_UINT   14\r
-#define EFI_IMAGE_SYM_TYPE_DWORD  15\r
-\r
-//\r
-// Type (derived) values.\r
-//\r
-#define EFI_IMAGE_SYM_DTYPE_NULL      0 // no derived type.\r
-#define EFI_IMAGE_SYM_DTYPE_POINTER   1\r
-#define EFI_IMAGE_SYM_DTYPE_FUNCTION  2\r
-#define EFI_IMAGE_SYM_DTYPE_ARRAY     3\r
-\r
-//\r
-// Storage classes.\r
-//\r
-#define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION   (UINT8) -1\r
-#define EFI_IMAGE_SYM_CLASS_NULL              0\r
-#define EFI_IMAGE_SYM_CLASS_AUTOMATIC         1\r
-#define EFI_IMAGE_SYM_CLASS_EXTERNAL          2\r
-#define EFI_IMAGE_SYM_CLASS_STATIC            3\r
-#define EFI_IMAGE_SYM_CLASS_REGISTER          4\r
-#define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF      5\r
-#define EFI_IMAGE_SYM_CLASS_LABEL             6\r
-#define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL   7\r
-#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT  8\r
-#define EFI_IMAGE_SYM_CLASS_ARGUMENT          9\r
-#define EFI_IMAGE_SYM_CLASS_STRUCT_TAG        10\r
-#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION   11\r
-#define EFI_IMAGE_SYM_CLASS_UNION_TAG         12\r
-#define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION   13\r
-#define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC  14\r
-#define EFI_IMAGE_SYM_CLASS_ENUM_TAG          15\r
-#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM    16\r
-#define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM    17\r
-#define EFI_IMAGE_SYM_CLASS_BIT_FIELD         18\r
-#define EFI_IMAGE_SYM_CLASS_BLOCK             100\r
-#define EFI_IMAGE_SYM_CLASS_FUNCTION          101\r
-#define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT     102\r
-#define EFI_IMAGE_SYM_CLASS_FILE              103\r
-#define EFI_IMAGE_SYM_CLASS_SECTION           104\r
-#define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL     105\r
-\r
-//\r
-// type packing constants\r
-//\r
-#define EFI_IMAGE_N_BTMASK  017\r
-#define EFI_IMAGE_N_TMASK   060\r
-#define EFI_IMAGE_N_TMASK1  0300\r
-#define EFI_IMAGE_N_TMASK2  0360\r
-#define EFI_IMAGE_N_BTSHFT  4\r
-#define EFI_IMAGE_N_TSHIFT  2\r
-\r
-//\r
-// Communal selection types.\r
-//\r
-#define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES    1\r
-#define EFI_IMAGE_COMDAT_SELECT_ANY             2\r
-#define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE       3\r
-#define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH     4\r
-#define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE     5\r
-\r
-#define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1\r
-#define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2\r
-#define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3\r
-\r
-///\r
-/// Relocation format.\r
-///\r
-typedef struct {\r
-  UINT32  VirtualAddress;\r
-  UINT32  SymbolTableIndex;\r
-  UINT16  Type;\r
-} EFI_IMAGE_RELOCATION;\r
-\r
-#define EFI_IMAGE_SIZEOF_RELOCATION 10\r
-\r
-//\r
-// I386 relocation types.\r
-//\r
-#define EFI_IMAGE_REL_I386_ABSOLUTE 0   // Reference is absolute, no relocation is necessary\r
-#define EFI_IMAGE_REL_I386_DIR16    01  // Direct 16-bit reference to the symbols virtual address\r
-#define EFI_IMAGE_REL_I386_REL16    02  // PC-relative 16-bit reference to the symbols virtual address\r
-#define EFI_IMAGE_REL_I386_DIR32    06  // Direct 32-bit reference to the symbols virtual address\r
-#define EFI_IMAGE_REL_I386_DIR32NB  07  // Direct 32-bit reference to the symbols virtual address, base not included\r
-#define EFI_IMAGE_REL_I386_SEG12    011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address\r
-#define EFI_IMAGE_REL_I386_SECTION  012\r
-#define EFI_IMAGE_REL_I386_SECREL   013\r
-#define EFI_IMAGE_REL_I386_REL32    024 // PC-relative 32-bit reference to the symbols virtual address\r
-\r
-///\r
-/// Based relocation format.\r
-///\r
-typedef struct {\r
-  UINT32  VirtualAddress;\r
-  UINT32  SizeOfBlock;\r
-} EFI_IMAGE_BASE_RELOCATION;\r
-\r
-#define EFI_IMAGE_SIZEOF_BASE_RELOCATION  8\r
-\r
-//\r
-// Based relocation types.\r
-//\r
-#define EFI_IMAGE_REL_BASED_ABSOLUTE      0\r
-#define EFI_IMAGE_REL_BASED_HIGH          1\r
-#define EFI_IMAGE_REL_BASED_LOW           2\r
-#define EFI_IMAGE_REL_BASED_HIGHLOW       3\r
-#define EFI_IMAGE_REL_BASED_HIGHADJ       4\r
-#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR  5\r
-#define EFI_IMAGE_REL_BASED_IA64_IMM64    9\r
-#define EFI_IMAGE_REL_BASED_DIR64         10\r
-\r
-///\r
-/// Line number format.\r
-///\r
-typedef struct {\r
-  union {\r
-    UINT32  SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.\r
-    UINT32  VirtualAddress;   // Virtual address of line number.\r
-  } Type;\r
-  UINT16  Linenumber;         // Line number.\r
-} EFI_IMAGE_LINENUMBER;\r
-\r
-#define EFI_IMAGE_SIZEOF_LINENUMBER 6\r
-\r
-//\r
-// Archive format.\r
-//\r
-#define EFI_IMAGE_ARCHIVE_START_SIZE        8\r
-#define EFI_IMAGE_ARCHIVE_START             "!<arch>\n"\r
-#define EFI_IMAGE_ARCHIVE_END               "`\n"\r
-#define EFI_IMAGE_ARCHIVE_PAD               "\n"\r
-#define EFI_IMAGE_ARCHIVE_LINKER_MEMBER     "/               "\r
-#define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER  "//              "\r
-\r
-typedef struct {\r
-  UINT8 Name[16];     // File member name - `/' terminated.\r
-  UINT8 Date[12];     // File member date - decimal.\r
-  UINT8 UserID[6];    // File member user id - decimal.\r
-  UINT8 GroupID[6];   // File member group id - decimal.\r
-  UINT8 Mode[8];      // File member mode - octal.\r
-  UINT8 Size[10];     // File member size - decimal.\r
-  UINT8 EndHeader[2]; // String to end header.\r
-} EFI_IMAGE_ARCHIVE_MEMBER_HEADER;\r
-\r
-#define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60\r
-\r
-//\r
-// DLL support.\r
-//\r
-\r
-///\r
-/// DLL Export Format\r
-///\r
-typedef struct {\r
-  UINT32  Characteristics;\r
-  UINT32  TimeDateStamp;\r
-  UINT16  MajorVersion;\r
-  UINT16  MinorVersion;\r
-  UINT32  Name;\r
-  UINT32  Base;\r
-  UINT32  NumberOfFunctions;\r
-  UINT32  NumberOfNames;\r
-  UINT32  AddressOfFunctions;\r
-  UINT32  AddressOfNames;\r
-  UINT32  AddressOfNameOrdinals;\r
-} EFI_IMAGE_EXPORT_DIRECTORY;\r
-\r
-///\r
-/// DLL support.\r
-/// Import Format\r
-///\r
-typedef struct {\r
-  UINT16  Hint;\r
-  UINT8   Name[1];\r
-} EFI_IMAGE_IMPORT_BY_NAME;\r
-\r
-typedef struct {\r
-  union {\r
-    UINT32                    Function;\r
-    UINT32                    Ordinal;\r
-    EFI_IMAGE_IMPORT_BY_NAME  *AddressOfData;\r
-  } u1;\r
-} EFI_IMAGE_THUNK_DATA;\r
-\r
-#define EFI_IMAGE_ORDINAL_FLAG              0x80000000\r
-#define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal)  ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)\r
-#define EFI_IMAGE_ORDINAL(Ordinal)          (Ordinal & 0xffff)\r
-\r
-typedef struct {\r
-  UINT32                Characteristics;\r
-  UINT32                TimeDateStamp;\r
-  UINT32                ForwarderChain;\r
-  UINT32                Name;\r
-  EFI_IMAGE_THUNK_DATA  *FirstThunk;\r
-} EFI_IMAGE_IMPORT_DESCRIPTOR;\r
-\r
-///\r
-/// Debug Format\r
-///\r
-#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2\r
-\r
-typedef struct {\r
-  UINT32  Characteristics;\r
-  UINT32  TimeDateStamp;\r
-  UINT16  MajorVersion;\r
-  UINT16  MinorVersion;\r
-  UINT32  Type;\r
-  UINT32  SizeOfData;\r
-  UINT32  RVA;\r
-  UINT32  FileOffset;\r
-} EFI_IMAGE_DEBUG_DIRECTORY_ENTRY;\r
-\r
-#define CODEVIEW_SIGNATURE_NB10 0x3031424E  // "NB10"\r
-typedef struct {\r
-  UINT32  Signature;                        // "NB10"\r
-  UINT32  Unknown;\r
-  UINT32  Unknown2;\r
-  UINT32  Unknown3;\r
-  //\r
-  // Filename of .PDB goes here\r
-  //\r
-} EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;\r
-\r
-#define CODEVIEW_SIGNATURE_RSDS 0x53445352  // "RSDS"\r
-typedef struct {\r
-  UINT32  Signature;                        // "RSDS"\r
-  UINT32  Unknown;\r
-  UINT32  Unknown2;\r
-  UINT32  Unknown3;\r
-  UINT32  Unknown4;\r
-  UINT32  Unknown5;\r
-  //\r
-  // Filename of .PDB goes here\r
-  //\r
-} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;\r
-\r
-///\r
-/// Header format for TE images\r
-///\r
-typedef struct {\r
-  UINT16                    Signature;            // signature for TE format = "VZ"\r
-  UINT16                    Machine;              // from the original file header\r
-  UINT8                     NumberOfSections;     // from the original file header\r
-  UINT8                     Subsystem;            // from original optional header\r
-  UINT16                    StrippedSize;         // how many bytes we removed from the header\r
-  UINT32                    AddressOfEntryPoint;  // offset to entry point -- from original optional header\r
-  UINT32                    BaseOfCode;           // from original image -- required for ITP debug\r
-  UINT64                    ImageBase;            // from original file header\r
-  EFI_IMAGE_DATA_DIRECTORY  DataDirectory[2];     // only base relocation and debug directory\r
-} EFI_TE_IMAGE_HEADER;\r
-\r
-#define EFI_TE_IMAGE_HEADER_SIGNATURE 0x5A56      // "VZ"\r
-\r
-//\r
-// Data directory indexes in our TE image header\r
-//\r
-#define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC  0\r
-#define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG      1\r
-\r
-#endif\r
diff --git a/Tools/Source/TianoTools/GenFvImage/Ia32/PeCoffLoaderEx.c b/Tools/Source/TianoTools/GenFvImage/Ia32/PeCoffLoaderEx.c
deleted file mode 100644 (file)
index 0af4340..0000000
+++ /dev/null
@@ -1,64 +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
-    IA-32 Specific relocation fixups\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-\r
-#define EFI_SPECIFICATION_VERSION    0x00000000\r
-#define EDK_RELEASE_VERSION          0x00020000\r
-#include <Base.h>\r
-#include <Library/PeCoffLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-\r
-\r
-\r
-\r
-RETURN_STATUS\r
-PeCoffLoaderRelocateImageEx (\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
diff --git a/Tools/Source/TianoTools/GenFvImage/Ipf/PeCoffLoaderEx.c b/Tools/Source/TianoTools/GenFvImage/Ipf/PeCoffLoaderEx.c
deleted file mode 100644 (file)
index 2a58a62..0000000
+++ /dev/null
@@ -1,251 +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
-    Fixes Intel Itanium(TM) specific relocation types\r
-\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#define EFI_SPECIFICATION_VERSION    0x00000000\r
-#define EDK_RELEASE_VERSION          0x00020000\r
-#include <Base.h>\r
-#include <Library/PeCoffLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-\r
-\r
-\r
-\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
-PeCoffLoaderRelocateImageEx (\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
diff --git a/Tools/Source/TianoTools/GenFvImage/X64/PeCoffLoaderEx.c b/Tools/Source/TianoTools/GenFvImage/X64/PeCoffLoaderEx.c
deleted file mode 100644 (file)
index 6bcae27..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*++\r
-\r
-Copyright 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
-\r
-Module Name:\r
-\r
-  PeCoffLoaderEx.c\r
-\r
-Abstract:\r
-\r
-  x64 Specific relocation fixups\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#define EFI_SPECIFICATION_VERSION    0x00000000\r
-#define EDK_RELEASE_VERSION          0x00020000\r
-#include <Base.h>\r
-#include <Library/PeCoffLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-\r
-\r
-\r
-\r
-RETURN_STATUS\r
-PeCoffLoaderRelocateImageEx (\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
-  Performs an x64 specific relocation fixup\r
-\r
-Arguments:\r
-  Reloc      - Pointer to the relocation record\r
-  Fixup      - Pointer to the address to fix up\r
-  FixupData  - Pointer to a buffer to log the fixups\r
-  Adjust     - The offset to adjust the fixup\r
-\r
-Returns:\r
-  None\r
-\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
index c0ba17a..d29a2ec 100644 (file)
@@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   Copyright (c) 2006, Intel Corporation\r
 -->\r
   <property name="ToolName" value="GenFvImage"/>\r
-  <property name="FileSet" value="BasePeCoff.c GenFvImageLib.c GenFvImageExe.c"/>\r
+  <property name="FileSet" value="GenFvImageLib.c GenFvImageExe.c"/>\r
 \r
   <taskdef resource="cpptasks.tasks"/>\r
   <typedef resource="cpptasks.types"/>\r
@@ -123,7 +123,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
       </defineset>\r
     \r
       <fileset dir="${basedir}/${ToolName}" \r
-        includes="${FileSet} Ia32/PeCoffLoaderEx.c" />\r
+        includes="${FileSet}"/>\r
 \r
       <includepath path="${PACKAGE_DIR}/${ToolName}"/>\r
       <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
@@ -134,7 +134,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
       <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
       <includepath path="${env.WORKSPACE}/MdePkg/Include/ToBeRemoved"/>\r
       <includepath path="${PACKAGE_DIR}/Common"/>\r
-      <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress"/>\r
+      <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress PeCoffLoader_Ia32"/>\r
       <linkerarg value="/nodefaultlib:libc.lib" unless="gcc"/>\r
       <syslibset dir="${syslibdirs}" libs="${syslibs}" if="gcc"/>\r
       <syslibset libs="RpcRT4" unless="gcc"/>\r
@@ -153,9 +153,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
       </defineset>\r
     \r
       <fileset dir="${basedir}/${ToolName}" \r
-        includes="${FileSet} Ia32/PeCoffLoaderEx.c" \r
-        defaultexcludes="TRUE" \r
-        excludes="*.xml *.inf"/>\r
+        includes="${FileSet}"/>\r
 \r
       <includepath path="${PACKAGE_DIR}/${ToolName}"/>\r
       <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
@@ -166,7 +164,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
       <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
       <includepath path="${env.WORKSPACE}/MdePkg/Include/ToBeRemoved"/>\r
       <includepath path="${PACKAGE_DIR}/Common"/>\r
-      <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress"/>\r
+      <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress PeCoffLoader_Ia32"/>\r
       <linkerarg value="/nodefaultlib:libc.lib" unless="gcc"/>\r
       <syslibset dir="${syslibdirs}" libs="${syslibs}" if="gcc"/>\r
       <syslibset libs="RpcRT4" unless="gcc"/>\r
@@ -177,7 +175,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     <cc name="${ToolChain}" objdir="${BUILD_DIR_X64}" \r
         outfile="${BIN_DIR}/${ToolName}_X64"\r
         outtype="executable"\r
-        libtool="${haveLibtool}"\r
         optimize="speed">\r
 \r
       <defineset>\r
@@ -186,9 +183,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
       </defineset>\r
     \r
       <fileset dir="${basedir}/${ToolName}" \r
-        includes="${FileSet} X64/PeCoffLoaderEx.c"  \r
-        defaultexcludes="TRUE" \r
-        excludes="*.xml *.inf"/>\r
+        includes="${FileSet}"/>\r
 \r
       <includepath path="${PACKAGE_DIR}/${ToolName}"/>\r
       <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
@@ -198,7 +193,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
       <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
       <includepath path="${env.WORKSPACE}/MdePkg/Include/ToBeRemoved"/>\r
       <includepath path="${PACKAGE_DIR}/Common"/>\r
-      <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress"/>\r
+      <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress PeCoffLoader_X64"/>\r
       <linkerarg value="/nodefaultlib:libc.lib" unless="gcc"/>\r
       <syslibset dir="${syslibdirs}" libs="${syslibs}" if="gcc"/>\r
       <syslibset libs="RpcRT4" unless="gcc"/>\r
@@ -209,7 +204,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     <cc name="${ToolChain}" objdir="${BUILD_DIR_IPF}" \r
         outfile="${BIN_DIR}/${ToolName}_Ipf"\r
         outtype="executable"\r
-        libtool="${haveLibtool}"\r
         optimize="speed">\r
 \r
       <defineset>\r
@@ -218,9 +212,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
       </defineset>\r
     \r
       <fileset dir="${basedir}/${ToolName}" \r
-        includes="${FileSet} Ipf/PeCoffLoaderEx.c"  \r
-        defaultexcludes="TRUE" \r
-        excludes="*.xml *.inf"/>\r
+        includes="${FileSet}"/>\r
 \r
       <includepath path="${PACKAGE_DIR}/${ToolName}"/>\r
       <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
@@ -230,7 +222,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
       <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
       <includepath path="${env.WORKSPACE}/MdePkg/Include/ToBeRemoved"/>\r
       <includepath path="${PACKAGE_DIR}/Common"/>\r
-      <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress"/>\r
+      <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress PeCoffLoader_Ipf"/>\r
       <linkerarg value="/nodefaultlib:libc.lib" unless="gcc"/>\r
       <syslibset dir="${syslibdirs}" libs="${syslibs}" if="gcc"/>\r
       <syslibset libs="RpcRT4" unless="gcc"/>\r
diff --git a/Tools/Source/TianoTools/PeCoffLoader/BasePeCoff.c b/Tools/Source/TianoTools/PeCoffLoader/BasePeCoff.c
new file mode 100644 (file)
index 0000000..b41a3a0
--- /dev/null
@@ -0,0 +1,1062 @@
+/*++\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
+\r
+#define EFI_SPECIFICATION_VERSION    0x00000000\r
+#define EDK_RELEASE_VERSION          0x00020000\r
+#include <Base.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/BaseMemoryLib.h>\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
+\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
+  // Read the PE/COFF Header\r
+  //\r
+  Size = sizeof (EFI_IMAGE_NT_HEADERS);\r
+  Status = ImageContext->ImageRead (\r
+                          ImageContext->Handle,\r
+                          ImageContext->PeCoffHeaderOffset,\r
+                          &Size,\r
+                          PeHdr\r
+                          );\r
+  if (RETURN_ERROR (Status)) {\r
+    ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+    return Status;\r
+  }\r
+  //\r
+  // Check the PE/COFF Header Signature. If not, then try to read a TE header\r
+  //\r
+  if (PeHdr->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
+    Size = sizeof (EFI_TE_IMAGE_HEADER);\r
+    Status = ImageContext->ImageRead (\r
+                            ImageContext->Handle,\r
+                            0,\r
+                            &Size,\r
+                            TeHdr\r
+                            );\r
+    if (TeHdr->Signature != EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+      return RETURN_UNSUPPORTED;\r
+    }\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.  We support a native machine type (IA-32/Itanium-based)\r
+  // and the machine type for the Virtual Machine.\r
+  //\r
+  if (ImageContext->IsTeImage == FALSE) {\r
+    ImageContext->Machine = PeHdr->FileHeader.Machine;\r
+  } else {\r
+    ImageContext->Machine = TeHdr->Machine;\r
+  }\r
+\r
+  if (!(EFI_IMAGE_MACHINE_TYPE_SUPPORTED (ImageContext->Machine))) {\r
+    ImageContext->ImageError = IMAGE_ERROR_INVALID_MACHINE_TYPE;\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // See if the image type is supported.  We support EFI Applications,\r
+  // EFI Boot Service Drivers, and EFI Runtime Drivers.\r
+  //\r
+  if (ImageContext->IsTeImage == FALSE) {\r
+    ImageContext->ImageType = PeHdr->OptionalHeader.Subsystem;\r
+  } else {\r
+    ImageContext->ImageType = (UINT16) (TeHdr->Subsystem);\r
+  }\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
+\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
+  // Verify machine type\r
+  //\r
+  Status = PeCoffLoaderCheckImageType (ImageContext, &PeHdr, &TeHdr);\r
+  if (RETURN_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Retrieve the base address of the image\r
+  //\r
+  if (!(ImageContext->IsTeImage)) {\r
+    ImageContext->ImageAddress = PeHdr.OptionalHeader.ImageBase;\r
+  } else {\r
+    ImageContext->ImageAddress = (PHYSICAL_ADDRESS) (TeHdr.ImageBase);\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
+    ImageContext->ImageSize         = (UINT64) PeHdr.OptionalHeader.SizeOfImage;\r
+    ImageContext->SectionAlignment  = PeHdr.OptionalHeader.SectionAlignment;\r
+    ImageContext->SizeOfHeaders     = PeHdr.OptionalHeader.SizeOfHeaders;\r
+\r
+    //\r
+    // Modify ImageSize to contain .PDB file name if required and initialize\r
+    // PdbRVA field...\r
+    //\r
+    if (PeHdr.OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
+      DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(PeHdr.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+\r
+      DebugDirectoryEntryRva = DebugDirectoryEntry->VirtualAddress;\r
+\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++) {\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 * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY));\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++) {\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 * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY));\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 (CHAR8 *) ((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
+\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
+    Adjust = (UINT64) BaseAddress - PeHdr->OptionalHeader.ImageBase;\r
+    PeHdr->OptionalHeader.ImageBase = (UINTN) BaseAddress;\r
+\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 (PeHdr->OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
+      RelocDir  = &PeHdr->OptionalHeader.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
+    TeHdr             = (EFI_TE_IMAGE_HEADER *) (UINTN) (ImageContext->ImageAddress);\r
+    Adjust            = (UINT64) (BaseAddress - TeHdr->ImageBase);\r
+    TeHdr->ImageBase  = (UINT64) (BaseAddress);\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 << 16) + (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_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
+        Status = PeCoffLoaderRelocateImageEx (Reloc, Fixup, &FixupData, Adjust);\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
+\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
+    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 (PeHdr->OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)\r
+        &PeHdr->OptionalHeader.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
+    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/Tools/Source/TianoTools/PeCoffLoader/Common/EfiImage.h b/Tools/Source/TianoTools/PeCoffLoader/Common/EfiImage.h
new file mode 100644 (file)
index 0000000..0ad71d3
--- /dev/null
@@ -0,0 +1,701 @@
+/** @file\r
+       EFI image format for PE32+. Please note some data structures are different\r
+       for IA-32 and Itanium-based images, look for UINTN and the #ifdef EFI_IA64\r
+\r
+       @bug Fix text - doc as defined in MSFT EFI specification.\r
+\r
+       Copyright (c) 2006, 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:    EfiImage.h\r
+\r
+**/\r
+\r
+#ifndef __EFI_IMAGE_H__\r
+#define __EFI_IMAGE_H__\r
+\r
+//\r
+// PE32+ Subsystem type for EFI images\r
+//\r
+#define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION         10\r
+#define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11\r
+#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER      12\r
+#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER      13\r
+\r
+//\r
+// BugBug: Need to get a real answer for this problem. This is not in the\r
+//         PE specification.\r
+//\r
+//         A SAL runtime driver does not get fixed up when a transition to\r
+//         virtual mode is made. In all other cases it should be treated\r
+//         like a EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER image\r
+//\r
+#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER  13\r
+\r
+//\r
+// PE32+ Machine type for EFI images\r
+//\r
+#define IMAGE_FILE_MACHINE_I386     0x014c\r
+#define IMAGE_FILE_MACHINE_IA64     0x0200\r
+#define IMAGE_FILE_MACHINE_EBC      0x0EBC\r
+#define IMAGE_FILE_MACHINE_X64      0x8664\r
+//\r
+// Support old names for backward compatible\r
+//\r
+#define EFI_IMAGE_MACHINE_IA32      IMAGE_FILE_MACHINE_I386 \r
+#define EFI_IMAGE_MACHINE_IA64      IMAGE_FILE_MACHINE_IA64  \r
+#define EFI_IMAGE_MACHINE_IPF       IMAGE_FILE_MACHINE_IA64  \r
+#define EFI_IMAGE_MACHINE_EBC       IMAGE_FILE_MACHINE_EBC  \r
+#define EFI_IMAGE_MACHINE_X64       IMAGE_FILE_MACHINE_X64\r
+\r
+#define EFI_IMAGE_DOS_SIGNATURE     0x5A4D      // MZ\r
+#define EFI_IMAGE_OS2_SIGNATURE     0x454E      // NE\r
+#define EFI_IMAGE_OS2_SIGNATURE_LE  0x454C      // LE\r
+#define EFI_IMAGE_NT_SIGNATURE      0x00004550  // PE00\r
+#define EFI_IMAGE_EDOS_SIGNATURE    0x44454550  // PEED\r
+\r
+///\r
+/// PE images can start with an optional DOS header, so if an image is run\r
+///  under DOS it can print an error message.\r
+///\r
+typedef struct {\r
+  UINT16  e_magic;    // Magic number\r
+  UINT16  e_cblp;     // Bytes on last page of file\r
+  UINT16  e_cp;       // Pages in file\r
+  UINT16  e_crlc;     // Relocations\r
+  UINT16  e_cparhdr;  // Size of header in paragraphs\r
+  UINT16  e_minalloc; // Minimum extra paragraphs needed\r
+  UINT16  e_maxalloc; // Maximum extra paragraphs needed\r
+  UINT16  e_ss;       // Initial (relative) SS value\r
+  UINT16  e_sp;       // Initial SP value\r
+  UINT16  e_csum;     // Checksum\r
+  UINT16  e_ip;       // Initial IP value\r
+  UINT16  e_cs;       // Initial (relative) CS value\r
+  UINT16  e_lfarlc;   // File address of relocation table\r
+  UINT16  e_ovno;     // Overlay number\r
+  UINT16  e_res[4];   // Reserved words\r
+  UINT16  e_oemid;    // OEM identifier (for e_oeminfo)\r
+  UINT16  e_oeminfo;  // OEM information; e_oemid specific\r
+  UINT16  e_res2[10]; // Reserved words\r
+  UINT32  e_lfanew;   // File address of new exe header\r
+} EFI_IMAGE_DOS_HEADER;\r
+\r
+///\r
+/// File header format.\r
+///\r
+typedef struct {\r
+  UINT16  Machine;\r
+  UINT16  NumberOfSections;\r
+  UINT32  TimeDateStamp;\r
+  UINT32  PointerToSymbolTable;\r
+  UINT32  NumberOfSymbols;\r
+  UINT16  SizeOfOptionalHeader;\r
+  UINT16  Characteristics;\r
+} EFI_IMAGE_FILE_HEADER;\r
+\r
+#define EFI_IMAGE_SIZEOF_FILE_HEADER        20\r
+\r
+#define EFI_IMAGE_FILE_RELOCS_STRIPPED      0x0001  // Relocation info stripped from file.\r
+#define EFI_IMAGE_FILE_EXECUTABLE_IMAGE     0x0002  // File is executable  (i.e. no unresolved externel references).\r
+#define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED   0x0004  // Line nunbers stripped from file.\r
+#define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008  // Local symbols stripped from file.\r
+#define EFI_IMAGE_FILE_BYTES_REVERSED_LO    0x0080  // Bytes of machine word are reversed.\r
+#define EFI_IMAGE_FILE_32BIT_MACHINE        0x0100  // 32 bit word machine.\r
+#define EFI_IMAGE_FILE_DEBUG_STRIPPED       0x0200  // Debugging info stripped from file in .DBG file\r
+#define EFI_IMAGE_FILE_SYSTEM               0x1000  // System File.\r
+#define EFI_IMAGE_FILE_DLL                  0x2000  // File is a DLL.\r
+#define EFI_IMAGE_FILE_BYTES_REVERSED_HI    0x8000  // Bytes of machine word are reversed.\r
+#define EFI_IMAGE_FILE_MACHINE_UNKNOWN      0\r
+#define EFI_IMAGE_FILE_MACHINE_I386         0x14c   // Intel 386.\r
+#define EFI_IMAGE_FILE_MACHINE_R3000        0x162   // MIPS* little-endian, 0540 big-endian\r
+#define EFI_IMAGE_FILE_MACHINE_R4000        0x166   // MIPS* little-endian\r
+#define EFI_IMAGE_FILE_MACHINE_ALPHA        0x184   // Alpha_AXP*\r
+#define EFI_IMAGE_FILE_MACHINE_POWERPC      0x1F0   // IBM* PowerPC Little-Endian\r
+#define EFI_IMAGE_FILE_MACHINE_TAHOE        0x7cc   // Intel EM machine\r
+//\r
+// * Other names and brands may be claimed as the property of others.\r
+//\r
+\r
+///\r
+/// Directory format.\r
+///\r
+typedef struct {\r
+  UINT32  VirtualAddress;\r
+  UINT32  Size;\r
+} EFI_IMAGE_DATA_DIRECTORY;\r
+\r
+#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16\r
+\r
+typedef struct {\r
+  UINT16  Magic;\r
+  UINT8   MajorLinkerVersion;\r
+  UINT8   MinorLinkerVersion;\r
+  UINT32  SizeOfCode;\r
+  UINT32  SizeOfInitializedData;\r
+  UINT32  SizeOfUninitializedData;\r
+  UINT32  AddressOfEntryPoint;\r
+  UINT32  BaseOfCode;\r
+  UINT32  BaseOfData;\r
+  UINT32  BaseOfBss;\r
+  UINT32  GprMask;\r
+  UINT32  CprMask[4];\r
+  UINT32  GpValue;\r
+} EFI_IMAGE_ROM_OPTIONAL_HEADER;\r
+\r
+#define EFI_IMAGE_ROM_OPTIONAL_HDR_MAGIC      0x107\r
+#define EFI_IMAGE_SIZEOF_ROM_OPTIONAL_HEADER  sizeof (EFI_IMAGE_ROM_OPTIONAL_HEADER)\r
+\r
+typedef struct {\r
+  EFI_IMAGE_FILE_HEADER         FileHeader;\r
+  EFI_IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;\r
+} EFI_IMAGE_ROM_HEADERS;\r
+\r
+///\r
+/// @attention\r
+/// EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64\r
+/// are for use ONLY by tools.  All proper EFI code MUST use\r
+/// EFI_IMAGE_OPTIONAL_HEADER ONLY!!!\r
+///\r
+#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b\r
+\r
+typedef struct {\r
+  //\r
+  // Standard fields.\r
+  //\r
+  UINT16                    Magic;\r
+  UINT8                     MajorLinkerVersion;\r
+  UINT8                     MinorLinkerVersion;\r
+  UINT32                    SizeOfCode;\r
+  UINT32                    SizeOfInitializedData;\r
+  UINT32                    SizeOfUninitializedData;\r
+  UINT32                    AddressOfEntryPoint;\r
+  UINT32                    BaseOfCode;\r
+  UINT32                    BaseOfData;\r
+  //\r
+  // NT additional fields.\r
+  //\r
+  UINT32                    ImageBase;\r
+  UINT32                    SectionAlignment;\r
+  UINT32                    FileAlignment;\r
+  UINT16                    MajorOperatingSystemVersion;\r
+  UINT16                    MinorOperatingSystemVersion;\r
+  UINT16                    MajorImageVersion;\r
+  UINT16                    MinorImageVersion;\r
+  UINT16                    MajorSubsystemVersion;\r
+  UINT16                    MinorSubsystemVersion;\r
+  UINT32                    Win32VersionValue;\r
+  UINT32                    SizeOfImage;\r
+  UINT32                    SizeOfHeaders;\r
+  UINT32                    CheckSum;\r
+  UINT16                    Subsystem;\r
+  UINT16                    DllCharacteristics;\r
+  UINT32                    SizeOfStackReserve;\r
+  UINT32                    SizeOfStackCommit;\r
+  UINT32                    SizeOfHeapReserve;\r
+  UINT32                    SizeOfHeapCommit;\r
+  UINT32                    LoaderFlags;\r
+  UINT32                    NumberOfRvaAndSizes;\r
+  EFI_IMAGE_DATA_DIRECTORY  DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];\r
+} EFI_IMAGE_OPTIONAL_HEADER32;\r
+\r
+///\r
+/// @attention\r
+/// EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64\r
+/// are for use ONLY by tools.  All proper EFI code MUST use\r
+/// EFI_IMAGE_OPTIONAL_HEADER ONLY!!!\r
+///\r
+#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b\r
+\r
+typedef struct {\r
+  //\r
+  // Standard fields.\r
+  //\r
+  UINT16                    Magic;\r
+  UINT8                     MajorLinkerVersion;\r
+  UINT8                     MinorLinkerVersion;\r
+  UINT32                    SizeOfCode;\r
+  UINT32                    SizeOfInitializedData;\r
+  UINT32                    SizeOfUninitializedData;\r
+  UINT32                    AddressOfEntryPoint;\r
+  UINT32                    BaseOfCode;\r
+  //\r
+  // NT additional fields.\r
+  //\r
+  UINT64                    ImageBase;\r
+  UINT32                    SectionAlignment;\r
+  UINT32                    FileAlignment;\r
+  UINT16                    MajorOperatingSystemVersion;\r
+  UINT16                    MinorOperatingSystemVersion;\r
+  UINT16                    MajorImageVersion;\r
+  UINT16                    MinorImageVersion;\r
+  UINT16                    MajorSubsystemVersion;\r
+  UINT16                    MinorSubsystemVersion;\r
+  UINT32                    Win32VersionValue;\r
+  UINT32                    SizeOfImage;\r
+  UINT32                    SizeOfHeaders;\r
+  UINT32                    CheckSum;\r
+  UINT16                    Subsystem;\r
+  UINT16                    DllCharacteristics;\r
+  UINT64                    SizeOfStackReserve;\r
+  UINT64                    SizeOfStackCommit;\r
+  UINT64                    SizeOfHeapReserve;\r
+  UINT64                    SizeOfHeapCommit;\r
+  UINT32                    LoaderFlags;\r
+  UINT32                    NumberOfRvaAndSizes;\r
+  EFI_IMAGE_DATA_DIRECTORY  DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];\r
+} EFI_IMAGE_OPTIONAL_HEADER64;\r
+\r
+///\r
+/// @attention\r
+/// EFI_IMAGE_NT_HEADERS32 and EFI_IMAGE_HEADERS64 are for use ONLY\r
+/// by tools.  All proper EFI code MUST use EFI_IMAGE_NT_HEADERS ONLY!!!\r
+///\r
+typedef struct {\r
+  UINT32                      Signature;\r
+  EFI_IMAGE_FILE_HEADER       FileHeader;\r
+  EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader;\r
+} EFI_IMAGE_NT_HEADERS32;\r
+\r
+#define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof (EFI_IMAGE_NT_HEADERS32)\r
+\r
+typedef struct {\r
+  UINT32                      Signature;\r
+  EFI_IMAGE_FILE_HEADER       FileHeader;\r
+  EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader;\r
+} EFI_IMAGE_NT_HEADERS64;\r
+\r
+#define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof (EFI_IMAGE_NT_HEADERS64)\r
+\r
+//\r
+// Processor specific definition of EFI_IMAGE_OPTIONAL_HEADER so the\r
+// type name EFI_IMAGE_OPTIONAL_HEADER is appropriate to the build.  Same for\r
+// EFI_IMAGE_NT_HEADERS.  These definitions MUST be used by ALL EFI code.\r
+//\r
+#if   defined (MDE_CPU_IA32) && !defined (BUILDING_TOOLS) || \\r
+      defined (BUILDING_TOOLS) && defined (TOOL_BUILD_IA32_TARGET)\r
+\r
+// typedef EFI_IMAGE_OPTIONAL_HEADER32     EFI_IMAGE_OPTIONAL_HEADER;\r
+typedef EFI_IMAGE_NT_HEADERS32          EFI_IMAGE_NT_HEADERS;\r
+\r
+#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC\r
+#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \\r
+  (((Machine) == EFI_IMAGE_MACHINE_IA32) || ((Machine) == EFI_IMAGE_MACHINE_EBC))\r
+\r
+#elif defined (MDE_CPU_IPF) && !defined (BUILDING_TOOLS) || \\r
+      defined (BUILDING_TOOLS) && defined (TOOL_BUILD_IPF_TARGET)\r
+\r
+typedef EFI_IMAGE_OPTIONAL_HEADER64     EFI_IMAGE_OPTIONAL_HEADER;\r
+typedef EFI_IMAGE_NT_HEADERS64          EFI_IMAGE_NT_HEADERS;\r
+\r
+#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
+#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \\r
+  (((Machine) == EFI_IMAGE_MACHINE_IPF) || ((Machine) == EFI_IMAGE_MACHINE_EBC))\r
+\r
+#elif defined (MDE_CPU_X64) && !defined (BUILDING_TOOLS) || \\r
+      defined (BUILDING_TOOLS) && defined (TOOL_BUILD_X64_TARGET)\r
+\r
+typedef EFI_IMAGE_OPTIONAL_HEADER64     EFI_IMAGE_OPTIONAL_HEADER;\r
+typedef EFI_IMAGE_NT_HEADERS64          EFI_IMAGE_NT_HEADERS;\r
+\r
+#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
+#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) \\r
+  (((Machine) == EFI_IMAGE_MACHINE_X64) || ((Machine) == EFI_IMAGE_MACHINE_EBC))\r
+\r
+#elif defined (MDE_CPU_EBC)\r
+\r
+//\r
+// This is just to make sure you can cross compile with the EBC compiiler.\r
+// It does not make sense to have a PE loader coded in EBC. You need to \r
+// understand the basic \r
+//\r
+typedef EFI_IMAGE_OPTIONAL_HEADER64     EFI_IMAGE_OPTIONAL_HEADER;\r
+typedef EFI_IMAGE_NT_HEADERS64          EFI_IMAGE_NT_HEADERS;\r
+\r
+#define EFI_IMAGE_NT_OPTIONAL_HDR_MAGIC EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC\r
+#define EFI_IMAGE_MACHINE_TYPE_SUPPORTED(Machine) ((Machine) == EFI_IMAGE_MACHINE_EBC)\r
+\r
+#else\r
+#error Unknown Processor Type\r
+#endif\r
+\r
+\r
+#define EFI_IMAGE_FIRST_SECTION(ntheader) \\r
+    ( \\r
+      (EFI_IMAGE_SECTION_HEADER *) \\r
+        ( \\r
+          (UINT32) ntheader + \\r
+          FIELD_OFFSET (EFI_IMAGE_NT_HEADERS, OptionalHeader) + \\r
+          ((EFI_IMAGE_NT_HEADERS *) (ntheader))->FileHeader.SizeOfOptionalHeader \\r
+        ) \\r
+    )\r
+\r
+//\r
+// Subsystem Values\r
+//\r
+#define EFI_IMAGE_SUBSYSTEM_UNKNOWN     0\r
+#define EFI_IMAGE_SUBSYSTEM_NATIVE      1\r
+#define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2\r
+#define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3.\r
+#define EFI_IMAGE_SUBSYSTEM_OS2_CUI     5\r
+#define EFI_IMAGE_SUBSYSTEM_POSIX_CUI   7\r
+\r
+//\r
+// Directory Entries\r
+//\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT      0\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT      1\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE    2\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION   3\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY    4\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC   5\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG       6\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT   7\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR   8\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_TLS         9\r
+#define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10\r
+\r
+//\r
+// Section header format.\r
+//\r
+#define EFI_IMAGE_SIZEOF_SHORT_NAME 8\r
+\r
+typedef struct {\r
+  UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];\r
+  union {\r
+    UINT32  PhysicalAddress;\r
+    UINT32  VirtualSize;\r
+  } Misc;\r
+  UINT32  VirtualAddress;\r
+  UINT32  SizeOfRawData;\r
+  UINT32  PointerToRawData;\r
+  UINT32  PointerToRelocations;\r
+  UINT32  PointerToLinenumbers;\r
+  UINT16  NumberOfRelocations;\r
+  UINT16  NumberOfLinenumbers;\r
+  UINT32  Characteristics;\r
+} EFI_IMAGE_SECTION_HEADER;\r
+\r
+#define EFI_IMAGE_SIZEOF_SECTION_HEADER       40\r
+\r
+#define EFI_IMAGE_SCN_TYPE_NO_PAD             0x00000008  // Reserved.\r
+#define EFI_IMAGE_SCN_CNT_CODE                0x00000020\r
+#define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA    0x00000040\r
+#define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA  0x00000080\r
+\r
+#define EFI_IMAGE_SCN_LNK_OTHER               0x00000100  // Reserved.\r
+#define EFI_IMAGE_SCN_LNK_INFO                0x00000200  // Section contains comments or some other type of information.\r
+#define EFI_IMAGE_SCN_LNK_REMOVE              0x00000800  // Section contents will not become part of image.\r
+#define EFI_IMAGE_SCN_LNK_COMDAT              0x00001000\r
+\r
+#define EFI_IMAGE_SCN_ALIGN_1BYTES            0x00100000\r
+#define EFI_IMAGE_SCN_ALIGN_2BYTES            0x00200000\r
+#define EFI_IMAGE_SCN_ALIGN_4BYTES            0x00300000\r
+#define EFI_IMAGE_SCN_ALIGN_8BYTES            0x00400000\r
+#define EFI_IMAGE_SCN_ALIGN_16BYTES           0x00500000\r
+#define EFI_IMAGE_SCN_ALIGN_32BYTES           0x00600000\r
+#define EFI_IMAGE_SCN_ALIGN_64BYTES           0x00700000\r
+\r
+#define EFI_IMAGE_SCN_MEM_DISCARDABLE         0x02000000\r
+#define EFI_IMAGE_SCN_MEM_NOT_CACHED          0x04000000\r
+#define EFI_IMAGE_SCN_MEM_NOT_PAGED           0x08000000\r
+#define EFI_IMAGE_SCN_MEM_SHARED              0x10000000\r
+#define EFI_IMAGE_SCN_MEM_EXECUTE             0x20000000\r
+#define EFI_IMAGE_SCN_MEM_READ                0x40000000\r
+#define EFI_IMAGE_SCN_MEM_WRITE               0x80000000\r
+\r
+///\r
+/// Symbol format.\r
+///\r
+#define EFI_IMAGE_SIZEOF_SYMBOL 18\r
+\r
+//\r
+// Section values.\r
+//\r
+// Symbols have a section number of the section in which they are\r
+// defined. Otherwise, section numbers have the following meanings:\r
+//\r
+#define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0  // Symbol is undefined or is common.\r
+#define EFI_IMAGE_SYM_ABSOLUTE  (UINT16) -1 // Symbol is an absolute value.\r
+#define EFI_IMAGE_SYM_DEBUG     (UINT16) -2 // Symbol is a special debug item.\r
+//\r
+// Type (fundamental) values.\r
+//\r
+#define EFI_IMAGE_SYM_TYPE_NULL   0   // no type.\r
+#define EFI_IMAGE_SYM_TYPE_VOID   1   //\r
+#define EFI_IMAGE_SYM_TYPE_CHAR   2   // type character.\r
+#define EFI_IMAGE_SYM_TYPE_SHORT  3   // type short integer.\r
+#define EFI_IMAGE_SYM_TYPE_INT    4\r
+#define EFI_IMAGE_SYM_TYPE_LONG   5\r
+#define EFI_IMAGE_SYM_TYPE_FLOAT  6\r
+#define EFI_IMAGE_SYM_TYPE_DOUBLE 7\r
+#define EFI_IMAGE_SYM_TYPE_STRUCT 8\r
+#define EFI_IMAGE_SYM_TYPE_UNION  9\r
+#define EFI_IMAGE_SYM_TYPE_ENUM   10  // enumeration.\r
+#define EFI_IMAGE_SYM_TYPE_MOE    11  // member of enumeration.\r
+#define EFI_IMAGE_SYM_TYPE_BYTE   12\r
+#define EFI_IMAGE_SYM_TYPE_WORD   13\r
+#define EFI_IMAGE_SYM_TYPE_UINT   14\r
+#define EFI_IMAGE_SYM_TYPE_DWORD  15\r
+\r
+//\r
+// Type (derived) values.\r
+//\r
+#define EFI_IMAGE_SYM_DTYPE_NULL      0 // no derived type.\r
+#define EFI_IMAGE_SYM_DTYPE_POINTER   1\r
+#define EFI_IMAGE_SYM_DTYPE_FUNCTION  2\r
+#define EFI_IMAGE_SYM_DTYPE_ARRAY     3\r
+\r
+//\r
+// Storage classes.\r
+//\r
+#define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION   (UINT8) -1\r
+#define EFI_IMAGE_SYM_CLASS_NULL              0\r
+#define EFI_IMAGE_SYM_CLASS_AUTOMATIC         1\r
+#define EFI_IMAGE_SYM_CLASS_EXTERNAL          2\r
+#define EFI_IMAGE_SYM_CLASS_STATIC            3\r
+#define EFI_IMAGE_SYM_CLASS_REGISTER          4\r
+#define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF      5\r
+#define EFI_IMAGE_SYM_CLASS_LABEL             6\r
+#define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL   7\r
+#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT  8\r
+#define EFI_IMAGE_SYM_CLASS_ARGUMENT          9\r
+#define EFI_IMAGE_SYM_CLASS_STRUCT_TAG        10\r
+#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION   11\r
+#define EFI_IMAGE_SYM_CLASS_UNION_TAG         12\r
+#define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION   13\r
+#define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC  14\r
+#define EFI_IMAGE_SYM_CLASS_ENUM_TAG          15\r
+#define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM    16\r
+#define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM    17\r
+#define EFI_IMAGE_SYM_CLASS_BIT_FIELD         18\r
+#define EFI_IMAGE_SYM_CLASS_BLOCK             100\r
+#define EFI_IMAGE_SYM_CLASS_FUNCTION          101\r
+#define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT     102\r
+#define EFI_IMAGE_SYM_CLASS_FILE              103\r
+#define EFI_IMAGE_SYM_CLASS_SECTION           104\r
+#define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL     105\r
+\r
+//\r
+// type packing constants\r
+//\r
+#define EFI_IMAGE_N_BTMASK  017\r
+#define EFI_IMAGE_N_TMASK   060\r
+#define EFI_IMAGE_N_TMASK1  0300\r
+#define EFI_IMAGE_N_TMASK2  0360\r
+#define EFI_IMAGE_N_BTSHFT  4\r
+#define EFI_IMAGE_N_TSHIFT  2\r
+\r
+//\r
+// Communal selection types.\r
+//\r
+#define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES    1\r
+#define EFI_IMAGE_COMDAT_SELECT_ANY             2\r
+#define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE       3\r
+#define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH     4\r
+#define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE     5\r
+\r
+#define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1\r
+#define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2\r
+#define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3\r
+\r
+///\r
+/// Relocation format.\r
+///\r
+typedef struct {\r
+  UINT32  VirtualAddress;\r
+  UINT32  SymbolTableIndex;\r
+  UINT16  Type;\r
+} EFI_IMAGE_RELOCATION;\r
+\r
+#define EFI_IMAGE_SIZEOF_RELOCATION 10\r
+\r
+//\r
+// I386 relocation types.\r
+//\r
+#define EFI_IMAGE_REL_I386_ABSOLUTE 0   // Reference is absolute, no relocation is necessary\r
+#define EFI_IMAGE_REL_I386_DIR16    01  // Direct 16-bit reference to the symbols virtual address\r
+#define EFI_IMAGE_REL_I386_REL16    02  // PC-relative 16-bit reference to the symbols virtual address\r
+#define EFI_IMAGE_REL_I386_DIR32    06  // Direct 32-bit reference to the symbols virtual address\r
+#define EFI_IMAGE_REL_I386_DIR32NB  07  // Direct 32-bit reference to the symbols virtual address, base not included\r
+#define EFI_IMAGE_REL_I386_SEG12    011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address\r
+#define EFI_IMAGE_REL_I386_SECTION  012\r
+#define EFI_IMAGE_REL_I386_SECREL   013\r
+#define EFI_IMAGE_REL_I386_REL32    024 // PC-relative 32-bit reference to the symbols virtual address\r
+\r
+///\r
+/// Based relocation format.\r
+///\r
+typedef struct {\r
+  UINT32  VirtualAddress;\r
+  UINT32  SizeOfBlock;\r
+} EFI_IMAGE_BASE_RELOCATION;\r
+\r
+#define EFI_IMAGE_SIZEOF_BASE_RELOCATION  8\r
+\r
+//\r
+// Based relocation types.\r
+//\r
+#define EFI_IMAGE_REL_BASED_ABSOLUTE      0\r
+#define EFI_IMAGE_REL_BASED_HIGH          1\r
+#define EFI_IMAGE_REL_BASED_LOW           2\r
+#define EFI_IMAGE_REL_BASED_HIGHLOW       3\r
+#define EFI_IMAGE_REL_BASED_HIGHADJ       4\r
+#define EFI_IMAGE_REL_BASED_MIPS_JMPADDR  5\r
+#define EFI_IMAGE_REL_BASED_IA64_IMM64    9\r
+#define EFI_IMAGE_REL_BASED_DIR64         10\r
+\r
+///\r
+/// Line number format.\r
+///\r
+typedef struct {\r
+  union {\r
+    UINT32  SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.\r
+    UINT32  VirtualAddress;   // Virtual address of line number.\r
+  } Type;\r
+  UINT16  Linenumber;         // Line number.\r
+} EFI_IMAGE_LINENUMBER;\r
+\r
+#define EFI_IMAGE_SIZEOF_LINENUMBER 6\r
+\r
+//\r
+// Archive format.\r
+//\r
+#define EFI_IMAGE_ARCHIVE_START_SIZE        8\r
+#define EFI_IMAGE_ARCHIVE_START             "!<arch>\n"\r
+#define EFI_IMAGE_ARCHIVE_END               "`\n"\r
+#define EFI_IMAGE_ARCHIVE_PAD               "\n"\r
+#define EFI_IMAGE_ARCHIVE_LINKER_MEMBER     "/               "\r
+#define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER  "//              "\r
+\r
+typedef struct {\r
+  UINT8 Name[16];     // File member name - `/' terminated.\r
+  UINT8 Date[12];     // File member date - decimal.\r
+  UINT8 UserID[6];    // File member user id - decimal.\r
+  UINT8 GroupID[6];   // File member group id - decimal.\r
+  UINT8 Mode[8];      // File member mode - octal.\r
+  UINT8 Size[10];     // File member size - decimal.\r
+  UINT8 EndHeader[2]; // String to end header.\r
+} EFI_IMAGE_ARCHIVE_MEMBER_HEADER;\r
+\r
+#define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60\r
+\r
+//\r
+// DLL support.\r
+//\r
+\r
+///\r
+/// DLL Export Format\r
+///\r
+typedef struct {\r
+  UINT32  Characteristics;\r
+  UINT32  TimeDateStamp;\r
+  UINT16  MajorVersion;\r
+  UINT16  MinorVersion;\r
+  UINT32  Name;\r
+  UINT32  Base;\r
+  UINT32  NumberOfFunctions;\r
+  UINT32  NumberOfNames;\r
+  UINT32  AddressOfFunctions;\r
+  UINT32  AddressOfNames;\r
+  UINT32  AddressOfNameOrdinals;\r
+} EFI_IMAGE_EXPORT_DIRECTORY;\r
+\r
+///\r
+/// DLL support.\r
+/// Import Format\r
+///\r
+typedef struct {\r
+  UINT16  Hint;\r
+  UINT8   Name[1];\r
+} EFI_IMAGE_IMPORT_BY_NAME;\r
+\r
+typedef struct {\r
+  union {\r
+    UINT32                    Function;\r
+    UINT32                    Ordinal;\r
+    EFI_IMAGE_IMPORT_BY_NAME  *AddressOfData;\r
+  } u1;\r
+} EFI_IMAGE_THUNK_DATA;\r
+\r
+#define EFI_IMAGE_ORDINAL_FLAG              0x80000000\r
+#define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal)  ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)\r
+#define EFI_IMAGE_ORDINAL(Ordinal)          (Ordinal & 0xffff)\r
+\r
+typedef struct {\r
+  UINT32                Characteristics;\r
+  UINT32                TimeDateStamp;\r
+  UINT32                ForwarderChain;\r
+  UINT32                Name;\r
+  EFI_IMAGE_THUNK_DATA  *FirstThunk;\r
+} EFI_IMAGE_IMPORT_DESCRIPTOR;\r
+\r
+///\r
+/// Debug Format\r
+///\r
+#define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2\r
+\r
+typedef struct {\r
+  UINT32  Characteristics;\r
+  UINT32  TimeDateStamp;\r
+  UINT16  MajorVersion;\r
+  UINT16  MinorVersion;\r
+  UINT32  Type;\r
+  UINT32  SizeOfData;\r
+  UINT32  RVA;\r
+  UINT32  FileOffset;\r
+} EFI_IMAGE_DEBUG_DIRECTORY_ENTRY;\r
+\r
+#define CODEVIEW_SIGNATURE_NB10 0x3031424E  // "NB10"\r
+typedef struct {\r
+  UINT32  Signature;                        // "NB10"\r
+  UINT32  Unknown;\r
+  UINT32  Unknown2;\r
+  UINT32  Unknown3;\r
+  //\r
+  // Filename of .PDB goes here\r
+  //\r
+} EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;\r
+\r
+#define CODEVIEW_SIGNATURE_RSDS 0x53445352  // "RSDS"\r
+typedef struct {\r
+  UINT32  Signature;                        // "RSDS"\r
+  UINT32  Unknown;\r
+  UINT32  Unknown2;\r
+  UINT32  Unknown3;\r
+  UINT32  Unknown4;\r
+  UINT32  Unknown5;\r
+  //\r
+  // Filename of .PDB goes here\r
+  //\r
+} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;\r
+\r
+///\r
+/// Header format for TE images\r
+///\r
+typedef struct {\r
+  UINT16                    Signature;            // signature for TE format = "VZ"\r
+  UINT16                    Machine;              // from the original file header\r
+  UINT8                     NumberOfSections;     // from the original file header\r
+  UINT8                     Subsystem;            // from original optional header\r
+  UINT16                    StrippedSize;         // how many bytes we removed from the header\r
+  UINT32                    AddressOfEntryPoint;  // offset to entry point -- from original optional header\r
+  UINT32                    BaseOfCode;           // from original image -- required for ITP debug\r
+  UINT64                    ImageBase;            // from original file header\r
+  EFI_IMAGE_DATA_DIRECTORY  DataDirectory[2];     // only base relocation and debug directory\r
+} EFI_TE_IMAGE_HEADER;\r
+\r
+#define EFI_TE_IMAGE_HEADER_SIGNATURE 0x5A56      // "VZ"\r
+\r
+//\r
+// Data directory indexes in our TE image header\r
+//\r
+#define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC  0\r
+#define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG      1\r
+\r
+#endif\r
diff --git a/Tools/Source/TianoTools/PeCoffLoader/Ia32/PeCoffLoaderEx.c b/Tools/Source/TianoTools/PeCoffLoader/Ia32/PeCoffLoaderEx.c
new file mode 100644 (file)
index 0000000..0af4340
--- /dev/null
@@ -0,0 +1,64 @@
+/*++\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
+    IA-32 Specific relocation fixups\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+\r
+#define EFI_SPECIFICATION_VERSION    0x00000000\r
+#define EDK_RELEASE_VERSION          0x00020000\r
+#include <Base.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+\r
+\r
+\r
+RETURN_STATUS\r
+PeCoffLoaderRelocateImageEx (\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
diff --git a/Tools/Source/TianoTools/PeCoffLoader/Ipf/PeCoffLoaderEx.c b/Tools/Source/TianoTools/PeCoffLoader/Ipf/PeCoffLoaderEx.c
new file mode 100644 (file)
index 0000000..2a58a62
--- /dev/null
@@ -0,0 +1,251 @@
+/*++\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
+    Fixes Intel Itanium(TM) specific relocation types\r
+\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#define EFI_SPECIFICATION_VERSION    0x00000000\r
+#define EDK_RELEASE_VERSION          0x00020000\r
+#include <Base.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+\r
+\r
+\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
+PeCoffLoaderRelocateImageEx (\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
diff --git a/Tools/Source/TianoTools/PeCoffLoader/X64/PeCoffLoaderEx.c b/Tools/Source/TianoTools/PeCoffLoader/X64/PeCoffLoaderEx.c
new file mode 100644 (file)
index 0000000..6bcae27
--- /dev/null
@@ -0,0 +1,76 @@
+/*++\r
+\r
+Copyright 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
+\r
+Module Name:\r
+\r
+  PeCoffLoaderEx.c\r
+\r
+Abstract:\r
+\r
+  x64 Specific relocation fixups\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#define EFI_SPECIFICATION_VERSION    0x00000000\r
+#define EDK_RELEASE_VERSION          0x00020000\r
+#include <Base.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+\r
+\r
+\r
+\r
+RETURN_STATUS\r
+PeCoffLoaderRelocateImageEx (\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
+  Performs an x64 specific relocation fixup\r
+\r
+Arguments:\r
+  Reloc      - Pointer to the relocation record\r
+  Fixup      - Pointer to the address to fix up\r
+  FixupData  - Pointer to a buffer to log the fixups\r
+  Adjust     - The offset to adjust the fixup\r
+\r
+Returns:\r
+  None\r
+\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
diff --git a/Tools/Source/TianoTools/PeCoffLoader/build.xml b/Tools/Source/TianoTools/PeCoffLoader/build.xml
new file mode 100644 (file)
index 0000000..7106bce
--- /dev/null
@@ -0,0 +1,203 @@
+<?xml version="1.0" ?>\r
+<!--\r
+Copyright (c) 2006, 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
+<project default="GenTool" basedir=".">\r
+<!--\r
+    EDK PeCoffLoader\r
+  Copyright (c) 2006, Intel Corporation\r
+-->\r
+  <taskdef resource="cpptasks.tasks"/>\r
+  <typedef resource="cpptasks.types"/>\r
+  <taskdef resource="net/sf/antcontrib/antlib.xml"/>\r
+\r
+  <property name="LibName" value="PeCoffLoader"/>\r
+  <property environment="env"/>\r
+\r
+  <property name="LINK_OUTPUT_TYPE" value="static"/>\r
+  <property name="BUILD_DIR_IA32" value="${PACKAGE_DIR}/${LibName}/tmp/Ia32"/>\r
+  <property name="BUILD_DIR_X64" value="${PACKAGE_DIR}/${LibName}/tmp/X64"/>\r
+  <property name="BUILD_DIR_IPF" value="${PACKAGE_DIR}/${LibName}/tmp/Ipf"/>\r
+\r
+  <target name="GenTool" depends="init, Tool">\r
+    <echo message="Building the EDK Tool: ${LibName}"/>\r
+  </target>\r
+\r
+  <target name="init">\r
+    <echo message="The EDK Library: ${LibName}"/>\r
+    <mkdir dir="${BUILD_DIR_IA32}"/>\r
+    <mkdir dir="${BUILD_DIR_X64}"/>\r
+    <mkdir dir="${BUILD_DIR_IPF}"/>\r
+    <if>\r
+      <equals arg1="${GCC}" arg2="cygwin"/>\r
+      <then>\r
+        <echo message="Cygwin Family"/>\r
+        <property name="ToolChain" value="gcc"/>\r
+      </then>\r
+    <elseif>\r
+      <os family="dos"/>\r
+      <then>\r
+        <echo message="Windows Family"/>\r
+        <property name="ToolChain" value="msvc"/>\r
+      </then>\r
+    </elseif>\r
+    <elseif>\r
+      <os family="unix"/>\r
+      <then>\r
+        <echo message="UNIX Family"/>\r
+        <property name="ToolChain" value="gcc"/>\r
+      </then>\r
+    </elseif>\r
+\r
+    <else>\r
+      <echo>\r
+        Unsupported Operating System\r
+        Please Contact Intel Corporation\r
+      </echo>\r
+    </else>\r
+    </if>\r
+        <property name="ToolChain" value="gcc"/>\r
+    <if>\r
+      <equals arg1="${ToolChain}" arg2="msvc"/>\r
+      <then>\r
+        <property name="ext_static" value=".lib"/>\r
+        <property name="ext_dynamic" value=".dll"/>\r
+        <property name="ext_exe" value=".exe"/>\r
+      </then>\r
+      <elseif>\r
+        <equals arg1="${ToolChain}" arg2="gcc"/>\r
+        <then>\r
+          <property name="ext_static" value=".a"/>\r
+          <property name="ext_dynamic" value=".so"/>\r
+          <property name="ext_exe" value=""/>\r
+        </then>\r
+      </elseif>\r
+    </if>\r
+\r
+    <condition property="syslibdirs" value="">\r
+      <os family="mac"/>\r
+    </condition>\r
+    \r
+    <condition property="syslibs" value="">\r
+      <os family="mac"/>\r
+    </condition>\r
+    \r
+    <condition property="syslibdirs" value="${env.CYGWIN_HOME}/lib/e2fsprogs">\r
+      <os family="windows"/>\r
+    </condition>\r
+    \r
+    <condition property="syslibs" value="uuid">\r
+      <os family="windows"/>\r
+    </condition>\r
+    \r
+    <condition property="syslibdirs" value="/usr/lib">\r
+      <os name="Linux"/>\r
+    </condition>\r
+    \r
+    <condition property="syslibs" value="uuid">\r
+      <os name="Linux"/>\r
+    </condition>\r
+    \r
+  </target>\r
+\r
+  <target name="Tool" depends="init, PeCoffLoader_Ia32, PeCoffLoader_Ipf, PeCoffLoader_X64"/>\r
+\r
+  <target name="PeCoffLoader_Ia32" >\r
+    <cc name="${ToolChain}" objdir="${BUILD_DIR_IA32}" \r
+        outfile="${LIB_DIR}/${LibName}_Ia32"\r
+        outtype="static"\r
+        optimize="speed">\r
+\r
+      <defineset>\r
+        <define name="BUILDING_TOOLS"/>\r
+        <define name="TOOL_BUILD_IA32_TARGET"/>\r
+      </defineset>\r
+    \r
+      <fileset dir="${basedir}/${LibName}" \r
+        includes="BasePeCoff.c Ia32/PeCoffLoaderEx.c" />\r
+\r
+      <includepath path="${PACKAGE_DIR}/${LibName}"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
+      <includepath path="${PACKAGE_DIR}/Common"/>\r
+    </cc>\r
+  </target>\r
+\r
+  <target name="PeCoffLoader_Ipf" >\r
+    <cc name="${ToolChain}" objdir="${BUILD_DIR_IPF}" \r
+        outfile="${LIB_DIR}/${LibName}_Ipf"\r
+        outtype="static"\r
+        optimize="speed">\r
+\r
+      <defineset>\r
+        <define name="BUILDING_TOOLS"/>\r
+        <define name="TOOL_BUILD_IPF_TARGET"/>\r
+      </defineset>\r
+    \r
+      <fileset dir="${basedir}/${LibName}" \r
+        includes="BasePeCoff.c Ipf/PeCoffLoaderEx.c" />\r
+\r
+      <includepath path="${PACKAGE_DIR}/${LibName}"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
+      <includepath path="${PACKAGE_DIR}/Common"/>\r
+    </cc>\r
+  </target>\r
+\r
+  <target name="PeCoffLoader_X64" >\r
+    <cc name="${ToolChain}" objdir="${BUILD_DIR_X64}" \r
+        outfile="${LIB_DIR}/${LibName}_X64"\r
+        outtype="static"\r
+        optimize="speed">\r
+\r
+      <defineset>\r
+        <define name="BUILDING_TOOLS"/>\r
+        <define name="TOOL_BUILD_X64_TARGET"/>\r
+      </defineset>\r
+    \r
+      <fileset dir="${basedir}/${LibName}" \r
+        includes="BasePeCoff.c X64/PeCoffLoaderEx.c" />\r
+\r
+      <includepath path="${PACKAGE_DIR}/${LibName}"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
+      <includepath path="${PACKAGE_DIR}/Common"/>\r
+    </cc>\r
+  </target>\r
+\r
+\r
+  <target name="clean" depends="init">\r
+    <echo message="Removing Intermediate Files Only"/>  \r
+    <delete>\r
+      <fileset dir="${BUILD_DIR_IA32}" includes="*.obj"/>\r
+      <fileset dir="${BUILD_DIR_X64}" includes="*.obj"/>\r
+      <fileset dir="${BUILD_DIR_IPF}" includes="*.obj"/>\r
+    </delete>\r
+  </target>\r
+\r
+  <target name="cleanall" depends="init">\r
+    <echo message="Removing Object Files and the Executable: ${LibName}${ext_exe}"/>  \r
+    <delete dir="${PACKAGE_DIR}/${LibName}/tmp">\r
+    </delete>\r
+  </target>\r
+\r
+</project>\r
index e951164..7dc95d6 100644 (file)
@@ -29,7 +29,6 @@ Abstract:
 #include <string.h>\r
 #include "CommonLib.h"\r
 #include "ParseInf.h"\r
-// #include <Guid/PeiPeCoffLoader.h>\r
 #include "FvLib.h"\r
 \r
 #include "EfiUtilityMsgs.h"\r
@@ -38,8 +37,6 @@ Abstract:
 \r
 #include "PeiRebaseExe.h"\r
 \r
-extern PEI_PE_COFF_LOADER_PROTOCOL  mPeCoffLoader;\r
-\r
 EFI_STATUS\r
 ReadHeader (\r
   IN FILE       *InputFile,\r
@@ -491,7 +488,7 @@ Returns:
 --*/\r
 {\r
   EFI_STATUS                            Status;\r
-  EFI_PEI_PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;\r
+  PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;\r
   UINTN                                 MemoryImagePointer;\r
   UINTN                                 MemoryImagePointerAligned;\r
   EFI_PHYSICAL_ADDRESS                  ImageAddress;\r
@@ -570,9 +567,9 @@ Returns:
     //\r
     memset (&ImageContext, 0, sizeof (ImageContext));\r
     ImageContext.Handle     = (VOID *) ((UINTN) CurrentPe32Section.Pe32Section + sizeof (EFI_PE32_SECTION));\r
-    ImageContext.ImageRead  = (EFI_PEI_PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead;\r
+    ImageContext.ImageRead  = (PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead;\r
 \r
-    Status                  = mPeCoffLoader.GetImageInfo (&mPeCoffLoader, &ImageContext);\r
+    Status                  = PeCoffLoaderGetImageInfo (&ImageContext);\r
 \r
     if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 0, "GetImageInfo() call failed on rebase", FileGuidString);\r
@@ -593,7 +590,7 @@ Returns:
 \r
     ImageContext.ImageAddress = MemoryImagePointerAligned;\r
 \r
-    Status                    = mPeCoffLoader.LoadImage (&mPeCoffLoader, &ImageContext);\r
+    Status                    = PeCoffLoaderLoadImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 0, "LoadImage() call failed on rebase", FileGuidString);\r
       free ((VOID *) MemoryImagePointer);\r
@@ -601,7 +598,7 @@ Returns:
     }\r
 \r
     ImageContext.DestinationAddress = NewPe32BaseAddress;\r
-    Status                          = mPeCoffLoader.RelocateImage (&mPeCoffLoader, &ImageContext);\r
+    Status                          = PeCoffLoaderRelocateImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 0, "RelocateImage() call failed on rebase", FileGuidString);\r
       free ((VOID *) MemoryImagePointer);\r
@@ -802,9 +799,9 @@ Returns:
     //\r
     memset (&ImageContext, 0, sizeof (ImageContext));\r
     ImageContext.Handle     = (VOID *) TEBuffer;\r
-    ImageContext.ImageRead  = (EFI_PEI_PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead;\r
+    ImageContext.ImageRead  = (PE_COFF_LOADER_READ_FILE) FfsRebaseImageRead;\r
 \r
-    Status                  = mPeCoffLoader.GetImageInfo (&mPeCoffLoader, &ImageContext);\r
+    Status                  = PeCoffLoaderGetImageInfo (&ImageContext);\r
 \r
     if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 0, "GetImageInfo() call failed on rebase of TE image", FileGuidString);\r
@@ -825,7 +822,7 @@ Returns:
     \r
 \r
     ImageContext.ImageAddress = MemoryImagePointerAligned;\r
-    Status                    = mPeCoffLoader.LoadImage (&mPeCoffLoader, &ImageContext);\r
+    Status                    = PeCoffLoaderLoadImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 0, "LoadImage() call failed on rebase of TE image", FileGuidString);\r
       free (TEBuffer);\r
@@ -834,7 +831,7 @@ Returns:
     }\r
 \r
     ImageContext.DestinationAddress = NewPe32BaseAddress;\r
-    Status                          = mPeCoffLoader.RelocateImage (&mPeCoffLoader, &ImageContext);\r
+    Status                          = PeCoffLoaderRelocateImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 0, "RelocateImage() call failed on rebase of TE image", FileGuidString);\r
       free ((VOID *) MemoryImagePointer);\r
diff --git a/Tools/Source/TianoTools/PeiRebase/build.xml b/Tools/Source/TianoTools/PeiRebase/build.xml
new file mode 100644 (file)
index 0000000..b49193c
--- /dev/null
@@ -0,0 +1,155 @@
+<?xml version="1.0" ?>\r
+<!--\r
+Copyright (c) 2006, 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
+<project default="GenTool" basedir=".">\r
+<!--\r
+    EDK PeiRebase Tool\r
+  Copyright (c) 2006, Intel Corporation\r
+-->\r
+  <property name="ToolName" value="PeiRebase"/>\r
+  <property name="FileSet" value="*.c"/>\r
+\r
+  <taskdef resource="cpptasks.tasks"/>\r
+  <typedef resource="cpptasks.types"/>\r
+  <taskdef resource="net/sf/antcontrib/antlib.xml"/>\r
+\r
+  <property environment="env"/>\r
+\r
+  <property name="LINK_OUTPUT_TYPE" value="static"/>\r
+  <property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>\r
+\r
+  <target name="GenTool" depends="init, Tool">\r
+    <echo message="Building the EDK Tool: ${ToolName}"/>\r
+  </target>\r
+\r
+  <target name="Tool" depends="init, PeiRebase_Ia32, PeiRebase_Ipf, PeiRebase_X64"/>\r
+\r
+  <target name="init">\r
+    <echo message="The EDK Tool: ${ToolName}"/>\r
+    <mkdir dir="${BUILD_DIR}"/>\r
+    <if>\r
+      <equals arg1="${GCC}" arg2="cygwin"/>\r
+      <then>\r
+        <echo message="Cygwin Family"/>\r
+        <property name="ToolChain" value="gcc"/>\r
+      </then>\r
+    <elseif>\r
+      <os family="dos"/>\r
+      <then>\r
+        <echo message="Windows Family"/>\r
+        <property name="ToolChain" value="msvc"/>\r
+      </then>\r
+    </elseif>\r
+    <elseif>\r
+      <os family="unix"/>\r
+      <then>\r
+        <echo message="UNIX Family"/>\r
+        <property name="ToolChain" value="gcc"/>\r
+      </then>\r
+    </elseif>\r
+\r
+    <else>\r
+      <echo>\r
+        Unsupported Operating System\r
+        Please Contact Intel Corporation\r
+      </echo>\r
+    </else>\r
+    </if>\r
+               <if>\r
+                 <equals arg1="${ToolChain}" arg2="msvc"/>\r
+                       <then>\r
+        <property name="ext_static" value=".lib"/>\r
+        <property name="ext_dynamic" value=".dll"/>\r
+        <property name="ext_exe" value=".exe"/>\r
+                       </then>\r
+                       <elseif>\r
+                         <equals arg1="${ToolChain}" arg2="gcc"/>\r
+                               <then>\r
+          <property name="ext_static" value=".a"/>\r
+          <property name="ext_dynamic" value=".so"/>\r
+          <property name="ext_exe" value=""/>\r
+                               </then>\r
+                       </elseif>\r
+               </if>\r
+  </target>\r
+\r
+  <target name="PeiRebase_Ia32" depends="init">\r
+    <cc name="${ToolChain}" objdir="${BUILD_DIR}" \r
+        outfile="${BIN_DIR}/${ToolName}_Ia32"\r
+        outtype="executable"\r
+        optimize="speed">\r
+\r
+      <fileset dir="${basedir}/${ToolName}" \r
+        includes="${FileSet}"/>\r
+\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
+      <includepath path="${PACKAGE_DIR}/Common"/>\r
+                       <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress PeCoffLoader_Ia32"/>\r
+    </cc>\r
+  </target>\r
+\r
+  <target name="PeiRebase_Ipf" depends="init">\r
+    <cc name="${ToolChain}" objdir="${BUILD_DIR}" \r
+        outfile="${BIN_DIR}/${ToolName}_Ipf"\r
+        outtype="executable"\r
+        optimize="speed">\r
+\r
+      <fileset dir="${basedir}/${ToolName}" \r
+        includes="${FileSet}"/>\r
+\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
+      <includepath path="${PACKAGE_DIR}/Common"/>\r
+                       <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress PeCoffLoader_Ipf"/>\r
+    </cc>\r
+  </target>\r
+\r
+  <target name="PeiRebase_X64" depends="init">\r
+    <cc name="${ToolChain}" objdir="${BUILD_DIR}" \r
+        outfile="${BIN_DIR}/${ToolName}_X64"\r
+        outtype="executable"\r
+        optimize="speed">\r
+\r
+      <fileset dir="${basedir}/${ToolName}" \r
+        includes="${FileSet}" />\r
+\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Ia32"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Common"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Protocol"/>\r
+      <includepath path="${env.WORKSPACE}/MdePkg/Include/Library"/>\r
+      <includepath path="${PACKAGE_DIR}/Common"/>\r
+                       <libset dir="${LIB_DIR}" libs="CommonTools CustomizedCompress PeCoffLoader_X64"/>\r
+    </cc>\r
+  </target>\r
+\r
+  <target name="clean" depends="init">\r
+    <echo message="Removing Intermediate Files Only"/>  \r
+    <delete>\r
+      <fileset dir="${BUILD_DIR}" includes="*.obj"/>\r
+    </delete>\r
+  </target>\r
+\r
+  <target name="cleanall" depends="init">\r
+    <echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>  \r
+    <delete dir="${BUILD_DIR}">\r
+      <fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>\r
+    </delete>\r
+  </target>\r
+\r
+</project>\r
index d5446f1..129e99f 100644 (file)
@@ -22,6 +22,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   <property name="LIB_DIR" value="${PACKAGE_DIR}/Library" />\r
   <property name="BIN_DIR" value="${WORKSPACE}/Tools/bin" />\r
   <property name="BUILD_MODE" value="PACKAGE" />\r
+  <property name="Libs" \r
+    value="Common/build.xml CustomizedCompress/build.xml PeCoffLoader/build.xml"/>\r
 \r
   <import file="${WORKSPACE_DIR}/Tools/Conf/BuildMacro.xml" />\r
 \r
@@ -92,14 +94,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   <target name="Libraries">\r
     <subant target="" inheritall="true">\r
       <fileset dir="${PACKAGE_DIR}" \r
-        includes="Common/build.xml CustomizedCompress/build.xml"/>\r
+        includes="${Libs}"/>\r
     </subant>\r
   </target>\r
 \r
   <target name="Tools" depends="Libraries">\r
     <subant target="" inheritall="true">\r
       <fileset dir="${PACKAGE_DIR}" includes="*/build.xml"\r
-        excludes="Common/build.xml CustomizedCompress/build.xml"/>\r
+        excludes="${Libs}"/>\r
     </subant>\r
   </target>\r
 \r