xref: /netbsd-src/sys/external/bsd/gnu-efi/dist/inc/ia64/pe.h (revision b2c829d73acfa2ef1ac1967460ebcec8f439b096)
1 /*	$NetBSD: pe.h,v 1.1.1.1 2014/04/01 16:16:07 jakllsch Exp $	*/
2 
3 /*
4     PE32+ header file
5  */
6 #ifndef _PE_H
7 #define _PE_H
8 
9 #define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
10 #define IMAGE_OS2_SIGNATURE                 0x454E      // NE
11 #define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
12 #define IMAGE_NT_SIGNATURE                  0x00004550  // PE00
13 #define IMAGE_EDOS_SIGNATURE                0x44454550  // PEED
14 
15 /*****************************************************************************
16  * The following stuff comes from winnt.h from the ia64sdk, plus the Plabel for
17  * loading EM executables.
18  *****************************************************************************/
19 //
20 // Intel IA64 specific
21 //
22 
23 #define IMAGE_REL_BASED_IA64_IMM64            9
24 #define IMAGE_REL_BASED_IA64_DIR64            10
25 
26 struct Plabel {
27     UINT64  EntryPoint;
28     UINT64  NewGP;
29 };
30 
31 typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
32     UINT16   e_magic;                     // Magic number
33     UINT16   e_cblp;                      // Bytes on last page of file
34     UINT16   e_cp;                        // Pages in file
35     UINT16   e_crlc;                      // Relocations
36     UINT16   e_cparhdr;                   // Size of header in paragraphs
37     UINT16   e_minalloc;                  // Minimum extra paragraphs needed
38     UINT16   e_maxalloc;                  // Maximum extra paragraphs needed
39     UINT16   e_ss;                        // Initial (relative) SS value
40     UINT16   e_sp;                        // Initial SP value
41     UINT16   e_csum;                      // Checksum
42     UINT16   e_ip;                        // Initial IP value
43     UINT16   e_cs;                        // Initial (relative) CS value
44     UINT16   e_lfarlc;                    // File address of relocation table
45     UINT16   e_ovno;                      // Overlay number
46     UINT16   e_res[4];                    // Reserved words
47     UINT16   e_oemid;                     // OEM identifier (for e_oeminfo)
48     UINT16   e_oeminfo;                   // OEM information; e_oemid specific
49     UINT16   e_res2[10];                  // Reserved words
50     UINT32   e_lfanew;                    // File address of new exe header
51   } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
52 
53 typedef struct _IMAGE_OS2_HEADER {      // OS/2 .EXE header
54     UINT16   ne_magic;                    // Magic number
55     UINT8    ne_ver;                      // Version number
56     UINT8    ne_rev;                      // Revision number
57     UINT16   ne_enttab;                   // Offset of Entry Table
58     UINT16   ne_cbenttab;                 // Number of bytes in Entry Table
59     UINT32   ne_crc;                      // Checksum of whole file
60     UINT16   ne_flags;                    // Flag UINT16
61     UINT16   ne_autodata;                 // Automatic data segment number
62     UINT16   ne_heap;                     // Initial heap allocation
63     UINT16   ne_stack;                    // Initial stack allocation
64     UINT32   ne_csip;                     // Initial CS:IP setting
65     UINT32   ne_sssp;                     // Initial SS:SP setting
66     UINT16   ne_cseg;                     // Count of file segments
67     UINT16   ne_cmod;                     // Entries in Module Reference Table
68     UINT16   ne_cbnrestab;                // Size of non-resident name table
69     UINT16   ne_segtab;                   // Offset of Segment Table
70     UINT16   ne_rsrctab;                  // Offset of Resource Table
71     UINT16   ne_restab;                   // Offset of resident name table
72     UINT16   ne_modtab;                   // Offset of Module Reference Table
73     UINT16   ne_imptab;                   // Offset of Imported Names Table
74     UINT32   ne_nrestab;                  // Offset of Non-resident Names Table
75     UINT16   ne_cmovent;                  // Count of movable entries
76     UINT16   ne_align;                    // Segment alignment shift count
77     UINT16   ne_cres;                     // Count of resource segments
78     UINT8    ne_exetyp;                   // Target Operating system
79     UINT8    ne_flagsothers;              // Other .EXE flags
80     UINT16   ne_pretthunks;               // offset to return thunks
81     UINT16   ne_psegrefbytes;             // offset to segment ref. bytes
82     UINT16   ne_swaparea;                 // Minimum code swap area size
83     UINT16   ne_expver;                   // Expected Windows version number
84   } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
85 
86 //
87 // File header format.
88 //
89 
90 typedef struct _IMAGE_FILE_HEADER {
91     UINT16   Machine;
92     UINT16   NumberOfSections;
93     UINT32   TimeDateStamp;
94     UINT32   PointerToSymbolTable;
95     UINT32   NumberOfSymbols;
96     UINT16   SizeOfOptionalHeader;
97     UINT16   Characteristics;
98 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
99 
100 #define IMAGE_SIZEOF_FILE_HEADER             20
101 
102 #define IMAGE_FILE_RELOCS_STRIPPED           0x0001  // Relocation info stripped from file.
103 #define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002  // File is executable  (i.e. no unresolved externel references).
104 #define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004  // Line nunbers stripped from file.
105 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008  // Local symbols stripped from file.
106 #define IMAGE_FILE_BYTES_REVERSED_LO         0x0080  // Bytes of machine word are reversed.
107 #define IMAGE_FILE_32BIT_MACHINE             0x0100  // 32 bit word machine.
108 #define IMAGE_FILE_DEBUG_STRIPPED            0x0200  // Debugging info stripped from file in .DBG file
109 #define IMAGE_FILE_SYSTEM                    0x1000  // System File.
110 #define IMAGE_FILE_DLL                       0x2000  // File is a DLL.
111 #define IMAGE_FILE_BYTES_REVERSED_HI         0x8000  // Bytes of machine word are reversed.
112 
113 #define IMAGE_FILE_MACHINE_UNKNOWN           0
114 #define IMAGE_FILE_MACHINE_I386              0x14c   // Intel 386.
115 #define IMAGE_FILE_MACHINE_R3000             0x162   // MIPS little-endian, 0540 big-endian
116 #define IMAGE_FILE_MACHINE_R4000             0x166   // MIPS little-endian
117 #define IMAGE_FILE_MACHINE_ALPHA             0x184   // Alpha_AXP
118 #define IMAGE_FILE_MACHINE_ARMTHUMB_MIXED    0x1c2   // Arm/Thumb
119 #define IMAGE_FILE_MACHINE_POWERPC           0x1F0   // IBM PowerPC Little-Endian
120 #define IMAGE_FILE_MACHINE_IA64              0x200   // IA-64
121 #define IMAGE_FILE_MACHINE_TAHOE             0x7cc   // Intel EM machine
122 #define IMAGE_FILE_MACHINE_EBC               0xebc   // EFI Byte Code
123 #define IMAGE_FILE_MACHINE_X64               0x8664  // x86_64
124 //
125 // Directory format.
126 //
127 
128 typedef struct _IMAGE_DATA_DIRECTORY {
129     UINT32   VirtualAddress;
130     UINT32   Size;
131 } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
132 
133 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16
134 
135 
136 typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
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 } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
151 
152 typedef struct _IMAGE_OPTIONAL_HEADER {
153     UINT16      Magic;
154     UINT8       MajorLinkerVersion;
155     UINT8       MinorLinkerVersion;
156     UINT32      SizeOfCode;
157     UINT32      SizeOfInitializedData;
158     UINT32      SizeOfUninitializedData;
159     UINT32      AddressOfEntryPoint;
160     UINT32      BaseOfCode;
161     // UINT32       BaseOfData;
162     UINT64      ImageBase;
163     UINT32      SectionAlignment;
164     UINT32      FileAlignment;
165     UINT16      MajorOperatingSystemVersion;
166     UINT16      MinorOperatingSystemVersion;
167     UINT16      MajorImageVersion;
168     UINT16      MinorImageVersion;
169     UINT16      MajorSubsystemVersion;
170     UINT16      MinorSubsystemVersion;
171     UINT32      Win32VersionValue;
172     UINT32      SizeOfImage;
173     UINT32      SizeOfHeaders;
174     UINT32      CheckSum;
175     UINT16      Subsystem;
176     UINT16      DllCharacteristics;
177     UINT64      SizeOfStackReserve;
178     UINT64      SizeOfStackCommit;
179     UINT64      SizeOfHeapReserve;
180     UINT64      SizeOfHeapCommit;
181     UINT32      LoaderFlags;
182     UINT32      NumberOfRvaAndSizes;
183     IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
184 } IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
185 
186 
187 #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER      56
188 #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER      28
189 #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER      224
190 #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER    244
191 
192 #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
193 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC      0x20b
194 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
195 
196 typedef struct _IMAGE_NT_HEADERS {
197     UINT32 Signature;
198     IMAGE_FILE_HEADER FileHeader;
199     IMAGE_OPTIONAL_HEADER OptionalHeader;
200 } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
201 
202 typedef struct _IMAGE_ROM_HEADERS {
203     IMAGE_FILE_HEADER FileHeader;
204     IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
205 } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
206 
207 #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER)        \
208     ((UINT32)ntheader +                                                  \
209      FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 \
210      ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   \
211     ))
212 
213 
214 // Subsystem Values
215 
216 #define IMAGE_SUBSYSTEM_UNKNOWN              0   // Unknown subsystem.
217 #define IMAGE_SUBSYSTEM_NATIVE               1   // Image doesn't require a subsystem.
218 #define IMAGE_SUBSYSTEM_WINDOWS_GUI          2   // Image runs in the Windows GUI subsystem.
219 #define IMAGE_SUBSYSTEM_WINDOWS_CUI          3   // Image runs in the Windows character subsystem.
220 #define IMAGE_SUBSYSTEM_OS2_CUI              5   // image runs in the OS/2 character subsystem.
221 #define IMAGE_SUBSYSTEM_POSIX_CUI            7   // image run  in the Posix character subsystem.
222 
223 
224 // Directory Entries
225 
226 #define IMAGE_DIRECTORY_ENTRY_EXPORT         0   // Export Directory
227 #define IMAGE_DIRECTORY_ENTRY_IMPORT         1   // Import Directory
228 #define IMAGE_DIRECTORY_ENTRY_RESOURCE       2   // Resource Directory
229 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION      3   // Exception Directory
230 #define IMAGE_DIRECTORY_ENTRY_SECURITY       4   // Security Directory
231 #define IMAGE_DIRECTORY_ENTRY_BASERELOC      5   // Base Relocation Table
232 #define IMAGE_DIRECTORY_ENTRY_DEBUG          6   // Debug Directory
233 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT      7   // Description String
234 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR      8   // Machine Value (MIPS GP)
235 #define IMAGE_DIRECTORY_ENTRY_TLS            9   // TLS Directory
236 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG   10   // Load Configuration Directory
237 
238 //
239 // Section header format.
240 //
241 
242 #define IMAGE_SIZEOF_SHORT_NAME              8
243 
244 typedef struct _IMAGE_SECTION_HEADER {
245     UINT8   Name[IMAGE_SIZEOF_SHORT_NAME];
246     union {
247             UINT32   PhysicalAddress;
248             UINT32   VirtualSize;
249     } Misc;
250     UINT32   VirtualAddress;
251     UINT32   SizeOfRawData;
252     UINT32   PointerToRawData;
253     UINT32   PointerToRelocations;
254     UINT32   PointerToLinenumbers;
255     UINT16   NumberOfRelocations;
256     UINT16   NumberOfLinenumbers;
257     UINT32   Characteristics;
258 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
259 
260 #define IMAGE_SIZEOF_SECTION_HEADER          40
261 
262 #define IMAGE_SCN_TYPE_NO_PAD                0x00000008  // Reserved.
263 
264 #define IMAGE_SCN_CNT_CODE                   0x00000020  // Section contains code.
265 #define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  // Section contains initialized data.
266 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  // Section contains uninitialized data.
267 
268 #define IMAGE_SCN_LNK_OTHER                  0x00000100  // Reserved.
269 #define IMAGE_SCN_LNK_INFO                   0x00000200  // Section contains comments or some other type of information.
270 #define IMAGE_SCN_LNK_REMOVE                 0x00000800  // Section contents will not become part of image.
271 #define IMAGE_SCN_LNK_COMDAT                 0x00001000  // Section contents comdat.
272 
273 #define IMAGE_SCN_ALIGN_1BYTES               0x00100000  //
274 #define IMAGE_SCN_ALIGN_2BYTES               0x00200000  //
275 #define IMAGE_SCN_ALIGN_4BYTES               0x00300000  //
276 #define IMAGE_SCN_ALIGN_8BYTES               0x00400000  //
277 #define IMAGE_SCN_ALIGN_16BYTES              0x00500000  // Default alignment if no others are specified.
278 #define IMAGE_SCN_ALIGN_32BYTES              0x00600000  //
279 #define IMAGE_SCN_ALIGN_64BYTES              0x00700000  //
280 
281 #define IMAGE_SCN_MEM_DISCARDABLE            0x02000000  // Section can be discarded.
282 #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  // Section is not cachable.
283 #define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  // Section is not pageable.
284 #define IMAGE_SCN_MEM_SHARED                 0x10000000  // Section is shareable.
285 #define IMAGE_SCN_MEM_EXECUTE                0x20000000  // Section is executable.
286 #define IMAGE_SCN_MEM_READ                   0x40000000  // Section is readable.
287 #define IMAGE_SCN_MEM_WRITE                  0x80000000  // Section is writeable.
288 
289 //
290 // Symbol format.
291 //
292 
293 
294 #define IMAGE_SIZEOF_SYMBOL                  18
295 
296 //
297 // Section values.
298 //
299 // Symbols have a section number of the section in which they are
300 // defined. Otherwise, section numbers have the following meanings:
301 //
302 
303 #define IMAGE_SYM_UNDEFINED           (UINT16)0           // Symbol is undefined or is common.
304 #define IMAGE_SYM_ABSOLUTE            (UINT16)-1          // Symbol is an absolute value.
305 #define IMAGE_SYM_DEBUG               (UINT16)-2          // Symbol is a special debug item.
306 
307 //
308 // Type (fundamental) values.
309 //
310 
311 #define IMAGE_SYM_TYPE_NULL                  0           // no type.
312 #define IMAGE_SYM_TYPE_VOID                  1           //
313 #define IMAGE_SYM_TYPE_CHAR                  2           // type character.
314 #define IMAGE_SYM_TYPE_SHORT                 3           // type short integer.
315 #define IMAGE_SYM_TYPE_INT                   4           //
316 #define IMAGE_SYM_TYPE_LONG                  5           //
317 #define IMAGE_SYM_TYPE_FLOAT                 6           //
318 #define IMAGE_SYM_TYPE_DOUBLE                7           //
319 #define IMAGE_SYM_TYPE_STRUCT                8           //
320 #define IMAGE_SYM_TYPE_UNION                 9           //
321 #define IMAGE_SYM_TYPE_ENUM                  10          // enumeration.
322 #define IMAGE_SYM_TYPE_MOE                   11          // member of enumeration.
323 #define IMAGE_SYM_TYPE_BYTE                  12          //
324 #define IMAGE_SYM_TYPE_WORD                  13          //
325 #define IMAGE_SYM_TYPE_UINT                  14          //
326 #define IMAGE_SYM_TYPE_DWORD                 15          //
327 
328 //
329 // Type (derived) values.
330 //
331 
332 #define IMAGE_SYM_DTYPE_NULL                 0           // no derived type.
333 #define IMAGE_SYM_DTYPE_POINTER              1           // pointer.
334 #define IMAGE_SYM_DTYPE_FUNCTION             2           // function.
335 #define IMAGE_SYM_DTYPE_ARRAY                3           // array.
336 
337 //
338 // Storage classes.
339 //
340 
341 #define IMAGE_SYM_CLASS_END_OF_FUNCTION      (BYTE )-1
342 #define IMAGE_SYM_CLASS_NULL                 0
343 #define IMAGE_SYM_CLASS_AUTOMATIC            1
344 #define IMAGE_SYM_CLASS_EXTERNAL             2
345 #define IMAGE_SYM_CLASS_STATIC               3
346 #define IMAGE_SYM_CLASS_REGISTER             4
347 #define IMAGE_SYM_CLASS_EXTERNAL_DEF         5
348 #define IMAGE_SYM_CLASS_LABEL                6
349 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL      7
350 #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT     8
351 #define IMAGE_SYM_CLASS_ARGUMENT             9
352 #define IMAGE_SYM_CLASS_STRUCT_TAG           10
353 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION      11
354 #define IMAGE_SYM_CLASS_UNION_TAG            12
355 #define IMAGE_SYM_CLASS_TYPE_DEFINITION      13
356 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC     14
357 #define IMAGE_SYM_CLASS_ENUM_TAG             15
358 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM       16
359 #define IMAGE_SYM_CLASS_REGISTER_PARAM       17
360 #define IMAGE_SYM_CLASS_BIT_FIELD            18
361 #define IMAGE_SYM_CLASS_BLOCK                100
362 #define IMAGE_SYM_CLASS_FUNCTION             101
363 #define IMAGE_SYM_CLASS_END_OF_STRUCT        102
364 #define IMAGE_SYM_CLASS_FILE                 103
365 // new
366 #define IMAGE_SYM_CLASS_SECTION              104
367 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL        105
368 
369 // type packing constants
370 
371 #define N_BTMASK                            017
372 #define N_TMASK                             060
373 #define N_TMASK1                            0300
374 #define N_TMASK2                            0360
375 #define N_BTSHFT                            4
376 #define N_TSHIFT                            2
377 
378 // MACROS
379 
380 //
381 // Communal selection types.
382 //
383 
384 #define IMAGE_COMDAT_SELECT_NODUPLICATES   1
385 #define IMAGE_COMDAT_SELECT_ANY            2
386 #define IMAGE_COMDAT_SELECT_SAME_SIZE      3
387 #define IMAGE_COMDAT_SELECT_EXACT_MATCH    4
388 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE    5
389 
390 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
391 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY   2
392 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS     3
393 
394 
395 //
396 // Relocation format.
397 //
398 
399 typedef struct _IMAGE_RELOCATION {
400     UINT32   VirtualAddress;
401     UINT32   SymbolTableIndex;
402     UINT16   Type;
403 } IMAGE_RELOCATION;
404 
405 #define IMAGE_SIZEOF_RELOCATION              10
406 
407 //
408 // I386 relocation types.
409 //
410 
411 #define IMAGE_REL_I386_ABSOLUTE              0           // Reference is absolute, no relocation is necessary
412 #define IMAGE_REL_I386_DIR16                 01          // Direct 16-bit reference to the symbols virtual address
413 #define IMAGE_REL_I386_REL16                 02          // PC-relative 16-bit reference to the symbols virtual address
414 #define IMAGE_REL_I386_DIR32                 06          // Direct 32-bit reference to the symbols virtual address
415 #define IMAGE_REL_I386_DIR32NB               07          // Direct 32-bit reference to the symbols virtual address, base not included
416 #define IMAGE_REL_I386_SEG12                 011         // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
417 #define IMAGE_REL_I386_SECTION               012
418 #define IMAGE_REL_I386_SECREL                013
419 #define IMAGE_REL_I386_REL32                 024         // PC-relative 32-bit reference to the symbols virtual address
420 
421 //
422 // MIPS relocation types.
423 //
424 
425 #define IMAGE_REL_MIPS_ABSOLUTE              0           // Reference is absolute, no relocation is necessary
426 #define IMAGE_REL_MIPS_REFHALF               01
427 #define IMAGE_REL_MIPS_REFWORD               02
428 #define IMAGE_REL_MIPS_JMPADDR               03
429 #define IMAGE_REL_MIPS_REFHI                 04
430 #define IMAGE_REL_MIPS_REFLO                 05
431 #define IMAGE_REL_MIPS_GPREL                 06
432 #define IMAGE_REL_MIPS_LITERAL               07
433 #define IMAGE_REL_MIPS_SECTION               012
434 #define IMAGE_REL_MIPS_SECREL                013
435 #define IMAGE_REL_MIPS_REFWORDNB             042
436 #define IMAGE_REL_MIPS_PAIR                  045
437 
438 //
439 // Alpha Relocation types.
440 //
441 
442 #define IMAGE_REL_ALPHA_ABSOLUTE             0x0
443 #define IMAGE_REL_ALPHA_REFLONG              0x1
444 #define IMAGE_REL_ALPHA_REFQUAD              0x2
445 #define IMAGE_REL_ALPHA_GPREL32              0x3
446 #define IMAGE_REL_ALPHA_LITERAL              0x4
447 #define IMAGE_REL_ALPHA_LITUSE               0x5
448 #define IMAGE_REL_ALPHA_GPDISP               0x6
449 #define IMAGE_REL_ALPHA_BRADDR               0x7
450 #define IMAGE_REL_ALPHA_HINT                 0x8
451 #define IMAGE_REL_ALPHA_INLINE_REFLONG       0x9
452 #define IMAGE_REL_ALPHA_REFHI                0xA
453 #define IMAGE_REL_ALPHA_REFLO                0xB
454 #define IMAGE_REL_ALPHA_PAIR                 0xC
455 #define IMAGE_REL_ALPHA_MATCH                0xD
456 #define IMAGE_REL_ALPHA_SECTION              0xE
457 #define IMAGE_REL_ALPHA_SECREL               0xF
458 #define IMAGE_REL_ALPHA_REFLONGNB            0x10
459 
460 //
461 // IBM PowerPC relocation types.
462 //
463 
464 #define IMAGE_REL_PPC_ABSOLUTE 0x0000  // NOP
465 #define IMAGE_REL_PPC_ADDR64   0x0001  // 64-bit address
466 #define IMAGE_REL_PPC_ADDR32   0x0002  // 32-bit address
467 #define IMAGE_REL_PPC_ADDR24   0x0003  // 26-bit address, shifted left 2 (branch absolute)
468 #define IMAGE_REL_PPC_ADDR16   0x0004  // 16-bit address
469 #define IMAGE_REL_PPC_ADDR14   0x0005  // 16-bit address, shifted left 2 (load doubleword)
470 #define IMAGE_REL_PPC_REL24    0x0006  // 26-bit PC-relative offset, shifted left 2 (branch relative)
471 #define IMAGE_REL_PPC_REL14    0x0007  // 16-bit PC-relative offset, shifted left 2 (br cond relative)
472 #define IMAGE_REL_PPC_TOCREL16 0x0008  // 16-bit offset from TOC base
473 #define IMAGE_REL_PPC_TOCREL14 0x0009  // 16-bit offset from TOC base, shifted left 2 (load doubleword)
474 
475 #define IMAGE_REL_PPC_ADDR32NB 0x000A  // 32-bit addr w/o image base
476 #define IMAGE_REL_PPC_SECREL   0x000B  // va of containing section (as in an image sectionhdr)
477 #define IMAGE_REL_PPC_SECTION  0x000C  // sectionheader number
478 #define IMAGE_REL_PPC_IFGLUE   0x000D  // substitute TOC restore instruction iff symbol is glue code
479 #define IMAGE_REL_PPC_IMGLUE   0x000E  // symbol is glue code; virtual address is TOC restore instruction
480 
481 #define IMAGE_REL_PPC_TYPEMASK 0x00FF  // mask to isolate above values in IMAGE_RELOCATION.Type
482 
483 // Flag bits in IMAGE_RELOCATION.TYPE
484 
485 #define IMAGE_REL_PPC_NEG      0x0100  // subtract reloc value rather than adding it
486 #define IMAGE_REL_PPC_BRTAKEN  0x0200  // fix branch prediction bit to predict branch taken
487 #define IMAGE_REL_PPC_BRNTAKEN 0x0400  // fix branch prediction bit to predict branch not taken
488 #define IMAGE_REL_PPC_TOCDEFN  0x0800  // toc slot defined in file (or, data in toc)
489 
490 //
491 // Based relocation format.
492 //
493 
494 typedef struct _IMAGE_BASE_RELOCATION {
495     UINT32   VirtualAddress;
496     UINT32   SizeOfBlock;
497 //  UINT16    TypeOffset[1];
498 } IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;
499 
500 #define IMAGE_SIZEOF_BASE_RELOCATION         8
501 
502 //
503 // Based relocation types.
504 //
505 
506 #define IMAGE_REL_BASED_ABSOLUTE              0
507 #define IMAGE_REL_BASED_HIGH                  1
508 #define IMAGE_REL_BASED_LOW                   2
509 #define IMAGE_REL_BASED_HIGHLOW               3
510 #define IMAGE_REL_BASED_HIGHADJ               4
511 #define IMAGE_REL_BASED_MIPS_JMPADDR          5
512 #define IMAGE_REL_BASED_IA64_IMM64            9
513 #define IMAGE_REL_BASED_DIR64                 10
514 
515 //
516 // Line number format.
517 //
518 
519 typedef struct _IMAGE_LINENUMBER {
520     union {
521         UINT32   SymbolTableIndex;               // Symbol table index of function name if Linenumber is 0.
522         UINT32   VirtualAddress;                 // Virtual address of line number.
523     } Type;
524     UINT16    Linenumber;                         // Line number.
525 } IMAGE_LINENUMBER;
526 
527 #define IMAGE_SIZEOF_LINENUMBER              6
528 
529 //
530 // Archive format.
531 //
532 
533 #define IMAGE_ARCHIVE_START_SIZE             8
534 #define IMAGE_ARCHIVE_START                  "!<arch>\n"
535 #define IMAGE_ARCHIVE_END                    "`\n"
536 #define IMAGE_ARCHIVE_PAD                    "\n"
537 #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
538 #define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
539 
540 typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
541     UINT8     Name[16];                          // File member name - `/' terminated.
542     UINT8     Date[12];                          // File member date - decimal.
543     UINT8     UserID[6];                         // File member user id - decimal.
544     UINT8     GroupID[6];                        // File member group id - decimal.
545     UINT8     Mode[8];                           // File member mode - octal.
546     UINT8     Size[10];                          // File member size - decimal.
547     UINT8     EndHeader[2];                      // String to end header.
548 } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
549 
550 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR      60
551 
552 //
553 // DLL support.
554 //
555 
556 //
557 // Export Format
558 //
559 
560 typedef struct _IMAGE_EXPORT_DIRECTORY {
561     UINT32   Characteristics;
562     UINT32   TimeDateStamp;
563     UINT16   MajorVersion;
564     UINT16   MinorVersion;
565     UINT32   Name;
566     UINT32   Base;
567     UINT32   NumberOfFunctions;
568     UINT32   NumberOfNames;
569     UINT32   AddressOfFunctions;
570     UINT32   AddressOfNames;
571     UINT32   AddressOfNameOrdinals;
572 } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
573 
574 //
575 // Import Format
576 //
577 
578 typedef struct _IMAGE_IMPORT_BY_NAME {
579     UINT16    Hint;
580     UINT8     Name[1];
581 } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
582 
583 typedef struct _IMAGE_THUNK_DATA {
584     union {
585         UINT32 Function;
586         UINT32 Ordinal;
587         PIMAGE_IMPORT_BY_NAME AddressOfData;
588     } u1;
589 } IMAGE_THUNK_DATA, *PIMAGE_THUNK_DATA;
590 
591 #define IMAGE_ORDINAL_FLAG 0x80000000
592 #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
593 #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
594 
595 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
596     UINT32   Characteristics;
597     UINT32   TimeDateStamp;
598     UINT32   ForwarderChain;
599     UINT32   Name;
600     PIMAGE_THUNK_DATA FirstThunk;
601 } IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
602 
603 #endif
604