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