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))
30 Performs an Itanium-based specific relocation fixup and is a no-op on other
33 @param Reloc The pointer to the relocation record.
34 @param Fixup The pointer to the address to fix up.
35 @param FixupData The pointer to a buffer to log the fixups.
36 @param Adjust The offset to adjust the fixup.
42 PeCoffLoaderRelocateImageEx (
45 IN OUT CHAR8
**FixupData
,
50 Performs an Itanium-based specific re-relocation fixup and is a no-op on other
51 instruction sets. This is used to re-relocated the image into the EFI virtual
52 space for runtime calls.
54 @param Reloc The pointer to the relocation record.
55 @param Fixup The pointer to the address to fix up.
56 @param FixupData The pointer to a buffer to log the fixups.
57 @param Adjust The offset to adjust the fixup.
63 PeHotRelocateImageEx (
66 IN OUT CHAR8
**FixupData
,
71 Returns TRUE if the machine type of PE/COFF image is supported. Supported
72 does not mean the image can be executed it means the PE/COFF loader supports
73 loading and relocating of the image type. It's up to the caller to support
76 @param Machine Machine type from the PE Header.
78 @return TRUE if this PE/COFF loader can load the image
82 PeCoffLoaderImageFormatSupported (
87 Retrieves the magic value from the PE/COFF header.
89 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
91 @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32
92 @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+
96 PeCoffLoaderGetPeHeaderMagicValue (
97 IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
101 Retrieves the PE or TE Header from a PE/COFF or TE image.
103 @param ImageContext The context of the image being loaded.
104 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
106 @retval RETURN_SUCCESS The PE or TE Header is read.
107 @retval Other The error status from reading the PE/COFF or TE image using the ImageRead function.
111 PeCoffLoaderGetPeHeader (
112 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
113 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
117 Converts an image address to the loaded address.
119 @param ImageContext The context of the image being loaded.
120 @param Address The address to be converted to the loaded address.
121 @param TeStrippedOffset Stripped offset for TE image.
123 @return The converted address or NULL if the address can not be converted.
127 PeCoffLoaderImageAddress (
128 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
130 IN UINTN TeStrippedOffset