]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c
Handle new relocation type EFI_IMAGE_REL_BASED_DIR64 for X64.
[mirror_edk2.git] / MdePkg / Library / BasePeCoffLib / x64 / PeCoffLoaderEx.c
index 7648447f7190fb4d9a69de2a35ef8ac34400b5ec..8628dc7df12a1ce9ac858fb25d99e54ac819357f 100644 (file)
@@ -1,35 +1,85 @@
 /** @file\r
   x64 Specific relocation fixups.\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
+Copyright (c) 2005 - 2006 Intel Corporation. <BR>\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
-  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
+/**\r
+  Performs an x64 specific relocation fixup.\r
 \r
-  Module Name:  PeCoffLoaderEx.c\r
+  @param  Reloc       Pointer to the relocation record\r
+  @param  Fixup       Pointer to the address to fix up\r
+  @param  FixupData   Pointer to a buffer to log the fixups\r
+  @param  Adjust      The offset to adjust the fixup\r
 \r
+  @retval RETURN_SUCCESS      Success to perform relocation\r
+  @retval RETURN_UNSUPPORTED  Unsupported.\r
 **/\r
+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
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Returns TRUE if the machine type of PE/COFF image is supported. Supported \r
+  does not mean the image can be executed it means the PE/COFF loader supports\r
+  loading and relocating of the image type. It's up to the caller to support\r
+  the entry point. \r
 \r
+  This function implies the basic PE/COFF loader/relocator supports IA32, EBC,\r
+  & X64 images. Calling the entry point in a correct mannor is up to the \r
+  consumer of this library.\r
 \r
+  @param  Machine   Machine type from the PE Header.\r
+\r
+  @return TRUE if this PE/COFF loader can load the image\r
+\r
+**/\r
+BOOLEAN\r
+PeCoffLoaderImageFormatSupported (\r
+  IN  UINT16  Machine\r
+  )\r
+{\r
+  if ((Machine == EFI_IMAGE_MACHINE_IA32) || (Machine == EFI_IMAGE_MACHINE_X64) || \r
+      (Machine ==  EFI_IMAGE_MACHINE_EBC)) {\r
+    return TRUE; \r
+  }\r
+\r
+  return FALSE;\r
+}\r
 \r
 \r
 /**\r
-  Performs an x64 specific relocation fixup.\r
+  Performs an X64 specific re-relocation fixup and is a no-op on other\r
+  instruction sets. This is used to re-relocated the image into the EFI virtual\r
+  space for runtime calls.\r
+\r
+  @param  Reloc       Pointer to the relocation record.\r
+  @param  Fixup       Pointer to the address to fix up.\r
+  @param  FixupData   Pointer to a buffer to log the fixups.\r
+  @param  Adjust      The offset to adjust the fixup.\r
 \r
-  @param  Reloc Pointer to the relocation record\r
-  @param  Fixup Pointer to the address to fix up\r
-  @param  FixupData Pointer to a buffer to log the fixups\r
-  @param  Adjust The offset to adjust the fixup\r
+  @return Status code.\r
 \r
 **/\r
 RETURN_STATUS\r
-PeCoffLoaderRelocateImageEx (\r
+PeHotRelocateImageEx (\r
   IN UINT16      *Reloc,\r
-  IN OUT CHAR8   *Fixup, \r
+  IN OUT CHAR8   *Fixup,\r
   IN OUT CHAR8   **FixupData,\r
   IN UINT64      Adjust\r
   )\r
@@ -37,20 +87,19 @@ PeCoffLoaderRelocateImageEx (
   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
+      *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));\r
+      if (*(UINT64 *)(*FixupData) == *F64) {\r
+        *F64  = *F64 + (UINT64) Adjust;\r
       }\r
+\r
+      *FixupData = *FixupData + sizeof(UINT64);\r
       break;\r
 \r
     default:\r
       return RETURN_UNSUPPORTED;\r
   }\r
-\r
\r
   return RETURN_SUCCESS;\r
 }\r