]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Common/BasePeCoff.c
Sync BaseTool trunk (version r2599) into EDKII BaseTools.
[mirror_edk2.git] / BaseTools / Source / C / Common / BasePeCoff.c
index 878c1c611b8d11b00cc0d6d7fbc5c28a397c0dd4..afb45df40b8486ec2383780cd88fb6753be1262e 100644 (file)
@@ -2,7 +2,8 @@
 \r
   Functions to get info and load PE/COFF image.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -79,6 +80,14 @@ PeCoffLoaderRelocateArmImage (
   IN UINT64      Adjust\r
   );\r
 \r
+RETURN_STATUS\r
+PeCoffLoaderRelocateAArch64Image (\r
+  IN UINT16      *Reloc,\r
+  IN OUT CHAR8   *Fixup,\r
+  IN OUT CHAR8   **FixupData,\r
+  IN UINT64      Adjust\r
+  );\r
+\r
 STATIC\r
 RETURN_STATUS\r
 PeCoffLoaderGetPeHeader (\r
@@ -194,7 +203,8 @@ Returns:
       ImageContext->Machine != EFI_IMAGE_MACHINE_IA64 && \\r
       ImageContext->Machine != EFI_IMAGE_MACHINE_X64  && \\r
       ImageContext->Machine != EFI_IMAGE_MACHINE_ARMT && \\r
-      ImageContext->Machine != EFI_IMAGE_MACHINE_EBC) {\r
+      ImageContext->Machine != EFI_IMAGE_MACHINE_EBC  && \\r
+      ImageContext->Machine != EFI_IMAGE_MACHINE_AARCH64) {\r
     if (ImageContext->Machine == IMAGE_FILE_MACHINE_ARM) {\r
       //\r
       // There are two types of ARM images. Pure ARM and ARM/Thumb. \r
@@ -629,15 +639,10 @@ Returns:
   }\r
 \r
   //\r
-  // If the destination address is not 0, use that rather than the\r
-  // image address as the relocation target.\r
+  // Use DestinationAddress field of ImageContext as the relocation address even if it is 0.\r
   //\r
-  if (ImageContext->DestinationAddress) {\r
-    BaseAddress = ImageContext->DestinationAddress;\r
-  } else {\r
-    BaseAddress = ImageContext->ImageAddress;\r
-  }\r
-\r
+  BaseAddress = ImageContext->DestinationAddress;\r
+  \r
   if (!(ImageContext->IsTeImage)) {\r
     PeHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((UINTN)ImageContext->ImageAddress + \r
                                             ImageContext->PeCoffHeaderOffset);\r
@@ -796,6 +801,9 @@ Returns:
         case EFI_IMAGE_MACHINE_IA64:\r
           Status = PeCoffLoaderRelocateIpfImage (Reloc, Fixup, &FixupData, Adjust);\r
           break;\r
+        case EFI_IMAGE_MACHINE_AARCH64:\r
+          Status = PeCoffLoaderRelocateAArch64Image (Reloc, Fixup, &FixupData, Adjust);\r
+          break;\r
         default:\r
           Status = RETURN_UNSUPPORTED;\r
           break;\r
@@ -984,14 +992,7 @@ Returns:
             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
@@ -1000,6 +1001,16 @@ Returns:
       return RETURN_LOAD_ERROR;\r
     }\r
 \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
     //\r
     // Read the section\r
     //\r