]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Include/Protocol/PeCoffLoader.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmbeddedPkg / Include / Protocol / PeCoffLoader.h
1 /** @file
2
3 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef __PE_COFF_LOADER_H__
10 #define __PE_COFF_LOADER_H__
11
12 // Needed for PE_COFF_LOADER_IMAGE_CONTEXT
13 #include <Library/PeCoffLib.h>
14
15 // B323179B-97FB-477E-B0FE-D88591FA11AB
16 #define PE_COFF_LOADER_PROTOCOL_GUID \
17 { 0xB323179B, 0x97FB, 0x477E, { 0xB0, 0xFE, 0xD8, 0x85, 0x91, 0xFA, 0x11, 0xAB } }
18
19 typedef struct _PE_COFF_LOADER_PROTOCOL PE_COFF_LOADER_PROTOCOL;
20
21 /**
22 Retrieves information about a PE/COFF image.
23
24 Computes the PeCoffHeaderOffset, IsTeImage, ImageType, ImageAddress, ImageSize,
25 DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and
26 DebugDirectoryEntryRva fields of the ImageContext structure.
27 If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
28 If the PE/COFF image accessed through the ImageRead service in the ImageContext
29 structure is not a supported PE/COFF image type, then return RETURN_UNSUPPORTED.
30 If any errors occur while computing the fields of ImageContext,
31 then the error status is returned in the ImageError field of ImageContext.
32 If the image is a TE image, then SectionAlignment is set to 0.
33 The ImageRead and Handle fields of ImageContext structure must be valid prior
34 to invoking this service.
35
36 @param ImageContext Pointer to the image context structure that describes the PE/COFF
37 image that needs to be examined by this function.
38
39 @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
40 @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
41 @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
42
43 **/
44 typedef
45 RETURN_STATUS
46 (EFIAPI *PE_COFF_LOADER_GET_IMAGE_INFO)(
47 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
48 );
49
50 /**
51 Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
52
53 If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
54 ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
55 of ImageContext as the relocation base address. The caller must allocate the relocation
56 fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
57
58 The ImageRead, Handle, PeCoffHeaderOffset, IsTeImage, Machine, ImageType, ImageAddress,
59 ImageSize, DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders,
60 DebugDirectoryEntryRva, EntryPoint, FixupDataSize, CodeView, PdbPointer, and FixupData of
61 the ImageContext structure must be valid prior to invoking this service.
62
63 If ImageContext is NULL, then ASSERT().
64
65 Note that if the platform does not maintain coherency between the instruction cache(s) and the data
66 cache(s) in hardware, then the caller is responsible for performing cache maintenance operations
67 prior to transferring control to a PE/COFF image that is loaded using this library.
68
69 @param ImageContext Pointer to the image context structure that describes the PE/COFF
70 image that is being relocated.
71
72 @retval RETURN_SUCCESS The PE/COFF image was relocated.
73 Extended status information is in the ImageError field of ImageContext.
74 @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
75 Extended status information is in the ImageError field of ImageContext.
76 @retval RETURN_UNSUPPORTED A relocation record type is not supported.
77 Extended status information is in the ImageError field of ImageContext.
78
79 **/
80 typedef
81 RETURN_STATUS
82 (EFIAPI *PE_COFF_LOADER_RELOCATE_IMAGE)(
83 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
84 );
85
86 /**
87 Loads a PE/COFF image into memory.
88
89 Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
90 specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
91 the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
92 The EntryPoint, FixupDataSize, CodeView, PdbPointer and HiiResourceData fields of ImageContext are computed.
93 The ImageRead, Handle, PeCoffHeaderOffset, IsTeImage, Machine, ImageType, ImageAddress, ImageSize,
94 DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
95 fields of the ImageContext structure must be valid prior to invoking this service.
96
97 If ImageContext is NULL, then ASSERT().
98
99 Note that if the platform does not maintain coherency between the instruction cache(s) and the data
100 cache(s) in hardware, then the caller is responsible for performing cache maintenance operations
101 prior to transferring control to a PE/COFF image that is loaded using this library.
102
103 @param ImageContext Pointer to the image context structure that describes the PE/COFF
104 image that is being loaded.
105
106 @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
107 the ImageAddress and ImageSize fields of ImageContext.
108 Extended status information is in the ImageError field of ImageContext.
109 @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
110 Extended status information is in the ImageError field of ImageContext.
111 @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
112 Extended status information is in the ImageError field of ImageContext.
113 @retval RETURN_INVALID_PARAMETER The image address is invalid.
114 Extended status information is in the ImageError field of ImageContext.
115
116 **/
117 typedef
118 RETURN_STATUS
119 (EFIAPI *PE_COFF_LOADER_LOAD_IMAGE)(
120 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
121 );
122
123 /**
124 Reads contents of a PE/COFF image from a buffer in system memory.
125
126 This is the default implementation of a PE_COFF_LOADER_READ_FILE function
127 that assumes FileHandle pointer to the beginning of a PE/COFF image.
128 This function reads contents of the PE/COFF image that starts at the system memory
129 address specified by FileHandle. The read operation copies ReadSize bytes from the
130 PE/COFF image starting at byte offset FileOffset into the buffer specified by Buffer.
131 The size of the buffer actually read is returned in ReadSize.
132
133 If FileHandle is NULL, then ASSERT().
134 If ReadSize is NULL, then ASSERT().
135 If Buffer is NULL, then ASSERT().
136
137 @param FileHandle Pointer to base of the input stream
138 @param FileOffset Offset into the PE/COFF image to begin the read operation.
139 @param ReadSize On input, the size in bytes of the requested read operation.
140 On output, the number of bytes actually read.
141 @param Buffer Output buffer that contains the data read from the PE/COFF image.
142
143 @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
144 the buffer.
145 **/
146 typedef
147 RETURN_STATUS
148 (EFIAPI *PE_COFF_LOADER_READ_FROM_MEMORY)(
149 IN VOID *FileHandle,
150 IN UINTN FileOffset,
151 IN OUT UINTN *ReadSize,
152 OUT VOID *Buffer
153 );
154
155 /**
156 Reapply fixups on a fixed up PE32/PE32+ image to allow virtual calling at EFI
157 runtime.
158
159 This function reapplies relocation fixups to the PE/COFF image specified by ImageBase
160 and ImageSize so the image will execute correctly when the PE/COFF image is mapped
161 to the address specified by VirtualImageBase. RelocationData must be identical
162 to the FixupData buffer from the PE_COFF_LOADER_IMAGE_CONTEXT structure
163 after this PE/COFF image was relocated with PeCoffLoaderRelocateImage().
164
165 Note that if the platform does not maintain coherency between the instruction cache(s) and the data
166 cache(s) in hardware, then the caller is responsible for performing cache maintenance operations
167 prior to transferring control to a PE/COFF image that is loaded using this library.
168
169 @param ImageBase Base address of a PE/COFF image that has been loaded
170 and relocated into system memory.
171 @param VirtImageBase The request virtual address that the PE/COFF image is to
172 be fixed up for.
173 @param ImageSize The size, in bytes, of the PE/COFF image.
174 @param RelocationData A pointer to the relocation data that was collected when the PE/COFF
175 image was relocated using PeCoffLoaderRelocateImage().
176
177 **/
178 typedef
179 VOID
180 (EFIAPI *PE_COFF_LOADER_RELOCATE_IMAGE_FOR_RUNTIME)(
181 IN PHYSICAL_ADDRESS ImageBase,
182 IN PHYSICAL_ADDRESS VirtImageBase,
183 IN UINTN ImageSize,
184 IN VOID *RelocationData
185 );
186
187 /**
188 Unloads a loaded PE/COFF image from memory and releases its taken resource.
189 Releases any environment specific resources that were allocated when the image
190 specified by ImageContext was loaded using PeCoffLoaderLoadImage().
191
192 For NT32 emulator, the PE/COFF image loaded by system needs to release.
193 For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
194 this function can simply return RETURN_SUCCESS.
195
196 If ImageContext is NULL, then ASSERT().
197
198 @param ImageContext Pointer to the image context structure that describes the PE/COFF
199 image to be unloaded.
200
201 @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.
202 **/
203 typedef
204 RETURN_STATUS
205 (EFIAPI *PE_COFF_LOADER_UNLOAD_IMAGE)(
206 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
207 );
208
209 struct _PE_COFF_LOADER_PROTOCOL {
210 PE_COFF_LOADER_GET_IMAGE_INFO GetImageInfo;
211 PE_COFF_LOADER_LOAD_IMAGE LoadImage;
212 PE_COFF_LOADER_RELOCATE_IMAGE RelocateImage;
213 PE_COFF_LOADER_READ_FROM_MEMORY ReadFromMemory;
214 PE_COFF_LOADER_RELOCATE_IMAGE_FOR_RUNTIME RelocateImageForRuntime;
215 PE_COFF_LOADER_UNLOAD_IMAGE UnloadImage;
216 };
217
218 extern EFI_GUID gPeCoffLoaderProtocolGuid;
219
220 #endif