toolsandutils/e32tools/inc/pe_defs.h
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #if !defined(__PE_DEFS_H__)
       
    17 #define __PE_DEFS_H__
       
    18 
       
    19 // A few additions to winnnt.h
       
    20 
       
    21 #define IMAGE_FILE_MINIMAL_OBJECT			0x0010
       
    22 #define IMAGE_FILE_UPDATE_OBJECT			0x0020
       
    23 #define IMAGE_FILE_16BIT_MACHINE			0x0040
       
    24 #define IMAGE_FILE_PATCH					0x0400
       
    25 #define IMAGE_FILE_MACHINE_I860				0x014d
       
    26 
       
    27 #define IMAGE_LIBRARY_PROCESS_INIT			0x0001
       
    28 #define IMAGE_LIBRARY_PROCESS_TERM			0x0002
       
    29 #define IMAGE_LIBRARY_THREAD_INIT			0x0004
       
    30 #define IMAGE_LIBRARY_THREAD_TERM			0x0008
       
    31 
       
    32 #define IMAGE_LOADER_FLAGS_BREAK_ON_LOAD	0x0001
       
    33 #define IMAGE_LOADER_FLAGS_DEBUG_ON_LOAD	0x0002 
       
    34 
       
    35 #define IMAGE_SCN_LNK_OVERLAY				0x00000400 
       
    36 
       
    37 
       
    38 //
       
    39 // Image Format	(copied entire from winnt.h)
       
    40 //
       
    41 
       
    42 #define IMAGE_DOS_SIGNATURE                 0x5A4D      // MZ
       
    43 #define IMAGE_OS2_SIGNATURE                 0x454E      // NE
       
    44 #define IMAGE_OS2_SIGNATURE_LE              0x454C      // LE
       
    45 #define IMAGE_NT_SIGNATURE                  0x00004550  // PE00
       
    46 
       
    47 typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
       
    48     TUint16   e_magic;                     // Magic number
       
    49     TUint16   e_cblp;                      // TUint8 on last page of file
       
    50     TUint16   e_cp;                        // Pages in file
       
    51     TUint16   e_crlc;                      // Relocations
       
    52     TUint16   e_cparhdr;                   // Size of header in paragraphs
       
    53     TUint16   e_minalloc;                  // Minimum extra paragraphs needed
       
    54     TUint16   e_maxalloc;                  // Maximum extra paragraphs needed
       
    55     TUint16   e_ss;                        // Initial (relative) SS value
       
    56     TUint16   e_sp;                        // Initial SP value
       
    57     TUint16   e_csum;                      // Checksum
       
    58     TUint16   e_ip;                        // Initial IP value
       
    59     TUint16   e_cs;                        // Initial (relative) CS value
       
    60     TUint16   e_lfarlc;                    // File address of relocation table
       
    61     TUint16   e_ovno;                      // Overlay number
       
    62     TUint16   e_res[4];                    // Reserved TUint16s
       
    63     TUint16   e_oemid;                     // OEM identifier (for e_oeminfo)
       
    64     TUint16   e_oeminfo;                   // OEM information; e_oemid specific
       
    65     TUint16   e_res2[10];                  // Reserved TUint16s
       
    66     TUint32   e_lfanew;                    // File address of new exe header
       
    67   } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
       
    68 
       
    69 typedef struct _IMAGE_OS2_HEADER {			// OS/2 .EXE header
       
    70     TUint16		ne_magic;                    // Magic number
       
    71     TUint8		ne_ver;                      // Version number
       
    72     TUint8		ne_rev;                      // Revision number
       
    73     TUint16		ne_enttab;                   // Offset of Entry Table
       
    74     TUint16		ne_cbenttab;                 // Number of TUint8 in Entry Table
       
    75     TUint32		ne_crc;                      // Checksum of whole file
       
    76     TUint16		ne_flags;                    // Flag TUint16
       
    77     TUint16		ne_autodata;                 // Automatic data segment number
       
    78     TUint16		ne_heap;                     // Initial heap allocation
       
    79     TUint16		ne_stack;                    // Initial stack allocation
       
    80     TUint32   ne_csip;                     // Initial CS:IP setting
       
    81     TUint32   ne_sssp;                     // Initial SS:SP setting
       
    82     TUint16   ne_cseg;                     // Count of file segments
       
    83     TUint16   ne_cmod;                     // Entries in Module Reference Table
       
    84     TUint16   ne_cbnrestab;                // Size of non-resident name table
       
    85     TUint16   ne_segtab;                   // Offset of Segment Table
       
    86     TUint16   ne_rsrctab;                  // Offset of Resource Table
       
    87     TUint16   ne_restab;                   // Offset of resident name table
       
    88     TUint16   ne_modtab;                   // Offset of Module Reference Table
       
    89     TUint16   ne_imptab;                   // Offset of Imported Names Table
       
    90     TUint32   ne_nrestab;                  // Offset of Non-resident Names Table
       
    91     TUint16   ne_cmovent;                  // Count of movable entries
       
    92     TUint16   ne_align;                    // Segment alignment shift count
       
    93     TUint16   ne_cres;                     // Count of resource segments
       
    94     TUint8   ne_exetyp;                   // Target Operating system
       
    95     TUint8   ne_flagsothers;              // Other .EXE flags
       
    96     TUint16   ne_pretthunks;               // offset to return thunks
       
    97     TUint16   ne_psegrefTUint8;             // offset to segment ref. TUint8
       
    98     TUint16   ne_swaparea;                 // Minimum code swap area size
       
    99     TUint16   ne_expver;                   // Expected Windows version number
       
   100   } IMAGE_OS2_HEADER, *PIMAGE_OS2_HEADER;
       
   101 
       
   102 //
       
   103 // File header format.
       
   104 //
       
   105 
       
   106 typedef struct _IMAGE_FILE_HEADER
       
   107 	{
       
   108 	TUint16	Machine;
       
   109     TUint16	NumberOfSections;
       
   110     TUint32	TimeDateStamp;
       
   111     TUint32	PointerToSymbolTable;
       
   112     TUint32	NumberOfSymbols;
       
   113     TUint16	SizeOfOptionalHeader;
       
   114     TUint16	Characteristics;
       
   115 	} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
       
   116 
       
   117 #define IMAGE_SIZEOF_FILE_HEADER             20
       
   118 
       
   119 #define IMAGE_FILE_RELOCS_STRIPPED			0x0001  // Relocation info stripped from file.
       
   120 #define IMAGE_FILE_EXECUTABLE_IMAGE			0x0002  // File is executable  (i.e. no unresolved externel references).
       
   121 #define IMAGE_FILE_LINE_NUMS_STRIPPED		0x0004  // Line nunbers stripped from file.
       
   122 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED		0x0008  // Local symbols stripped from file.
       
   123 #define IMAGE_FILE_CHAR_REVERSED_LO			0x0080  // TUint8 of machine TUint16 are reversed.
       
   124 #define IMAGE_FILE_32BIT_MACHINE			0x0100  // 32 bit word machine.
       
   125 #define IMAGE_FILE_DEBUG_STRIPPED			0x0200  // Debugging info stripped from file in .DBG file
       
   126 #define IMAGE_FILE_SYSTEM					0x1000  // System File.
       
   127 #define IMAGE_FILE_DLL						0x2000  // File is a DLL.
       
   128 #define IMAGE_FILE_CHAR_REVERSED_HI			0x8000  // Char of machine short are reversed.
       
   129 
       
   130 #define IMAGE_FILE_MACHINE_UNKNOWN           0
       
   131 #define IMAGE_FILE_MACHINE_I386              0x14c   // Intel 386.
       
   132 #define IMAGE_FILE_MACHINE_R3000             0x162   // MIPS little-endian, 0540 big-endian
       
   133 #define IMAGE_FILE_MACHINE_R4000             0x166   // MIPS little-endian
       
   134 #define IMAGE_FILE_MACHINE_ALPHA             0x184   // Alpha_AXP
       
   135 #define IMAGE_FILE_MACHINE_POWERPC           0x1F0   // IBM PowerPC Little-Endian
       
   136 
       
   137 //
       
   138 // Directory format.
       
   139 //
       
   140 typedef struct _IMAGE_DATA_DIRECTORY
       
   141 	{
       
   142     TUint32	VirtualAddress;
       
   143     TUint32	Size;
       
   144 	} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
       
   145 
       
   146 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16
       
   147 
       
   148 //
       
   149 // Optional header format.
       
   150 //
       
   151 typedef struct _IMAGE_OPTIONAL_HEADER
       
   152 	{
       
   153     //
       
   154     // Standard fields.
       
   155     //
       
   156 
       
   157 	TUint16	Magic;
       
   158     TUint8	MajorLinkerVersion;
       
   159     TUint8	MinorLinkerVersion;
       
   160     TUint32	SizeOfCode;
       
   161     TUint32	SizeOfInitializedData;
       
   162     TUint32	SizeOfUninitializedData;
       
   163     TUint32	AddressOfEntryPoint;
       
   164     TUint32	BaseOfCode;
       
   165     TUint32	BaseOfData;
       
   166 
       
   167     //
       
   168     // NT additional fields.
       
   169     //
       
   170 
       
   171     TUint32	ImageBase;
       
   172     TUint32	SectionAlignment;
       
   173     TUint32	FileAlignment;
       
   174     TUint16	MajorOperatingSystemVersion;
       
   175     TUint16	MinorOperatingSystemVersion;
       
   176     TUint16	MajorImageVersion;
       
   177     TUint16	MinorImageVersion;
       
   178     TUint16	MajorSubsystemVersion;
       
   179     TUint16	MinorSubsystemVersion;
       
   180     TUint32	Reserved1;
       
   181     TUint32	SizeOfImage;
       
   182     TUint32	SizeOfHeaders;
       
   183     TUint32	CheckSum;
       
   184     TUint16	Subsystem;
       
   185     TUint16	DllCharacteristics;
       
   186     TUint32	SizeOfStackReserve;
       
   187     TUint32	SizeOfStackCommit;
       
   188     TUint32	SizeOfHeapReserve;
       
   189     TUint32	SizeOfHeapCommit;
       
   190     TUint32	LoaderFlags;
       
   191     TUint32	NumberOfRvaAndSizes;
       
   192     IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
       
   193 	} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
       
   194 
       
   195 typedef struct _IMAGE_ROM_OPTIONAL_HEADER {
       
   196     TUint16   Magic;
       
   197     TUint8   MajorLinkerVersion;
       
   198     TUint8   MinorLinkerVersion;
       
   199     TUint32  SizeOfCode;
       
   200     TUint32  SizeOfInitializedData;
       
   201     TUint32  SizeOfUninitializedData;
       
   202     TUint32  AddressOfEntryPoint;
       
   203     TUint32  BaseOfCode;
       
   204     TUint32  BaseOfData;
       
   205     TUint32  BaseOfBss;
       
   206     TUint32  GprMask;
       
   207     TUint32  CprMask[4];
       
   208     TUint32  GpValue;
       
   209 } IMAGE_ROM_OPTIONAL_HEADER, *PIMAGE_ROM_OPTIONAL_HEADER;
       
   210 
       
   211 #define IMAGE_SIZEOF_ROM_OPTIONAL_HEADER      56
       
   212 #define IMAGE_SIZEOF_STD_OPTIONAL_HEADER      28
       
   213 #define IMAGE_SIZEOF_NT_OPTIONAL_HEADER      224
       
   214 
       
   215 #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
       
   216 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
       
   217 
       
   218 typedef struct _IMAGE_NT_HEADERS {
       
   219     TUint32 Signature;
       
   220     IMAGE_FILE_HEADER FileHeader;
       
   221     IMAGE_OPTIONAL_HEADER OptionalHeader;
       
   222 } IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
       
   223 
       
   224 typedef struct _IMAGE_ROM_HEADERS {
       
   225     IMAGE_FILE_HEADER FileHeader;
       
   226     IMAGE_ROM_OPTIONAL_HEADER OptionalHeader;
       
   227 } IMAGE_ROM_HEADERS, *PIMAGE_ROM_HEADERS;
       
   228 
       
   229 #define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER)        \
       
   230     ((TUint32)ntheader +                                                  \
       
   231      FIELD_OFFSET( IMAGE_NT_HEADERS, OptionalHeader ) +                 \
       
   232      ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader   \
       
   233     ))
       
   234 
       
   235 
       
   236 // Subsystem Values
       
   237 
       
   238 #define IMAGE_SUBSYSTEM_UNKNOWN              0   // Unknown subsystem.
       
   239 #define IMAGE_SUBSYSTEM_NATIVE               1   // Image doesn't require a subsystem.
       
   240 #define IMAGE_SUBSYSTEM_WINDOWS_GUI          2   // Image runs in the Windows GUI subsystem.
       
   241 #define IMAGE_SUBSYSTEM_WINDOWS_CUI          3   // Image runs in the Windows character subsystem.
       
   242 #define IMAGE_SUBSYSTEM_OS2_CUI              5   // image runs in the OS/2 character subsystem.
       
   243 #define IMAGE_SUBSYSTEM_POSIX_CUI            7   // image run  in the Posix character subsystem.
       
   244 
       
   245 
       
   246 // Directory Entries
       
   247 
       
   248 #define IMAGE_DIRECTORY_ENTRY_EXPORT         0   // Export Directory
       
   249 #define IMAGE_DIRECTORY_ENTRY_IMPORT         1   // Import Directory
       
   250 #define IMAGE_DIRECTORY_ENTRY_RESOURCE       2   // Resource Directory
       
   251 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION      3   // Exception Directory
       
   252 #define IMAGE_DIRECTORY_ENTRY_SECURITY       4   // Security Directory
       
   253 #define IMAGE_DIRECTORY_ENTRY_BASERELOC      5   // Base Relocation Table
       
   254 #define IMAGE_DIRECTORY_ENTRY_DEBUG          6   // Debug Directory
       
   255 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT      7   // Description String
       
   256 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR      8   // Machine Value (MIPS GP)
       
   257 #define IMAGE_DIRECTORY_ENTRY_TLS            9   // TLS Directory
       
   258 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG   10   // Load Configuration Directory
       
   259 
       
   260 //
       
   261 // Section header format.
       
   262 //
       
   263 
       
   264 #define IMAGE_SIZEOF_SHORT_NAME              8
       
   265 
       
   266 typedef struct _IMAGE_SECTION_HEADER {
       
   267     TUint8 		Name[IMAGE_SIZEOF_SHORT_NAME];
       
   268     union	{
       
   269             TUint32   PhysicalAddress;
       
   270             TUint32   VirtualSize;
       
   271     		} Misc;
       
   272     TUint32		VirtualAddress;
       
   273     TUint32		SizeOfRawData;
       
   274     TUint32		PointerToRawData;
       
   275     TUint32		PointerToRelocations;
       
   276     TUint32		PointerToLinenumbers;
       
   277     TUint16		NumberOfRelocations;
       
   278     TUint16		NumberOfLinenumbers;
       
   279     TUint32		Characteristics;
       
   280 } IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
       
   281 
       
   282 #define IMAGE_SIZEOF_SECTION_HEADER          40
       
   283 
       
   284 #define IMAGE_SCN_TYPE_NO_PAD                0x00000008  // Reserved.
       
   285 
       
   286 #define IMAGE_SCN_CNT_CODE                   0x00000020  // Section contains code.
       
   287 #define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  // Section contains initialized data.
       
   288 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  // Section contains uninitialized data.
       
   289 
       
   290 #define IMAGE_SCN_LNK_OTHER                  0x00000100  // Reserved.
       
   291 #define IMAGE_SCN_LNK_INFO                   0x00000200  // Section contains comments or some other type of information.
       
   292 #define IMAGE_SCN_LNK_REMOVE                 0x00000800  // Section contents will not become part of image.
       
   293 #define IMAGE_SCN_LNK_COMDAT                 0x00001000  // Section contents comdat.
       
   294 
       
   295 #define IMAGE_SCN_ALIGN_1Byte               0x00100000  //
       
   296 #define IMAGE_SCN_ALIGN_2Byte               0x00200000  //
       
   297 #define IMAGE_SCN_ALIGN_4Byte               0x00300000  //
       
   298 #define IMAGE_SCN_ALIGN_8Byte               0x00400000  //
       
   299 #define IMAGE_SCN_ALIGN_16Byte              0x00500000  // Default alignment if no others are specified.
       
   300 #define IMAGE_SCN_ALIGN_32Byte              0x00600000  //
       
   301 #define IMAGE_SCN_ALIGN_64Byte              0x00700000  //
       
   302 
       
   303 #define IMAGE_SCN_MEM_DISCARDABLE            0x02000000  // Section can be discarded.
       
   304 #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  // Section is not cachable.
       
   305 #define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  // Section is not pageable.
       
   306 #define IMAGE_SCN_MEM_SHARED                 0x10000000  // Section is shareable.
       
   307 #define IMAGE_SCN_MEM_EXECUTE                0x20000000  // Section is executable.
       
   308 #define IMAGE_SCN_MEM_READ                   0x40000000  // Section is readable.
       
   309 #define IMAGE_SCN_MEM_WRITE                  0x80000000  // Section is writeable.
       
   310 
       
   311 //
       
   312 // Symbol format.
       
   313 //
       
   314 
       
   315 typedef struct _IMAGE_SYMBOL {
       
   316     union {
       
   317         TUint8    ShortName[8];
       
   318         struct {
       
   319             TUint32   Short;     // if 0, use LongName
       
   320             TUint32   Long;      // offset into string table
       
   321         } Name;
       
   322         TUint8   *LongName[2];
       
   323     } N;
       
   324     TUint32   Value;
       
   325     TInt16   SectionNumber;
       
   326     TUint16    Type;
       
   327     TUint8    StorageClass;
       
   328     TUint8    NumberOfAuxSymbols;
       
   329 } IMAGE_SYMBOL;
       
   330 typedef IMAGE_SYMBOL *PIMAGE_SYMBOL;
       
   331 
       
   332 #define IMAGE_SIZEOF_SYMBOL                  18
       
   333 
       
   334 //
       
   335 // Section values.
       
   336 //
       
   337 // Symbols have a section number of the section in which they are
       
   338 // defined. Otherwise, section numbers have the following meanings:
       
   339 //
       
   340 
       
   341 #define IMAGE_SYM_UNDEFINED           (TInt16)0           // Symbol is undefined or is common.
       
   342 #define IMAGE_SYM_ABSOLUTE            (TInt16)-1          // Symbol is an absolute value.
       
   343 #define IMAGE_SYM_DEBUG               (TInt16)-2          // Symbol is a special debug item.
       
   344 
       
   345 //
       
   346 // Type (fundamental) values.
       
   347 //
       
   348 
       
   349 #define IMAGE_SYM_TYPE_NULL                  0           // no type.
       
   350 #define IMAGE_SYM_TYPE_VOID                  1           //
       
   351 #define IMAGE_SYM_TYPE_TUint8                  2           // type character.
       
   352 #define IMAGE_SYM_TYPE_TInt16                 3           // type TInt16 integer.
       
   353 #define IMAGE_SYM_TYPE_INT                   4           //
       
   354 #define IMAGE_SYM_TYPE_TUint32                  5           //
       
   355 #define IMAGE_SYM_TYPE_FLOAT                 6           //
       
   356 #define IMAGE_SYM_TYPE_DOUBLE                7           //
       
   357 #define IMAGE_SYM_TYPE_STRUCT                8           //
       
   358 #define IMAGE_SYM_TYPE_UNION                 9           //
       
   359 #define IMAGE_SYM_TYPE_ENUM                  10          // enumeration.
       
   360 #define IMAGE_SYM_TYPE_MOE                   11          // member of enumeration.
       
   361 #define IMAGE_SYM_TYPE_BYTE                  12          //
       
   362 #define IMAGE_SYM_TYPE_WORD                  13          //
       
   363 #define IMAGE_SYM_TYPE_UINT                  14          //
       
   364 #define IMAGE_SYM_TYPE_DWORD                 15          //
       
   365 
       
   366 //
       
   367 // Type (derived) values.
       
   368 //
       
   369 
       
   370 #define IMAGE_SYM_DTYPE_NULL                 0           // no derived type.
       
   371 #define IMAGE_SYM_DTYPE_POINTER              1           // pointer.
       
   372 #define IMAGE_SYM_DTYPE_FUNCTION             2           // function.
       
   373 #define IMAGE_SYM_DTYPE_ARRAY                3           // array.
       
   374 
       
   375 //
       
   376 // Storage classes.
       
   377 //
       
   378 
       
   379 #define IMAGE_SYM_CLASS_END_OF_FUNCTION      (TUint8 )-1
       
   380 #define IMAGE_SYM_CLASS_NULL                 0
       
   381 #define IMAGE_SYM_CLASS_AUTOMATIC            1
       
   382 #define IMAGE_SYM_CLASS_EXTERNAL             2
       
   383 #define IMAGE_SYM_CLASS_STATIC               3
       
   384 #define IMAGE_SYM_CLASS_REGISTER             4
       
   385 #define IMAGE_SYM_CLASS_EXTERNAL_DEF         5
       
   386 #define IMAGE_SYM_CLASS_LABEL                6
       
   387 #define IMAGE_SYM_CLASS_UNDEFINED_LABEL      7
       
   388 #define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT     8
       
   389 #define IMAGE_SYM_CLASS_ARGUMENT             9
       
   390 #define IMAGE_SYM_CLASS_STRUCT_TAG           10
       
   391 #define IMAGE_SYM_CLASS_MEMBER_OF_UNION      11
       
   392 #define IMAGE_SYM_CLASS_UNION_TAG            12
       
   393 #define IMAGE_SYM_CLASS_TYPE_DEFINITION      13
       
   394 #define IMAGE_SYM_CLASS_UNDEFINED_STATIC     14
       
   395 #define IMAGE_SYM_CLASS_ENUM_TAG             15
       
   396 #define IMAGE_SYM_CLASS_MEMBER_OF_ENUM       16
       
   397 #define IMAGE_SYM_CLASS_REGISTER_PARAM       17
       
   398 #define IMAGE_SYM_CLASS_BIT_FIELD            18
       
   399 #define IMAGE_SYM_CLASS_BLOCK                100
       
   400 #define IMAGE_SYM_CLASS_FUNCTION             101
       
   401 #define IMAGE_SYM_CLASS_END_OF_STRUCT        102
       
   402 #define IMAGE_SYM_CLASS_FILE                 103
       
   403 // new
       
   404 #define IMAGE_SYM_CLASS_SECTION              104
       
   405 #define IMAGE_SYM_CLASS_WEAK_EXTERNAL        105
       
   406 
       
   407 // type packing constants
       
   408 
       
   409 #define N_BTMASK                            017
       
   410 #define N_TMASK                             060
       
   411 #define N_TMASK1                            0300
       
   412 #define N_TMASK2                            0360
       
   413 #define N_BTSHFT                            4
       
   414 #define N_TSHIFT                            2
       
   415 
       
   416 // MACROS
       
   417 
       
   418 // Basic Type of  x
       
   419 #define BTYPE(x) ((x) & N_BTMASK)
       
   420 
       
   421 // Is x a pointer?
       
   422 #ifndef ISPTR
       
   423 #define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
       
   424 #endif
       
   425 
       
   426 // Is x a function?
       
   427 #ifndef ISFCN
       
   428 #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
       
   429 #endif
       
   430 
       
   431 // Is x an array?
       
   432 
       
   433 #ifndef ISARY
       
   434 #define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
       
   435 #endif
       
   436 
       
   437 // Is x a structure, union, or enumeration TAG?
       
   438 #ifndef ISTAG
       
   439 #define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
       
   440 #endif
       
   441 
       
   442 #ifndef INCREF
       
   443 #define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
       
   444 #endif
       
   445 #ifndef DECREF
       
   446 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
       
   447 #endif
       
   448 
       
   449 //
       
   450 // Auxiliary entry format.
       
   451 //
       
   452 
       
   453 typedef union _IMAGE_AUX_SYMBOL {
       
   454     struct {
       
   455         TUint32    TagIndex;                      // struct, union, or enum tag index
       
   456         union {
       
   457             struct {
       
   458                 TUint16    Linenumber;             // declaration line number
       
   459                 TUint16    Size;                   // size of struct, union, or enum
       
   460             } LnSz;
       
   461            TUint32    TotalSize;
       
   462         } Misc;
       
   463         union {
       
   464             struct {                            // if ISFCN, tag, or .bb
       
   465                 TUint32    PointerToLinenumber;
       
   466                 TUint32    PointerToNextFunction;
       
   467             } Function;
       
   468             struct {                            // if ISARY, up to 4 dimen.
       
   469                 TUint16     Dimension[4];
       
   470             } Array;
       
   471         } FcnAry;
       
   472         TUint16    TvIndex;                        // tv index
       
   473     } Sym;
       
   474     struct {
       
   475         TUint8    Name[IMAGE_SIZEOF_SYMBOL];
       
   476     } File;
       
   477     struct {
       
   478         TUint32   Length;                         // section length
       
   479         TUint16    NumberOfRelocations;            // number of relocation entries
       
   480         TUint16    NumberOfLinenumbers;            // number of line numbers
       
   481         TUint32   CheckSum;                       // checksum for communal
       
   482         TInt16   Number;                         // section number to associate with
       
   483         TUint8    Selection;                      // communal selection type
       
   484     } Section;
       
   485 } IMAGE_AUX_SYMBOL;
       
   486 typedef IMAGE_AUX_SYMBOL *PIMAGE_AUX_SYMBOL;
       
   487 
       
   488 #define IMAGE_SIZEOF_AUX_SYMBOL              18
       
   489 
       
   490 //
       
   491 // Communal selection types.
       
   492 //
       
   493 
       
   494 #define IMAGE_COMDAT_SELECT_NODUPLICATES   1
       
   495 #define IMAGE_COMDAT_SELECT_ANY            2
       
   496 #define IMAGE_COMDAT_SELECT_SAME_SIZE      3
       
   497 #define IMAGE_COMDAT_SELECT_EXACT_MATCH    4
       
   498 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE    5
       
   499 
       
   500 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
       
   501 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY   2
       
   502 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS     3
       
   503 
       
   504 
       
   505 //
       
   506 // Relocation format.
       
   507 //
       
   508 
       
   509 typedef struct _IMAGE_RELOCATION {
       
   510     TUint32   VirtualAddress;
       
   511     TUint32   SymbolTableIndex;
       
   512     TUint16    Type;
       
   513 } IMAGE_RELOCATION;
       
   514 typedef IMAGE_RELOCATION *PIMAGE_RELOCATION;
       
   515 
       
   516 #define IMAGE_SIZEOF_RELOCATION              10
       
   517 
       
   518 //
       
   519 // I386 relocation types.
       
   520 //
       
   521 
       
   522 #define IMAGE_REL_I386_ABSOLUTE              0           // Reference is absolute, no relocation is necessary
       
   523 #define IMAGE_REL_I386_DIR16                 01          // Direct 16-bit reference to the symbols virtual address
       
   524 #define IMAGE_REL_I386_REL16                 02          // PC-relative 16-bit reference to the symbols virtual address
       
   525 #define IMAGE_REL_I386_DIR32                 06          // Direct 32-bit reference to the symbols virtual address
       
   526 #define IMAGE_REL_I386_DIR32NB               07          // Direct 32-bit reference to the symbols virtual address, base not included
       
   527 #define IMAGE_REL_I386_SEG12                 011         // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address
       
   528 #define IMAGE_REL_I386_SECTION               012
       
   529 #define IMAGE_REL_I386_SECREL                013
       
   530 #define IMAGE_REL_I386_REL32                 024         // PC-relative 32-bit reference to the symbols virtual address
       
   531 
       
   532 //
       
   533 // MIPS relocation types.
       
   534 //
       
   535 
       
   536 #define IMAGE_REL_MIPS_ABSOLUTE              0           // Reference is absolute, no relocation is necessary
       
   537 #define IMAGE_REL_MIPS_REFHALF               01
       
   538 #define IMAGE_REL_MIPS_REFTUint16               02
       
   539 #define IMAGE_REL_MIPS_JMPADDR               03
       
   540 #define IMAGE_REL_MIPS_REFHI                 04
       
   541 #define IMAGE_REL_MIPS_REFLO                 05
       
   542 #define IMAGE_REL_MIPS_GPREL                 06
       
   543 #define IMAGE_REL_MIPS_LITERAL               07
       
   544 #define IMAGE_REL_MIPS_SECTION               012
       
   545 #define IMAGE_REL_MIPS_SECREL                013
       
   546 #define IMAGE_REL_MIPS_REFTUint16NB             042
       
   547 #define IMAGE_REL_MIPS_PAIR                  045
       
   548 
       
   549 //
       
   550 // Alpha Relocation types.
       
   551 //
       
   552 
       
   553 #define IMAGE_REL_ALPHA_ABSOLUTE             0x0
       
   554 #define IMAGE_REL_ALPHA_REFTUint32              0x1
       
   555 #define IMAGE_REL_ALPHA_REFQUAD              0x2
       
   556 #define IMAGE_REL_ALPHA_GPREL32              0x3
       
   557 #define IMAGE_REL_ALPHA_LITERAL              0x4
       
   558 #define IMAGE_REL_ALPHA_LITUSE               0x5
       
   559 #define IMAGE_REL_ALPHA_GPDISP               0x6
       
   560 #define IMAGE_REL_ALPHA_BRADDR               0x7
       
   561 #define IMAGE_REL_ALPHA_HINT                 0x8
       
   562 #define IMAGE_REL_ALPHA_INLINE_REFTUint32       0x9
       
   563 #define IMAGE_REL_ALPHA_REFHI                0xA
       
   564 #define IMAGE_REL_ALPHA_REFLO                0xB
       
   565 #define IMAGE_REL_ALPHA_PAIR                 0xC
       
   566 #define IMAGE_REL_ALPHA_MATCH                0xD
       
   567 #define IMAGE_REL_ALPHA_SECTION              0xE
       
   568 #define IMAGE_REL_ALPHA_SECREL               0xF
       
   569 #define IMAGE_REL_ALPHA_REFTUint32NB            0x10
       
   570 
       
   571 //
       
   572 // IBM PowerPC relocation types.
       
   573 //
       
   574 
       
   575 #define IMAGE_REL_PPC_ABSOLUTE 0x0000  // NOP
       
   576 #define IMAGE_REL_PPC_ADDR64   0x0001  // 64-bit address
       
   577 #define IMAGE_REL_PPC_ADDR32   0x0002  // 32-bit address
       
   578 #define IMAGE_REL_PPC_ADDR24   0x0003  // 26-bit address, shifted left 2 (branch absolute)
       
   579 #define IMAGE_REL_PPC_ADDR16   0x0004  // 16-bit address
       
   580 #define IMAGE_REL_PPC_ADDR14   0x0005  // 16-bit address, shifted left 2 (load doubleTUint16)
       
   581 #define IMAGE_REL_PPC_REL24    0x0006  // 26-bit PC-relative offset, shifted left 2 (branch relative)
       
   582 #define IMAGE_REL_PPC_REL14    0x0007  // 16-bit PC-relative offset, shifted left 2 (br cond relative)
       
   583 #define IMAGE_REL_PPC_TOCREL16 0x0008  // 16-bit offset from TOC base
       
   584 #define IMAGE_REL_PPC_TOCREL14 0x0009  // 16-bit offset from TOC base, shifted left 2 (load doubleTUint16)
       
   585 
       
   586 #define IMAGE_REL_PPC_ADDR32NB 0x000A  // 32-bit addr w/o image base
       
   587 #define IMAGE_REL_PPC_SECREL   0x000B  // va of containing section (as in an image sectionhdr)
       
   588 #define IMAGE_REL_PPC_SECTION  0x000C  // sectionheader number
       
   589 #define IMAGE_REL_PPC_IFGLUE   0x000D  // substitute TOC restore instruction iff symbol is glue code
       
   590 #define IMAGE_REL_PPC_IMGLUE   0x000E  // symbol is glue code; virtual address is TOC restore instruction
       
   591 
       
   592 #define IMAGE_REL_PPC_TYPEMASK 0x00FF  // mask to isolate above values in IMAGE_RELOCATION.Type
       
   593 
       
   594 // Flag bits in IMAGE_RELOCATION.TYPE
       
   595 
       
   596 #define IMAGE_REL_PPC_NEG      0x0100  // subtract reloc value rather than adding it
       
   597 #define IMAGE_REL_PPC_BRTAKEN  0x0200  // fix branch prediction bit to predict branch taken
       
   598 #define IMAGE_REL_PPC_BRNTAKEN 0x0400  // fix branch prediction bit to predict branch not taken
       
   599 #define IMAGE_REL_PPC_TOCDEFN  0x0800  // toc slot defined in file (or, data in toc)
       
   600 
       
   601 //
       
   602 // Based relocation format.
       
   603 //
       
   604 
       
   605 typedef struct _IMAGE_BASE_RELOCATION {
       
   606     TUint32   VirtualAddress;
       
   607     TUint32   SizeOfBlock;
       
   608 //  TUint16    TypeOffset[1];
       
   609 } IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION;
       
   610 
       
   611 #define IMAGE_SIZEOF_BASE_RELOCATION         8
       
   612 
       
   613 //
       
   614 // Based relocation types.
       
   615 //
       
   616 
       
   617 #define IMAGE_REL_BASED_ABSOLUTE              0
       
   618 #define IMAGE_REL_BASED_HIGH                  1
       
   619 #define IMAGE_REL_BASED_LOW                   2
       
   620 #define IMAGE_REL_BASED_HIGHLOW               3
       
   621 #define IMAGE_REL_BASED_HIGHADJ               4
       
   622 #define IMAGE_REL_BASED_MIPS_JMPADDR          5
       
   623 
       
   624 //
       
   625 // Line number format.
       
   626 //
       
   627 
       
   628 typedef struct _IMAGE_LINENUMBER {
       
   629     union {
       
   630         TUint32   SymbolTableIndex;               // Symbol table index of function name if Linenumber is 0.
       
   631         TUint32   VirtualAddress;                 // Virtual address of line number.
       
   632     } Type;
       
   633     TUint16    Linenumber;                         // Line number.
       
   634 } IMAGE_LINENUMBER;
       
   635 typedef IMAGE_LINENUMBER *PIMAGE_LINENUMBER;
       
   636 
       
   637 #define IMAGE_SIZEOF_LINENUMBER              6
       
   638 
       
   639 //
       
   640 // Archive format.
       
   641 //
       
   642 
       
   643 #define IMAGE_ARCHIVE_START_SIZE             8
       
   644 #define IMAGE_ARCHIVE_START                  "!<arch>\n"
       
   645 #define IMAGE_ARCHIVE_END                    "`\n"
       
   646 #define IMAGE_ARCHIVE_PAD                    "\n"
       
   647 #define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
       
   648 #define IMAGE_ARCHIVE_TUint32NAMES_MEMBER       "//              "
       
   649 
       
   650 typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER {
       
   651     TUint8     Name[16];                          // File member name - `/' terminated.
       
   652     TUint8     Date[12];                          // File member date - decimal.
       
   653     TUint8     UserID[6];                         // File member user id - decimal.
       
   654     TUint8     GroupID[6];                        // File member group id - decimal.
       
   655     TUint8     Mode[8];                           // File member mode - octal.
       
   656     TUint8     Size[10];                          // File member size - decimal.
       
   657     TUint8     EndHeader[2];                      // String to end header.
       
   658 } IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
       
   659 
       
   660 #define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR      60
       
   661 
       
   662 //
       
   663 // DLL support.
       
   664 //
       
   665 
       
   666 //
       
   667 // Export Format
       
   668 //
       
   669 
       
   670 typedef struct _IMAGE_EXPORT_DIRECTORY {
       
   671     TUint32   Characteristics;
       
   672     TUint32   TimeDateStamp;
       
   673     TUint16    MajorVersion;
       
   674     TUint16    MinorVersion;
       
   675     TUint32   Name;
       
   676     TUint32   Base;
       
   677     TUint32   NumberOfFunctions;
       
   678     TUint32   NumberOfNames;
       
   679     TUint32  **AddressOfFunctions;
       
   680     TUint32  **AddressOfNames;
       
   681     TUint16   **AddressOfNameOrdinals;
       
   682 } IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;
       
   683 
       
   684 //
       
   685 // Import Format
       
   686 //
       
   687 
       
   688 typedef struct _IMAGE_IMPORT_BY_NAME {
       
   689     TUint16    Hint;
       
   690     TUint8    Name[1];
       
   691 } IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
       
   692 
       
   693 typedef struct _IMAGE_THUNK_DATA {
       
   694     union {
       
   695         TUint32 *Function;
       
   696         TUint32 Ordinal;
       
   697         PIMAGE_IMPORT_BY_NAME AddressOfData;
       
   698     } u1;
       
   699 } IMAGE_THUNK_DATA, *PIMAGE_THUNK_DATA;
       
   700 
       
   701 #define IMAGE_ORDINAL_FLAG 0x80000000
       
   702 #define IMAGE_SNAP_BY_ORDINAL(Ordinal) ((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
       
   703 #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
       
   704 
       
   705 typedef struct _IMAGE_IMPORT_DESCRIPTOR {
       
   706     TUint32   Characteristics;
       
   707     TUint32   TimeDateStamp;
       
   708     TUint32   ForwarderChain;
       
   709     TUint32   Name;
       
   710     PIMAGE_THUNK_DATA FirstThunk;
       
   711 } IMAGE_IMPORT_DESCRIPTOR, *PIMAGE_IMPORT_DESCRIPTOR;
       
   712 
       
   713 
       
   714 //
       
   715 // Debug Format
       
   716 //
       
   717 
       
   718 typedef struct _IMAGE_DEBUG_DIRECTORY {
       
   719     TUint32   characteristics;
       
   720     TUint32   TimeDateStamp;
       
   721     TUint16    MajorVersion;
       
   722     TUint16    MinorVersion;
       
   723     TUint32   Type;
       
   724     TUint32   SizeOfData;
       
   725     TUint32   AddressOfRawData;
       
   726     TUint32   PointerToRawData;
       
   727 } IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
       
   728 
       
   729 #define IMAGE_DEBUG_TYPE_UNKNOWN          0
       
   730 #define IMAGE_DEBUG_TYPE_COFF             1
       
   731 #define IMAGE_DEBUG_TYPE_CODEVIEW         2
       
   732 #define IMAGE_DEBUG_TYPE_FPO              3
       
   733 #define IMAGE_DEBUG_TYPE_MISC             4
       
   734 #define IMAGE_DEBUG_TYPE_EXCEPTION        5
       
   735 #define IMAGE_DEBUG_TYPE_FIXUP            6
       
   736 #define IMAGE_DEBUG_TYPE_OMAP_TO_SRC      7
       
   737 #define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC    8
       
   738 
       
   739 typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
       
   740     TUint32   NumberOfSymbols;
       
   741     TUint32   LvaToFirstSymbol;
       
   742     TUint32   NumberOfLinenumbers;
       
   743     TUint32   LvaToFirstLinenumber;
       
   744     TUint32   RvaToFirstTUint8OfCode;
       
   745     TUint32   RvaToLastTUint8OfCode;
       
   746     TUint32   RvaToFirstTUint8OfData;
       
   747     TUint32   RvaToLastTUint8OfData;
       
   748 } IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
       
   749 
       
   750 #define FRAME_FPO   0
       
   751 #define FRAME_TRAP  1
       
   752 #define FRAME_TSS   2
       
   753 
       
   754 typedef struct _FPO_DATA {
       
   755     TUint32       ulOffStart;             // offset 1st TUint8 of function code
       
   756     TUint32       cbProcSize;             // # TUint8 in function
       
   757     TUint32       cdwLocals;              // # TUint8 in locals/4
       
   758     TUint16        cdwParams;              // # TUint8 in params/4
       
   759     TUint16        cbProlog : 8;           // # TUint8 in prolog
       
   760     TUint16        cbRegs   : 3;           // # regs saved
       
   761     TUint16        fHasSEH  : 1;           // TRUE if SEH in func
       
   762     TUint16        fUseBP   : 1;           // TRUE if EBP has been allocated
       
   763     TUint16        reserved : 1;           // reserved for future use
       
   764     TUint16        cbFrame  : 2;           // frame type
       
   765 } FPO_DATA, *PFPO_DATA;
       
   766 #define SIZEOF_RFPO_DATA 16
       
   767 
       
   768 
       
   769 #define IMAGE_DEBUG_MISC_EXENAME    1
       
   770 
       
   771 typedef struct _IMAGE_DEBUG_MISC {
       
   772     TUint32       DataType;               // type of misc data, see defines
       
   773     TUint32       Length;                 // total length of record, rounded to four
       
   774                                         // TUint8 multiple.
       
   775     TBool     Unicode;                // TRUE if data is unicode string
       
   776     TUint8        Reserved[ 3 ];
       
   777     TUint8        Data[ 1 ];              // Actual data
       
   778 } IMAGE_DEBUG_MISC, *PIMAGE_DEBUG_MISC;
       
   779 
       
   780 
       
   781 //
       
   782 // Function table extracted from MIPS/ALPHA images.  Does not contain
       
   783 // information needed only for runtime support.  Just those fields for
       
   784 // each entry needed by a debugger.
       
   785 //
       
   786 
       
   787 typedef struct _IMAGE_FUNCTION_ENTRY {
       
   788     TUint32   StartingAddress;
       
   789     TUint32   EndingAddress;
       
   790     TUint32   EndOfPrologue;
       
   791 } IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
       
   792 
       
   793 //
       
   794 // Debugging information can be stripped from an image file and placed
       
   795 // in a separate .DBG file, whose file name part is the same as the
       
   796 // image file name part (e.g. symbols for CMD.EXE could be stripped
       
   797 // and placed in CMD.DBG).  This is indicated by the IMAGE_FILE_DEBUG_STRIPPED
       
   798 // flag in the characteristics field of the file header.  The beginning of
       
   799 // the .DBG file contains the following structure which captures certain
       
   800 // information from the image file.  This allows a debug to proceed even if
       
   801 // the original image file is not accessable.  This header is followed by
       
   802 // zero of more IMAGE_SECTION_HEADER structures, followed by zero or more
       
   803 // IMAGE_DEBUG_DIRECTORY structures.  The latter structures and those in
       
   804 // the image file contain file offsets relative to the beginning of the
       
   805 // .DBG file.
       
   806 //
       
   807 // If symbols have been stripped from an image, the IMAGE_DEBUG_MISC structure
       
   808 // is left in the image file, but not mapped.  This allows a debugger to
       
   809 // compute the name of the .DBG file, from the name of the image in the
       
   810 // IMAGE_DEBUG_MISC structure.
       
   811 //
       
   812 
       
   813 typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
       
   814     TUint16        Signature;
       
   815     TUint16        Flags;
       
   816     TUint16        Machine;
       
   817     TUint16        characteristics;
       
   818     TUint32       TimeDateStamp;
       
   819     TUint32       CheckSum;
       
   820     TUint32       ImageBase;
       
   821     TUint32       SizeOfImage;
       
   822     TUint32       NumberOfSections;
       
   823     TUint32       ExportedNamesSize;
       
   824     TUint32       DebugDirectorySize;
       
   825     TUint32       Reserved[ 3 ];          // Note: reserved[0] is actually the section alignment
       
   826 } IMAGE_SEPARATE_DEBUG_HEADER, *PIMAGE_SEPARATE_DEBUG_HEADER;
       
   827 
       
   828 #define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
       
   829 
       
   830 #endif