Add support for 16 byte quantities to sim-endian macro H2T.
[external/binutils.git] / sim / igen / ld-insn.h
1 /*  This file is part of the program psim.
2
3     Copyright (C) 1994,1995,1996,1997 Andrew Cagney <cagney@highland.com.au>
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 2 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, write to the Free Software
17     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  
19     */
20
21
22
23 typedef unsigned64 insn_uint;
24
25
26 /* Common among most entries:
27
28    All non instruction records have the format:
29
30    <...> ::=
31        ":" <record-name>
32        ":" <filter-flags>
33        ":" <filter-models>
34        ":" ...
35    
36  */
37
38 enum {
39   record_type_field = 1,
40   old_record_type_field = 2,
41   record_filter_flags_field = 2,
42   record_filter_models_field = 3,
43 };
44
45
46 /* Include:
47
48    Include the specified file.
49
50    <include> ::=
51        ":" "include"
52        ":" <filter-flags>
53        ":" <filter-models>
54        ":" <filename>
55        <nl>
56        ;
57
58    */
59
60 enum {
61   include_filename_field = 4,
62   nr_include_fields,
63 };
64
65
66
67 /* Options:
68
69    Valid options are: hi-bit-nr (default 0), insn-bit-size (default
70    32), insn-specifying-widths (default true), multi-sim (default false).
71
72    <option> ::=
73        ":" "option"
74        ":" <filter-flags>
75        ":" <filter-models>
76        ":" <option-name>
77        ":" <option-value>
78        <nl>
79        ;
80
81    <option-name> ::=
82        "insn-bit-size"
83        | "insn-specifying-widths"
84        | "hi-bit-nr"
85        | "flags-filter"
86        | "model-filter"
87        | "multi-sim"
88        | "format-names"
89        ;
90
91    <option-value> ::=
92        "true"
93        | "false"
94        | <integer>
95        | <list>
96        ;
97
98
99    These update the global options structure. */       
100
101
102 enum {
103   option_name_field = 4,
104   option_value_field,
105   nr_option_fields,
106 };
107
108
109
110 /* Macro definitions:
111
112    <insn-macro> ::=
113        <expression>
114        ":" ( "define" | "undef" )
115        ":" <filter-flags>
116        ":" <filter-models>
117        ":" <name>
118        <nl>
119        ;
120
121    Macro define/undef is currently unimplemented. */
122
123
124 /* Functions and internal routins:
125
126    <function> ::=
127        ":" "function"
128        <function-spec>
129        ;
130
131    <internal> ::=
132        ":" "internal"
133        <function-spec>
134        ;
135
136    <format> ::=
137        ":" ( "%s" | ... )
138        <function-spec>
139        ;
140
141    <function-spec> ::=
142        ":" <filter-flags>
143        ":" <filter-models>
144        ":" <typedef>
145        ":" <name>
146        [ ":" <parameter-list> ]
147        <nl>
148        <code-block>
149        ;
150
151    */
152
153 enum {
154   function_typedef_field = 4,
155   function_name_field,
156   function_param_field,
157   nr_function_fields,
158 };
159
160 enum {
161   old_function_typedef_field = 0,
162   old_function_type_field = 2,
163   old_function_name_field = 4,
164   old_function_param_field = 5,
165   nr_old_function_fields = 5, /* parameter-list is optional */
166 };
167
168
169 typedef struct _function_entry function_entry;
170 struct _function_entry {
171   line_ref *line;
172   filter *flags;
173   filter *models;
174   char *type;
175   char *name;
176   char *param;
177   table_entry *code;
178   int is_internal;
179   function_entry *next;
180 };
181
182
183 typedef void function_entry_handler
184 (lf *file,
185  function_entry *function,
186  void *data);
187
188 extern void function_entry_traverse
189 (lf *file,
190  function_entry *functions,
191  function_entry_handler *handler,
192  void *data);
193
194
195 /* cache-macro:
196
197    <cache-macro> ::=
198        ":" <macro-type>
199        ":" <filter-flags>
200        ":" <filter-models>
201        ":" <typedef>
202        ":" <name>
203        ":" <field-name> { "," <field-name> }
204        ":" <expression>
205        <nl>
206        ;
207
208    <cache-macro-type> ::=
209        "scratch"
210        | "cache"
211        | "compute"
212        ;
213
214    <name> ::=
215        <ident>
216        | <ident> "_is_" <integer>
217        ;
218
219    A cache entry is defined (for an instruction) when all
220    <field-name>s are present as named opcode fields within the
221    instructions format.
222
223    SCRATCH and CACHE macros are defined during the cache fill stage
224    while CACHE and COMPUTE macros are defined during the instruction
225    execution stage.
226
227    */
228
229 enum {
230   cache_typedef_field = 4,
231   cache_name_field,
232   cache_original_fields_field,
233   cache_expression_field,
234   nr_cache_fields,
235 };
236
237 typedef enum {
238   scratch_value,
239   cache_value,
240   compute_value,
241 } cache_entry_type;
242
243 typedef struct _cache_entry cache_entry;
244 struct _cache_entry {
245   line_ref *line;
246   filter *flags;
247   filter *models;
248   cache_entry_type entry_type;
249   char *name;
250   filter *original_fields;
251   char *type;
252   char *expression;
253   cache_entry *next;
254 };
255
256
257
258 /* Model specs:
259
260    <model-processor> ::=
261        ":" "model"
262        ":" <filter-flags>
263        ":" <filter-models>
264        ":" <processor>
265        ":" <long-processor>
266        ":" <function-unit-data>
267        <nl>
268        ;
269
270    <model-macro> ::=
271        ":" "model-macro"
272        ":" <filter-flags>
273        ":" <filter-models>
274        <nl>
275        <code-block>
276        ;
277
278    <model-data> ::=
279        ":" "model-data"
280        ":" <filter-flags>
281        ":" <filter-models>
282        <nl>
283        <code-block>
284        ;
285
286    <model-static> ::=
287        ":" "model-static"
288        <function-spec>
289        ;
290
291    <model-internal> ::=
292        ":" "model-internal"
293        <function-spec>
294        ;
295
296    <model-function> ::=
297        ":" "model-internal"
298        <function-spec>
299        ;
300
301  */
302
303 enum {
304   nr_model_macro_fields = 4,
305   nr_model_data_fields = 4,
306   nr_model_static_fields = nr_function_fields,
307   nr_model_internal_fields = nr_function_fields,
308   nr_model_function_fields = nr_function_fields,
309 };
310
311 typedef struct _model_data model_data;
312 struct _model_data {
313   line_ref *line;
314   filter *flags;
315   table_entry *entry;
316   table_entry *code;
317   model_data *next;
318 };
319
320 enum {
321   model_name_field = 4,
322   model_full_name_field,
323   model_unit_data_field,
324   nr_model_processor_fields,
325 };
326
327 typedef struct _model_entry model_entry;
328 struct _model_entry {
329   line_ref *line;
330   filter *flags;
331   char *name;
332   char *full_name;
333   char *unit_data;
334   model_entry *next;
335 };
336
337
338 typedef struct _model_table model_table;
339 struct _model_table {
340   filter *processors;
341   int nr_models;
342   model_entry *models;
343   model_data *macros;
344   model_data *data;
345   function_entry *statics;
346   function_entry *internals;
347   function_entry *functions;
348 };
349
350
351
352 /* Instruction format:
353
354    An instruction is composed of a sequence of N bit instruction
355    words.  Each word broken into a number of instruction fields.
356    Those fields being constant (ex. an opcode) or variable (register
357    spec).
358
359    <insn-word> ::=
360        <insn-field> { "," <insn-field> } ;
361
362    <insn-word> ::=
363        ( <binary-value-implying-width>
364        | <field-name-implying-width>
365        | [ <start-or-width> "." ] <field> 
366        )
367        { "!" <excluded-value> }
368        ;
369
370    <field> ::=
371        "*" +
372        | "/" +
373        | <field-name>
374        | "0x" <hex-value>
375        | "0b" <binary-value>
376        | "0" <octal-value>
377        | <integer-value> ;
378
379 */
380
381 typedef struct _insn_field_exclusion insn_field_exclusion;
382 struct _insn_field_exclusion {
383   char *string;
384   insn_uint value;
385   insn_field_exclusion *next;
386 };
387
388 typedef enum {
389   insn_field_int,
390   insn_field_reserved,
391   insn_field_wild,
392   insn_field_string,
393 } insn_field_type;
394
395 typedef struct _insn_field_entry insn_field_entry;
396 struct _insn_field_entry {
397   int first;
398   int last;
399   int width;
400   int word_nr;
401   insn_field_type type;
402   insn_uint val_int;
403   char *pos_string;
404   char *val_string;
405   insn_field_exclusion *exclusions;
406   insn_field_entry *next;
407   insn_field_entry *prev;
408 };
409
410 typedef struct _insn_bit_entry insn_bit_entry;
411 struct _insn_bit_entry {
412   int value;
413   int mask;
414   insn_field_entry *field;
415 };
416
417
418
419
420 typedef struct _insn_entry insn_entry; /* forward */
421
422 typedef struct _insn_word_entry insn_word_entry;
423 struct _insn_word_entry {
424   /* list of sub-fields making up the instruction.  bit provides
425      faster access to the field data for bit N.  */
426   insn_field_entry *first;
427   insn_field_entry *last;
428   insn_bit_entry *bit[max_insn_bit_size];
429   /* set of all the string fields */
430   filter *field_names;
431   /* For multi-word instructions, The Nth word (from zero). */
432   insn_word_entry *next;
433 };
434
435
436
437 /* Instruction model:
438
439    Provides scheduling data for the code modeling the instruction unit. 
440
441    <insn-model> ::=
442        "*" [ <processor> ]
443        ":" <function-unit-data>
444        <nl>
445        ;
446
447    If <processor> is NULL, the model is made the default for this
448    instruction.
449
450    */
451
452 enum {
453   insn_model_name_field = 0,
454   insn_model_unit_data_field = 1,
455   nr_insn_model_fields = 1,
456 };
457
458 typedef struct _insn_model_entry insn_model_entry;
459 struct _insn_model_entry {
460   line_ref *line;
461   insn_entry *insn;
462   char *name;
463   char *full_name;
464   char *unit_data;
465   insn_model_entry *next;
466 };
467
468
469
470 /* Instruction mnemonic:
471
472    List of assembler mnemonics for the instruction.
473
474    <insn-mnenonic> ::=
475        "\"" <assembler-mnemonic> "\""
476        [ ":" <conditional-expression> ]
477        <nl>
478        ;
479
480    */
481
482 enum {
483   insn_mnemonic_format_field = 0,
484   insn_mnemonic_condition_field = 1,
485   nr_insn_mnemonic_fields = 1,
486 };
487
488 typedef struct _insn_mnemonic_entry insn_mnemonic_entry;
489 struct _insn_mnemonic_entry {
490   line_ref *line;
491   insn_entry *insn;
492   char *format;
493   char *condition;
494   insn_mnemonic_entry *next;
495 };
496
497
498
499 /* Instruction:
500
501    <insn> ::=
502        <insn-word> { "+" <insn-word> }
503        ":" <format-name>
504        ":" <filter-flags>
505        ":" <options>
506        ":" <name>
507        <nl>
508        { <insn-model> }
509        { <insn-mnemonic> }
510        <code-block>
511
512  */
513
514 enum {
515   insn_word_field = 0,
516   insn_format_name_field = 1,
517   insn_filter_flags_field = 2,
518   insn_options_field = 3,
519   insn_name_field = 4,
520   nr_insn_fields = 5,
521 };
522
523
524 /* typedef struct _insn_entry insn_entry; */
525 struct _insn_entry {
526   line_ref *line;
527   filter *flags; /* filtered by options.filters */
528   char *format_name;
529   filter *options;
530   char *name;
531   /* the words that make up the instruction. Word provides direct
532      access to word N. Pseudo instructions can be identified by
533      nr_words == 0. */
534   int nr_words;
535   insn_word_entry *words;
536   insn_word_entry **word;
537   /* a set of all the fields from all the words */
538   filter *field_names;
539   /* an array of processor models, missing models are NULL! */
540   int nr_models;
541   insn_model_entry *models;
542   insn_model_entry **model;
543   filter *processors;
544   /* list of assember formats */
545   int nr_mnemonics;
546   insn_mnemonic_entry *mnemonics;
547   /* code body */
548   table_entry *code;
549   insn_entry *next;
550 };
551
552
553 /* Instruction table:
554
555  */
556
557 typedef struct _insn_table insn_table;
558 struct _insn_table {
559   cache_entry *caches;
560   int max_nr_words;
561   int nr_insns;
562   insn_entry *insns;
563   function_entry *functions;
564   insn_entry *illegal_insn;
565   model_table *model;
566   filter *options;
567   filter *flags;
568 };
569
570 extern insn_table *load_insn_table
571 (char *file_name,
572  cache_entry *cache);
573
574 typedef void insn_entry_handler
575 (lf *file,
576  insn_table *isa,
577  insn_entry *insn,
578  void *data);
579
580 extern void insn_table_traverse_insn
581 (lf *file,
582  insn_table *isa,
583  insn_entry_handler *handler,
584  void *data);
585
586
587
588 /* Printing */
589
590 extern void print_insn_words
591 (lf *file,
592  insn_entry *insn);
593
594
595
596 /* Debugging */
597
598 void
599 dump_insn_field
600 (lf *file,
601  char *prefix,
602  insn_field_entry *field,
603  char *suffix);
604
605 void
606 dump_insn_word_entry
607 (lf *file,
608  char *prefix,
609  insn_word_entry *word,
610  char *suffix);
611
612 void
613 dump_insn_entry
614 (lf *file,
615  char *prefix,
616  insn_entry *insn,
617  char *suffix);
618
619 void
620 dump_cache_entries
621 (lf *file,
622  char *prefix,
623  cache_entry *entry,
624  char *suffix);
625
626 void
627 dump_insn_table
628 (lf *file,
629  char *prefix,
630  insn_table *isa,
631  char *suffix);