OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [include/] [opcode/] [cgen.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/* Header file for targets using CGEN: Cpu tools GENerator.
2
 
3
Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4
 
5
This file is part of GDB, the GNU debugger, and the GNU Binutils.
6
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License along
18
with this program; if not, write to the Free Software Foundation, Inc.,
19
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
 
21
#ifndef CGEN_H
22
#define CGEN_H
23
 
24
/* ??? This file requires bfd.h but only to get bfd_vma.
25
   Seems like an awful lot to require just to get such a fundamental type.
26
   Perhaps the definition of bfd_vma can be moved outside of bfd.h.
27
   Or perhaps one could duplicate its definition in another file.
28
   Until such time, this file conditionally compiles definitions that require
29
   bfd_vma using BFD_VERSION.  */
30
 
31
/* Enums must be defined before they can be used.
32
   Allow them to be used in struct definitions, even though the enum must
33
   be defined elsewhere.
34
   If CGEN_ARCH isn't defined, this file is being included by something other
35
   than <arch>-desc.h.  */
36
 
37
/* Prepend the arch name, defined in <arch>-desc.h, and _cgen_ to symbol S.
38
   The lack of spaces in the arg list is important for non-stdc systems.
39
   This file is included by <arch>-desc.h.
40
   It can be included independently of <arch>-desc.h, in which case the arch
41
   dependent portions will be declared as "unknown_cgen_foo".  */
42
 
43
#ifndef CGEN_SYM
44
#define CGEN_SYM(s) CONCAT3 (unknown,_cgen_,s)
45
#endif
46
 
47
/* This file contains the static (unchanging) pieces and as much other stuff
48
   as we can reasonably put here.  It's generally cleaner to put stuff here
49
   rather than having it machine generated if possible.  */
50
 
51
/* The assembler syntax is made up of expressions (duh...).
52
   At the lowest level the values are mnemonics, register names, numbers, etc.
53
   Above that are subexpressions, if any (an example might be the
54
   "effective address" in m68k cpus).  Subexpressions are wip.
55
   At the second highest level are the insns themselves.  Above that are
56
   pseudo-insns, synthetic insns, and macros, if any.  */
57
 
58
/* Lots of cpu's have a fixed insn size, or one which rarely changes,
59
   and it's generally easier to handle these by treating the insn as an
60
   integer type, rather than an array of characters.  So we allow targets
61
   to control this.  When an integer type the value is in host byte order,
62
   when an array of characters the value is in target byte order.  */
63
 
64
typedef unsigned int CGEN_INSN_INT;
65
#if CGEN_INT_INSN_P
66
typedef CGEN_INSN_INT CGEN_INSN_BYTES;
67
typedef CGEN_INSN_INT *CGEN_INSN_BYTES_PTR;
68
#else
69
typedef unsigned char *CGEN_INSN_BYTES;
70
typedef unsigned char *CGEN_INSN_BYTES_PTR;
71
#endif
72
 
73
#ifdef __GNUC__
74
#define CGEN_INLINE __inline__
75
#else
76
#define CGEN_INLINE
77
#endif
78
 
79
enum cgen_endian
80
{
81
  CGEN_ENDIAN_UNKNOWN,
82
  CGEN_ENDIAN_LITTLE,
83
  CGEN_ENDIAN_BIG
84
};
85
 
86
/* Forward decl.  */
87
 
88
typedef struct cgen_insn CGEN_INSN;
89
 
90
/* Opaque pointer version for use by external world.  */
91
 
92
typedef struct cgen_cpu_desc *CGEN_CPU_DESC;
93
 
94
/* Attributes.
95
   Attributes are used to describe various random things associated with
96
   an object (ifield, hardware, operand, insn, whatever) and are specified
97
   as name/value pairs.
98
   Integer attributes computed at compile time are currently all that's
99
   supported, though adding string attributes and run-time computation is
100
   straightforward.  Integer attribute values are always host int's
101
   (signed or unsigned).  For portability, this means 32 bits.
102
   Integer attributes are further categorized as boolean, bitset, integer,
103
   and enum types.  Boolean attributes appear frequently enough that they're
104
   recorded in one host int.  This limits the maximum number of boolean
105
   attributes to 32, though that's a *lot* of attributes.  */
106
 
107
/* Type of attribute values.  */
108
 
109
typedef int CGEN_ATTR_VALUE_TYPE;
110
 
111
/* Struct to record attribute information.  */
112
 
113
typedef struct
114
{
115
  /* Boolean attributes.  */
116
  unsigned int bool;
117
  /* Non-boolean integer attributes.  */
118
  CGEN_ATTR_VALUE_TYPE nonbool[1];
119
} CGEN_ATTR;
120
 
121
/* Define a structure member for attributes with N non-boolean entries.
122
   There is no maximum number of non-boolean attributes.
123
   There is a maximum of 32 boolean attributes (since they are all recorded
124
   in one host int).  */
125
 
126
#define CGEN_ATTR_TYPE(n) \
127
struct { unsigned int bool; \
128
         CGEN_ATTR_VALUE_TYPE nonbool[(n) ? (n) : 1]; }
129
 
130
/* Return the boolean attributes.  */
131
 
132
#define CGEN_ATTR_BOOLS(a) ((a)->bool)
133
 
134
/* Non-boolean attribute numbers are offset by this much.  */
135
 
136
#define CGEN_ATTR_NBOOL_OFFSET 32
137
 
138
/* Given a boolean attribute number, return its mask.  */
139
 
140
#define CGEN_ATTR_MASK(attr) (1 << (attr))
141
 
142
/* Return the value of boolean attribute ATTR in ATTRS.  */
143
 
144
#define CGEN_BOOL_ATTR(attrs, attr) ((CGEN_ATTR_MASK (attr) & (attrs)) != 0)
145
 
146
/* Return value of attribute ATTR in ATTR_TABLE for OBJ.
147
   OBJ is a pointer to the entity that has the attributes
148
   (??? not used at present but is reserved for future purposes - eventually
149
   the goal is to allow recording attributes in source form and computing
150
   them lazily at runtime, not sure of the details yet).  */
151
 
152
#define CGEN_ATTR_VALUE(obj, attr_table, attr) \
153
((unsigned int) (attr) < CGEN_ATTR_NBOOL_OFFSET \
154
 ? ((CGEN_ATTR_BOOLS (attr_table) & CGEN_ATTR_MASK (attr)) != 0) \
155
 : ((attr_table)->nonbool[(attr) - CGEN_ATTR_NBOOL_OFFSET]))
156
 
157
/* Attribute name/value tables.
158
   These are used to assist parsing of descriptions at run-time.  */
159
 
160
typedef struct
161
{
162
  const char * name;
163
  CGEN_ATTR_VALUE_TYPE value;
164
} CGEN_ATTR_ENTRY;
165
 
166
/* For each domain (ifld,hw,operand,insn), list of attributes.  */
167
 
168
typedef struct
169
{
170
  const char * name;
171
  const CGEN_ATTR_ENTRY * dfault;
172
  const CGEN_ATTR_ENTRY * vals;
173
} CGEN_ATTR_TABLE;
174
 
175
/* Instruction set variants.  */
176
 
177
typedef struct {
178
  const char *name;
179
 
180
  /* Default instruction size (in bits).
181
     This is used by the assembler when it encounters an unknown insn.  */
182
  unsigned int default_insn_bitsize;
183
 
184
  /* Base instruction size (in bits).
185
     For non-LIW cpus this is generally the length of the smallest insn.
186
     For LIW cpus its wip (work-in-progress).  For the m32r its 32.  */
187
  unsigned int base_insn_bitsize;
188
 
189
  /* Minimum/maximum instruction size (in bits).  */
190
  unsigned int min_insn_bitsize;
191
  unsigned int max_insn_bitsize;
192
} CGEN_ISA;
193
 
194
/* Machine variants.  */
195
 
196
typedef struct {
197
  const char *name;
198
  /* The argument to bfd_arch_info->scan.  */
199
  const char *bfd_name;
200
  /* one of enum mach_attr */
201
  int num;
202
} CGEN_MACH;
203
 
204
/* Parse result (also extraction result).
205
 
206
   The result of parsing an insn is stored here.
207
   To generate the actual insn, this is passed to the insert handler.
208
   When printing an insn, the result of extraction is stored here.
209
   To print the insn, this is passed to the print handler.
210
 
211
   It is machine generated so we don't define it here,
212
   but we do need a forward decl for the handler fns.
213
 
214
   There is one member for each possible field in the insn.
215
   The type depends on the field.
216
   Also recorded here is the computed length of the insn for architectures
217
   where it varies.
218
*/
219
 
220
typedef struct cgen_fields CGEN_FIELDS;
221
 
222
/* Total length of the insn, as recorded in the `fields' struct.  */
223
/* ??? The field insert handler has lots of opportunities for optimization
224
   if it ever gets inlined.  On architectures where insns all have the same
225
   size, may wish to detect that and make this macro a constant - to allow
226
   further optimizations.  */
227
 
228
#define CGEN_FIELDS_BITSIZE(fields) ((fields)->length)
229
 
230
/* Extraction support for variable length insn sets.  */
231
 
232
/* When disassembling we don't know the number of bytes to read at the start.
233
   So the first CGEN_BASE_INSN_SIZE bytes are read at the start and the rest
234
   are read when needed.  This struct controls this.  It is basically the
235
   disassemble_info stuff, except that we provide a cache for values already
236
   read (since bytes can typically be read several times to fetch multiple
237
   operands that may be in them), and that extraction of fields is needed
238
   in contexts other than disassembly.  */
239
 
240
typedef struct {
241
  /* A pointer to the disassemble_info struct.
242
     We don't require dis-asm.h so we use PTR for the type here.
243
     If NULL, BYTES is full of valid data (VALID == -1).  */
244
  PTR dis_info;
245
  /* Points to a working buffer of sufficient size.  */
246
  unsigned char *insn_bytes;
247
  /* Mask of bytes that are valid in INSN_BYTES.  */
248
  unsigned int valid;
249
} CGEN_EXTRACT_INFO;
250
 
251
/* Associated with each insn or expression is a set of "handlers" for
252
   performing operations like parsing, printing, etc.  These require a bfd_vma
253
   value to be passed around but we don't want all applications to need bfd.h.
254
   So this stuff is only provided if bfd.h has been included.  */
255
 
256
/* Parse handler.
257
   CD is a cpu table descriptor.
258
   INSN is a pointer to a struct describing the insn being parsed.
259
   STRP is a pointer to a pointer to the text being parsed.
260
   FIELDS is a pointer to a cgen_fields struct in which the results are placed.
261
   If the expression is successfully parsed, *STRP is updated.
262
   If not it is left alone.
263
   The result is NULL if success or an error message.  */
264
typedef const char * (cgen_parse_fn)
265
     PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *insn_,
266
              const char **strp_, CGEN_FIELDS *fields_));
