1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45#ifdef __linux__
46#include "../queue.h"
47#else
48#include <sys/queue.h>
49#endif
50
51typedef enum {
52 UNINITIALIZED,
53 REGISTER,
54 ALIAS,
55 SCBLOC,
56 SRAMLOC,
57 ENUM_ENTRY,
58 FIELD,
59 MASK,
60 ENUM,
61 CONST,
62 DOWNLOAD_CONST,
63 LABEL,
64 CONDITIONAL,
65 MACRO
66} symtype;
67
68typedef enum {
69 RO = 0x01,
70 WO = 0x02,
71 RW = 0x03
72}amode_t;
73
74typedef SLIST_HEAD(symlist, symbol_node) symlist_t;
75
76struct reg_info {
77 u_int address;
78 int size;
79 amode_t mode;
80 symlist_t fields;
81 uint8_t valid_bitmask;
82 uint8_t modes;
83 int typecheck_masks;
84};
85
86struct field_info {
87 symlist_t symrefs;
88 uint8_t value;
89 uint8_t mask;
90};
91
92struct const_info {
93 u_int value;
94 int define;
95};
96
97struct alias_info {
98 struct symbol *parent;
99};
100
101struct label_info {
102 int address;
103 int exported;
104};
105
106struct cond_info {
107 int func_num;
108};
109
110struct macro_arg {
111 STAILQ_ENTRY(macro_arg) links;
112 regex_t arg_regex;
113 char *replacement_text;
114};
115STAILQ_HEAD(macro_arg_list, macro_arg) args;
116
117struct macro_info {
118 struct macro_arg_list args;
119 int narg;
120 const char* body;
121};
122
123typedef struct expression_info {
124 symlist_t referenced_syms;
125 int value;
126} expression_t;
127
128typedef struct symbol {
129 char *name;
130 symtype type;
131 int count;
132 union {
133 struct reg_info *rinfo;
134 struct field_info *finfo;
135 struct const_info *cinfo;
136 struct alias_info *ainfo;
137 struct label_info *linfo;
138 struct cond_info *condinfo;
139 struct macro_info *macroinfo;
140 } info;
141 int dont_generate_debug_code;
142} symbol_t;
143
144typedef struct symbol_ref {
145 symbol_t *symbol;
146 int offset;
147} symbol_ref_t;
148
149typedef struct symbol_node {
150 SLIST_ENTRY(symbol_node) links;
151 symbol_t *symbol;
152} symbol_node_t;
153
154typedef struct critical_section {
155 TAILQ_ENTRY(critical_section) links;
156 int begin_addr;
157 int end_addr;
158} critical_section_t;
159
160typedef enum {
161 SCOPE_ROOT,
162 SCOPE_IF,
163 SCOPE_ELSE_IF,
164 SCOPE_ELSE
165} scope_type;
166
167typedef struct patch_info {
168 int skip_patch;
169 int skip_instr;
170} patch_info_t;
171
172typedef struct scope {
173 SLIST_ENTRY(scope) scope_stack_links;
174 TAILQ_ENTRY(scope) scope_links;
175 TAILQ_HEAD(, scope) inner_scope;
176 scope_type type;
177 int inner_scope_patches;
178 int begin_addr;
179 int end_addr;
180 patch_info_t patches[2];
181 int func_num;
182} scope_t;
183
184TAILQ_HEAD(cs_tailq, critical_section);
185SLIST_HEAD(scope_list, scope);
186TAILQ_HEAD(scope_tailq, scope);
187
188void symbol_delete(symbol_t *symbol);
189
190void symtable_open(void);
191
192void symtable_close(void);
193
194symbol_t *
195 symtable_get(char *name);
196
197symbol_node_t *
198 symlist_search(symlist_t *symlist, char *symname);
199
200void
201 symlist_add(symlist_t *symlist, symbol_t *symbol, int how);
202#define SYMLIST_INSERT_HEAD 0x00
203#define SYMLIST_SORT 0x01
204
205void symlist_free(symlist_t *symlist);
206
207void symlist_merge(symlist_t *symlist_dest, symlist_t *symlist_src1,
208 symlist_t *symlist_src2);
209void symtable_dump(FILE *ofile, FILE *dfile);
210