]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BasePeCoffLib/BasePeCoffLibInternals.h
MdePkg/BasePeCoff: Add RISC-V PE/Coff related code.
[mirror_edk2.git] / MdePkg / Library / BasePeCoffLib / BasePeCoffLibInternals.h
CommitLineData
d071fb19 1/** @file\r
2 Declaration of internal functions in PE/COFF Lib.\r
3\r
d4b6dd93 4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
54a3d5ec 5 Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>\r
9344f092 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
d071fb19 7\r
d071fb19 8**/\r
9\r
10#ifndef __BASE_PECOFF_LIB_INTERNALS__\r
11#define __BASE_PECOFF_LIB_INTERNALS__\r
12\r
f734a10a
A
13#include <Base.h>\r
14#include <Library/PeCoffLib.h>\r
15#include <Library/BaseMemoryLib.h>\r
16#include <Library/DebugLib.h>\r
27b2d249 17#include <Library/PeCoffExtraActionLib.h>\r
f734a10a
A
18#include <IndustryStandard/PeImage.h>\r
19\r
54a3d5ec
AC
20//\r
21// Macro definitions for RISC-V architecture.\r
22//\r
23#define RV_X(x, s, n) (((x) >> (s)) & ((1<<(n))-1))\r
24#define RISCV_IMM_BITS 12\r
25#define RISCV_IMM_REACH (1LL<<RISCV_IMM_BITS)\r
26#define RISCV_CONST_HIGH_PART(VALUE) \\r
27 (((VALUE) + (RISCV_IMM_REACH/2)) & ~(RISCV_IMM_REACH-1))\r
f734a10a 28\r
d071fb19 29\r
30/**\r
31 Performs an Itanium-based specific relocation fixup and is a no-op on other\r
32 instruction sets.\r
33\r
2fc59a00 34 @param Reloc The pointer to the relocation record.\r
35 @param Fixup The pointer to the address to fix up.\r
36 @param FixupData The pointer to a buffer to log the fixups.\r
d071fb19 37 @param Adjust The offset to adjust the fixup.\r
38\r
39 @return Status code.\r
40\r
41**/\r
42RETURN_STATUS\r
43PeCoffLoaderRelocateImageEx (\r
44 IN UINT16 *Reloc,\r
45 IN OUT CHAR8 *Fixup,\r
46 IN OUT CHAR8 **FixupData,\r
47 IN UINT64 Adjust\r
48 );\r
49\r
50\r
51/**\r
52 Performs an Itanium-based specific re-relocation fixup and is a no-op on other\r
53 instruction sets. This is used to re-relocated the image into the EFI virtual\r
54 space for runtime calls.\r
55\r
2fc59a00 56 @param Reloc The pointer to the relocation record.\r
57 @param Fixup The pointer to the address to fix up.\r
58 @param FixupData The pointer to a buffer to log the fixups.\r
d071fb19 59 @param Adjust The offset to adjust the fixup.\r
60\r
61 @return Status code.\r
62\r
63**/\r
64RETURN_STATUS\r
65PeHotRelocateImageEx (\r
66 IN UINT16 *Reloc,\r
67 IN OUT CHAR8 *Fixup,\r
68 IN OUT CHAR8 **FixupData,\r
69 IN UINT64 Adjust\r
70 );\r
71\r
72\r
73/**\r
74 Returns TRUE if the machine type of PE/COFF image is supported. Supported\r
75 does not mean the image can be executed it means the PE/COFF loader supports\r
76 loading and relocating of the image type. It's up to the caller to support\r
77 the entry point.\r
78\r
79 @param Machine Machine type from the PE Header.\r
80\r
81 @return TRUE if this PE/COFF loader can load the image\r
82\r
83**/\r
84BOOLEAN\r
85PeCoffLoaderImageFormatSupported (\r
86 IN UINT16 Machine\r
87 );\r
88\r
89/**\r
90 Retrieves the magic value from the PE/COFF header.\r
91\r
92 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.\r
93\r
94 @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32\r
95 @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+\r
96\r
97**/\r
98UINT16\r
99PeCoffLoaderGetPeHeaderMagicValue (\r
100 IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
101 );\r
102\r
103/**\r
104 Retrieves the PE or TE Header from a PE/COFF or TE image.\r
105\r
106 @param ImageContext The context of the image being loaded.\r
107 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.\r
108\r
109 @retval RETURN_SUCCESS The PE or TE Header is read.\r
110 @retval Other The error status from reading the PE/COFF or TE image using the ImageRead function.\r
111\r
112**/\r
113RETURN_STATUS\r
114PeCoffLoaderGetPeHeader (\r
115 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
116 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
117 );\r
118\r
119/**\r
120 Converts an image address to the loaded address.\r
121\r
bf29dc16
ED
122 @param ImageContext The context of the image being loaded.\r
123 @param Address The address to be converted to the loaded address.\r
124 @param TeStrippedOffset Stripped offset for TE image.\r
d071fb19 125\r
126 @return The converted address or NULL if the address can not be converted.\r
127\r
128**/\r
129VOID *\r
130PeCoffLoaderImageAddress (\r
131 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
bf29dc16
ED
132 IN UINTN Address,\r
133 IN UINTN TeStrippedOffset\r
d071fb19 134 );\r
135\r
136#endif\r