]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: Added ARM Aarch64 support to PE/COFF support
authorHarry Liebel <Harry.Liebel@arm.com>
Mon, 29 Jul 2013 09:50:38 +0000 (09:50 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 29 Jul 2013 09:50:38 +0000 (09:50 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Harry Liebel <Harry.Liebel@arm.com>
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14512 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Include/IndustryStandard/PeImage.h
MdePkg/Library/BasePeCoffLib/AArch64/PeCoffLoaderEx.c [new file with mode: 0644]
MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf

index c0e812873c37171cb00ed1c0de75613baa30ffe7..1abe72971ecbfb9e8faf8098ce88f2c9d8441de9 100644 (file)
@@ -4,7 +4,7 @@
   EFI_IMAGE_NT_HEADERS64 is for PE32+. \r
 \r
   This file is coded to the Visual Studio, Microsoft Portable Executable and \r
-  Common Object File Format Specification, Revision 8.0 - May 16, 2006. \r
+  Common Object File Format Specification, Revision 8.3 - February 6, 2013.\r
   This file also includes some definitions in PI Specification, Revision 1.0.\r
 \r
 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
@@ -39,6 +39,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define IMAGE_FILE_MACHINE_EBC             0x0EBC\r
 #define IMAGE_FILE_MACHINE_X64             0x8664\r
 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED  0x01c2\r
+#define IMAGE_FILE_MACHINE_ARM64           0xAA64\r
 \r
 //\r
 // EXE file formats\r
diff --git a/MdePkg/Library/BasePeCoffLib/AArch64/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/AArch64/PeCoffLoaderEx.c
new file mode 100644 (file)
index 0000000..e14fce0
--- /dev/null
@@ -0,0 +1,127 @@
+/** @file\r
+  Specific relocation fixups for ARM architecture.\r
+\r
+  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
+  Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>\r
+\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
+  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
+\r
+#include "BasePeCoffLibInternals.h"\r
+#include <Library/BaseLib.h>\r
+\r
+// Note: Currently only large memory model is supported by UEFI relocation code.\r
+\r
+/**\r
+  Performs an AARCH64-based specific relocation fixup and is a no-op on other\r
+  instruction sets.\r
+\r
+  @param  Reloc       The pointer to the relocation record.\r
+  @param  Fixup       The pointer to the address to fix up.\r
+  @param  FixupData   The pointer to a buffer to log the fixups.\r
+  @param  Adjust      The offset to adjust the fixup.\r
+\r
+  @return Status code.\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
+  UINT64      *F64;\r
+\r
+  switch ((*Reloc) >> 12) {\r
+\r
+    case EFI_IMAGE_REL_BASED_DIR64:\r
+      F64 = (UINT64 *) Fixup;\r
+      *F64 = *F64 + (UINT64) Adjust;\r
+      if (*FixupData != NULL) {\r
+        *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));\r
+        *(UINT64 *)(*FixupData) = *F64;\r
+        *FixupData = *FixupData + sizeof(UINT64);\r
+      }\r
+      break;\r
+\r
+    default:\r
+      return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/**\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
+  @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 == IMAGE_FILE_MACHINE_ARM64) || (Machine ==  IMAGE_FILE_MACHINE_EBC)) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Performs an ARM-based 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       The pointer to the relocation record.\r
+  @param  Fixup       The pointer to the address to fix up.\r
+  @param  FixupData   The pointer to a buffer to log the fixups.\r
+  @param  Adjust      The offset to adjust the fixup.\r
+\r
+  @return Status code.\r
+\r
+**/\r
+RETURN_STATUS\r
+PeHotRelocateImageEx (\r
+  IN UINT16      *Reloc,\r
+  IN OUT CHAR8   *Fixup,\r
+  IN OUT CHAR8   **FixupData,\r
+  IN UINT64      Adjust\r
+  )\r
+{\r
+  UINT64  *Fixup64;\r
+\r
+  switch ((*Reloc) >> 12) {\r
+  case EFI_IMAGE_REL_BASED_DIR64:\r
+    Fixup64     = (UINT64 *) Fixup;\r
+    *FixupData  = ALIGN_POINTER (*FixupData, sizeof (UINT64));\r
+    if (*(UINT64 *) (*FixupData) == *Fixup64) {\r
+      *Fixup64 = *Fixup64 + (UINT64) Adjust;\r
+    }\r
+\r
+    *FixupData = *FixupData + sizeof (UINT64);\r
+    break;\r
+\r
+  default:\r
+    DEBUG ((EFI_D_ERROR, "PeHotRelocateEx:unknown fixed type\n"));\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
index 470ae884069caf7594540ae4f11e1877f30c454a..1cc979bd30159ea657af815a851fd876fd930781 100644 (file)
@@ -32,7 +32,7 @@
 \r
 \r
 #\r
-#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC ARM\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC ARM AARCH64\r
 #\r
 \r
 [Sources]\r
@@ -48,6 +48,9 @@
 [Sources.ARM]\r
   Arm/PeCoffLoaderEx.c\r
 \r
+[Sources.AARCH64]\r
+  AArch64/PeCoffLoaderEx.c\r
+\r
 [Packages]\r
   MdePkg/MdePkg.dec\r
 \r