Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

coff_s.h

Go to the documentation of this file.
00001 /* 
00002  *      HT Editor
00003  *      coff_s.h
00004  *
00005  *      Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de)
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 version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifndef __COFF_S_H_
00022 #define __COFF_S_H_
00023 
00024 #include "global.h"
00025 #include "tools.h"
00026 
00027 typedef unsigned int RVA;
00028 
00029 typedef struct  COFF_HEADER {
00030         word machine HTPACKED;
00031         word section_count HTPACKED;
00032         dword timestamp HTPACKED;
00033         dword symbol_table_offset HTPACKED;
00034         dword symbol_count HTPACKED;
00035         word optional_header_size HTPACKED;
00036         word characteristics HTPACKED;
00037 };
00038 
00039 #define COFF_RELOCS_STRIPPED                    0x0001  // Relocation info stripped from file.
00040 #define COFF_EXECUTABLE_IMAGE                   0x0002  // File is executable  (i.e. no unresolved externel references).
00041 #define COFF_LINE_NUMS_STRIPPED                 0x0004  // Line nunbers stripped from file.
00042 #define COFF_LOCAL_SYMS_STRIPPED                0x0008  // Local symbols stripped from file.
00043 #define COFF_AGGRESIVE_WS_TRIM                  0x0010  // Agressively trim working set
00044 #define COFF_BYTES_REVERSED_LO                  0x0080  // Bytes of machine word are reversed.
00045 #define COFF_32BIT_MACHINE                      0x0100  // 32 bit word machine.
00046 #define COFF_DEBUG_STRIPPED                     0x0200  // Debugging info stripped from file in .DBG file
00047 #define COFF_REMOVABLE_RUN_FROM_SWAP            0x0400  // If Image is on removable media, copy and run from the swap file.
00048 #define COFF_NET_RUN_FROM_SWAP                  0x0800  // If Image is on Net, copy and run from the swap file.
00049 #define COFF_SYSTEM                             0x1000  // System File.
00050 #define COFF_DLL                                0x2000  // File is a DLL.
00051 #define COFF_UP_SYSTEM_ONLY                     0x4000  // File should only be run on a UP machine
00052 #define COFF_BYTES_REVERSED_HI                  0x8000  // Bytes of machine word are reversed.
00053 
00054 #define COFF_MACHINE_UNKNOWN                    0
00055 #define COFF_MACHINE_I386                       0x14c   // Intel 386
00056 #define COFF_MACHINE_I486                       0x14d   // Intel 486
00057 #define COFF_MACHINE_I586                       0x14e   // Intel 586
00058 #define COFF_MACHINE_R3000BE                    0x160   // MIPS big-endian
00059 #define COFF_MACHINE_R3000                      0x162   // MIPS little-endian
00060 #define COFF_MACHINE_R4000                      0x166   // MIPS little-endian
00061 #define COFF_MACHINE_R10000                     0x168   // MIPS little-endian
00062 #define COFF_MACHINE_ALPHA                      0x184   // Alpha_AXP
00063 #define COFF_MACHINE_SH3                        0x1a2   // Hitachi SH3
00064 #define COFF_MACHINE_SH4                        0x1a6   // Hitachi SH4
00065 #define COFF_MACHINE_ARM                        0x1c0   // ARM
00066 #define COFF_MACHINE_THUMB                      0x1c2   // THUMB
00067 #define COFF_MACHINE_POWERPC_BE                 0x1df   // IBM PowerPC Big-Endian (?)
00068 #define COFF_MACHINE_POWERPC_LE                 0x1f0   // IBM PowerPC Little-Endian
00069 #define COFF_MACHINE_IA64                       0x200   // Intel IA64
00070 #define COFF_MACHINE_MIPS16                     0x266   // MIPS16
00071 #define COFF_MACHINE_68k                        0x268   // Motorola 68k
00072 #define COFF_MACHINE_ALPHA_AXP_64               0x284   // Alpha AXP 64
00073 #define COFF_MACHINE_MIPSf                      0x366   // MIPSf
00074 #define COFF_MACHINE_MIPS16f                    0x466   // MIPS16f
00075 #define COFF_MACHINE_AMD_HAMMER                 0x8664  // AMD Hammer
00076 
00077 // FIXME: not yet implemented: XCOFF64, no sample file available
00078 //#define COFF_MACHINE_POWERPC64_BE             0x1ef   // XCOFF 64Bit Big-Endian (PowerPC only ?)
00079 
00080 //
00081 // Optional header format.
00082 //
00083 
00084 #define COFF_OPTSIZE_0                          0x00
00085 
00086 #define COFF_OPTSIZE_COFF32                     0x1c
00087 #define COFF_OPTSIZE_XCOFF32                    0x48
00088 
00089 #define COFF_OPTSIZE_PE32                       0xe0
00090 
00091 
00092 #define COFF_OPTMAGIC_ROMIMAGE                  0x107
00093 
00094 #define COFF_OPTMAGIC_PE32                      0x10b
00095 #define COFF_OPTMAGIC_COFF32                    0x10b
00096 
00097 #define COFF_OPTMAGIC_PE64                      0x20b
00098 
00099 typedef struct  COFF_OPTIONAL_HEADER32 {
00100         word magic HTPACKED;
00101         byte major_linker_version HTPACKED;
00102         byte minor_linker_version HTPACKED;
00103         dword code_size HTPACKED;
00104         dword data_size HTPACKED;
00105         dword bss_size HTPACKED;
00106         dword entrypoint_address HTPACKED;
00107         dword code_base HTPACKED;
00108         dword data_base HTPACKED;
00109 };
00110 
00111 /*
00112  *      same as COFF_OPTIONAL_HEADER32 but no data_base
00113  */
00114 typedef struct  COFF_OPTIONAL_HEADER64 {
00115         word magic HTPACKED;
00116         byte major_linker_version HTPACKED;
00117         byte minor_linker_version HTPACKED;
00118         dword code_size HTPACKED;
00119         dword data_size HTPACKED;
00120         dword bss_size HTPACKED;
00121         dword entrypoint_address HTPACKED;
00122         dword code_base HTPACKED;
00123 };
00124 
00125 /*
00126  *      Section header
00127  */
00128 
00129 #define COFF_SIZEOF_SHORT_NAME                  8
00130 
00131 struct COFF_SECTION_HEADER {
00132         byte name[COFF_SIZEOF_SHORT_NAME] HTPACKED;
00133         dword data_vsize HTPACKED;      // or data_phys_address !
00134         dword data_address HTPACKED;
00135         dword data_size HTPACKED;
00136         dword data_offset HTPACKED;
00137         dword relocation_offset HTPACKED;
00138         dword linenumber_offset HTPACKED;
00139         word relocation_count HTPACKED;
00140         word linenumber_count HTPACKED;
00141         dword characteristics HTPACKED;
00142 };
00143 
00144 #define COFF_SIZEOF_SECTION_HEADER              40
00145 
00146 /*
00147  * Section characteristics.
00148  */
00149 
00150 //      COFF_SCN_TYPE_REG                       0x00000000  // Reserved.
00151 //      COFF_SCN_TYPE_DSECT                     0x00000001  // Reserved.
00152 //      COFF_SCN_TYPE_NOLOAD                    0x00000002  // Reserved.
00153 //      COFF_SCN_TYPE_GROUP                     0x00000004  // Reserved.
00154 #define COFF_SCN_TYPE_NO_PAD                    0x00000008  // Reserved.
00155 //      COFF_SCN_TYPE_COPY                      0x00000010  // Reserved.
00156 
00157 #define COFF_SCN_CNT_CODE                       0x00000020      // Section contains code.
00158 #define COFF_SCN_CNT_INITIALIZED_DATA           0x00000040      // Section contains initialized data.
00159 #define COFF_SCN_CNT_UNINITIALIZED_DATA         0x00000080      // Section contains uninitialized data.
00160 
00161 #define COFF_SCN_LNK_OTHER                      0x00000100      // Reserved.
00162 #define COFF_SCN_LNK_INFO                       0x00000200      // Section contains comments or some other type of information.
00163 //      COFF_SCN_TYPE_OVER                      0x00000400      // Reserved.
00164 #define COFF_SCN_LNK_REMOVE                     0x00000800      // Section contents will not become part of image.
00165 #define COFF_SCN_LNK_COMDAT                     0x00001000      // Section contents comdat.
00166 //                                              0x00002000      // Reserved.
00167 
00168 //      COFF_SCN_MEM_PROTECTED - Obsolete       0x00004000
00169 #define COFF_SCN_MEM_FARDATA                    0x00008000
00170 //      COFF_SCN_MEM_SYSHEAP  - Obsolete        0x00010000
00171 #define COFF_SCN_MEM_PURGEABLE                  0x00020000
00172 #define COFF_SCN_MEM_16BIT                      0x00020000
00173 #define COFF_SCN_MEM_LOCKED                     0x00040000
00174 #define COFF_SCN_MEM_PRELOAD                    0x00080000
00175 
00176 #define COFF_SCN_ALIGN_1BYTES                   0x00100000      //
00177 #define COFF_SCN_ALIGN_2BYTES                   0x00200000      //
00178 #define COFF_SCN_ALIGN_4BYTES                   0x00300000      //
00179 #define COFF_SCN_ALIGN_8BYTES                   0x00400000      //
00180 #define COFF_SCN_ALIGN_16BYTES                  0x00500000      // Default alignment if no others are specified.
00181 #define COFF_SCN_ALIGN_32BYTES                  0x00600000      //
00182 #define COFF_SCN_ALIGN_64BYTES                  0x00700000      //
00183 // Unused                                       0x00800000
00184 
00185 #define COFF_SCN_LNK_NRELOC_OVFL                0x01000000      // Section contains extended relocations.
00186 #define COFF_SCN_MEM_DISCARDABLE                0x02000000      // Section can be discarded.
00187 #define COFF_SCN_MEM_NOT_CACHED                 0x04000000      // Section is not cachable.
00188 #define COFF_SCN_MEM_NOT_PAGED                  0x08000000      // Section is not pageable.
00189 #define COFF_SCN_MEM_SHARED                     0x10000000      // Section is shareable.
00190 #define COFF_SCN_MEM_EXECUTE                    0x20000000      // Section is executable.
00191 #define COFF_SCN_MEM_READ                       0x40000000      // Section is readable.
00192 #define COFF_SCN_MEM_WRITE                      0x80000000      // Section is writeable.
00193 
00194 extern byte COFF_HEADER_struct[];
00195 extern byte COFF_OPTIONAL_HEADER32_struct[];
00196 extern byte COFF_OPTIONAL_HEADER64_struct[];
00197 extern byte COFF_SECTION_HEADER_struct[];
00198 
00199 #endif /* !__COFF_S_H_ */

Generated on Fri May 7 21:15:29 2004 by doxygen 1.3.5