source: trunk/src/binutils/include/opcode/cgen.h@ 239

Last change on this file since 239 was 10, checked in by bird, 23 years ago

Initial revision

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