From a8f69bde9648e4e0db6c9e15490ae3bb9f6300c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Ha=CC=88user?= <8659494+mhaeuser@users.noreply.github.com> Date: Sun, 16 Apr 2023 18:26:50 +0200 Subject: [PATCH] MdePkg/PeCoffLib2: Expose ARM Thumb MOVW/MOVT relocation helpers --- MdePkg/Include/Library/PeCoffLib2.h | 24 +++++++++++++++++++ .../Library/BasePeCoffLib2/PeCoffRelocate.c | 19 ++++----------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/MdePkg/Include/Library/PeCoffLib2.h b/MdePkg/Include/Library/PeCoffLib2.h index b62f5204d1..95222dfdef 100644 --- a/MdePkg/Include/Library/PeCoffLib2.h +++ b/MdePkg/Include/Library/PeCoffLib2.h @@ -564,4 +564,28 @@ PeCoffLoaderGetImageAddress ( IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *Context ); +/** + Retrieve the immediate data encoded in an ARM MOVW/MOVT instruciton pair. + + @param[in] Instructions Pointer to an ARM MOVW/MOVT insturction pair. + + @returns The Immediate address encoded in the instructions. +**/ +UINT32 +PeCoffThumbMovwMovtImmediateAddress ( + IN CONST VOID *Instructions + ); + +/** + Relocate an ARM MOVW/MOVT immediate instruction instruction pair. + + @param[in,out] Instructions Pointer to ARM MOVW/MOVT instruction pair. + @param[in] Adjust The delta to add to the addresses. +**/ +VOID +PeCoffThumbMovwMovtImmediateFixup ( + IN OUT VOID *Instructions, + IN UINT64 Adjust + ); + #endif // PE_COFF_LIB2_H_ diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c b/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c index 90e7a8ccb0..1fb84e64cc 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c @@ -137,16 +137,8 @@ ThumbMovtImmediatePatch ( (PatchedInstruction & ~(UINT16) 0x70FFU) | Patch; } -/** - Retrieve the immediate data encoded in an ARM MOVW/MOVT instruciton pair. - - @param[in] Instructions Pointer to an ARM MOVW/MOVT insturction pair. - - @returns The Immediate address encoded in the instructions. -**/ -STATIC UINT32 -ThumbMovwMovtImmediateAddress ( +PeCoffThumbMovwMovtImmediateAddress ( IN CONST VOID *Instructions ) { @@ -192,9 +184,8 @@ ThumbMovwMovtImmediatePatch ( @param[in,out] Instructions Pointer to ARM MOVW/MOVT instruction pair. @param[in] Adjust The delta to add to the addresses. **/ -STATIC VOID -ThumbMovwMovtImmediateFixup ( +PeCoffThumbMovwMovtImmediateFixup ( IN OUT VOID *Instructions, IN UINT64 Adjust ) @@ -203,7 +194,7 @@ ThumbMovwMovtImmediateFixup ( // // Relocate the instruction pair. // - Fixup32 = ThumbMovwMovtImmediateAddress (Instructions) + (UINT32) Adjust; + Fixup32 = PeCoffThumbMovwMovtImmediateAddress (Instructions) + (UINT32) Adjust; ThumbMovwMovtImmediatePatch (Instructions, Fixup32); } @@ -396,7 +387,7 @@ InternalApplyRelocation ( // // Relocate the target instruction. // - ThumbMovwMovtImmediateFixup (Fixup, Adjust); + PeCoffThumbMovwMovtImmediateFixup (Fixup, Adjust); // // Record the relocated value for Image runtime relocation. // @@ -715,7 +706,7 @@ InternalApplyRelocationRuntime ( return RETURN_VOLUME_CORRUPTED; } - ThumbMovwMovtImmediateFixup (Fixup, Adjust); + PeCoffThumbMovwMovtImmediateFixup (Fixup, Adjust); break;