]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Include/Library/EdkIIGluePeCoffLib.h
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Include / Library / EdkIIGluePeCoffLib.h
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 EdkIIGluePeCoffLib.h
16
17 Abstract:
18
19 Public header file for PeCoff Lib
20
21 --*/
22
23 #ifndef __EDKII_GLUE_BASE_PE_COFF_LIB_H__
24 #define __EDKII_GLUE_BASE_PE_COFF_LIB_H__
25
26
27 #define PeCoffLoaderGetImageInfo(_IMAGECONTEXT) GluePeCoffLoaderGetImageInfo(_IMAGECONTEXT)
28 #define PeCoffLoaderRelocateImage(_IMAGECONTEXT) GluePeCoffLoaderRelocateImage(_IMAGECONTEXT)
29 #define PeCoffLoaderLoadImage(_IMAGECONTEXT) GluePeCoffLoaderLoadImage(_IMAGECONTEXT)
30 #define PeCoffLoaderGetPeHeader(_IMAGECONTEXT, _HDR) GluePeCoffLoaderGetPeHeader(_IMAGECONTEXT, _HDR)
31 #define PeCoffLoaderImageAddress(_IMAGECONTEXT, _ADR) GluePeCoffLoaderImageAddress(_IMAGECONTEXT, _ADR)
32 #define PeCoffLoaderRelocateImage(_IMAGECONTEXT) GluePeCoffLoaderRelocateImage(_IMAGECONTEXT)
33 #define PeCoffLoaderRelocateImageEx(_RELOC, _FIXUP, _FIXUPDATA, _ADJUST) \
34 GluePeCoffLoaderRelocateImageEx(_RELOC, _FIXUP, _FIXUPDATA, _ADJUST)
35 #define PeHotRelocateImageEx(_RELOC, _FIXUP, _FIXUPDATA, _ADJUST) \
36 GluePeHotRelocateImageEx(_RELOC, _FIXUP, _FIXUPDATA, _ADJUST)
37
38
39 //
40 // Return status codes from the PE/COFF Loader services
41 // BUGBUG: Find where used and see if can be replaced by RETURN_STATUS codes
42 //
43 #define IMAGE_ERROR_SUCCESS 0
44 #define IMAGE_ERROR_IMAGE_READ 1
45 #define IMAGE_ERROR_INVALID_PE_HEADER_SIGNATURE 2
46 #define IMAGE_ERROR_INVALID_MACHINE_TYPE 3
47 #define IMAGE_ERROR_INVALID_SUBSYSTEM 4
48 #define IMAGE_ERROR_INVALID_IMAGE_ADDRESS 5
49 #define IMAGE_ERROR_INVALID_IMAGE_SIZE 6
50 #define IMAGE_ERROR_INVALID_SECTION_ALIGNMENT 7
51 #define IMAGE_ERROR_SECTION_NOT_LOADED 8
52 #define IMAGE_ERROR_FAILED_RELOCATION 9
53 #define IMAGE_ERROR_FAILED_ICACHE_FLUSH 10
54
55 //
56 // PE/COFF Loader Read Function passed in by caller
57 //
58 typedef
59 RETURN_STATUS
60 (EFIAPI *PE_COFF_LOADER_READ_FILE) (
61 IN VOID *FileHandle,
62 IN UINTN FileOffset,
63 IN OUT UINTN *ReadSize,
64 OUT VOID *Buffer
65 );
66
67 //
68 // Context structure used while PE/COFF image is being loaded and relocated
69 //
70 typedef struct {
71 PHYSICAL_ADDRESS ImageAddress;
72 UINT64 ImageSize;
73 PHYSICAL_ADDRESS DestinationAddress;
74 PHYSICAL_ADDRESS EntryPoint;
75 PE_COFF_LOADER_READ_FILE ImageRead;
76 VOID *Handle;
77 VOID *FixupData;
78 UINT32 SectionAlignment;
79 UINT32 PeCoffHeaderOffset;
80 UINT32 DebugDirectoryEntryRva;
81 VOID *CodeView;
82 CHAR8 *PdbPointer;
83 UINTN SizeOfHeaders;
84 UINT32 ImageCodeMemoryType;
85 UINT32 ImageDataMemoryType;
86 UINT32 ImageError;
87 UINTN FixupDataSize;
88 UINT16 Machine;
89 UINT16 ImageType;
90 BOOLEAN RelocationsStripped;
91 BOOLEAN IsTeImage;
92 } PE_COFF_LOADER_IMAGE_CONTEXT;
93
94 /**
95 Retrieves information about a PE/COFF image.
96
97 Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
98 PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
99 fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
100 If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
101 a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
102 computing the fields of ImageContext, then the error status is returned in the ImageError field of
103 ImageContext.
104
105 @param ImageContext Pointer to the image context structure that describes the PE/COFF
106 image that needs to be examined by this function.
107
108 @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
109 @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
110 @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
111
112 **/
113 RETURN_STATUS
114 EFIAPI
115 GluePeCoffLoaderGetImageInfo (
116 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
117 )
118 ;
119
120 /**
121 Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
122
123 If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
124 ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
125 of ImageContext as the relocation base address. The caller must allocate the relocation
126 fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
127 If ImageContext is NULL, then ASSERT().
128
129 @param ImageContext Pointer to the image context structure that describes the PE/COFF
130 image that is being relocated.
131
132 @retval RETURN_SUCCESS The PE/COFF image was relocated.
133 Extended status information is in the ImageError field of ImageContext.
134 @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
135 Extended status information is in the ImageError field of ImageContext.
136 @retval RETURN_UNSUPPORTED A relocation record type is not supported.
137 Extended status information is in the ImageError field of ImageContext.
138
139 **/
140 RETURN_STATUS
141 EFIAPI
142 GluePeCoffLoaderRelocateImage (
143 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
144 )
145 ;
146
147 /**
148 Loads a PE/COFF image into memory.
149
150 Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
151 specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
152 the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
153 The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
154 If ImageContext is NULL, then ASSERT().
155
156 @param ImageContext Pointer to the image context structure that describes the PE/COFF
157 image that is being loaded.
158
159 @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
160 the ImageAddress and ImageSize fields of ImageContext.
161 Extended status information is in the ImageError field of ImageContext.
162 @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
163 Extended status information is in the ImageError field of ImageContext.
164 @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
165 Extended status information is in the ImageError field of ImageContext.
166 @retval RETURN_INVALID_PARAMETER The image address is invalid.
167 Extended status information is in the ImageError field of ImageContext.
168
169 **/
170 RETURN_STATUS
171 EFIAPI
172 GluePeCoffLoaderLoadImage (
173 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
174 )
175 ;
176
177
178 /**
179 ImageRead function that operates on a memory buffer whos base is passed into
180 FileHandle.
181
182 @param FileHandle Ponter to baes of the input stream
183 @param FileOffset Offset to the start of the buffer
184 @param ReadSize Number of bytes to copy into the buffer
185 @param Buffer Location to place results of read
186
187 @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
188 the buffer.
189 **/
190 RETURN_STATUS
191 EFIAPI
192 PeCoffLoaderImageReadFromMemory (
193 IN VOID *FileHandle,
194 IN UINTN FileOffset,
195 IN OUT UINTN *ReadSize,
196 OUT VOID *Buffer
197 )
198 ;
199
200
201 /**
202 Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
203 runtime.
204
205 PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
206 the fixups with a virtual mapping.
207
208
209 @param ImageBase Base address of relocated image
210 @param VirtImageBase Virtual mapping for ImageBase
211 @param ImageSize Size of the image to relocate
212 @param RelocationData Location to place results of read
213
214 **/
215 VOID
216 EFIAPI
217 PeCoffLoaderRelocateImageForRuntime (
218 IN PHYSICAL_ADDRESS ImageBase,
219 IN PHYSICAL_ADDRESS VirtImageBase,
220 IN UINTN ImageSize,
221 IN VOID *RelocationData
222 )
223 ;
224
225
226 #endif