267
 
268
/* Insert handler.
269
   CD is a cpu table descriptor.
270
   INSN is a pointer to a struct describing the insn being parsed.
271
   FIELDS is a pointer to a cgen_fields struct from which the values
272
   are fetched.
273
   INSNP is a pointer to a buffer in which to place the insn.
274
   PC is the pc value of the insn.
275
   The result is an error message or NULL if success.  */
276
 
277
#ifdef BFD_VERSION
278
typedef const char * (cgen_insert_fn)
279
     PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *insn_,
280
              CGEN_FIELDS *fields_, CGEN_INSN_BYTES_PTR insnp_,
281
              bfd_vma pc_));
282
#else
283
typedef const char * (cgen_insert_fn) ();
284
#endif
285
 
286
/* Extract handler.
287
   CD is a cpu table descriptor.
288
   INSN is a pointer to a struct describing the insn being parsed.
289
   The second argument is a pointer to a struct controlling extraction
290
   (only used for variable length insns).
291
   EX_INFO is a pointer to a struct for controlling reading of further
292
   bytes for the insn.
293
   BASE_INSN is the first CGEN_BASE_INSN_SIZE bytes (host order).
294
   FIELDS is a pointer to a cgen_fields struct in which the results are placed.
295
   PC is the pc value of the insn.
296
   The result is the length of the insn in bits or zero if not recognized.  */
297
 
298
#ifdef BFD_VERSION
299
typedef int (cgen_extract_fn)
300
     PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *insn_,
301
              CGEN_EXTRACT_INFO *ex_info_, CGEN_INSN_INT base_insn_,
302
              CGEN_FIELDS *fields_, bfd_vma pc_));
303
#else
304
typedef int (cgen_extract_fn) ();
305
#endif
306
 
307
/* Print handler.
308
   CD is a cpu table descriptor.
309
   INFO is a pointer to the disassembly info.
310
   Eg: disassemble_info.  It's defined as `PTR' so this file can be included
311
   without dis-asm.h.
312
   INSN is a pointer to a struct describing the insn being printed.
313
   FIELDS is a pointer to a cgen_fields struct.
314
   PC is the pc value of the insn.
315
   LEN is the length of the insn, in bits.  */
316
 
317
#ifdef BFD_VERSION
318
typedef void (cgen_print_fn)
319
     PARAMS ((CGEN_CPU_DESC, PTR info_, const CGEN_INSN *insn_,
320
              CGEN_FIELDS *fields_, bfd_vma pc_, int len_));
321
#else
322
typedef void (cgen_print_fn) ();
323
#endif
324
 
325
/* Parse/insert/extract/print handlers.
326
 
327
   Indices into the handler tables.
328
   We could use pointers here instead, but 90% of them are generally identical
329
   and that's a lot of redundant data.  Making these unsigned char indices
330
   into tables of pointers saves a bit of space.
331
   Using indices also keeps assembler code out of the disassembler and
332
   vice versa.  */
333
 
334
struct cgen_opcode_handler
335
{
336
  unsigned char parse, insert, extract, print;
337
};
338
 
339
/* Assembler interface.
340
 
341
   The interface to the assembler is intended to be clean in the sense that
342
   libopcodes.a is a standalone entity and could be used with any assembler.
343
   Not that one would necessarily want to do that but rather that it helps
344
   keep a clean interface.  The interface will obviously be slanted towards
345
   GAS, but at least it's a start.
346
   ??? Note that one possible user of the assembler besides GAS is GDB.
347
 
348
   Parsing is controlled by the assembler which calls
349
   CGEN_SYM (assemble_insn).  If it can parse and build the entire insn
350
   it doesn't call back to the assembler.  If it needs/wants to call back
351
   to the assembler, cgen_parse_operand_fn is called which can either
352
 
353
   - return a number to be inserted in the insn
354
   - return a "register" value to be inserted
355
     (the register might not be a register per pe)
356
   - queue the argument and return a marker saying the expression has been
357
     queued (eg: a fix-up)
358
   - return an error message indicating the expression wasn't recognizable
359
 
360
   The result is an error message or NULL for success.
361
   The parsed value is stored in the bfd_vma *.  */
362
 
363
/* Values for indicating what the caller wants.  */
364
 
365
enum cgen_parse_operand_type
366
{
367
  CGEN_PARSE_OPERAND_INIT,
368
  CGEN_PARSE_OPERAND_INTEGER,
369
  CGEN_PARSE_OPERAND_ADDRESS
370
};
371
 
372
/* Values for indicating what was parsed.  */
373
 
374
enum cgen_parse_operand_result
375
{
376
  CGEN_PARSE_OPERAND_RESULT_NUMBER,
377
  CGEN_PARSE_OPERAND_RESULT_REGISTER,
378
  CGEN_PARSE_OPERAND_RESULT_QUEUED,
379
  CGEN_PARSE_OPERAND_RESULT_ERROR
380
};
381
 
382
#ifdef BFD_VERSION /* Don't require bfd.h unnecessarily.  */
383
typedef const char * (cgen_parse_operand_fn)
384
     PARAMS ((CGEN_CPU_DESC,
385
              enum cgen_parse_operand_type, const char **, int, int,
386
              enum cgen_parse_operand_result *, bfd_vma *));
387
#else
388
typedef const char * (cgen_parse_operand_fn) ();
389
#endif
390
 
391
/* Set the cgen_parse_operand_fn callback.  */
392
 
393
extern void cgen_set_parse_operand_fn
394
     PARAMS ((CGEN_CPU_DESC, cgen_parse_operand_fn));
395
 
396
/* Called before trying to match a table entry with the insn.  */
397
 
