From da92f27632d2c89fa8726948ac9b02461ca8b61e Mon Sep 17 00:00:00 2001 From: lgao4 Date: Wed, 11 May 2011 10:26:49 +0000 Subject: Sync BaseTools Branch (version r2149) to EDKII main trunk. BaseTool Branch: https://edk2-buildtools.svn.sourceforge.net/svnroot/edk2-buildtools/branches/Releases/BaseTools_r2100 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11640 6f19259b-4bc3-4df7-8a09-765794883524 --- BaseTools/Source/C/Common/PeCoffLoaderEx.c | 89 +++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 25 deletions(-) (limited to 'BaseTools/Source/C/Common/PeCoffLoaderEx.c') diff --git a/BaseTools/Source/C/Common/PeCoffLoaderEx.c b/BaseTools/Source/C/Common/PeCoffLoaderEx.c index 5d827cefe4..2afd441845 100644 --- a/BaseTools/Source/C/Common/PeCoffLoaderEx.c +++ b/BaseTools/Source/C/Common/PeCoffLoaderEx.c @@ -24,6 +24,8 @@ Revision History #include #include #include "PeCoffLib.h" +#include "CommonLib.h" + #define EXT_IMM64(Value, Address, Size, InstPos, ValPos) \ Value |= (((UINT64)((*(Address) >> InstPos) & (((UINT64)1 << Size) - 1))) << ValPos) @@ -374,6 +376,55 @@ ThumbMovtImmediatePatch ( *Instruction = (*Instruction & ~0x70ff) | Patch; } +/** + 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 @@ PeCoffLoaderRelocateArmImage ( ) { 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); - - if (*FixupData != NULL) { - *FixupData = ALIGN_POINTER (*FixupData, sizeof (UINT16)); - *(UINT16 *)*FixupData = *Fixup16; - *FixupData = *FixupData + sizeof (UINT16); - } - 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); - + + 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_MOV32A: + // break omitted - ARM instruction encoding not implemented default: return RETURN_UNSUPPORTED; } -- cgit v1.2.3