VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Include/IndustryStandard/PeImage.h@ 101291

Last change on this file since 101291 was 101291, checked in by vboxsync, 14 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette