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