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