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