xref: /netbsd-src/external/gpl3/gdb.old/dist/sim/igen/ld-insn.h (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1 /* The IGEN simulator generator for GDB, the GNU Debugger.
2 
3    Copyright 2002-2023 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 
23 
24 typedef uint64_t insn_uint;
25 
26 
27 /* Common among most entries:
28 
29    All non instruction records have the format:
30 
31    <...> ::=
32        ":" <record-name>
33        ":" <filter-flags>
34        ":" <filter-models>
35        ":" ...
36 
37  */
38 
39 enum
40 {
41   record_type_field = 1,
42   old_record_type_field = 2,
43   record_filter_flags_field = 2,
44   record_filter_models_field = 3,
45 };
46 
47 
48 /* Include:
49 
50    Include the specified file.
51 
52    <include> ::=
53        ":" "include"
54        ":" <filter-flags>
55        ":" <filter-models>
56        ":" <filename>
57        <nl>
58        ;
59 
60    */
61 
62 enum
63 {
64   include_filename_field = 4,
65   nr_include_fields,
66 };
67 
68 
69 
70 /* Options:
71 
72    Valid options are: hi-bit-nr (default 0), insn-bit-size (default
73    32), insn-specifying-widths (default true), multi-sim (default false).
74 
75    <option> ::=
76        ":" "option"
77        ":" <filter-flags>
78        ":" <filter-models>
79        ":" <option-name>
80        ":" <option-value>
81        <nl>
82        ;
83 
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"
92        ;
93 
94    <option-value> ::=
95        "true"
96        | "false"
97        | <integer>
98        | <list>
99        ;
100 
101 
102    These update the global options structure. */
103 
104 
105 enum
106 {
107   option_name_field = 4,
108   option_value_field,
109   nr_option_fields,
110 };
111 
112 
113 
114 /* Macro definitions:
115 
116    <insn-macro> ::=
117        ":" "define"
118        ":" <filter-flags>
119        ":" <filter-models>
120        ":" <name>
121        ":" <arg-list>
122        ":" <expression>
123        <nl>
124        ;
125 
126    <arg-list> ::=
127        [ <name> { "," <arg-list> } ]
128        ;
129 
130    */
131 
132 
133 enum
134 {
135   macro_name_field = 4,
136   macro_args_field,
137   macro_expr_field,
138   nr_macro_fields,
139 };
140 
141 
142 
143 /* Functions and internal routins:
144 
145    NB: <filter-models> and <function-models> are equivalent.
146 
147 
148    <function> ::=
149        ":" "function"
150        <function-spec>
151        ;
152 
153    <internal> ::=
154        ":" "internal"
155        <function-spec>
156        ;
157 
158    <format> ::=
159        ":" ( "%s" | ... )
160        <function-spec>
161        ;
162 
163    <function-model> ::=
164        "*" [ <processor-list> ]
165        ":"
166        <nl>
167        ;
168 
169    <function-spec> ::=
170        ":" <filter-flags>
171        ":" <filter-models>
172        ":" <typedef>
173        ":" <name>
174        [ ":" <parameter-list> ]
175        <nl>
176        [ <function-model> ]
177        <code-block>
178        ;
179 
180    */
181 
182 enum
183 {
184   function_typedef_field = 4,
185   function_name_field,
186   function_param_field,
187   nr_function_fields,
188 };
189 
190 enum
191 {
192   function_model_name_field = 0,
193   nr_function_model_fields = 1,
194 };
195 
196 enum
197 {
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 */
203 };
204 
205 
206 typedef struct _function_entry function_entry;
207 struct _function_entry
208 {
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;
218 };
219 
220 
221 typedef void function_entry_handler
222   (lf *file, const function_entry *function, void *data);
223 
224 extern void function_entry_traverse
225   (lf *file,
226    const function_entry *functions,
227    function_entry_handler * handler, void *data);
228 
229 
230 /* cache-macro:
231 
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>
241        ;
242 
243    <cache-macro-type> ::=
244        "scratch"
245        | "cache"
246        | "compute"
247        ;
248 
249    <name> ::=
250        <ident>
251        | <ident> "_is_" <integer>
252        ;
253 
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.
257 
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.
261 
262    */
263 
264 enum
265 {
266   cache_typedef_field = 4,
267   cache_name_field,
268   cache_original_fields_field,
269   cache_expression_field,
270   nr_cache_fields,
271 };
272 
273 typedef enum
274 {
275   scratch_value,
276   cache_value,
277   compute_value,
278 }
279 cache_entry_type;
280 
281 typedef struct _cache_entry cache_entry;
282 struct _cache_entry
283 {
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;
293 };
294 
295 
296 
297 /* Model specs:
298 
299    <model-processor> ::=
300        ":" "model"
301        ":" <filter-flags>
302        ":" <filter-models>
303        ":" <processor>
304        ":" <BFD-processor>
305        ":" <function-unit-data>
306        <nl>
307        ;
308 
309    <model-macro> ::=
310        ":" "model-macro"
311        ":" <filter-flags>
312        ":" <filter-models>
313        <nl>
314        <code-block>
315        ;
316 
317    <model-data> ::=
318        ":" "model-data"
319        ":" <filter-flags>
320        ":" <filter-models>
321        <nl>
322        <code-block>
323        ;
324 
325    <model-static> ::=
326        ":" "model-static"
327        <function-spec>
328        ;
329 
330    <model-internal> ::=
331        ":" "model-internal"
332        <function-spec>
333        ;
334 
335    <model-function> ::=
336        ":" "model-internal"
337        <function-spec>
338        ;
339 
340  */
341 
342 enum
343 {
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,
349 };
350 
351 typedef struct _model_data model_data;
352 struct _model_data
353 {
354   line_ref *line;
355   filter *flags;
356   table_entry *entry;
357   table_entry *code;
358   model_data *next;
359 };
360 
361 enum
362 {
363   model_name_field = 4,
364   model_full_name_field,
365   model_unit_data_field,
366   nr_model_processor_fields,
367 };
368 
369 typedef struct _model_entry model_entry;
370 struct _model_entry
371 {
372   line_ref *line;
373   filter *flags;
374   char *name;
375   char *full_name;
376   char *unit_data;
377   model_entry *next;
378 };
379 
380 
381 typedef struct _model_table model_table;
382 struct _model_table
383 {
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;
392 };
393 
394 
395 
396 /* Instruction format:
397 
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).
402 
403    <insn-word> ::=
404        <insn-field> { "," <insn-field> } ;
405 
406    <insn-field> ::=
407        ( <binary-value-implying-width>
408        | <field-name-implying-width>
409        | [ <start-or-width> "." ] <field>
410        )
411        { [ "!" | "=" ] [ <value> | <field-name> ] }
412        ;
413 
414    <field> ::=
415          { "*" }+
416        | { "/" }+
417        | <field-name>
418        | "0x" <hex-value>
419        | "0b" <binary-value>
420        | "0" <octal-value>
421        | <integer-value> ;
422 
423 */
424 
425 typedef enum _insn_field_cond_type
426 {
427   insn_field_cond_value,
428   insn_field_cond_field,
429 }
430 insn_field_cond_type;
431 typedef enum _insn_field_cond_test
432 {
433   insn_field_cond_eq,
434   insn_field_cond_ne,
435 }
436 insn_field_cond_test;
437 typedef struct _insn_field_cond insn_field_cond;
438 struct _insn_field_cond
439 {
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;
446 };
447 
448 
449 typedef enum _insn_field_type
450 {
451   insn_field_invalid,
452   insn_field_int,
453   insn_field_reserved,
454   insn_field_wild,
455   insn_field_string,
456 }
457 insn_field_type;
458 
459 typedef struct _insn_field_entry insn_field_entry;
460 struct _insn_field_entry
461 {
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;
473 };
474 
475 typedef struct _insn_bit_entry insn_bit_entry;
476 struct _insn_bit_entry
477 {
478   int value;
479   int mask;
480   insn_field_entry *field;
481 };
482 
483 
484 
485 
486 typedef struct _insn_entry insn_entry;	/* forward */
487 
488 typedef struct _insn_word_entry insn_word_entry;
489 struct _insn_word_entry
490 {
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;
500 };
501 
502 
503 
504 /* Instruction model:
505 
506    Provides scheduling and other data for the code modeling the
507    instruction unit.
508 
509    <insn-model> ::=
510        "*" [ <processor-list> ]
511        ":" [ <function-unit-data> ]
512        <nl>
513        ;
514 
515    <processor-list> ::=
516        <processor> { "," <processor>" }
517        ;
518 
519    If the <processor-list> is empty, the model is made the default for
520    this instruction.
521 
522    */
523 
524 enum
525 {
526   insn_model_name_field = 0,
527   insn_model_unit_data_field = 1,
528   nr_insn_model_fields = 1,
529 };
530 
531 typedef struct _insn_model_entry insn_model_entry;
532 struct _insn_model_entry
533 {
534   line_ref *line;
535   insn_entry *insn;
536   filter *names;
537   char *full_name;
538   char *unit_data;
539   insn_model_entry *next;
540 };
541 
542 
543 
544 /* Instruction mnemonic:
545 
546    List of assembler mnemonics for the instruction.
547 
548    <insn-mnenonic> ::=
549        "\"" <assembler-mnemonic> "\""
550        [ ":" <conditional-expression> ]
551        <nl>
552        ;
553 
554    An assembler mnemonic string has the syntax:
555 
556    <assembler-mnemonic>  ::=
557        ( [ "%" <format-spec> ] "<" <func> [ "#" <param-list> ] ">"
558        | "%%"
559        | <other-letter>
560        )+
561 
562     Where, for instance, the text is translated into a printf format
563     and argument pair:
564 
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
571 
572     And "<%s>FUNC" denotes a function declared using the "%s" record
573     specifier.
574 
575 
576 
577        ;
578 
579    */
580 
581 enum
582 {
583   insn_mnemonic_format_field = 0,
584   insn_mnemonic_condition_field = 1,
585   nr_insn_mnemonic_fields = 1,
586 };
587 
588 typedef struct _insn_mnemonic_entry insn_mnemonic_entry;
589 struct _insn_mnemonic_entry
590 {
591   line_ref *line;
592   insn_entry *insn;
593   char *format;
594   char *condition;
595   insn_mnemonic_entry *next;
596 };
597 
598 
599 
600 /* Instruction:
601 
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>
612 
613  */
614 
615 enum
616 {
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,
623 };
624 
625 
626 /* typedef struct _insn_entry insn_entry; */
627 struct _insn_entry
628 {
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;
653 };
654 
655 
656 /* Instruction table:
657 
658  */
659 
660 typedef struct _insn_table insn_table;
661 struct _insn_table
662 {
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;
672 };
673 
674 extern insn_table *load_insn_table (const char *file_name, cache_entry *cache);
675 
676 typedef void insn_entry_handler
677   (lf *file, const insn_table *isa, const insn_entry *insn, void *data);
678 
679 extern void insn_table_traverse_insn
680   (lf *file, const insn_table *isa, insn_entry_handler *handler, void *data);
681 
682 
683 
684 /* Printing */
685 
686 extern void print_insn_words (lf *file, const insn_entry *insn);
687 
688 
689 
690 /* Debugging */
691 
692 void dump_insn_field
693   (lf *file, const char *prefix, const insn_field_entry *field,
694    const char *suffix);
695 
696 void dump_insn_word_entry
697   (lf *file, const char *prefix, const insn_word_entry *word,
698    const char *suffix);
699 
700 void dump_insn_entry
701   (lf *file, const char *prefix, const insn_entry *insn, const char *suffix);
702 
703 void dump_cache_entries
704   (lf *file, const char *prefix, const cache_entry *entry, const char *suffix);
705 
706 void dump_insn_table
707   (lf *file, const char *prefix, const insn_table *isa, const char *suffix);
708