| 1 | /* This file is part of the program psim. |
| 2 | |
| 3 | Copyright 1994, 1995, 1996, 2003 Andrew Cagney |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | # -- |
| 22 | # |
| 23 | # |
| 24 | # Fields: |
| 25 | # |
| 26 | # 1 Instruction format as a `start-bit,content' pairs. |
| 27 | # the content is one of a digit, field name or `/' (aka.0) |
| 28 | # |
| 29 | # 2 Format specifier |
| 30 | # |
| 31 | # 3 Flags: 64 - 64bit only |
| 32 | # f - floating point enabled required |
| 33 | # |
| 34 | # 4 short name |
| 35 | # |
| 36 | # 5 Description |
| 37 | # |
| 38 | # |
| 39 | # For flags marked 'model', the fields are interpreted as follows: |
| 40 | # |
| 41 | # 1 Not used |
| 42 | # |
| 43 | # 2 Not used |
| 44 | # |
| 45 | # 3 "macro" |
| 46 | # |
| 47 | # 4 String name for model |
| 48 | # |
| 49 | # 5 Specific CPU model, must be an identifier |
| 50 | # |
| 51 | # 6 Comma separated list of functional units |
| 52 | |
| 53 | */ |
| 54 | |
| 55 | |
| 56 | /* Global constants */ |
| 57 | |
| 58 | enum { |
| 59 | max_insn_bit_size = 32, |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | typedef struct _insn_field insn_field; |
| 64 | struct _insn_field { |
| 65 | int first; |
| 66 | int last; |
| 67 | int width; |
| 68 | int is_int; |
| 69 | int is_slash; |
| 70 | int is_string; |
| 71 | int val_int; |
| 72 | char *pos_string; |
| 73 | char *val_string; |
| 74 | insn_field *next; |
| 75 | insn_field *prev; |
| 76 | }; |
| 77 | |
| 78 | typedef struct _insn_fields insn_fields; |
| 79 | struct _insn_fields { |
| 80 | insn_field *bits[max_insn_bit_size]; |
| 81 | insn_field *first; |
| 82 | insn_field *last; |
| 83 | unsigned value; |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | /****************************************************************/ |
| 88 | |
| 89 | typedef struct _opcode_field opcode_field; |
| 90 | struct _opcode_field { |
| 91 | int first; |
| 92 | int last; |
| 93 | int is_boolean; |
| 94 | unsigned boolean_constant; |
| 95 | opcode_field *parent; |
| 96 | }; |
| 97 | |
| 98 | |
| 99 | /****************************************************************/ |
| 100 | |
| 101 | typedef struct _insn_bits insn_bits; |
| 102 | struct _insn_bits { |
| 103 | int is_expanded; |
| 104 | int value; |
| 105 | insn_field *field; |
| 106 | opcode_field *opcode; |
| 107 | insn_bits *last; |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | /****************************************************************/ |
| 112 | |
| 113 | |
| 114 | typedef enum { |
| 115 | insn_format, |
| 116 | insn_form, |
| 117 | insn_flags, |
| 118 | insn_mnemonic, |
| 119 | insn_name, |
| 120 | insn_comment, |
| 121 | insn_field_6, |
| 122 | insn_field_7, |
| 123 | nr_insn_table_fields |
| 124 | } insn_table_fields; |
| 125 | |
| 126 | typedef enum { |
| 127 | function_type = insn_format, |
| 128 | function_name = insn_name, |
| 129 | function_param = insn_comment |
| 130 | } function_table_fields; |
| 131 | |
| 132 | typedef enum { |
| 133 | model_name = insn_mnemonic, |
| 134 | model_identifer = insn_name, |
| 135 | model_default = insn_comment, |
| 136 | } model_table_fields; |
| 137 | |
| 138 | typedef enum { |
| 139 | include_flags = insn_flags, |
| 140 | include_path = insn_name, |
| 141 | } model_include_fields; |
| 142 | |
| 143 | typedef enum { |
| 144 | cache_type_def = insn_name, |
| 145 | cache_derived_name = insn_comment, |
| 146 | cache_name = insn_field_6, |
| 147 | cache_expression = insn_field_7, |
| 148 | } cache_fields; |
| 149 | |
| 150 | typedef struct _insn insn; |
| 151 | struct _insn { |
| 152 | table_entry *file_entry; |
| 153 | insn_fields *fields; |
| 154 | insn *next; |
| 155 | }; |
| 156 | |
| 157 | typedef struct _insn_undef insn_undef; |
| 158 | struct _insn_undef { |
| 159 | insn_undef *next; |
| 160 | char *name; |
| 161 | }; |
| 162 | |
| 163 | typedef struct _model model; |
| 164 | struct _model { |
| 165 | model *next; |
| 166 | char *name; |
| 167 | char *printable_name; |
| 168 | char *insn_default; |
| 169 | table_model_entry *func_unit_start; |
| 170 | table_model_entry *func_unit_end; |
| 171 | }; |
| 172 | |
| 173 | typedef struct _insn_table insn_table; |
| 174 | struct _insn_table { |
| 175 | int opcode_nr; |
| 176 | insn_bits *expanded_bits; |
| 177 | int nr_insn; |
| 178 | insn *insns; |
| 179 | insn *functions; |
| 180 | insn *last_function; |
| 181 | decode_table *opcode_rule; |
| 182 | opcode_field *opcode; |
| 183 | int nr_entries; |
| 184 | insn_table *entries; |
| 185 | insn_table *sibling; |
| 186 | insn_table *parent; |
| 187 | }; |
| 188 | |
| 189 | typedef enum { |
| 190 | insn_model_name, |
| 191 | insn_model_fields, |
| 192 | nr_insn_model_table_fields |
| 193 | } insn_model_table_fields; |
| 194 | |
| 195 | |
| 196 | extern insn_table *load_insn_table |
| 197 | (const char *file_name, |
| 198 | decode_table *decode_rules, |
| 199 | filter *filters, |
| 200 | table_include *includes, |
| 201 | cache_table **cache_rules); |
| 202 | |
| 203 | model *models; |
| 204 | model *last_model; |
| 205 | |
| 206 | insn *model_macros; |
| 207 | insn *last_model_macro; |
| 208 | |
| 209 | insn *model_functions; |
| 210 | insn *last_model_function; |
| 211 | |
| 212 | insn *model_internal; |
| 213 | insn *last_model_internal; |
| 214 | |
| 215 | insn *model_static; |
| 216 | insn *last_model_static; |
| 217 | |
| 218 | insn *model_data; |
| 219 | insn *last_model_data; |
| 220 | |
| 221 | int max_model_fields_len; |
| 222 | |
| 223 | extern void insn_table_insert_insn |
| 224 | (insn_table *table, |
| 225 | table_entry *file_entry, |
| 226 | insn_fields *fields); |
| 227 | |
| 228 | |
| 229 | /****************************************************************/ |
| 230 | |
| 231 | /****************************************************************/ |
| 232 | |
| 233 | typedef void leaf_handler |
| 234 | (insn_table *entry, |
| 235 | lf *file, |
| 236 | void *data, |
| 237 | int depth); |
| 238 | |
| 239 | typedef void insn_handler |
| 240 | (insn_table *table, |
| 241 | lf *file, |
| 242 | void *data, |
| 243 | insn *instruction, |
| 244 | int depth); |
| 245 | |
| 246 | typedef void padding_handler |
| 247 | (insn_table *table, |
| 248 | lf *file, |
| 249 | void *data, |
| 250 | int depth, |
| 251 | int opcode_nr); |
| 252 | |
| 253 | |
| 254 | extern void insn_table_traverse_tree |
| 255 | (insn_table *table, |
| 256 | lf *file, |
| 257 | void *data, |
| 258 | int depth, |
| 259 | leaf_handler *start, |
| 260 | insn_handler *handler, |
| 261 | leaf_handler *end, |
| 262 | padding_handler *padding); |
| 263 | |
| 264 | |
| 265 | extern void insn_table_traverse_insn |
| 266 | (insn_table *table, |
| 267 | lf *file, |
| 268 | void *data, |
| 269 | insn_handler *handler); |
| 270 | |
| 271 | |
| 272 | |
| 273 | /****************************************************************/ |
| 274 | |
| 275 | typedef void function_handler |
| 276 | (insn_table *table, |
| 277 | lf *file, |
| 278 | void *data, |
| 279 | table_entry *function); |
| 280 | |
| 281 | extern void |
| 282 | insn_table_traverse_function |
| 283 | (insn_table *table, |
| 284 | lf *file, |
| 285 | void *data, |
| 286 | function_handler *leaf); |
| 287 | |
| 288 | /****************************************************************/ |
| 289 | |
| 290 | |
| 291 | |
| 292 | extern void insn_table_expand_insns |
| 293 | (insn_table *table); |
| 294 | |
| 295 | extern int insn_table_depth |
| 296 | (insn_table *table); |