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