398
extern void cgen_init_parse_operand PARAMS ((CGEN_CPU_DESC));
399
 
400
/* Operand values (keywords, integers, symbols, etc.)  */
401
 
402
/* Types of assembler elements.  */
403
 
404
enum cgen_asm_type
405
{
406
  CGEN_ASM_NONE, CGEN_ASM_KEYWORD, CGEN_ASM_MAX
407
};
408
 
409
#ifndef CGEN_ARCH
410
enum cgen_hw_type { CGEN_HW_MAX };
411
#endif
412
 
413
/* List of hardware elements.  */
414
 
415
typedef struct
416
{
417
  char *name;
418
  enum cgen_hw_type type;
419
  /* There is currently no example where both index specs and value specs
420
     are required, so for now both are clumped under "asm_data".  */
421
  enum cgen_asm_type asm_type;
422
  PTR asm_data;
423
#ifndef CGEN_HW_NBOOL_ATTRS
424
#define CGEN_HW_NBOOL_ATTRS 1
425
#endif
426
  CGEN_ATTR_TYPE (CGEN_HW_NBOOL_ATTRS) attrs;
427
#define CGEN_HW_ATTRS(hw) (&(hw)->attrs)
428
} CGEN_HW_ENTRY;
429
 
430
/* Return value of attribute ATTR in HW.  */
431
 
432
#define CGEN_HW_ATTR_VALUE(hw, attr) \
433
CGEN_ATTR_VALUE ((hw), CGEN_HW_ATTRS (hw), (attr))
434
 
435
/* Table of hardware elements for selected mach, computed at runtime.
436
   enum cgen_hw_type is an index into this table (specifically `entries').  */
437
 
438
typedef struct {
439
  /* Pointer to null terminated table of all compiled in entries.  */
440
  const CGEN_HW_ENTRY *init_entries;
441
  unsigned int entry_size; /* since the attribute member is variable sized */
442
  /* Array of all entries, initial and run-time added.  */
443
  const CGEN_HW_ENTRY **entries;
444
  /* Number of elements in `entries'.  */
445
  unsigned int num_entries;
446
  /* For now, xrealloc is called each time a new entry is added at runtime.
447
     ??? May wish to keep track of some slop to reduce the number of calls to
448
     xrealloc, except that there's unlikely to be many and not expected to be
449
     in speed critical code.  */
450
} CGEN_HW_TABLE;
451
 
452
extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_name
453
     PARAMS ((CGEN_CPU_DESC, const char *));
454
extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_num
455
     PARAMS ((CGEN_CPU_DESC, unsigned int));
456
 
457
/* This struct is used to describe things like register names, etc.  */
458
 
459
typedef struct cgen_keyword_entry
460
{
461
  /* Name (as in register name).  */
462
  char * name;
463
 
464
  /* Value (as in register number).
465
     The value cannot be -1 as that is used to indicate "not found".
466
     IDEA: Have "FUNCTION" attribute? [function is called to fetch value].  */
467
  int value;
468
 
469
  /* Attributes.
470
     This should, but technically needn't, appear last.  It is a variable sized
471
     array in that one architecture may have 1 nonbool attribute and another
472
     may have more.  Having this last means the non-architecture specific code
473
     needn't care.  The goal is to eventually record
474
     attributes in their raw form, evaluate them at run-time, and cache the
475
     values, so this worry will go away anyway.  */
476
  /* ??? Moving this last should be done by treating keywords like insn lists
477
     and moving the `next' fields into a CGEN_KEYWORD_LIST struct.  */
478
  /* FIXME: Not used yet.  */
479
#ifndef CGEN_KEYWORD_NBOOL_ATTRS
480
#define CGEN_KEYWORD_NBOOL_ATTRS 1
481
#endif
482
  CGEN_ATTR_TYPE (CGEN_KEYWORD_NBOOL_ATTRS) attrs;
483
 
484
  /* ??? Putting these here means compiled in entries can't be const.
485
     Not a really big deal, but something to consider.  */
486
  /* Next name hash table entry.  */
487
  struct cgen_keyword_entry *next_name;
488
  /* Next value hash table entry.  */
489
  struct cgen_keyword_entry *next_value;
490
} CGEN_KEYWORD_ENTRY;
491
 
492
/* Top level struct for describing a set of related keywords
493
   (e.g. register names).
494
 
495
   This struct supports run-time entry of new values, and hashed lookups.  */
496
 
497
typedef struct cgen_keyword
498
{
499
  /* Pointer to initial [compiled in] values.  */
500
  CGEN_KEYWORD_ENTRY *init_entries;
501
 
502
  /* Number of entries in `init_entries'.  */
503
  unsigned int num_init_entries;
504
 
505
  /* Hash table used for name lookup.  */
506
  CGEN_KEYWORD_ENTRY **name_hash_table;
507
 
508
  /* Hash table used for value lookup.  */
509
  CGEN_KEYWORD_ENTRY **value_hash_table;
510
 
511
  /* Number of entries in the hash_tables.  */
512
  unsigned int hash_table_size;
513
 
514
  /* Pointer to null keyword "" entry if present.  */
515
  const CGEN_KEYWORD_ENTRY *null_entry;
516
 
517
  /* String containing non-alphanumeric characters used
518
     in keywords.
519
     At present, the highest number of entries used is 1.  */
520
  char nonalpha_chars[8];
521
} CGEN_KEYWORD;
522
 
523
/* Structure used for searching.  */
524
 
525
typedef struct
526
{
527
  /* Table being searched.  */
528
  const CGEN_KEYWORD *table;
529
 
530
  /* Specification of what is being searched for.  */
531
  const char *spec;
532
 
533
  /* Current index in hash table.  */
534
  unsigned int current_hash;
535
 
536
  /* Current element in current hash chain.  */
537
  CGEN_KEYWORD_ENTRY *current_entry;
538
} CGEN_KEYWORD_SEARCH;
539
 
540
/* Lookup a keyword from its name.  */
541
 
542
const CGEN_KEYWORD_ENTRY *cgen_keyword_lookup_name
543
  PARAMS ((CGEN_KEYWORD *, const char *));
544
 
545
/* Lookup a keyword from its value.  */
546
 
547
const CGEN_KEYWORD_ENTRY *cgen_keyword_lookup_value
548
  PARAMS ((CGEN_KEYWORD *, int));
549
 
550
/* Add a keyword.  */
551
 
552
void cgen_keyword_add PARAMS ((CGEN_KEYWORD *, CGEN_KEYWORD_ENTRY *));
553
 
554
/* Keyword searching.
555
   This can be used to retrieve every keyword, or a subset.  */
556
 
557
CGEN_KEYWORD_SEARCH cgen_keyword_search_init
558
  PARAMS ((CGEN_KEYWORD *, const char *));
559
const CGEN_KEYWORD_ENTRY *cgen_keyword_search_next
560
  PARAMS ((CGEN_KEYWORD_SEARCH *));
561
 
562
/* Operand value support routines.  */
563
 
564
extern const char *cgen_parse_keyword
565
     PARAMS ((CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *));
566
#ifdef BFD_VERSION /* Don't require bfd.h unnecessarily.  */
567
extern const char *cgen_parse_signed_integer
568
     PARAMS ((CGEN_CPU_DESC, const char **, int, long *));
569
extern const char *cgen_parse_unsigned_integer
570
     PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
571
extern const char *cgen_parse_address
572
     PARAMS ((CGEN_CPU_DESC, const char **, int, int,
573
              enum cgen_parse_operand_result *, bfd_vma *));
574
extern const char *cgen_validate_signed_integer
575
     PARAMS ((long, long, long));
576
extern const char *cgen_validate_unsigned_integer
577
     PARAMS ((unsigned long, unsigned long, unsigned long));
578
#endif
579
 
580
/* Operand modes.  */
581
 
582
/* ??? This duplicates the values in arch.h.  Revisit.
583
   These however need the CGEN_ prefix [as does everything in this file].  */
584
/* ??? Targets may need to add their own modes so we may wish to move this
585
   to <arch>-opc.h, or add a hook.  */
586
 
