iPXE
PeImage.h
Go to the documentation of this file.
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 9.3 - December 29, 2015.
8  This file also includes some definitions in PI Specification, Revision 1.0.
9 
10 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
11 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
12 Portions Copyright (c) 2016 - 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
13 Portions Copyright (c) 2022, Loongson Technology Corporation Limited. All rights reserved.<BR>
14 
15 SPDX-License-Identifier: BSD-2-Clause-Patent
16 
17 **/
18 
19 #ifndef __PE_IMAGE_H__
20 #define __PE_IMAGE_H__
21 
22 FILE_LICENCE ( BSD2_PATENT );
23 
24 //
25 // PE32+ Subsystem type for EFI images
26 //
27 #define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10
28 #define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
29 #define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
30 
31 //
32 // PE32+ Machine type for EFI images
33 //
34 #define IMAGE_FILE_MACHINE_I386 0x014c
35 #define IMAGE_FILE_MACHINE_IA64 0x0200
36 #define IMAGE_FILE_MACHINE_EBC 0x0EBC
37 #define IMAGE_FILE_MACHINE_X64 0x8664
38 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED 0x01c2
39 #define IMAGE_FILE_MACHINE_ARM64 0xAA64
40 #define IMAGE_FILE_MACHINE_RISCV32 0x5032
41 #define IMAGE_FILE_MACHINE_RISCV64 0x5064
42 #define IMAGE_FILE_MACHINE_RISCV128 0x5128
43 #define IMAGE_FILE_MACHINE_LOONGARCH32 0x6232
44 #define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264
45 
46 //
47 // EXE file formats
48 //
49 #define EFI_IMAGE_DOS_SIGNATURE SIGNATURE_16('M', 'Z')
50 #define EFI_IMAGE_OS2_SIGNATURE SIGNATURE_16('N', 'E')
51 #define EFI_IMAGE_OS2_SIGNATURE_LE SIGNATURE_16('L', 'E')
52 #define EFI_IMAGE_NT_SIGNATURE SIGNATURE_32('P', 'E', '\0', '\0')
53 
54 ///
55 /// PE images can start with an optional DOS header, so if an image is run
56 /// under DOS it can print an error message.
57 ///
58 typedef struct {
59  UINT16 e_magic; ///< Magic number.
60  UINT16 e_cblp; ///< Bytes on last page of file.
61  UINT16 e_cp; ///< Pages in file.
62  UINT16 e_crlc; ///< Relocations.
63  UINT16 e_cparhdr; ///< Size of header in paragraphs.
64  UINT16 e_minalloc; ///< Minimum extra paragraphs needed.
65  UINT16 e_maxalloc; ///< Maximum extra paragraphs needed.
66  UINT16 e_ss; ///< Initial (relative) SS value.
67  UINT16 e_sp; ///< Initial SP value.
68  UINT16 e_csum; ///< Checksum.
69  UINT16 e_ip; ///< Initial IP value.
70  UINT16 e_cs; ///< Initial (relative) CS value.
71  UINT16 e_lfarlc; ///< File address of relocation table.
72  UINT16 e_ovno; ///< Overlay number.
73  UINT16 e_res[4]; ///< Reserved words.
74  UINT16 e_oemid; ///< OEM identifier (for e_oeminfo).
75  UINT16 e_oeminfo; ///< OEM information; e_oemid specific.
76  UINT16 e_res2[10]; ///< Reserved words.
77  UINT32 e_lfanew; ///< File address of new exe header.
79 
80 ///
81 /// COFF File Header (Object and Image).
82 ///
83 typedef struct {
92 
93 ///
94 /// Size of EFI_IMAGE_FILE_HEADER.
95 ///
96 #define EFI_IMAGE_SIZEOF_FILE_HEADER 20
97 
98 //
99 // Characteristics
100 //
101 #define EFI_IMAGE_FILE_RELOCS_STRIPPED BIT0 ///< 0x0001 Relocation info stripped from file.
102 #define EFI_IMAGE_FILE_EXECUTABLE_IMAGE BIT1 ///< 0x0002 File is executable (i.e. no unresolved externel references).
103 #define EFI_IMAGE_FILE_LINE_NUMS_STRIPPED BIT2 ///< 0x0004 Line numbers stripped from file.
104 #define EFI_IMAGE_FILE_LOCAL_SYMS_STRIPPED BIT3 ///< 0x0008 Local symbols stripped from file.
105 #define EFI_IMAGE_FILE_LARGE_ADDRESS_AWARE BIT5 ///< 0x0020 Supports addresses > 2-GB
106 #define EFI_IMAGE_FILE_BYTES_REVERSED_LO BIT7 ///< 0x0080 Bytes of machine word are reversed.
107 #define EFI_IMAGE_FILE_32BIT_MACHINE BIT8 ///< 0x0100 32 bit word machine.
108 #define EFI_IMAGE_FILE_DEBUG_STRIPPED BIT9 ///< 0x0200 Debugging info stripped from file in .DBG file.
109 #define EFI_IMAGE_FILE_SYSTEM BIT12 ///< 0x1000 System File.
110 #define EFI_IMAGE_FILE_DLL BIT13 ///< 0x2000 File is a DLL.
111 #define EFI_IMAGE_FILE_BYTES_REVERSED_HI BIT15 ///< 0x8000 Bytes of machine word are reversed.
112 
113 ///
114 /// Header Data Directories.
115 ///
116 typedef struct {
120 
121 //
122 // Directory Entries
123 //
124 #define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0
125 #define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1
126 #define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2
127 #define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
128 #define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4
129 #define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
130 #define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6
131 #define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
132 #define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
133 #define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9
134 #define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
135 
136 #define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16
137 
138 ///
139 /// @attention
140 /// EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC means PE32 and
141 /// EFI_IMAGE_OPTIONAL_HEADER32 must be used. The data structures only vary
142 /// after NT additional fields.
143 ///
144 #define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
145 
146 ///
147 /// Optional Header Standard Fields for PE32.
148 ///
149 typedef struct {
150  ///
151  /// Standard fields.
152  ///
161  UINT32 BaseOfData; ///< PE32 contains this additional field, which is absent in PE32+.
162  ///
163  /// Optional Header Windows-Specific Fields.
164  ///
188 
189 ///
190 /// @attention
191 /// EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC means PE32+ and
192 /// EFI_IMAGE_OPTIONAL_HEADER64 must be used. The data structures only vary
193 /// after NT additional fields.
194 ///
195 #define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
196 
197 ///
198 /// Optional Header Standard Fields for PE32+.
199 ///
200 typedef struct {
201  ///
202  /// Standard fields.
203  ///
212  ///
213  /// Optional Header Windows-Specific Fields.
214  ///
238 
239 ///
240 /// @attention
241 /// EFI_IMAGE_NT_HEADERS32 is for use ONLY by tools.
242 ///
243 typedef struct {
248 
249 #define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof (EFI_IMAGE_NT_HEADERS32)
250 
251 ///
252 /// @attention
253 /// EFI_IMAGE_HEADERS64 is for use ONLY by tools.
254 ///
255 typedef struct {
260 
261 #define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof (EFI_IMAGE_NT_HEADERS64)
262 
263 //
264 // Other Windows Subsystem Values
265 //
266 #define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0
267 #define EFI_IMAGE_SUBSYSTEM_NATIVE 1
268 #define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2
269 #define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3
270 #define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5
271 #define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7
272 
273 //
274 // DLL Characteristics
275 //
276 #define IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA 0x0020
277 #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE 0x0040
278 #define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY 0x0080
279 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
280 #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
281 #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
282 #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
283 #define IMAGE_DLLCHARACTERISTICS_APPCONTAINER 0x1000
284 #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
285 #define IMAGE_DLLCHARACTERISTICS_GUARD_CF 0x4000
286 #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
287 
288 ///
289 /// Length of ShortName.
290 ///
291 #define EFI_IMAGE_SIZEOF_SHORT_NAME 8
292 
293 ///
294 /// Section Table. This table immediately follows the optional header.
295 ///
296 typedef struct {
298  union {
301  } Misc;
311 
312 ///
313 /// Size of EFI_IMAGE_SECTION_HEADER.
314 ///
315 #define EFI_IMAGE_SIZEOF_SECTION_HEADER 40
316 
317 //
318 // Section Flags Values
319 //
320 #define EFI_IMAGE_SCN_TYPE_NO_PAD BIT3 ///< 0x00000008 ///< Reserved.
321 #define EFI_IMAGE_SCN_CNT_CODE BIT5 ///< 0x00000020
322 #define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA BIT6 ///< 0x00000040
323 #define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA BIT7 ///< 0x00000080
324 
325 #define EFI_IMAGE_SCN_LNK_OTHER BIT8 ///< 0x00000100 ///< Reserved.
326 #define EFI_IMAGE_SCN_LNK_INFO BIT9 ///< 0x00000200 ///< Section contains comments or some other type of information.
327 #define EFI_IMAGE_SCN_LNK_REMOVE BIT11 ///< 0x00000800 ///< Section contents will not become part of image.
328 #define EFI_IMAGE_SCN_LNK_COMDAT BIT12 ///< 0x00001000
329 
330 #define EFI_IMAGE_SCN_ALIGN_1BYTES BIT20 ///< 0x00100000
331 #define EFI_IMAGE_SCN_ALIGN_2BYTES BIT21 ///< 0x00200000
332 #define EFI_IMAGE_SCN_ALIGN_4BYTES (BIT20|BIT21) ///< 0x00300000
333 #define EFI_IMAGE_SCN_ALIGN_8BYTES BIT22 ///< 0x00400000
334 #define EFI_IMAGE_SCN_ALIGN_16BYTES (BIT20|BIT22) ///< 0x00500000
335 #define EFI_IMAGE_SCN_ALIGN_32BYTES (BIT21|BIT22) ///< 0x00600000
336 #define EFI_IMAGE_SCN_ALIGN_64BYTES (BIT20|BIT21|BIT22) ///< 0x00700000
337 
338 #define EFI_IMAGE_SCN_MEM_DISCARDABLE BIT25 ///< 0x02000000
339 #define EFI_IMAGE_SCN_MEM_NOT_CACHED BIT26 ///< 0x04000000
340 #define EFI_IMAGE_SCN_MEM_NOT_PAGED BIT27 ///< 0x08000000
341 #define EFI_IMAGE_SCN_MEM_SHARED BIT28 ///< 0x10000000
342 #define EFI_IMAGE_SCN_MEM_EXECUTE BIT29 ///< 0x20000000
343 #define EFI_IMAGE_SCN_MEM_READ BIT30 ///< 0x40000000
344 #define EFI_IMAGE_SCN_MEM_WRITE BIT31 ///< 0x80000000
345 
346 ///
347 /// Size of a Symbol Table Record.
348 ///
349 #define EFI_IMAGE_SIZEOF_SYMBOL 18
350 
351 //
352 // Symbols have a section number of the section in which they are
353 // defined. Otherwise, section numbers have the following meanings:
354 //
355 #define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0 ///< Symbol is undefined or is common.
356 #define EFI_IMAGE_SYM_ABSOLUTE (UINT16) -1 ///< Symbol is an absolute value.
357 #define EFI_IMAGE_SYM_DEBUG (UINT16) -2 ///< Symbol is a special debug item.
358 
359 //
360 // Symbol Type (fundamental) values.
361 //
362 #define EFI_IMAGE_SYM_TYPE_NULL 0 ///< no type.
363 #define EFI_IMAGE_SYM_TYPE_VOID 1 ///< no valid type.
364 #define EFI_IMAGE_SYM_TYPE_CHAR 2 ///< type character.
365 #define EFI_IMAGE_SYM_TYPE_SHORT 3 ///< type short integer.
366 #define EFI_IMAGE_SYM_TYPE_INT 4
367 #define EFI_IMAGE_SYM_TYPE_LONG 5
368 #define EFI_IMAGE_SYM_TYPE_FLOAT 6
369 #define EFI_IMAGE_SYM_TYPE_DOUBLE 7
370 #define EFI_IMAGE_SYM_TYPE_STRUCT 8
371 #define EFI_IMAGE_SYM_TYPE_UNION 9
372 #define EFI_IMAGE_SYM_TYPE_ENUM 10 ///< enumeration.
373 #define EFI_IMAGE_SYM_TYPE_MOE 11 ///< member of enumeration.
374 #define EFI_IMAGE_SYM_TYPE_BYTE 12
375 #define EFI_IMAGE_SYM_TYPE_WORD 13
376 #define EFI_IMAGE_SYM_TYPE_UINT 14
377 #define EFI_IMAGE_SYM_TYPE_DWORD 15
378 
379 //
380 // Symbol Type (derived) values.
381 //
382 #define EFI_IMAGE_SYM_DTYPE_NULL 0 ///< no derived type.
383 #define EFI_IMAGE_SYM_DTYPE_POINTER 1
384 #define EFI_IMAGE_SYM_DTYPE_FUNCTION 2
385 #define EFI_IMAGE_SYM_DTYPE_ARRAY 3
386 
387 //
388 // Storage classes.
389 //
390 #define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION ((UINT8) -1)
391 #define EFI_IMAGE_SYM_CLASS_NULL 0
392 #define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1
393 #define EFI_IMAGE_SYM_CLASS_EXTERNAL 2
394 #define EFI_IMAGE_SYM_CLASS_STATIC 3
395 #define EFI_IMAGE_SYM_CLASS_REGISTER 4
396 #define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5
397 #define EFI_IMAGE_SYM_CLASS_LABEL 6
398 #define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
399 #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
400 #define EFI_IMAGE_SYM_CLASS_ARGUMENT 9
401 #define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10
402 #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
403 #define EFI_IMAGE_SYM_CLASS_UNION_TAG 12
404 #define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13
405 #define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
406 #define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15
407 #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
408 #define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17
409 #define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18
410 #define EFI_IMAGE_SYM_CLASS_BLOCK 100
411 #define EFI_IMAGE_SYM_CLASS_FUNCTION 101
412 #define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102
413 #define EFI_IMAGE_SYM_CLASS_FILE 103
414 #define EFI_IMAGE_SYM_CLASS_SECTION 104
415 #define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
416 
417 //
418 // type packing constants
419 //
420 #define EFI_IMAGE_N_BTMASK 017
421 #define EFI_IMAGE_N_TMASK 060
422 #define EFI_IMAGE_N_TMASK1 0300
423 #define EFI_IMAGE_N_TMASK2 0360
424 #define EFI_IMAGE_N_BTSHFT 4
425 #define EFI_IMAGE_N_TSHIFT 2
426 
427 //
428 // Communal selection types.
429 //
430 #define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1
431 #define EFI_IMAGE_COMDAT_SELECT_ANY 2
432 #define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3
433 #define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4
434 #define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
435 
436 //
437 // the following values only be referred in PeCoff, not defined in PECOFF.
438 //
439 #define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
440 #define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
441 #define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
442 
443 ///
444 /// Relocation format.
445 ///
446 typedef struct {
451 
452 ///
453 /// Size of EFI_IMAGE_RELOCATION
454 ///
455 #define EFI_IMAGE_SIZEOF_RELOCATION 10
456 
457 //
458 // I386 relocation types.
459 //
460 #define EFI_IMAGE_REL_I386_ABSOLUTE 0x0000 ///< Reference is absolute, no relocation is necessary.
461 #define EFI_IMAGE_REL_I386_DIR16 0x0001 ///< Direct 16-bit reference to the symbols virtual address.
462 #define EFI_IMAGE_REL_I386_REL16 0x0002 ///< PC-relative 16-bit reference to the symbols virtual address.
463 #define EFI_IMAGE_REL_I386_DIR32 0x0006 ///< Direct 32-bit reference to the symbols virtual address.
464 #define EFI_IMAGE_REL_I386_DIR32NB 0x0007 ///< Direct 32-bit reference to the symbols virtual address, base not included.
465 #define EFI_IMAGE_REL_I386_SEG12 0x0009 ///< Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address.
466 #define EFI_IMAGE_REL_I386_SECTION 0x000A
467 #define EFI_IMAGE_REL_I386_SECREL 0x000B
468 #define EFI_IMAGE_REL_I386_REL32 0x0014 ///< PC-relative 32-bit reference to the symbols virtual address.
469 
470 //
471 // x64 processor relocation types.
472 //
473 #define IMAGE_REL_AMD64_ABSOLUTE 0x0000
474 #define IMAGE_REL_AMD64_ADDR64 0x0001
475 #define IMAGE_REL_AMD64_ADDR32 0x0002
476 #define IMAGE_REL_AMD64_ADDR32NB 0x0003
477 #define IMAGE_REL_AMD64_REL32 0x0004
478 #define IMAGE_REL_AMD64_REL32_1 0x0005
479 #define IMAGE_REL_AMD64_REL32_2 0x0006
480 #define IMAGE_REL_AMD64_REL32_3 0x0007
481 #define IMAGE_REL_AMD64_REL32_4 0x0008
482 #define IMAGE_REL_AMD64_REL32_5 0x0009
483 #define IMAGE_REL_AMD64_SECTION 0x000A
484 #define IMAGE_REL_AMD64_SECREL 0x000B
485 #define IMAGE_REL_AMD64_SECREL7 0x000C
486 #define IMAGE_REL_AMD64_TOKEN 0x000D
487 #define IMAGE_REL_AMD64_SREL32 0x000E
488 #define IMAGE_REL_AMD64_PAIR 0x000F
489 #define IMAGE_REL_AMD64_SSPAN32 0x0010
490 
491 ///
492 /// Based relocation format.
493 ///
494 typedef struct {
498 
499 ///
500 /// Size of EFI_IMAGE_BASE_RELOCATION.
501 ///
502 #define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8
503 
504 //
505 // Based relocation types.
506 //
507 #define EFI_IMAGE_REL_BASED_ABSOLUTE 0
508 #define EFI_IMAGE_REL_BASED_HIGH 1
509 #define EFI_IMAGE_REL_BASED_LOW 2
510 #define EFI_IMAGE_REL_BASED_HIGHLOW 3
511 #define EFI_IMAGE_REL_BASED_HIGHADJ 4
512 #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
513 #define EFI_IMAGE_REL_BASED_ARM_MOV32A 5
514 #define EFI_IMAGE_REL_BASED_ARM_MOV32T 7
515 #define EFI_IMAGE_REL_BASED_IA64_IMM64 9
516 #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR16 9
517 #define EFI_IMAGE_REL_BASED_DIR64 10
518 
519 ///
520 /// Relocation types of RISC-V processor.
521 ///
522 #define EFI_IMAGE_REL_BASED_RISCV_HI20 5
523 #define EFI_IMAGE_REL_BASED_RISCV_LOW12I 7
524 #define EFI_IMAGE_REL_BASED_RISCV_LOW12S 8
525 
526 //
527 // Relocation types of LoongArch processor.
528 //
529 #define EFI_IMAGE_REL_BASED_LOONGARCH32_MARK_LA 8
530 #define EFI_IMAGE_REL_BASED_LOONGARCH64_MARK_LA 8
531 
532 ///
533 /// Line number format.
534 ///
535 typedef struct {
536  union {
537  UINT32 SymbolTableIndex; ///< Symbol table index of function name if Linenumber is 0.
538  UINT32 VirtualAddress; ///< Virtual address of line number.
539  } Type;
540  UINT16 Linenumber; ///< Line number.
542 
543 ///
544 /// Size of EFI_IMAGE_LINENUMBER.
545 ///
546 #define EFI_IMAGE_SIZEOF_LINENUMBER 6
547 
548 //
549 // Archive format.
550 //
551 #define EFI_IMAGE_ARCHIVE_START_SIZE 8
552 #define EFI_IMAGE_ARCHIVE_START "!<arch>\n"
553 #define EFI_IMAGE_ARCHIVE_END "`\n"
554 #define EFI_IMAGE_ARCHIVE_PAD "\n"
555 #define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ "
556 #define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
557 
558 ///
559 /// Archive Member Headers
560 ///
561 typedef struct {
562  UINT8 Name[16]; ///< File member name - `/' terminated.
563  UINT8 Date[12]; ///< File member date - decimal.
564  UINT8 UserID[6]; ///< File member user id - decimal.
565  UINT8 GroupID[6]; ///< File member group id - decimal.
566  UINT8 Mode[8]; ///< File member mode - octal.
567  UINT8 Size[10]; ///< File member size - decimal.
568  UINT8 EndHeader[2]; ///< String to end header. (0x60 0x0A).
570 
571 ///
572 /// Size of EFI_IMAGE_ARCHIVE_MEMBER_HEADER.
573 ///
574 #define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
575 
576 //
577 // DLL Support
578 //
579 
580 ///
581 /// Export Directory Table.
582 ///
583 typedef struct {
596 
597 //
598 // Based export types.
599 //
600 #define EFI_IMAGE_EXPORT_ORDINAL_BASE 1
601 #define EFI_IMAGE_EXPORT_ADDR_SIZE 4
602 #define EFI_IMAGE_EXPORT_ORDINAL_SIZE 2
603 
604 ///
605 /// Hint/Name Table.
606 ///
607 typedef struct {
611 
612 ///
613 /// Import Address Table RVA (Thunk Table).
614 ///
615 typedef struct {
616  union {
620  } u1;
622 
623 #define EFI_IMAGE_ORDINAL_FLAG BIT31 ///< Flag for PE32.
624 #define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)
625 #define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
626 
627 ///
628 /// Import Directory Table
629 ///
630 typedef struct {
637 
638 ///
639 /// Debug Directory Format.
640 ///
641 typedef struct {
648  UINT32 RVA; ///< The address of the debug data when loaded, relative to the image base.
649  UINT32 FileOffset; ///< The file pointer to the debug data.
651 
652 #define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2 ///< The Visual C++ debug information.
653 #define EFI_IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS 20
654 
655 ///
656 /// Debug Data Structure defined in Microsoft C++.
657 ///
658 #define CODEVIEW_SIGNATURE_NB10 SIGNATURE_32('N', 'B', '1', '0')
659 typedef struct {
660  UINT32 Signature; ///< "NB10"
664  //
665  // Filename of .PDB goes here
666  //
668 
669 ///
670 /// Debug Data Structure defined in Microsoft C++.
671 ///
672 #define CODEVIEW_SIGNATURE_RSDS SIGNATURE_32('R', 'S', 'D', 'S')
673 typedef struct {
674  UINT32 Signature; ///< "RSDS".
680  //
681  // Filename of .PDB goes here
682  //
684 
685 ///
686 /// Debug Data Structure defined by Apple Mach-O to Coff utility.
687 ///
688 #define CODEVIEW_SIGNATURE_MTOC SIGNATURE_32('M', 'T', 'O', 'C')
689 typedef struct {
690  UINT32 Signature; ///< "MTOC".
692  //
693  // Filename of .DLL (Mach-O with debug info) goes here
694  //
696 
697 //
698 // .pdata entries for X64
699 //
700 typedef struct {
705 
706 typedef struct {
713 } UNWIND_INFO;
714 
715 ///
716 /// Extended DLL Characteristics
717 ///
718 #define EFI_IMAGE_DLLCHARACTERISTICS_EX_CET_COMPAT 0x0001
719 #define EFI_IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT 0x0040
720 
721 typedef struct {
724 
725 ///
726 /// Resource format.
727 ///
728 typedef struct {
735  //
736  // Array of EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY entries goes here.
737  //
739 
740 ///
741 /// Resource directory entry format.
742 ///
743 typedef struct {
744  union {
745  struct {
748  } s;
750  } u1;
751  union {
753  struct {
756  } s;
757  } u2;
759 
760 ///
761 /// Resource directory entry for string.
762 ///
763 typedef struct {
765  CHAR16 String[1];
767 
768 ///
769 /// Resource directory entry for data array.
770 ///
771 typedef struct {
777 
778 ///
779 /// Header format for TE images, defined in the PI Specification, 1.0.
780 ///
781 typedef struct {
782  UINT16 Signature; ///< The signature for TE format = "VZ".
783  UINT16 Machine; ///< From the original file header.
784  UINT8 NumberOfSections; ///< From the original file header.
785  UINT8 Subsystem; ///< From original optional header.
786  UINT16 StrippedSize; ///< Number of bytes we removed from the header.
787  UINT32 AddressOfEntryPoint; ///< Offset to entry point -- from original optional header.
788  UINT32 BaseOfCode; ///< From original image -- required for ITP debug.
789  UINT64 ImageBase; ///< From original file header.
790  EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; ///< Only base relocation and debug directory.
792 
793 #define EFI_TE_IMAGE_HEADER_SIGNATURE SIGNATURE_16('V', 'Z')
794 
795 //
796 // Data directory indexes in our TE image header
797 //
798 #define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC 0
799 #define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG 1
800 
801 ///
802 /// Union of PE32, PE32+, and TE headers.
803 ///
804 typedef union {
809 
810 typedef union {
816 
817 #endif
UINT8 CountOfUnwindCodes
Definition: PeImage.h:710
EFI_IMAGE_IMPORT_BY_NAME * AddressOfData
Definition: PeImage.h:619
UINT16 e_ip
Initial IP value.
Definition: PeImage.h:69
Archive Member Headers.
Definition: PeImage.h:561
UINT32 DllCharacteristicsEx
Definition: PeImage.h:722
UINT16 MinorVersion
Definition: PeImage.h:645
UINT16 SizeOfOptionalHeader
Definition: PeImage.h:89
UINT32 Unknown3
Definition: PeImage.h:663
UINT8 Type
Definition: Acpi10.h:136
EFI_IMAGE_FILE_HEADER FileHeader
Definition: PeImage.h:245
UINT16 MajorOperatingSystemVersion
Definition: PeImage.h:168
FILE_LICENCE(BSD2_PATENT)
UINT8 NumberOfSections
From the original file header.
Definition: PeImage.h:784
UINT32 Characteristics
Definition: PeImage.h:642
EFI_IMAGE_OPTIONAL_HEADER_UNION * Union
Definition: PeImage.h:814
UINT32 Unknown5
Definition: PeImage.h:679
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
UINT16 e_maxalloc
Maximum extra paragraphs needed.
Definition: PeImage.h:65
EFI_IMAGE_NT_HEADERS32 * Pe32
Definition: PeImage.h:811
UINT32 NameIsString
Definition: PeImage.h:747
UINT16 e_cp
Pages in file.
Definition: PeImage.h:61
UINT32 BaseOfCode
From original image – required for ITP debug.
Definition: PeImage.h:788
UINT32 OffsetToData
Definition: PeImage.h:752
UINT8 FrameRegister
Definition: PeImage.h:711
Union of PE32, PE32+, and TE headers.
Definition: PeImage.h:804
UINT8 Version
Definition: PeImage.h:707
UINT32 VirtualAddress
Definition: PeImage.h:447
UINT32 TimeDateStamp
Definition: PeImage.h:86
unsigned int UINT32
Definition: ProcessorBind.h:98
Definition: PeImage.h:659
unsigned short CHAR16
GUID MachOUuid
Definition: PeImage.h:691
UINT16 e_oemid
OEM identifier (for e_oeminfo).
Definition: PeImage.h:74
Optional Header Standard Fields for PE32+.
Definition: PeImage.h:200
UINT16 Linenumber
Line number.
Definition: PeImage.h:540
Optional Header Standard Fields for PE32.
Definition: PeImage.h:149
UINT16 e_csum
Checksum.
Definition: PeImage.h:68
UINT32 PointerToSymbolTable
Definition: PeImage.h:87
Import Address Table RVA (Thunk Table).
Definition: PeImage.h:615
UINT8 FrameRegisterOffset
Definition: PeImage.h:712
EFI_IMAGE_NT_HEADERS32 Pe32
Definition: PeImage.h:805
Definition: PeImage.h:721
unsigned char UINT8
COFF File Header (Object and Image).
Definition: PeImage.h:83
Resource directory entry format.
Definition: PeImage.h:743
UINT16_t Size
Size of structure.
Definition: pxe_api.h:58
UINT16 e_lfarlc
File address of relocation table.
Definition: PeImage.h:71
UINT16 Machine
From the original file header.
Definition: PeImage.h:783
Definition: PeImage.h:689
UINT32 Type
Definition: PeImage.h:646
UINT16 MajorOperatingSystemVersion
Definition: PeImage.h:218
Section Table.
Definition: PeImage.h:296
UINT32 SymbolTableIndex
Definition: PeImage.h:448
UINT8 Name
Definition: Acpi10.h:135
UINT32 ImageBase
Optional Header Windows-Specific Fields.
Definition: PeImage.h:165
EFI_TE_IMAGE_HEADER Te
Definition: PeImage.h:807
UINT16 MajorVersion
Definition: PeImage.h:644
Resource directory entry for string.
Definition: PeImage.h:763
EFI_IMAGE_FILE_HEADER FileHeader
Definition: PeImage.h:257
UINT32 FunctionEndAddress
Definition: PeImage.h:702
UINT32 BaseOfData
PE32 contains this additional field, which is absent in PE32+.
Definition: PeImage.h:161
UINT16 MinorOperatingSystemVersion
Definition: PeImage.h:169
UINT16 MinorOperatingSystemVersion
Definition: PeImage.h:219
#define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES
Definition: PeImage.h:136
UINT32 FileOffset
The file pointer to the debug data.
Definition: PeImage.h:649
Relocation format.
Definition: PeImage.h:446
UINT16 e_minalloc
Minimum extra paragraphs needed.
Definition: PeImage.h:64
UINT32 Size
Definition: PeImage.h:773
UINT16 e_cparhdr
Size of header in paragraphs.
Definition: PeImage.h:63
UINT64 ImageBase
Optional Header Windows-Specific Fields.
Definition: PeImage.h:215
UINT32 Unknown3
Definition: PeImage.h:677
unsigned short UINT16
Export Directory Table.
Definition: PeImage.h:583
UINT16 Magic
Standard fields.
Definition: PeImage.h:153
Line number format.
Definition: PeImage.h:535
UINT16 NumberOfSections
Definition: PeImage.h:85
UINT32 UnwindInfoAddress
Definition: PeImage.h:703
UINT32 Unknown2
Definition: PeImage.h:676
UINT32 Id
Definition: PeImage.h:749
UINT16 e_crlc
Relocations.
Definition: PeImage.h:62
EFI_IMAGE_THUNK_DATA * FirstThunk
Definition: PeImage.h:635
UINT32 Signature
"NB10"
Definition: PeImage.h:660
UINT16 Signature
The signature for TE format = "VZ".
Definition: PeImage.h:782
UINT8 Flags
Definition: PeImage.h:708
Header Data Directories.
Definition: PeImage.h:116
UINT32 Unknown
Definition: PeImage.h:661
UINT16 Characteristics
Definition: PeImage.h:90
EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader
Definition: PeImage.h:258
UINT16 e_oeminfo
OEM information; e_oemid specific.
Definition: PeImage.h:75
Definition: PeImage.h:673
UINT16 e_ovno
Overlay number.
Definition: PeImage.h:72
unsigned long long UINT64
Definition: ProcessorBind.h:96
Hint/Name Table.
Definition: PeImage.h:607
Debug Directory Format.
Definition: PeImage.h:641
UINT16 StrippedSize
Number of bytes we removed from the header.
Definition: PeImage.h:786
UINT32 AddressOfEntryPoint
Offset to entry point – from original optional header.
Definition: PeImage.h:787
#define EFI_IMAGE_SIZEOF_SHORT_NAME
Length of ShortName.
Definition: PeImage.h:291
Header format for TE images, defined in the PI Specification, 1.0.
Definition: PeImage.h:781
Resource directory entry for data array.
Definition: PeImage.h:771
UINT32 e_lfanew
File address of new exe header.
Definition: PeImage.h:77
UINT32 FunctionStartAddress
Definition: PeImage.h:701
UINT16 e_magic
Magic number.
Definition: PeImage.h:59
UINT32 DataIsDirectory
Definition: PeImage.h:755
EFI_TE_IMAGE_HEADER * Te
Definition: PeImage.h:813
UINT32 CodePage
Definition: PeImage.h:774
UINT32 NumberOfSymbols
Definition: PeImage.h:88
UINT32 Unknown4
Definition: PeImage.h:678
UINT32 NameOffset
Definition: PeImage.h:746
PE images can start with an optional DOS header, so if an image is run under DOS it can print an erro...
Definition: PeImage.h:58
UINT32 TimeDateStamp
Definition: PeImage.h:643
UINT32 OffsetToData
Definition: PeImage.h:772
UINT64 ImageBase
From original file header.
Definition: PeImage.h:789
UINT32 SymbolTableIndex
Symbol table index of function name if Linenumber is 0.
Definition: PeImage.h:537
Resource format.
Definition: PeImage.h:728
UINT32 Unknown
Definition: PeImage.h:675
UINT8 Subsystem
From original optional header.
Definition: PeImage.h:785
UINT32 Signature
"RSDS".
Definition: PeImage.h:674
EFI_IMAGE_NT_HEADERS64 Pe32Plus
Definition: PeImage.h:806
EFI_IMAGE_NT_HEADERS64 * Pe32Plus
Definition: PeImage.h:812
UINT8 SizeOfProlog
Definition: PeImage.h:709
UINT32 RVA
The address of the debug data when loaded, relative to the image base.
Definition: PeImage.h:648
UINT32 SizeOfData
Definition: PeImage.h:647
UINT16 e_ss
Initial (relative) SS value.
Definition: PeImage.h:66
UINT16 Magic
Standard fields.
Definition: PeImage.h:204
Based relocation format.
Definition: PeImage.h:494
UINT16 e_cblp
Bytes on last page of file.
Definition: PeImage.h:60
Import Directory Table.
Definition: PeImage.h:630
UINT32 OffsetToDirectory
Definition: PeImage.h:754
UINT32 VirtualAddress
Virtual address of line number.
Definition: PeImage.h:538
UINT16 e_cs
Initial (relative) CS value.
Definition: PeImage.h:70
UINT32 Reserved
Definition: PeImage.h:775
EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: PeImage.h:246
UINT32 Unknown2
Definition: PeImage.h:662
UINT16 e_sp
Initial SP value.
Definition: PeImage.h:67
UINT32 Signature
"MTOC".
Definition: PeImage.h:690