1c2c66affSColin Finck /* rsym.h */ 2c2c66affSColin Finck 3c2c66affSColin Finck #pragma once 4c2c66affSColin Finck #include <typedefs.h> 5c2c66affSColin Finck #include <pecoff.h> 6c2c66affSColin Finck 7c2c66affSColin Finck typedef struct { 8c2c66affSColin Finck USHORT f_magic; /* magic number */ 9c2c66affSColin Finck USHORT f_nscns; /* number of sections */ 10c2c66affSColin Finck ULONG f_timdat; /* time & date stamp */ 11c2c66affSColin Finck ULONG f_symptr; /* file pointer to symtab */ 12c2c66affSColin Finck ULONG f_nsyms; /* number of symtab entries */ 13c2c66affSColin Finck USHORT f_opthdr; /* sizeof(optional hdr) */ 14c2c66affSColin Finck USHORT f_flags; /* flags */ 15c2c66affSColin Finck } FILHDR; 16c2c66affSColin Finck 17c2c66affSColin Finck typedef struct { 18c2c66affSColin Finck char s_name[8]; /* section name */ 19c2c66affSColin Finck ULONG s_paddr; /* physical address, aliased s_nlib */ 20c2c66affSColin Finck ULONG s_vaddr; /* virtual address */ 21c2c66affSColin Finck ULONG s_size; /* section size */ 22c2c66affSColin Finck ULONG s_scnptr; /* file ptr to raw data for section */ 23c2c66affSColin Finck ULONG s_relptr; /* file ptr to relocation */ 24c2c66affSColin Finck ULONG s_lnnoptr; /* file ptr to line numbers */ 25c2c66affSColin Finck USHORT s_nreloc; /* number of relocation entries */ 26c2c66affSColin Finck USHORT s_nlnno; /* number of line number entries */ 27c2c66affSColin Finck ULONG s_flags; /* flags */ 28c2c66affSColin Finck } SCNHDR; 29*a09d5baeSMark Jansen #pragma pack(push, 4) 30c2c66affSColin Finck 31c2c66affSColin Finck typedef struct _SYMBOLFILE_HEADER { 32c2c66affSColin Finck ULONG SymbolsOffset; 33c2c66affSColin Finck ULONG SymbolsLength; 34c2c66affSColin Finck ULONG StringsOffset; 35c2c66affSColin Finck ULONG StringsLength; 36c2c66affSColin Finck } SYMBOLFILE_HEADER, *PSYMBOLFILE_HEADER; 37c2c66affSColin Finck 38c2c66affSColin Finck typedef struct _STAB_ENTRY { 39c2c66affSColin Finck ULONG n_strx; /* index into string table of name */ 40c2c66affSColin Finck UCHAR n_type; /* type of symbol */ 41c2c66affSColin Finck UCHAR n_other; /* misc info (usually empty) */ 42c2c66affSColin Finck USHORT n_desc; /* description field */ 43c2c66affSColin Finck ULONG n_value; /* value of symbol */ 44c2c66affSColin Finck } STAB_ENTRY, *PSTAB_ENTRY; 45c2c66affSColin Finck 46c2c66affSColin Finck /* http://www.math.utah.edu/docs/info/stabs_12.html */ 47c2c66affSColin Finck #define N_GYSM 0x20 48c2c66affSColin Finck #define N_FNAME 0x22 49c2c66affSColin Finck #define N_FUN 0x24 50c2c66affSColin Finck #define N_STSYM 0x26 51c2c66affSColin Finck #define N_LCSYM 0x28 52c2c66affSColin Finck #define N_MAIN 0x2A 53c2c66affSColin Finck #define N_PC 0x30 54c2c66affSColin Finck #define N_NSYMS 0x32 55c2c66affSColin Finck #define N_NOMAP 0x34 56c2c66affSColin Finck #define N_RSYM 0x40 57c2c66affSColin Finck #define N_M2C 0x42 58c2c66affSColin Finck #define N_SLINE 0x44 59c2c66affSColin Finck #define N_DSLINE 0x46 60c2c66affSColin Finck #define N_BSLINE 0x48 61c2c66affSColin Finck #define N_BROWS 0x48 62c2c66affSColin Finck #define N_DEFD 0x4A 63c2c66affSColin Finck #define N_EHDECL 0x50 64c2c66affSColin Finck #define N_MOD2 0x50 65c2c66affSColin Finck #define N_CATCH 0x54 66c2c66affSColin Finck #define N_SSYM 0x60 67c2c66affSColin Finck #define N_SO 0x64 68c2c66affSColin Finck #define N_LSYM 0x80 69c2c66affSColin Finck #define N_BINCL 0x82 70c2c66affSColin Finck #define N_SOL 0x84 71c2c66affSColin Finck #define N_PSYM 0xA0 72c2c66affSColin Finck #define N_EINCL 0xA2 73c2c66affSColin Finck #define N_ENTRY 0xA4 74c2c66affSColin Finck #define N_LBRAC 0xC0 75c2c66affSColin Finck #define N_EXCL 0xC2 76c2c66affSColin Finck #define N_SCOPE 0xC4 77c2c66affSColin Finck #define N_RBRAC 0xE0 78c2c66affSColin Finck #define N_BCOMM 0xE2 79c2c66affSColin Finck #define N_ECOMM 0xE4 80c2c66affSColin Finck #define N_ECOML 0xE8 81c2c66affSColin Finck #define N_LENG 0xFE 82c2c66affSColin Finck 83c2c66affSColin Finck /* COFF symbol table */ 84c2c66affSColin Finck 85c2c66affSColin Finck #define E_SYMNMLEN 8 /* # characters in a symbol name */ 86c2c66affSColin Finck #define E_FILNMLEN 14 /* # characters in a file name */ 87c2c66affSColin Finck #define E_DIMNUM 4 /* # array dimensions in auxiliary entry */ 88c2c66affSColin Finck 89c2c66affSColin Finck #define N_BTMASK (0xf) 90c2c66affSColin Finck #define N_TMASK (0x30) 91c2c66affSColin Finck #define N_BTSHFT (4) 92c2c66affSColin Finck #define N_TSHIFT (2) 93c2c66affSColin Finck 94c2c66affSColin Finck /* derived types, in e_type */ 95c2c66affSColin Finck #define DT_NON (0) /* no derived type */ 96c2c66affSColin Finck #define DT_PTR (1) /* pointer */ 97c2c66affSColin Finck #define DT_FCN (2) /* function */ 98c2c66affSColin Finck #define DT_ARY (3) /* array */ 99c2c66affSColin Finck 100c2c66affSColin Finck #define BTYPE(x) ((x) & N_BTMASK) 101c2c66affSColin Finck 102c2c66affSColin Finck #define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT)) 103c2c66affSColin Finck #define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT)) 104c2c66affSColin Finck #define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT)) 105c2c66affSColin Finck #define ISTAG(x) ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG) 106c2c66affSColin Finck #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK)) 107c2c66affSColin Finck 108c2c66affSColin Finck #define C_EFCN 0xff /* physical end of function */ 109c2c66affSColin Finck #define C_NULL 0 110c2c66affSColin Finck #define C_AUTO 1 /* automatic variable */ 111c2c66affSColin Finck #define C_EXT 2 /* external symbol */ 112c2c66affSColin Finck #define C_STAT 3 /* static */ 113c2c66affSColin Finck #define C_REG 4 /* register variable */ 114c2c66affSColin Finck #define C_EXTDEF 5 /* external definition */ 115c2c66affSColin Finck #define C_LABEL 6 /* label */ 116c2c66affSColin Finck #define C_ULABEL 7 /* undefined label */ 117c2c66affSColin Finck #define C_MOS 8 /* member of structure */ 118c2c66affSColin Finck #define C_ARG 9 /* function argument */ 119c2c66affSColin Finck #define C_STRTAG 10 /* structure tag */ 120c2c66affSColin Finck #define C_MOU 11 /* member of union */ 121c2c66affSColin Finck #define C_UNTAG 12 /* union tag */ 122c2c66affSColin Finck #define C_TPDEF 13 /* type definition */ 123c2c66affSColin Finck #define C_USTATIC 14 /* undefined static */ 124c2c66affSColin Finck #define C_ENTAG 15 /* enumeration tag */ 125c2c66affSColin Finck #define C_MOE 16 /* member of enumeration */ 126c2c66affSColin Finck #define C_REGPARM 17 /* register parameter */ 127c2c66affSColin Finck #define C_FIELD 18 /* bit field */ 128c2c66affSColin Finck #define C_AUTOARG 19 /* auto argument */ 129c2c66affSColin Finck #define C_LASTENT 20 /* dummy entry (end of block) */ 130c2c66affSColin Finck #define C_BLOCK 100 /* ".bb" or ".eb" */ 131c2c66affSColin Finck #define C_FCN 101 /* ".bf" or ".ef" */ 132c2c66affSColin Finck #define C_EOS 102 /* end of structure */ 133c2c66affSColin Finck #define C_FILE 103 /* file name */ 134c2c66affSColin Finck #define C_LINE 104 /* line # reformatted as symbol table entry */ 135c2c66affSColin Finck #define C_ALIAS 105 /* duplicate tag */ 136c2c66affSColin Finck #define C_HIDDEN 106 /* ext symbol in dmert public lib */ 137c2c66affSColin Finck 138*a09d5baeSMark Jansen #pragma pack(push, 1) 139c2c66affSColin Finck typedef struct _COFF_SYMENT 140c2c66affSColin Finck { 141c2c66affSColin Finck union 142c2c66affSColin Finck { 143c2c66affSColin Finck char e_name[E_SYMNMLEN]; 144c2c66affSColin Finck struct 145c2c66affSColin Finck { 146c2c66affSColin Finck ULONG e_zeroes; 147c2c66affSColin Finck ULONG e_offset; 148c2c66affSColin Finck } 149c2c66affSColin Finck e; 150c2c66affSColin Finck } 151c2c66affSColin Finck e; 152c2c66affSColin Finck ULONG e_value; 153c2c66affSColin Finck short e_scnum; 154c2c66affSColin Finck USHORT e_type; 155c2c66affSColin Finck UCHAR e_sclass; 156c2c66affSColin Finck UCHAR e_numaux; 157c2c66affSColin Finck } COFF_SYMENT, *PCOFF_SYMENT; 158*a09d5baeSMark Jansen #pragma pack(pop) 159c2c66affSColin Finck 160c2c66affSColin Finck #ifdef TARGET_i386 161c2c66affSColin Finck typedef ULONG TARGET_ULONG_PTR; 162c2c66affSColin Finck #else 163c2c66affSColin Finck typedef ULONGLONG TARGET_ULONG_PTR; 164c2c66affSColin Finck #endif 165c2c66affSColin Finck 166c2c66affSColin Finck typedef struct _ROSSYM_ENTRY { 167c2c66affSColin Finck TARGET_ULONG_PTR Address; 168c2c66affSColin Finck ULONG FunctionOffset; 169c2c66affSColin Finck ULONG FileOffset; 170c2c66affSColin Finck ULONG SourceLine; 171c2c66affSColin Finck } ROSSYM_ENTRY, *PROSSYM_ENTRY; 172c2c66affSColin Finck 173*a09d5baeSMark Jansen #pragma pack(pop) 174*a09d5baeSMark Jansen 175c2c66affSColin Finck #define ROUND_UP(N, S) (((N) + (S) - 1) & ~((S) - 1)) 176c2c66affSColin Finck 177c2c66affSColin Finck extern char* 178c2c66affSColin Finck convert_path(const char* origpath); 179c2c66affSColin Finck 180c2c66affSColin Finck extern void* 181c2c66affSColin Finck load_file ( const char* file_name, size_t* file_size ); 182