587
enum cgen_mode {
588
  CGEN_MODE_VOID, /* ??? rename simulator's VM to VOID? */
589
  CGEN_MODE_BI, CGEN_MODE_QI, CGEN_MODE_HI, CGEN_MODE_SI, CGEN_MODE_DI,
590
  CGEN_MODE_UBI, CGEN_MODE_UQI, CGEN_MODE_UHI, CGEN_MODE_USI, CGEN_MODE_UDI,
591
  CGEN_MODE_SF, CGEN_MODE_DF, CGEN_MODE_XF, CGEN_MODE_TF,
592
  CGEN_MODE_TARGET_MAX,
593
  CGEN_MODE_INT, CGEN_MODE_UINT,
594
  CGEN_MODE_MAX
595
};
596
 
597
/* FIXME: Until simulator is updated.  */
598
 
599
#define CGEN_MODE_VM CGEN_MODE_VOID
600
 
601
/* Operands.  */
602
 
603
#ifndef CGEN_ARCH
604
enum cgen_operand_type { CGEN_OPERAND_MAX };
605
#endif
606
 
607
/* "nil" indicator for the operand instance table */
608
#define CGEN_OPERAND_NIL CGEN_OPERAND_MAX
609
 
610
/* This struct defines each entry in the operand table.  */
611
 
612
typedef struct
613
{
614
  /* Name as it appears in the syntax string.  */
615
  char *name;
616
 
617
  /* Operand type.  */
618
  enum cgen_operand_type type;
619
 
620
  /* The hardware element associated with this operand.  */
621
  enum cgen_hw_type hw_type;
622
 
623
  /* FIXME: We don't yet record ifield definitions, which we should.
624
     When we do it might make sense to delete start/length (since they will
625
     be duplicated in the ifield's definition) and replace them with a
626
     pointer to the ifield entry.  */
627
 
628
  /* Bit position.
629
     This is just a hint, and may be unused in more complex operands.
630
     May be unused for a modifier.  */
631
  unsigned char start;
632
 
633
  /* The number of bits in the operand.
634
     This is just a hint, and may be unused in more complex operands.
635
     May be unused for a modifier.  */
636
  unsigned char length;
637
 
638
#if 0 /* ??? Interesting idea but relocs tend to get too complicated,
639
         and ABI dependent, for simple table lookups to work.  */
640
  /* Ideally this would be the internal (external?) reloc type.  */
641
  int reloc_type;
642
#endif
643
 
644
  /* Attributes.
645
     This should, but technically needn't, appear last.  It is a variable sized
646
     array in that one architecture may have 1 nonbool attribute and another
647
     may have more.  Having this last means the non-architecture specific code
648
     needn't care, now or tomorrow.  The goal is to eventually record
649
     attributes in their raw form, evaluate them at run-time, and cache the
650
     values, so this worry will go away anyway.  */
651
#ifndef CGEN_OPERAND_NBOOL_ATTRS
652
#define CGEN_OPERAND_NBOOL_ATTRS 1
653
#endif
654
  CGEN_ATTR_TYPE (CGEN_OPERAND_NBOOL_ATTRS) attrs;
655
#define CGEN_OPERAND_ATTRS(operand) (&(operand)->attrs)
656
} CGEN_OPERAND;
657
 
658
/* Return value of attribute ATTR in OPERAND.  */
659
 
660
#define CGEN_OPERAND_ATTR_VALUE(operand, attr) \
661
CGEN_ATTR_VALUE ((operand), CGEN_OPERAND_ATTRS (operand), (attr))
662
 
663
/* Table of operands for selected mach/isa, computed at runtime.
664
   enum cgen_operand_type is an index into this table (specifically
665
   `entries').  */
666
 
667
typedef struct {
668
  /* Pointer to null terminated table of all compiled in entries.  */
669
  const CGEN_OPERAND *init_entries;
670
  unsigned int entry_size; /* since the attribute member is variable sized */
671
  /* Array of all entries, initial and run-time added.  */
672
  const CGEN_OPERAND **entries;
673
  /* Number of elements in `entries'.  */
674
  unsigned int num_entries;
675
  /* For now, xrealloc is called each time a new entry is added at runtime.
676
     ??? May wish to keep track of some slop to reduce the number of calls to
677
     xrealloc, except that there's unlikely to be many and not expected to be
678
     in speed critical code.  */
679
} CGEN_OPERAND_TABLE;
680
 
681
extern const CGEN_OPERAND * cgen_operand_lookup_by_name
682
     PARAMS ((CGEN_CPU_DESC, const char *));
683
extern const CGEN_OPERAND * cgen_operand_lookup_by_num
684
     PARAMS ((CGEN_CPU_DESC, int));
685
 
686
/* Instruction operand instances.
687
 
688
   For each instruction, a list of the hardware elements that are read and
689
   written are recorded.  */
690
 
691
/* The type of the instance.  */
692
 
693
enum cgen_opinst_type {
694
  /* End of table marker.  */
695
  CGEN_OPINST_END = 0,
696
  CGEN_OPINST_INPUT, CGEN_OPINST_OUTPUT
697
};
698
 
699
typedef struct
700
{
701
  /* Input or output indicator.  */
702
  enum cgen_opinst_type type;
703
 
704
  /* Name of operand.  */
705
  const char *name;
706
 
707
  /* The hardware element referenced.  */
708
  enum cgen_hw_type hw_type;
709
 
710
  /* The mode in which the operand is being used.  */
711
  enum cgen_mode mode;
712
 
713
  /* The operand table entry CGEN_OPERAND_NIL if there is none
714
     (i.e. an explicit hardware reference).  */
715
  enum cgen_operand_type op_type;
716
 
717
  /* If `operand' is "nil", the index (e.g. into array of registers).  */
718
  int index;
719
 
720
  /* Attributes.
721
     ??? This perhaps should be a real attribute struct but there's
722
     no current need, so we save a bit of space and just have a set of
723
     flags.  The interface is such that this can easily be made attributes
724
     should it prove useful.  */
725
  unsigned int attrs;
726
#define CGEN_OPINST_ATTRS(opinst) ((opinst)->attrs)
727
/* Return value of attribute ATTR in OPINST.  */
728
#define CGEN_OPINST_ATTR(opinst, attr) \
729
((CGEN_OPINST_ATTRS (opinst) & (attr)) != 0)
730
/* Operand is conditionally referenced (read/written).  */
731
#define CGEN_OPINST_COND_REF 1
732
} CGEN_OPINST;
733
 
734
/* Syntax string.
735
 
736
   Each insn format and subexpression has one of these.
737
 
738
   The syntax "string" consists of characters (n > 0 && n < 128), and operand
739
   values (n >= 128), and is terminated by 0.  Operand values are 128 + index
740
   into the operand table.  The operand table doesn't exist in C, per se, as
741
   the data is recorded in the parse/insert/extract/print switch statements. */
742
 
743
/* This should be at least as large as necessary for any target. */
744
#define CGEN_MAX_SYNTAX_ELEMENTS 48
745
 
746
/* A target may know its own precise maximum.  Assert that it falls below
747
   the above limit. */
748
#ifdef CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS
749
#if CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS > CGEN_MAX_SYNTAX_ELEMENTS
750
#error "CGEN_ACTUAL_MAX_SYNTAX_ELEMENTS too high - enlarge CGEN_MAX_SYNTAX_ELEMENTS"
751
#endif
752
#endif
753
 
754
typedef unsigned short CGEN_SYNTAX_CHAR_TYPE;
755
 
756
typedef struct
757
{
758
  CGEN_SYNTAX_CHAR_TYPE syntax[CGEN_MAX_SYNTAX_ELEMENTS];
759
} CGEN_SYNTAX;
760
 
761
#define CGEN_SYNTAX_STRING(syn) (syn->syntax)
762
#define CGEN_SYNTAX_CHAR_P(c) ((c) < 128)
763
#define CGEN_SYNTAX_CHAR(c) ((unsigned char)c)
764
#define CGEN_SYNTAX_FIELD(c) ((c) - 128)
765
#define CGEN_SYNTAX_MAKE_FIELD(c) ((c) + 128)
766
 
767
/* ??? I can't currently think of any case where the mnemonic doesn't come
768
   first [and if one ever doesn't building the hash tables will be tricky].
769
   However, we treat mnemonics as just another operand of the instruction.
770
   A value of 1 means "this is where the mnemonic appears".  1 isn't
771
   special other than it's a non-printable ASCII char.  */
772
 
