VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/tools/include/IndustryStandard/PeImage.h@ 23119

Last change on this file since 23119 was 23119, checked in by vboxsync, 15 years ago

re-export EFI

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