]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | /** @file\r |
2 | Function prototypes and defines on Memory Only PE COFF loader\r | |
3 | \r | |
40d841f6 LG |
4 | Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials \r | |
30fdf114 LG |
6 | are licensed and made available under the terms and conditions of the BSD License \r |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
12 | \r | |
13 | Module Name: PeCoffLib.h\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef __BASE_PE_COFF_LIB_H__\r | |
18 | #define __BASE_PE_COFF_LIB_H__\r | |
19 | \r | |
20 | //\r | |
21 | // Return status codes from the PE/COFF Loader services\r | |
22 | // BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes\r | |
23 | //\r | |
24 | #define IMAGE_ERROR_SUCCESS 0\r | |
25 | #define IMAGE_ERROR_IMAGE_READ 1 \r | |
26 | #define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2\r | |
27 | #define IMAGE_ERROR_INVALID_MACHINE_TYPE 3\r | |
28 | #define IMAGE_ERROR_INVALID_SUBSYSTEM 4\r | |
29 | #define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5\r | |
30 | #define IMAGE_ERROR_INVALID_IMAGE_SIZE 6\r | |
31 | #define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7\r | |
32 | #define IMAGE_ERROR_SECTION_NOT_LOADED 8\r | |
33 | #define IMAGE_ERROR_FAILED_RELOCATION 9\r | |
34 | #define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10\r | |
35 | \r | |
36 | \r | |
37 | //\r | |
38 | // PE/COFF Loader Read Function passed in by caller\r | |
39 | //\r | |
40 | typedef\r | |
41 | RETURN_STATUS\r | |
42 | (EFIAPI *PE_COFF_LOADER_READ_FILE) (\r | |
43 | IN VOID *FileHandle,\r | |
44 | IN UINTN FileOffset,\r | |
45 | IN OUT UINTN *ReadSize,\r | |
46 | OUT VOID *Buffer\r | |
47 | );\r | |
48 | \r | |
49 | //\r | |
50 | // Context structure used while PE/COFF image is being loaded and relocated\r | |
51 | //\r | |
52 | typedef struct {\r | |
53 | PHYSICAL_ADDRESS ImageAddress;\r | |
54 | UINT64 ImageSize;\r | |
55 | PHYSICAL_ADDRESS DestinationAddress;\r | |
56 | PHYSICAL_ADDRESS EntryPoint;\r | |
57 | PE_COFF_LOADER_READ_FILE ImageRead;\r | |
58 | VOID *Handle;\r | |
59 | VOID *FixupData;\r | |
60 | UINT32 SectionAlignment;\r | |
61 | UINT32 PeCoffHeaderOffset;\r | |
62 | UINT32 DebugDirectoryEntryRva;\r | |
63 | VOID *CodeView;\r | |
64 | CHAR8 *PdbPointer;\r | |
65 | UINTN SizeOfHeaders;\r | |
66 | UINT32 ImageCodeMemoryType;\r | |
67 | UINT32 ImageDataMemoryType;\r | |
68 | UINT32 ImageError;\r | |
69 | UINTN FixupDataSize;\r | |
70 | UINT16 Machine;\r | |
71 | UINT16 ImageType;\r | |
72 | BOOLEAN RelocationsStripped;\r | |
73 | BOOLEAN IsTeImage;\r | |
74 | } PE_COFF_LOADER_IMAGE_CONTEXT;\r | |
75 | \r | |
76 | \r | |
77 | /**\r | |
78 | Retrieves information on a PE/COFF image\r | |
79 | \r | |
80 | @param ImageContext The context of the image being loaded\r | |
81 | \r | |
82 | @retval EFI_SUCCESS The information on the PE/COFF image was collected.\r | |
83 | @retval EFI_INVALID_PARAMETER ImageContext is NULL.\r | |
84 | @retval EFI_UNSUPPORTED The PE/COFF image is not supported.\r | |
85 | @retval Otherwise The error status from reading the PE/COFF image using the\r | |
86 | ImageContext->ImageRead() function\r | |
87 | \r | |
88 | **/\r | |
89 | RETURN_STATUS\r | |
90 | EFIAPI\r | |
91 | PeCoffLoaderGetImageInfo (\r | |
92 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
93 | )\r | |
94 | ;\r | |
95 | \r | |
96 | /**\r | |
97 | Relocates a PE/COFF image in memory\r | |
98 | \r | |
99 | @param ImageContext Contains information on the loaded image to relocate\r | |
100 | \r | |
101 | @retval EFI_SUCCESS if the PE/COFF image was relocated\r | |
102 | @retval EFI_LOAD_ERROR if the image is not a valid PE/COFF image\r | |
103 | @retval EFI_UNSUPPORTED not support\r | |
104 | \r | |
105 | **/\r | |
106 | RETURN_STATUS\r | |
107 | EFIAPI\r | |
108 | PeCoffLoaderRelocateImage (\r | |
109 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
110 | )\r | |
111 | ;\r | |
112 | \r | |
113 | /**\r | |
114 | Loads a PE/COFF image into memory\r | |
115 | \r | |
116 | @param ImageContext Contains information on image to load into memory\r | |
117 | \r | |
118 | @retval EFI_SUCCESS if the PE/COFF image was loaded\r | |
119 | @retval EFI_BUFFER_TOO_SMALL if the caller did not provide a large enough buffer\r | |
120 | @retval EFI_LOAD_ERROR if the image is a runtime driver with no relocations\r | |
121 | @retval EFI_INVALID_PARAMETER if the image address is invalid\r | |
122 | \r | |
123 | **/\r | |
124 | RETURN_STATUS\r | |
125 | EFIAPI\r | |
126 | PeCoffLoaderLoadImage (\r | |
127 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r | |
128 | )\r | |
129 | ;\r | |
130 | \r | |
131 | VOID *\r | |
132 | EFIAPI\r | |
133 | PeCoffLoaderGetPdbPointer (\r | |
134 | IN VOID *Pe32Data\r | |
135 | )\r | |
136 | ;\r | |
a709adfa LG |
137 | \r |
138 | RETURN_STATUS\r | |
139 | EFIAPI\r | |
140 | PeCoffLoaderGetEntryPoint (\r | |
141 | IN VOID *Pe32Data,\r | |
142 | OUT VOID **EntryPoint,\r | |
143 | OUT VOID **BaseOfImage\r | |
144 | )\r | |
145 | ;\r | |
146 | \r | |
40d841f6 LG |
147 | //\r |
148 | // These functions are used by the ARM PE/COFF relocation code and by\r | |
149 | // the ELF to PE/COFF converter so that is why they are public\r | |
150 | //\r | |
151 | \r | |
152 | /**\r | |
153 | Pass in a pointer to an ARM MOVT or MOVW immediate instruciton and \r | |
154 | return the immediate data encoded in the instruction\r | |
155 | \r | |
156 | @param Instruction Pointer to ARM MOVT or MOVW immediate instruction\r | |
157 | \r | |
158 | @return Immediate address encoded in the instruction\r | |
159 | \r | |
160 | **/\r | |
161 | UINT16\r | |
da92f276 | 162 | EFIAPI\r |
40d841f6 LG |
163 | ThumbMovtImmediateAddress (\r |
164 | IN UINT16 *Instruction\r | |
165 | );\r | |
166 | \r | |
167 | /**\r | |
168 | Update an ARM MOVT or MOVW immediate instruction immediate data.\r | |
169 | \r | |
170 | @param Instruction Pointer to ARM MOVT or MOVW immediate instruction\r | |
171 | @param Address New addres to patch into the instruction\r | |
172 | \r | |
173 | **/\r | |
174 | VOID\r | |
da92f276 | 175 | EFIAPI\r |
40d841f6 LG |
176 | ThumbMovtImmediatePatch (\r |
177 | IN OUT UINT16 *Instruction,\r | |
178 | IN UINT16 Address\r | |
179 | );\r | |
180 | \r | |
181 | \r | |
da92f276 LG |
182 | /**\r |
183 | Pass in a pointer to an ARM MOVW/MOVT instruciton pair and \r | |
184 | return the immediate data encoded in the two` instruction\r | |
185 | \r | |
186 | @param Instructions Pointer to ARM MOVW/MOVT insturction pair\r | |
187 | \r | |
188 | @return Immediate address encoded in the instructions\r | |
189 | \r | |
190 | **/\r | |
191 | UINT32\r | |
192 | EFIAPI\r | |
193 | ThumbMovwMovtImmediateAddress (\r | |
194 | IN UINT16 *Instructions\r | |
195 | );\r | |
196 | \r | |
197 | /**\r | |
198 | Update an ARM MOVW/MOVT immediate instruction instruction pair.\r | |
199 | \r | |
200 | @param Instructions Pointer to ARM MOVW/MOVT instruction pair\r | |
201 | @param Address New addres to patch into the instructions\r | |
202 | **/\r | |
203 | VOID\r | |
204 | EFIAPI\r | |
205 | ThumbMovwMovtImmediatePatch (\r | |
206 | IN OUT UINT16 *Instructions,\r | |
207 | IN UINT32 Address\r | |
208 | );\r | |
209 | \r | |
210 | \r | |
40d841f6 | 211 | \r |
30fdf114 | 212 | #endif\r |