773
#define CGEN_SYNTAX_MNEMONIC       1
774
#define CGEN_SYNTAX_MNEMONIC_P(ch) ((ch) == CGEN_SYNTAX_MNEMONIC)
775
 
776
/* Instruction fields.
777
 
778
   ??? We currently don't allow adding fields at run-time.
779
   Easy to fix when needed.  */
780
 
781
typedef struct cgen_ifld {
782
  /* Enum of ifield.  */
783
  int num;
784
#define CGEN_IFLD_NUM(f) ((f)->num)
785
 
786
  /* Name of the field, distinguishes it from all other fields.  */
787
  const char *name;
788
#define CGEN_IFLD_NAME(f) ((f)->name)
789
 
790
  /* Default offset, in bits, from the start of the insn to the word
791
     containing the field.  */
792
  int word_offset;
793
#define CGEN_IFLD_WORD_OFFSET(f) ((f)->word_offset)
794
 
795
  /* Default length of the word containing the field.  */
796
  int word_size;
797
#define CGEN_IFLD_WORD_SIZE(f) ((f)->word_size)
798
 
799
  /* Default starting bit number.
800
     Whether lsb=0 or msb=0 is determined by CGEN_INSN_LSB0_P.  */
801
  int start;
802
#define CGEN_IFLD_START(f) ((f)->start)
803
 
804
  /* Length of the field, in bits.  */
805
  int length;
806
#define CGEN_IFLD_LENGTH(f) ((f)->length)
807
 
808
#ifndef CGEN_IFLD_NBOOL_ATTRS
809
#define CGEN_IFLD_NBOOL_ATTRS 1
810
#endif
811
  CGEN_ATTR_TYPE (CGEN_IFLD_NBOOL_ATTRS) attrs;
812
#define CGEN_IFLD_ATTRS(f) (&(f)->attrs)
813
} CGEN_IFLD;
814
 
815
/* Return value of attribute ATTR in IFLD.  */
816
#define CGEN_IFLD_ATTR_VALUE(ifld, attr) \
817
CGEN_ATTR_VALUE ((ifld), CGEN_IFLD_ATTRS (ifld), (attr))
818
 
819
/* Instruction data.  */
820
 
821
/* Instruction formats.
822
 
823
   Instructions are grouped by format.  Associated with an instruction is its
824
   format.  Each insn's opcode table entry contains a format table entry.
825
   ??? There is usually very few formats compared with the number of insns,
826
   so one can reduce the size of the opcode table by recording the format table
827
   as a separate entity.  Given that we currently don't, format table entries
828
   are also distinguished by their operands.  This increases the size of the
829
   table, but reduces the number of tables.  It's all minutiae anyway so it
830
   doesn't really matter [at this point in time].
831
 
832
   ??? Support for variable length ISA's is wip.  */
833
 
834
/* Accompanying each iformat description is a list of its fields.  */
835
 
836
typedef struct {
837
  const CGEN_IFLD *ifld;
838
#define CGEN_IFMT_IFLD_IFLD(ii) ((ii)->ifld)
839
} CGEN_IFMT_IFLD;
840
 
841
/* This should be at least as large as necessary for any target. */
842
#define CGEN_MAX_IFMT_OPERANDS 16
843
 
844
/* A target may know its own precise maximum.  Assert that it falls below
845
   the above limit. */
846
#ifdef CGEN_ACTUAL_MAX_IFMT_OPERANDS
847
#if CGEN_ACTUAL_MAX_IFMT_OPERANDS > CGEN_MAX_IFMT_OPERANDS
848
#error "CGEN_ACTUAL_MAX_IFMT_OPERANDS too high - enlarge CGEN_MAX_IFMT_OPERANDS"
849
#endif
850
#endif
851
 
852
 
853
typedef struct
854
{
855
  /* Length that MASK and VALUE have been calculated to
856
     [VALUE is recorded elsewhere].
857
     Normally it is base_insn_bitsize.  On [V]LIW architectures where the base
858
     insn size may be larger than the size of an insn, this field is less than
859
     base_insn_bitsize.  */
860
  unsigned char mask_length;
861
#define CGEN_IFMT_MASK_LENGTH(ifmt) ((ifmt)->mask_length)
862
 
863
  /* Total length of instruction, in bits.  */
864
  unsigned char length;
865
#define CGEN_IFMT_LENGTH(ifmt) ((ifmt)->length)
866
 
867
  /* Mask to apply to the first MASK_LENGTH bits.
868
     Each insn's value is stored with the insn.
869
     The first step in recognizing an insn for disassembly is
870
     (opcode & mask) == value.  */
871
  CGEN_INSN_INT mask;
872
#define CGEN_IFMT_MASK(ifmt) ((ifmt)->mask)
873
 
874
  /* Instruction fields.
875
     +1 for trailing NULL.  */
876
  CGEN_IFMT_IFLD iflds[CGEN_MAX_IFMT_OPERANDS + 1];
877
#define CGEN_IFMT_IFLDS(ifmt) ((ifmt)->iflds)
878
} CGEN_IFMT;
879
 
880
/* Instruction values.  */
881
 
882
typedef struct
883
{
884
  /* The opcode portion of the base insn.  */
885
  CGEN_INSN_INT base_value;
886
 
887
#ifdef CGEN_MAX_EXTRA_OPCODE_OPERANDS
888
  /* Extra opcode values beyond base_value.  */
889
  unsigned long ifield_values[CGEN_MAX_EXTRA_OPCODE_OPERANDS];
890
#endif
891
} CGEN_IVALUE;
892
 
893
/* Instruction opcode table.
894
   This contains the syntax and format data of an instruction.  */
895
 
896
/* ??? Some ports already have an opcode table yet still need to use the rest
897
   of what cgen_insn has.  Plus keeping the opcode data with the operand
898
   instance data can create a pretty big file.  So we keep them separately.
899
   Not sure this is a good idea in the long run.  */
900
 
901
typedef struct
902
{
903
  /* Indices into parse/insert/extract/print handler tables.  */
904
  struct cgen_opcode_handler handlers;
905
#define CGEN_OPCODE_HANDLERS(opc) (& (opc)->handlers)
906
 
907
  /* Syntax string.  */
908
  CGEN_SYNTAX syntax;
909
#define CGEN_OPCODE_SYNTAX(opc) (& (opc)->syntax)
910
 
911
  /* Format entry.  */
912
  const CGEN_IFMT *format;
913
#define CGEN_OPCODE_FORMAT(opc) ((opc)->format)
914
#define CGEN_OPCODE_MASK_BITSIZE(opc) CGEN_IFMT_MASK_LENGTH (CGEN_OPCODE_FORMAT (opc))
915
#define CGEN_OPCODE_BITSIZE(opc) CGEN_IFMT_LENGTH (CGEN_OPCODE_FORMAT (opc))
916
#define CGEN_OPCODE_IFLDS(opc) CGEN_IFMT_IFLDS (CGEN_OPCODE_FORMAT (opc))
917
 
918
  /* Instruction opcode value.  */
919
  CGEN_IVALUE value;
920
#define CGEN_OPCODE_VALUE(opc) (& (opc)->value)
921
#define CGEN_OPCODE_BASE_VALUE(opc) (CGEN_OPCODE_VALUE (opc)->base_value)
922
#define CGEN_OPCODE_BASE_MASK(opc) CGEN_IFMT_MASK (CGEN_OPCODE_FORMAT (opc))
923
} CGEN_OPCODE;
924
 
925
/* Instruction attributes.
926
   This is made a published type as applications can cache a pointer to
927
   the attributes for speed.  */
928
 
929
#ifndef CGEN_INSN_NBOOL_ATTRS
930
#define CGEN_INSN_NBOOL_ATTRS 1
931
#endif
932
typedef CGEN_ATTR_TYPE (CGEN_INSN_NBOOL_ATTRS) CGEN_INSN_ATTR_TYPE;
933
 
934
/* Enum of architecture independent attributes.  */
935
 
936
#ifndef CGEN_ARCH
937
/* ??? Numbers here are recorded in two places.  */
938
typedef enum cgen_insn_attr {
939
  CGEN_INSN_ALIAS = 0
940
} CGEN_INSN_ATTR;
941
#endif
942
 
943
/* This struct defines each entry in the instruction table.  */
944
 
