1 /* Header file for targets using CGEN: Cpu tools GENerator.
3 Copyright (C) 1996, 1997, 1998 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 /* Version information. */
25 #define CGEN_VERSION_MAJOR 0
26 #define CGEN_VERSION_MINOR 6
27 #define CGEN_VERSION_FIXLEVEL 0
29 /* Prepend the arch name, defined in <arch>-opc.h, and _cgen_ to symbol S.
30 The lack of spaces in the arg list is important for non-stdc systems.
31 This file is included by <arch>-opc.h.
32 It can be included independently of <arch>-opc.h, in which case the arch
33 dependent portions will be declared as "unknown_cgen_foo". */
36 #define CGEN_SYM(s) CONCAT3 (unknown,_cgen_,s)
39 /* This file contains the static (unchanging) pieces and as much other stuff
40 as we can reasonably put here. It's generally cleaner to put stuff here
41 rather than having it machine generated if possible. */
43 /* The assembler syntax is made up of expressions (duh...).
44 At the lowest level the values are mnemonics, register names, numbers, etc.
45 Above that are subexpressions, if any (an example might be the
46 "effective address" in m68k cpus). At the second highest level are the
47 insns themselves. Above that are pseudo-insns, synthetic insns, and macros,
51 /* Lots of cpu's have a fixed insn size, or one which rarely changes,
52 and it's generally easier to handle these by treating the insn as an
53 integer type, rather than an array of characters. So we allow targets
57 typedef unsigned int cgen_insn_t;
59 typedef char * cgen_insn_t;
63 #define CGEN_INLINE inline
76 typedef struct cgen_insn CGEN_INSN;
79 Attributes are used to describe various random things. */
81 /* Struct to record attribute information. */
84 unsigned char num_nonbools;
86 unsigned int nonbool[1];
89 /* Define a structure member for attributes with N non-boolean entries.
90 The attributes are sorted so that the non-boolean ones come first.
91 num_nonbools: count of nonboolean attributes
92 bool: values of boolean attributes
93 nonbool: values of non-boolean attributes
94 There is a maximum of 32 attributes total. */
95 #define CGEN_ATTR_TYPE(n) \
96 struct { unsigned char num_nonbools; \
98 unsigned int nonbool[(n) ? (n) : 1]; }
100 /* Given an attribute number, return its mask. */
101 #define CGEN_ATTR_MASK(attr) (1 << (attr))
103 /* Return the value of boolean attribute ATTR in ATTRS. */
104 #define CGEN_BOOL_ATTR(attrs, attr) \
105 ((CGEN_ATTR_MASK (attr) & (attrs)) != 0)
107 /* Return value of attribute ATTR in ATTR_TABLE for OBJ.
108 OBJ is a pointer to the entity that has the attributes.
109 It's not used at present but is reserved for future purposes. */
110 #define CGEN_ATTR_VALUE(obj, attr_table, attr) \
111 ((unsigned int) (attr) < (attr_table)->num_nonbools \
112 ? ((attr_table)->nonbool[attr]) \
113 : (((attr_table)->bool & (1 << (attr))) != 0))
115 /* Attribute name/value tables.
116 These are used to assist parsing of descriptions at runtime. */
124 /* For each domain (ifld,operand,insn), list of attributes. */
129 /* NULL for boolean attributes. */
130 const CGEN_ATTR_ENTRY * vals;
133 /* Parse result (also extraction result).
135 The result of parsing an insn is stored here.
136 To generate the actual insn, this is passed to the insert handler.
137 When printing an insn, the result of extraction is stored here.
138 To print the insn, this is passed to the print handler.
140 It is machine generated so we don't define it here,
141 but we do need a forward decl for the handler fns.
143 There is one member for each possible field in the insn.
144 The type depends on the field.
145 Also recorded here is the computed length of the insn for architectures
149 typedef struct cgen_fields CGEN_FIELDS;
151 /* Total length of the insn, as recorded in the `fields' struct. */
152 /* ??? The field insert handler has lots of opportunities for optimization
153 if it ever gets inlined. On architectures where insns all have the same
154 size, may wish to detect that and make this macro a constant - to allow
155 further optimizations. */
156 #define CGEN_FIELDS_BITSIZE(fields) ((fields)->length)
158 /* Associated with each insn or expression is a set of "handlers" for
159 performing operations like parsing, printing, etc. These require a bfd_vma
160 value to be passed around but we don't want all applications to need bfd.h.
161 So this stuff is only provided if bfd.h has been included. */
166 The first argument is a pointer to a struct describing the insn being
168 The second argument is a pointer to a pointer to the text being parsed.
169 The third argument is a pointer to a cgen_fields struct
170 in which the results are placed.
171 If the expression is successfully parsed, the pointer to the text is
172 updated. If not it is left alone.
173 The result is NULL if success or an error message. */
174 typedef const char * (cgen_parse_fn) PARAMS ((const struct cgen_insn *,
179 The first argument is a pointer to the disassembly info.
180 Eg: disassemble_info. It's defined as `PTR' so this file can be included
182 The second argument is a pointer to a struct describing the insn being
184 The third argument is a pointer to a cgen_fields struct.
185 The fourth argument is the pc value of the insn.
186 The fifth argument is the length of the insn, in bytes. */
187 typedef void (cgen_print_fn) PARAMS ((PTR, const struct cgen_insn *,
188 CGEN_FIELDS *, bfd_vma, int));
191 The first argument is a pointer to a struct describing the insn being
193 The second argument is a pointer to a cgen_fields struct
194 from which the values are fetched.
195 The third argument is a pointer to a buffer in which to place the insn.
196 The fourth argument is the pc value of the insn.
197 The result is an error message or NULL if success. */
198 typedef const char * (cgen_insert_fn) PARAMS ((const struct cgen_insn *,
199 CGEN_FIELDS *, cgen_insn_t *,
203 The first argument is a pointer to a struct describing the insn being
205 The second argument is a pointer to a struct controlling extraction
206 (only used for variable length insns).
207 The third argument is the first CGEN_BASE_INSN_SIZE bytes.
208 The fourth argument is a pointer to a cgen_fields struct
209 in which the results are placed.
210 The fifth argument is the pc value of the insn.
211 The result is the length of the insn or zero if not recognized. */
212 typedef int (cgen_extract_fn) PARAMS ((const struct cgen_insn *,
214 CGEN_FIELDS *, bfd_vma));
216 /* The `parse' and `insert' fields are indices into these tables.
217 The elements are pointer to specialized handler functions.
218 Element 0 is special, it means use the default handler. */
219 extern cgen_parse_fn * CGEN_SYM (parse_handlers) [];
220 #define CGEN_PARSE_FN(x) (CGEN_SYM (parse_handlers)[(x)->base.parse])
221 extern cgen_insert_fn * CGEN_SYM (insert_handlers) [];
222 #define CGEN_INSERT_FN(x) (CGEN_SYM (insert_handlers)[(x)->base.insert])
224 /* Likewise for the `extract' and `print' fields. */
225 extern cgen_extract_fn * CGEN_SYM (extract_handlers) [];
226 #define CGEN_EXTRACT_FN(x) (CGEN_SYM (extract_handlers)[(x)->base.extract])
227 extern cgen_print_fn * CGEN_SYM (print_handlers) [];
228 #define CGEN_PRINT_FN(x) (CGEN_SYM (print_handlers)[(x)->base.print])
230 /* Default insn parser, printer. */
231 extern cgen_parse_fn CGEN_SYM (parse_insn);
232 extern cgen_insert_fn CGEN_SYM (insert_insn);
233 extern cgen_extract_fn CGEN_SYM (extract_insn);
234 extern cgen_print_fn CGEN_SYM (print_insn);
236 #endif /* BFD_VERSION */
238 /* Base class of parser/printer.
239 (Don't read too much into the use of the phrase "base class".
240 It's a name I'm using to organize my thoughts.)
242 Instructions and expressions all share this data in common.
243 It's a collection of the common elements needed to parse, insert, extract,
244 and print each of them. */
248 /* Indices into the handler tables.
249 We could use pointers here instead, but in the case of the insn table,
250 90% of them would be identical and that's a lot of redundant data.
251 0 means use the default (what the default is is up to the code).
252 Using indices also keeps assembler code out of the disassembler and
254 unsigned char parse, insert, extract, print;
257 /* Assembler interface.
259 The interface to the assembler is intended to be clean in the sense that
260 libopcodes.a is a standalone entity and could be used with any assembler.
261 Not that one would necessarily want to do that but rather that it helps
262 keep a clean interface. The interface will obviously be slanted towards
263 GAS, but at least it's a start.
264 ??? Note that one possible use of the assembler besides GAS is GDB.
266 Parsing is controlled by the assembler which calls
267 CGEN_SYM (assemble_insn). If it can parse and build the entire insn
268 it doesn't call back to the assembler. If it needs/wants to call back
269 to the assembler, (*cgen_parse_operand_fn) is called which can either
271 - return a number to be inserted in the insn
272 - return a "register" value to be inserted
273 (the register might not be a register per pe)
274 - queue the argument and return a marker saying the expression has been
275 queued (eg: a fix-up)
276 - return an error message indicating the expression wasn't recognizable
278 The result is an error message or NULL for success.
279 The parsed value is stored in the bfd_vma *. */
281 /* Values for indicating what the caller wants. */
282 enum cgen_parse_operand_type
284 CGEN_PARSE_OPERAND_INIT,
285 CGEN_PARSE_OPERAND_INTEGER,
286 CGEN_PARSE_OPERAND_ADDRESS
289 /* Values for indicating what was parsed. */
290 enum cgen_parse_operand_result
292 CGEN_PARSE_OPERAND_RESULT_NUMBER,
293 CGEN_PARSE_OPERAND_RESULT_REGISTER,
294 CGEN_PARSE_OPERAND_RESULT_QUEUED,
295 CGEN_PARSE_OPERAND_RESULT_ERROR
298 #ifdef BFD_VERSION /* Don't require bfd.h unnecessarily. */
299 extern const char * (*cgen_parse_operand_fn)
300 PARAMS ((enum cgen_parse_operand_type, const char **, int, int,
301 enum cgen_parse_operand_result *, bfd_vma *));
304 /* Called before trying to match a table entry with the insn. */
305 extern void cgen_init_parse_operand PARAMS ((void));
307 /* The result is an error message or NULL for success.
308 The parsed value is stored in the bfd_vma *. */
309 #ifdef BFD_VERSION /* Don't require bfd.h unnecessarily. */
310 extern const char * cgen_parse_operand
311 PARAMS ((enum cgen_parse_operand_type,
312 const char **, int, int,
313 enum cgen_parse_operand_result *,
317 /* Operand values (keywords, integers, symbols, etc.) */
319 /* Types of assembler elements. */
323 CGEN_ASM_KEYWORD, CGEN_ASM_MAX
326 /* List of hardware elements. */
328 typedef struct cgen_hw_entry
330 /* The type of this entry, one of `enum hw_type'.
331 This is an int and not the enum as the latter may not be declared yet. */
333 const struct cgen_hw_entry * next;
335 enum cgen_asm_type asm_type;
339 extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_name PARAMS ((const char *));
340 extern const CGEN_HW_ENTRY * cgen_hw_lookup_by_num PARAMS ((int));
342 /* This struct is used to describe things like register names, etc. */
344 typedef struct cgen_keyword_entry
346 /* Name (as in register name). */
349 /* Value (as in register number).
350 The value cannot be -1 as that is used to indicate "not found".
351 IDEA: Have "FUNCTION" attribute? [function is called to fetch value]. */
355 This should, but technically needn't, appear last. It is a variable sized
356 array in that one architecture may have 1 nonbool attribute and another
357 may have more. Having this last means the non-architecture specific code
359 /* ??? Moving this last should be done by treating keywords like insn lists
360 and moving the `next' fields into a CGEN_KEYWORD_LIST struct. */
361 /* FIXME: Not used yet. */
362 #ifndef CGEN_KEYWORD_NBOOL_ATTRS
363 #define CGEN_KEYWORD_NBOOL_ATTRS 1
365 const CGEN_ATTR_TYPE (CGEN_KEYWORD_NBOOL_ATTRS) attrs;
367 /* Next name hash table entry. */
368 struct cgen_keyword_entry *next_name;
369 /* Next value hash table entry. */
370 struct cgen_keyword_entry *next_value;
371 } CGEN_KEYWORD_ENTRY;
373 /* Top level struct for describing a set of related keywords
374 (e.g. register names).
376 This struct supports runtime entry of new values, and hashed lookups. */
378 typedef struct cgen_keyword
380 /* Pointer to initial [compiled in] values. */
381 CGEN_KEYWORD_ENTRY * init_entries;
383 /* Number of entries in `init_entries'. */
384 unsigned int num_init_entries;
386 /* Hash table used for name lookup. */
387 CGEN_KEYWORD_ENTRY ** name_hash_table;
389 /* Hash table used for value lookup. */
390 CGEN_KEYWORD_ENTRY ** value_hash_table;
392 /* Number of entries in the hash_tables. */
393 unsigned int hash_table_size;
395 /* Pointer to null keyword "" entry if present. */
396 const CGEN_KEYWORD_ENTRY * null_entry;
399 /* Structure used for searching. */
403 /* Table being searched. */
404 const CGEN_KEYWORD * table;
406 /* Specification of what is being searched for. */
409 /* Current index in hash table. */
410 unsigned int current_hash;
412 /* Current element in current hash chain. */
413 CGEN_KEYWORD_ENTRY * current_entry;
414 } CGEN_KEYWORD_SEARCH;
416 /* Lookup a keyword from its name. */
417 const CGEN_KEYWORD_ENTRY * cgen_keyword_lookup_name
418 PARAMS ((CGEN_KEYWORD *, const char *));
419 /* Lookup a keyword from its value. */
420 const CGEN_KEYWORD_ENTRY * cgen_keyword_lookup_value
421 PARAMS ((CGEN_KEYWORD *, int));
423 void cgen_keyword_add PARAMS ((CGEN_KEYWORD *, CGEN_KEYWORD_ENTRY *));
424 /* Keyword searching.
425 This can be used to retrieve every keyword, or a subset. */
426 CGEN_KEYWORD_SEARCH cgen_keyword_search_init
427 PARAMS ((CGEN_KEYWORD *, const char *));
428 const CGEN_KEYWORD_ENTRY *cgen_keyword_search_next
429 PARAMS ((CGEN_KEYWORD_SEARCH *));
431 /* Operand value support routines. */
432 /* FIXME: some of the long's here will need to be bfd_vma or some such. */
434 extern const char * cgen_parse_keyword PARAMS ((const char **,
437 extern const char * cgen_parse_signed_integer PARAMS ((const char **, int,
439 extern const char * cgen_parse_unsigned_integer PARAMS ((const char **, int,
441 extern const char * cgen_parse_address PARAMS ((const char **, int, int,
442 enum cgen_parse_operand_result *,
444 extern const char * cgen_validate_signed_integer PARAMS ((long, long, long));
445 extern const char * cgen_validate_unsigned_integer PARAMS ((unsigned long,
451 /* ??? This duplicates the values in arch.h. Revisit.
452 These however need the CGEN_ prefix [as does everything in this file]. */
453 /* ??? Targets may need to add their own modes so we may wish to move this
454 to <arch>-opc.h, or add a hook. */
457 CGEN_MODE_VOID, /* FIXME: rename simulator's VM to VOID */
458 CGEN_MODE_BI, CGEN_MODE_QI, CGEN_MODE_HI, CGEN_MODE_SI, CGEN_MODE_DI,
459 CGEN_MODE_UBI, CGEN_MODE_UQI, CGEN_MODE_UHI, CGEN_MODE_USI, CGEN_MODE_UDI,
460 CGEN_MODE_SF, CGEN_MODE_DF, CGEN_MODE_XF, CGEN_MODE_TF,
464 /* FIXME: Until simulator is updated. */
465 #define CGEN_MODE_VM CGEN_MODE_VOID
467 /* This struct defines each entry in the operand table. */
469 typedef struct cgen_operand
471 /* Name as it appears in the syntax string. */
474 /* The hardware element associated with this operand. */
475 const CGEN_HW_ENTRY *hw;
477 /* FIXME: We don't yet record ifield definitions, which we should.
478 When we do it might make sense to delete start/length (since they will
479 be duplicated in the ifield's definition) and replace them with a
480 pointer to the ifield entry. Note that as more complicated situations
481 need to be handled, going more and more with an OOP paradigm will help
482 keep the complication under control. Of course, this was the goal from
483 the start, but getting there in one step was too much too soon. */
485 /* Bit position (msb of first byte = bit 0).
486 This is just a hint, and may be unused in more complex operands.
487 May be unused for a modifier. */
490 /* The number of bits in the operand.
491 This is just a hint, and may be unused in more complex operands.
492 May be unused for a modifier. */
493 unsigned char length;
495 #if 0 /* ??? Interesting idea but relocs tend to get too complicated,
496 and ABI dependent, for simple table lookups to work. */
497 /* Ideally this would be the internal (external?) reloc type. */
502 This should, but technically needn't, appear last. It is a variable sized
503 array in that one architecture may have 1 nonbool attribute and another
504 may have more. Having this last means the non-architecture specific code
505 needn't care, now or tomorrow. */
506 #ifndef CGEN_OPERAND_NBOOL_ATTRS
507 #define CGEN_OPERAND_NBOOL_ATTRS 1
509 const CGEN_ATTR_TYPE (CGEN_OPERAND_NBOOL_ATTRS) attrs;
510 #define CGEN_OPERAND_ATTRS(operand) (&(operand)->attrs)
513 /* Return value of attribute ATTR in OPERAND. */
514 #define CGEN_OPERAND_ATTR(operand, attr) \
515 CGEN_ATTR_VALUE (operand, CGEN_OPERAND_ATTRS (operand), attr)
517 /* The operand table is currently a very static entity. */
518 extern const CGEN_OPERAND CGEN_SYM (operand_table)[];
520 enum cgen_operand_type;
522 #define CGEN_OPERAND_INDEX(operand) ((int) ((operand) - CGEN_SYM (operand_table)))
523 /* FIXME: Rename, cpu-opc.h defines this as the typedef of the enum. */
524 #define CGEN_OPERAND_TYPE(operand) ((enum cgen_operand_type) CGEN_OPERAND_INDEX (operand))
525 #define CGEN_OPERAND_ENTRY(n) (& CGEN_SYM (operand_table) [n])
527 /* Types of parse/insert/extract/print cover-fn handlers. */
528 /* FIXME: move opindex first to match caller. */
529 /* FIXME: also need types of insert/extract/print fns. */
530 /* FIXME: not currently used as type of 3rd arg varies. */
531 typedef const char * (CGEN_PARSE_OPERAND_FN) PARAMS ((const char **, int,
534 /* Instruction operand instances.
536 For each instruction, a list of the hardware elements that are read and
537 written are recorded. */
539 /* The type of the instance. */
540 enum cgen_operand_instance_type {
541 /* End of table marker. */
542 CGEN_OPERAND_INSTANCE_END = 0,
543 CGEN_OPERAND_INSTANCE_INPUT, CGEN_OPERAND_INSTANCE_OUTPUT
548 /* The type of this operand. */
549 enum cgen_operand_instance_type type;
550 #define CGEN_OPERAND_INSTANCE_TYPE(opinst) ((opinst)->type)
552 /* The hardware element referenced. */
553 const CGEN_HW_ENTRY *hw;
554 #define CGEN_OPERAND_INSTANCE_HW(opinst) ((opinst)->hw)
556 /* The mode in which the operand is being used. */
558 #define CGEN_OPERAND_INSTANCE_MODE(opinst) ((opinst)->mode)
560 /* The operand table entry or NULL if there is none (i.e. an explicit
561 hardware reference). */
562 const CGEN_OPERAND *operand;
563 #define CGEN_OPERAND_INSTANCE_OPERAND(opinst) ((opinst)->operand)
565 /* If `operand' is NULL, the index (e.g. into array of registers). */
567 #define CGEN_OPERAND_INSTANCE_INDEX(opinst) ((opinst)->index)
568 } CGEN_OPERAND_INSTANCE;
572 Each insn format and subexpression has one of these.
574 The syntax "string" consists of characters (n > 0 && n < 128), and operand
575 values (n >= 128), and is terminated by 0. Operand values are 128 + index
576 into the operand table. The operand table doesn't exist in C, per se, as
577 the data is recorded in the parse/insert/extract/print switch statements. */
579 #ifndef CGEN_MAX_SYNTAX_BYTES
580 #define CGEN_MAX_SYNTAX_BYTES 16
585 unsigned char syntax[CGEN_MAX_SYNTAX_BYTES];
588 #define CGEN_SYNTAX_STRING(syn) (syn->syntax)
589 #define CGEN_SYNTAX_CHAR_P(c) ((c) < 128)
590 #define CGEN_SYNTAX_CHAR(c) (c)
591 #define CGEN_SYNTAX_FIELD(c) ((c) - 128)
592 #define CGEN_SYNTAX_MAKE_FIELD(c) ((c) + 128)
594 /* ??? I can't currently think of any case where the mnemonic doesn't come
595 first [and if one ever doesn't building the hash tables will be tricky].
596 However, we treat mnemonics as just another operand of the instruction.
597 A value of 1 means "this is where the mnemonic appears". 1 isn't
598 special other than it's a non-printable ASCII char. */
599 #define CGEN_SYNTAX_MNEMONIC 1
600 #define CGEN_SYNTAX_MNEMONIC_P(ch) ((ch) == CGEN_SYNTAX_MNEMONIC)
602 /* Instruction formats.
604 Instructions are grouped by format. Associated with an instruction is its
605 format. Each opcode table entry contains a format table entry.
606 ??? There is usually very few formats compared with the number of insns,
607 so one can reduce the size of the opcode table by recording the format table
608 as a separate entity. Given that we currently don't, format table entries
609 are also distinguished by their operands. This increases the size of the
610 table, but reduces the number of tables. It's all minutiae anyway so it
611 doesn't really matter [at this point in time].
613 ??? Support for variable length ISA's is wip. */
617 /* Length that MASK and VALUE have been calculated to
618 [VALUE is recorded elsewhere].
619 Normally it is CGEN_BASE_INSN_BITSIZE. On [V]LIW architectures where
620 the base insn size may be larger than the size of an insn, this field is
621 less than CGEN_BASE_INSN_BITSIZE. */
622 unsigned char mask_length;
624 /* Total length of instruction, in bits. */
625 unsigned char length;
627 /* Mask to apply to the first MASK_LENGTH bits.
628 Each insn's value is stored with the insn.
629 The first step in recognizing an insn for disassembly is
630 (opcode & mask) == value. */
634 /* This struct defines each entry in the instruction table. */
638 /* This field is an array of functions that operand on this entry. */
639 struct cgen_base base;
640 #define CGEN_INSN_BASE(insn) (&(insn)->base)
642 /* Each real instruction is enumerated.
643 The simulator use to use this value but currently no longer does.
644 This may go away in time. */
646 #define CGEN_INSN_NUM(insn) ((insn)->num)
648 /* Name of entry (that distinguishes it from all other entries).
649 This is used, for example, in simulator profiling results. */
650 /* ??? If mnemonics have operands, try to print full mnemonic. */
652 #define CGEN_INSN_NAME(insn) ((insn)->name)
654 /* Mnemonic. This is used when parsing and printing the insn.
655 In the case of insns that have operands on the mnemonics, this is
656 only the constant part. E.g. for conditional execution of an `add' insn,
657 where the full mnemonic is addeq, addne, etc., this is only "add". */
658 const char * mnemonic;
659 #define CGEN_INSN_MNEMONIC(insn) ((insn)->mnemonic)
662 const CGEN_SYNTAX syntax;
663 #define CGEN_INSN_SYNTAX(insn) (& (insn)->syntax)
666 const CGEN_FORMAT format;
667 #define CGEN_INSN_MASK_BITSIZE(insn) ((insn)->format.mask_length)
668 #define CGEN_INSN_BITSIZE(insn) ((insn)->format.length)
670 /* Instruction opcode value. */
672 #define CGEN_INSN_VALUE(insn) ((insn)->value)
673 #define CGEN_INSN_MASK(insn) ((insn)->format.mask)
675 /* Opaque pointer to "subclass" specific data.
676 In the case of real insns this points to a NULL entry terminated
677 table of operands used, or NULL if none.
678 In the case of macro insns this points to data to control the expansion.
679 ??? I'd rather not get carried away and lay things out with pedantic
680 purity right now. Sure, other fields might better be tucked away in
683 #define CGEN_INSN_DATA(insn) ((insn)->data)
684 #define CGEN_INSN_OPERANDS(insn) ((CGEN_OPERAND_INSTANCE *) (insn)->data)
687 This must appear last. It is a variable sized array in that one
688 architecture may have 1 nonbool attribute and another may have more.
689 Having this last means the non-architecture specific code needn't
691 #ifndef CGEN_INSN_NBOOL_ATTRS
692 #define CGEN_INSN_NBOOL_ATTRS 1
694 const CGEN_ATTR_TYPE (CGEN_INSN_NBOOL_ATTRS) attrs;
695 #define CGEN_INSN_ATTRS(insn) (&(insn)->attrs)
696 /* Return value of attribute ATTR in INSN. */
697 #define CGEN_INSN_ATTR(insn, attr) \
698 CGEN_ATTR_VALUE (insn, CGEN_INSN_ATTRS (insn), attr)
701 /* Instruction lists.
702 This is used for adding new entries and for creating the hash lists. */
704 typedef struct cgen_insn_list
706 struct cgen_insn_list * next;
707 const CGEN_INSN * insn;
710 /* The table of instructions. */
714 /* Pointer to initial [compiled in] entries. */
715 const CGEN_INSN * init_entries;
717 /* Size of an entry (since the attribute member is variable sized). */
718 unsigned int entry_size;
720 /* Number of entries in `init_entries', including trailing NULL entry. */
721 unsigned int num_init_entries;
723 /* Values added at runtime. */
724 CGEN_INSN_LIST * new_entries;
727 /* ??? This is currently used by the simulator. */
728 extern const CGEN_INSN CGEN_SYM (insn_table_entries)[];
730 /* Return number of instructions. This includes any added at runtime. */
732 extern int cgen_insn_count PARAMS ((void));
734 /* Macro instructions.
735 Macro insns aren't real insns, they map to one or more real insns.
736 E.g. An architecture's "nop" insn may actually be an "mv r0,r0" or
739 Macro insns can expand to nothing (e.g. a nop that is optimized away).
740 This is useful in multi-insn macros that build a constant in a register.
741 Of course this isn't the default behaviour and must be explicitly enabled.
743 Assembly of macro-insns is relatively straightforward. Disassembly isn't.
744 However, disassembly of at least some kinds of macro insns is important
745 in order that the disassembled code preserve the readability of the original
746 insn. What is attempted here is to disassemble all "simple" macro-insns,
747 where "simple" is currently defined to mean "expands to one real insn".
749 Simple macro-insns are handled specially. They are emitted as ALIAS's
750 of real insns. This simplifies their handling since there's usually more
751 of them than any other kind of macro-insn, and proper disassembly of them
752 falls out for free. */
754 /* For each macro-insn there may be multiple expansion possibilities,
755 depending on the arguments. This structure is accessed via the `data'
756 member of CGEN_INSN. */
758 typedef struct cgen_minsn_expansion {
759 /* Function to do the expansion.
760 If the expansion fails (e.g. "no match") NULL is returned.
761 Space for the expansion is obtained with malloc.
762 It is up to the caller to free it. */
763 const char * (* fn) PARAMS ((const struct cgen_minsn_expansion *,
764 const char *, const char **, int *, CGEN_OPERAND **));
765 #define CGEN_MIEXPN_FN(ex) ((ex)->fn)
767 /* Instruction(s) the macro expands to.
768 The format of STR is defined by FN.
769 It is typically the assembly code of the real insn, but it could also be
770 the original Scheme expression or a tokenized form of it (with FN being
771 an appropriate interpreter). */
773 #define CGEN_MIEXPN_STR(ex) ((ex)->str)
774 } CGEN_MINSN_EXPANSION;
777 When supported, this function will convert the input string to another
778 string and the parser will be invoked recursively. The output string
779 may contain further macro invocations. */
781 extern const char * cgen_expand_macro_insn
782 PARAMS ((const struct cgen_minsn_expansion *,
783 const char *, const char **, int *, CGEN_OPERAND **));
785 /* The assembler insn table is hashed based on some function of the mnemonic
786 (the actually hashing done is up to the target, but we provide a few
787 examples like the first letter or a function of the entire mnemonic). */
789 #ifndef CGEN_ASM_HASH_P
790 #define CGEN_ASM_HASH_P(insn) 1
793 /* INSN is the CGEN_INSN entry when building the hash table and NULL
794 when looking up the insn during assembly. */
795 #ifndef CGEN_ASM_HASH
796 #define CGEN_ASM_HASH_SIZE 127
797 #ifdef CGEN_MNEMONIC_OPERANDS
798 #define CGEN_ASM_HASH(mnem) (*(unsigned char *) (mnem) % CGEN_ASM_HASH_SIZE)
800 #define CGEN_ASM_HASH(mnem) (*(unsigned char *) (mnem) % CGEN_ASM_HASH_SIZE) /*FIXME*/
804 extern CGEN_INSN_LIST * cgen_asm_lookup_insn PARAMS ((const char *));
805 #define CGEN_ASM_LOOKUP_INSN(string) cgen_asm_lookup_insn (string)
806 #define CGEN_ASM_NEXT_INSN(insn) ((insn)->next)
808 /* The disassembler insn table is hashed based on some function of machine
809 instruction (the actually hashing done is up to the target). */
811 #ifndef CGEN_DIS_HASH_P
812 #define CGEN_DIS_HASH_P(insn) 1
815 /* It doesn't make much sense to provide a default here,
816 but while this is under development we do.
817 INSN is the CGEN_INSN entry when building the hash table and NULL
818 when looking up the insn during assembly.
819 BUFFER is a pointer to the bytes of the insn.
820 VALUE is the first CGEN_BASE_INSN_SIZE bytes as an int in host order. */
821 #ifndef CGEN_DIS_HASH
822 #define CGEN_DIS_HASH_SIZE 256
823 #define CGEN_DIS_HASH(buffer, value) (*(unsigned char *) (buffer))
826 extern CGEN_INSN_LIST * cgen_dis_lookup_insn PARAMS ((const char *,
828 #define CGEN_DIS_LOOKUP_INSN(buf, value) cgen_dis_lookup_insn ((buf), (value))
829 #define CGEN_DIS_NEXT_INSN(insn) ((insn)->next)
831 /* Top level structures and functions. */
835 const CGEN_HW_ENTRY * hw_list;
837 /*CGEN_OPERAND_TABLE * operand_table; - FIXME:wip */
839 CGEN_INSN_TABLE * insn_table;
841 /* Macro instructions are defined separately and are combined with real
842 insns during hash table computation. */
843 CGEN_INSN_TABLE * macro_insn_table;
845 /* Return non-zero if insn should be added to hash table. */
846 int (* asm_hash_p) PARAMS ((const CGEN_INSN *));
848 /* Assembler hash function. */
849 unsigned int (* asm_hash) PARAMS ((const char *));
851 /* Number of entries in assembler hash table. */
852 unsigned int asm_hash_table_size;
854 /* Return non-zero if insn should be added to hash table. */
855 int (* dis_hash_p) PARAMS ((const CGEN_INSN *));
857 /* Disassembler hash function. */
858 unsigned int (* dis_hash) PARAMS ((const char *, unsigned long));
860 /* Number of entries in disassembler hash table. */
861 unsigned int dis_hash_table_size;
864 /* Each CPU has one of these. */
865 extern const CGEN_OPCODE_TABLE CGEN_SYM (opcode_table);
867 /* Global state access macros.
868 Some of these are tucked away and accessed with cover fns.
869 Simpler things like the current machine and endian are not. */
871 extern int cgen_current_machine;
872 #define CGEN_CURRENT_MACHINE cgen_current_machine
874 extern enum cgen_endian cgen_current_endian;
875 #define CGEN_CURRENT_ENDIAN cgen_current_endian
877 /* Prototypes of major functions. */
879 /* Set the current cpu (+ mach number, endian, etc.). */
880 extern void cgen_set_cpu PARAMS ((const CGEN_OPCODE_TABLE *, int,
883 /* Initialize the assembler, disassembler. */
884 extern void cgen_asm_init PARAMS ((void));
885 extern void cgen_dis_init PARAMS ((void));
887 /* `init_tables' must be called before `xxx_supported'. */
888 extern void CGEN_SYM (init_tables) PARAMS ((int));
889 extern void CGEN_SYM (init_asm) PARAMS ((int, enum cgen_endian));
890 extern void CGEN_SYM (init_dis) PARAMS ((int, enum cgen_endian));
892 /* FIXME: This prototype is wrong ifndef CGEN_INT_INSN.
893 Furthermore, ifdef CGEN_INT_INSN, the insn is created in
894 target byte order (in which case why use int's at all).
895 Perhaps replace cgen_insn_t * with char *? */
896 extern const struct cgen_insn *
897 CGEN_SYM (assemble_insn) PARAMS ((const char *, CGEN_FIELDS *,
898 cgen_insn_t *, char **));
900 extern int CGEN_SYM (insn_supported) PARAMS ((const struct cgen_insn *));
901 extern int CGEN_SYM (opval_supported) PARAMS ((const struct cgen_opval *));
904 extern const CGEN_KEYWORD CGEN_SYM (operand_mach);
905 extern int CGEN_SYM (get_mach) PARAMS ((const char *));
907 extern const CGEN_INSN *
908 CGEN_SYM (lookup_insn) PARAMS ((const CGEN_INSN *, cgen_insn_t,
909 int, CGEN_FIELDS *, int));
911 CGEN_SYM (get_insn_operands) PARAMS ((const CGEN_INSN *, const CGEN_FIELDS *,
913 extern const CGEN_INSN *
914 CGEN_SYM (lookup_get_insn_operands) PARAMS ((const CGEN_INSN *, cgen_insn_t,
917 /* Get/set fields in the CGEN_FIELDS struct. */
919 CGEN_SYM (get_int_operand) PARAMS ((int, const CGEN_FIELDS *));
921 CGEN_SYM (set_int_operand) PARAMS ((int, CGEN_FIELDS *, int));
922 #ifdef BFD_VERSION /* Don't require bfd.h unnecessarily. */
924 CGEN_SYM (get_vma_operand) PARAMS ((int, const CGEN_FIELDS *));
926 CGEN_SYM (set_vma_operand) PARAMS ((int, CGEN_FIELDS *, bfd_vma));
930 CGEN_SYM (parse_operand) PARAMS ((int, const char **, CGEN_FIELDS *));
932 #ifdef BFD_VERSION /* Don't require bfd.h unnecessarily. */
934 CGEN_SYM (insert_operand) PARAMS ((int, CGEN_FIELDS *, char *, bfd_vma));
937 /* Read in a cpu description file. */
938 extern const char * cgen_read_cpu_file PARAMS ((const char *));