]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Efi/Include/EfiImage.h
1ea3d0a8bf4360d3a5b17b30fc933af649b98e45
[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 #define EFI_IMAGE_MACHINE_ARMTHUMB_MIXED 0x01c2
52
53 //
54 // #define EFI_IMAGE_MACHINE_FCODE 0xfc0d
55 //
56 #define EFI_IMAGE_MACHINE_EBC 0x0EBC
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 // 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 // Directory format.
126 //
127 typedef struct {
128 UINT32 VirtualAddress;
129 UINT32 Size;
130 } EFI_IMAGE_DATA_DIRECTORY;
131
132 #define EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES 16
133
134 typedef struct {
135 UINT16 Magic;
136 UINT8 MajorLinkerVersion;
137 UINT8 MinorLinkerVersion;
138 UINT32 SizeOfCode;
139 UINT32 SizeOfInitializedData;
140 UINT32 SizeOfUninitializedData;
141 UINT32 AddressOfEntryPoint;
142 UINT32 BaseOfCode;
143 UINT32 BaseOfData;
144 UINT32 BaseOfBss;
145 UINT32 GprMask;
146 UINT32 CprMask[4];
147 UINT32 GpValue;
148 } EFI_IMAGE_ROM_OPTIONAL_HEADER;
149
150 #define EFI_IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
151 #define EFI_IMAGE_SIZEOF_ROM_OPTIONAL_HEADER sizeof (EFI_IMAGE_ROM_OPTIONAL_HEADER)
152
153 typedef struct {
154 EFI_IMAGE_FILE_HEADER FileHeader;
155 EFI_IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
156 } EFI_IMAGE_ROM_HEADERS;
157
158 //
159 // ATTENTION!!! EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64
160 // are for use ONLY by tools. All proper EFI code MUST use
161 // EFI_IMAGE_OPTIONAL_HEADER ONLY!!!
162 //
163 #define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
164
165 typedef struct {
166 //
167 // Standard fields.
168 //
169 UINT16 Magic;
170 UINT8 MajorLinkerVersion;
171 UINT8 MinorLinkerVersion;
172 UINT32 SizeOfCode;
173 UINT32 SizeOfInitializedData;
174 UINT32 SizeOfUninitializedData;
175 UINT32 AddressOfEntryPoint;
176 UINT32 BaseOfCode;
177 UINT32 BaseOfData;
178 //
179 // NT additional fields.
180 //
181 UINT32 ImageBase;
182 UINT32 SectionAlignment;
183 UINT32 FileAlignment;
184 UINT16 MajorOperatingSystemVersion;
185 UINT16 MinorOperatingSystemVersion;
186 UINT16 MajorImageVersion;
187 UINT16 MinorImageVersion;
188 UINT16 MajorSubsystemVersion;
189 UINT16 MinorSubsystemVersion;
190 UINT32 Win32VersionValue;
191 UINT32 SizeOfImage;
192 UINT32 SizeOfHeaders;
193 UINT32 CheckSum;
194 UINT16 Subsystem;
195 UINT16 DllCharacteristics;
196 UINT32 SizeOfStackReserve;
197 UINT32 SizeOfStackCommit;
198 UINT32 SizeOfHeapReserve;
199 UINT32 SizeOfHeapCommit;
200 UINT32 LoaderFlags;
201 UINT32 NumberOfRvaAndSizes;
202 EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
203 } EFI_IMAGE_OPTIONAL_HEADER32;
204
205 //
206 // ATTENTION!!! EFI_IMAGE_OPTIONAL_HEADER32 and EFI_IMAGE_OPTIONAL_HEADER64
207 // are for use ONLY by tools. All proper EFI code MUST use
208 // EFI_IMAGE_OPTIONAL_HEADER ONLY!!!
209 //
210 #define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
211
212 typedef struct {
213 //
214 // Standard fields.
215 //
216 UINT16 Magic;
217 UINT8 MajorLinkerVersion;
218 UINT8 MinorLinkerVersion;
219 UINT32 SizeOfCode;
220 UINT32 SizeOfInitializedData;
221 UINT32 SizeOfUninitializedData;
222 UINT32 AddressOfEntryPoint;
223 UINT32 BaseOfCode;
224 //
225 // NT additional fields.
226 //
227 UINT64 ImageBase;
228 UINT32 SectionAlignment;
229 UINT32 FileAlignment;
230 UINT16 MajorOperatingSystemVersion;
231 UINT16 MinorOperatingSystemVersion;
232 UINT16 MajorImageVersion;
233 UINT16 MinorImageVersion;
234 UINT16 MajorSubsystemVersion;
235 UINT16 MinorSubsystemVersion;
236 UINT32 Win32VersionValue;
237 UINT32 SizeOfImage;
238 UINT32 SizeOfHeaders;
239 UINT32 CheckSum;
240 UINT16 Subsystem;
241 UINT16 DllCharacteristics;
242 UINT64 SizeOfStackReserve;
243 UINT64 SizeOfStackCommit;
244 UINT64 SizeOfHeapReserve;
245 UINT64 SizeOfHeapCommit;
246 UINT32 LoaderFlags;
247 UINT32 NumberOfRvaAndSizes;
248 EFI_IMAGE_DATA_DIRECTORY DataDirectory[EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES];
249 } EFI_IMAGE_OPTIONAL_HEADER64;
250
251 //
252 // ATTENTION!!! EFI_IMAGE_NT_HEADERS32 and EFI_IMAGE_HEADERS64 are for use ONLY
253 // by tools. All proper EFI code MUST use EFI_IMAGE_NT_HEADERS ONLY!!!
254 //
255 typedef struct {
256 UINT32 Signature;
257 EFI_IMAGE_FILE_HEADER FileHeader;
258 EFI_IMAGE_OPTIONAL_HEADER32 OptionalHeader;
259 } EFI_IMAGE_NT_HEADERS32;
260
261 #define EFI_IMAGE_SIZEOF_NT_OPTIONAL32_HEADER sizeof (EFI_IMAGE_NT_HEADERS32)
262
263 typedef struct {
264 UINT32 Signature;
265 EFI_IMAGE_FILE_HEADER FileHeader;
266 EFI_IMAGE_OPTIONAL_HEADER64 OptionalHeader;
267 } EFI_IMAGE_NT_HEADERS64;
268
269 #define EFI_IMAGE_SIZEOF_NT_OPTIONAL64_HEADER sizeof (EFI_IMAGE_NT_HEADERS64)
270
271 //
272 // Include processor specific definition of EFI_IMAGE_OPTIONAL_HEADER so the
273 // type name EFI_IMAGE_OPTIONAL_HEADER is appropriate to the build. Same for
274 // EFI_IMAGE_NT_HEADERS. These definitions MUST be used by ALL EFI code.
275 //
276 #include "EfiPeOptionalHeader.h"
277
278 #define EFI_IMAGE_FIRST_SECTION(ntheader) \
279 ( \
280 (EFI_IMAGE_SECTION_HEADER *) \
281 ( \
282 (UINT32) ntheader + \
283 FIELD_OFFSET (EFI_IMAGE_NT_HEADERS, OptionalHeader) + \
284 ((EFI_IMAGE_NT_HEADERS *) (ntheader))->FileHeader.SizeOfOptionalHeader \
285 ) \
286 )
287
288 //
289 // Subsystem Values
290 //
291 #define EFI_IMAGE_SUBSYSTEM_UNKNOWN 0
292 #define EFI_IMAGE_SUBSYSTEM_NATIVE 1
293 #define EFI_IMAGE_SUBSYSTEM_WINDOWS_GUI 2
294 #define EFI_IMAGE_SUBSYSTEM_WINDOWS_CUI 3.
295 #define EFI_IMAGE_SUBSYSTEM_OS2_CUI 5
296 #define EFI_IMAGE_SUBSYSTEM_POSIX_CUI 7
297
298 //
299 // Directory Entries
300 //
301 #define EFI_IMAGE_DIRECTORY_ENTRY_EXPORT 0
302 #define EFI_IMAGE_DIRECTORY_ENTRY_IMPORT 1
303 #define EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE 2
304 #define EFI_IMAGE_DIRECTORY_ENTRY_EXCEPTION 3
305 #define EFI_IMAGE_DIRECTORY_ENTRY_SECURITY 4
306 #define EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC 5
307 #define EFI_IMAGE_DIRECTORY_ENTRY_DEBUG 6
308 #define EFI_IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7
309 #define EFI_IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8
310 #define EFI_IMAGE_DIRECTORY_ENTRY_TLS 9
311 #define EFI_IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10
312
313 //
314 // Section header format.
315 //
316 #define EFI_IMAGE_SIZEOF_SHORT_NAME 8
317
318 typedef struct {
319 UINT8 Name[EFI_IMAGE_SIZEOF_SHORT_NAME];
320 union {
321 UINT32 PhysicalAddress;
322 UINT32 VirtualSize;
323 } Misc;
324 UINT32 VirtualAddress;
325 UINT32 SizeOfRawData;
326 UINT32 PointerToRawData;
327 UINT32 PointerToRelocations;
328 UINT32 PointerToLinenumbers;
329 UINT16 NumberOfRelocations;
330 UINT16 NumberOfLinenumbers;
331 UINT32 Characteristics;
332 } EFI_IMAGE_SECTION_HEADER;
333
334 #define EFI_IMAGE_SIZEOF_SECTION_HEADER 40
335
336 #define EFI_IMAGE_SCN_TYPE_NO_PAD 0x00000008 // Reserved.
337 #define EFI_IMAGE_SCN_CNT_CODE 0x00000020
338 #define EFI_IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
339 #define EFI_IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
340
341 #define EFI_IMAGE_SCN_LNK_OTHER 0x00000100 // Reserved.
342 #define EFI_IMAGE_SCN_LNK_INFO 0x00000200 // Section contains comments or some other type of information.
343 #define EFI_IMAGE_SCN_LNK_REMOVE 0x00000800 // Section contents will not become part of image.
344 #define EFI_IMAGE_SCN_LNK_COMDAT 0x00001000
345
346 #define EFI_IMAGE_SCN_ALIGN_1BYTES 0x00100000
347 #define EFI_IMAGE_SCN_ALIGN_2BYTES 0x00200000
348 #define EFI_IMAGE_SCN_ALIGN_4BYTES 0x00300000
349 #define EFI_IMAGE_SCN_ALIGN_8BYTES 0x00400000
350 #define EFI_IMAGE_SCN_ALIGN_16BYTES 0x00500000
351 #define EFI_IMAGE_SCN_ALIGN_32BYTES 0x00600000
352 #define EFI_IMAGE_SCN_ALIGN_64BYTES 0x00700000
353
354 #define EFI_IMAGE_SCN_MEM_DISCARDABLE 0x02000000
355 #define EFI_IMAGE_SCN_MEM_NOT_CACHED 0x04000000
356 #define EFI_IMAGE_SCN_MEM_NOT_PAGED 0x08000000
357 #define EFI_IMAGE_SCN_MEM_SHARED 0x10000000
358 #define EFI_IMAGE_SCN_MEM_EXECUTE 0x20000000
359 #define EFI_IMAGE_SCN_MEM_READ 0x40000000
360 #define EFI_IMAGE_SCN_MEM_WRITE 0x80000000
361
362 //
363 // Symbol format.
364 //
365 #define EFI_IMAGE_SIZEOF_SYMBOL 18
366
367 //
368 // Section values.
369 //
370 // Symbols have a section number of the section in which they are
371 // defined. Otherwise, section numbers have the following meanings:
372 //
373 #define EFI_IMAGE_SYM_UNDEFINED (UINT16) 0 // Symbol is undefined or is common.
374 #define EFI_IMAGE_SYM_ABSOLUTE (UINT16) -1 // Symbol is an absolute value.
375 #define EFI_IMAGE_SYM_DEBUG (UINT16) -2 // Symbol is a special debug item.
376 //
377 // Type (fundamental) values.
378 //
379 #define EFI_IMAGE_SYM_TYPE_NULL 0 // no type.
380 #define EFI_IMAGE_SYM_TYPE_VOID 1 //
381 #define EFI_IMAGE_SYM_TYPE_CHAR 2 // type character.
382 #define EFI_IMAGE_SYM_TYPE_SHORT 3 // type short integer.
383 #define EFI_IMAGE_SYM_TYPE_INT 4
384 #define EFI_IMAGE_SYM_TYPE_LONG 5
385 #define EFI_IMAGE_SYM_TYPE_FLOAT 6
386 #define EFI_IMAGE_SYM_TYPE_DOUBLE 7
387 #define EFI_IMAGE_SYM_TYPE_STRUCT 8
388 #define EFI_IMAGE_SYM_TYPE_UNION 9
389 #define EFI_IMAGE_SYM_TYPE_ENUM 10 // enumeration.
390 #define EFI_IMAGE_SYM_TYPE_MOE 11 // member of enumeration.
391 #define EFI_IMAGE_SYM_TYPE_BYTE 12
392 #define EFI_IMAGE_SYM_TYPE_WORD 13
393 #define EFI_IMAGE_SYM_TYPE_UINT 14
394 #define EFI_IMAGE_SYM_TYPE_DWORD 15
395
396 //
397 // Type (derived) values.
398 //
399 #define EFI_IMAGE_SYM_DTYPE_NULL 0 // no derived type.
400 #define EFI_IMAGE_SYM_DTYPE_POINTER 1
401 #define EFI_IMAGE_SYM_DTYPE_FUNCTION 2
402 #define EFI_IMAGE_SYM_DTYPE_ARRAY 3
403
404 //
405 // Storage classes.
406 //
407 #define EFI_IMAGE_SYM_CLASS_END_OF_FUNCTION (UINT8) -1
408 #define EFI_IMAGE_SYM_CLASS_NULL 0
409 #define EFI_IMAGE_SYM_CLASS_AUTOMATIC 1
410 #define EFI_IMAGE_SYM_CLASS_EXTERNAL 2
411 #define EFI_IMAGE_SYM_CLASS_STATIC 3
412 #define EFI_IMAGE_SYM_CLASS_REGISTER 4
413 #define EFI_IMAGE_SYM_CLASS_EXTERNAL_DEF 5
414 #define EFI_IMAGE_SYM_CLASS_LABEL 6
415 #define EFI_IMAGE_SYM_CLASS_UNDEFINED_LABEL 7
416 #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_STRUCT 8
417 #define EFI_IMAGE_SYM_CLASS_ARGUMENT 9
418 #define EFI_IMAGE_SYM_CLASS_STRUCT_TAG 10
419 #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_UNION 11
420 #define EFI_IMAGE_SYM_CLASS_UNION_TAG 12
421 #define EFI_IMAGE_SYM_CLASS_TYPE_DEFINITION 13
422 #define EFI_IMAGE_SYM_CLASS_UNDEFINED_STATIC 14
423 #define EFI_IMAGE_SYM_CLASS_ENUM_TAG 15
424 #define EFI_IMAGE_SYM_CLASS_MEMBER_OF_ENUM 16
425 #define EFI_IMAGE_SYM_CLASS_REGISTER_PARAM 17
426 #define EFI_IMAGE_SYM_CLASS_BIT_FIELD 18
427 #define EFI_IMAGE_SYM_CLASS_BLOCK 100
428 #define EFI_IMAGE_SYM_CLASS_FUNCTION 101
429 #define EFI_IMAGE_SYM_CLASS_END_OF_STRUCT 102
430 #define EFI_IMAGE_SYM_CLASS_FILE 103
431 #define EFI_IMAGE_SYM_CLASS_SECTION 104
432 #define EFI_IMAGE_SYM_CLASS_WEAK_EXTERNAL 105
433
434 //
435 // type packing constants
436 //
437 #define EFI_IMAGE_N_BTMASK 017
438 #define EFI_IMAGE_N_TMASK 060
439 #define EFI_IMAGE_N_TMASK1 0300
440 #define EFI_IMAGE_N_TMASK2 0360
441 #define EFI_IMAGE_N_BTSHFT 4
442 #define EFI_IMAGE_N_TSHIFT 2
443
444 //
445 // Communal selection types.
446 //
447 #define EFI_IMAGE_COMDAT_SELECT_NODUPLICATES 1
448 #define EFI_IMAGE_COMDAT_SELECT_ANY 2
449 #define EFI_IMAGE_COMDAT_SELECT_SAME_SIZE 3
450 #define EFI_IMAGE_COMDAT_SELECT_EXACT_MATCH 4
451 #define EFI_IMAGE_COMDAT_SELECT_ASSOCIATIVE 5
452
453 #define EFI_IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
454 #define EFI_IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
455 #define EFI_IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
456
457 //
458 // Relocation format.
459 //
460 typedef struct {
461 UINT32 VirtualAddress;
462 UINT32 SymbolTableIndex;
463 UINT16 Type;
464 } EFI_IMAGE_RELOCATION;
465
466 #define EFI_IMAGE_SIZEOF_RELOCATION 10
467
468 //
469 // I386 relocation types.
470 //
471 #define EFI_IMAGE_REL_I386_ABSOLUTE 0 // Reference is absolute, no relocation is necessary
472 #define EFI_IMAGE_REL_I386_DIR16 01 // Direct 16-bit reference to the symbols virtual address
473 #define EFI_IMAGE_REL_I386_REL16 02 // PC-relative 16-bit reference to the symbols virtual address
474 #define EFI_IMAGE_REL_I386_DIR32 06 // Direct 32-bit reference to the symbols virtual address
475 #define EFI_IMAGE_REL_I386_DIR32NB 07 // Direct 32-bit reference to the symbols virtual address, base not included
476 #define EFI_IMAGE_REL_I386_SEG12 011 // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
477 #define EFI_IMAGE_REL_I386_SECTION 012
478 #define EFI_IMAGE_REL_I386_SECREL 013
479 #define EFI_IMAGE_REL_I386_REL32 024 // PC-relative 32-bit reference to the symbols virtual address
480 //
481 // Based relocation format.
482 //
483 typedef struct {
484 UINT32 VirtualAddress;
485 UINT32 SizeOfBlock;
486 } EFI_IMAGE_BASE_RELOCATION;
487
488 #define EFI_IMAGE_SIZEOF_BASE_RELOCATION 8
489
490 //
491 // Based relocation types.
492 //
493 #define EFI_IMAGE_REL_BASED_ABSOLUTE 0
494 #define EFI_IMAGE_REL_BASED_HIGH 1
495 #define EFI_IMAGE_REL_BASED_LOW 2
496 #define EFI_IMAGE_REL_BASED_HIGHLOW 3
497 #define EFI_IMAGE_REL_BASED_HIGHADJ 4
498 #define EFI_IMAGE_REL_BASED_MIPS_JMPADDR 5
499 #define EFI_IMAGE_REL_BASED_IA64_IMM64 9
500 #define EFI_IMAGE_REL_BASED_DIR64 10
501
502 //
503 // Line number format.
504 //
505 typedef struct {
506 union {
507 UINT32 SymbolTableIndex; // Symbol table index of function name if Linenumber is 0.
508 UINT32 VirtualAddress; // Virtual address of line number.
509 } Type;
510 UINT16 Linenumber; // Line number.
511 } EFI_IMAGE_LINENUMBER;
512
513 #define EFI_IMAGE_SIZEOF_LINENUMBER 6
514
515 //
516 // Archive format.
517 //
518 #define EFI_IMAGE_ARCHIVE_START_SIZE 8
519 #define EFI_IMAGE_ARCHIVE_START "!<arch>\n"
520 #define EFI_IMAGE_ARCHIVE_END "`\n"
521 #define EFI_IMAGE_ARCHIVE_PAD "\n"
522 #define EFI_IMAGE_ARCHIVE_LINKER_MEMBER "/ "
523 #define EFI_IMAGE_ARCHIVE_LONGNAMES_MEMBER "// "
524
525 typedef struct {
526 UINT8 Name[16]; // File member name - `/' terminated.
527 UINT8 Date[12]; // File member date - decimal.
528 UINT8 UserID[6]; // File member user id - decimal.
529 UINT8 GroupID[6]; // File member group id - decimal.
530 UINT8 Mode[8]; // File member mode - octal.
531 UINT8 Size[10]; // File member size - decimal.
532 UINT8 EndHeader[2]; // String to end header.
533 } EFI_IMAGE_ARCHIVE_MEMBER_HEADER;
534
535 #define EFI_IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
536
537 //
538 // DLL support.
539 //
540 //
541 // Export Format
542 //
543 typedef struct {
544 UINT32 Characteristics;
545 UINT32 TimeDateStamp;
546 UINT16 MajorVersion;
547 UINT16 MinorVersion;
548 UINT32 Name;
549 UINT32 Base;
550 UINT32 NumberOfFunctions;
551 UINT32 NumberOfNames;
552 UINT32 AddressOfFunctions;
553 UINT32 AddressOfNames;
554 UINT32 AddressOfNameOrdinals;
555 } EFI_IMAGE_EXPORT_DIRECTORY;
556
557 //
558 // Import Format
559 //
560 typedef struct {
561 UINT16 Hint;
562 UINT8 Name[1];
563 } EFI_IMAGE_IMPORT_BY_NAME;
564
565 typedef struct {
566 union {
567 UINT32 Function;
568 UINT32 Ordinal;
569 EFI_IMAGE_IMPORT_BY_NAME *AddressOfData;
570 } u1;
571 } EFI_IMAGE_THUNK_DATA;
572
573 #define EFI_IMAGE_ORDINAL_FLAG 0x80000000
574 #define EFI_IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & EFI_IMAGE_ORDINAL_FLAG) != 0)
575 #define EFI_IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
576
577 typedef struct {
578 UINT32 Characteristics;
579 UINT32 TimeDateStamp;
580 UINT32 ForwarderChain;
581 UINT32 Name;
582 EFI_IMAGE_THUNK_DATA *FirstThunk;
583 } EFI_IMAGE_IMPORT_DESCRIPTOR;
584
585 //
586 // Debug Format
587 //
588 #define EFI_IMAGE_DEBUG_TYPE_CODEVIEW 2
589
590 typedef struct {
591 UINT32 Characteristics;
592 UINT32 TimeDateStamp;
593 UINT16 MajorVersion;
594 UINT16 MinorVersion;
595 UINT32 Type;
596 UINT32 SizeOfData;
597 UINT32 RVA;
598 UINT32 FileOffset;
599 } EFI_IMAGE_DEBUG_DIRECTORY_ENTRY;
600
601 #define CODEVIEW_SIGNATURE_NB10 0x3031424E // "NB10"
602 typedef struct {
603 UINT32 Signature; // "NB10"
604 UINT32 Unknown;
605 UINT32 Unknown2;
606 UINT32 Unknown3;
607 //
608 // Filename of .PDB goes here
609 //
610 } EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;
611
612 #define CODEVIEW_SIGNATURE_RSDS 0x53445352 // "RSDS"
613 typedef struct {
614 UINT32 Signature; // "RSDS"
615 UINT32 Unknown;
616 UINT32 Unknown2;
617 UINT32 Unknown3;
618 UINT32 Unknown4;
619 UINT32 Unknown5;
620 //
621 // Filename of .PDB goes here
622 //
623 } EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;
624
625 //
626 // Header format for TE images
627 //
628 typedef struct {
629 UINT16 Signature; // signature for TE format = "VZ"
630 UINT16 Machine; // from the original file header
631 UINT8 NumberOfSections; // from the original file header
632 UINT8 Subsystem; // from original optional header
633 UINT16 StrippedSize; // how many bytes we removed from the header
634 UINT32 AddressOfEntryPoint; // offset to entry point -- from original optional header
635 UINT32 BaseOfCode; // from original image -- required for ITP debug
636 UINT64 ImageBase; // from original file header
637 EFI_IMAGE_DATA_DIRECTORY DataDirectory[2]; // only base relocation and debug directory
638 } EFI_TE_IMAGE_HEADER;
639
640 #define EFI_TE_IMAGE_HEADER_SIGNATURE 0x5A56 // "VZ"
641 //
642 // Data directory indexes in our TE image header
643 //
644 #define EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC 0
645 #define EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG 1
646
647 //
648 // Union of PE32, PE32+, and TE headers
649 //
650 typedef union {
651 EFI_IMAGE_NT_HEADERS32 Pe32;
652 EFI_IMAGE_NT_HEADERS64 Pe32Plus;
653 EFI_TE_IMAGE_HEADER Te;
654 } EFI_IMAGE_OPTIONAL_HEADER_UNION;
655
656 typedef union {
657 EFI_IMAGE_NT_HEADERS32 *Pe32;
658 EFI_IMAGE_NT_HEADERS64 *Pe32Plus;
659 EFI_TE_IMAGE_HEADER *Te;
660 EFI_IMAGE_OPTIONAL_HEADER_UNION *Union;
661 } EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION;
662
663 #endif