]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePeCoffLib/Arm/PeCoffLoaderEx.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BasePeCoffLib / Arm / PeCoffLoaderEx.c
index 2fb408e680a283e9546dd211041b8da4cb9f4553..7e868db895fdae76d25ea2a62ace3d785fdd0111 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   Specific relocation fixups for ARM architecture.\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
   Portions copyright (c) 2008 - 2010, Apple Inc. 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
-  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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -18,8 +12,8 @@
 \r
 \r
 /**\r
-  Pass in a pointer to an ARM MOVT or MOVW immediate instruciton and \r
-  return the immediate data encoded in the instruction\r
+  Pass in a pointer to an ARM MOVT or MOVW immediate instruciton and\r
+  return the immediate data encoded in the instruction.\r
 \r
   @param  Instruction   Pointer to ARM MOVT or MOVW immediate instruction\r
 \r
@@ -33,10 +27,10 @@ ThumbMovtImmediateAddress (
 {\r
   UINT32  Movt;\r
   UINT16  Address;\r
-  \r
+\r
   // Thumb2 is two 16-bit instructions working together. Not a single 32-bit instruction\r
   // Example MOVT R0, #0 is 0x0000f2c0 or 0xf2c0 0x0000\r
-  Movt = (*Instruction << 16) | (*(Instruction + 1)); \r
+  Movt = (*Instruction << 16) | (*(Instruction + 1));\r
 \r
   // imm16 = imm4:i:imm3:imm8\r
   //         imm4 -> Bit19:Bit16\r
@@ -45,7 +39,7 @@ ThumbMovtImmediateAddress (
   //         imm8 -> Bit7:Bit0\r
   Address  = (UINT16)(Movt & 0x000000ff);         // imm8\r
   Address |= (UINT16)((Movt >> 4) &  0x0000f700); // imm4 imm3\r
-  Address |= ((Movt & BIT26) ? BIT11 : 0);        // i\r
+  Address |= (((Movt & BIT26) != 0) ? BIT11 : 0); // i\r
   return Address;\r
 }\r
 \r
@@ -65,7 +59,7 @@ ThumbMovtImmediatePatch (
   UINT16  Patch;\r
 \r
   // First 16-bit chunk of instruciton\r
-  Patch  = ((Address >> 12) & 0x000f);            // imm4 \r
+  Patch  = ((Address >> 12) & 0x000f);            // imm4\r
   Patch |= (((Address & BIT11) != 0) ? BIT10 : 0); // i\r
   // Mask out instruction bits and or in address\r
   *(Instruction) = (*Instruction & ~0x040f) | Patch;\r
@@ -81,8 +75,8 @@ ThumbMovtImmediatePatch (
 \r
 \r
 /**\r
-  Pass in a pointer to an ARM MOVW/MOVT instruciton pair and \r
-  return the immediate data encoded in the two` instruction\r
+  Pass in a pointer to an ARM MOVW/MOVT instruciton pair and\r
+  return the immediate data encoded in the two` instruction.\r
 \r
   @param  Instructions  Pointer to ARM MOVW/MOVT insturction pair\r
 \r
@@ -96,10 +90,10 @@ ThumbMovwMovtImmediateAddress (
 {\r
   UINT16  *Word;\r
   UINT16  *Top;\r
-  \r
+\r
   Word = Instructions;  // MOVW\r
   Top  = Word + 2;      // MOVT\r
-  \r
+\r
   return (ThumbMovtImmediateAddress (Top) << 16) + ThumbMovtImmediateAddress (Word);\r
 }\r
 \r
@@ -118,15 +112,15 @@ ThumbMovwMovtImmediatePatch (
 {\r
   UINT16  *Word;\r
   UINT16  *Top;\r
-  \r
+\r
   Word = Instructions;  // MOVW\r
   Top  = Word + 2;      // MOVT\r
 \r
   ThumbMovtImmediatePatch (Word, (UINT16)(Address & 0xffff));\r
   ThumbMovtImmediatePatch (Top, (UINT16)(Address >> 16));\r
 }\r
-  \r
-  \r
+\r
+\r
 \r
 /**\r
   Performs an ARM-based specific relocation fixup and is a no-op on other\r
@@ -154,19 +148,19 @@ PeCoffLoaderRelocateImageEx (
   Fixup16   = (UINT16 *) Fixup;\r
 \r
   switch ((*Reloc) >> 12) {\r
-  \r
+\r
   case EFI_IMAGE_REL_BASED_ARM_MOV32T:\r
     FixupVal = ThumbMovwMovtImmediateAddress (Fixup16) + (UINT32)Adjust;\r
     ThumbMovwMovtImmediatePatch (Fixup16, FixupVal);\r
 \r
     if (*FixupData != NULL) {\r
       *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));\r
-      // Fixup16 is not aligned so we must copy it. Thumb instructions are streams of 16 bytes. \r
+      // Fixup16 is not aligned so we must copy it. Thumb instructions are streams of 16 bytes.\r
       CopyMem (*FixupData, Fixup16, sizeof (UINT64));\r
       *FixupData = *FixupData + sizeof(UINT64);\r
     }\r
     break;\r
-  \r
+\r
   case EFI_IMAGE_REL_BASED_ARM_MOV32A:\r
      ASSERT (FALSE);\r
      // break omitted - ARM instruction encoding not implemented\r
@@ -182,7 +176,7 @@ PeCoffLoaderRelocateImageEx (
   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
+\r
   @param  Machine   Machine type from the PE Header.\r
 \r
   @return TRUE if this PE/COFF loader can load the image\r
@@ -194,7 +188,7 @@ PeCoffLoaderImageFormatSupported (
   )\r
 {\r
   if ((Machine == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) || (Machine ==  IMAGE_FILE_MACHINE_EBC)) {\r
-    return TRUE; \r
+    return TRUE;\r
   }\r
 \r
   return FALSE;\r
@@ -234,8 +228,9 @@ PeHotRelocateImageEx (
       FixupVal = ThumbMovwMovtImmediateAddress (Fixup16) + (UINT32)Adjust;\r
       ThumbMovwMovtImmediatePatch (Fixup16, FixupVal);\r
     }\r
+    *FixupData = *FixupData + sizeof(UINT64);\r
     break;\r
-  \r
+\r
   case EFI_IMAGE_REL_BASED_ARM_MOV32A:\r
     ASSERT (FALSE);\r
     // break omitted - ARM instruction encoding not implemented\r
@@ -243,7 +238,7 @@ PeHotRelocateImageEx (
     DEBUG ((EFI_D_ERROR, "PeHotRelocateEx:unknown fixed type\n"));\r
     return RETURN_UNSUPPORTED;\r
   }\r
-  \r
+\r
   return RETURN_SUCCESS;\r
 }\r
 \r