177298Sobrien/* pe.h  -  PE COFF header information
233965Sjdp
3218822Sdim   Copyright 1999, 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
477298Sobrien
577298Sobrien   This file is part of BFD, the Binary File Descriptor library.
677298Sobrien
777298Sobrien   This program is free software; you can redistribute it and/or modify
877298Sobrien   it under the terms of the GNU General Public License as published by
977298Sobrien   the Free Software Foundation; either version 2 of the License, or
1077298Sobrien   (at your option) any later version.
1177298Sobrien
1277298Sobrien   This program is distributed in the hope that it will be useful,
1377298Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1477298Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1577298Sobrien   GNU General Public License for more details.
1677298Sobrien
1777298Sobrien   You should have received a copy of the GNU General Public License
1877298Sobrien   along with this program; if not, write to the Free Software Foundation,
19218822Sdim   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
2033965Sjdp#ifndef _PE_H
2133965Sjdp#define _PE_H
2233965Sjdp
2360484Sobrien/* NT specific file attributes.  */
2433965Sjdp#define IMAGE_FILE_RELOCS_STRIPPED           0x0001
2533965Sjdp#define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002
2633965Sjdp#define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004
2733965Sjdp#define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008
2860484Sobrien#define IMAGE_FILE_AGGRESSIVE_WS_TRIM        0x0010
2960484Sobrien#define IMAGE_FILE_LARGE_ADDRESS_AWARE       0x0020
3060484Sobrien#define IMAGE_FILE_16BIT_MACHINE             0x0040
3133965Sjdp#define IMAGE_FILE_BYTES_REVERSED_LO         0x0080
3233965Sjdp#define IMAGE_FILE_32BIT_MACHINE             0x0100
3333965Sjdp#define IMAGE_FILE_DEBUG_STRIPPED            0x0200
3460484Sobrien#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP   0x0400
35130561Sobrien#define IMAGE_FILE_NET_RUN_FROM_SWAP         0x0800
3633965Sjdp#define IMAGE_FILE_SYSTEM                    0x1000
3733965Sjdp#define IMAGE_FILE_DLL                       0x2000
3860484Sobrien#define IMAGE_FILE_UP_SYSTEM_ONLY            0x4000
3933965Sjdp#define IMAGE_FILE_BYTES_REVERSED_HI         0x8000
4033965Sjdp
4160484Sobrien/* Additional flags to be set for section headers to allow the NT loader to
4233965Sjdp   read and write to the section data (to replace the addresses of data in
4360484Sobrien   dlls for one thing); also to execute the section in .text's case.  */
4433965Sjdp#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
4533965Sjdp#define IMAGE_SCN_MEM_EXECUTE     0x20000000
4633965Sjdp#define IMAGE_SCN_MEM_READ        0x40000000
4733965Sjdp#define IMAGE_SCN_MEM_WRITE       0x80000000
4833965Sjdp
4960484Sobrien/* Section characteristics added for ppc-nt.  */
5033965Sjdp
5133965Sjdp#define IMAGE_SCN_TYPE_NO_PAD                0x00000008  /* Reserved. */
5233965Sjdp
5333965Sjdp#define IMAGE_SCN_CNT_CODE                   0x00000020  /* Section contains code. */
5433965Sjdp#define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  /* Section contains initialized data. */
5533965Sjdp#define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  /* Section contains uninitialized data. */
5633965Sjdp
5733965Sjdp#define IMAGE_SCN_LNK_OTHER                  0x00000100  /* Reserved. */
5833965Sjdp#define IMAGE_SCN_LNK_INFO                   0x00000200  /* Section contains comments or some other type of information. */
5933965Sjdp#define IMAGE_SCN_LNK_REMOVE                 0x00000800  /* Section contents will not become part of image. */
6033965Sjdp#define IMAGE_SCN_LNK_COMDAT                 0x00001000  /* Section contents comdat. */
6133965Sjdp
6233965Sjdp#define IMAGE_SCN_MEM_FARDATA                0x00008000
6333965Sjdp
6433965Sjdp#define IMAGE_SCN_MEM_PURGEABLE              0x00020000
6533965Sjdp#define IMAGE_SCN_MEM_16BIT                  0x00020000
6633965Sjdp#define IMAGE_SCN_MEM_LOCKED                 0x00040000
6733965Sjdp#define IMAGE_SCN_MEM_PRELOAD                0x00080000
6833965Sjdp
6933965Sjdp#define IMAGE_SCN_ALIGN_1BYTES               0x00100000
7033965Sjdp#define IMAGE_SCN_ALIGN_2BYTES               0x00200000
7133965Sjdp#define IMAGE_SCN_ALIGN_4BYTES               0x00300000
7233965Sjdp#define IMAGE_SCN_ALIGN_8BYTES               0x00400000
7333965Sjdp#define IMAGE_SCN_ALIGN_16BYTES              0x00500000  /* Default alignment if no others are specified. */
7433965Sjdp#define IMAGE_SCN_ALIGN_32BYTES              0x00600000
7533965Sjdp#define IMAGE_SCN_ALIGN_64BYTES              0x00700000
7633965Sjdp
7733965Sjdp#define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  /* Section contains extended relocations. */
7833965Sjdp#define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  /* Section is not cachable.               */
7933965Sjdp#define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  /* Section is not pageable.               */
8033965Sjdp#define IMAGE_SCN_MEM_SHARED                 0x10000000  /* Section is shareable.                  */
8133965Sjdp
8233965Sjdp/* COMDAT selection codes.  */
8333965Sjdp
8433965Sjdp#define IMAGE_COMDAT_SELECT_NODUPLICATES     (1) /* Warn if duplicates.  */
8533965Sjdp#define IMAGE_COMDAT_SELECT_ANY		     (2) /* No warning.  */
8633965Sjdp#define IMAGE_COMDAT_SELECT_SAME_SIZE	     (3) /* Warn if different size.  */
8733965Sjdp#define IMAGE_COMDAT_SELECT_EXACT_MATCH	     (4) /* Warn if different.  */
8833965Sjdp#define IMAGE_COMDAT_SELECT_ASSOCIATIVE	     (5) /* Base on other section.  */
8933965Sjdp
9060484Sobrien/* Machine numbers.  */
9160484Sobrien
92130561Sobrien#define IMAGE_FILE_MACHINE_UNKNOWN           0x0000
93130561Sobrien#define IMAGE_FILE_MACHINE_ALPHA             0x0184
94130561Sobrien#define IMAGE_FILE_MACHINE_ALPHA64           0x0284
95130561Sobrien#define IMAGE_FILE_MACHINE_AM33              0x01d3
96130561Sobrien#define IMAGE_FILE_MACHINE_AMD64             0x8664
97130561Sobrien#define IMAGE_FILE_MACHINE_ARM               0x01c0
98130561Sobrien#define IMAGE_FILE_MACHINE_AXP64             IMAGE_FILE_MACHINE_ALPHA64
99130561Sobrien#define IMAGE_FILE_MACHINE_CEE               0xc0ee
100130561Sobrien#define IMAGE_FILE_MACHINE_CEF               0x0cef
101130561Sobrien#define IMAGE_FILE_MACHINE_EBC               0x0ebc
102130561Sobrien#define IMAGE_FILE_MACHINE_I386              0x014c
103130561Sobrien#define IMAGE_FILE_MACHINE_IA64              0x0200
104130561Sobrien#define IMAGE_FILE_MACHINE_M32R              0x9041
105130561Sobrien#define IMAGE_FILE_MACHINE_M68K              0x0268
106130561Sobrien#define IMAGE_FILE_MACHINE_MIPS16            0x0266
107130561Sobrien#define IMAGE_FILE_MACHINE_MIPSFPU           0x0366
108130561Sobrien#define IMAGE_FILE_MACHINE_MIPSFPU16         0x0466
109130561Sobrien#define IMAGE_FILE_MACHINE_POWERPC           0x01f0
110130561Sobrien#define IMAGE_FILE_MACHINE_POWERPCFP         0x01f1
111130561Sobrien#define IMAGE_FILE_MACHINE_R10000            0x0168
112130561Sobrien#define IMAGE_FILE_MACHINE_R3000             0x0162
113130561Sobrien#define IMAGE_FILE_MACHINE_R4000             0x0166
114130561Sobrien#define IMAGE_FILE_MACHINE_SH3               0x01a2
115130561Sobrien#define IMAGE_FILE_MACHINE_SH3DSP            0x01a3
116130561Sobrien#define IMAGE_FILE_MACHINE_SH3E              0x01a4
117130561Sobrien#define IMAGE_FILE_MACHINE_SH4               0x01a6
118130561Sobrien#define IMAGE_FILE_MACHINE_SH5               0x01a8
119130561Sobrien#define IMAGE_FILE_MACHINE_THUMB             0x01c2
120130561Sobrien#define IMAGE_FILE_MACHINE_TRICORE           0x0520
121130561Sobrien#define IMAGE_FILE_MACHINE_WCEMIPSV2         0x0169
122218822Sdim#define IMAGE_FILE_MACHINE_AMD64             0x8664
123130561Sobrien
12477298Sobrien#define IMAGE_SUBSYSTEM_UNKNOWN			 0
12577298Sobrien#define IMAGE_SUBSYSTEM_NATIVE			 1
12677298Sobrien#define IMAGE_SUBSYSTEM_WINDOWS_GUI		 2
12777298Sobrien#define IMAGE_SUBSYSTEM_WINDOWS_CUI		 3
12877298Sobrien#define IMAGE_SUBSYSTEM_POSIX_CUI		 7
12977298Sobrien#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI		 9
13077298Sobrien#define IMAGE_SUBSYSTEM_EFI_APPLICATION		10
13177298Sobrien#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER	11
13277298Sobrien#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER	12
133218822Sdim#define IMAGE_SUBSYSTEM_EFI_ROM			13
134218822Sdim#define IMAGE_SUBSYSTEM_XBOX			14
13577298Sobrien
13677298Sobrien/* Magic values that are true for all dos/nt implementations.  */
13733965Sjdp#define DOSMAGIC       0x5a4d
13833965Sjdp#define NT_SIGNATURE   0x00004550
13933965Sjdp
14077298Sobrien/* NT allows long filenames, we want to accommodate this.
14177298Sobrien   This may break some of the bfd functions.  */
14233965Sjdp#undef  FILNMLEN
14377298Sobrien#define FILNMLEN	18	/* # characters in a file name.  */
14433965Sjdp
14577298Sobrienstruct external_PEI_DOS_hdr
14677298Sobrien{
14777298Sobrien  /* DOS header fields - always at offset zero in the EXE file.  */
14877298Sobrien  char e_magic[2];		/* Magic number, 0x5a4d.  */
14977298Sobrien  char e_cblp[2];		/* Bytes on last page of file, 0x90.  */
15077298Sobrien  char e_cp[2];			/* Pages in file, 0x3.  */
15177298Sobrien  char e_crlc[2];		/* Relocations, 0x0.  */
15277298Sobrien  char e_cparhdr[2];		/* Size of header in paragraphs, 0x4.  */
15377298Sobrien  char e_minalloc[2];		/* Minimum extra paragraphs needed, 0x0.  */
15477298Sobrien  char e_maxalloc[2];		/* Maximum extra paragraphs needed, 0xFFFF.  */
15577298Sobrien  char e_ss[2];			/* Initial (relative) SS value, 0x0.  */
15677298Sobrien  char e_sp[2];			/* Initial SP value, 0xb8.  */
15777298Sobrien  char e_csum[2];		/* Checksum, 0x0.  */
15877298Sobrien  char e_ip[2];			/* Initial IP value, 0x0.  */
15977298Sobrien  char e_cs[2];			/* Initial (relative) CS value, 0x0.  */
16077298Sobrien  char e_lfarlc[2];		/* File address of relocation table, 0x40.  */
16177298Sobrien  char e_ovno[2];		/* Overlay number, 0x0.  */
16277298Sobrien  char e_res[4][2];		/* Reserved words, all 0x0.  */
16377298Sobrien  char e_oemid[2];		/* OEM identifier (for e_oeminfo), 0x0.  */
16477298Sobrien  char e_oeminfo[2];		/* OEM information; e_oemid specific, 0x0.  */
16577298Sobrien  char e_res2[10][2];		/* Reserved words, all 0x0.  */
16677298Sobrien  char e_lfanew[4];		/* File address of new exe header, usually 0x80.  */
16777298Sobrien  char dos_message[16][4];	/* Other stuff, always follow DOS header.  */
16877298Sobrien};
16977298Sobrien
17077298Sobrienstruct external_PEI_IMAGE_hdr
17177298Sobrien{
17277298Sobrien  char nt_signature[4];		/* required NT signature, 0x4550.  */
17377298Sobrien
17477298Sobrien  /* From standard header.  */
17577298Sobrien  char f_magic[2];		/* Magic number.		*/
17677298Sobrien  char f_nscns[2];		/* Number of sections.		*/
17777298Sobrien  char f_timdat[4];		/* Time & date stamp.		*/
17877298Sobrien  char f_symptr[4];		/* File pointer to symtab.	*/
17977298Sobrien  char f_nsyms[4];		/* Number of symtab entries.	*/
18077298Sobrien  char f_opthdr[2];		/* Sizeof(optional hdr).	*/
18177298Sobrien  char f_flags[2];		/* Flags.			*/
18277298Sobrien};
18377298Sobrien
18460484Sobrienstruct external_PEI_filehdr
18533965Sjdp{
18677298Sobrien  /* DOS header fields - always at offset zero in the EXE file.  */
18777298Sobrien  char e_magic[2];		/* Magic number, 0x5a4d.  */
18877298Sobrien  char e_cblp[2];		/* Bytes on last page of file, 0x90.  */
18977298Sobrien  char e_cp[2];			/* Pages in file, 0x3.  */
19077298Sobrien  char e_crlc[2];		/* Relocations, 0x0.  */
19177298Sobrien  char e_cparhdr[2];		/* Size of header in paragraphs, 0x4.  */
19277298Sobrien  char e_minalloc[2];		/* Minimum extra paragraphs needed, 0x0.  */
19377298Sobrien  char e_maxalloc[2];		/* Maximum extra paragraphs needed, 0xFFFF.  */
19477298Sobrien  char e_ss[2];			/* Initial (relative) SS value, 0x0.  */
19577298Sobrien  char e_sp[2];			/* Initial SP value, 0xb8.  */
19677298Sobrien  char e_csum[2];		/* Checksum, 0x0.  */
19777298Sobrien  char e_ip[2];			/* Initial IP value, 0x0.  */
19877298Sobrien  char e_cs[2];			/* Initial (relative) CS value, 0x0.  */
19977298Sobrien  char e_lfarlc[2];		/* File address of relocation table, 0x40.  */
20077298Sobrien  char e_ovno[2];		/* Overlay number, 0x0.  */
20177298Sobrien  char e_res[4][2];		/* Reserved words, all 0x0.  */
20277298Sobrien  char e_oemid[2];		/* OEM identifier (for e_oeminfo), 0x0.  */
20377298Sobrien  char e_oeminfo[2];		/* OEM information; e_oemid specific, 0x0.  */
20477298Sobrien  char e_res2[10][2];		/* Reserved words, all 0x0.  */
20577298Sobrien  char e_lfanew[4];		/* File address of new exe header, usually 0x80.  */
20677298Sobrien  char dos_message[16][4];	/* Other stuff, always follow DOS header.  */
20733965Sjdp
20877298Sobrien  /* Note: additional bytes may be inserted before the signature.  Use
20977298Sobrien   the e_lfanew field to find the actual location of the NT signature.  */
21033965Sjdp
21177298Sobrien  char nt_signature[4];		/* required NT signature, 0x4550.  */
21233965Sjdp
21377298Sobrien  /* From standard header.  */
21477298Sobrien  char f_magic[2];		/* Magic number.		*/
21577298Sobrien  char f_nscns[2];		/* Number of sections.		*/
21677298Sobrien  char f_timdat[4];		/* Time & date stamp.		*/
21777298Sobrien  char f_symptr[4];		/* File pointer to symtab.	*/
21877298Sobrien  char f_nsyms[4];		/* Number of symtab entries.	*/
21977298Sobrien  char f_opthdr[2];		/* Sizeof(optional hdr).	*/
22077298Sobrien  char f_flags[2];		/* Flags.			*/
22133965Sjdp};
22233965Sjdp
22360484Sobrien#ifdef COFF_IMAGE_WITH_PE
22433965Sjdp
22560484Sobrien/* The filehdr is only weird in images.  */
22660484Sobrien
22760484Sobrien#undef  FILHDR
22860484Sobrien#define FILHDR struct external_PEI_filehdr
22960484Sobrien#undef  FILHSZ
23033965Sjdp#define FILHSZ 152
23133965Sjdp
23260484Sobrien#endif /* COFF_IMAGE_WITH_PE */
23333965Sjdp
23477298Sobrien/* 32-bit PE a.out header: */
23577298Sobrien
23633965Sjdptypedef struct
23733965Sjdp{
23833965Sjdp  AOUTHDR standard;
23933965Sjdp
24077298Sobrien  /* NT extra fields; see internal.h for descriptions.  */
24133965Sjdp  char  ImageBase[4];
24233965Sjdp  char  SectionAlignment[4];
24333965Sjdp  char  FileAlignment[4];
24433965Sjdp  char  MajorOperatingSystemVersion[2];
24533965Sjdp  char  MinorOperatingSystemVersion[2];
24633965Sjdp  char  MajorImageVersion[2];
24733965Sjdp  char  MinorImageVersion[2];
24833965Sjdp  char  MajorSubsystemVersion[2];
24933965Sjdp  char  MinorSubsystemVersion[2];
25033965Sjdp  char  Reserved1[4];
25133965Sjdp  char  SizeOfImage[4];
25233965Sjdp  char  SizeOfHeaders[4];
25333965Sjdp  char  CheckSum[4];
25433965Sjdp  char  Subsystem[2];
25533965Sjdp  char  DllCharacteristics[2];
25633965Sjdp  char  SizeOfStackReserve[4];
25733965Sjdp  char  SizeOfStackCommit[4];
25833965Sjdp  char  SizeOfHeapReserve[4];
25933965Sjdp  char  SizeOfHeapCommit[4];
26033965Sjdp  char  LoaderFlags[4];
26133965Sjdp  char  NumberOfRvaAndSizes[4];
26277298Sobrien  /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];  */
26377298Sobrien  char  DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars.  */
26433965Sjdp} PEAOUTHDR;
265218822Sdim
26633965Sjdp#undef AOUTSZ
26733965Sjdp#define AOUTSZ (AOUTHDRSZ + 196)
26833965Sjdp
26977298Sobrien/* Like PEAOUTHDR, except that the "standard" member has no BaseOfData
27077298Sobrien   (aka data_start) member and that some of the members are 8 instead
27177298Sobrien   of just 4 bytes long.  */
27277298Sobrientypedef struct
27377298Sobrien{
274218822Sdim#ifdef AOUTHDRSZ64
275218822Sdim  AOUTHDR64 standard;
276218822Sdim#else
27777298Sobrien  AOUTHDR standard;
278218822Sdim#endif
27977298Sobrien  /* NT extra fields; see internal.h for descriptions.  */
28077298Sobrien  char  ImageBase[8];
28177298Sobrien  char  SectionAlignment[4];
28277298Sobrien  char  FileAlignment[4];
28377298Sobrien  char  MajorOperatingSystemVersion[2];
28477298Sobrien  char  MinorOperatingSystemVersion[2];
28577298Sobrien  char  MajorImageVersion[2];
28677298Sobrien  char  MinorImageVersion[2];
28777298Sobrien  char  MajorSubsystemVersion[2];
28877298Sobrien  char  MinorSubsystemVersion[2];
28977298Sobrien  char  Reserved1[4];
29077298Sobrien  char  SizeOfImage[4];
29177298Sobrien  char  SizeOfHeaders[4];
29277298Sobrien  char  CheckSum[4];
29377298Sobrien  char  Subsystem[2];
29477298Sobrien  char  DllCharacteristics[2];
29577298Sobrien  char  SizeOfStackReserve[8];
29677298Sobrien  char  SizeOfStackCommit[8];
29777298Sobrien  char  SizeOfHeapReserve[8];
29877298Sobrien  char  SizeOfHeapCommit[8];
29977298Sobrien  char  LoaderFlags[4];
30077298Sobrien  char  NumberOfRvaAndSizes[4];
30177298Sobrien  /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];  */
30277298Sobrien  char  DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars.  */
30378828Sobrien} PEPAOUTHDR;
304218822Sdim
305218822Sdim#ifdef AOUTHDRSZ64
306218822Sdim#define PEPAOUTSZ	(AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */
307218822Sdim#else
30878828Sobrien#define PEPAOUTSZ	240
309218822Sdim#endif
31077298Sobrien
31133965Sjdp#undef  E_FILNMLEN
31277298Sobrien#define E_FILNMLEN	18	/* # characters in a file name.  */
31333965Sjdp
31460484Sobrien/* Import Tyoes fot ILF format object files..  */
31560484Sobrien#define IMPORT_CODE	0
31660484Sobrien#define IMPORT_DATA	1
31760484Sobrien#define IMPORT_CONST	2
31833965Sjdp
31960484Sobrien/* Import Name Tyoes for ILF format object files.  */
32060484Sobrien#define IMPORT_ORDINAL		0
32160484Sobrien#define IMPORT_NAME		1
32260484Sobrien#define IMPORT_NAME_NOPREFIX	2
32360484Sobrien#define IMPORT_NAME_UNDECORATE	3
32433965Sjdp
325218822Sdim/* Weak external characteristics.  */
326218822Sdim#define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY	1
327218822Sdim#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY	2
328218822Sdim#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS		3
329218822Sdim
33060484Sobrien#endif /* _PE_H */
331