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