1 | /** @file
|
---|
2 | EFI image format for PE32, PE32+ and TE. Please note some data structures are
|
---|
3 | different for PE32 and PE32+. EFI_IMAGE_NT_HEADERS32 is for PE32 and
|
---|
4 | EFI_IMAGE_NT_HEADERS64 is for PE32+.
|
---|
5 |
|
---|
6 | This file is coded to the Visual Studio, Microsoft Portable Executable and
|
---|
7 | Common Object File Format Specification, Revision 8.3 - February 6, 2013.
|
---|
8 | This file also includes some definitions in PI Specification, Revision 1.0.
|
---|
9 |
|
---|
10 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
---|
11 | Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
---|
12 | This program and the accompanying materials
|
---|
13 | are licensed and made available under the terms and conditions of the BSD License
|
---|
14 | which accompanies this distribution. The full text of the license may be found at
|
---|
15 | http://opensource.org/licenses/bsd-license.php.
|
---|
16 |
|
---|
17 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
18 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
19 |
|
---|
20 | **/
|
---|
21 |
|
---|
22 | #ifndef __PE_IMAGE_H__
|
---|
23 | #define __PE_IMAGE_H__
|
---|
24 |
|
---|
25 | //
|
---|
26 | // PE32+ Subsystem type for EFI images
|
---|
27 | //
|
---|
28 | #define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10
|
---|
29 | #define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
|
---|
30 | #define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
|
---|
31 | #define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13 ///< defined PI Specification, 1.0
|
---|
32 |
|
---|
33 |
|
---|
34 | //
|
---|
35 | // PE32+ Machine type for EFI images
|
---|
36 | //
|
---|
37 | #define IMAGE_FILE_MACHINE_I386 0x014c
|
---|
38 | #define IMAGE_FILE_MACHINE_IA64 0x0200
|
---|
39 | #define IMAGE_FILE_MACHINE_EBC 0x0EBC
|
---|
40 | #define IMAGE_FILE_MACHINE_X64 0x8664
|
---|
41 | #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED 0x01c2
|
---|
42 | #define IMAGE_FILE_MACHINE_ARM64 0xAA64
|
---|
43 |
|
---|
44 | //
|
---|
45 | // EXE file formats
|
---|
46 | //
|
---|
47 | #define EFI_IMAGE_DOS_SIGNATURE SIGNATURE_16('M', 'Z')
|
---|
48 | #define EFI_IMAGE_OS2_SIGNATURE SIGNATURE_16('N', 'E')
|
---|
49 | #define EFI_IMAGE_OS2_SIGNATURE_LE SIGNATURE_16('L', 'E')
|
---|
50 | #define EFI_IMAGE_NT_SIGNATURE SIGNATURE_32('P', 'E', '\0', '\0')
|
---|
51 |
|
---|
52 | ///
|
---|
53 | /// PE images can start with an optional DOS header, so if an image is run
|
---|
54 | /// under DOS it can print an error message.
|
---|
55 | ///
|
---|
56 | typedef struct {
|
---|
57 | UINT16 e_magic; ///< Magic number.
|
---|
58 | UINT16 e_cblp; ///< Bytes on last page of file.
|
---|
59 | UINT16 e_cp; ///< Pages in file.
|
---|
60 | UINT16 e_crlc; ///< Relocations.
|
---|
61 | UINT16 e_cparhdr; ///< Size of header in paragraphs.
|
---|
62 | UINT16 e_minalloc; ///< Minimum extra paragraphs needed.
|
---|
63 | UINT16 e_maxalloc; ///< Maximum extra paragraphs needed.
|
---|
64 | UINT16 e_ss; ///< Initial (relative) SS value.
|
---|
65 | UINT16 e_sp; ///< Initial SP value.
|
---|
66 | UINT16 e_csum; ///< Checksum.
|
---|
67 | UINT16 e_ip; ///< Initial IP value.
|
---|
68 | UINT16 e_cs; ///< Initial (relative) CS value.
|
---|
69 | UINT16 e_lfarlc; ///< File address of relocation table.
|
---|
70 | UINT16 e_ovno; ///< Overlay number.
|
---|
71 | UINT16 e_res[4]; ///< Reserved words.
|
---|
72 | UINT16 e_oemid; ///< OEM identifier (for e_oeminfo).
|
---|
73 | UINT16 e_oeminfo; ///< OEM information; e_oemid specific.
|
---|
74 | UINT16 e_res2[10]; ///< Reserved words.
|
---|
75 | UINT32 e_lfanew; ///< File address of new exe header.
|
---|
76 | } EFI_IMAGE_DOS_HEADER;
|
---|
77 |
|
---|
78 | ///
|
---|
79 | /// COFF File Header (Object and Image).
|
---|
80 | ///
|
---|
81 | typedef struct {
|
---|
82 | UINT16 Machine;
|
---|
83 | UINT16 NumberOfSections;
|
---|
84 | UINT32 TimeDateStamp;
|
---|
85 | UINT32 PointerToSymbolTable;
|
---|
86 | UINT32 NumberOfSymbols;
|
---|
87 | UINT16 SizeOfOptionalHeader;
|
---|
88 | UINT16 Characteristics;
|
---|
89 | } EFI_IMAGE_FILE_HEADER;
|
---|
90 |
|
---|
91 | ///
|
---|
92 | /// Size of EFI_IMAGE_FILE_HEADER.
|
---|
93 | ///
|
---|
94 | #define EFI_IMAGE_SIZEOF_FILE_HEADER 20
|
---|
95 |
|
---|
96 | //
|
---|
97 | // Characteristics
|
---|
98 | //
|
---|
99 | #define EFI_IMAGE_FILE_RELOCS_STRIPPED BIT0 ///< 0x0001 Relocation info stripped from file.
|
---|
100 | #define EFI_IMAGE_FILE_EXECUTABLE_IMAGE BIT1 ///< 0x0002 File is executable (i.e. no unresolved externel references).
|
---|
101 | #define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED BIT2 ///< 0x0004 Line nunbers stripped from file.
|
---|
102 | #define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED BIT3 ///< 0x0008 Local symbols stripped from file.
|
---|
103 | #define EFI_IMAGE_FILE_BYTES_REVERSED_LO BIT7 ///< 0x0080 Bytes of machine word are reversed.
|
---|
104 | #define EFI_IMAGE_FILE_32BIT_MACHINE BIT8 ///< 0x0100 32 bit word machine.
|
---|
105 | #define EFI_IMAGE_FILE_DEBUG_STRIPPED BIT9 ///< 0x0200 Debugging info stripped from file in .DBG file.
|
---|
106 | #define EFI_IMAGE_FILE_SYSTEM BIT12 ///< 0x1000 System File.
|
---|
107 | #define EFI_IMAGE_FILE_DLL BIT13 ///< 0x2000 File is a DLL.
|
---|
108 | #define EFI_IMAGE_FILE_BYTES_REVERSED_HI BIT15 ///< 0x8000 Bytes of machine word are reversed.
|
---|
109 |
|
---|
110 | ///
|
---|
111 | /// Header Data Directories.
|
---|
112 | ///
|
---|
113 | typedef struct {
|
---|
114 | UINT32 VirtualAddress;
|
---|
115 | UINT32 Size;
|
---|
116 | } EFI_IMAGE_DATA_DIRECTORY;
|
---|
117 |
|
---|
118 | //
|
---|
119 | // Directory Entries
|
---|
120 | //
|
---|
121 | #define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0
|
---|
122 | #define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1
|
---|
123 | #define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2
|
---|
124 | #define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
|
---|
125 | #define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4
|
---|
126 | #define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
|
---|
127 | #define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6
|
---|
128 | #define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
|
---|
129 | #define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
|
---|
130 | #define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9
|
---|
131 | #define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
|
---|
132 |
|
---|
133 | #define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16
|
---|
134 |
|
---|
135 | ///
|
---|
136 | /// @attention
|
---|
137 | /// EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC means PE32 and
|
---|
138 | /// EFI_IMAGE_OPTIONAL_HEADER32 must be used. The data structures only vary
|
---|
139 | /// after NT additional fields.
|
---|
140 | ///
|
---|
141 | #define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
|
---|
142 |
|
---|
143 | ///
|
---|
144 | /// Optional Header Standard Fields for PE32.
|
---|
145 | ///
|
---|
146 | typedef struct {
|
---|
147 | ///
|
---|
148 | /// Standard fields.
|
---|
149 | ///
|
---|
150 | UINT16 Magic;
|
---|
151 | UINT8 MajorLinkerVersion;
|
---|
152 | UINT8 MinorLinkerVersion;
|
---|
153 | UINT32 SizeOfCode;
|
---|
154 | UINT32 SizeOfInitializedData;
|
---|
155 | UINT32 SizeOfUninitializedData;
|
---|
156 | UINT32 AddressOfEntryPoint;
|
---|
157 | UINT32 BaseOfCode;
|
---|
158 | UINT32 BaseOfData; ///< PE32 contains this additional field, which is absent in PE32+.
|
---|
159 | ///
|
---|
160 | /// Optional Header Windows-Specific Fields.
|
---|
161 | ///
|
---|
162 | UINT32 ImageBase;
|
---|
163 | UINT32 SectionAlignment;
|
---|
164 | UINT32 FileAlignment;
|
---|
165 | UINT16 MajorOperatingSystemVersion;
|
---|
166 | UINT16 MinorOperatingSystemVersion;
|
---|
167 | UINT16 MajorImageVersion;
|
---|
168 | UINT16 MinorImageVersion;
|
---|
169 | UINT16 MajorSubsystemVersion;
|
---|
170 | UINT16 MinorSubsystemVersion;
|
---|
171 | UINT32 Win32VersionValue;
|
---|
172 | UINT32 SizeOfImage;
|
---|
173 | UINT32 SizeOfHeaders;
|
---|
174 | UINT32 CheckSum;
|
---|
175 | UINT16 Subsystem;
|
---|
176 | UINT16 DllCharacteristics;
|
---|
177 | UINT32 SizeOfStackReserve;
|
---|
178 | UINT32 SizeOfStackCommit;
|
---|
179 | UINT32 SizeOfHeapReserve;
|
---|
180 | UINT32 SizeOfHeapCommit;
|
---|
181 | UINT32 LoaderFlags;
|
---|
182 | UINT32 NumberOfRvaAndSizes;
|
---|
183 | EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
|
---|
184 | } EFI_IMAGE_OPTIONAL_HEADER32;
|
---|
185 |
|
---|
186 | ///
|
---|
187 | /// @attention
|
---|
188 | /// EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC means PE32+ and
|
---|
189 | /// EFI_IMAGE_OPTIONAL_HEADER64 must be used. The data structures only vary
|
---|
190 | /// after NT additional fields.
|
---|
191 | ///
|
---|
192 | #define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
|
---|
193 |
|
---|
194 | ///
|
---|
195 | /// Optional Header Standard Fields for PE32+.
|
---|
196 | ///
|
---|
197 | typedef struct {
|
---|
198 | ///
|
---|
199 | /// Standard fields.
|
---|
200 | ///
|
---|
201 | UINT16 Magic;
|
---|
202 | UINT8 MajorLinkerVersion;
|
---|
203 | UINT8 MinorLinkerVersion;
|
---|
204 | UINT32 SizeOfCode;
|
---|
205 | UINT32 SizeOfInitializedData;
|
---|
206 | UINT32 SizeOfUninitializedData;
|
---|
207 | UINT32 AddressOfEntryPoint;
|
---|
208 | UINT32 BaseOfCode;
|
---|
209 | ///
|
---|
210 | /// Optional Header Windows-Specific Fields.
|
---|
211 | ///
|
---|
212 | UINT64 ImageBase;
|
---|
213 | UINT32 SectionAlignment;
|
---|
214 | UINT32 FileAlignment;
|
---|
215 | UINT16 MajorOperatingSystemVersion;
|
---|
216 | UINT16 MinorOperatingSystemVersion;
|
---|
217 | UINT16 MajorImageVersion;
|
---|
218 | UINT16 MinorImageVersion;
|
---|
219 | UINT16 MajorSubsystemVersion;
|
---|
220 | UINT16 MinorSubsystemVersion;
|
---|
221 | UINT32 Win32VersionValue;
|
---|
222 | UINT32 SizeOfImage;
|
---|
223 | UINT32 SizeOfHeaders;
|
---|
224 | UINT32 CheckSum;
|
---|
225 | UINT16 Subsystem;
|
---|
226 | UINT16 DllCharacteristics;
|
---|
227 | UINT64 SizeOfStackReserve;
|
---|
228 | UINT64 SizeOfStackCommit;
|
---|
229 | UINT64 SizeOfHeapReserve;
|
---|
230 | UINT64 SizeOfHeapCommit;
|
---|
231 | UINT32 LoaderFlags;
|
---|
232 | UINT32 NumberOfRvaAndSizes;
|
---|
233 | EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
|
---|
234 | } EFI_IMAGE_OPTIONAL_HEADER64;
|
---|
235 |
|
---|
236 |
|
---|
237 | ///
|
---|
238 | /// @attention
|
---|
239 | /// EFI_IMAGE_NT_HEADERS32 is for use ONLY by tools.
|
---|
240 | ///
|
---|
241 | typedef struct {
|
---|
242 | UINT32 Signature;
|
---|
243 | EFI_IMAGE_FILE_HEADER FileHeader;
|
---|
244 | EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader;
|
---|
245 | } EFI_IMAGE_NT_HEADERS32;
|
---|
246 |
|
---|
247 | #define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof (EFI_IMAGE_NT_HEADERS32)
|
---|
248 |
|
---|
249 | ///
|
---|
250 | /// @attention
|
---|
251 | /// EFI_IMAGE_HEADERS64 is for use ONLY by tools.
|
---|
252 | ///
|
---|
253 | typedef struct {
|
---|
254 | UINT32 Signature;
|
---|
255 | EFI_IMAGE_FILE_HEADER FileHeader;
|
---|
256 | EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader;
|
---|
257 | } EFI_IMAGE_NT_HEADERS64;
|
---|
258 |
|
---|
259 | #define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof (EFI_IMAGE_NT_HEADERS64)
|
---|
260 |
|
---|
261 | //
|
---|
262 | // Other Windows Subsystem Values
|
---|
263 | //
|
---|
264 | #define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0
|
---|
265 | #define EFI_IMAGE_SUBSYSTEM_NATIVE 1
|
---|
266 | #define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2
|
---|
267 | #define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3
|
---|
268 | #define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5
|
---|
269 | #define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7
|
---|
270 |
|
---|
271 | ///
|
---|
272 | /// Length of ShortName.
|
---|
273 | ///
|
---|
274 | #define EFI_IMAGE_SIZEOF_SHORT_NAME 8
|
---|
275 |
|
---|
276 | ///
|
---|
277 | /// Section Table. This table immediately follows the optional header.
|
---|
278 | ///
|
---|
279 | typedef struct {
|
---|
280 | UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];
|
---|
281 | union {
|
---|
282 | UINT32 PhysicalAddress;
|
---|
283 | UINT32 VirtualSize;
|
---|
284 | } Misc;
|
---|
285 | UINT32 VirtualAddress;
|
---|
286 | UINT32 SizeOfRawData;
|
---|
287 | UINT32 PointerToRawData;
|
---|
288 | UINT32 PointerToRelocations;
|
---|
289 | UINT32 PointerToLinenumbers;
|
---|
290 | UINT16 NumberOfRelocations;
|
---|
291 | UINT16 NumberOfLinenumbers;
|
---|
292 | UINT32 Characteristics;
|
---|
293 | } EFI_IMAGE_SECTION_HEADER;
|
---|
294 |
|
---|
295 | ///
|
---|
296 | /// Size of EFI_IMAGE_SECTION_HEADER.
|
---|
297 | ///
|
---|
298 | #define EFI_IMAGE_SIZEOF_SECTION_HEADER 40
|
---|
299 |
|
---|
300 | //
|
---|
301 | // Section Flags Values
|
---|
302 | //
|
---|
303 | #define EFI_IMAGE_SCN_TYPE_NO_PAD BIT3 ///< 0x00000008 ///< Reserved.
|
---|
304 | #define EFI_IMAGE_SCN_CNT_CODE BIT5 ///< 0x00000020
|
---|
305 | #define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA BIT6 ///< 0x00000040
|
---|
306 | #define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA BIT7 ///< 0x00000080
|
---|
307 |
|
---|
308 | #define EFI_IMAGE_SCN_LNK_OTHER BIT8 ///< 0x00000100 ///< Reserved.
|
---|
309 | #define EFI_IMAGE_SCN_LNK_INFO BIT9 ///< 0x00000200 ///< Section contains comments or some other type of information.
|
---|
310 | #define EFI_IMAGE_SCN_LNK_REMOVE BIT11 ///< 0x00000800 ///< Section contents will not become part of image.
|
---|
311 | #define EFI_IMAGE_SCN_LNK_COMDAT BIT12 ///< 0x00001000
|
---|
312 |
|
---|
313 | #define EFI_IMAGE_SCN_ALIGN_1BYTES BIT20 ///< 0x00100000
|
---|
314 | #define EFI_IMAGE_SCN_ALIGN_2BYTES BIT21 ///< 0x00200000
|
---|
315 | #define EFI_IMAGE_SCN_ALIGN_4BYTES (BIT20|BIT21) ///< 0x00300000
|
---|
316 | #define EFI_IMAGE_SCN_ALIGN_8BYTES BIT22 ///< 0x00400000
|
---|
317 | #define EFI_IMAGE_SCN_ALIGN_16BYTES (BIT20|BIT22) ///< 0x00500000
|
---|
318 | #define EFI_IMAGE_SCN_ALIGN_32BYTES (BIT21|BIT22) ///< 0x00600000
|
---|
319 | #define EFI_IMAGE_SCN_ALIGN_64BYTES (BIT20|BIT21|BIT22) ///< 0x00700000
|
---|
320 |
|
---|
321 | #define EFI_IMAGE_SCN_MEM_DISCARDABLE BIT25 ///< 0x02000000
|
---|
322 | #define EFI_IMAGE_SCN_MEM_NOT_CACHED BIT26 ///< 0x04000000
|
---|
323 | #define EFI_IMAGE_SCN_MEM_NOT_PAGED BIT27 ///< 0x08000000
|
---|
324 | #define EFI_IMAGE_SCN_MEM_SHARED BIT28 ///< 0x10000000
|
---|
325 | #define EFI_IMAGE_SCN_MEM_EXECUTE BIT29 ///< 0x20000000
|
---|
326 | #define EFI_IMAGE_SCN_MEM_READ BIT30 ///< 0x40000000
|
---|
327 | #define EFI_IMAGE_SCN_MEM_WRITE BIT31 ///< 0x80000000
|
---|
328 |
|
---|
329 | ///
|
---|
330 | /// Size of a Symbol Table Record.
|
---|
331 | ///
|
---|
332 | #define EFI_IMAGE_SIZEOF_SYMBOL 18
|
---|
333 |
|
---|
334 | //
|
---|
335 | // Symbols have a section number of the section in which they are
|
---|
336 | // defined. Otherwise, section numbers have the following meanings:
|
---|
337 | //
|
---|
338 | #define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0 ///< Symbol is undefined or is common.
|
---|
339 | #define EFI_IMAGE_SYM_ABSOLUTE (UINT16) -1 ///< Symbol is an absolute value.
|
---|
340 | #define EFI_IMAGE_SYM_DEBUG (UINT16) -2 ///< Symbol is a special debug item.
|
---|
341 |
|
---|
342 | //
|
---|
343 | // Symbol Type (fundamental) values.
|
---|
344 | //
|
---|
345 | #define EFI_IMAGE_SYM_TYPE_NULL 0 ///< no type.
|
---|
346 | #define EFI_IMAGE_SYM_TYPE_VOID 1 ///< no valid type.
|
---|
347 | #define EFI_IMAGE_SYM_TYPE_CHAR 2 ///< type character.
|
---|
348 | #define EFI_IMAGE_SYM_TYPE_SHORT 3 ///< type short integer.
|
---|
349 | #define EFI_IMAGE_SYM_TYPE_INT 4
|
---|
350 | #define EFI_IMAGE_SYM_TYPE_LONG 5
|
---|
351 | #define EFI_IMAGE_SYM_TYPE_FLOAT 6
|
---|
352 | #define EFI_IMAGE_SYM_TYPE_DOUBLE 7
|
---|
353 | #define EFI_IMAGE_SYM_TYPE_STRUCT 8
|
---|
354 | #define EFI_IMAGE_SYM_TYPE_UNION 9
|
---|
355 | #define EFI_IMAGE_SYM_TYPE_ENUM 10 ///< enumeration.
|
---|
356 | #define EFI_IMAGE_SYM_TYPE_MOE 11 ///< member of enumeration.
|
---|
357 | #define EFI_IMAGE_SYM_TYPE_BYTE 12
|
---|
358 | #define EFI_IMAGE_SYM_TYPE_WORD 13
|
---|
359 | #define EFI_IMAGE_SYM_TYPE_UINT 14
|
---|
360 | #define EFI_IMAGE_SYM_TYPE_DWORD 15
|
---|
361 |
|
---|
362 | //
|
---|
363 | // Symbol Type (derived) values.
|
---|
364 | //
|
---|
365 | #define EFI_IMAGE_SYM_DTYPE_NULL 0 ///< no derived type.
|
---|
366 | #define EFI_IMAGE_SYM_DTYPE_POINTER 1
|
---|
367 | #define EFI_IMAGE_SYM_DTYPE_FUNCTION 2
|
---|
368 | #define EFI_IMAGE_SYM_DTYPE_ARRAY 3
|
---|
369 |
|
---|
370 | //
|
---|
371 | // Storage classes.
|
---|
372 | //
|
---|
373 | #define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION ((UINT8) -1)
|
---|
374 | #define EFI_IMAGE_SYM_CLASS_NULL 0
|
---|
375 | #define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1
|
---|
376 | #define EFI_IMAGE_SYM_CLASS_EXTERNAL 2
|
---|
377 | #define EFI_IMAGE_SYM_CLASS_STATIC 3
|
---|
378 | #define EFI_IMAGE_SYM_CLASS_REGISTER 4
|
---|
379 | #define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5
|
---|
380 | #define EFI_IMAGE_SYM_CLASS_LABEL 6
|
---|
381 | #define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
|
---|
382 | #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
|
---|
383 | #define EFI_IMAGE_SYM_CLASS_ARGUMENT 9
|
---|
384 | #define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10
|
---|
385 | #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
|
---|
386 | #define EFI_IMAGE_SYM_CLASS_UNION_TAG 12
|
---|
387 | #define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13
|
---|
388 | #define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
|
---|
389 | #define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15
|
---|
390 | #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
|
---|
391 | #define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17
|
---|
392 | #define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18
|
---|
393 | #define EFI_IMAGE_SYM_CLASS_BLOCK 100
|
---|
394 | #define EFI_IMAGE_SYM_CLASS_FUNCTION 101
|
---|
395 | #define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102
|
---|
396 | #define EFI_IMAGE_SYM_CLASS_FILE 103
|
---|
397 | #define EFI_IMAGE_SYM_CLASS_SECTION 104
|
---|
398 | #define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
|
---|
399 |
|
---|
400 | //
|
---|
401 | // type packing constants
|
---|
402 | //
|
---|
403 | #define EFI_IMAGE_N_BTMASK 017
|
---|
404 | #define EFI_IMAGE_N_TMASK 060
|
---|
405 | #define EFI_IMAGE_N_TMASK1 0300
|
---|
406 | #define EFI_IMAGE_N_TMASK2 0360
|
---|
407 | #define EFI_IMAGE_N_BTSHFT 4
|
---|
408 | #define EFI_IMAGE_N_TSHIFT 2
|
---|
409 |
|
---|
410 | //
|
---|
411 | // Communal selection types.
|
---|
412 | //
|
---|
413 | #define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1
|
---|
414 | #define EFI_IMAGE_COMDAT_SELECT_ANY 2
|
---|
415 | #define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3
|
---|
416 | #define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4
|
---|
417 | #define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
|
---|
418 |
|
---|
419 | //
|
---|
420 | // the following values only be referred in PeCoff, not defined in PECOFF.
|
---|
421 | //
|
---|
422 | #define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
|
---|
423 | #define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
|
---|
424 | #define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
|
---|
425 |
|
---|
426 | ///
|
---|
427 | /// Relocation format.
|
---|
428 | ///
|
---|
429 | typedef struct {
|
---|
430 | UINT32 VirtualAddress;
|
---|
431 | UINT32 SymbolTableIndex;
|
---|
432 | UINT16 Type;
|
---|
433 | } EFI_IMAGE_RELOCATION;
|
---|
434 |
|
---|
435 | ///
|
---|
436 | /// Size of EFI_IMAGE_RELOCATION
|
---|
437 | ///
|
---|
438 | #define EFI_IMAGE_SIZEOF_RELOCATION 10
|
---|
439 |
|
---|
440 | //
|
---|
441 | // I386 relocation types.
|
---|
442 | //
|
---|
443 | #define EFI_IMAGE_REL_I386_ABSOLUTE 0x0000 ///< Reference is absolute, no relocation is necessary.
|
---|
444 | #define EFI_IMAGE_REL_I386_DIR16 0x0001 ///< Direct 16-bit reference to the symbols virtual address.
|
---|
445 | #define EFI_IMAGE_REL_I386_REL16 0x0002 ///< PC-relative 16-bit reference to the symbols virtual address.
|
---|
446 | #define EFI_IMAGE_REL_I386_DIR32 0x0006 ///< Direct 32-bit reference to the symbols virtual address.
|
---|
447 | #define EFI_IMAGE_REL_I386_DIR32NB 0x0007 ///< Direct 32-bit reference to the symbols virtual address, base not included.
|
---|
448 | #define EFI_IMAGE_REL_I386_SEG12 0x0009 ///< Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address.
|
---|
449 | #define EFI_IMAGE_REL_I386_SECTION 0x000A
|
---|
450 | #define EFI_IMAGE_REL_I386_SECREL 0x000B
|
---|
451 | #define EFI_IMAGE_REL_I386_REL32 0x0014 ///< PC-relative 32-bit reference to the symbols virtual address.
|
---|
452 |
|
---|
453 | //
|
---|
454 | // x64 processor relocation types.
|
---|
455 | //
|
---|
456 | #define IMAGE_REL_AMD64_ABSOLUTE 0x0000
|
---|
457 | #define IMAGE_REL_AMD64_ADDR64 0x0001
|
---|
458 | #define IMAGE_REL_AMD64_ADDR32 0x0002
|
---|
459 | #define IMAGE_REL_AMD64_ADDR32NB 0x0003
|
---|
460 | #define IMAGE_REL_AMD64_REL32 0x0004
|
---|
461 | #define IMAGE_REL_AMD64_REL32_1 0x0005
|
---|
462 | #define IMAGE_REL_AMD64_REL32_2 0x0006
|
---|
463 | #define IMAGE_REL_AMD64_REL32_3 0x0007
|
---|
464 | #define IMAGE_REL_AMD64_REL32_4 0x0008
|
---|
465 | #define IMAGE_REL_AMD64_REL32_5 0x0009
|
---|
466 | #define IMAGE_REL_AMD64_SECTION 0x000A
|
---|
467 | #define IMAGE_REL_AMD64_SECREL 0x000B
|
---|
468 | #define IMAGE_REL_AMD64_SECREL7 0x000C
|
---|
469 | #define IMAGE_REL_AMD64_TOKEN 0x000D
|
---|
470 | #define IMAGE_REL_AMD64_SREL32 0x000E
|
---|
471 | #define IMAGE_REL_AMD64_PAIR 0x000F
|
---|
472 | #define IMAGE_REL_AMD64_SSPAN32 0x0010
|
---|
473 |
|
---|
474 | ///
|
---|
475 | /// Based relocation format.
|
---|
476 | ///
|
---|
477 | typedef struct {
|
---|
478 | UINT32 VirtualAddress;
|
---|
479 | UINT32 SizeOfBlock;
|
---|
480 | } EFI_IMAGE_BASE_RELOCATION;
|
---|
481 |
|
---|
482 | ///
|
---|
483 | /// Size of EFI_IMAGE_BASE_RELOCATION.
|
---|
484 | ///
|
---|
485 | #define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8
|
---|
486 |
|
---|
487 | //
|
---|
488 | // Based relocation types.
|
---|
489 | //
|
---|
490 | #define EFI_IMAGE_REL_BASED_ABSOLUTE 0
|
---|
491 | #define EFI_IMAGE_REL_BASED_HIGH 1
|
---|
492 | #define EFI_IMAGE_REL_BASED_LOW 2
|
---|
493 | #define EFI_IMAGE_REL_BASED_HIGHLOW 3
|
---|
494 | #define EFI_IMAGE_REL_BASED_HIGHADJ 4
|
---|
495 | #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
|
---|
496 | #define EFI_IMAGE_REL_BASED_ARM_MOV32A 5
|
---|
497 | #define EFI_IMAGE_REL_BASED_ARM_MOV32T 7
|
---|
498 | #define EFI_IMAGE_REL_BASED_IA64_IMM64 9
|
---|
499 | #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16 9
|
---|
500 | #define EFI_IMAGE_REL_BASED_DIR64 10
|
---|
501 |
|
---|
502 | ///
|
---|
503 | /// Line number format.
|
---|
504 | ///
|
---|
505 | typedef struct {
|
---|
506 | union {
|
---|
507 | UINT32 SymbolTableIndex; ///< Symbol table index of function name if Linenumber is 0.
|
---|
508 | UINT32 VirtualAddress; ///< Virtual address of line number.
|
---|
509 | } Type;
|
---|
510 | UINT16 Linenumber; ///< Line number.
|
---|
511 | } EFI_IMAGE_LINENUMBER;
|
---|
512 |
|
---|
513 | ///
|
---|
514 | /// Size of EFI_IMAGE_LINENUMBER.
|
---|
515 | ///
|
---|
516 | #define EFI_IMAGE_SIZEOF_LINENUMBER 6
|
---|
517 |
|
---|
518 | //
|
---|
519 | // Archive format.
|
---|
520 | //
|
---|
521 | #define EFI_IMAGE_ARCHIVE_START_SIZE 8
|
---|
522 | #define EFI_IMAGE_ARCHIVE_START "!<arch>\n"
|
---|
523 | #define EFI_IMAGE_ARCHIVE_END "`\n"
|
---|
524 | #define EFI_IMAGE_ARCHIVE_PAD "\n"
|
---|
525 | #define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ "
|
---|
526 | #define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
|
---|
527 |
|
---|
528 | ///
|
---|
529 | /// Archive Member Headers
|
---|
530 | ///
|
---|
531 | typedef struct {
|
---|
532 | UINT8 Name[16]; ///< File member name - `/' terminated.
|
---|
533 | UINT8 Date[12]; ///< File member date - decimal.
|
---|
534 | UINT8 UserID[6]; ///< File member user id - decimal.
|
---|
535 | UINT8 GroupID[6]; ///< File member group id - decimal.
|
---|
536 | UINT8 Mode[8]; ///< File member mode - octal.
|
---|
537 | UINT8 Size[10]; ///< File member size - decimal.
|
---|
538 | UINT8 EndHeader[2]; ///< String to end header. (0x60 0x0A).
|
---|
539 | } EFI_IMAGE_ARCHIVE_MEMBER_HEADER;
|
---|
540 |
|
---|
541 | ///
|
---|
542 | /// Size of EFI_IMAGE_ARCHIVE_MEMBER_HEADER.
|
---|
543 | ///
|
---|
544 | #define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
|
---|
545 |
|
---|
546 |
|
---|
547 | //
|
---|
548 | // DLL Support
|
---|
549 | //
|
---|
550 |
|
---|
551 | ///
|
---|
552 | /// Export Directory Table.
|
---|
553 | ///
|
---|
554 | typedef struct {
|
---|
555 | UINT32 Characteristics;
|
---|
556 | UINT32 TimeDateStamp;
|
---|
557 | UINT16 MajorVersion;
|
---|
558 | UINT16 MinorVersion;
|
---|
559 | UINT32 Name;
|
---|
560 | UINT32 Base;
|
---|
561 | UINT32 NumberOfFunctions;
|
---|
562 | UINT32 NumberOfNames;
|
---|
563 | UINT32 AddressOfFunctions;
|
---|
564 | UINT32 AddressOfNames;
|
---|
565 | UINT32 AddressOfNameOrdinals;
|
---|
566 | } EFI_IMAGE_EXPORT_DIRECTORY;
|
---|
567 |
|
---|
568 | ///
|
---|
569 | /// Hint/Name Table.
|
---|
570 | ///
|
---|
571 | typedef struct {
|
---|
572 | UINT16 Hint;
|
---|
573 | UINT8 Name[1];
|
---|
574 | } EFI_IMAGE_IMPORT_BY_NAME;
|
---|
575 |
|
---|
576 | ///
|
---|
577 | /// Import Address Table RVA (Thunk Table).
|
---|
578 | ///
|
---|
579 | typedef struct {
|
---|
580 | union {
|
---|
581 | UINT32 Function;
|
---|
582 | UINT32 Ordinal;
|
---|
583 | EFI_IMAGE_IMPORT_BY_NAME *AddressOfData;
|
---|
584 | } u1;
|
---|
585 | } EFI_IMAGE_THUNK_DATA;
|
---|
586 |
|
---|
587 | #define EFI_IMAGE_ORDINAL_FLAG BIT31 ///< Flag for PE32.
|
---|
588 | #define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)
|
---|
589 | #define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
|
---|
590 |
|
---|
591 | ///
|
---|
592 | /// Import Directory Table
|
---|
593 | ///
|
---|
594 | typedef struct {
|
---|
595 | UINT32 Characteristics;
|
---|
596 | UINT32 TimeDateStamp;
|
---|
597 | UINT32 ForwarderChain;
|
---|
598 | UINT32 Name;
|
---|
599 | EFI_IMAGE_THUNK_DATA *FirstThunk;
|
---|
600 | } EFI_IMAGE_IMPORT_DESCRIPTOR;
|
---|
601 |
|
---|
602 |
|
---|
603 | ///
|
---|
604 | /// Debug Directory Format.
|
---|
605 | ///
|
---|
606 | typedef struct {
|
---|
607 | UINT32 Characteristics;
|
---|
608 | UINT32 TimeDateStamp;
|
---|
609 | UINT16 MajorVersion;
|
---|
610 | UINT16 MinorVersion;
|
---|
611 | UINT32 Type;
|
---|
612 | UINT32 SizeOfData;
|
---|
613 | UINT32 RVA; ///< The address of the debug data when loaded, relative to the image base.
|
---|
614 | UINT32 FileOffset; ///< The file pointer to the debug data.
|
---|
615 | } EFI_IMAGE_DEBUG_DIRECTORY_ENTRY;
|
---|
616 |
|
---|
617 | #define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 ///< The Visual C++ debug information.
|
---|
618 |
|
---|
619 | ///
|
---|
620 | /// Debug Data Structure defined in Microsoft C++.
|
---|
621 | ///
|
---|
622 | #define CODEVIEW_SIGNATURE_NB10 SIGNATURE_32('N', 'B', '1', '0')
|
---|
623 | typedef struct {
|
---|
624 | UINT32 Signature; ///< "NB10"
|
---|
625 | UINT32 Unknown;
|
---|
626 | UINT32 Unknown2;
|
---|
627 | UINT32 Unknown3;
|
---|
628 | //
|
---|
629 | // Filename of .PDB goes here
|
---|
630 | //
|
---|
631 | } EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;
|
---|
632 |
|
---|
633 | ///
|
---|
634 | /// Debug Data Structure defined in Microsoft C++.
|
---|
635 | ///
|
---|
636 | #define CODEVIEW_SIGNATURE_RSDS SIGNATURE_32('R', 'S', 'D', 'S')
|
---|
637 | typedef struct {
|
---|
638 | UINT32 Signature; ///< "RSDS".
|
---|
639 | UINT32 Unknown;
|
---|
640 | UINT32 Unknown2;
|
---|
641 | UINT32 Unknown3;
|
---|
642 | UINT32 Unknown4;
|
---|
643 | UINT32 Unknown5;
|
---|
644 | //
|
---|
645 | // Filename of .PDB goes here
|
---|
646 | //
|
---|
647 | } EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;
|
---|
648 |
|
---|
649 |
|
---|
650 | ///
|
---|
651 | /// Debug Data Structure defined by Apple Mach-O to Coff utility.
|
---|
652 | ///
|
---|
653 | #define CODEVIEW_SIGNATURE_MTOC SIGNATURE_32('M', 'T', 'O', 'C')
|
---|
654 | typedef struct {
|
---|
655 | UINT32 Signature; ///< "MTOC".
|
---|
656 | GUID MachOUuid;
|
---|
657 | //
|
---|
658 | // Filename of .DLL (Mach-O with debug info) goes here
|
---|
659 | //
|
---|
660 | } EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY;
|
---|
661 |
|
---|
662 | ///
|
---|
663 | /// Resource format.
|
---|
664 | ///
|
---|
665 | typedef struct {
|
---|
666 | UINT32 Characteristics;
|
---|
667 | UINT32 TimeDateStamp;
|
---|
668 | UINT16 MajorVersion;
|
---|
669 | UINT16 MinorVersion;
|
---|
670 | UINT16 NumberOfNamedEntries;
|
---|
671 | UINT16 NumberOfIdEntries;
|
---|
672 | //
|
---|
673 | // Array of EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY entries goes here.
|
---|
674 | //
|
---|
675 | } EFI_IMAGE_RESOURCE_DIRECTORY;
|
---|
676 |
|
---|
677 | ///
|
---|
678 | /// Resource directory entry format.
|
---|
679 | ///
|
---|
680 | typedef struct {
|
---|
681 | union {
|
---|
682 | struct {
|
---|
683 | UINT32 NameOffset:31;
|
---|
684 | UINT32 NameIsString:1;
|
---|
685 | } s;
|
---|
686 | UINT32 Id;
|
---|
687 | } u1;
|
---|
688 | union {
|
---|
689 | UINT32 OffsetToData;
|
---|
690 | struct {
|
---|
691 | UINT32 OffsetToDirectory:31;
|
---|
692 | UINT32 DataIsDirectory:1;
|
---|
693 | } s;
|
---|
694 | } u2;
|
---|
695 | } EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY;
|
---|
696 |
|
---|
697 | ///
|
---|
698 | /// Resource directory entry for string.
|
---|
699 | ///
|
---|
700 | typedef struct {
|
---|
701 | UINT16 Length;
|
---|
702 | CHAR16 String[1];
|
---|
703 | } EFI_IMAGE_RESOURCE_DIRECTORY_STRING;
|
---|
704 |
|
---|
705 | ///
|
---|
706 | /// Resource directory entry for data array.
|
---|
707 | ///
|
---|
708 | typedef struct {
|
---|
709 | UINT32 OffsetToData;
|
---|
710 | UINT32 Size;
|
---|
711 | UINT32 CodePage;
|
---|
712 | UINT32 Reserved;
|
---|
713 | } EFI_IMAGE_RESOURCE_DATA_ENTRY;
|
---|
714 |
|
---|
715 | ///
|
---|
716 | /// Header format for TE images, defined in the PI Specification, 1.0.
|
---|
717 | ///
|
---|
718 | typedef struct {
|
---|
719 | UINT16 Signature; ///< The signature for TE format = "VZ".
|
---|
720 | UINT16 Machine; ///< From the original file header.
|
---|
721 | UINT8 NumberOfSections; ///< From the original file header.
|
---|
722 | UINT8 Subsystem; ///< From original optional header.
|
---|
723 | UINT16 StrippedSize; ///< Number of bytes we removed from the header.
|
---|
724 | UINT32 AddressOfEntryPoint; ///< Offset to entry point -- from original optional header.
|
---|
725 | UINT32 BaseOfCode; ///< From original image -- required for ITP debug.
|
---|
726 | UINT64 ImageBase; ///< From original file header.
|
---|
727 | EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; ///< Only base relocation and debug directory.
|
---|
728 | } EFI_TE_IMAGE_HEADER;
|
---|
729 |
|
---|
730 |
|
---|
731 | #define EFI_TE_IMAGE_HEADER_SIGNATURE SIGNATURE_16('V', 'Z')
|
---|
732 |
|
---|
733 | //
|
---|
734 | // Data directory indexes in our TE image header
|
---|
735 | //
|
---|
736 | #define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC 0
|
---|
737 | #define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG 1
|
---|
738 |
|
---|
739 |
|
---|
740 | ///
|
---|
741 | /// Union of PE32, PE32+, and TE headers.
|
---|
742 | ///
|
---|
743 | typedef union {
|
---|
744 | EFI_IMAGE_NT_HEADERS32 Pe32;
|
---|
745 | EFI_IMAGE_NT_HEADERS64 Pe32Plus;
|
---|
746 | EFI_TE_IMAGE_HEADER Te;
|
---|
747 | } EFI_IMAGE_OPTIONAL_HEADER_UNION;
|
---|
748 |
|
---|
749 | typedef union {
|
---|
750 | EFI_IMAGE_NT_HEADERS32 *Pe32;
|
---|
751 | EFI_IMAGE_NT_HEADERS64 *Pe32Plus;
|
---|
752 | EFI_TE_IMAGE_HEADER *Te;
|
---|
753 | EFI_IMAGE_OPTIONAL_HEADER_UNION *Union;
|
---|
754 | } EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION;
|
---|
755 |
|
---|
756 | #endif
|
---|