Fix: symbols eliminated by --gc-sections still trigger warnings for gnu.warning.SYM
[binutils-gdb.git] / sim / igen / ld-insn.h
blobd22b855e1ce1d6e0d4c1b18c374bcaea1eb2922d
1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2023 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 uint64_t 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, const function_entry *function, void *data);
224 extern void function_entry_traverse
225 (lf *file,
226 const function_entry *functions,
227 function_entry_handler * handler, void *data);
230 /* cache-macro:
232 <cache-macro> ::=
233 ":" <macro-type>
234 ":" <filter-flags>
235 ":" <filter-models>
236 ":" <typedef>
237 ":" <name>
238 ":" <field-name> { "," <field-name> }
239 ":" <expression>
240 <nl>
243 <cache-macro-type> ::=
244 "scratch"
245 | "cache"
246 | "compute"
249 <name> ::=
250 <ident>
251 | <ident> "_is_" <integer>
254 A cache entry is defined (for an instruction) when all
255 <field-name>s are present as named opcode fields within the
256 instructions format.
258 SCRATCH and CACHE macros are defined during the cache fill stage
259 while CACHE and COMPUTE macros are defined during the instruction
260 execution stage.
264 enum
266 cache_typedef_field = 4,
267 cache_name_field,
268 cache_original_fields_field,
269 cache_expression_field,
270 nr_cache_fields,
273 typedef enum
275 scratch_value,
276 cache_value,
277 compute_value,
279 cache_entry_type;
281 typedef struct _cache_entry cache_entry;
282 struct _cache_entry
284 line_ref *line;
285 filter *flags;
286 filter *models;
287 cache_entry_type entry_type;
288 char *name;
289 filter *original_fields;
290 char *type;
291 char *expression;
292 cache_entry *next;
297 /* Model specs:
299 <model-processor> ::=
300 ":" "model"
301 ":" <filter-flags>
302 ":" <filter-models>
303 ":" <processor>
304 ":" <BFD-processor>
305 ":" <function-unit-data>
306 <nl>
309 <model-macro> ::=
310 ":" "model-macro"
311 ":" <filter-flags>
312 ":" <filter-models>
313 <nl>
314 <code-block>
317 <model-data> ::=
318 ":" "model-data"
319 ":" <filter-flags>
320 ":" <filter-models>
321 <nl>
322 <code-block>
325 <model-static> ::=
326 ":" "model-static"
327 <function-spec>
330 <model-internal> ::=
331 ":" "model-internal"
332 <function-spec>
335 <model-function> ::=
336 ":" "model-internal"
337 <function-spec>
342 enum
344 nr_model_macro_fields = 4,
345 nr_model_data_fields = 4,
346 nr_model_static_fields = nr_function_fields,
347 nr_model_internal_fields = nr_function_fields,
348 nr_model_function_fields = nr_function_fields,
351 typedef struct _model_data model_data;
352 struct _model_data
354 line_ref *line;
355 filter *flags;
356 table_entry *entry;
357 table_entry *code;
358 model_data *next;
361 enum
363 model_name_field = 4,
364 model_full_name_field,
365 model_unit_data_field,
366 nr_model_processor_fields,
369 typedef struct _model_entry model_entry;
370 struct _model_entry
372 line_ref *line;
373 filter *flags;
374 char *name;
375 char *full_name;
376 char *unit_data;
377 model_entry *next;
381 typedef struct _model_table model_table;
382 struct _model_table
384 filter *processors;
385 int nr_models;
386 model_entry *models;
387 model_data *macros;
388 model_data *data;
389 function_entry *statics;
390 function_entry *internals;
391 function_entry *functions;
396 /* Instruction format:
398 An instruction is composed of a sequence of N bit instruction
399 words. Each word broken into a number of instruction fields.
400 Those fields being constant (ex. an opcode) or variable (register
401 spec).
403 <insn-word> ::=
404 <insn-field> { "," <insn-field> } ;
406 <insn-field> ::=
407 ( <binary-value-implying-width>
408 | <field-name-implying-width>
409 | [ <start-or-width> "." ] <field>
411 { [ "!" | "=" ] [ <value> | <field-name> ] }
414 <field> ::=
415 { "*" }+
416 | { "/" }+
417 | <field-name>
418 | "0x" <hex-value>
419 | "0b" <binary-value>
420 | "0" <octal-value>
421 | <integer-value> ;
425 typedef enum _insn_field_cond_type
427 insn_field_cond_value,
428 insn_field_cond_field,
430 insn_field_cond_type;
431 typedef enum _insn_field_cond_test
433 insn_field_cond_eq,
434 insn_field_cond_ne,
436 insn_field_cond_test;
437 typedef struct _insn_field_cond insn_field_cond;
438 struct _insn_field_cond
440 insn_field_cond_type type;
441 insn_field_cond_test test;
442 insn_uint value;
443 struct _insn_field_entry *field;
444 char *string;
445 insn_field_cond *next;
449 typedef enum _insn_field_type
451 insn_field_invalid,
452 insn_field_int,
453 insn_field_reserved,
454 insn_field_wild,
455 insn_field_string,
457 insn_field_type;
459 typedef struct _insn_field_entry insn_field_entry;
460 struct _insn_field_entry
462 int first;
463 int last;
464 int width;
465 int word_nr;
466 insn_field_type type;
467 insn_uint val_int;
468 char *pos_string;
469 char *val_string;
470 insn_field_cond *conditions;
471 insn_field_entry *next;
472 insn_field_entry *prev;
475 typedef struct _insn_bit_entry insn_bit_entry;
476 struct _insn_bit_entry
478 int value;
479 int mask;
480 insn_field_entry *field;
486 typedef struct _insn_entry insn_entry; /* forward */
488 typedef struct _insn_word_entry insn_word_entry;
489 struct _insn_word_entry
491 /* list of sub-fields making up the instruction. bit provides
492 faster access to the field data for bit N. */
493 insn_field_entry *first;
494 insn_field_entry *last;
495 insn_bit_entry *bit[max_insn_bit_size];
496 /* set of all the string fields */
497 filter *field_names;
498 /* For multi-word instructions, The Nth word (from zero). */
499 insn_word_entry *next;
504 /* Instruction model:
506 Provides scheduling and other data for the code modeling the
507 instruction unit.
509 <insn-model> ::=
510 "*" [ <processor-list> ]
511 ":" [ <function-unit-data> ]
512 <nl>
515 <processor-list> ::=
516 <processor> { "," <processor>" }
519 If the <processor-list> is empty, the model is made the default for
520 this instruction.
524 enum
526 insn_model_name_field = 0,
527 insn_model_unit_data_field = 1,
528 nr_insn_model_fields = 1,
531 typedef struct _insn_model_entry insn_model_entry;
532 struct _insn_model_entry
534 line_ref *line;
535 insn_entry *insn;
536 filter *names;
537 char *full_name;
538 char *unit_data;
539 insn_model_entry *next;
544 /* Instruction mnemonic:
546 List of assembler mnemonics for the instruction.
548 <insn-mnenonic> ::=
549 "\"" <assembler-mnemonic> "\""
550 [ ":" <conditional-expression> ]
551 <nl>
554 An assembler mnemonic string has the syntax:
556 <assembler-mnemonic> ::=
557 ( [ "%" <format-spec> ] "<" <func> [ "#" <param-list> ] ">"
558 | "%%"
559 | <other-letter>
562 Where, for instance, the text is translated into a printf format
563 and argument pair:
565 "<FUNC>" : "%ld", (long) FUNC
566 "%<FUNC>..." : "%...", FUNC
567 "%s<FUNC>" : "%s", <%s>FUNC (SD_, FUNC)
568 "%s<FUNC#P1,P2>" : "%s", <%s>FUNC (SD_, P1,P2)
569 "%lx<FUNC>" : "%lx", (unsigned long) FUNC
570 "%08lx<FUNC>" : "%08lx", (unsigned long) FUNC
572 And "<%s>FUNC" denotes a function declared using the "%s" record
573 specifier.
581 enum
583 insn_mnemonic_format_field = 0,
584 insn_mnemonic_condition_field = 1,
585 nr_insn_mnemonic_fields = 1,
588 typedef struct _insn_mnemonic_entry insn_mnemonic_entry;
589 struct _insn_mnemonic_entry
591 line_ref *line;
592 insn_entry *insn;
593 char *format;
594 char *condition;
595 insn_mnemonic_entry *next;
600 /* Instruction:
602 <insn> ::=
603 <insn-word> { "+" <insn-word> }
604 ":" <format-name>
605 ":" <filter-flags>
606 ":" <options>
607 ":" <name>
608 <nl>
609 { <insn-model> }
610 { <insn-mnemonic> }
611 <code-block>
615 enum
617 insn_word_field = 0,
618 insn_format_name_field = 1,
619 insn_filter_flags_field = 2,
620 insn_options_field = 3,
621 insn_name_field = 4,
622 nr_insn_fields = 5,
626 /* typedef struct _insn_entry insn_entry; */
627 struct _insn_entry
629 line_ref *line;
630 filter *flags; /* filtered by options.filters */
631 char *format_name;
632 filter *options;
633 char *name;
634 /* the words that make up the instruction. Word provides direct
635 access to word N. Pseudo instructions can be identified by
636 nr_words == 0. */
637 int nr_words;
638 insn_word_entry *words;
639 insn_word_entry **word;
640 /* a set of all the fields from all the words */
641 filter *field_names;
642 /* an array of processor models, missing models are NULL! */
643 int nr_models;
644 insn_model_entry *models;
645 insn_model_entry **model;
646 filter *processors;
647 /* list of assember formats */
648 int nr_mnemonics;
649 insn_mnemonic_entry *mnemonics;
650 /* code body */
651 table_entry *code;
652 insn_entry *next;
656 /* Instruction table:
660 typedef struct _insn_table insn_table;
661 struct _insn_table
663 cache_entry *caches;
664 int max_nr_words;
665 int nr_insns;
666 insn_entry *insns;
667 function_entry *functions;
668 insn_entry *illegal_insn;
669 model_table *model;
670 filter *options;
671 filter *flags;
674 extern insn_table *load_insn_table (const char *file_name, cache_entry *cache);
676 typedef void insn_entry_handler
677 (lf *file, const insn_table *isa, const insn_entry *insn, void *data);
679 extern void insn_table_traverse_insn
680 (lf *file, const insn_table *isa, insn_entry_handler *handler, void *data);
684 /* Printing */
686 extern void print_insn_words (lf *file, const insn_entry *insn);
690 /* Debugging */
692 void dump_insn_field
693 (lf *file, const char *prefix, const insn_field_entry *field,
694 const char *suffix);
696 void dump_insn_word_entry
697 (lf *file, const char *prefix, const insn_word_entry *word,
698 const char *suffix);
700 void dump_insn_entry
701 (lf *file, const char *prefix, const insn_entry *insn, const char *suffix);
703 void dump_cache_entries
704 (lf *file, const char *prefix, const cache_entry *entry, const char *suffix);
706 void dump_insn_table
707 (lf *file, const char *prefix, const insn_table *isa, const char *suffix);