2 Declaration of internal functions in PE/COFF Lib.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef __BASE_PECOFF_LIB_INTERNALS__
11 #define __BASE_PECOFF_LIB_INTERNALS__
14 #include <Library/PeCoffLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/PeCoffExtraActionLib.h>
18 #include <IndustryStandard/PeImage.h>
21 // Macro definitions for RISC-V architecture.
23 #define RV_X(x, s, n) (((x) >> (s)) & ((1<<(n))-1))
24 #define RISCV_IMM_BITS 12
25 #define RISCV_IMM_REACH (1LL<<RISCV_IMM_BITS)
26 #define RISCV_CONST_HIGH_PART(VALUE) \
27 (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))
31 Performs an Itanium-based specific relocation fixup and is a no-op on other
34 @param Reloc The pointer to the relocation record.
35 @param Fixup The pointer to the address to fix up.
36 @param FixupData The pointer to a buffer to log the fixups.
37 @param Adjust The offset to adjust the fixup.
43 PeCoffLoaderRelocateImageEx (
46 IN OUT CHAR8
**FixupData
,
52 Performs an Itanium-based specific re-relocation fixup and is a no-op on other
53 instruction sets. This is used to re-relocated the image into the EFI virtual
54 space for runtime calls.
56 @param Reloc The pointer to the relocation record.
57 @param Fixup The pointer to the address to fix up.
58 @param FixupData The pointer to a buffer to log the fixups.
59 @param Adjust The offset to adjust the fixup.
65 PeHotRelocateImageEx (
68 IN OUT CHAR8
**FixupData
,
74 Returns TRUE if the machine type of PE/COFF image is supported. Supported
75 does not mean the image can be executed it means the PE/COFF loader supports
76 loading and relocating of the image type. It's up to the caller to support
79 @param Machine Machine type from the PE Header.
81 @return TRUE if this PE/COFF loader can load the image
85 PeCoffLoaderImageFormatSupported (
90 Retrieves the magic value from the PE/COFF header.
92 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
94 @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
95 @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
99 PeCoffLoaderGetPeHeaderMagicValue (
100 IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
104 Retrieves the PE or TE Header from a PE/COFF or TE image.
106 @param ImageContext The context of the image being loaded.
107 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
109 @retval RETURN_SUCCESS The PE or TE Header is read.
110 @retval Other The error status from reading the PE/COFF or TE image using the ImageRead function.
114 PeCoffLoaderGetPeHeader (
115 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
116 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
120 Converts an image address to the loaded address.
122 @param ImageContext The context of the image being loaded.
123 @param Address The address to be converted to the loaded address.
124 @param TeStrippedOffset Stripped offset for TE image.
126 @return The converted address or NULL if the address can not be converted.
130 PeCoffLoaderImageAddress (
131 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
133 IN UINTN TeStrippedOffset