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