1 /* Header file for targets using CGEN: Cpu tools GENerator.
3 Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
5 This file is part of GDB, the GNU debugger, and the GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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. */
31 /* Enums must be defined before they can be used.
32 Allow them to be used in struct definitions, even though the enum must
34 If CGEN_ARCH isn't defined, this file is being included by something other
35 than <arch>-desc.h. */
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". */
44 #define CGEN_SYM(s) CONCAT3 (unknown,_cgen_,s)
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. */
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. */
58 /* Lots of cpu's have a fixed insn size, or one which rarely changes,
59 and it's generally easier to handle these by treating the insn as an
60 integer type, rather than an array of characters. So we allow targets
61 to control this. When an integer type the value is in host byte order,
62 when an array of characters the value is in target byte order. */
64 typedef unsigned int CGEN_INSN_INT;
66 typedef CGEN_INSN_INT CGEN_INSN_BYTES;
67 typedef CGEN_INSN_INT *CGEN_INSN_BYTES_PTR;
69 typedef unsigned char *CGEN_INSN_BYTES;
70 typedef unsigned char *CGEN_INSN_BYTES_PTR;
74 #define CGEN_INLINE __inline__
88 typedef struct cgen_insn CGEN_INSN;
90 /* Opaque pointer version for use by external world. */
92 typedef struct cgen_cpu_desc *CGEN_CPU_DESC;
95 Attributes are used to describe various random things associated with
96 an object (ifield, hardware, operand, insn, whatever) and are specified
98 Integer attributes computed at compile time are currently all that's
99 supported, though adding string attributes and run-time computation is
100 straightforward. Integer attribute values are always host int's
101 (signed or unsigned). For portability, this means 32 bits.
102 Integer attributes are further categorized as boolean, bitset, integer,
103 and enum types. Boolean attributes appear frequently enough that they're
104 recorded in one host int. This limits the maximum number of boolean
105 attributes to 32, though that's a *lot* of attributes. */
107 /* Type of attribute values. */
109 typedef int CGEN_ATTR_VALUE_TYPE;
111 /* Struct to record attribute information. */
115 /* Boolean attributes. */
117 /* Non-boolean integer attributes. */
118 CGEN_ATTR_VALUE_TYPE nonbool[1];
121 /* Define a structure member for attributes with N non-boolean entries.
122 There is no maximum number of non-boolean attributes.
123 There is a maximum of 32 boolean attributes (since they are all recorded
126 #define CGEN_ATTR_TYPE(n) \
127 struct { unsigned int bool; \
128 CGEN_ATTR_VALUE_TYPE nonbool[(n) ? (n) : 1]; }
130 /* Return the boolean attributes. */
132 #define CGEN_ATTR_BOOLS(a) ((a)->bool)
134 /* Non-boolean attribute numbers are offset by this much. */
136 #define CGEN_ATTR_NBOOL_OFFSET 32
138 /* Given a boolean attribute number, return its mask. */
140 #define CGEN_ATTR_MASK(attr) (1 << (attr))
142 /* Return the value of boolean attribute ATTR in ATTRS. */
144 #define CGEN_BOOL_ATTR(attrs, attr) ((CGEN_ATTR_MASK (attr) & (attrs)) != 0)
146 /* Return value of attribute ATTR in ATTR_TABLE for OBJ.
147 OBJ is a pointer to the entity that has the attributes
148 (??? not used at present but is reserved for future purposes - eventually
149 the goal is to allow recording attributes in source form and computing
150 them lazily at runtime, not sure of the details yet). */
152 #define CGEN_ATTR_VALUE(obj, attr_table, attr) \
153 ((unsigned int) (attr) < CGEN_ATTR_NBOOL_OFFSET \
154 ? ((CGEN_ATTR_BOOLS (attr_table) & CGEN_ATTR_MASK (attr)) != 0) \
155 : ((attr_table)->nonbool[(attr) - CGEN_ATTR_NBOOL_OFFSET]))
157 /* Attribute name/value tables.
158 These are used to assist parsing of descriptions at run-time. */
163 CGEN_ATTR_VALUE_TYPE value;
166 /* For each domain (ifld,hw,operand,insn), list of attributes. */
171 const CGEN_ATTR_ENTRY * dfault;
172 const CGEN_ATTR_ENTRY * vals;
175 /* Instruction set variants. */
180 /* Default instruction size (in bits).
181 This is used by the assembler when it encounters an unknown insn. */
182 unsigned int default_insn_bitsize;
184 /* Base instruction size (in bits).
185 For non-LIW cpus this is generally the length of the smallest insn.
186 For LIW cpus its wip (work-in-progress). For the m32r its 32. */
187 unsigned int base_insn_bitsize;
189 /* Minimum/maximum instruction size (in bits). */
190 unsigned int min_insn_bitsize;
191 unsigned int max_insn_bitsize;
194 /* Machine variants. */
198 /* The argument to bfd_arch_info->scan. */
199 const char *bfd_name;
200 /* one of enum mach_attr */
204 /* Parse result (also extraction result).
206 The result of parsing an insn is stored here.
207 To generate the actual insn, this is passed to the insert handler.
208 When printing an insn, the result of extraction is stored here.
209 To print the insn, this is passed to the print handler.
211 It is machine generated so we don't define it here,
212 but we do need a forward decl for the handler fns.
214 There is one member for each possible field in the insn.
215 The type depends on the field.
216 Also recorded here is the computed length of the insn for architectures
220 typedef struct cgen_fields CGEN_FIELDS;
222 /* Total length of the insn, as recorded in the `fields' struct. */
223 /* ??? The field insert handler has lots of opportunities for optimization
224 if it ever gets inlined. On architectures where insns all have the same
225 size, may wish to detect that and make this macro a constant - to allow
226 further optimizations. */
228 #define CGEN_FIELDS_BITSIZE(fields) ((fields)->length)
230 /* Extraction support for variable length insn sets. */
232 /* When disassembling we don't know the number of bytes to read at the start.
233 So the first CGEN_BASE_INSN_SIZE bytes are read at the start and the rest
234 are read when needed. This struct controls this. It is basically the
235 disassemble_info stuff, except that we provide a cache for values already
236 read (since bytes can typically be read several times to fetch multiple
237 operands that may be in them), and that extraction of fields is needed
238 in contexts other than disassembly. */
241 /* A pointer to the disassemble_info struct.
242 We don't require dis-asm.h so we use PTR for the type here.
243 If NULL, BYTES is full of valid data (VALID == -1). */
245 /* Points to a working buffer of sufficient size. */
246 unsigned char *insn_bytes;
247 /* Mask of bytes that are valid in INSN_BYTES. */
251 /* Associated with each insn or expression is a set of "handlers" for
252 performing operations like parsing, printing, etc. These require a bfd_vma
253 value to be passed around but we don't want all applications to need bfd.h.
254 So this stuff is only provided if bfd.h has been included. */
257 CD is a cpu table descriptor.
258 INSN is a pointer to a struct describing the insn being parsed.
259 STRP is a pointer to a pointer to the text being parsed.
260 FIELDS is a pointer to a cgen_fields struct in which the results are placed.
261 If the expression is successfully parsed, *STRP is updated.
262 If not it is left alone.
263 The result is NULL if success or an error message. */
264 typedef const char * (cgen_parse_fn)
265 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *insn_,
266 const char **strp_, CGEN_FIELDS *fields_));
269 CD is a cpu table descriptor.
270 INSN is a pointer to a struct describing the insn being parsed.
271 FIELDS is a pointer to a cgen_fields struct from which the values
273 INSNP is a pointer to a buffer in which to place the insn.
274 PC is the pc value of the insn.
275 The result is an error message or NULL if success. */
278 typedef const char * (cgen_insert_fn)
279 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *insn_,
280 CGEN_FIELDS *fields_, CGEN_INSN_BYTES_PTR insnp_,
283 typedef const char * (cgen_insert_fn) ();
287 CD is a cpu table descriptor.
288 INSN is a pointer to a struct describing the insn being parsed.
289 The second argument is a pointer to a struct controlling extraction
290 (only used for variable length insns).
291 EX_INFO is a pointer to a struct for controlling reading of further
293 BASE_INSN is the first CGEN_BASE_INSN_SIZE bytes (host order).
294 FIELDS is a pointer to a cgen_fields struct in which the results are placed.
295 PC is the pc value of the insn.
296 The result is the length of the insn in bits or zero if not recognized. */
299 typedef int (cgen_extract_fn)
300 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *insn_,
301 CGEN_EXTRACT_INFO *ex_info_, CGEN_INSN_INT base_insn_,
302 CGEN_FIELDS *fields_, bfd_vma pc_));
304 typedef int (cgen_extract_fn) ();
308 CD is a cpu table descriptor.
309 INFO is a pointer to the disassembly info.
310 Eg: disassemble_info. It's defined as `PTR' so this file can be included
312 INSN is a pointer to a struct describing the insn being printed.
313 FIELDS is a pointer to a cgen_fields struct.
314 PC is the pc value of the insn.
315 LEN is the length of the insn, in bits. */
318 typedef void (cgen_print_fn)
319 PARAMS ((CGEN_CPU_DESC, PTR info_, const CGEN_INSN *insn_,
320 CGEN_FIELDS *fields_, bfd_vma pc_, int len_));
322 typedef void (cgen_print_fn) ();
325 /* Parse/insert/extract/print handlers.
327 Indices into the handler tables.
328 We could use pointers here instead, but 90% of them are generally identical
329 and that's a lot of redundant data. Making these unsigned char indices
330 into tables of pointers saves a bit of space.
331 Using indices also keeps assembler code out of the disassembler and
334 struct cgen_opcode_handler
336 unsigned char parse, insert, extract, print;
339 /* Assembler interface.
341 The interface to the assembler is intended to be clean in the sense that
342 libopcodes.a is a standalone entity and could be used with any assembler.
343 Not that one would necessarily want to do that but rather that it helps
344 keep a clean interface. The interface will obviously be slanted towards
345 GAS, but at least it's a start.
346 ??? Note that one possible user of the assembler besides GAS is GDB.
348 Parsing is controlled by the assembler which calls
349 CGEN_SYM (assemble_insn). If it can parse and build the entire insn
350 it doesn't call back to the assembler. If it needs/wants to call back
351 to the assembler, cgen_parse_operand_fn is called which can either
353 - return a number to be inserted in the insn
354 - return a "register" value to be inserted
355 (the register might not be a register per pe)
356 - queue the argument and return a marker saying the expression has been
357 queued (eg: a fix-up)
358 - return an error message indicating the expression wasn't recognizable
360 The result is an error message or NULL for success.
361 The parsed value is stored in the bfd_vma *. */
363 /* Values for indicating what the caller wants. */
365 enum cgen_parse_operand_type
367 CGEN_PARSE_OPERAND_INIT,
368 CGEN_PARSE_OPERAND_INTEGER,
369 CGEN_PARSE_OPERAND_ADDRESS
372 /* Values for indicating what was parsed. */
374 enum cgen_parse_operand_result
376 CGEN_PARSE_OPERAND_RESULT_NUMBER,
377 CGEN_PARSE_OPERAND_RESULT_REGISTER,
378 CGEN_PARSE_OPERAND_RESULT_QUEUED,
379 CGEN_PARSE_OPERAND_RESULT_ERROR
382 #ifdef BFD_VERSION /* Don't require bfd.h unnecessarily. */
383 typedef const char * (cgen_parse_operand_fn)
384 PARAMS ((CGEN_CPU_DESC,
385 enum cgen_parse_operand_type, const char **, int, int,
386 enum cgen_parse_operand_result *, bfd_vma *));
388 typedef const char * (cgen_parse_operand_fn) ();
391 /* Set the cgen_parse_operand_fn callback. */
393 extern void cgen_set_parse_operand_fn
394 PARAMS ((CGEN_CPU_DESC, cgen_parse_operand_fn));
396 /* Called before trying to match a table entry with the insn. */
398 extern void cgen_init_parse_operand PARAMS ((CGEN_CPU_DESC));
400 /* Operand values (keywords, integers, symbols, etc.) */
402 /* Types of assembler elements. */
406 CGEN_ASM_NONE, CGEN_ASM_KEYWORD, CGEN_ASM_MAX
410 enum cgen_hw_type { CGEN_HW_MAX };
413 /* List of hardware elements. */
418 enum cgen_hw_type type;
419 /* There is currently no example where both index specs and value specs
420 are required, so for now both are clumped under "asm_data". */
421 enum cgen_asm_type asm_type;
423 #ifndef CGEN_HW_NBOOL_ATTRS
424 #define CGEN_HW_NBOOL_ATTRS 1
426 CGEN_ATTR_TYPE (CGEN_HW_NBOOL_ATTRS) attrs;
427 #define CGEN_HW_ATTRS(hw) (&(hw)->attrs)
430 /* Return value of attribute ATTR in HW. */
432 #define CGEN_HW_ATTR_VALUE(hw, attr) \
433 CGEN_ATTR_VALUE ((hw), CGEN_HW_ATTRS (hw), (attr))
435 /* Table of hardware elements for selected mach, computed at runtime.
436 enum cgen_hw_type is an index into this table (specifically `entries'). */
439 /* Pointer to null terminated table of all compiled in entries. */
440 const CGEN_HW_ENTRY *init_entries;
441 unsigned int entry_size; /* since the attribute member is variable sized */
442 /* Array of all entries, initial and run-time added. */
443 const CGEN_HW_ENTRY **entries;
444 /* Number of elements in `entries'. */
445 unsigned int num_entries;
446 /* For now, xrealloc is called each time a new entry is added at runtime.
447 ??? May wish to keep track of some slop to reduce the number of calls to
448 xrealloc, except that there's unlikely to be many and not expected to be
449 in speed critical code. */
452 extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_name
453 PARAMS ((CGEN_CPU_DESC, const char *));
454 extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_num
455 PARAMS ((CGEN_CPU_DESC, int));
457 /* This struct is used to describe things like register names, etc. */
459 typedef struct cgen_keyword_entry
461 /* Name (as in register name). */
464 /* Value (as in register number).
465 The value cannot be -1 as that is used to indicate "not found".
466 IDEA: Have "FUNCTION" attribute? [function is called to fetch value]. */
470 This should, but technically needn't, appear last. It is a variable sized
471 array in that one architecture may have 1 nonbool attribute and another
472 may have more. Having this last means the non-architecture specific code
473 needn't care. The goal is to eventually record
474 attributes in their raw form, evaluate them at run-time, and cache the
475 values, so this worry will go away anyway. */
476 /* ??? Moving this last should be done by treating keywords like insn lists
477 and moving the `next' fields into a CGEN_KEYWORD_LIST struct. */
478 /* FIXME: Not used yet. */
479 #ifndef CGEN_KEYWORD_NBOOL_ATTRS
480 #define CGEN_KEYWORD_NBOOL_ATTRS 1
482 CGEN_ATTR_TYPE (CGEN_KEYWORD_NBOOL_ATTRS) attrs;
484 /* ??? Putting these here means compiled in entries can't be const.
485 Not a really big deal, but something to consider. */
486 /* Next name hash table entry. */
487 struct cgen_keyword_entry *next_name;
488 /* Next value hash table entry. */
489 struct cgen_keyword_entry *next_value;
490 } CGEN_KEYWORD_ENTRY;
492 /* Top level struct for describing a set of related keywords
493 (e.g. register names).
495 This struct supports run-time entry of new values, and hashed lookups. */
497 typedef struct cgen_keyword
499 /* Pointer to initial [compiled in] values. */
500 CGEN_KEYWORD_ENTRY *init_entries;
502 /* Number of entries in `init_entries'. */
503 unsigned int num_init_entries;
505 /* Hash table used for name lookup. */
506 CGEN_KEYWORD_ENTRY **name_hash_table;
508 /* Hash table used for value lookup. */
509 CGEN_KEYWORD_ENTRY **value_hash_table;
511 /* Number of entries in the hash_tables. */
512 unsigned int hash_table_size;
514 /* Pointer to null keyword "" entry if present. */
515 const CGEN_KEYWORD_ENTRY *null_entry;
518 /* Structure used for searching. */
522 /* Table being searched. */
523 const CGEN_KEYWORD *table;
525 /* Specification of what is being searched for. */
528 /* Current index in hash table. */
529 unsigned int current_hash;
531 /* Current element in current hash chain. */
532 CGEN_KEYWORD_ENTRY *current_entry;
533 } CGEN_KEYWORD_SEARCH;
535 /* Lookup a keyword from its name. */
537 const CGEN_KEYWORD_ENTRY *cgen_keyword_lookup_name
538 PARAMS ((CGEN_KEYWORD *, const char *));
540 /* Lookup a keyword from its value. */
542 const CGEN_KEYWORD_ENTRY *cgen_keyword_lookup_value
543 PARAMS ((CGEN_KEYWORD *, int));
547 void cgen_keyword_add PARAMS ((CGEN_KEYWORD *, CGEN_KEYWORD_ENTRY *));
549 /* Keyword searching.
550 This can be used to retrieve every keyword, or a subset. */
552 CGEN_KEYWORD_SEARCH cgen_keyword_search_init
553 PARAMS ((CGEN_KEYWORD *, const char *));
554 const CGEN_KEYWORD_ENTRY *cgen_keyword_search_next
555 PARAMS ((CGEN_KEYWORD_SEARCH *));
557 /* Operand value support routines. */
559 extern const char *cgen_parse_keyword
560 PARAMS ((CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *));
561 #ifdef BFD_VERSION /* Don't require bfd.h unnecessarily. */
562 extern const char *cgen_parse_signed_integer
563 PARAMS ((CGEN_CPU_DESC, const char **, int, long *));
564 extern const char *cgen_parse_unsigned_integer
565 PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
566 extern const char *cgen_parse_address
567 PARAMS ((CGEN_CPU_DESC, const char **, int, int,
568 enum cgen_parse_operand_result *, bfd_vma *));
569 extern const char *cgen_validate_signed_integer
570 PARAMS ((long, long, long));
571 extern const char *cgen_validate_unsigned_integer
572 PARAMS ((unsigned long, unsigned long, unsigned long));
577 /* ??? This duplicates the values in arch.h. Revisit.
578 These however need the CGEN_ prefix [as does everything in this file]. */
579 /* ??? Targets may need to add their own modes so we may wish to move this
580 to <arch>-opc.h, or add a hook. */
583 CGEN_MODE_VOID, /* ??? rename simulator's VM to VOID? */
584 CGEN_MODE_BI, CGEN_MODE_QI, CGEN_MODE_HI, CGEN_MODE_SI, CGEN_MODE_DI,
585 CGEN_MODE_UBI, CGEN_MODE_UQI, CGEN_MODE_UHI, CGEN_MODE_USI, CGEN_MODE_UDI,
586 CGEN_MODE_SF, CGEN_MODE_DF, CGEN_MODE_XF, CGEN_MODE_TF,
587 CGEN_MODE_TARGET_MAX,
588 CGEN_MODE_INT, CGEN_MODE_UINT,
592 /* FIXME: Until simulator is updated. */
594 #define CGEN_MODE_VM CGEN_MODE_VOID
599 enum cgen_operand_type { CGEN_OPERAND_MAX };
602 /* "nil" indicator for the operand instance table */
603 #define CGEN_OPERAND_NIL CGEN_OPERAND_MAX
605 /* This struct defines each entry in the operand table. */
609 /* Name as it appears in the syntax string. */
613 enum cgen_operand_type type;
615 /* The hardware element associated with this operand. */
616 enum cgen_hw_type hw_type;
618 /* FIXME: We don't yet record ifield definitions, which we should.
619 When we do it might make sense to delete start/length (since they will
620 be duplicated in the ifield's definition) and replace them with a
621 pointer to the ifield entry. */
624 This is just a hint, and may be unused in more complex operands.
625 May be unused for a modifier. */
628 /* The number of bits in the operand.
629 This is just a hint, and may be unused in more complex operands.
630 May be unused for a modifier. */
631 unsigned char length;
633 #if 0 /* ??? Interesting idea but relocs tend to get too complicated,
634 and ABI dependent, for simple table lookups to work. */
635 /* Ideally this would be the internal (external?) reloc type. */
640 This should, but technically needn't, appear last. It is a variable sized
641 array in that one architecture may have 1 nonbool attribute and another
642 may have more. Having this last means the non-architecture specific code
643 needn't care, now or tomorrow. The goal is to eventually record
644 attributes in their raw form, evaluate them at run-time, and cache the
645 values, so this worry will go away anyway. */
646 #ifndef CGEN_OPERAND_NBOOL_ATTRS
647 #define CGEN_OPERAND_NBOOL_ATTRS 1
649 CGEN_ATTR_TYPE (CGEN_OPERAND_NBOOL_ATTRS) attrs;
650 #define CGEN_OPERAND_ATTRS(operand) (&(operand)->attrs)
653 /* Return value of attribute ATTR in OPERAND. */
655 #define CGEN_OPERAND_ATTR_VALUE(operand, attr) \
656 CGEN_ATTR_VALUE ((operand), CGEN_OPERAND_ATTRS (operand), (attr))
658 /* Table of operands for selected mach/isa, computed at runtime.
659 enum cgen_operand_type is an index into this table (specifically
663 /* Pointer to null terminated table of all compiled in entries. */
664 const CGEN_OPERAND *init_entries;
665 unsigned int entry_size; /* since the attribute member is variable sized */
666 /* Array of all entries, initial and run-time added. */
667 const CGEN_OPERAND **entries;
668 /* Number of elements in `entries'. */
669 unsigned int num_entries;
670 /* For now, xrealloc is called each time a new entry is added at runtime.
671 ??? May wish to keep track of some slop to reduce the number of calls to
672 xrealloc, except that there's unlikely to be many and not expected to be
673 in speed critical code. */
674 } CGEN_OPERAND_TABLE;
676 extern const CGEN_OPERAND * cgen_operand_lookup_by_name
677 PARAMS ((CGEN_CPU_DESC, const char *));
678 extern const CGEN_OPERAND * cgen_operand_lookup_by_num
679 PARAMS ((CGEN_CPU_DESC, int));
681 /* Instruction operand instances.
683 For each instruction, a list of the hardware elements that are read and
684 written are recorded. */
686 /* The type of the instance. */
688 enum cgen_opinst_type {
689 /* End of table marker. */
691 CGEN_OPINST_INPUT, CGEN_OPINST_OUTPUT
696 /* Input or output indicator. */
697 enum cgen_opinst_type type;
699 /* Name of operand. */
702 /* The hardware element referenced. */
703 enum cgen_hw_type hw_type;
705 /* The mode in which the operand is being used. */
708 /* The operand table entry CGEN_OPERAND_NIL if there is none
709 (i.e. an explicit hardware reference). */
710 enum cgen_operand_type op_type;
712 /* If `operand' is "nil", the index (e.g. into array of registers). */
716 ??? This perhaps should be a real attribute struct but there's
717 no current need, so we save a bit of space and just have a set of
718 flags. The interface is such that this can easily be made attributes
719 should it prove useful. */
721 #define CGEN_OPINST_ATTRS(opinst) ((opinst)->attrs)
722 /* Return value of attribute ATTR in OPINST. */
723 #define CGEN_OPINST_ATTR(opinst, attr) \
724 ((CGEN_OPINST_ATTRS (opinst) & (attr)) != 0)
725 /* Operand is conditionally referenced (read/written). */
726 #define CGEN_OPINST_COND_REF 1
731 Each insn format and subexpression has one of these.
733 The syntax "string" consists of characters (n > 0 && n < 128), and operand
734 values (n >= 128), and is terminated by 0. Operand values are 128 + index
735 into the operand table. The operand table doesn't exist in C, per se, as
736 the data is recorded in the parse/insert/extract/print switch statements. */
738 #ifndef CGEN_MAX_SYNTAX_BYTES
739 #define CGEN_MAX_SYNTAX_BYTES 16
744 unsigned char syntax[CGEN_MAX_SYNTAX_BYTES];
747 #define CGEN_SYNTAX_STRING(syn) (syn->syntax)
748 #define CGEN_SYNTAX_CHAR_P(c) ((c) < 128)
749 #define CGEN_SYNTAX_CHAR(c) (c)
750 #define CGEN_SYNTAX_FIELD(c) ((c) - 128)
751 #define CGEN_SYNTAX_MAKE_FIELD(c) ((c) + 128)
753 /* ??? I can't currently think of any case where the mnemonic doesn't come
754 first [and if one ever doesn't building the hash tables will be tricky].
755 However, we treat mnemonics as just another operand of the instruction.
756 A value of 1 means "this is where the mnemonic appears". 1 isn't
757 special other than it's a non-printable ASCII char. */
759 #define CGEN_SYNTAX_MNEMONIC 1
760 #define CGEN_SYNTAX_MNEMONIC_P(ch) ((ch) == CGEN_SYNTAX_MNEMONIC)
762 /* Instruction fields.
764 ??? We currently don't allow adding fields at run-time.
765 Easy to fix when needed. */
767 typedef struct cgen_ifld {
768 /* Enum of ifield. */
770 #define CGEN_IFLD_NUM(f) ((f)->num)
772 /* Name of the field, distinguishes it from all other fields. */
774 #define CGEN_IFLD_NAME(f) ((f)->name)
776 /* Default offset, in bits, from the start of the insn to the word
777 containing the field. */
779 #define CGEN_IFLD_WORD_OFFSET(f) ((f)->word_offset)
781 /* Default length of the word containing the field. */
783 #define CGEN_IFLD_WORD_SIZE(f) ((f)->word_size)
785 /* Default starting bit number.
786 Whether lsb=0 or msb=0 is determined by CGEN_INSN_LSB0_P. */
788 #define CGEN_IFLD_START(f) ((f)->start)
790 /* Length of the field, in bits. */
792 #define CGEN_IFLD_LENGTH(f) ((f)->length)
794 #ifndef CGEN_IFLD_NBOOL_ATTRS
795 #define CGEN_IFLD_NBOOL_ATTRS 1
797 CGEN_ATTR_TYPE (CGEN_IFLD_NBOOL_ATTRS) attrs;
798 #define CGEN_IFLD_ATTRS(f) (&(f)->attrs)
801 /* Return value of attribute ATTR in IFLD. */
802 #define CGEN_IFLD_ATTR_VALUE(ifld, attr) \
803 CGEN_ATTR_VALUE ((ifld), CGEN_IFLD_ATTRS (ifld), (attr))
805 /* Instruction data. */
807 /* Instruction formats.
809 Instructions are grouped by format. Associated with an instruction is its
810 format. Each insn's opcode table entry contains a format table entry.
811 ??? There is usually very few formats compared with the number of insns,
812 so one can reduce the size of the opcode table by recording the format table
813 as a separate entity. Given that we currently don't, format table entries
814 are also distinguished by their operands. This increases the size of the
815 table, but reduces the number of tables. It's all minutiae anyway so it
816 doesn't really matter [at this point in time].
818 ??? Support for variable length ISA's is wip. */
820 /* Accompanying each iformat description is a list of its fields. */
823 const CGEN_IFLD *ifld;
824 #define CGEN_IFMT_IFLD_IFLD(ii) ((ii)->ifld)
827 #ifndef CGEN_MAX_IFMT_OPERANDS
828 #define CGEN_MAX_IFMT_OPERANDS 1
833 /* Length that MASK and VALUE have been calculated to
834 [VALUE is recorded elsewhere].
835 Normally it is base_insn_bitsize. On [V]LIW architectures where the base
836 insn size may be larger than the size of an insn, this field is less than
837 base_insn_bitsize. */
838 unsigned char mask_length;
839 #define CGEN_IFMT_MASK_LENGTH(ifmt) ((ifmt)->mask_length)
841 /* Total length of instruction, in bits. */
842 unsigned char length;
843 #define CGEN_IFMT_LENGTH(ifmt) ((ifmt)->length)
845 /* Mask to apply to the first MASK_LENGTH bits.
846 Each insn's value is stored with the insn.
847 The first step in recognizing an insn for disassembly is
848 (opcode & mask) == value. */
850 #define CGEN_IFMT_MASK(ifmt) ((ifmt)->mask)
852 /* Instruction fields.
853 +1 for trailing NULL. */
854 CGEN_IFMT_IFLD iflds[CGEN_MAX_IFMT_OPERANDS + 1];
855 #define CGEN_IFMT_IFLDS(ifmt) ((ifmt)->iflds)
858 /* Instruction values. */
862 /* The opcode portion of the base insn. */
863 CGEN_INSN_INT base_value;
865 #ifdef CGEN_MAX_EXTRA_OPCODE_OPERANDS
866 /* Extra opcode values beyond base_value. */
867 unsigned long ifield_values[CGEN_MAX_EXTRA_OPCODE_OPERANDS];
871 /* Instruction opcode table.
872 This contains the syntax and format data of an instruction. */
874 /* ??? Some ports already have an opcode table yet still need to use the rest
875 of what cgen_insn has. Plus keeping the opcode data with the operand
876 instance data can create a pretty big file. So we keep them separately.
877 Not sure this is a good idea in the long run. */
881 /* Indices into parse/insert/extract/print handler tables. */
882 struct cgen_opcode_handler handlers;
883 #define CGEN_OPCODE_HANDLERS(opc) (& (opc)->handlers)
887 #define CGEN_OPCODE_SYNTAX(opc) (& (opc)->syntax)
890 const CGEN_IFMT *format;
891 #define CGEN_OPCODE_FORMAT(opc) ((opc)->format)
892 #define CGEN_OPCODE_MASK_BITSIZE(opc) CGEN_IFMT_MASK_LENGTH (CGEN_OPCODE_FORMAT (opc))
893 #define CGEN_OPCODE_BITSIZE(opc) CGEN_IFMT_LENGTH (CGEN_OPCODE_FORMAT (opc))
894 #define CGEN_OPCODE_IFLDS(opc) CGEN_IFMT_IFLDS (CGEN_OPCODE_FORMAT (opc))
896 /* Instruction opcode value. */
898 #define CGEN_OPCODE_VALUE(opc) (& (opc)->value)
899 #define CGEN_OPCODE_BASE_VALUE(opc) (CGEN_OPCODE_VALUE (opc)->base_value)
900 #define CGEN_OPCODE_BASE_MASK(opc) CGEN_IFMT_MASK (CGEN_OPCODE_FORMAT (opc))
903 /* Instruction attributes.
904 This is made a published type as applications can cache a pointer to
905 the attributes for speed. */
907 #ifndef CGEN_INSN_NBOOL_ATTRS
908 #define CGEN_INSN_NBOOL_ATTRS 1
910 typedef CGEN_ATTR_TYPE (CGEN_INSN_NBOOL_ATTRS) CGEN_INSN_ATTR_TYPE;
912 /* Enum of architecture independent attributes. */
915 /* ??? Numbers here are recorded in two places. */
916 typedef enum cgen_insn_attr {
921 /* This struct defines each entry in the instruction table. */
925 /* Each real instruction is enumerated. */
926 /* ??? This may go away in time. */
928 #define CGEN_INSN_NUM(insn) ((insn)->base->num)
930 /* Name of entry (that distinguishes it from all other entries). */
931 /* ??? If mnemonics have operands, try to print full mnemonic. */
933 #define CGEN_INSN_NAME(insn) ((insn)->base->name)
935 /* Mnemonic. This is used when parsing and printing the insn.
936 In the case of insns that have operands on the mnemonics, this is
937 only the constant part. E.g. for conditional execution of an `add' insn,
938 where the full mnemonic is addeq, addne, etc., and the condition is
939 treated as an operand, this is only "add". */
940 const char *mnemonic;
941 #define CGEN_INSN_MNEMONIC(insn) ((insn)->base->mnemonic)
943 /* Total length of instruction, in bits. */
945 #define CGEN_INSN_BITSIZE(insn) ((insn)->base->bitsize)
947 #if 0 /* ??? Disabled for now as there is a problem with embedded newlines
948 and the table is already pretty big. Should perhaps be moved
949 to a file of its own. */
950 /* Semantics, as RTL. */
951 /* ??? Plain text or bytecodes? */
952 /* ??? Note that the operand instance table could be computed at run-time
953 if we parse this and cache the results. Something to eventually do. */
955 #define CGEN_INSN_RTX(insn) ((insn)->base->rtx)
959 This must appear last. It is a variable sized array in that one
960 architecture may have 1 nonbool attribute and another may have more.
961 Having this last means the non-architecture specific code needn't
962 care. The goal is to eventually record attributes in their raw form,
963 evaluate them at run-time, and cache the values, so this worry will go
965 CGEN_INSN_ATTR_TYPE attrs;
966 #define CGEN_INSN_ATTRS(insn) (&(insn)->base->attrs)
967 /* Return value of attribute ATTR in INSN. */
968 #define CGEN_INSN_ATTR_VALUE(insn, attr) \
969 CGEN_ATTR_VALUE ((insn), CGEN_INSN_ATTRS (insn), (attr))
972 /* Return non-zero if INSN is the "invalid" insn marker. */
974 #define CGEN_INSN_INVALID_P(insn) (CGEN_INSN_MNEMONIC (insn) == 0)
976 /* Main struct contain instruction information.
977 BASE is always present, the rest is present only if asked for. */
981 /* ??? May be of use to put a type indicator here.
982 Then this struct could different info for different classes of insns. */
983 /* ??? A speedup can be had by moving `base' into this struct.
985 const CGEN_IBASE *base;
986 const CGEN_OPCODE *opcode;
987 const CGEN_OPINST *opinst;
990 /* Instruction lists.
991 This is used for adding new entries and for creating the hash lists. */
993 typedef struct cgen_insn_list
995 struct cgen_insn_list *next;
996 const CGEN_INSN *insn;
999 /* Table of instructions. */
1003 const CGEN_INSN *init_entries;
1004 unsigned int entry_size; /* since the attribute member is variable sized */
1005 unsigned int num_init_entries;
1006 CGEN_INSN_LIST *new_entries;
1009 /* Return number of instructions. This includes any added at run-time. */
1011 extern int cgen_insn_count PARAMS ((CGEN_CPU_DESC));
1012 extern int cgen_macro_insn_count PARAMS ((CGEN_CPU_DESC));
1014 /* Macros to access the other insn elements not recorded in CGEN_IBASE. */
1016 /* Fetch INSN's operand instance table. */
1017 /* ??? Doesn't handle insns added at runtime. */
1018 #define CGEN_INSN_OPERANDS(insn) ((insn)->opinst)
1020 /* Return INSN's opcode table entry. */
1021 #define CGEN_INSN_OPCODE(insn) ((insn)->opcode)
1023 /* Return INSN's handler data. */
1024 #define CGEN_INSN_HANDLERS(insn) CGEN_OPCODE_HANDLERS (CGEN_INSN_OPCODE (insn))
1026 /* Return INSN's syntax. */
1027 #define CGEN_INSN_SYNTAX(insn) CGEN_OPCODE_SYNTAX (CGEN_INSN_OPCODE (insn))
1029 /* Return size of base mask in bits. */
1030 #define CGEN_INSN_MASK_BITSIZE(insn) \
1031 CGEN_OPCODE_MASK_BITSIZE (CGEN_INSN_OPCODE (insn))
1033 /* Return mask of base part of INSN. */
1034 #define CGEN_INSN_BASE_MASK(insn) \
1035 CGEN_OPCODE_BASE_MASK (CGEN_INSN_OPCODE (insn))
1037 /* Return value of base part of INSN. */
1038 #define CGEN_INSN_BASE_VALUE(insn) \
1039 CGEN_OPCODE_BASE_VALUE (CGEN_INSN_OPCODE (insn))
1041 /* Standard way to test whether INSN is supported by MACH.
1042 MACH is one of enum mach_attr.
1043 The "|1" is because the base mach is always selected. */
1044 #define CGEN_INSN_MACH_HAS_P(insn, mach) \
1045 ((CGEN_INSN_ATTR_VALUE ((insn), CGEN_INSN_MACH) & ((1 << (mach)) | 1)) != 0)
1047 /* Macro instructions.
1048 Macro insns aren't real insns, they map to one or more real insns.
1049 E.g. An architecture's "nop" insn may actually be an "mv r0,r0" or
1052 Macro insns can expand to nothing (e.g. a nop that is optimized away).
1053 This is useful in multi-insn macros that build a constant in a register.
1054 Of course this isn't the default behaviour and must be explicitly enabled.
1056 Assembly of macro-insns is relatively straightforward. Disassembly isn't.
1057 However, disassembly of at least some kinds of macro insns is important
1058 in order that the disassembled code preserve the readability of the original
1059 insn. What is attempted here is to disassemble all "simple" macro-insns,
1060 where "simple" is currently defined to mean "expands to one real insn".
1062 Simple macro-insns are handled specially. They are emitted as ALIAS's
1063 of real insns. This simplifies their handling since there's usually more
1064 of them than any other kind of macro-insn, and proper disassembly of them
1065 falls out for free. */
1067 /* For each macro-insn there may be multiple expansion possibilities,
1068 depending on the arguments. This structure is accessed via the `data'
1069 member of CGEN_INSN. */
1071 typedef struct cgen_minsn_expansion {
1072 /* Function to do the expansion.
1073 If the expansion fails (e.g. "no match") NULL is returned.
1074 Space for the expansion is obtained with malloc.
1075 It is up to the caller to free it. */
1076 const char * (* fn) PARAMS ((const struct cgen_minsn_expansion *,
1077 const char *, const char **, int *,
1079 #define CGEN_MIEXPN_FN(ex) ((ex)->fn)
1081 /* Instruction(s) the macro expands to.
1082 The format of STR is defined by FN.
1083 It is typically the assembly code of the real insn, but it could also be
1084 the original Scheme expression or a tokenized form of it (with FN being
1085 an appropriate interpreter). */
1087 #define CGEN_MIEXPN_STR(ex) ((ex)->str)
1088 } CGEN_MINSN_EXPANSION;
1091 When supported, this function will convert the input string to another
1092 string and the parser will be invoked recursively. The output string
1093 may contain further macro invocations. */
1095 extern const char * cgen_expand_macro_insn
1096 PARAMS ((CGEN_CPU_DESC, const struct cgen_minsn_expansion *,
1097 const char *, const char **, int *, CGEN_OPERAND **));
1099 /* The assembler insn table is hashed based on some function of the mnemonic
1100 (the actually hashing done is up to the target, but we provide a few
1101 examples like the first letter or a function of the entire mnemonic). */
1103 extern CGEN_INSN_LIST * cgen_asm_lookup_insn
1104 PARAMS ((CGEN_CPU_DESC, const char *));
1105 #define CGEN_ASM_LOOKUP_INSN(cd, string) cgen_asm_lookup_insn ((cd), (string))
1106 #define CGEN_ASM_NEXT_INSN(insn) ((insn)->next)
1108 /* The disassembler insn table is hashed based on some function of machine
1109 instruction (the actually hashing done is up to the target). */
1111 extern CGEN_INSN_LIST * cgen_dis_lookup_insn
1112 PARAMS ((CGEN_CPU_DESC, const char *, CGEN_INSN_INT));
1113 /* FIXME: delete these two */
1114 #define CGEN_DIS_LOOKUP_INSN(cd, buf, value) cgen_dis_lookup_insn ((cd), (buf), (value))
1115 #define CGEN_DIS_NEXT_INSN(insn) ((insn)->next)
1117 /* The CPU description.
1118 A copy of this is created when the cpu table is "opened".
1119 All global state information is recorded here.
1120 Access macros are provided for "public" members. */
1122 typedef struct cgen_cpu_desc
1124 /* Bitmap of selected machine(s) (a la BFD machine number). */
1127 /* Bitmap of selected isa(s).
1128 ??? Simultaneous multiple isas might not make sense, but it's not (yet)
1132 /* Current endian. */
1133 enum cgen_endian endian;
1134 #define CGEN_CPU_ENDIAN(cd) ((cd)->endian)
1136 /* Current insn endian. */
1137 enum cgen_endian insn_endian;
1138 #define CGEN_CPU_INSN_ENDIAN(cd) ((cd)->insn_endian)
1140 /* Word size (in bits). */
1141 /* ??? Or maybe maximum word size - might we ever need to allow a cpu table
1142 to be opened for both sparc32/sparc64?
1143 ??? Another alternative is to create a table of selected machs and
1144 lazily fetch the data from there. */
1145 unsigned int word_bitsize;
1147 /* Indicator if sizes are unknown.
1148 This is used by default_insn_bitsize,base_insn_bitsize if there is a
1149 difference between the selected isa's. */
1150 #define CGEN_SIZE_UNKNOWN 65535
1152 /* Default instruction size (in bits).
1153 This is used by the assembler when it encounters an unknown insn. */
1154 unsigned int default_insn_bitsize;
1156 /* Base instruction size (in bits).
1157 For non-LIW cpus this is generally the length of the smallest insn.
1158 For LIW cpus its wip (work-in-progress). For the m32r its 32. */
1159 unsigned int base_insn_bitsize;
1161 /* Minimum/maximum instruction size (in bits). */
1162 unsigned int min_insn_bitsize;
1163 unsigned int max_insn_bitsize;
1165 /* Instruction set variants. */
1166 const CGEN_ISA *isa_table;
1168 /* Machine variants. */
1169 const CGEN_MACH *mach_table;
1171 /* Hardware elements. */
1172 CGEN_HW_TABLE hw_table;
1174 /* Instruction fields. */
1175 const CGEN_IFLD *ifld_table;
1178 CGEN_OPERAND_TABLE operand_table;
1180 /* Main instruction table. */
1181 CGEN_INSN_TABLE insn_table;
1182 #define CGEN_CPU_INSN_TABLE(cd) (& (cd)->insn_table)
1184 /* Macro instructions are defined separately and are combined with real
1185 insns during hash table computation. */
1186 CGEN_INSN_TABLE macro_insn_table;
1188 /* Copy of CGEN_INT_INSN_P. */
1191 /* Called to rebuild the tables after something has changed. */
1192 void (*rebuild_tables) PARAMS ((CGEN_CPU_DESC));
1194 /* Operand parser callback. */
1195 cgen_parse_operand_fn * parse_operand_fn;
1197 /* Parse/insert/extract/print cover fns for operands. */
1198 const char * (*parse_operand)
1199 PARAMS ((CGEN_CPU_DESC, int opindex_, const char **,
1200 CGEN_FIELDS *fields_));
1202 const char * (*insert_operand)
1203 PARAMS ((CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_,
1204 CGEN_INSN_BYTES_PTR, bfd_vma pc_));
1205 int (*extract_operand)
1206 PARAMS ((CGEN_CPU_DESC, int opindex_, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
1207 CGEN_FIELDS *fields_, bfd_vma pc_));
1208 void (*print_operand)
1209 PARAMS ((CGEN_CPU_DESC, int opindex_, PTR info_, CGEN_FIELDS * fields_,
1210 void const *attrs_, bfd_vma pc_, int length_));
1212 const char * (*insert_operand) ();
1213 int (*extract_operand) ();
1214 void (*print_operand) ();
1216 #define CGEN_CPU_PARSE_OPERAND(cd) ((cd)->parse_operand)
1217 #define CGEN_CPU_INSERT_OPERAND(cd) ((cd)->insert_operand)
1218 #define CGEN_CPU_EXTRACT_OPERAND(cd) ((cd)->extract_operand)
1219 #define CGEN_CPU_PRINT_OPERAND(cd) ((cd)->print_operand)
1221 /* Size of CGEN_FIELDS struct. */
1222 unsigned int sizeof_fields;
1223 #define CGEN_CPU_SIZEOF_FIELDS(cd) ((cd)->sizeof_fields)
1225 /* Set the bitsize field. */
1226 void (*set_fields_bitsize) PARAMS ((CGEN_FIELDS *fields_, int size_));
1227 #define CGEN_CPU_SET_FIELDS_BITSIZE(cd) ((cd)->set_fields_bitsize)
1229 /* CGEN_FIELDS accessors. */
1230 int (*get_int_operand)
1231 PARAMS ((CGEN_CPU_DESC, int opindex_, const CGEN_FIELDS *fields_));
1232 void (*set_int_operand)
1233 PARAMS ((CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, int value_));
1235 bfd_vma (*get_vma_operand)
1236 PARAMS ((CGEN_CPU_DESC, int opindex_, const CGEN_FIELDS *fields_));
1237 void (*set_vma_operand)
1238 PARAMS ((CGEN_CPU_DESC, int opindex_, CGEN_FIELDS *fields_, bfd_vma value_));
1240 long (*get_vma_operand) ();
1241 void (*set_vma_operand) ();
1243 #define CGEN_CPU_GET_INT_OPERAND(cd) ((cd)->get_int_operand)
1244 #define CGEN_CPU_SET_INT_OPERAND(cd) ((cd)->set_int_operand)
1245 #define CGEN_CPU_GET_VMA_OPERAND(cd) ((cd)->get_vma_operand)
1246 #define CGEN_CPU_SET_VMA_OPERAND(cd) ((cd)->set_vma_operand)
1248 /* Instruction parse/insert/extract/print handlers. */
1249 /* FIXME: make these types uppercase. */
1250 cgen_parse_fn * const *parse_handlers;
1251 cgen_insert_fn * const *insert_handlers;
1252 cgen_extract_fn * const *extract_handlers;
1253 cgen_print_fn * const *print_handlers;
1254 #define CGEN_PARSE_FN(cd, insn) (cd->parse_handlers[(insn)->opcode->handlers.parse])
1255 #define CGEN_INSERT_FN(cd, insn) (cd->insert_handlers[(insn)->opcode->handlers.insert])
1256 #define CGEN_EXTRACT_FN(cd, insn) (cd->extract_handlers[(insn)->opcode->handlers.extract])
1257 #define CGEN_PRINT_FN(cd, insn) (cd->print_handlers[(insn)->opcode->handlers.print])
1259 /* Return non-zero if insn should be added to hash table. */
1260 int (* asm_hash_p) PARAMS ((const CGEN_INSN *));
1262 /* Assembler hash function. */
1263 unsigned int (* asm_hash) PARAMS ((const char *));
1265 /* Number of entries in assembler hash table. */
1266 unsigned int asm_hash_size;
1268 /* Return non-zero if insn should be added to hash table. */
1269 int (* dis_hash_p) PARAMS ((const CGEN_INSN *));
1271 /* Disassembler hash function. */
1272 unsigned int (* dis_hash) PARAMS ((const char *, CGEN_INSN_INT));
1274 /* Number of entries in disassembler hash table. */
1275 unsigned int dis_hash_size;
1277 /* Assembler instruction hash table. */
1278 CGEN_INSN_LIST **asm_hash_table;
1279 CGEN_INSN_LIST *asm_hash_table_entries;
1281 /* Disassembler instruction hash table. */
1282 CGEN_INSN_LIST **dis_hash_table;
1283 CGEN_INSN_LIST *dis_hash_table_entries;
1287 #ifndef CGEN_WORD_ENDIAN
1288 #define CGEN_WORD_ENDIAN(cd) CGEN_CPU_ENDIAN (cd)
1290 #ifndef CGEN_INSN_WORD_ENDIAN
1291 #define CGEN_INSN_WORD_ENDIAN(cd) CGEN_CPU_INSN_ENDIAN (cd)
1294 /* Prototypes of major functions. */
1295 /* FIXME: Move more CGEN_SYM-defined functions into CGEN_CPU_DESC.
1296 Not the init fns though, as that would drag in things that mightn't be
1297 used and might not even exist. */
1299 /* Argument types to cpu_open. */
1301 enum cgen_cpu_open_arg {
1303 /* Select instruction set(s), arg is bitmap or 0 meaning "unspecified". */
1305 /* Select machine(s), arg is bitmap or 0 meaning "unspecified". */
1306 CGEN_CPU_OPEN_MACHS,
1307 /* Select machine, arg is mach's bfd name.
1308 Multiple machines can be specified by repeated use. */
1309 CGEN_CPU_OPEN_BFDMACH,
1310 /* Select endian, arg is CGEN_ENDIAN_*. */
1311 CGEN_CPU_OPEN_ENDIAN
1314 /* Open a cpu descriptor table for use.
1315 ??? We only support ISO C stdargs here, not K&R.
1316 Laziness, plus experiment to see if anything requires K&R - eventually
1317 K&R will no longer be supported - e.g. GDB is currently trying this. */
1319 extern CGEN_CPU_DESC CGEN_SYM (cpu_open) (enum cgen_cpu_open_arg, ...);
1321 /* Cover fn to handle simple case. */
1323 extern CGEN_CPU_DESC CGEN_SYM (cpu_open_1) PARAMS ((const char *mach_name_,
1324 enum cgen_endian endian_));
1328 extern void CGEN_SYM (cpu_close) PARAMS ((CGEN_CPU_DESC));
1330 /* Initialize the opcode table for use.
1331 Called by init_asm/init_dis. */
1333 extern void CGEN_SYM (init_opcode_table) PARAMS ((CGEN_CPU_DESC cd_));
1335 /* Initialize the ibld table for use.
1336 Called by init_asm/init_dis. */
1338 extern void CGEN_SYM (init_ibld_table) PARAMS ((CGEN_CPU_DESC cd_));
1340 /* Initialize an cpu table for assembler or disassembler use.
1341 These must be called immediately after cpu_open. */
1343 extern void CGEN_SYM (init_asm) PARAMS ((CGEN_CPU_DESC));
1344 extern void CGEN_SYM (init_dis) PARAMS ((CGEN_CPU_DESC));
1346 /* Initialize the operand instance table for use. */
1348 extern void CGEN_SYM (init_opinst_table) PARAMS ((CGEN_CPU_DESC cd_));
1350 /* Assemble an instruction. */
1352 extern const CGEN_INSN * CGEN_SYM (assemble_insn)
1353 PARAMS ((CGEN_CPU_DESC, const char *, CGEN_FIELDS *,
1354 CGEN_INSN_BYTES_PTR, char **));
1356 extern const CGEN_KEYWORD CGEN_SYM (operand_mach);
1357 extern int CGEN_SYM (get_mach) PARAMS ((const char *));
1359 /* Operand index computation. */
1360 extern const CGEN_INSN * cgen_lookup_insn
1361 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN * insn_,
1362 CGEN_INSN_INT int_value_, unsigned char *bytes_value_,
1363 int length_, CGEN_FIELDS *fields_, int alias_p_));
1364 extern void cgen_get_insn_operands
1365 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN * insn_,
1366 const CGEN_FIELDS *fields_, int *indices_));
1367 extern const CGEN_INSN * cgen_lookup_get_insn_operands
1368 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *insn_,
1369 CGEN_INSN_INT int_value_, unsigned char *bytes_value_,
1370 int length_, int *indices_, CGEN_FIELDS *fields_));
1372 /* Cover fns to bfd_get/set. */
1374 extern CGEN_INSN_INT cgen_get_insn_value
1375 PARAMS ((CGEN_CPU_DESC, unsigned char *, int));
1376 extern void cgen_put_insn_value
1377 PARAMS ((CGEN_CPU_DESC, unsigned char *, int, CGEN_INSN_INT));
1379 /* Read in a cpu description file.
1380 ??? For future concerns, including adding instructions to the assembler/
1381 disassembler at run-time. */
1383 extern const char * cgen_read_cpu_file
1384 PARAMS ((CGEN_CPU_DESC, const char * filename_));