|
From: <and...@us...> - 2010-12-21 20:38:17
|
Revision: 2104
http://edk2-buildtools.svn.sourceforge.net/edk2-buildtools/?rev=2104&view=rev
Author: andrewfish
Date: 2010-12-21 20:38:10 +0000 (Tue, 21 Dec 2010)
Log Message:
-----------
Update tools to follow latest PE/COFF specification in reguards to ARM MOVW/MOVT relocations that were added in the latest specification. Previous implementation was a guess on how it may be implemented, so it was removed.
Modified Paths:
--------------
trunk/BaseTools/Source/C/Common/PeCoffLib.h
trunk/BaseTools/Source/C/Common/PeCoffLoaderEx.c
trunk/BaseTools/Source/C/GenFw/Elf32Convert.c
trunk/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
Modified: trunk/BaseTools/Source/C/Common/PeCoffLib.h
===================================================================
--- trunk/BaseTools/Source/C/Common/PeCoffLib.h 2010-12-15 00:54:06 UTC (rev 2103)
+++ trunk/BaseTools/Source/C/Common/PeCoffLib.h 2010-12-21 20:38:10 UTC (rev 2104)
@@ -159,6 +159,7 @@
**/
UINT16
+EFIAPI
ThumbMovtImmediateAddress (
IN UINT16 *Instruction
);
@@ -171,11 +172,41 @@
**/
VOID
+EFIAPI
ThumbMovtImmediatePatch (
IN OUT UINT16 *Instruction,
IN UINT16 Address
);
+/**
+ Pass in a pointer to an ARM MOVW/MOVT instruciton pair and
+ return the immediate data encoded in the two` instruction
+ @param Instructions Pointer to ARM MOVW/MOVT insturction pair
+
+ @return Immediate address encoded in the instructions
+
+**/
+UINT32
+EFIAPI
+ThumbMovwMovtImmediateAddress (
+ IN UINT16 *Instructions
+ );
+
+/**
+ Update an ARM MOVW/MOVT immediate instruction instruction pair.
+
+ @param Instructions Pointer to ARM MOVW/MOVT instruction pair
+ @param Address New addres to patch into the instructions
+**/
+VOID
+EFIAPI
+ThumbMovwMovtImmediatePatch (
+ IN OUT UINT16 *Instructions,
+ IN UINT32 Address
+ );
+
+
+
#endif
Modified: trunk/BaseTools/Source/C/Common/PeCoffLoaderEx.c
===================================================================
--- trunk/BaseTools/Source/C/Common/PeCoffLoaderEx.c 2010-12-15 00:54:06 UTC (rev 2103)
+++ trunk/BaseTools/Source/C/Common/PeCoffLoaderEx.c 2010-12-21 20:38:10 UTC (rev 2104)
@@ -24,7 +24,9 @@
#include <Common/UefiBaseTypes.h>
#include <IndustryStandard/PeImage.h>
#include "PeCoffLib.h"
+#include "CommonLib.h"
+
#define EXT_IMM64(Value, Address, Size, InstPos, ValPos) \
Value |= (((UINT64)((*(Address) >> InstPos) & (((UINT64)1 << Size) - 1))) << ValPos)
@@ -375,6 +377,55 @@
}
/**
+ Pass in a pointer to an ARM MOVW/MOVT instruciton pair and
+ return the immediate data encoded in the two` instruction
+
+ @param Instructions Pointer to ARM MOVW/MOVT insturction pair
+
+ @return Immediate address encoded in the instructions
+
+**/
+UINT32
+EFIAPI
+ThumbMovwMovtImmediateAddress (
+ IN UINT16 *Instructions
+ )
+{
+ UINT16 *Word;
+ UINT16 *Top;
+
+ Word = Instructions; // MOVW
+ Top = Word + 2; // MOVT
+
+ return (ThumbMovtImmediateAddress (Top) << 16) + ThumbMovtImmediateAddress (Word);
+}
+
+
+/**
+ Update an ARM MOVW/MOVT immediate instruction instruction pair.
+
+ @param Instructions Pointer to ARM MOVW/MOVT instruction pair
+ @param Address New addres to patch into the instructions
+**/
+VOID
+EFIAPI
+ThumbMovwMovtImmediatePatch (
+ IN OUT UINT16 *Instructions,
+ IN UINT32 Address
+ )
+{
+ UINT16 *Word;
+ UINT16 *Top;
+
+ Word = (UINT16 *)Instructions; // MOVW
+ Top = Word + 2; // MOVT
+
+ ThumbMovtImmediatePatch (Word, (UINT16)(Address & 0xffff));
+ ThumbMovtImmediatePatch (Top, (UINT16)(Address >> 16));
+}
+
+
+/**
Performs an ARM-based specific relocation fixup and is a no-op on other
instruction sets.
@@ -395,38 +446,26 @@
)
{
UINT16 *Fixup16;
- UINT16 FixupVal;
- UINT16 *Addend;
+ UINT32 FixupVal;
- Fixup16 = (UINT16 *) Fixup;
+ Fixup16 = (UINT16 *) Fixup;
switch ((**Reloc) >> 12) {
- case EFI_IMAGE_REL_BASED_ARM_THUMB_MOVW:
- FixupVal = ThumbMovtImmediateAddress (Fixup16) + (UINT16)Adjust;
- ThumbMovtImmediatePatch (Fixup16, FixupVal);
-
+
+ case EFI_IMAGE_REL_BASED_ARM_MOV32T:
+ FixupVal = ThumbMovwMovtImmediateAddress (Fixup16) + (UINT32)Adjust;
+ ThumbMovwMovtImmediatePatch (Fixup16, FixupVal);
+
+
if (*FixupData != NULL) {
- *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT16));
- *(UINT16 *)*FixupData = *Fixup16;
- *FixupData = *FixupData + sizeof (UINT16);
+ *FixupData = ALIGN_POINTER(*FixupData, sizeof(UINT64));
+ *(UINT64 *)(*FixupData) = *Fixup16;
+ CopyMem (*FixupData, Fixup16, sizeof (UINT64));
}
break;
-
- case EFI_IMAGE_REL_BASED_ARM_THUMB_MOVT:
- // For MOVT you need to know the lower 16-bits do do the math
- // So this relocation entry is really two entries.
- *Reloc = *Reloc + 1;
- Addend = *Reloc;
- FixupVal = (UINT16)(((ThumbMovtImmediateAddress (Fixup16) << 16) + Adjust + *Addend) >> 16);
- ThumbMovtImmediatePatch (Fixup16, FixupVal);
-
- if (*FixupData != NULL) {
- *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT16));
- *(UINT16 *)*FixupData = *Fixup16;
- *FixupData = *FixupData + sizeof (UINT16);
- }
- break;
+ case EFI_IMAGE_REL_BASED_ARM_MOV32A:
+ // break omitted - ARM instruction encoding not implemented
default:
return RETURN_UNSUPPORTED;
}
Modified: trunk/BaseTools/Source/C/GenFw/Elf32Convert.c
===================================================================
--- trunk/BaseTools/Source/C/GenFw/Elf32Convert.c 2010-12-15 00:54:06 UTC (rev 2103)
+++ trunk/BaseTools/Source/C/GenFw/Elf32Convert.c 2010-12-21 20:38:10 UTC (rev 2104)
@@ -650,18 +650,18 @@
case R_ARM_THM_ALU_PREL_11_0:
case R_ARM_THM_PC12:
case R_ARM_REL32_NOI:
- case R_ARM_ALU_PC_G0_NC:
- case R_ARM_ALU_PC_G0:
- case R_ARM_ALU_PC_G1_NC:
- case R_ARM_ALU_PC_G1:
- case R_ARM_ALU_PC_G2:
- case R_ARM_LDR_PC_G1:
- case R_ARM_LDR_PC_G2:
- case R_ARM_LDRS_PC_G0:
- case R_ARM_LDRS_PC_G1:
- case R_ARM_LDRS_PC_G2:
- case R_ARM_LDC_PC_G0:
- case R_ARM_LDC_PC_G1:
+ case R_ARM_ALU_PC_G0_NC:
+ case R_ARM_ALU_PC_G0:
+ case R_ARM_ALU_PC_G1_NC:
+ case R_ARM_ALU_PC_G1:
+ case R_ARM_ALU_PC_G2:
+ case R_ARM_LDR_PC_G1:
+ case R_ARM_LDR_PC_G2:
+ case R_ARM_LDRS_PC_G0:
+ case R_ARM_LDRS_PC_G1:
+ case R_ARM_LDRS_PC_G2:
+ case R_ARM_LDC_PC_G0:
+ case R_ARM_LDC_PC_G1:
case R_ARM_LDC_PC_G2:
case R_ARM_GOT_PREL:
case R_ARM_THM_JUMP11:
@@ -704,6 +704,8 @@
return TRUE;
}
+UINTN gMovwOffset = 0;
+
STATIC
VOID
WriteRelocations32 (
@@ -786,18 +788,18 @@
case R_ARM_THM_ALU_PREL_11_0:
case R_ARM_THM_PC12:
case R_ARM_REL32_NOI:
- case R_ARM_ALU_PC_G0_NC:
- case R_ARM_ALU_PC_G0:
- case R_ARM_ALU_PC_G1_NC:
- case R_ARM_ALU_PC_G1:
- case R_ARM_ALU_PC_G2:
- case R_ARM_LDR_PC_G1:
- case R_ARM_LDR_PC_G2:
- case R_ARM_LDRS_PC_G0:
- case R_ARM_LDRS_PC_G1:
- case R_ARM_LDRS_PC_G2:
- case R_ARM_LDC_PC_G0:
- case R_ARM_LDC_PC_G1:
+ case R_ARM_ALU_PC_G0_NC:
+ case R_ARM_ALU_PC_G0:
+ case R_ARM_ALU_PC_G1_NC:
+ case R_ARM_ALU_PC_G1:
+ case R_ARM_ALU_PC_G2:
+ case R_ARM_LDR_PC_G1:
+ case R_ARM_LDR_PC_G2:
+ case R_ARM_LDRS_PC_G0:
+ case R_ARM_LDRS_PC_G1:
+ case R_ARM_LDRS_PC_G2:
+ case R_ARM_LDC_PC_G0:
+ case R_ARM_LDC_PC_G1:
case R_ARM_LDC_PC_G2:
case R_ARM_GOT_PREL:
case R_ARM_THM_JUMP11:
@@ -812,19 +814,18 @@
CoffAddFixup (
mCoffSectionsOffset[RelShdr->sh_info]
+ (Rel->r_offset - SecShdr->sh_addr),
- EFI_IMAGE_REL_BASED_ARM_THUMB_MOVW
+ EFI_IMAGE_REL_BASED_ARM_MOV32T
);
+
+ // PE/COFF treats MOVW/MOVT relocation as single 64-bit instruction
+ // Track this address so we can log an error for unsupported sequence of MOVW/MOVT
+ gMovwOffset = mCoffSectionsOffset[RelShdr->sh_info] + (Rel->r_offset - SecShdr->sh_addr);
break;
case R_ARM_THM_MOVT_ABS:
- CoffAddFixup (
- mCoffSectionsOffset[RelShdr->sh_info]
- + (Rel->r_offset - SecShdr->sh_addr),
- EFI_IMAGE_REL_BASED_ARM_THUMB_MOVT
- );
-
- // The relocation entry needs to contain the lower 16-bits so we can do math
- CoffAddFixupEntry ((UINT16)(Sym->st_value - SymShdr->sh_addr + mCoffSectionsOffset[Sym->st_shndx]));
+ if ((gMovwOffset + 4) != (mCoffSectionsOffset[RelShdr->sh_info] + (Rel->r_offset - SecShdr->sh_addr))) {
+ Error (NULL, 0, 3000, "Not Supported", "PE/COFF requires MOVW+MOVT instruction sequence %x +4 != %x.", gMovwOffset, mCoffSectionsOffset[RelShdr->sh_info] + (Rel->r_offset - SecShdr->sh_addr));
+ }
break;
case R_ARM_ABS32:
Modified: trunk/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
===================================================================
--- trunk/BaseTools/Source/C/Include/IndustryStandard/PeImage.h 2010-12-15 00:54:06 UTC (rev 2103)
+++ trunk/BaseTools/Source/C/Include/IndustryStandard/PeImage.h 2010-12-21 20:38:10 UTC (rev 2104)
@@ -516,8 +516,6 @@
#define EFI_IMAGE_REL_BASED_IA64_IMM64 9
#define EFI_IMAGE_REL_BASED_DIR64 10
-#define EFI_IMAGE_REL_BASED_ARM_THUMB_MOVW 11
-#define EFI_IMAGE_REL_BASED_ARM_THUMB_MOVT 12
///
/// Line number format.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|