]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - include/coff/pe.h
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / include / coff / pe.h
CommitLineData
61e2488c 1/* pe.h - PE COFF header information
252b5132 2
250d07de 3 Copyright (C) 1999-2021 Free Software Foundation, Inc.
d155c6ea
NC
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
e4e42b45 9 the Free Software Foundation; either version 3 of the License, or
d155c6ea
NC
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
e172dbf8 19 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
20#ifndef _PE_H
21#define _PE_H
22
830db048
ZF
23#include "msdos.h"
24
cbaede9c 25/* NT specific file attributes. */
252b5132
RH
26#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
27#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
28#define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
29#define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
cbaede9c
NC
30#define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
31#define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
32#define IMAGE_FILE_16BIT_MACHINE 0x0040
252b5132
RH
33#define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
34#define IMAGE_FILE_32BIT_MACHINE 0x0100
35#define IMAGE_FILE_DEBUG_STRIPPED 0x0200
cbaede9c 36#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
93e49a47 37#define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
252b5132
RH
38#define IMAGE_FILE_SYSTEM 0x1000
39#define IMAGE_FILE_DLL 0x2000
cbaede9c 40#define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
252b5132
RH
41#define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
42
2f563b51
DK
43/* DllCharacteristics flag bits. The inconsistent naming may seem
44 odd, but that is how they are defined in the PE specification. */
2d5c3743 45#define IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA 0x0020
2f563b51
DK
46#define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040
47#define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080
48#define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100
49#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
50#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
51#define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
52#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
53#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
54
cbaede9c 55/* Additional flags to be set for section headers to allow the NT loader to
252b5132 56 read and write to the section data (to replace the addresses of data in
cbaede9c 57 dlls for one thing); also to execute the section in .text's case. */
252b5132
RH
58#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
59#define IMAGE_SCN_MEM_EXECUTE 0x20000000
60#define IMAGE_SCN_MEM_READ 0x40000000
61#define IMAGE_SCN_MEM_WRITE 0x80000000
62
cbaede9c 63/* Section characteristics added for ppc-nt. */
252b5132 64
2d5c3743 65#define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
252b5132 66
2d5c3743
NC
67#define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
68#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
69#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
252b5132 70
2d5c3743
NC
71#define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */
72#define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
73#define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
74#define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
252b5132
RH
75
76#define IMAGE_SCN_MEM_FARDATA 0x00008000
77
78#define IMAGE_SCN_MEM_PURGEABLE 0x00020000
79#define IMAGE_SCN_MEM_16BIT 0x00020000
80#define IMAGE_SCN_MEM_LOCKED 0x00040000
81#define IMAGE_SCN_MEM_PRELOAD 0x00080000
82
2d5c3743 83/* Bit position in the s_flags field where the alignment values start. */
bd33be6e
L
84#define IMAGE_SCN_ALIGN_POWER_BIT_POS 20
85#define IMAGE_SCN_ALIGN_POWER_BIT_MASK 0x00f00000
86#define IMAGE_SCN_ALIGN_POWER_NUM(val) \
87 (((val) >> IMAGE_SCN_ALIGN_POWER_BIT_POS) - 1)
88#define IMAGE_SCN_ALIGN_POWER_CONST(val) \
89 (((val) + 1) << IMAGE_SCN_ALIGN_POWER_BIT_POS)
90
91#define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_POWER_CONST (0)
92#define IMAGE_SCN_ALIGN_2BYTES IMAGE_SCN_ALIGN_POWER_CONST (1)
93#define IMAGE_SCN_ALIGN_4BYTES IMAGE_SCN_ALIGN_POWER_CONST (2)
94#define IMAGE_SCN_ALIGN_8BYTES IMAGE_SCN_ALIGN_POWER_CONST (3)
2d5c3743 95/* Default alignment if no others are specified. */
bd33be6e
L
96#define IMAGE_SCN_ALIGN_16BYTES IMAGE_SCN_ALIGN_POWER_CONST (4)
97#define IMAGE_SCN_ALIGN_32BYTES IMAGE_SCN_ALIGN_POWER_CONST (5)
98#define IMAGE_SCN_ALIGN_64BYTES IMAGE_SCN_ALIGN_POWER_CONST (6)
99#define IMAGE_SCN_ALIGN_128BYTES IMAGE_SCN_ALIGN_POWER_CONST (7)
100#define IMAGE_SCN_ALIGN_256BYTES IMAGE_SCN_ALIGN_POWER_CONST (8)
101#define IMAGE_SCN_ALIGN_512BYTES IMAGE_SCN_ALIGN_POWER_CONST (9)
102#define IMAGE_SCN_ALIGN_1024BYTES IMAGE_SCN_ALIGN_POWER_CONST (10)
103#define IMAGE_SCN_ALIGN_2048BYTES IMAGE_SCN_ALIGN_POWER_CONST (11)
104#define IMAGE_SCN_ALIGN_4096BYTES IMAGE_SCN_ALIGN_POWER_CONST (12)
105#define IMAGE_SCN_ALIGN_8192BYTES IMAGE_SCN_ALIGN_POWER_CONST (13)
252b5132 106
2d5c3743 107/* Encode alignment power into IMAGE_SCN_ALIGN bits of s_flags. */
11ec4ba9 108#define COFF_ENCODE_ALIGNMENT(SECTION, ALIGNMENT_POWER) \
5be87c8f
JB
109 ((SECTION).s_flags |= IMAGE_SCN_ALIGN_POWER_CONST ((ALIGNMENT_POWER) <= 13 \
110 ? (ALIGNMENT_POWER) : 13))
111#define COFF_DECODE_ALIGNMENT(X) \
112 IMAGE_SCN_ALIGN_POWER_NUM ((X) & IMAGE_SCN_ALIGN_POWER_BIT_MASK)
11ec4ba9 113
252b5132
RH
114#define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
115#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
116#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */
117#define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
118
119/* COMDAT selection codes. */
120
121#define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */
122#define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */
123#define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */
124#define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */
125#define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */
126
cbaede9c
NC
127/* Machine numbers. */
128
93e49a47
NC
129#define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
130#define IMAGE_FILE_MACHINE_ALPHA 0x0184
131#define IMAGE_FILE_MACHINE_ALPHA64 0x0284
132#define IMAGE_FILE_MACHINE_AM33 0x01d3
133#define IMAGE_FILE_MACHINE_AMD64 0x8664
134#define IMAGE_FILE_MACHINE_ARM 0x01c0
135#define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
136#define IMAGE_FILE_MACHINE_CEE 0xc0ee
137#define IMAGE_FILE_MACHINE_CEF 0x0cef
138#define IMAGE_FILE_MACHINE_EBC 0x0ebc
139#define IMAGE_FILE_MACHINE_I386 0x014c
140#define IMAGE_FILE_MACHINE_IA64 0x0200
141#define IMAGE_FILE_MACHINE_M32R 0x9041
142#define IMAGE_FILE_MACHINE_M68K 0x0268
143#define IMAGE_FILE_MACHINE_MIPS16 0x0266
144#define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
145#define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
146#define IMAGE_FILE_MACHINE_POWERPC 0x01f0
147#define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
148#define IMAGE_FILE_MACHINE_R10000 0x0168
149#define IMAGE_FILE_MACHINE_R3000 0x0162
150#define IMAGE_FILE_MACHINE_R4000 0x0166
151#define IMAGE_FILE_MACHINE_SH3 0x01a2
152#define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
153#define IMAGE_FILE_MACHINE_SH3E 0x01a4
154#define IMAGE_FILE_MACHINE_SH4 0x01a6
155#define IMAGE_FILE_MACHINE_SH5 0x01a8
156#define IMAGE_FILE_MACHINE_THUMB 0x01c2
157#define IMAGE_FILE_MACHINE_TRICORE 0x0520
158#define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
99ad8390 159#define IMAGE_FILE_MACHINE_AMD64 0x8664
93e49a47 160
63fa1674
JW
161#define IMAGE_SUBSYSTEM_UNKNOWN 0
162#define IMAGE_SUBSYSTEM_NATIVE 1
163#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
164#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
165#define IMAGE_SUBSYSTEM_POSIX_CUI 7
166#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
167#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
168#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
169#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
d9118602 170#define IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
6c73cbb1 171#define IMAGE_SUBSYSTEM_XBOX 14
61e2488c 172
d155c6ea
NC
173/* NT allows long filenames, we want to accommodate this.
174 This may break some of the bfd functions. */
252b5132 175#undef FILNMLEN
d155c6ea 176#define FILNMLEN 18 /* # characters in a file name. */
252b5132 177
98536290
L
178struct external_PEI_IMAGE_hdr
179{
2d5c3743 180 char nt_signature[4]; /* Required NT signature, 0x4550. */
98536290
L
181
182 /* From standard header. */
183 char f_magic[2]; /* Magic number. */
184 char f_nscns[2]; /* Number of sections. */
185 char f_timdat[4]; /* Time & date stamp. */
186 char f_symptr[4]; /* File pointer to symtab. */
187 char f_nsyms[4]; /* Number of symtab entries. */
188 char f_opthdr[2]; /* Sizeof(optional hdr). */
189 char f_flags[2]; /* Flags. */
190};
191
25bcc51d 192struct external_PEI_filehdr
252b5132 193{
d155c6ea
NC
194 /* DOS header fields - always at offset zero in the EXE file. */
195 char e_magic[2]; /* Magic number, 0x5a4d. */
196 char e_cblp[2]; /* Bytes on last page of file, 0x90. */
197 char e_cp[2]; /* Pages in file, 0x3. */
198 char e_crlc[2]; /* Relocations, 0x0. */
199 char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
200 char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
201 char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
202 char e_ss[2]; /* Initial (relative) SS value, 0x0. */
203 char e_sp[2]; /* Initial SP value, 0xb8. */
204 char e_csum[2]; /* Checksum, 0x0. */
205 char e_ip[2]; /* Initial IP value, 0x0. */
206 char e_cs[2]; /* Initial (relative) CS value, 0x0. */
207 char e_lfarlc[2]; /* File address of relocation table, 0x40. */
208 char e_ovno[2]; /* Overlay number, 0x0. */
209 char e_res[4][2]; /* Reserved words, all 0x0. */
210 char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
211 char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
212 char e_res2[10][2]; /* Reserved words, all 0x0. */
213 char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
214 char dos_message[16][4]; /* Other stuff, always follow DOS header. */
c689311b
DD
215
216 /* Note: additional bytes may be inserted before the signature. Use
d155c6ea
NC
217 the e_lfanew field to find the actual location of the NT signature. */
218
2d5c3743 219 char nt_signature[4]; /* Required NT signature, 0x4550. */
d155c6ea
NC
220
221 /* From standard header. */
222 char f_magic[2]; /* Magic number. */
223 char f_nscns[2]; /* Number of sections. */
224 char f_timdat[4]; /* Time & date stamp. */
225 char f_symptr[4]; /* File pointer to symtab. */
226 char f_nsyms[4]; /* Number of symtab entries. */
227 char f_opthdr[2]; /* Sizeof(optional hdr). */
228 char f_flags[2]; /* Flags. */
252b5132
RH
229};
230
25bcc51d
ILT
231#ifdef COFF_IMAGE_WITH_PE
232
cbaede9c 233/* The filehdr is only weird in images. */
252b5132 234
cbaede9c 235#undef FILHDR
25bcc51d 236#define FILHDR struct external_PEI_filehdr
cbaede9c 237#undef FILHSZ
252b5132
RH
238#define FILHSZ 152
239
25bcc51d 240#endif /* COFF_IMAGE_WITH_PE */
252b5132 241
2d5c3743 242/* 32-bit PE a.out header: */
63fa1674 243
61e2488c 244typedef struct
252b5132
RH
245{
246 AOUTHDR standard;
247
d155c6ea 248 /* NT extra fields; see internal.h for descriptions. */
252b5132
RH
249 char ImageBase[4];
250 char SectionAlignment[4];
251 char FileAlignment[4];
252 char MajorOperatingSystemVersion[2];
253 char MinorOperatingSystemVersion[2];
254 char MajorImageVersion[2];
255 char MinorImageVersion[2];
256 char MajorSubsystemVersion[2];
257 char MinorSubsystemVersion[2];
258 char Reserved1[4];
259 char SizeOfImage[4];
260 char SizeOfHeaders[4];
261 char CheckSum[4];
262 char Subsystem[2];
263 char DllCharacteristics[2];
264 char SizeOfStackReserve[4];
265 char SizeOfStackCommit[4];
266 char SizeOfHeapReserve[4];
267 char SizeOfHeapCommit[4];
268 char LoaderFlags[4];
269 char NumberOfRvaAndSizes[4];
d155c6ea
NC
270 /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
271 char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
252b5132 272} PEAOUTHDR;
99ad8390 273
252b5132
RH
274#undef AOUTSZ
275#define AOUTSZ (AOUTHDRSZ + 196)
276
63fa1674
JW
277/* Like PEAOUTHDR, except that the "standard" member has no BaseOfData
278 (aka data_start) member and that some of the members are 8 instead
279 of just 4 bytes long. */
61e2488c 280typedef struct
63fa1674 281{
99ad8390
NC
282#ifdef AOUTHDRSZ64
283 AOUTHDR64 standard;
284#else
63fa1674 285 AOUTHDR standard;
99ad8390 286#endif
d155c6ea 287 /* NT extra fields; see internal.h for descriptions. */
63fa1674
JW
288 char ImageBase[8];
289 char SectionAlignment[4];
290 char FileAlignment[4];
291 char MajorOperatingSystemVersion[2];
292 char MinorOperatingSystemVersion[2];
293 char MajorImageVersion[2];
294 char MinorImageVersion[2];
295 char MajorSubsystemVersion[2];
296 char MinorSubsystemVersion[2];
297 char Reserved1[4];
298 char SizeOfImage[4];
299 char SizeOfHeaders[4];
300 char CheckSum[4];
301 char Subsystem[2];
302 char DllCharacteristics[2];
303 char SizeOfStackReserve[8];
304 char SizeOfStackCommit[8];
305 char SizeOfHeapReserve[8];
306 char SizeOfHeapCommit[8];
307 char LoaderFlags[4];
308 char NumberOfRvaAndSizes[4];
d155c6ea
NC
309 /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
310 char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
c9430732 311} PEPAOUTHDR;
99ad8390
NC
312
313#ifdef AOUTHDRSZ64
314#define PEPAOUTSZ (AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */
315#else
c9430732 316#define PEPAOUTSZ 240
99ad8390 317#endif
61e2488c 318
252b5132 319#undef E_FILNMLEN
d155c6ea 320#define E_FILNMLEN 18 /* # characters in a file name. */
056350c6
NC
321
322/* Import Tyoes fot ILF format object files.. */
323#define IMPORT_CODE 0
324#define IMPORT_DATA 1
325#define IMPORT_CONST 2
326
327/* Import Name Tyoes for ILF format object files. */
328#define IMPORT_ORDINAL 0
329#define IMPORT_NAME 1
330#define IMPORT_NAME_NOPREFIX 2
331#define IMPORT_NAME_UNDECORATE 3
332
977cdf5a
NC
333/* Weak external characteristics. */
334#define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
335#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
336#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
337
167ad85b
TG
338/* Bigobj header. */
339struct external_ANON_OBJECT_HEADER_BIGOBJ
340{
341 /* ANON_OBJECT_HEADER_V2 header. */
342 char Sig1[2];
343 char Sig2[2];
344 char Version[2];
345 char Machine[2];
346 char TimeDateStamp[4];
347 char ClassID[16];
348 char SizeOfData[4];
349 char Flags[4];
350 char MetaDataSize[4];
351 char MetaDataOffset[4];
352
353 /* BIGOBJ specific. */
354 char NumberOfSections[4];
355 char PointerToSymbolTable[4];
356 char NumberOfSymbols[4];
357};
358
359#define FILHSZ_BIGOBJ (14 * 4)
360
361struct external_SYMBOL_EX
362{
363 union
364 {
365 char e_name[E_SYMNMLEN];
366
367 struct
368 {
369 char e_zeroes[4];
370 char e_offset[4];
371 } e;
372 } e;
373
374 char e_value[4];
375 char e_scnum[4];
376 char e_type[2];
377 char e_sclass[1];
378 char e_numaux[1];
379} ATTRIBUTE_PACKED ;
380
381#define SYMENT_BIGOBJ struct external_SYMBOL_EX
382#define SYMESZ_BIGOBJ 20
383
384#define FILNMLEN_BIGOBJ 20
385
386union external_AUX_SYMBOL_EX
387{
388 struct
389 {
390 char WeakDefaultSymIndex[4];
391 char WeakSearchType[4];
392 char rgbReserved[12];
393 } Sym;
394
395 struct
396 {
397 char Name[FILNMLEN_BIGOBJ];
398 } File;
399
400 struct
401 {
2d5c3743
NC
402 char Length[4]; /* Section length. */
403 char NumberOfRelocations[2];/* # relocation entries. */
404 char NumberOfLinenumbers[2];/* # line numbers. */
405 char Checksum[4]; /* Section COMDAT checksum. */
406 char Number[2]; /* COMDAT associated section index. */
407 char Selection[1]; /* COMDAT selection number. */
167ad85b 408 char bReserved[1];
2d5c3743 409 char HighNumber[2]; /* High bits of COMDAT associated sec. */
167ad85b
TG
410 char rgbReserved[2];
411 } Section;
412} ATTRIBUTE_PACKED;
413
414#define AUXENT_BIGOBJ union external_AUX_SYMBOL_EX
415#define AUXESZ_BIGOBJ 20
416
e48570bb
DK
417/* .pdata/.xdata defines and structures for x64 PE+ for exception handling. */
418
419/* .pdata in exception directory. */
420
421struct pex64_runtime_function
422{
423 bfd_vma rva_BeginAddress;
424 bfd_vma rva_EndAddress;
425 bfd_vma rva_UnwindData;
e48570bb
DK
426};
427
428struct external_pex64_runtime_function
429{
430 bfd_byte rva_BeginAddress[4];
431 bfd_byte rva_EndAddress[4];
432 bfd_byte rva_UnwindData[4];
433};
434
435/* If the lowest significant bit is set for rva_UnwindData RVA, it
436 means that the unified RVA points to another pex64_runtime_function
437 that this entry shares the unwind_info block with. */
438#define PEX64_IS_RUNTIME_FUNCTION_CHAINED(PTR_RTF) \
439 (((PTR_RTF)->rva_UnwindData & 1) != 0)
440#define PEX64_GET_UNWINDDATA_UNIFIED_RVA(PTR_RTF) \
441 ((PTR_RTF)->rva_UnwindData & ~1)
442
443/* The unwind codes. */
444#define UWOP_PUSH_NONVOL 0
445#define UWOP_ALLOC_LARGE 1
446#define UWOP_ALLOC_SMALL 2
447#define UWOP_SET_FPREG 3
448#define UWOP_SAVE_NONVOL 4
449#define UWOP_SAVE_NONVOL_FAR 5
2b597f54
TG
450#define UWOP_SAVE_XMM 6 /* For version 1. */
451#define UWOP_EPILOG 6 /* For version 2. */
452#define UWOP_SAVE_XMM_FAR 7 /* For version 1 (deprecated). */
453#define UWOP_SPARE 7 /* For version 2. */
e48570bb
DK
454#define UWOP_SAVE_XMM128 8
455#define UWOP_SAVE_XMM128_FAR 9
456#define UWOP_PUSH_MACHFRAME 10
457
458struct pex64_unwind_code
459{
460 bfd_vma prologue_offset;
461 /* Contains Frame offset, or frame allocation size. */
462 bfd_vma frame_addr;
463 unsigned int uwop_code : 4;
464 /* xmm, mm, or standard register from 0 - 15. */
465 unsigned int reg : 4;
466 /* Used for UWOP_PUSH_MACHFRAME to indicate optional errorcode stack
467 argument. */
468 unsigned int has_errorcode : 1;
469};
470
471struct external_pex64_unwind_code
472{
473 bfd_byte dta[2];
474};
475
476#define PEX64_UNWCODE_CODE(VAL) ((VAL) & 0xf)
477#define PEX64_UNWCODE_INFO(VAL) (((VAL) >> 4) & 0xf)
478
479/* The unwind info. */
480#define UNW_FLAG_NHANDLER 0
481#define UNW_FLAG_EHANDLER 1
482#define UNW_FLAG_UHANDLER 2
483#define UNW_FLAG_FHANDLER 3
484#define UNW_FLAG_CHAININFO 4
485
486#define UNW_FLAG_MASK 0x1f
487
488struct pex64_unwind_info
489{
490 bfd_vma SizeOfBlock;
491 bfd_byte Version; /* Values from 0 up to 7 are possible. */
492 bfd_byte Flags; /* Values from 0 up to 31 are possible. */
493 bfd_vma SizeOfPrologue;
494 bfd_vma CountOfCodes; /* Amount of pex64_unwind_code elements. */
495 /* 0 = CFA, 1..15 are index of integer registers. */
496 unsigned int FrameRegister : 4;
497 bfd_vma FrameOffset;
498 bfd_vma sizeofUnwindCodes;
499 bfd_byte *rawUnwindCodes;
3e33b239 500 bfd_byte *rawUnwindCodesEnd;
48d5accb
TG
501 bfd_vma rva_ExceptionHandler; /* UNW_EHANDLER or UNW_FLAG_UHANDLER. */
502 bfd_vma rva_BeginAddress; /* UNW_FLAG_CHAININFO. */
503 bfd_vma rva_EndAddress; /* UNW_FLAG_CHAININFO. */
504 bfd_vma rva_UnwindData; /* UNW_FLAG_CHAININFO. */
e48570bb
DK
505};
506
507struct external_pex64_unwind_info
508{
509 bfd_byte Version_Flags;
510 bfd_byte SizeOfPrologue;
511 bfd_byte CountOfCodes;
512 bfd_byte FrameRegisterOffset;
513 /* external_pex64_unwind_code array. */
514 /* bfd_byte handler[4]; */
515 /* Optional language specific data. */
516};
517
518struct external_pex64_scope
519{
520 bfd_vma Count;
521};
522
523struct pex64_scope
524{
525 bfd_byte Count[4];
526};
527
528struct pex64_scope_entry
529{
530 bfd_vma rva_BeginAddress;
531 bfd_vma rva_EndAddress;
532 bfd_vma rva_HandlerAddress;
533 bfd_vma rva_JumpAddress;
534};
535#define PEX64_SCOPE_ENTRY_SIZE 16
536
537struct external_pex64_scope_entry
538{
539 bfd_byte rva_BeginAddress[4];
540 bfd_byte rva_EndAddress[4];
541 bfd_byte rva_HandlerAddress[4];
542 bfd_byte rva_JumpAddress[4];
543};
544
545#define PEX64_UWI_VERSION(VAL) ((VAL) & 7)
546#define PEX64_UWI_FLAGS(VAL) (((VAL) >> 3) & 0x1f)
547#define PEX64_UWI_FRAMEREG(VAL) ((VAL) & 0xf)
548#define PEX64_UWI_FRAMEOFF(VAL) (((VAL) >> 4) & 0xf)
549#define PEX64_UWI_SIZEOF_UWCODE_ARRAY(VAL) \
550 ((((VAL) + 1) & ~1) * 2)
551
552#define PEX64_OFFSET_TO_UNWIND_CODE 0x4
553
554#define PEX64_OFFSET_TO_HANDLER_RVA (COUNTOFUNWINDCODES) \
555 (PEX64_OFFSET_TO_UNWIND_CODE + \
556 PEX64_UWI_SIZEOF_UWCODE_ARRAY(COUNTOFUNWINDCODES))
557
558#define PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) \
559 (PEX64_OFFSET_TO_HANDLER_RVA(COUNTOFUNWINDCODES) + 4)
560
561#define PEX64_SCOPE_ENTRY(COUNTOFUNWINDCODES, IDX) \
562 (PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) + \
563 PEX64_SCOPE_ENTRY_SIZE * (IDX))
564
2d5c3743
NC
565/* Extra structure used in debug directory. */
566struct external_IMAGE_DEBUG_DIRECTORY
567{
61e2488c
JT
568 char Characteristics[4];
569 char TimeDateStamp[4];
570 char MajorVersion[2];
571 char MinorVersion[2];
572 char Type[4];
573 char SizeOfData[4];
574 char AddressOfRawData[4];
575 char PointerToRawData[4];
576};
577
2d5c3743
NC
578/* Extra structures used in codeview debug record. */
579/* This is not part of the PE specification. */
61e2488c 580
279edac5
AM
581#define CVINFO_PDB70_CVSIGNATURE 0x53445352 /* "RSDS" */
582#define CVINFO_PDB20_CVSIGNATURE 0x3031424e /* "NB10" */
583#define CVINFO_CV50_CVSIGNATURE 0x3131424e /* "NB11" */
584#define CVINFO_CV41_CVSIGNATURE 0x3930424e /* "NB09" */
61e2488c
JT
585
586typedef struct _CV_INFO_PDB70
587{
588 char CvSignature[4];
589 char Signature[16];
590 char Age[4];
591 char PdbFileName[];
592} CV_INFO_PDB70;
593
594typedef struct _CV_INFO_PDB20
595{
596 char CvHeader[4];
597 char Offset[4];
598 char Signature[4];
599 char Age[4];
600 char PdbFileName[];
601} CV_INFO_PDB20;
602
056350c6 603#endif /* _PE_H */