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