0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 #include "../queue.h"
0046
0047 typedef enum {
0048 UNINITIALIZED,
0049 REGISTER,
0050 ALIAS,
0051 SCBLOC,
0052 SRAMLOC,
0053 ENUM_ENTRY,
0054 FIELD,
0055 MASK,
0056 ENUM,
0057 CONST,
0058 DOWNLOAD_CONST,
0059 LABEL,
0060 CONDITIONAL,
0061 MACRO
0062 } symtype;
0063
0064 typedef enum {
0065 RO = 0x01,
0066 WO = 0x02,
0067 RW = 0x03
0068 }amode_t;
0069
0070 typedef SLIST_HEAD(symlist, symbol_node) symlist_t;
0071
0072 struct reg_info {
0073 u_int address;
0074 int size;
0075 amode_t mode;
0076 symlist_t fields;
0077 uint8_t valid_bitmask;
0078 uint8_t modes;
0079 int typecheck_masks;
0080 };
0081
0082 struct field_info {
0083 symlist_t symrefs;
0084 uint8_t value;
0085 uint8_t mask;
0086 };
0087
0088 struct const_info {
0089 u_int value;
0090 int define;
0091 };
0092
0093 struct alias_info {
0094 struct symbol *parent;
0095 };
0096
0097 struct label_info {
0098 int address;
0099 int exported;
0100 };
0101
0102 struct cond_info {
0103 int func_num;
0104 };
0105
0106 struct macro_arg {
0107 STAILQ_ENTRY(macro_arg) links;
0108 regex_t arg_regex;
0109 char *replacement_text;
0110 };
0111 STAILQ_HEAD(macro_arg_list, macro_arg);
0112
0113 struct macro_info {
0114 struct macro_arg_list args;
0115 int narg;
0116 const char* body;
0117 };
0118
0119 typedef struct expression_info {
0120 symlist_t referenced_syms;
0121 int value;
0122 } expression_t;
0123
0124 typedef struct symbol {
0125 char *name;
0126 symtype type;
0127 int count;
0128 union {
0129 struct reg_info *rinfo;
0130 struct field_info *finfo;
0131 struct const_info *cinfo;
0132 struct alias_info *ainfo;
0133 struct label_info *linfo;
0134 struct cond_info *condinfo;
0135 struct macro_info *macroinfo;
0136 } info;
0137 int dont_generate_debug_code;
0138 } symbol_t;
0139
0140 typedef struct symbol_ref {
0141 symbol_t *symbol;
0142 int offset;
0143 } symbol_ref_t;
0144
0145 typedef struct symbol_node {
0146 SLIST_ENTRY(symbol_node) links;
0147 symbol_t *symbol;
0148 } symbol_node_t;
0149
0150 typedef struct critical_section {
0151 TAILQ_ENTRY(critical_section) links;
0152 int begin_addr;
0153 int end_addr;
0154 } critical_section_t;
0155
0156 typedef enum {
0157 SCOPE_ROOT,
0158 SCOPE_IF,
0159 SCOPE_ELSE_IF,
0160 SCOPE_ELSE
0161 } scope_type;
0162
0163 typedef struct patch_info {
0164 int skip_patch;
0165 int skip_instr;
0166 } patch_info_t;
0167
0168 typedef struct scope {
0169 SLIST_ENTRY(scope) scope_stack_links;
0170 TAILQ_ENTRY(scope) scope_links;
0171 TAILQ_HEAD(, scope) inner_scope;
0172 scope_type type;
0173 int inner_scope_patches;
0174 int begin_addr;
0175 int end_addr;
0176 patch_info_t patches[2];
0177 int func_num;
0178 } scope_t;
0179
0180 TAILQ_HEAD(cs_tailq, critical_section);
0181 SLIST_HEAD(scope_list, scope);
0182 TAILQ_HEAD(scope_tailq, scope);
0183
0184 void symbol_delete(symbol_t *symbol);
0185
0186 void symtable_open(void);
0187
0188 void symtable_close(void);
0189
0190 symbol_t *
0191 symtable_get(char *name);
0192
0193 symbol_node_t *
0194 symlist_search(symlist_t *symlist, char *symname);
0195
0196 void
0197 symlist_add(symlist_t *symlist, symbol_t *symbol, int how);
0198 #define SYMLIST_INSERT_HEAD 0x00
0199 #define SYMLIST_SORT 0x01
0200
0201 void symlist_free(symlist_t *symlist);
0202
0203 void symlist_merge(symlist_t *symlist_dest, symlist_t *symlist_src1,
0204 symlist_t *symlist_src2);
0205 void symtable_dump(FILE *ofile, FILE *dfile);