945
typedef struct
946
{
947
  /* Each real instruction is enumerated.  */
948
  /* ??? This may go away in time.  */
949
  int num;
950
#define CGEN_INSN_NUM(insn) ((insn)->base->num)
951
 
952
  /* Name of entry (that distinguishes it from all other entries).  */
953
  /* ??? If mnemonics have operands, try to print full mnemonic.  */
954
  const char *name;
955
#define CGEN_INSN_NAME(insn) ((insn)->base->name)
956
 
957
  /* Mnemonic.  This is used when parsing and printing the insn.
958
     In the case of insns that have operands on the mnemonics, this is
959
     only the constant part.  E.g. for conditional execution of an `add' insn,
960
     where the full mnemonic is addeq, addne, etc., and the condition is
961
     treated as an operand, this is only "add".  */
962
  const char *mnemonic;
963
#define CGEN_INSN_MNEMONIC(insn) ((insn)->base->mnemonic)
964
 
965
  /* Total length of instruction, in bits.  */
966
  int bitsize;
967
#define CGEN_INSN_BITSIZE(insn) ((insn)->base->bitsize)
968
 
969
#if 0 /* ??? Disabled for now as there is a problem with embedded newlines
970
         and the table is already pretty big.  Should perhaps be moved
971
         to a file of its own.  */
972
  /* Semantics, as RTL.  */
973
  /* ??? Plain text or bytecodes?  */
974
  /* ??? Note that the operand instance table could be computed at run-time
975
     if we parse this and cache the results.  Something to eventually do.  */
976
  const char *rtx;
977
#define CGEN_INSN_RTX(insn) ((insn)->base->rtx)
978
#endif
979
 
980
  /* Attributes.
981
     This must appear last.  It is a variable sized array in that one
982
     architecture may have 1 nonbool attribute and another may have more.
983
     Having this last means the non-architecture specific code needn't
984
     care.  The goal is to eventually record attributes in their raw form,
985
     evaluate them at run-time, and cache the values, so this worry will go
986
     away anyway.  */
987
  CGEN_INSN_ATTR_TYPE attrs;
988
#define CGEN_INSN_ATTRS(insn) (&(insn)->base->attrs)
989
/* Return value of attribute ATTR in INSN.  */
990
#define CGEN_INSN_ATTR_VALUE(insn, attr) \
991
CGEN_ATTR_VALUE ((insn), CGEN_INSN_ATTRS (insn), (attr))
992
} CGEN_IBASE;
993
 
994
/* Return non-zero if INSN is the "invalid" insn marker.  */
995
 
996
#define CGEN_INSN_INVALID_P(insn) (CGEN_INSN_MNEMONIC (insn) == 0)
997
 
998
/* Main struct contain instruction information.
999
   BASE is always present, the rest is present only if asked for.  */
1000
 
1001
struct cgen_insn
1002
{
1003
  /* ??? May be of use to put a type indicator here.
1004
     Then this struct could different info for different classes of insns.  */
1005
  /* ??? A speedup can be had by moving `base' into this struct.
1006
     Maybe later.  */
1007
  const CGEN_IBASE *base;
1008
  const CGEN_OPCODE *opcode;
1009
  const CGEN_OPINST *opinst;
1010
};
1011
 
1012
/* Instruction lists.
1013
   This is used for adding new entries and for creating the hash lists.  */
1014
 
1015
typedef struct cgen_insn_list
1016
{
1017
  struct cgen_insn_list *next;
1018
  const CGEN_INSN *insn;
1019
} CGEN_INSN_LIST;
1020
 
1021
/* Table of instructions.  */
1022
 
1023
typedef struct
1024
{
1025
  const CGEN_INSN *init_entries;
1026
  unsigned int entry_size; /* since the attribute member is variable sized */
1027
  unsigned int num_init_entries;
1028
  CGEN_INSN_LIST *new_entries;
1029
} CGEN_INSN_TABLE;
1030
 
1031
/* Return number of instructions.  This includes any added at run-time.  */
1032
 
1033
extern int cgen_insn_count PARAMS ((CGEN_CPU_DESC));
1034
extern int cgen_macro_insn_count PARAMS ((CGEN_CPU_DESC));
1035
 
1036
/* Macros to access the other insn elements not recorded in CGEN_IBASE.  */
1037
 
1038
/* Fetch INSN's operand instance table.  */
1039
/* ??? Doesn't handle insns added at runtime.  */
1040
#define CGEN_INSN_OPERANDS(insn) ((insn)->opinst)
1041
 
1042
/* Return INSN's opcode table entry.  */
1043
#define CGEN_INSN_OPCODE(insn) ((insn)->opcode)
1044
 
1045
/* Return INSN's handler data.  */
1046
#define CGEN_INSN_HANDLERS(insn) CGEN_OPCODE_HANDLERS (CGEN_INSN_OPCODE (insn))
1047
 
1048
/* Return INSN's syntax.  */
1049
#define CGEN_INSN_SYNTAX(insn) CGEN_OPCODE_SYNTAX (CGEN_INSN_OPCODE (insn))
1050
 
1051
/* Return size of base mask in bits.  */
1052
#define CGEN_INSN_MASK_BITSIZE(insn) \
1053
  CGEN_OPCODE_MASK_BITSIZE (CGEN_INSN_OPCODE (insn))
1054
 
1055
/* Return mask of base part of INSN.  */
1056
#define CGEN_INSN_BASE_MASK(insn) \
1057
  CGEN_OPCODE_BASE_MASK (CGEN_INSN_OPCODE (insn))
1058
 
1059
/* Return value of base part of INSN.  */
1060
#define CGEN_INSN_BASE_VALUE(insn) \
1061
  CGEN_OPCODE_BASE_VALUE (CGEN_INSN_OPCODE (insn))
1062
 
1063
/* Standard way to test whether INSN is supported by MACH.
1064
   MACH is one of enum mach_attr.
1065
   The "|1" is because the base mach is always selected.  */
1066
#define CGEN_INSN_MACH_HAS_P(insn, mach) \
1067
((CGEN_INSN_ATTR_VALUE ((insn), CGEN_INSN_MACH) & ((1 << (mach)) | 1)) != 0)
1068
 
1069
/* Macro instructions.
1070
   Macro insns aren't real insns, they map to one or more real insns.
1071
   E.g. An architecture's "nop" insn may actually be an "mv r0,r0" or
1072
   some such.
1073
 
1074
   Macro insns can expand to nothing (e.g. a nop that is optimized away).
1075
   This is useful in multi-insn macros that build a constant in a register.
1076
   Of course this isn't the default behaviour and must be explicitly enabled.
1077
 
1078
   Assembly of macro-insns is relatively straightforward.  Disassembly isn't.
1079
   However, disassembly of at least some kinds of macro insns is important
1080
   in order that the disassembled code preserve the readability of the original
1081
   insn.  What is attempted here is to disassemble all "simple" macro-insns,
1082
   where "simple" is currently defined to mean "expands to one real insn".
1083
 
1084
   Simple macro-insns are handled specially.  They are emitted as ALIAS's
1085
   of real insns.  This simplifies their handling since there's usually more
1086
   of them than any other kind of macro-insn, and proper disassembly of them
1087
   falls out for free.  */
1088
 
1089
/* For each macro-insn there may be multiple expansion possibilities,
1090
   depending on the arguments.  This structure is accessed via the `data'
1091
   member of CGEN_INSN.  */
1092
 
1093
typedef struct cgen_minsn_expansion {
1094
  /* Function to do the expansion.
1095
     If the expansion fails (e.g. "no match") NULL is returned.
1096
     Space for the expansion is obtained with malloc.
1097
     It is up to the caller to free it.  */
1098
  const char * (* fn) PARAMS ((const struct cgen_minsn_expansion *,
1099
                               const char *, const char **, int *,
1100
                               CGEN_OPERAND **));
1101
#define CGEN_MIEXPN_FN(ex) ((ex)->fn)
1102
 
1103
  /* Instruction(s) the macro expands to.
1104
     The format of STR is defined by FN.
1105
     It is typically the assembly code of the real insn, but it could also be
1106
     the original Scheme expression or a tokenized form of it (with FN being
1107
     an appropriate interpreter).  */
1108
  const char * str;
1109
#define CGEN_MIEXPN_STR(ex) ((ex)->str)
1110
} CGEN_MINSN_EXPANSION;
1111
 
