1 /* The IGEN simulator generator for GDB, the GNU Debugger. 2 3 Copyright 2002-2024 Free Software Foundation, Inc. 4 5 Contributed by Andrew Cagney. 6 7 This file is part of GDB. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 3 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 21 22 #ifndef IGEN_LD_INSN_H 23 #define IGEN_LD_INSN_H 24 25 typedef uint64_t insn_uint; 26 27 28 /* Common among most entries: 29 30 All non instruction records have the format: 31 32 <...> ::= 33 ":" <record-name> 34 ":" <filter-flags> 35 ":" <filter-models> 36 ":" ... 37 38 */ 39 40 enum 41 { 42 record_type_field = 1, 43 old_record_type_field = 2, 44 record_filter_flags_field = 2, 45 record_filter_models_field = 3, 46 }; 47 48 49 /* Include: 50 51 Include the specified file. 52 53 <include> ::= 54 ":" "include" 55 ":" <filter-flags> 56 ":" <filter-models> 57 ":" <filename> 58 <nl> 59 ; 60 61 */ 62 63 enum 64 { 65 include_filename_field = 4, 66 nr_include_fields, 67 }; 68 69 70 71 /* Options: 72 73 Valid options are: hi-bit-nr (default 0), insn-bit-size (default 74 32), insn-specifying-widths (default true), multi-sim (default false). 75 76 <option> ::= 77 ":" "option" 78 ":" <filter-flags> 79 ":" <filter-models> 80 ":" <option-name> 81 ":" <option-value> 82 <nl> 83 ; 84 85 <option-name> ::= 86 "insn-bit-size" 87 | "insn-specifying-widths" 88 | "hi-bit-nr" 89 | "flags-filter" 90 | "model-filter" 91 | "multi-sim" 92 | "format-names" 93 ; 94 95 <option-value> ::= 96 "true" 97 | "false" 98 | <integer> 99 | <list> 100 ; 101 102 103 These update the global options structure. */ 104 105 106 enum 107 { 108 option_name_field = 4, 109 option_value_field, 110 nr_option_fields, 111 }; 112 113 114 115 /* Macro definitions: 116 117 <insn-macro> ::= 118 ":" "define" 119 ":" <filter-flags> 120 ":" <filter-models> 121 ":" <name> 122 ":" <arg-list> 123 ":" <expression> 124 <nl> 125 ; 126 127 <arg-list> ::= 128 [ <name> { "," <arg-list> } ] 129 ; 130 131 */ 132 133 134 enum 135 { 136 macro_name_field = 4, 137 macro_args_field, 138 macro_expr_field, 139 nr_macro_fields, 140 }; 141 142 143 144 /* Functions and internal routins: 145 146 NB: <filter-models> and <function-models> are equivalent. 147 148 149 <function> ::= 150 ":" "function" 151 <function-spec> 152 ; 153 154 <internal> ::= 155 ":" "internal" 156 <function-spec> 157 ; 158 159 <format> ::= 160 ":" ( "%s" | ... ) 161 <function-spec> 162 ; 163 164 <function-model> ::= 165 "*" [ <processor-list> ] 166 ":" 167 <nl> 168 ; 169 170 <function-spec> ::= 171 ":" <filter-flags> 172 ":" <filter-models> 173 ":" <typedef> 174 ":" <name> 175 [ ":" <parameter-list> ] 176 <nl> 177 [ <function-model> ] 178 <code-block> 179 ; 180 181 */ 182 183 enum 184 { 185 function_typedef_field = 4, 186 function_name_field, 187 function_param_field, 188 nr_function_fields, 189 }; 190 191 enum 192 { 193 function_model_name_field = 0, 194 nr_function_model_fields = 1, 195 }; 196 197 enum 198 { 199 old_function_typedef_field = 0, 200 old_function_type_field = 2, 201 old_function_name_field = 4, 202 old_function_param_field = 5, 203 nr_old_function_fields = 5, /* parameter-list is optional */ 204 }; 205 206 207 typedef struct _function_entry function_entry; 208 struct _function_entry 209 { 210 line_ref *line; 211 filter *flags; 212 filter *models; 213 char *type; 214 char *name; 215 char *param; 216 table_entry *code; 217 int is_internal; 218 function_entry *next; 219 }; 220 221 222 typedef void function_entry_handler 223 (lf *file, const function_entry *function, void *data); 224 225 extern void function_entry_traverse 226 (lf *file, 227 const function_entry *functions, 228 function_entry_handler * handler, void *data); 229 230 231 /* cache-macro: 232 233 <cache-macro> ::= 234 ":" <macro-type> 235 ":" <filter-flags> 236 ":" <filter-models> 237 ":" <typedef> 238 ":" <name> 239 ":" <field-name> { "," <field-name> } 240 ":" <expression> 241 <nl> 242 ; 243 244 <cache-macro-type> ::= 245 "scratch" 246 | "cache" 247 | "compute" 248 ; 249 250 <name> ::= 251 <ident> 252 | <ident> "_is_" <integer> 253 ; 254 255 A cache entry is defined (for an instruction) when all 256 <field-name>s are present as named opcode fields within the 257 instructions format. 258 259 SCRATCH and CACHE macros are defined during the cache fill stage 260 while CACHE and COMPUTE macros are defined during the instruction 261 execution stage. 262 263 */ 264 265 enum 266 { 267 cache_typedef_field = 4, 268 cache_name_field, 269 cache_original_fields_field, 270 cache_expression_field, 271 nr_cache_fields, 272 }; 273 274 typedef enum 275 { 276 scratch_value, 277 cache_value, 278 compute_value, 279 } 280 cache_entry_type; 281 282 typedef struct _cache_entry cache_entry; 283 struct _cache_entry 284 { 285 line_ref *line; 286 filter *flags; 287 filter *models; 288 cache_entry_type entry_type; 289 char *name; 290 filter *original_fields; 291 char *type; 292 char *expression; 293 cache_entry *next; 294 }; 295 296 297 298 /* Model specs: 299 300 <model-processor> ::= 301 ":" "model" 302 ":" <filter-flags> 303 ":" <filter-models> 304 ":" <processor> 305 ":" <BFD-processor> 306 ":" <function-unit-data> 307 <nl> 308 ; 309 310 <model-macro> ::= 311 ":" "model-macro" 312 ":" <filter-flags> 313 ":" <filter-models> 314 <nl> 315 <code-block> 316 ; 317 318 <model-data> ::= 319 ":" "model-data" 320 ":" <filter-flags> 321 ":" <filter-models> 322 <nl> 323 <code-block> 324 ; 325 326 <model-static> ::= 327 ":" "model-static" 328 <function-spec> 329 ; 330 331 <model-internal> ::= 332 ":" "model-internal" 333 <function-spec> 334 ; 335 336 <model-function> ::= 337 ":" "model-internal" 338 <function-spec> 339 ; 340 341 */ 342 343 enum 344 { 345 nr_model_macro_fields = 4, 346 nr_model_data_fields = 4, 347 nr_model_static_fields = nr_function_fields, 348 nr_model_internal_fields = nr_function_fields, 349 nr_model_function_fields = nr_function_fields, 350 }; 351 352 typedef struct _model_data model_data; 353 struct _model_data 354 { 355 line_ref *line; 356 filter *flags; 357 table_entry *entry; 358 table_entry *code; 359 model_data *next; 360 }; 361 362 enum 363 { 364 model_name_field = 4, 365 model_full_name_field, 366 model_unit_data_field, 367 nr_model_processor_fields, 368 }; 369 370 typedef struct _model_entry model_entry; 371 struct _model_entry 372 { 373 line_ref *line; 374 filter *flags; 375 char *name; 376 char *full_name; 377 char *unit_data; 378 model_entry *next; 379 }; 380 381 382 typedef struct _model_table model_table; 383 struct _model_table 384 { 385 filter *processors; 386 int nr_models; 387 model_entry *models; 388 model_data *macros; 389 model_data *data; 390 function_entry *statics; 391 function_entry *internals; 392 function_entry *functions; 393 }; 394 395 396 397 /* Instruction format: 398 399 An instruction is composed of a sequence of N bit instruction 400 words. Each word broken into a number of instruction fields. 401 Those fields being constant (ex. an opcode) or variable (register 402 spec). 403 404 <insn-word> ::= 405 <insn-field> { "," <insn-field> } ; 406 407 <insn-field> ::= 408 ( <binary-value-implying-width> 409 | <field-name-implying-width> 410 | [ <start-or-width> "." ] <field> 411 ) 412 { [ "!" | "=" ] [ <value> | <field-name> ] } 413 ; 414 415 <field> ::= 416 { "*" }+ 417 | { "/" }+ 418 | <field-name> 419 | "0x" <hex-value> 420 | "0b" <binary-value> 421 | "0" <octal-value> 422 | <integer-value> ; 423 424 */ 425 426 typedef enum _insn_field_cond_type 427 { 428 insn_field_cond_value, 429 insn_field_cond_field, 430 } 431 insn_field_cond_type; 432 typedef enum _insn_field_cond_test 433 { 434 insn_field_cond_eq, 435 insn_field_cond_ne, 436 } 437 insn_field_cond_test; 438 typedef struct _insn_field_cond insn_field_cond; 439 struct _insn_field_cond 440 { 441 insn_field_cond_type type; 442 insn_field_cond_test test; 443 insn_uint value; 444 struct _insn_field_entry *field; 445 char *string; 446 insn_field_cond *next; 447 }; 448 449 450 typedef enum _insn_field_type 451 { 452 insn_field_invalid, 453 insn_field_int, 454 insn_field_reserved, 455 insn_field_wild, 456 insn_field_string, 457 } 458 insn_field_type; 459 460 typedef struct _insn_field_entry insn_field_entry; 461 struct _insn_field_entry 462 { 463 int first; 464 int last; 465 int width; 466 int word_nr; 467 insn_field_type type; 468 insn_uint val_int; 469 char *pos_string; 470 char *val_string; 471 insn_field_cond *conditions; 472 insn_field_entry *next; 473 insn_field_entry *prev; 474 }; 475 476 typedef struct _insn_bit_entry insn_bit_entry; 477 struct _insn_bit_entry 478 { 479 int value; 480 int mask; 481 insn_field_entry *field; 482 }; 483 484 485 486 487 typedef struct _insn_entry insn_entry; /* forward */ 488 489 typedef struct _insn_word_entry insn_word_entry; 490 struct _insn_word_entry 491 { 492 /* list of sub-fields making up the instruction. bit provides 493 faster access to the field data for bit N. */ 494 insn_field_entry *first; 495 insn_field_entry *last; 496 insn_bit_entry *bit[max_insn_bit_size]; 497 /* set of all the string fields */ 498 filter *field_names; 499 /* For multi-word instructions, The Nth word (from zero). */ 500 insn_word_entry *next; 501 }; 502 503 504 505 /* Instruction model: 506 507 Provides scheduling and other data for the code modeling the 508 instruction unit. 509 510 <insn-model> ::= 511 "*" [ <processor-list> ] 512 ":" [ <function-unit-data> ] 513 <nl> 514 ; 515 516 <processor-list> ::= 517 <processor> { "," <processor>" } 518 ; 519 520 If the <processor-list> is empty, the model is made the default for 521 this instruction. 522 523 */ 524 525 enum 526 { 527 insn_model_name_field = 0, 528 insn_model_unit_data_field = 1, 529 nr_insn_model_fields = 1, 530 }; 531 532 typedef struct _insn_model_entry insn_model_entry; 533 struct _insn_model_entry 534 { 535 line_ref *line; 536 insn_entry *insn; 537 filter *names; 538 char *full_name; 539 char *unit_data; 540 insn_model_entry *next; 541 }; 542 543 544 545 /* Instruction mnemonic: 546 547 List of assembler mnemonics for the instruction. 548 549 <insn-mnenonic> ::= 550 "\"" <assembler-mnemonic> "\"" 551 [ ":" <conditional-expression> ] 552 <nl> 553 ; 554 555 An assembler mnemonic string has the syntax: 556 557 <assembler-mnemonic> ::= 558 ( [ "%" <format-spec> ] "<" <func> [ "#" <param-list> ] ">" 559 | "%%" 560 | <other-letter> 561 )+ 562 563 Where, for instance, the text is translated into a printf format 564 and argument pair: 565 566 "<FUNC>" : "%ld", (long) FUNC 567 "%<FUNC>..." : "%...", FUNC 568 "%s<FUNC>" : "%s", <%s>FUNC (SD_, FUNC) 569 "%s<FUNC#P1,P2>" : "%s", <%s>FUNC (SD_, P1,P2) 570 "%lx<FUNC>" : "%lx", (unsigned long) FUNC 571 "%08lx<FUNC>" : "%08lx", (unsigned long) FUNC 572 573 And "<%s>FUNC" denotes a function declared using the "%s" record 574 specifier. 575 576 577 578 ; 579 580 */ 581 582 enum 583 { 584 insn_mnemonic_format_field = 0, 585 insn_mnemonic_condition_field = 1, 586 nr_insn_mnemonic_fields = 1, 587 }; 588 589 typedef struct _insn_mnemonic_entry insn_mnemonic_entry; 590 struct _insn_mnemonic_entry 591 { 592 line_ref *line; 593 insn_entry *insn; 594 char *format; 595 char *condition; 596 insn_mnemonic_entry *next; 597 }; 598 599 600 601 /* Instruction: 602 603 <insn> ::= 604 <insn-word> { "+" <insn-word> } 605 ":" <format-name> 606 ":" <filter-flags> 607 ":" <options> 608 ":" <name> 609 <nl> 610 { <insn-model> } 611 { <insn-mnemonic> } 612 <code-block> 613 614 */ 615 616 enum 617 { 618 insn_word_field = 0, 619 insn_format_name_field = 1, 620 insn_filter_flags_field = 2, 621 insn_options_field = 3, 622 insn_name_field = 4, 623 nr_insn_fields = 5, 624 }; 625 626 627 /* typedef struct _insn_entry insn_entry; */ 628 struct _insn_entry 629 { 630 line_ref *line; 631 filter *flags; /* filtered by options.filters */ 632 char *format_name; 633 filter *options; 634 char *name; 635 /* the words that make up the instruction. Word provides direct 636 access to word N. Pseudo instructions can be identified by 637 nr_words == 0. */ 638 int nr_words; 639 insn_word_entry *words; 640 insn_word_entry **word; 641 /* a set of all the fields from all the words */ 642 filter *field_names; 643 /* an array of processor models, missing models are NULL! */ 644 int nr_models; 645 insn_model_entry *models; 646 insn_model_entry **model; 647 filter *processors; 648 /* list of assember formats */ 649 int nr_mnemonics; 650 insn_mnemonic_entry *mnemonics; 651 /* code body */ 652 table_entry *code; 653 insn_entry *next; 654 }; 655 656 657 /* Instruction table: 658 659 */ 660 661 typedef struct _insn_table insn_table; 662 struct _insn_table 663 { 664 cache_entry *caches; 665 int max_nr_words; 666 int nr_insns; 667 insn_entry *insns; 668 function_entry *functions; 669 insn_entry *illegal_insn; 670 model_table *model; 671 filter *options; 672 filter *flags; 673 }; 674 675 extern insn_table *load_insn_table (const char *file_name, cache_entry *cache); 676 677 typedef void insn_entry_handler 678 (lf *file, const insn_table *isa, const insn_entry *insn, void *data); 679 680 extern void insn_table_traverse_insn 681 (lf *file, const insn_table *isa, insn_entry_handler *handler, void *data); 682 683 684 685 /* Printing */ 686 687 extern void print_insn_words (lf *file, const insn_entry *insn); 688 689 690 691 /* Debugging */ 692 693 void dump_insn_field 694 (lf *file, const char *prefix, const insn_field_entry *field, 695 const char *suffix); 696 697 void dump_insn_word_entry 698 (lf *file, const char *prefix, const insn_word_entry *word, 699 const char *suffix); 700 701 void dump_insn_entry 702 (lf *file, const char *prefix, const insn_entry *insn, const char *suffix); 703 704 void dump_cache_entries 705 (lf *file, const char *prefix, const cache_entry *entry, const char *suffix); 706 707 void dump_insn_table 708 (lf *file, const char *prefix, const insn_table *isa, const char *suffix); 709 710 #endif /* IGEN_LD_INSN_H */ 711