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