1191983Sweongyo/* $FreeBSD: releng/10.2/sys/boot/efi/include/i386/pe.h 163898 2006-11-02 02:42:48Z marcel $ */
2191983Sweongyo/*
3191983Sweongyo    PE32+ header file
4191983Sweongyo */
5191983Sweongyo#ifndef _PE_H
6191983Sweongyo#define _PE_H
7191983Sweongyo
8191983Sweongyo#define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
9191983Sweongyo#define IMAGE_OS2_SIGNATURE                 0x454E      // NE
10191983Sweongyo#define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
11191983Sweongyo#define IMAGE_NT_SIGNATURE                  0x00004550  // PE00
12191983Sweongyo#define IMAGE_EDOS_SIGNATURE                0x44454550  // PEED
13191983Sweongyo
14191983Sweongyo
15191983Sweongyotypedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
16191983Sweongyo    UINT16   e_magic;                     // Magic number
17191983Sweongyo    UINT16   e_cblp;                      // Bytes on last page of file
18191983Sweongyo    UINT16   e_cp;                        // Pages in file
19191983Sweongyo    UINT16   e_crlc;                      // Relocations
20191983Sweongyo    UINT16   e_cparhdr;                   // Size of header in paragraphs
21191983Sweongyo    UINT16   e_minalloc;                  // Minimum extra paragraphs needed
22191983Sweongyo    UINT16   e_maxalloc;                  // Maximum extra paragraphs needed
23191983Sweongyo    UINT16   e_ss;                        // Initial (relative) SS value
24191983Sweongyo    UINT16   e_sp;                        // Initial SP value
25191983Sweongyo    UINT16   e_csum;                      // Checksum
26191983Sweongyo    UINT16   e_ip;                        // Initial IP value
27191983Sweongyo    UINT16   e_cs;                        // Initial (relative) CS value
28191983Sweongyo    UINT16   e_lfarlc;                    // File address of relocation table
29191983Sweongyo    UINT16   e_ovno;                      // Overlay number
30191983Sweongyo    UINT16   e_res[4];                    // Reserved words
31191983Sweongyo    UINT16   e_oemid;                     // OEM identifier (for e_oeminfo)
32191983Sweongyo    UINT16   e_oeminfo;                   // OEM information; e_oemid specific
33191983Sweongyo    UINT16   e_res2[10];                  // Reserved words
34257176Sglebius    UINT32   e_lfanew;                    // File address of new exe header
35191983Sweongyo  } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
36191983Sweongyo
37191983Sweongyotypedef struct _IMAGE_OS2_HEADER {      // OS/2 .EXE header
38191983Sweongyo    UINT16   ne_magic;                    // Magic number
39191983Sweongyo    UINT8    ne_ver;                      // Version number
40191983Sweongyo    UINT8    ne_rev;                      // Revision number
41191983Sweongyo    UINT16   ne_enttab;                   // Offset of Entry Table
42191983Sweongyo    UINT16   ne_cbenttab;                 // Number of bytes in Entry Table
43191983Sweongyo    UINT32   ne_crc;                      // Checksum of whole file
44191983Sweongyo    UINT16   ne_flags;                    // Flag UINT16
45191983Sweongyo    UINT16   ne_autodata;                 // Automatic data segment number
46191983Sweongyo    UINT16   ne_heap;                     // Initial heap allocation
47191983Sweongyo    UINT16   ne_stack;                    // Initial stack allocation
48191983Sweongyo    UINT32   ne_csip;                     // Initial CS:IP setting
49191983Sweongyo    UINT32   ne_sssp;                     // Initial SS:SP setting
50191983Sweongyo    UINT16   ne_cseg;                     // Count of file segments
51191983Sweongyo    UINT16   ne_cmod;                     // Entries in Module Reference Table
52194677Sthompsa    UINT16   ne_cbnrestab;                // Size of non-resident name table
53191983Sweongyo    UINT16   ne_segtab;                   // Offset of Segment Table
54191983Sweongyo    UINT16   ne_rsrctab;                  // Offset of Resource Table
55191983Sweongyo    UINT16   ne_restab;                   // Offset of resident name table
56191983Sweongyo    UINT16   ne_modtab;                   // Offset of Module Reference Table
57191983Sweongyo    UINT16   ne_imptab;                   // Offset of Imported Names Table
58191983Sweongyo    UINT32   ne_nrestab;                  // Offset of Non-resident Names Table
59191983Sweongyo    UINT16   ne_cmovent;                  // Count of movable entries
60191983Sweongyo    UINT16   ne_align;                    // Segment alignment shift count
61191983Sweongyo    UINT16   ne_cres;                     // Count of resource segments
62191983Sweongyo    UINT8    ne_exetyp;                   // Target Operating system
63191983Sweongyo    UINT8    ne_flagsothers;              // Other .EXE flags
64191983Sweongyo    UINT16   ne_pretthunks;               // offset to return thunks
65191983Sweongyo    UINT16   ne_psegrefbytes;             // offset to segment ref. bytes
66191983Sweongyo    UINT16   ne_swaparea;                 // Minimum code swap area size
67191983Sweongyo    UINT16   ne_expver;                   // Expected Windows version number
68191983Sweongyo  } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
69191983Sweongyo
70191983Sweongyo//
71191983Sweongyo// File header format.
72191983Sweongyo//
73191983Sweongyo
74227309Sedtypedef struct _IMAGE_FILE_HEADER {
75191983Sweongyo    UINT16   Machine;
76191983Sweongyo    UINT16   NumberOfSections;
77191983Sweongyo    UINT32   TimeDateStamp;
78191983Sweongyo    UINT32   PointerToSymbolTable;
79267992Shselasky    UINT32   NumberOfSymbols;
80191983Sweongyo    UINT16   SizeOfOptionalHeader;
81191983Sweongyo    UINT16   Characteristics;
82191983Sweongyo} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
83191983Sweongyo
84191983Sweongyo#define IMAGE_SIZEOF_FILE_HEADER             20
85191983Sweongyo
86191983Sweongyo#define IMAGE_FILE_RELOCS_STRIPPED           0x0001  // Relocation info stripped from file.
87191983Sweongyo#define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002  // File is executable  (i.e. no unresolved externel references).
88191983Sweongyo#define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004  // Line nunbers stripped from file.
89191983Sweongyo#define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008  // Local symbols stripped from file.
90191983Sweongyo#define IMAGE_FILE_BYTES_REVERSED_LO         0x0080  // Bytes of machine word are reversed.
91191983Sweongyo#define IMAGE_FILE_32BIT_MACHINE             0x0100  // 32 bit word machine.
92191983Sweongyo#define IMAGE_FILE_DEBUG_STRIPPED            0x0200  // Debugging info stripped from file in .DBG file
93191983Sweongyo#define IMAGE_FILE_SYSTEM                    0x1000  // System File.
94191983Sweongyo#define IMAGE_FILE_DLL                       0x2000  // File is a DLL.
95191983Sweongyo#define IMAGE_FILE_BYTES_REVERSED_HI         0x8000  // Bytes of machine word are reversed.
96191983Sweongyo
97191983Sweongyo#define IMAGE_FILE_MACHINE_UNKNOWN           0
98191983Sweongyo#define IMAGE_FILE_MACHINE_I386              0x14c   // Intel 386.
99191983Sweongyo#define IMAGE_FILE_MACHINE_R3000             0x162   // MIPS little-endian, 0540 big-endian
100191983Sweongyo#define IMAGE_FILE_MACHINE_R4000             0x166   // MIPS little-endian
101191983Sweongyo#define IMAGE_FILE_MACHINE_ALPHA             0x184   // Alpha_AXP
102191983Sweongyo#define IMAGE_FILE_MACHINE_POWERPC           0x1F0   // IBM PowerPC Little-Endian
103191983Sweongyo#define IMAGE_FILE_MACHINE_TAHOE             0x7cc   // Intel EM machine
104191983Sweongyo//
105191983Sweongyo// Directory format.
106191983Sweongyo//
107191983Sweongyo
108191983Sweongyotypedef struct _IMAGE_DATA_DIRECTORY {
109191983Sweongyo    UINT32   VirtualAddress;
110191983Sweongyo    UINT32   Size;
111191983Sweongyo} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
112191983Sweongyo
113191983Sweongyo#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16
114191983Sweongyo
115191983Sweongyo//
116191983Sweongyo// Optional header format.
117191983Sweongyo//
118191983Sweongyo
119192984Sthompsatypedef struct _IMAGE_OPTIONAL_HEADER {
120191983Sweongyo    //
121191983Sweongyo    // Standard fields.
122192984Sthompsa    //
123191983Sweongyo
124191983Sweongyo    UINT16    Magic;
125191983Sweongyo    UINT8     MajorLinkerVersion;
126191983Sweongyo    UINT8     MinorLinkerVersion;
127191983Sweongyo    UINT32    SizeOfCode;
128191983Sweongyo    UINT32    SizeOfInitializedData;
129191983Sweongyo    UINT32    SizeOfUninitializedData;
130191983Sweongyo    UINT32    AddressOfEntryPoint;
131191983Sweongyo    UINT32    BaseOfCode;
132191983Sweongyo    UINT32    BaseOfData;
133191983Sweongyo
134191983Sweongyo    //
135191983Sweongyo    // NT additional fields.
136191983Sweongyo    //
137191983Sweongyo
138191983Sweongyo    UINT32   ImageBase;
139191983Sweongyo    UINT32   SectionAlignment;
140191983Sweongyo    UINT32   FileAlignment;
141228621Sbschmidt    UINT16   MajorOperatingSystemVersion;
142228621Sbschmidt    UINT16   MinorOperatingSystemVersion;
143228621Sbschmidt    UINT16   MajorImageVersion;
144191983Sweongyo    UINT16   MinorImageVersion;
145191983Sweongyo    UINT16   MajorSubsystemVersion;
146191983Sweongyo    UINT16   MinorSubsystemVersion;
147191983Sweongyo    UINT32   Reserved1;
148191983Sweongyo    UINT32   SizeOfImage;
149191983Sweongyo    UINT32   SizeOfHeaders;
150191983Sweongyo    UINT32   CheckSum;
151191983Sweongyo    UINT16   Subsystem;
152191983Sweongyo    UINT16   DllCharacteristics;
153191983Sweongyo    UINT32   SizeOfStackReserve;
154191983Sweongyo    UINT32   SizeOfStackCommit;
155191983Sweongyo    UINT32   SizeOfHeapReserve;
156191983Sweongyo    UINT32   SizeOfHeapCommit;
157191983Sweongyo    UINT32   LoaderFlags;
158191983Sweongyo    UINT32   NumberOfRvaAndSizes;
159191983Sweongyo    IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
160191983Sweongyo} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
161191983Sweongyo
162191983Sweongyotypedef struct _IMAGE_ROM_OPTIONAL_HEADER {
163191983Sweongyo    UINT16  Magic;
164191983Sweongyo    UINT8   MajorLinkerVersion;
165191983Sweongyo    UINT8   MinorLinkerVersion;
166191983Sweongyo    UINT32  SizeOfCode;
167191983Sweongyo    UINT32  SizeOfInitializedData;
168191983Sweongyo    UINT32  SizeOfUninitializedData;
169191983Sweongyo    UINT32  AddressOfEntryPoint;
170191983Sweongyo    UINT32  BaseOfCode;
171191983Sweongyo    UINT32  BaseOfData;
172191983Sweongyo    UINT32  BaseOfBss;
173223486Shselasky    UINT32  GprMask;
174191983Sweongyo    UINT32  CprMask[4];
175191983Sweongyo    UINT32  GpValue;
176191983Sweongyo} IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
177191983Sweongyo
178191983Sweongyo#define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER      56
179191983Sweongyo#define IMAGE_SIZEOF_STD_OPTIONAL_HEADER      28
180191983Sweongyo#define IMAGE_SIZEOF_NT_OPTIONAL_HEADER      224
181191983Sweongyo
182191983Sweongyo#define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
183191983Sweongyo#define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
184191983Sweongyo
185275646Smptypedef struct _IMAGE_NT_HEADERS {
186191983Sweongyo    UINT32 Signature;
187191983Sweongyo    IMAGE_FILE_HEADER FileHeader;
188209447Sthompsa    IMAGE_OPTIONAL_HEADER OptionalHeader;
189191983Sweongyo} IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
190191983Sweongyo
191191983Sweongyotypedef struct _IMAGE_ROM_HEADERS {
192191983Sweongyo    IMAGE_FILE_HEADER FileHeader;
193191983Sweongyo    IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
194191983Sweongyo} IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
195191983Sweongyo
196193045Sthompsa#define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER)        \
197193045Sthompsa    ((UINT32)ntheader +                                                  \
198191983Sweongyo     FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 \
199192984Sthompsa     ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   \
200191983Sweongyo    ))
201191983Sweongyo
202191983Sweongyo
203191983Sweongyo// Subsystem Values
204244503Shselasky
205191983Sweongyo#define IMAGE_SUBSYSTEM_UNKNOWN              0   // Unknown subsystem.
206191983Sweongyo#define IMAGE_SUBSYSTEM_NATIVE               1   // Image doesn't require a subsystem.
207191983Sweongyo#define IMAGE_SUBSYSTEM_WINDOWS_GUI          2   // Image runs in the Windows GUI subsystem.
208191983Sweongyo#define IMAGE_SUBSYSTEM_WINDOWS_CUI          3   // Image runs in the Windows character subsystem.
209191983Sweongyo#define IMAGE_SUBSYSTEM_OS2_CUI              5   // image runs in the OS/2 character subsystem.
210191983Sweongyo#define IMAGE_SUBSYSTEM_POSIX_CUI            7   // image run  in the Posix character subsystem.
211191983Sweongyo
212191983Sweongyo
213191983Sweongyo// Directory Entries
214191983Sweongyo
215191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_EXPORT         0   // Export Directory
216244503Shselasky#define IMAGE_DIRECTORY_ENTRY_IMPORT         1   // Import Directory
217191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_RESOURCE       2   // Resource Directory
218191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_EXCEPTION      3   // Exception Directory
219191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_SECURITY       4   // Security Directory
220191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_BASERELOC      5   // Base Relocation Table
221191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_DEBUG          6   // Debug Directory
222191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT      7   // Description String
223191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR      8   // Machine Value (MIPS GP)
224191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_TLS            9   // TLS Directory
225191983Sweongyo#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG   10   // Load Configuration Directory
226191983Sweongyo
227191983Sweongyo//
228192984Sthompsa// Section header format.
229191983Sweongyo//
230192499Sthompsa
231191983Sweongyo#define IMAGE_SIZEOF_SHORT_NAME              8
232191983Sweongyo
233191983Sweongyotypedef struct _IMAGE_SECTION_HEADER {
234191983Sweongyo    UINT8   Name[IMAGE_SIZEOF_SHORT_NAME];
235191983Sweongyo    union {
236191983Sweongyo            UINT32   PhysicalAddress;
237223486Shselasky            UINT32   VirtualSize;
238191983Sweongyo    } Misc;
239191983Sweongyo    UINT32   VirtualAddress;
240191983Sweongyo    UINT32   SizeOfRawData;
241191983Sweongyo    UINT32   PointerToRawData;
242191983Sweongyo    UINT32   PointerToRelocations;
243191983Sweongyo    UINT32   PointerToLinenumbers;
244191983Sweongyo    UINT16   NumberOfRelocations;
245191983Sweongyo    UINT16   NumberOfLinenumbers;
246191983Sweongyo    UINT32   Characteristics;
247192984Sthompsa} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
248191983Sweongyo
249191983Sweongyo#define IMAGE_SIZEOF_SECTION_HEADER          40
250191983Sweongyo
251191983Sweongyo#define IMAGE_SCN_TYPE_NO_PAD                0x00000008  // Reserved.
252191983Sweongyo
253191983Sweongyo#define IMAGE_SCN_CNT_CODE                   0x00000020  // Section contains code.
254191983Sweongyo#define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  // Section contains initialized data.
255194228Sthompsa#define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  // Section contains uninitialized data.
256191983Sweongyo
257191983Sweongyo#define IMAGE_SCN_LNK_OTHER                  0x00000100  // Reserved.
258191983Sweongyo#define IMAGE_SCN_LNK_INFO                   0x00000200  // Section contains comments or some other type of information.
259191983Sweongyo#define IMAGE_SCN_LNK_REMOVE                 0x00000800  // Section contents will not become part of image.
260191983Sweongyo#define IMAGE_SCN_LNK_COMDAT                 0x00001000  // Section contents comdat.
261191983Sweongyo
262194228Sthompsa#define IMAGE_SCN_ALIGN_1BYTES               0x00100000  //
263191983Sweongyo#define IMAGE_SCN_ALIGN_2BYTES               0x00200000  //
264191983Sweongyo#define IMAGE_SCN_ALIGN_4BYTES               0x00300000  //
265191983Sweongyo#define IMAGE_SCN_ALIGN_8BYTES               0x00400000  //
266194228Sthompsa#define IMAGE_SCN_ALIGN_16BYTES              0x00500000  // Default alignment if no others are specified.
267246565Shselasky#define IMAGE_SCN_ALIGN_32BYTES              0x00600000  //
268191983Sweongyo#define IMAGE_SCN_ALIGN_64BYTES              0x00700000  //
269191983Sweongyo
270244503Shselasky#define IMAGE_SCN_MEM_DISCARDABLE            0x02000000  // Section can be discarded.
271244503Shselasky#define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  // Section is not cachable.
272244503Shselasky#define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  // Section is not pageable.
273244503Shselasky#define IMAGE_SCN_MEM_SHARED                 0x10000000  // Section is shareable.
274244503Shselasky#define IMAGE_SCN_MEM_EXECUTE                0x20000000  // Section is executable.
275246565Shselasky#define IMAGE_SCN_MEM_READ                   0x40000000  // Section is readable.
276246565Shselasky#define IMAGE_SCN_MEM_WRITE                  0x80000000  // Section is writeable.
277246565Shselasky
278246565Shselasky//
279246565Shselasky// Symbol format.
280246565Shselasky//
281246565Shselasky
282246565Shselasky
283191983Sweongyo#define IMAGE_SIZEOF_SYMBOL                  18
284191983Sweongyo
285191983Sweongyo//
286191983Sweongyo// Section values.
287191983Sweongyo//
288191983Sweongyo// Symbols have a section number of the section in which they are
289191983Sweongyo// defined. Otherwise, section numbers have the following meanings:
290191983Sweongyo//
291191983Sweongyo
292191983Sweongyo#define IMAGE_SYM_UNDEFINED           (UINT16)0           // Symbol is undefined or is common.
293191983Sweongyo#define IMAGE_SYM_ABSOLUTE            (UINT16)-1          // Symbol is an absolute value.
294191983Sweongyo#define IMAGE_SYM_DEBUG               (UINT16)-2          // Symbol is a special debug item.
295191983Sweongyo
296191983Sweongyo//
297191983Sweongyo// Type (fundamental) values.
298191983Sweongyo//
299191983Sweongyo
300199816Sthompsa#define IMAGE_SYM_TYPE_NULL                  0           // no type.
301191983Sweongyo#define IMAGE_SYM_TYPE_VOID                  1           //
302191983Sweongyo#define IMAGE_SYM_TYPE_CHAR                  2           // type character.
303191983Sweongyo#define IMAGE_SYM_TYPE_SHORT                 3           // type short integer.
304191983Sweongyo#define IMAGE_SYM_TYPE_INT                   4           //
305191983Sweongyo#define IMAGE_SYM_TYPE_LONG                  5           //
306191983Sweongyo#define IMAGE_SYM_TYPE_FLOAT                 6           //
307191983Sweongyo#define IMAGE_SYM_TYPE_DOUBLE                7           //
308191983Sweongyo#define IMAGE_SYM_TYPE_STRUCT                8           //
309191983Sweongyo#define IMAGE_SYM_TYPE_UNION                 9           //
310191983Sweongyo#define IMAGE_SYM_TYPE_ENUM                  10          // enumeration.
311191983Sweongyo#define IMAGE_SYM_TYPE_MOE                   11          // member of enumeration.
312191983Sweongyo#define IMAGE_SYM_TYPE_BYTE                  12          //
313191983Sweongyo#define IMAGE_SYM_TYPE_WORD                  13          //
314191983Sweongyo#define IMAGE_SYM_TYPE_UINT                  14          //
315191983Sweongyo#define IMAGE_SYM_TYPE_DWORD                 15          //
316191983Sweongyo
317191983Sweongyo//
318191983Sweongyo// Type (derived) values.
319191983Sweongyo//
320191983Sweongyo
321191983Sweongyo#define IMAGE_SYM_DTYPE_NULL                 0           // no derived type.
322191983Sweongyo#define IMAGE_SYM_DTYPE_POINTER              1           // pointer.
323191983Sweongyo#define IMAGE_SYM_DTYPE_FUNCTION             2           // function.
324191983Sweongyo#define IMAGE_SYM_DTYPE_ARRAY                3           // array.
325191983Sweongyo
326191983Sweongyo//
327191983Sweongyo// Storage classes.
328191983Sweongyo//
329191983Sweongyo
330191983Sweongyo#define IMAGE_SYM_CLASS_END_OF_FUNCTION      (BYTE )-1
331191983Sweongyo#define IMAGE_SYM_CLASS_NULL                 0
332191983Sweongyo#define IMAGE_SYM_CLASS_AUTOMATIC            1
333191983Sweongyo#define IMAGE_SYM_CLASS_EXTERNAL             2
334191983Sweongyo#define IMAGE_SYM_CLASS_STATIC               3
335191983Sweongyo#define IMAGE_SYM_CLASS_REGISTER             4
336191983Sweongyo#define IMAGE_SYM_CLASS_EXTERNAL_DEF         5
337191983Sweongyo#define IMAGE_SYM_CLASS_LABEL                6
338191983Sweongyo#define IMAGE_SYM_CLASS_UNDEFINED_LABEL      7
339207554Ssobomax#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT     8
340191983Sweongyo#define IMAGE_SYM_CLASS_ARGUMENT             9
341191983Sweongyo#define IMAGE_SYM_CLASS_STRUCT_TAG           10
342191983Sweongyo#define IMAGE_SYM_CLASS_MEMBER_OF_UNION      11
343191983Sweongyo#define IMAGE_SYM_CLASS_UNION_TAG            12
344283537Sglebius#define IMAGE_SYM_CLASS_TYPE_DEFINITION      13
345283527Sglebius#define IMAGE_SYM_CLASS_UNDEFINED_STATIC     14
346191983Sweongyo#define IMAGE_SYM_CLASS_ENUM_TAG             15
347191983Sweongyo#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM       16
348191983Sweongyo#define IMAGE_SYM_CLASS_REGISTER_PARAM       17
349191983Sweongyo#define IMAGE_SYM_CLASS_BIT_FIELD            18
350191983Sweongyo#define IMAGE_SYM_CLASS_BLOCK                100
351191983Sweongyo#define IMAGE_SYM_CLASS_FUNCTION             101
352191983Sweongyo#define IMAGE_SYM_CLASS_END_OF_STRUCT        102
353191983Sweongyo#define IMAGE_SYM_CLASS_FILE                 103
354191983Sweongyo// new
355191983Sweongyo#define IMAGE_SYM_CLASS_SECTION              104
356191983Sweongyo#define IMAGE_SYM_CLASS_WEAK_EXTERNAL        105
357191983Sweongyo
358191983Sweongyo// type packing constants
359191983Sweongyo
360191983Sweongyo#define N_BTMASK                            017
361191983Sweongyo#define N_TMASK                             060
362191983Sweongyo#define N_TMASK1                            0300
363191983Sweongyo#define N_TMASK2                            0360
364191983Sweongyo#define N_BTSHFT                            4
365191983Sweongyo#define N_TSHIFT                            2
366191983Sweongyo
367191983Sweongyo// MACROS
368191983Sweongyo
369191983Sweongyo//
370191983Sweongyo// Communal selection types.
371191983Sweongyo//
372191983Sweongyo
373192468Ssam#define IMAGE_COMDAT_SELECT_NODUPLICATES   1
374192468Ssam#define IMAGE_COMDAT_SELECT_ANY            2
375192468Ssam#define IMAGE_COMDAT_SELECT_SAME_SIZE      3
376192468Ssam#define IMAGE_COMDAT_SELECT_EXACT_MATCH    4
377192468Ssam#define IMAGE_COMDAT_SELECT_ASSOCIATIVE    5
378191983Sweongyo
379191983Sweongyo#define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
380191983Sweongyo#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY   2
381191983Sweongyo#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS     3
382191983Sweongyo
383191983Sweongyo
384191983Sweongyo//
385191983Sweongyo// Relocation format.
386191983Sweongyo//
387246565Shselasky
388246565Shselaskytypedef struct _IMAGE_RELOCATION {
389246565Shselasky    UINT32   VirtualAddress;
390191983Sweongyo    UINT32   SymbolTableIndex;
391191983Sweongyo    UINT16    Type;
392191983Sweongyo} IMAGE_RELOCATION;
393191983Sweongyo
394191983Sweongyo#define IMAGE_SIZEOF_RELOCATION              10
395191983Sweongyo
396192984Sthompsa//
397191983Sweongyo// I386 relocation types.
398194677Sthompsa//
399191983Sweongyo
400191983Sweongyo#define IMAGE_REL_I386_ABSOLUTE              0           // Reference is absolute, no relocation is necessary
401191983Sweongyo#define IMAGE_REL_I386_DIR16                 01          // Direct 16-bit reference to the symbols virtual address
402191983Sweongyo#define IMAGE_REL_I386_REL16                 02          // PC-relative 16-bit reference to the symbols virtual address
403191983Sweongyo#define IMAGE_REL_I386_DIR32                 06          // Direct 32-bit reference to the symbols virtual address
404191983Sweongyo#define IMAGE_REL_I386_DIR32NB               07          // Direct 32-bit reference to the symbols virtual address, base not included
405191983Sweongyo#define IMAGE_REL_I386_SEG12                 011         // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
406191983Sweongyo#define IMAGE_REL_I386_SECTION               012
407191983Sweongyo#define IMAGE_REL_I386_SECREL                013
408191983Sweongyo#define IMAGE_REL_I386_REL32                 024         // PC-relative 32-bit reference to the symbols virtual address
409191983Sweongyo
410191983Sweongyo//
411191983Sweongyo// MIPS relocation types.
412191983Sweongyo//
413191983Sweongyo
414191983Sweongyo#define IMAGE_REL_MIPS_ABSOLUTE              0           // Reference is absolute, no relocation is necessary
415191983Sweongyo#define IMAGE_REL_MIPS_REFHALF               01
416191983Sweongyo#define IMAGE_REL_MIPS_REFWORD               02
417191983Sweongyo#define IMAGE_REL_MIPS_JMPADDR               03
418191983Sweongyo#define IMAGE_REL_MIPS_REFHI                 04
419191983Sweongyo#define IMAGE_REL_MIPS_REFLO                 05
420191983Sweongyo#define IMAGE_REL_MIPS_GPREL                 06
421271866Sglebius#define IMAGE_REL_MIPS_LITERAL               07
422191983Sweongyo#define IMAGE_REL_MIPS_SECTION               012
423191983Sweongyo#define IMAGE_REL_MIPS_SECREL                013
424191983Sweongyo#define IMAGE_REL_MIPS_REFWORDNB             042
425191983Sweongyo#define IMAGE_REL_MIPS_PAIR                  045
426191983Sweongyo
427191983Sweongyo//
428191983Sweongyo// Alpha Relocation types.
429191983Sweongyo//
430191983Sweongyo
431191983Sweongyo#define IMAGE_REL_ALPHA_ABSOLUTE             0x0
432191983Sweongyo#define IMAGE_REL_ALPHA_REFLONG              0x1
433269569Sn_hibma#define IMAGE_REL_ALPHA_REFQUAD              0x2
434191983Sweongyo#define IMAGE_REL_ALPHA_GPREL32              0x3
435191983Sweongyo#define IMAGE_REL_ALPHA_LITERAL              0x4
436191983Sweongyo#define IMAGE_REL_ALPHA_LITUSE               0x5
437191983Sweongyo#define IMAGE_REL_ALPHA_GPDISP               0x6
438191983Sweongyo#define IMAGE_REL_ALPHA_BRADDR               0x7
439191983Sweongyo#define IMAGE_REL_ALPHA_HINT                 0x8
440227461Shselasky#define IMAGE_REL_ALPHA_INLINE_REFLONG       0x9
441191983Sweongyo#define IMAGE_REL_ALPHA_REFHI                0xA
442191983Sweongyo#define IMAGE_REL_ALPHA_REFLO                0xB
443191983Sweongyo#define IMAGE_REL_ALPHA_PAIR                 0xC
444191983Sweongyo#define IMAGE_REL_ALPHA_MATCH                0xD
445191983Sweongyo#define IMAGE_REL_ALPHA_SECTION              0xE
446191983Sweongyo#define IMAGE_REL_ALPHA_SECREL               0xF
447191983Sweongyo#define IMAGE_REL_ALPHA_REFLONGNB            0x10
448191983Sweongyo
449191983Sweongyo//
450191983Sweongyo// IBM PowerPC relocation types.
451191983Sweongyo//
452191983Sweongyo
453191983Sweongyo#define IMAGE_REL_PPC_ABSOLUTE 0x0000  // NOP
454191983Sweongyo#define IMAGE_REL_PPC_ADDR64   0x0001  // 64-bit address
455191983Sweongyo#define IMAGE_REL_PPC_ADDR32   0x0002  // 32-bit address
456191983Sweongyo#define IMAGE_REL_PPC_ADDR24   0x0003  // 26-bit address, shifted left 2 (branch absolute)
457191983Sweongyo#define IMAGE_REL_PPC_ADDR16   0x0004  // 16-bit address
458191983Sweongyo#define IMAGE_REL_PPC_ADDR14   0x0005  // 16-bit address, shifted left 2 (load doubleword)
459191983Sweongyo#define IMAGE_REL_PPC_REL24    0x0006  // 26-bit PC-relative offset, shifted left 2 (branch relative)
460191983Sweongyo#define IMAGE_REL_PPC_REL14    0x0007  // 16-bit PC-relative offset, shifted left 2 (br cond relative)
461191983Sweongyo#define IMAGE_REL_PPC_TOCREL16 0x0008  // 16-bit offset from TOC base
462191983Sweongyo#define IMAGE_REL_PPC_TOCREL14 0x0009  // 16-bit offset from TOC base, shifted left 2 (load doubleword)
463191983Sweongyo
464191983Sweongyo#define IMAGE_REL_PPC_ADDR32NB 0x000A  // 32-bit addr w/o image base
465191983Sweongyo#define IMAGE_REL_PPC_SECREL   0x000B  // va of containing section (as in an image sectionhdr)
466191983Sweongyo#define IMAGE_REL_PPC_SECTION  0x000C  // sectionheader number
467191983Sweongyo#define IMAGE_REL_PPC_IFGLUE   0x000D  // substitute TOC restore instruction iff symbol is glue code
468191983Sweongyo#define IMAGE_REL_PPC_IMGLUE   0x000E  // symbol is glue code; virtual address is TOC restore instruction
469191983Sweongyo
470191983Sweongyo#define IMAGE_REL_PPC_TYPEMASK 0x00FF  // mask to isolate above values in IMAGE_RELOCATION.Type
471246614Shselasky
472246614Shselasky// Flag bits in IMAGE_RELOCATION.TYPE
473191983Sweongyo
474246614Shselasky#define IMAGE_REL_PPC_NEG      0x0100  // subtract reloc value rather than adding it
475246614Shselasky#define IMAGE_REL_PPC_BRTAKEN  0x0200  // fix branch prediction bit to predict branch taken
476246614Shselasky#define IMAGE_REL_PPC_BRNTAKEN 0x0400  // fix branch prediction bit to predict branch not taken
477246614Shselasky#define IMAGE_REL_PPC_TOCDEFN  0x0800  // toc slot defined in file (or, data in toc)
478246614Shselasky
479246614Shselasky//
480191983Sweongyo// Based relocation format.
481191983Sweongyo//
482191983Sweongyo
483191983Sweongyotypedef struct _IMAGE_BASE_RELOCATION {
484191983Sweongyo    UINT32   VirtualAddress;
485191983Sweongyo    UINT32   SizeOfBlock;
486191983Sweongyo//  UINT16    TypeOffset[1];
487191983Sweongyo} IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;
488191983Sweongyo
489191983Sweongyo#define IMAGE_SIZEOF_BASE_RELOCATION         8
490191983Sweongyo
491191983Sweongyo//
492191983Sweongyo// Based relocation types.
493191983Sweongyo//
494191983Sweongyo
495191983Sweongyo#define IMAGE_REL_BASED_ABSOLUTE              0
496191983Sweongyo#define IMAGE_REL_BASED_HIGH                  1
497191983Sweongyo#define IMAGE_REL_BASED_LOW                   2
498191983Sweongyo#define IMAGE_REL_BASED_HIGHLOW               3
499191983Sweongyo#define IMAGE_REL_BASED_HIGHADJ               4
500191983Sweongyo#define IMAGE_REL_BASED_MIPS_JMPADDR          5
501191983Sweongyo#define IMAGE_REL_BASED_IA64_IMM64            9
502191983Sweongyo#define IMAGE_REL_BASED_DIR64                 10
503191983Sweongyo
504191983Sweongyo//
505191983Sweongyo// Line number format.
506191983Sweongyo//
507191983Sweongyo
508191983Sweongyotypedef struct _IMAGE_LINENUMBER {
509191983Sweongyo    union {
510191983Sweongyo        UINT32   SymbolTableIndex;               // Symbol table index of function name if Linenumber is 0.
511191983Sweongyo        UINT32   VirtualAddress;                 // Virtual address of line number.
512191983Sweongyo    } Type;
513191983Sweongyo    UINT16    Linenumber;                         // Line number.
514191983Sweongyo} IMAGE_LINENUMBER;
515191983Sweongyo
516191983Sweongyo#define IMAGE_SIZEOF_LINENUMBER              6
517191983Sweongyo
518191983Sweongyo//
519191983Sweongyo// Archive format.
520191983Sweongyo//
521191983Sweongyo
522191983Sweongyo#define IMAGE_ARCHIVE_START_SIZE             8
523191983Sweongyo#define IMAGE_ARCHIVE_START                  "!<arch>\n"
524191983Sweongyo#define IMAGE_ARCHIVE_END                    "`\n"
525191983Sweongyo#define IMAGE_ARCHIVE_PAD                    "\n"
526191983Sweongyo#define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
527191983Sweongyo#define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
528191983Sweongyo
529191983Sweongyotypedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
530191983Sweongyo    UINT8     Name[16];                          // File member name - `/' terminated.
531191983Sweongyo    UINT8     Date[12];                          // File member date - decimal.
532191983Sweongyo    UINT8     UserID[6];                         // File member user id - decimal.
533191983Sweongyo    UINT8     GroupID[6];                        // File member group id - decimal.
534191983Sweongyo    UINT8     Mode[8];                           // File member mode - octal.
535191983Sweongyo    UINT8     Size[10];                          // File member size - decimal.
536191983Sweongyo    UINT8     EndHeader[2];                      // String to end header.
537191983Sweongyo} IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
538191983Sweongyo
539191983Sweongyo#define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR      60
540191983Sweongyo
541191983Sweongyo//
542191983Sweongyo// DLL support.
543191983Sweongyo//
544191983Sweongyo
545191983Sweongyo//
546191983Sweongyo// Export Format
547191983Sweongyo//
548191983Sweongyo
549191983Sweongyotypedef struct _IMAGE_EXPORT_DIRECTORY {
550191983Sweongyo    UINT32   Characteristics;
551191983Sweongyo    UINT32   TimeDateStamp;
552191983Sweongyo    UINT16   MajorVersion;
553191983Sweongyo    UINT16   MinorVersion;
554191983Sweongyo    UINT32   Name;
555227461Shselasky    UINT32   Base;
556191983Sweongyo    UINT32   NumberOfFunctions;
557191983Sweongyo    UINT32   NumberOfNames;
558191983Sweongyo    UINT32   *AddressOfFunctions;
559191983Sweongyo    UINT32   *AddressOfNames;
560191983Sweongyo    UINT32   *AddressOfNameOrdinals;
561191983Sweongyo} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
562191983Sweongyo
563191983Sweongyo//
564191983Sweongyo// Import Format
565191983Sweongyo//
566191983Sweongyo
567191983Sweongyotypedef struct _IMAGE_IMPORT_BY_NAME {
568191983Sweongyo    UINT16    Hint;
569191983Sweongyo    UINT8     Name[1];
570191983Sweongyo} IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
571191983Sweongyo
572191983Sweongyotypedef struct _IMAGE_THUNK_DATA {
573191983Sweongyo    union {
574191983Sweongyo        UINT32 Function;
575191983Sweongyo        UINT32 Ordinal;
576191983Sweongyo        PIMAGE_IMPORT_BY_NAME AddressOfData;
577191983Sweongyo    } u1;
578191983Sweongyo} IMAGE_THUNK_DATA, *PIMAGE_THUNK_DATA;
579191983Sweongyo
580191983Sweongyo#define IMAGE_ORDINAL_FLAG 0x80000000
581191983Sweongyo#define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
582191983Sweongyo#define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
583191983Sweongyo
584191983Sweongyotypedef struct _IMAGE_IMPORT_DESCRIPTOR {
585191983Sweongyo    UINT32   Characteristics;
586191983Sweongyo    UINT32   TimeDateStamp;
587191983Sweongyo    UINT32   ForwarderChain;
588191983Sweongyo    UINT32   Name;
589191983Sweongyo    PIMAGE_THUNK_DATA FirstThunk;
590191983Sweongyo} IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
591191983Sweongyo
592191983Sweongyo#define IMAGE_DEBUG_TYPE_CODEVIEW   2
593191983Sweongyo
594191983Sweongyotypedef struct {
595191983Sweongyo  UINT32    Characteristics;
596191983Sweongyo  UINT32    TimeDateStamp;
597191983Sweongyo  UINT16    MajorVersion;
598191983Sweongyo  UINT16    MinorVersion;
599191983Sweongyo  UINT32    Type;
600191983Sweongyo  UINT32    SizeOfData;
601191983Sweongyo  UINT32    RVA;
602191983Sweongyo  UINT32    FileOffset;
603191983Sweongyo} IMAGE_DEBUG_DIRECTORY_ENTRY;
604191983Sweongyo
605191983Sweongyo#define CODEVIEW_SIGNATURE_NB10  0x3031424E // "NB10"
606191983Sweongyo
607191983Sweongyotypedef struct {
608191983Sweongyo  UINT32    Signature; // "NB10"
609191983Sweongyo  UINT32    Unknown;
610191983Sweongyo  UINT32    Unknown2;
611191983Sweongyo  UINT32    Unknown3;
612191983Sweongyo  //
613191983Sweongyo  // Filename of .PDB goes here
614191983Sweongyo  //
615191983Sweongyo} EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY;
616191983Sweongyo
617191983Sweongyo#define CODEVIEW_SIGNATURE_RSDS  0x53445352 // "RSDS"
618191983Sweongyo
619191983Sweongyotypedef struct {
620191983Sweongyo  UINT32    Signature; // "RSDS"
621191983Sweongyo  UINT32    Unknown;
622191983Sweongyo  UINT32    Unknown2;
623191983Sweongyo  UINT32    Unknown3;
624191983Sweongyo  UINT32    Unknown4;
625191983Sweongyo  UINT32    Unknown5;
626191983Sweongyo  //
627191983Sweongyo  // Filename of .PDB goes here
628191983Sweongyo  //
629191983Sweongyo} EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY;
630191983Sweongyo
631191983Sweongyo#endif
632191983Sweongyo