]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.c
Modify all file header to follow doxygen format
[mirror_edk2.git] / Nt32Pkg / Library / PeiNt32PeCoffLib / PeiNt32PeCoffLib.c
CommitLineData
6ae81428 1/**@file\r
3d7b0992
LG
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 PeiNt32PeCoffLib.c\r
15\r
16Abstract:\r
17\r
18 Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure\r
19 to produce PeCoff library class.\r
20\r
21\r
6ae81428 22**/\r
3d7b0992
LG
23\r
24#include <PiPei.h>\r
25#include <Guid/PeiPeCoffLoader.h>\r
26#include <Library/DebugLib.h>\r
27#include <Library/PeCoffLib.h>\r
28#include <Library/HobLib.h>\r
29\r
30EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader;\r
31\r
32/**\r
33 The constructor function caches the pointer of PeCofferLoader guid structure\r
34 into the guid data hob.\r
35\r
36 The constructor must be called after PeCofferLoader guid structure is installed.\r
37 It will ASSERT() if PeCofferLoader guid structure is not installed.\r
38\r
39 @param FfsHeader Pointer to FFS header the loaded driver.\r
40 @param PeiServices Pointer to the PEI services.\r
41\r
42 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
43\r
44**/\r
45EFI_STATUS\r
46EFIAPI\r
47PeiNt32PeCoffLibConstructor (\r
48 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
49 IN EFI_PEI_SERVICES **PeiServices\r
50 )\r
51{\r
52 EFI_STATUS Status;\r
53 EFI_HOB_GUID_TYPE *GuidHob;\r
54\r
55 Status = EFI_NOT_FOUND;\r
56 \r
57 //\r
58 // Try to get guid data hob that contains PeCoffLoader guid structure.\r
59 //\r
60 GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
61\r
62 if (GuidHob == NULL) {\r
63 //\r
64 // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
65 //\r
66 Status = (*PeiServices)->LocatePpi (\r
67 PeiServices,\r
68 &gEfiPeiPeCoffLoaderGuid,\r
69 0,\r
70 NULL,\r
71 &mPeiEfiPeiPeCoffLoader\r
72 );\r
73 \r
74 //\r
75 // PeCofferLoader guid structure must be installed before this library runs.\r
76 //\r
77 ASSERT_EFI_ERROR (Status);\r
78 \r
79 //\r
80 // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
81 //\r
82 BuildGuidDataHob (\r
83 &gEfiPeiPeCoffLoaderGuid,\r
84 (VOID *) &mPeiEfiPeiPeCoffLoader,\r
85 sizeof (VOID *)\r
86 );\r
87 } else {\r
88 //\r
89 // Get PeCofferLoader guid structure directly from guid hob data.\r
90 //\r
91 mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
92 }\r
93\r
94 return EFI_SUCCESS;\r
95}\r
96\r
97/**\r
98 Retrieves information about a PE/COFF image.\r
99\r
100 Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
101 PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
102 fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
103 If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
104 a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while\r
105 computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
106 ImageContext. \r
107\r
108 @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
109 image that needs to be examined by this function.\r
110\r
111 @retval RETURN_SUCCESS The information on the PE/COFF image was collected.\r
112 @retval RETURN_INVALID_PARAMETER ImageContext is NULL.\r
113 @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.\r
114\r
115**/\r
116RETURN_STATUS\r
117EFIAPI\r
118PeCoffLoaderGetImageInfo (\r
119 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
120 )\r
121{\r
122 return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
123}\r
124\r
125/**\r
126 Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
127\r
128 If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
129 ImageContext as the relocation base address. Otherwise, use the DestinationAddress field\r
130 of ImageContext as the relocation base address. The caller must allocate the relocation\r
131 fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. \r
132 If ImageContext is NULL, then ASSERT().\r
133\r
134 @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
135 image that is being relocated.\r
136\r
137 @retval RETURN_SUCCESS The PE/COFF image was relocated.\r
138 Extended status information is in the ImageError field of ImageContext.\r
139 @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.\r
140 Extended status information is in the ImageError field of ImageContext.\r
141 @retval RETURN_UNSUPPORTED A relocation record type is not supported.\r
142 Extended status information is in the ImageError field of ImageContext.\r
143\r
144**/\r
145RETURN_STATUS\r
146EFIAPI\r
147PeCoffLoaderRelocateImage (\r
148 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
149 )\r
150{\r
151 return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
152}\r
153\r
154/**\r
155 Loads a PE/COFF image into memory.\r
156\r
157 Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
158 specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate\r
159 the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
160 The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
161 If ImageContext is NULL, then ASSERT().\r
162\r
163 @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
164 image that is being loaded.\r
165\r
166 @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by\r
167 the ImageAddress and ImageSize fields of ImageContext.\r
168 Extended status information is in the ImageError field of ImageContext.\r
169 @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.\r
170 Extended status information is in the ImageError field of ImageContext.\r
171 @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.\r
172 Extended status information is in the ImageError field of ImageContext.\r
173 @retval RETURN_INVALID_PARAMETER The image address is invalid.\r
174 Extended status information is in the ImageError field of ImageContext.\r
175\r
176**/\r
177RETURN_STATUS\r
178EFIAPI\r
179PeCoffLoaderLoadImage (\r
180 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
181 )\r
182{\r
183 return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
184}\r
185\r
186/**\r
187 ImageRead function that operates on a memory buffer whos base is passed into\r
188 FileHandle. \r
189\r
190 @param FileHandle Ponter to baes of the input stream\r
191 @param FileOffset Offset to the start of the buffer\r
192 @param ReadSize Number of bytes to copy into the buffer\r
193 @param Buffer Location to place results of read\r
194\r
195 @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into \r
196 the buffer.\r
197**/\r
198RETURN_STATUS\r
199EFIAPI\r
200PeCoffLoaderImageReadFromMemory (\r
201 IN VOID *FileHandle,\r
202 IN UINTN FileOffset,\r
203 IN OUT UINTN *ReadSize,\r
204 OUT VOID *Buffer\r
205 )\r
206{\r
207 return RETURN_UNSUPPORTED;\r
208}\r
209\r
210\r
211/**\r
212 Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
213 runtime. \r
214 \r
215 PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
216 the fixups with a virtual mapping.\r
217\r
218\r
219 @param ImageBase Base address of relocated image\r
220 @param VirtImageBase Virtual mapping for ImageBase\r
221 @param ImageSize Size of the image to relocate\r
222 @param RelocationData Location to place results of read\r
223 \r
224**/\r
225VOID\r
226EFIAPI\r
227PeCoffLoaderRelocateImageForRuntime (\r
228 IN PHYSICAL_ADDRESS ImageBase,\r
229 IN PHYSICAL_ADDRESS VirtImageBase,\r
230 IN UINTN ImageSize,\r
231 IN VOID *RelocationData\r
232 )\r
233{\r
234}\r
235\r
236/**\r
237 Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
238 \r
239 For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
240 For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
241 this function can simply return RETURN_SUCCESS.\r
242\r
243 @param ImageContext Pointer to the image context structure that describes the PE/COFF\r
244 image to be unloaded.\r
245\r
246 @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.\r
247**/\r
248RETURN_STATUS\r
249EFIAPI\r
250PeCoffLoaderUnloadImage (\r
251 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
252 )\r
253{\r
254 return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
255}\r