[src/erc32] Use ncurses instead of termcap on Cygwin too
[binutils-gdb.git] / sim / igen / ld-insn.h
blob6806d58dd64a268ff5a1707a743d4ff6902c43b3
1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2018 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney.
7 This file is part of GDB.
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.
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.
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/>. */
24 typedef unsigned64 insn_uint;
27 /* Common among most entries:
29 All non instruction records have the format:
31 <...> ::=
32 ":" <record-name>
33 ":" <filter-flags>
34 ":" <filter-models>
35 ":" ...
39 enum
41 record_type_field = 1,
42 old_record_type_field = 2,
43 record_filter_flags_field = 2,
44 record_filter_models_field = 3,
48 /* Include:
50 Include the specified file.
52 <include> ::=
53 ":" "include"
54 ":" <filter-flags>
55 ":" <filter-models>
56 ":" <filename>
57 <nl>
62 enum
64 include_filename_field = 4,
65 nr_include_fields,
70 /* Options:
72 Valid options are: hi-bit-nr (default 0), insn-bit-size (default
73 32), insn-specifying-widths (default true), multi-sim (default false).
75 <option> ::=
76 ":" "option"
77 ":" <filter-flags>
78 ":" <filter-models>
79 ":" <option-name>
80 ":" <option-value>
81 <nl>
84 <option-name> ::=
85 "insn-bit-size"
86 | "insn-specifying-widths"
87 | "hi-bit-nr"
88 | "flags-filter"
89 | "model-filter"
90 | "multi-sim"
91 | "format-names"
94 <option-value> ::=
95 "true"
96 | "false"
97 | <integer>
98 | <list>
102 These update the global options structure. */
105 enum
107 option_name_field = 4,
108 option_value_field,
109 nr_option_fields,
114 /* Macro definitions:
116 <insn-macro> ::=
117 ":" "define"
118 ":" <filter-flags>
119 ":" <filter-models>
120 ":" <name>
121 ":" <arg-list>
122 ":" <expression>
123 <nl>
126 <arg-list> ::=
127 [ <name> { "," <arg-list> } ]
133 enum
135 macro_name_field = 4,
136 macro_args_field,
137 macro_expr_field,
138 nr_macro_fields,
143 /* Functions and internal routins:
145 NB: <filter-models> and <function-models> are equivalent.
148 <function> ::=
149 ":" "function"
150 <function-spec>
153 <internal> ::=
154 ":" "internal"
155 <function-spec>
158 <format> ::=
159 ":" ( "%s" | ... )
160 <function-spec>
163 <function-model> ::=
164 "*" [ <processor-list> ]
166 <nl>
169 <function-spec> ::=
170 ":" <filter-flags>
171 ":" <filter-models>
172 ":" <typedef>
173 ":" <name>
174 [ ":" <parameter-list> ]
175 <nl>
176 [ <function-model> ]
177 <code-block>
182 enum
184 function_typedef_field = 4,
185 function_name_field,
186 function_param_field,
187 nr_function_fields,
190 enum
192 function_model_name_field = 0,
193 nr_function_model_fields = 1,
196 enum
198 old_function_typedef_field = 0,
199 old_function_type_field = 2,
200 old_function_name_field = 4,
201 old_function_param_field = 5,
202 nr_old_function_fields = 5, /* parameter-list is optional */
206 typedef struct _function_entry function_entry;
207 struct _function_entry
209 line_ref *line;
210 filter *flags;
211 filter *models;
212 char *type;
213 char *name;
214 char *param;
215 table_entry *code;
216 int is_internal;
217 function_entry *next;
221 typedef void function_entry_handler
222 (lf *file, function_entry * function, void *data);
224 extern void function_entry_traverse
225 (lf *file,
226 function_entry * functions, function_entry_handler * handler, void *data);
229 /* cache-macro:
231 <cache-macro> ::=
232 ":" <macro-type>
233 ":" <filter-flags>
234 ":" <filter-models>
235 ":" <typedef>
236 ":" <name>
237 ":" <field-name> { "," <field-name> }
238 ":" <expression>
239 <nl>
242 <cache-macro-type> ::=
243 "scratch"
244 | "cache"
245 | "compute"
248 <name> ::=
249 <ident>
250 | <ident> "_is_" <integer>
253 A cache entry is defined (for an instruction) when all
254 <field-name>s are present as named opcode fields within the
255 instructions format.
257 SCRATCH and CACHE macros are defined during the cache fill stage
258 while CACHE and COMPUTE macros are defined during the instruction
259 execution stage.
263 enum
265 cache_typedef_field = 4,
266 cache_name_field,
267 cache_original_fields_field,
268 cache_expression_field,
269 nr_cache_fields,
272 typedef enum
274 scratch_value,
275 cache_value,
276 compute_value,
278 cache_entry_type;
280 typedef struct _cache_entry cache_entry;
281 struct _cache_entry
283 line_ref *line;
284 filter *flags;
285 filter *models;
286 cache_entry_type entry_type;
287 char *name;
288 filter *original_fields;
289 char *type;
290 char *expression;
291 cache_entry *next;
296 /* Model specs:
298 <model-processor> ::=
299 ":" "model"
300 ":" <filter-flags>
301 ":" <filter-models>
302 ":" <processor>
303 ":" <BFD-processor>
304 ":" <function-unit-data>
305 <nl>
308 <model-macro> ::=
309 ":" "model-macro"
310 ":" <filter-flags>
311 ":" <filter-models>
312 <nl>
313 <code-block>
316 <model-data> ::=
317 ":" "model-data"
318 ":" <filter-flags>
319 ":" <filter-models>
320 <nl>
321 <code-block>
324 <model-static> ::=
325 ":" "model-static"
326 <function-spec>
329 <model-internal> ::=
330 ":" "model-internal"
331 <function-spec>
334 <model-function> ::=
335 ":" "model-internal"
336 <function-spec>
341 enum
343 nr_model_macro_fields = 4,
344 nr_model_data_fields = 4,
345 nr_model_static_fields = nr_function_fields,
346 nr_model_internal_fields = nr_function_fields,
347 nr_model_function_fields = nr_function_fields,
350 typedef struct _model_data model_data;
351 struct _model_data
353 line_ref *line;
354 filter *flags;
355 table_entry *entry;
356 table_entry *code;
357 model_data *next;
360 enum
362 model_name_field = 4,
363 model_full_name_field,
364 model_unit_data_field,
365 nr_model_processor_fields,
368 typedef struct _model_entry model_entry;
369 struct _model_entry
371 line_ref *line;
372 filter *flags;
373 char *name;
374 char *full_name;
375 char *unit_data;
376 model_entry *next;
380 typedef struct _model_table model_table;
381 struct _model_table
383 filter *processors;
384 int nr_models;
385 model_entry *models;
386 model_data *macros;
387 model_data *data;
388 function_entry *statics;
389 function_entry *internals;
390 function_entry *functions;
395 /* Instruction format:
397 An instruction is composed of a sequence of N bit instruction
398 words. Each word broken into a number of instruction fields.
399 Those fields being constant (ex. an opcode) or variable (register
400 spec).
402 <insn-word> ::=
403 <insn-field> { "," <insn-field> } ;
405 <insn-field> ::=
406 ( <binary-value-implying-width>
407 | <field-name-implying-width>
408 | [ <start-or-width> "." ] <field>
410 { [ "!" | "=" ] [ <value> | <field-name> ] }
413 <field> ::=
414 { "*" }+
415 | { "/" }+
416 | <field-name>
417 | "0x" <hex-value>
418 | "0b" <binary-value>
419 | "0" <octal-value>
420 | <integer-value> ;
424 typedef enum _insn_field_cond_type
426 insn_field_cond_value,
427 insn_field_cond_field,
429 insn_field_cond_type;
430 typedef enum _insn_field_cond_test
432 insn_field_cond_eq,
433 insn_field_cond_ne,
435 insn_field_cond_test;
436 typedef struct _insn_field_cond insn_field_cond;
437 struct _insn_field_cond
439 insn_field_cond_type type;
440 insn_field_cond_test test;
441 insn_uint value;
442 struct _insn_field_entry *field;
443 char *string;
444 insn_field_cond *next;
448 typedef enum _insn_field_type
450 insn_field_invalid,
451 insn_field_int,
452 insn_field_reserved,
453 insn_field_wild,
454 insn_field_string,
456 insn_field_type;
458 typedef struct _insn_field_entry insn_field_entry;
459 struct _insn_field_entry
461 int first;
462 int last;
463 int width;
464 int word_nr;
465 insn_field_type type;
466 insn_uint val_int;
467 char *pos_string;
468 char *val_string;
469 insn_field_cond *conditions;
470 insn_field_entry *next;
471 insn_field_entry *prev;
474 typedef struct _insn_bit_entry insn_bit_entry;
475 struct _insn_bit_entry
477 int value;
478 int mask;
479 insn_field_entry *field;
485 typedef struct _insn_entry insn_entry; /* forward */
487 typedef struct _insn_word_entry insn_word_entry;
488 struct _insn_word_entry
490 /* list of sub-fields making up the instruction. bit provides
491 faster access to the field data for bit N. */
492 insn_field_entry *first;
493 insn_field_entry *last;
494 insn_bit_entry *bit[max_insn_bit_size];
495 /* set of all the string fields */
496 filter *field_names;
497 /* For multi-word instructions, The Nth word (from zero). */
498 insn_word_entry *next;
503 /* Instruction model:
505 Provides scheduling and other data for the code modeling the
506 instruction unit.
508 <insn-model> ::=
509 "*" [ <processor-list> ]
510 ":" [ <function-unit-data> ]
511 <nl>
514 <processor-list> ::=
515 <processor> { "," <processor>" }
518 If the <processor-list> is empty, the model is made the default for
519 this instruction.
523 enum
525 insn_model_name_field = 0,
526 insn_model_unit_data_field = 1,
527 nr_insn_model_fields = 1,
530 typedef struct _insn_model_entry insn_model_entry;
531 struct _insn_model_entry
533 line_ref *line;
534 insn_entry *insn;
535 filter *names;
536 char *full_name;
537 char *unit_data;
538 insn_model_entry *next;
543 /* Instruction mnemonic:
545 List of assembler mnemonics for the instruction.
547 <insn-mnenonic> ::=
548 "\"" <assembler-mnemonic> "\""
549 [ ":" <conditional-expression> ]
550 <nl>
553 An assembler mnemonic string has the syntax:
555 <assembler-mnemonic> ::=
556 ( [ "%" <format-spec> ] "<" <func> [ "#" <param-list> ] ">"
557 | "%%"
558 | <other-letter>
561 Where, for instance, the text is translated into a printf format
562 and argument pair:
564 "<FUNC>" : "%ld", (long) FUNC
565 "%<FUNC>..." : "%...", FUNC
566 "%s<FUNC>" : "%s", <%s>FUNC (SD_, FUNC)
567 "%s<FUNC#P1,P2>" : "%s", <%s>FUNC (SD_, P1,P2)
568 "%lx<FUNC>" : "%lx", (unsigned long) FUNC
569 "%08lx<FUNC>" : "%08lx", (unsigned long) FUNC
571 And "<%s>FUNC" denotes a function declared using the "%s" record
572 specifier.
580 enum
582 insn_mnemonic_format_field = 0,
583 insn_mnemonic_condition_field = 1,
584 nr_insn_mnemonic_fields = 1,
587 typedef struct _insn_mnemonic_entry insn_mnemonic_entry;
588 struct _insn_mnemonic_entry
590 line_ref *line;
591 insn_entry *insn;
592 char *format;
593 char *condition;
594 insn_mnemonic_entry *next;
599 /* Instruction:
601 <insn> ::=
602 <insn-word> { "+" <insn-word> }
603 ":" <format-name>
604 ":" <filter-flags>
605 ":" <options>
606 ":" <name>
607 <nl>
608 { <insn-model> }
609 { <insn-mnemonic> }
610 <code-block>
614 enum
616 insn_word_field = 0,
617 insn_format_name_field = 1,
618 insn_filter_flags_field = 2,
619 insn_options_field = 3,
620 insn_name_field = 4,
621 nr_insn_fields = 5,
625 /* typedef struct _insn_entry insn_entry; */
626 struct _insn_entry
628 line_ref *line;
629 filter *flags; /* filtered by options.filters */
630 char *format_name;
631 filter *options;
632 char *name;
633 /* the words that make up the instruction. Word provides direct
634 access to word N. Pseudo instructions can be identified by
635 nr_words == 0. */
636 int nr_words;
637 insn_word_entry *words;
638 insn_word_entry **word;
639 /* a set of all the fields from all the words */
640 filter *field_names;
641 /* an array of processor models, missing models are NULL! */
642 int nr_models;
643 insn_model_entry *models;
644 insn_model_entry **model;
645 filter *processors;
646 /* list of assember formats */
647 int nr_mnemonics;
648 insn_mnemonic_entry *mnemonics;
649 /* code body */
650 table_entry *code;
651 insn_entry *next;
655 /* Instruction table:
659 typedef struct _insn_table insn_table;
660 struct _insn_table
662 cache_entry *caches;
663 int max_nr_words;
664 int nr_insns;
665 insn_entry *insns;
666 function_entry *functions;
667 insn_entry *illegal_insn;
668 model_table *model;
669 filter *options;
670 filter *flags;
673 extern insn_table *load_insn_table (char *file_name, cache_entry *cache);
675 typedef void insn_entry_handler
676 (lf *file, insn_table *isa, insn_entry * insn, void *data);
678 extern void insn_table_traverse_insn
679 (lf *file, insn_table *isa, insn_entry_handler * handler, void *data);
683 /* Printing */
685 extern void print_insn_words (lf *file, insn_entry * insn);
689 /* Debugging */
691 void
692 dump_insn_field
693 (lf *file, char *prefix, insn_field_entry *field, char *suffix);
695 void
696 dump_insn_word_entry
697 (lf *file, char *prefix, insn_word_entry *word, char *suffix);
699 void
700 dump_insn_entry (lf *file, char *prefix, insn_entry * insn, char *suffix);
702 void
703 dump_cache_entries
704 (lf *file, char *prefix, cache_entry *entry, char *suffix);
706 void dump_insn_table (lf *file, char *prefix, insn_table *isa, char *suffix);