1112
/* Normal expander.
1113
   When supported, this function will convert the input string to another
1114
   string and the parser will be invoked recursively.  The output string
1115
   may contain further macro invocations.  */
1116
 
1117
extern const char * cgen_expand_macro_insn
1118
     PARAMS ((CGEN_CPU_DESC, const struct cgen_minsn_expansion *,
1119
              const char *, const char **, int *, CGEN_OPERAND **));
1120
 
1121
/* The assembler insn table is hashed based on some function of the mnemonic
1122
   (the actually hashing done is up to the target, but we provide a few
1123
   examples like the first letter or a function of the entire mnemonic).  */
1124
 
1125
extern CGEN_INSN_LIST * cgen_asm_lookup_insn
1126
     PARAMS ((CGEN_CPU_DESC, const char *));
1127
#define CGEN_ASM_LOOKUP_INSN(cd, string) cgen_asm_lookup_insn ((cd), (string))
1128
#define CGEN_ASM_NEXT_INSN(insn) ((insn)->next)
1129
 
1130
/* The disassembler insn table is hashed based on some function of machine
1131
   instruction (the actually hashing done is up to the target).  */
1132
 
1133
extern CGEN_INSN_LIST * cgen_dis_lookup_insn
1134
     PARAMS ((CGEN_CPU_DESC, const char *, CGEN_INSN_INT));
1135
/* FIXME: delete these two */
1136
#define CGEN_DIS_LOOKUP_INSN(cd, buf, value) cgen_dis_lookup_insn ((cd), (buf), (value))
1137
#define CGEN_DIS_NEXT_INSN(insn) ((insn)->next)
1138
 
1139
/* The CPU description.
1140
   A copy of this is created when the cpu table is "opened".
1141
   All global state information is recorded here.
1142
   Access macros are provided for "public" members.  */
1143
 
1144
typedef struct cgen_cpu_desc
1145
{
1146
  /* Bitmap of selected machine(s) (a la BFD machine number).  */
1147
  int machs;
1148
 
1149
  /* Bitmap of selected isa(s).
1150
     ??? Simultaneous multiple isas might not make sense, but it's not (yet)
1151
     precluded.  */
1152
  int isas;
1153
 
1154
  /* Current endian.  */
1155
  enum cgen_endian endian;
1156
#define CGEN_CPU_ENDIAN(cd) ((cd)->endian)
1157
 
1158
  /* Current insn endian.  */
1159
  enum cgen_endian insn_endian;
1160
#define CGEN_CPU_INSN_ENDIAN(cd) ((cd)->insn_endian)
1161
 
1162
  /* Word size (in bits).  */
1163
  /* ??? Or maybe maximum word size - might we ever need to allow a cpu table
1164
     to be opened for both sparc32/sparc64?
1165
     ??? Another alternative is to create a table of selected machs and
1166
     lazily fetch the data from there.  */
1167
  unsigned int word_bitsize;
1168
 
1169
  /* Indicator if sizes are unknown.
1170
     This is used by default_insn_bitsize,base_insn_bitsize if there is a
1171
     difference between the selected isa's.  */
1172
#define CGEN_SIZE_UNKNOWN 65535
1173
 
1174
  /* Default instruction size (in bits).
1175
     This is used by the assembler when it encounters an unknown insn.  */
1176
  unsigned int default_insn_bitsize;
1177
 
1178
  /* Base instruction size (in bits).
1179
     For non-LIW cpus this is generally the length of the smallest insn.
1180
     For LIW cpus its wip (work-in-progress).  For the m32r its 32.  */
1181
  unsigned int base_insn_bitsize;
1182
 
1183
  /* Minimum/maximum instruction size (in bits).  */
1184
  unsigned int min_insn_bitsize;
1185
  unsigned int max_insn_bitsize;
1186
 
1187
  /* Instruction set variants.  */
1188
  const CGEN_ISA *isa_table;
1189
 
1190
  /* Machine variants.  */
1191
  const CGEN_MACH *mach_table;
1192
 
1193
  /* Hardware elements.  */
1194
  CGEN_HW_TABLE hw_table;
1195
 
1196
  /* Instruction fields.  */
1197
  const CGEN_IFLD *ifld_table;
1198
 
1199
  /* Operands.  */
1200
  CGEN_OPERAND_TABLE operand_table;
1201
 
1202
  /* Main instruction table.  */
1203
  CGEN_INSN_TABLE insn_table;
1204
#define CGEN_CPU_INSN_TABLE(cd) (& (cd)->insn_table)
1205
 
1206
  /* Macro instructions are defined separately and are combined with real
1207
     insns during hash table computation.  */
1208
  CGEN_INSN_TABLE macro_insn_table;
1209
 
1210
  /* Copy of CGEN_INT_INSN_P.  */
1211
  int int_insn_p;
1212
 
1213
  /* Called to rebuild the tables after something has changed.  */
1214
  void (*rebuild_tables) PARAMS ((CGEN_CPU_DESC));
1215
 
1216
  /* Operand parser callback.  */
1217
  cgen_parse_operand_fn * parse_operand_fn;
1218
 
1219
  /* Parse/insert/extract/print cover fns for operands.  */
1220
  const char * (*parse_operand)
1221
     PARAMS ((CGEN_CPU_DESC, int opindex_, const char **,
1222
              CGEN_FIELDS *fields_));
1223
#ifdef BFD_VERSION
1224
  const char * (*insert_operand)
1225
     PARAMS ((CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_,
1226
              CGEN_INSN_BYTES_PTR, bfd_vma pc_));
1227
  int (*extract_operand)
1228
     PARAMS ((CGEN_CPU_DESC, int opindex_, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
1229
              CGEN_FIELDS *fields_, bfd_vma pc_));
1230
  void (*print_operand)
1231
     PARAMS ((CGEN_CPU_DESC, int opindex_, PTR info_, CGEN_FIELDS * fields_,
1232
              void const *attrs_, bfd_vma pc_, int length_));
1233
#else
1234
  const char * (*insert_operand) ();
1235
  int (*extract_operand) ();
1236
  void (*print_operand) ();
1237
#endif
1238
#define CGEN_CPU_PARSE_OPERAND(cd) ((cd)->parse_operand)
1239
#define CGEN_CPU_INSERT_OPERAND(cd) ((cd)->insert_operand)
1240
#define CGEN_CPU_EXTRACT_OPERAND(cd) ((cd)->extract_operand)
1241
#define CGEN_CPU_PRINT_OPERAND(cd) ((cd)->print_operand)
1242
 
1243
  /* Size of CGEN_FIELDS struct.  */
1244
  unsigned int sizeof_fields;
1245
#define CGEN_CPU_SIZEOF_FIELDS(cd) ((cd)->sizeof_fields)
1246
 
1247
  /* Set the bitsize field.  */
1248
  void (*set_fields_bitsize) PARAMS ((CGEN_FIELDS *fields_, int size_));
1249
#define CGEN_CPU_SET_FIELDS_BITSIZE(cd) ((cd)->set_fields_bitsize)
1250
 
1251
  /* CGEN_FIELDS accessors.  */
1252
  int (*get_int_operand)
1253
       PARAMS ((CGEN_CPU_DESC, int opindex_, const CGEN_FIELDS *fields_));
1254
  void (*set_int_operand)
1255
       PARAMS ((CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, int value_));
1256
#ifdef BFD_VERSION
1257
  bfd_vma (*get_vma_operand)
1258
       PARAMS ((CGEN_CPU_DESC, int opindex_, const CGEN_FIELDS *fields_));
1259
  void (*set_vma_operand)
1260
       PARAMS ((CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, bfd_vma value_));
1261
#else
1262
  long (*get_vma_operand) ();
1263
  void (*set_vma_operand) ();
1264
#endif
1265
#define CGEN_CPU_GET_INT_OPERAND(cd) ((cd)->get_int_operand)
1266
#define CGEN_CPU_SET_INT_OPERAND(cd) ((cd)->set_int_operand)
1267
#define CGEN_CPU_GET_VMA_OPERAND(cd) ((cd)->get_vma_operand)
1268
#define CGEN_CPU_SET_VMA_OPERAND(cd) ((cd)->set_vma_operand)
1269
 
1270
  /* Instruction parse/insert/extract/print handlers.  */
1271
  /* FIXME: make these types uppercase.  */
1272
  cgen_parse_fn * const *parse_handlers;
1273
  cgen_insert_fn * const *insert_handlers;
1274
  cgen_extract_fn * const *extract_handlers;
1275
  cgen_print_fn * const *print_handlers;
1276
#define CGEN_PARSE_FN(cd, insn)   (cd->parse_handlers[(insn)->opcode->handlers.parse])
1277
#define CGEN_INSERT_FN(cd, insn)  (cd->insert_handlers[(insn)->opcode->handlers.insert])
1278
#define CGEN_EXTRACT_FN(cd, insn) (cd->extract_handlers[(insn)->opcode->handlers.extract])
1279
#define CGEN_PRINT_FN(cd, insn)   (cd->print_handlers[(insn)->opcode->handlers.print])
1280
 
1281
  /* Return non-zero if insn should be added to hash table.  */
1282
  int (* asm_hash_p) PARAMS ((const CGEN_INSN *));
1283
 
1284
  /* Assembler hash function.  */
1285
  unsigned int (* asm_hash) PARAMS ((const char *));
1286
 
1287
  /* Number of entries in assembler hash table.  */
1288
  unsigned int asm_hash_size;
1289
 
1290
  /* Return non-zero if insn should be added to hash table.  */
1291
  int (* dis_hash_p) PARAMS ((const CGEN_INSN *));
1292
 
1293
  /* Disassembler hash function.  */
1294
  unsigned int (* dis_hash) PARAMS ((const char *, CGEN_INSN_INT));
1295
 
1296
  /* Number of entries in disassembler hash table.  */
1297
  unsigned int dis_hash_size;
1298
 
1299
  /* Assembler instruction hash table.  */
1300
  CGEN_INSN_LIST **asm_hash_table;
1301
  CGEN_INSN_LIST *asm_hash_table_entries;
1302
 
1303
  /* Disassembler instruction hash table.  */
1304
  CGEN_INSN_LIST **dis_hash_table;
1305
  CGEN_INSN_LIST *dis_hash_table_entries;
1306
 
1307
  /* This field could be turned into a bitfield if room for other flags is needed.  */
1308
  unsigned int signed_overflow_ok_p;
1309
 
1310
} CGEN_CPU_TABLE;
1311
 
