Back to index

cell-binutils  2.17cvs20070401
pe.h
Go to the documentation of this file.
00001 /* pe.h  -  PE COFF header information 
00002 
00003    Copyright 1999, 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
00004 
00005    This file is part of BFD, the Binary File Descriptor library.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software Foundation,
00019    Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 #ifndef _PE_H
00021 #define _PE_H
00022 
00023 /* NT specific file attributes.  */
00024 #define IMAGE_FILE_RELOCS_STRIPPED           0x0001
00025 #define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002
00026 #define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004
00027 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008
00028 #define IMAGE_FILE_AGGRESSIVE_WS_TRIM        0x0010
00029 #define IMAGE_FILE_LARGE_ADDRESS_AWARE       0x0020
00030 #define IMAGE_FILE_16BIT_MACHINE             0x0040
00031 #define IMAGE_FILE_BYTES_REVERSED_LO         0x0080
00032 #define IMAGE_FILE_32BIT_MACHINE             0x0100
00033 #define IMAGE_FILE_DEBUG_STRIPPED            0x0200
00034 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP   0x0400
00035 #define IMAGE_FILE_NET_RUN_FROM_SWAP         0x0800
00036 #define IMAGE_FILE_SYSTEM                    0x1000
00037 #define IMAGE_FILE_DLL                       0x2000
00038 #define IMAGE_FILE_UP_SYSTEM_ONLY            0x4000
00039 #define IMAGE_FILE_BYTES_REVERSED_HI         0x8000
00040 
00041 /* Additional flags to be set for section headers to allow the NT loader to
00042    read and write to the section data (to replace the addresses of data in
00043    dlls for one thing); also to execute the section in .text's case.  */
00044 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
00045 #define IMAGE_SCN_MEM_EXECUTE     0x20000000
00046 #define IMAGE_SCN_MEM_READ        0x40000000
00047 #define IMAGE_SCN_MEM_WRITE       0x80000000
00048 
00049 /* Section characteristics added for ppc-nt.  */
00050 
00051 #define IMAGE_SCN_TYPE_NO_PAD                0x00000008  /* Reserved. */
00052 
00053 #define IMAGE_SCN_CNT_CODE                   0x00000020  /* Section contains code. */
00054 #define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  /* Section contains initialized data. */
00055 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  /* Section contains uninitialized data. */
00056 
00057 #define IMAGE_SCN_LNK_OTHER                  0x00000100  /* Reserved. */
00058 #define IMAGE_SCN_LNK_INFO                   0x00000200  /* Section contains comments or some other type of information. */
00059 #define IMAGE_SCN_LNK_REMOVE                 0x00000800  /* Section contents will not become part of image. */
00060 #define IMAGE_SCN_LNK_COMDAT                 0x00001000  /* Section contents comdat. */
00061 
00062 #define IMAGE_SCN_MEM_FARDATA                0x00008000
00063 
00064 #define IMAGE_SCN_MEM_PURGEABLE              0x00020000
00065 #define IMAGE_SCN_MEM_16BIT                  0x00020000
00066 #define IMAGE_SCN_MEM_LOCKED                 0x00040000
00067 #define IMAGE_SCN_MEM_PRELOAD                0x00080000
00068 
00069 #define IMAGE_SCN_ALIGN_1BYTES               0x00100000
00070 #define IMAGE_SCN_ALIGN_2BYTES               0x00200000
00071 #define IMAGE_SCN_ALIGN_4BYTES               0x00300000
00072 #define IMAGE_SCN_ALIGN_8BYTES               0x00400000
00073 #define IMAGE_SCN_ALIGN_16BYTES              0x00500000  /* Default alignment if no others are specified. */
00074 #define IMAGE_SCN_ALIGN_32BYTES              0x00600000
00075 #define IMAGE_SCN_ALIGN_64BYTES              0x00700000
00076 
00077 #define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  /* Section contains extended relocations. */
00078 #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  /* Section is not cachable.               */
00079 #define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  /* Section is not pageable.               */
00080 #define IMAGE_SCN_MEM_SHARED                 0x10000000  /* Section is shareable.                  */
00081 
00082 /* COMDAT selection codes.  */
00083 
00084 #define IMAGE_COMDAT_SELECT_NODUPLICATES     (1) /* Warn if duplicates.  */
00085 #define IMAGE_COMDAT_SELECT_ANY                (2) /* No warning.  */
00086 #define IMAGE_COMDAT_SELECT_SAME_SIZE          (3) /* Warn if different size.  */
00087 #define IMAGE_COMDAT_SELECT_EXACT_MATCH        (4) /* Warn if different.  */
00088 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE        (5) /* Base on other section.  */
00089 
00090 /* Machine numbers.  */
00091 
00092 #define IMAGE_FILE_MACHINE_UNKNOWN           0x0000
00093 #define IMAGE_FILE_MACHINE_ALPHA             0x0184
00094 #define IMAGE_FILE_MACHINE_ALPHA64           0x0284
00095 #define IMAGE_FILE_MACHINE_AM33              0x01d3
00096 #define IMAGE_FILE_MACHINE_AMD64             0x8664
00097 #define IMAGE_FILE_MACHINE_ARM               0x01c0
00098 #define IMAGE_FILE_MACHINE_AXP64             IMAGE_FILE_MACHINE_ALPHA64
00099 #define IMAGE_FILE_MACHINE_CEE               0xc0ee
00100 #define IMAGE_FILE_MACHINE_CEF               0x0cef
00101 #define IMAGE_FILE_MACHINE_EBC               0x0ebc
00102 #define IMAGE_FILE_MACHINE_I386              0x014c
00103 #define IMAGE_FILE_MACHINE_IA64              0x0200
00104 #define IMAGE_FILE_MACHINE_M32R              0x9041
00105 #define IMAGE_FILE_MACHINE_M68K              0x0268
00106 #define IMAGE_FILE_MACHINE_MIPS16            0x0266
00107 #define IMAGE_FILE_MACHINE_MIPSFPU           0x0366
00108 #define IMAGE_FILE_MACHINE_MIPSFPU16         0x0466
00109 #define IMAGE_FILE_MACHINE_POWERPC           0x01f0
00110 #define IMAGE_FILE_MACHINE_POWERPCFP         0x01f1
00111 #define IMAGE_FILE_MACHINE_R10000            0x0168
00112 #define IMAGE_FILE_MACHINE_R3000             0x0162
00113 #define IMAGE_FILE_MACHINE_R4000             0x0166
00114 #define IMAGE_FILE_MACHINE_SH3               0x01a2
00115 #define IMAGE_FILE_MACHINE_SH3DSP            0x01a3
00116 #define IMAGE_FILE_MACHINE_SH3E              0x01a4
00117 #define IMAGE_FILE_MACHINE_SH4               0x01a6
00118 #define IMAGE_FILE_MACHINE_SH5               0x01a8
00119 #define IMAGE_FILE_MACHINE_THUMB             0x01c2
00120 #define IMAGE_FILE_MACHINE_TRICORE           0x0520
00121 #define IMAGE_FILE_MACHINE_WCEMIPSV2         0x0169
00122 #define IMAGE_FILE_MACHINE_AMD64             0x8664
00123 
00124 #define IMAGE_SUBSYSTEM_UNKNOWN                   0
00125 #define IMAGE_SUBSYSTEM_NATIVE                    1
00126 #define IMAGE_SUBSYSTEM_WINDOWS_GUI               2
00127 #define IMAGE_SUBSYSTEM_WINDOWS_CUI               3
00128 #define IMAGE_SUBSYSTEM_POSIX_CUI          7
00129 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI            9
00130 #define IMAGE_SUBSYSTEM_EFI_APPLICATION          10
00131 #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER  11
00132 #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER       12
00133 #define IMAGE_SUBSYSTEM_EFI_ROM                  13
00134 #define IMAGE_SUBSYSTEM_XBOX                     14
00135   
00136 /* Magic values that are true for all dos/nt implementations.  */
00137 #define DOSMAGIC       0x5a4d  
00138 #define NT_SIGNATURE   0x00004550
00139 
00140 /* NT allows long filenames, we want to accommodate this.
00141    This may break some of the bfd functions.  */
00142 #undef  FILNMLEN
00143 #define FILNMLEN     18     /* # characters in a file name.  */
00144 
00145 struct external_PEI_DOS_hdr
00146 {
00147   /* DOS header fields - always at offset zero in the EXE file.  */
00148   char e_magic[2];          /* Magic number, 0x5a4d.  */
00149   char e_cblp[2];           /* Bytes on last page of file, 0x90.  */
00150   char e_cp[2];                    /* Pages in file, 0x3.  */
00151   char e_crlc[2];           /* Relocations, 0x0.  */
00152   char e_cparhdr[2];        /* Size of header in paragraphs, 0x4.  */
00153   char e_minalloc[2];              /* Minimum extra paragraphs needed, 0x0.  */
00154   char e_maxalloc[2];              /* Maximum extra paragraphs needed, 0xFFFF.  */
00155   char e_ss[2];                    /* Initial (relative) SS value, 0x0.  */
00156   char e_sp[2];                    /* Initial SP value, 0xb8.  */
00157   char e_csum[2];           /* Checksum, 0x0.  */
00158   char e_ip[2];                    /* Initial IP value, 0x0.  */
00159   char e_cs[2];                    /* Initial (relative) CS value, 0x0.  */
00160   char e_lfarlc[2];         /* File address of relocation table, 0x40.  */
00161   char e_ovno[2];           /* Overlay number, 0x0.  */
00162   char e_res[4][2];         /* Reserved words, all 0x0.  */
00163   char e_oemid[2];          /* OEM identifier (for e_oeminfo), 0x0.  */
00164   char e_oeminfo[2];        /* OEM information; e_oemid specific, 0x0.  */
00165   char e_res2[10][2];              /* Reserved words, all 0x0.  */
00166   char e_lfanew[4];         /* File address of new exe header, usually 0x80.  */
00167   char dos_message[16][4];  /* Other stuff, always follow DOS header.  */
00168 };
00169 
00170 struct external_PEI_IMAGE_hdr
00171 {
00172   char nt_signature[4];            /* required NT signature, 0x4550.  */
00173 
00174   /* From standard header.  */
00175   char f_magic[2];          /* Magic number.            */
00176   char f_nscns[2];          /* Number of sections.             */
00177   char f_timdat[4];         /* Time & date stamp.              */
00178   char f_symptr[4];         /* File pointer to symtab.  */
00179   char f_nsyms[4];          /* Number of symtab entries.       */
00180   char f_opthdr[2];         /* Sizeof(optional hdr).    */
00181   char f_flags[2];          /* Flags.                   */
00182 };
00183 
00184 struct external_PEI_filehdr
00185 {
00186   /* DOS header fields - always at offset zero in the EXE file.  */
00187   char e_magic[2];          /* Magic number, 0x5a4d.  */
00188   char e_cblp[2];           /* Bytes on last page of file, 0x90.  */
00189   char e_cp[2];                    /* Pages in file, 0x3.  */
00190   char e_crlc[2];           /* Relocations, 0x0.  */
00191   char e_cparhdr[2];        /* Size of header in paragraphs, 0x4.  */
00192   char e_minalloc[2];              /* Minimum extra paragraphs needed, 0x0.  */
00193   char e_maxalloc[2];              /* Maximum extra paragraphs needed, 0xFFFF.  */
00194   char e_ss[2];                    /* Initial (relative) SS value, 0x0.  */
00195   char e_sp[2];                    /* Initial SP value, 0xb8.  */
00196   char e_csum[2];           /* Checksum, 0x0.  */
00197   char e_ip[2];                    /* Initial IP value, 0x0.  */
00198   char e_cs[2];                    /* Initial (relative) CS value, 0x0.  */
00199   char e_lfarlc[2];         /* File address of relocation table, 0x40.  */
00200   char e_ovno[2];           /* Overlay number, 0x0.  */
00201   char e_res[4][2];         /* Reserved words, all 0x0.  */
00202   char e_oemid[2];          /* OEM identifier (for e_oeminfo), 0x0.  */
00203   char e_oeminfo[2];        /* OEM information; e_oemid specific, 0x0.  */
00204   char e_res2[10][2];              /* Reserved words, all 0x0.  */
00205   char e_lfanew[4];         /* File address of new exe header, usually 0x80.  */
00206   char dos_message[16][4];  /* Other stuff, always follow DOS header.  */
00207 
00208   /* Note: additional bytes may be inserted before the signature.  Use
00209    the e_lfanew field to find the actual location of the NT signature.  */
00210 
00211   char nt_signature[4];            /* required NT signature, 0x4550.  */
00212 
00213   /* From standard header.  */
00214   char f_magic[2];          /* Magic number.            */
00215   char f_nscns[2];          /* Number of sections.             */
00216   char f_timdat[4];         /* Time & date stamp.              */
00217   char f_symptr[4];         /* File pointer to symtab.  */
00218   char f_nsyms[4];          /* Number of symtab entries.       */
00219   char f_opthdr[2];         /* Sizeof(optional hdr).    */
00220   char f_flags[2];          /* Flags.                   */
00221 };
00222 
00223 #ifdef COFF_IMAGE_WITH_PE
00224 
00225 /* The filehdr is only weird in images.  */
00226 
00227 #undef  FILHDR
00228 #define FILHDR struct external_PEI_filehdr
00229 #undef  FILHSZ
00230 #define FILHSZ 152
00231 
00232 #endif /* COFF_IMAGE_WITH_PE */
00233 
00234 /* 32-bit PE a.out header: */
00235 
00236 typedef struct 
00237 {
00238   AOUTHDR standard;
00239 
00240   /* NT extra fields; see internal.h for descriptions.  */
00241   char  ImageBase[4];
00242   char  SectionAlignment[4];
00243   char  FileAlignment[4];
00244   char  MajorOperatingSystemVersion[2];
00245   char  MinorOperatingSystemVersion[2];
00246   char  MajorImageVersion[2];
00247   char  MinorImageVersion[2];
00248   char  MajorSubsystemVersion[2];
00249   char  MinorSubsystemVersion[2];
00250   char  Reserved1[4];
00251   char  SizeOfImage[4];
00252   char  SizeOfHeaders[4];
00253   char  CheckSum[4];
00254   char  Subsystem[2];
00255   char  DllCharacteristics[2];
00256   char  SizeOfStackReserve[4];
00257   char  SizeOfStackCommit[4];
00258   char  SizeOfHeapReserve[4];
00259   char  SizeOfHeapCommit[4];
00260   char  LoaderFlags[4];
00261   char  NumberOfRvaAndSizes[4];
00262   /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];  */
00263   char  DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars.  */
00264 } PEAOUTHDR;
00265 
00266 #undef AOUTSZ
00267 #define AOUTSZ (AOUTHDRSZ + 196)
00268 
00269 /* Like PEAOUTHDR, except that the "standard" member has no BaseOfData
00270    (aka data_start) member and that some of the members are 8 instead
00271    of just 4 bytes long.  */
00272 typedef struct 
00273 {
00274 #ifdef AOUTHDRSZ64
00275   AOUTHDR64 standard;
00276 #else
00277   AOUTHDR standard;
00278 #endif
00279   /* NT extra fields; see internal.h for descriptions.  */
00280   char  ImageBase[8];
00281   char  SectionAlignment[4];
00282   char  FileAlignment[4];
00283   char  MajorOperatingSystemVersion[2];
00284   char  MinorOperatingSystemVersion[2];
00285   char  MajorImageVersion[2];
00286   char  MinorImageVersion[2];
00287   char  MajorSubsystemVersion[2];
00288   char  MinorSubsystemVersion[2];
00289   char  Reserved1[4];
00290   char  SizeOfImage[4];
00291   char  SizeOfHeaders[4];
00292   char  CheckSum[4];
00293   char  Subsystem[2];
00294   char  DllCharacteristics[2];
00295   char  SizeOfStackReserve[8];
00296   char  SizeOfStackCommit[8];
00297   char  SizeOfHeapReserve[8];
00298   char  SizeOfHeapCommit[8];
00299   char  LoaderFlags[4];
00300   char  NumberOfRvaAndSizes[4];
00301   /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];  */
00302   char  DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars.  */
00303 } PEPAOUTHDR;
00304 
00305 #ifdef AOUTHDRSZ64
00306 #define PEPAOUTSZ    (AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */
00307 #else
00308 #define PEPAOUTSZ    240
00309 #endif
00310   
00311 #undef  E_FILNMLEN
00312 #define E_FILNMLEN   18     /* # characters in a file name.  */
00313 
00314 /* Import Tyoes fot ILF format object files..  */
00315 #define IMPORT_CODE  0
00316 #define IMPORT_DATA  1
00317 #define IMPORT_CONST 2
00318 
00319 /* Import Name Tyoes for ILF format object files.  */
00320 #define IMPORT_ORDINAL             0
00321 #define IMPORT_NAME         1
00322 #define IMPORT_NAME_NOPREFIX       2
00323 #define IMPORT_NAME_UNDECORATE     3
00324 
00325 /* Weak external characteristics.  */
00326 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY       1
00327 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY  2
00328 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS           3
00329 
00330 #endif /* _PE_H */