summaryrefslogtreecommitdiff
path: root/BaseTools/Source/C/Common
diff options
context:
space:
mode:
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2011-05-11 10:26:49 +0000
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2011-05-11 10:26:49 +0000
commitda92f27632d2c89fa8726948ac9b02461ca8b61e (patch)
tree5d81f058c42e5be0d57287a7ddd8e3e4325eda7a /BaseTools/Source/C/Common
parente472e8d3cca67f5e058f26fb6edc214b01114a3c (diff)
downloadedk2-platforms-da92f27632d2c89fa8726948ac9b02461ca8b61e.tar.xz
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
Diffstat (limited to 'BaseTools/Source/C/Common')
-rw-r--r--BaseTools/Source/C/Common/PeCoffLib.h31
-rw-r--r--BaseTools/Source/C/Common/PeCoffLoaderEx.c89
2 files changed, 95 insertions, 25 deletions
diff --git a/BaseTools/Source/C/Common/PeCoffLib.h b/BaseTools/Source/C/Common/PeCoffLib.h
index 31c6f0fca1..fe6b29251b 100644
--- a/BaseTools/Source/C/Common/PeCoffLib.h
+++ b/BaseTools/Source/C/Common/PeCoffLib.h
@@ -159,6 +159,7 @@ PeCoffLoaderGetEntryPoint (
**/
UINT16
+EFIAPI
ThumbMovtImmediateAddress (
IN UINT16 *Instruction
);
@@ -171,11 +172,41 @@ ThumbMovtImmediateAddress (
**/
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
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 <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 @@ ThumbMovtImmediatePatch (
}
/**
+ 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;
}