1312
/* wip */
1313
#ifndef CGEN_WORD_ENDIAN
1314
#define CGEN_WORD_ENDIAN(cd) CGEN_CPU_ENDIAN (cd)
1315
#endif
1316
#ifndef CGEN_INSN_WORD_ENDIAN
1317
#define CGEN_INSN_WORD_ENDIAN(cd) CGEN_CPU_INSN_ENDIAN (cd)
1318
#endif
1319
 
1320
/* Prototypes of major functions.  */
1321
/* FIXME: Move more CGEN_SYM-defined functions into CGEN_CPU_DESC.
1322
   Not the init fns though, as that would drag in things that mightn't be
1323
   used and might not even exist.  */
1324
 
1325
/* Argument types to cpu_open.  */
1326
 
1327
enum cgen_cpu_open_arg {
1328
  CGEN_CPU_OPEN_END,
1329
  /* Select instruction set(s), arg is bitmap or 0 meaning "unspecified".  */
1330
  CGEN_CPU_OPEN_ISAS,
1331
  /* Select machine(s), arg is bitmap or 0 meaning "unspecified".  */
1332
  CGEN_CPU_OPEN_MACHS,
1333
  /* Select machine, arg is mach's bfd name.
1334
     Multiple machines can be specified by repeated use.  */
1335
  CGEN_CPU_OPEN_BFDMACH,
1336
  /* Select endian, arg is CGEN_ENDIAN_*.  */
1337
  CGEN_CPU_OPEN_ENDIAN
1338
};
1339
 
1340
/* Open a cpu descriptor table for use.
1341
   ??? We only support ISO C stdargs here, not K&R.
1342
   Laziness, plus experiment to see if anything requires K&R - eventually
1343
   K&R will no longer be supported - e.g. GDB is currently trying this.  */
1344
 
1345
extern CGEN_CPU_DESC CGEN_SYM (cpu_open) (enum cgen_cpu_open_arg, ...);
1346
 
1347
/* Cover fn to handle simple case.  */
1348
 
1349
extern CGEN_CPU_DESC CGEN_SYM (cpu_open_1) PARAMS ((const char *mach_name_,
1350
                                                    enum cgen_endian endian_));
1351
 
1352
/* Close it.  */
1353
 
1354
extern void CGEN_SYM (cpu_close) PARAMS ((CGEN_CPU_DESC));
1355
 
1356
/* Initialize the opcode table for use.
1357
   Called by init_asm/init_dis.  */
1358
 
1359
extern void CGEN_SYM (init_opcode_table) PARAMS ((CGEN_CPU_DESC cd_));
1360
 
1361
/* Initialize the ibld table for use.
1362
   Called by init_asm/init_dis.  */
1363
 
1364
extern void CGEN_SYM (init_ibld_table) PARAMS ((CGEN_CPU_DESC cd_));
1365
 
1366
/* Initialize an cpu table for assembler or disassembler use.
1367
   These must be called immediately after cpu_open.  */
1368
 
1369
extern void CGEN_SYM (init_asm) PARAMS ((CGEN_CPU_DESC));
1370
extern void CGEN_SYM (init_dis) PARAMS ((CGEN_CPU_DESC));
1371
 
1372
/* Initialize the operand instance table for use.  */
1373
 
1374
extern void CGEN_SYM (init_opinst_table) PARAMS ((CGEN_CPU_DESC cd_));
1375
 
1376
/* Assemble an instruction.  */
1377
 
1378
extern const CGEN_INSN * CGEN_SYM (assemble_insn)
1379
     PARAMS ((CGEN_CPU_DESC, const char *, CGEN_FIELDS *,
1380
              CGEN_INSN_BYTES_PTR, char **));
1381
 
1382
extern const CGEN_KEYWORD CGEN_SYM (operand_mach);
1383
extern int CGEN_SYM (get_mach) PARAMS ((const char *));
1384
 
1385
/* Operand index computation.  */
1386
extern const CGEN_INSN * cgen_lookup_insn
1387
     PARAMS ((CGEN_CPU_DESC, const CGEN_INSN * insn_,
1388
              CGEN_INSN_INT int_value_, unsigned char *bytes_value_,
1389
              int length_, CGEN_FIELDS *fields_, int alias_p_));
1390
extern void cgen_get_insn_operands
1391
     PARAMS ((CGEN_CPU_DESC, const CGEN_INSN * insn_,
1392
              const CGEN_FIELDS *fields_, int *indices_));
1393
extern const CGEN_INSN * cgen_lookup_get_insn_operands
1394
     PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *insn_,
1395
              CGEN_INSN_INT int_value_, unsigned char *bytes_value_,
1396
              int length_, int *indices_, CGEN_FIELDS *fields_));
1397
 
1398
/* Cover fns to bfd_get/set.  */
1399
 
1400
extern CGEN_INSN_INT cgen_get_insn_value
1401
     PARAMS ((CGEN_CPU_DESC, unsigned char *, int));
1402
extern void cgen_put_insn_value
1403
     PARAMS ((CGEN_CPU_DESC, unsigned char *, int, CGEN_INSN_INT));
1404
 
1405
/* Read in a cpu description file.
1406
   ??? For future concerns, including adding instructions to the assembler/
1407
   disassembler at run-time.  */
1408
 
1409
extern const char * cgen_read_cpu_file
1410
     PARAMS ((CGEN_CPU_DESC, const char * filename_));
1411
 
1412
/* Allow signed overflow of instruction fields.  */
1413
extern void cgen_set_signed_overflow_ok PARAMS ((CGEN_CPU_DESC));
1414
 
1415
/* Generate an error message if a signed field in an instruction overflows.  */
1416
extern void cgen_clear_signed_overflow_ok PARAMS ((CGEN_CPU_DESC));
1417
 
1418
/* Will an error message be generated if a signed field in an instruction overflows ? */
1419
extern unsigned int cgen_signed_overflow_ok_p PARAMS ((CGEN_CPU_DESC));
1420
 
1421
#endif /* CGEN_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.