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