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