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. */
25 #if defined(__STDC__) || defined(ALMOST_STDC)
26 #define CGEN_XCAT3(a,b,c) a ## b ## c
27 #define CGEN_CAT3(a,b,c) CGEN_XCAT3 (a, b, c)
29 #define CGEN_CAT3(a,b,c) a/**/b/**/c
33 /* Prepend the cpu name, defined in cpu-opc.h, and _cgen_ to symbol S.
34 The lack of spaces in the arg list is important for non-stdc systems.
35 This file is included by <cpu>-opc.h.
36 It can be included independently of cpu-opc.h, in which case the cpu
37 dependent portions will be declared as "unknown_cgen_foo". */
40 #define CGEN_SYM(s) CGEN_CAT3 (unknown,_cgen_,s)
43 /* This file contains the static (unchanging) pieces and as much other stuff
44 as we can reasonably put here. It's generally cleaner to put stuff here
45 rather than having it machine generated if possible. */
47 /* The assembler syntax is made up of expressions (duh...).
48 At the lowest level the values are mnemonics, register names, numbers, etc.
49 Above that are subexpressions, if any (an example might be the
50 "effective address" in m68k cpus). At the second highest level are the
51 insns themselves. Above that are pseudo-insns, synthetic insns, and macros,
55 /* Lots of cpu's have a fixed insn size, or one which rarely changes,
56 and it's generally easier to handle these by treating the insn as an
57 integer type, rather than an array of characters. So we allow targets
61 typedef unsigned int cgen_insn_t
;
63 typedef char * cgen_insn_t
;
67 #define CGEN_INLINE inline
72 /* Perhaps we should just use bfd.h, but it's not clear
73 one would want to require that yet. */
82 Attributes are used to describe various random things. */
84 /* Struct to record attribute information. */
87 unsigned char num_nonbools
;
89 unsigned int nonbool
[1];
92 /* Define a structure member for attributes with N non-boolean entries.
93 The attributes are sorted so that the non-boolean ones come first.
94 num_nonbools: count of nonboolean attributes
95 bool: values of boolean attributes
96 nonbool: values of non-boolean attributes
97 There is a maximum of 32 attributes total. */
98 #define CGEN_ATTR_TYPE(n) \
99 const struct { unsigned char num_nonbools; \
101 unsigned int nonbool[(n) ? (n) : 1]; }
103 /* Given an attribute number, return its mask. */
104 #define CGEN_ATTR_MASK(attr) (1 << (attr))
106 /* Return value of attribute ATTR in ATTR_TABLE for OBJ.
107 OBJ is a pointer to the entity that has the attributes.
108 It's not used at present but is reserved for future purposes. */
109 #define CGEN_ATTR_VALUE(obj, attr_table, attr) \
110 ((unsigned int) (attr) < (attr_table)->num_nonbools \
111 ? ((attr_table)->nonbool[attr]) \
112 : (((attr_table)->bool & (1 << (attr))) != 0))
114 /* Attribute name/value tables.
115 These are used to assist parsing of descriptions at runtime. */
123 /* For each domain (fld,operand,insn), list of attributes. */
128 /* NULL for boolean attributes. */
129 const CGEN_ATTR_ENTRY
* vals
;
132 /* Parse result (also extraction result).
134 The result of parsing an insn is stored here.
135 To generate the actual insn, this is passed to the insert handler.
136 When printing an insn, the result of extraction is stored here.
137 To print the insn, this is passed to the print handler.
139 It is machine generated so we don't define it here,
140 but we do need a forward decl for the handler fns.
142 There is one member for each possible field in the insn.
143 The type depends on the field.
144 Also recorded here is the computed length of the insn for architectures
148 typedef struct cgen_fields CGEN_FIELDS
;
150 /* Total length of the insn, as recorded in the `fields' struct. */
151 /* ??? The field insert handler has lots of opportunities for optimization
152 if it ever gets inlined. On architectures where insns all have the same
153 size, may wish to detect that and make this macro a constant - to allow
154 further optimizations. */
155 #define CGEN_FIELDS_BITSIZE(fields) ((fields)->length)
157 /* Associated with each insn or expression is a set of "handlers" for
158 performing operations like parsing, printing, etc. */
161 typedef struct cgen_insn CGEN_INSN
;
164 The first argument is a pointer to a struct describing the insn being
166 The second argument is a pointer to a pointer to the text being parsed.
167 The third argument is a pointer to a cgen_fields struct
168 in which the results are placed.
169 If the expression is successfully parsed, the pointer to the text is
170 updated. If not it is left alone.
171 The result is NULL if success or an error message. */
172 typedef const char * (cgen_parse_fn
) PARAMS ((const struct cgen_insn
*,
177 The first argument is a pointer to the disassembly info.
178 Eg: disassemble_info. It's defined as `PTR' so this file can be included
180 The second argument is a pointer to a struct describing the insn being
182 The third argument is a pointer to a cgen_fields struct.
183 The fourth argument is the pc value of the insn.
184 The fifth argument is the length of the insn, in bytes. */
185 /* Don't require bfd.h unnecessarily. */
187 typedef void (cgen_print_fn
) PARAMS ((PTR
, const struct cgen_insn
*,
188 CGEN_FIELDS
*, bfd_vma
, int));
190 typedef void (cgen_print_fn
) ();
194 The first argument is a pointer to a struct describing the insn being
196 The second argument is a pointer to a cgen_fields struct
197 from which the values are fetched.
198 The third argument is a pointer to a buffer in which to place the insn.
199 The result is an error message or NULL if success. */
200 typedef const char * (cgen_insert_fn
) PARAMS ((const struct cgen_insn
*,
201 CGEN_FIELDS
*, cgen_insn_t
*));
204 The first argument is a pointer to a struct describing the insn being
206 The second argument is a pointer to a struct controlling extraction
207 (only used for variable length insns).
208 The third argument is the first CGEN_BASE_INSN_SIZE bytes.
209 The fourth argument is a pointer to a cgen_fields struct
210 in which the results are placed.
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
*,
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 /* Base class of parser/printer.
231 (Don't read too much into the use of the phrase "base class".
232 It's a name I'm using to organize my thoughts.)
234 Instructions and expressions all share this data in common.
235 It's a collection of the common elements needed to parse, insert, extract,
236 and print each of them. */
238 #ifndef CGEN_INSN_MAX_ATTRS
239 #define CGEN_INSN_MAX_ATTRS 1
244 /* Indices into the handler tables.
245 We could use pointers here instead, but in the case of the insn table,
246 90% of them would be identical and that's a lot of redundant data.
247 0 means use the default (what the default is is up to the code). */
248 unsigned char parse
, insert
, extract
, print
;
251 /* Assembler interface.
253 The interface to the assembler is intended to be clean in the sense that
254 libopcodes.a is a standalone entity and could be used with any assembler.
255 Not that one would necessarily want to do that but rather that it helps
256 keep a clean interface. The interface will obviously be slanted towards
257 GAS, but at least it's a start.
259 Parsing is controlled by the assembler which calls
260 CGEN_SYM (assemble_insn). If it can parse and build the entire insn
261 it doesn't call back to the assembler. If it needs/wants to call back
262 to the assembler, (*cgen_parse_operand_fn) is called which can either
264 - return a number to be inserted in the insn
265 - return a "register" value to be inserted
266 (the register might not be a register per pe)
267 - queue the argument and return a marker saying the expression has been
268 queued (eg: a fix-up)
269 - return an error message indicating the expression wasn't recognizable
271 The result is an error message or NULL for success.
272 The parsed value is stored in the bfd_vma *. */
274 /* Values for indicating what the caller wants. */
275 enum cgen_parse_operand_type
277 CGEN_PARSE_OPERAND_INIT
,
278 CGEN_PARSE_OPERAND_INTEGER
,
279 CGEN_PARSE_OPERAND_ADDRESS
282 /* Values for indicating what was parsed.
283 ??? Not too useful at present but in time. */
284 enum cgen_parse_operand_result
286 CGEN_PARSE_OPERAND_RESULT_NUMBER
,
287 CGEN_PARSE_OPERAND_RESULT_REGISTER
,
288 CGEN_PARSE_OPERAND_RESULT_QUEUED
,
289 CGEN_PARSE_OPERAND_RESULT_ERROR
292 /* Don't require bfd.h unnecessarily. */
294 extern const char * (*cgen_parse_operand_fn
)
295 PARAMS ((enum cgen_parse_operand_type
, const char **, int, int,
296 enum cgen_parse_operand_result
*, bfd_vma
*));
299 /* Called before trying to match a table entry with the insn. */
300 void cgen_init_parse_operand
PARAMS ((void));
302 /* Called from <cpu>-asm.c to initialize operand parsing. */
304 /* These are GAS specific. They're not here as part of the interface,
305 but rather that we need to put them somewhere. */
307 /* Call this from md_assemble to initialize the assembler callback. */
308 void cgen_asm_init_parse
PARAMS ((void));
310 /* Don't require bfd.h unnecessarily. */
312 /* The result is an error message or NULL for success.
313 The parsed value is stored in the bfd_vma *. */
314 const char * cgen_parse_operand
PARAMS ((enum cgen_parse_operand_type
,
315 const char **, int, int,
316 enum cgen_parse_operand_result
*,
320 void cgen_save_fixups
PARAMS ((void));
321 void cgen_restore_fixups
PARAMS ((void));
322 void cgen_swap_fixups
PARAMS ((void));
324 /* Add a register to the assembler's hash table.
325 This makes lets GAS parse registers for us.
326 ??? This isn't currently used, but it could be in the future. */
327 void cgen_asm_record_register
PARAMS ((char *, int));
329 /* After CGEN_SYM (assemble_insn) is done, this is called to
330 output the insn and record any fixups. The address of the
331 assembled instruction is returned in case it is needed by
333 char * cgen_asm_finish_insn
PARAMS ((const struct cgen_insn
*, cgen_insn_t
*,
336 /* Operand values (keywords, integers, symbols, etc.) */
338 /* Types of assembler elements. */
342 CGEN_ASM_KEYWORD
, CGEN_ASM_MAX
345 /* List of hardware elements. */
347 typedef struct cgen_hw_entry
349 /* The type of this entry, one of `enum hw_type'.
350 This is an int and not the enum as the latter may not be declared yet. */
352 const struct cgen_hw_entry
* next
;
354 enum cgen_asm_type asm_type
;
358 const CGEN_HW_ENTRY
* cgen_hw_lookup
PARAMS ((const char *));
360 #ifndef CGEN_KEYWORD_MAX_ATTRS
361 #define CGEN_KEYWORD_MAX_ATTRS 1
364 /* This struct is used to describe things like register names, etc. */
366 typedef struct cgen_keyword_entry
368 /* Name (as in register name). */
371 /* Value (as in register number).
372 The value cannot be -1 as that is used to indicate "not found".
373 IDEA: Have "FUNCTION" attribute? [function is called to fetch value]. */
377 This should, but technically needn't, appear last. It is a variable sized
378 array in that one architecture may have 1 nonbool attribute and another
379 may have more. Having this last means the non-architecture specific code
381 /* ??? Moving this last should be done by treating keywords like insn lists
382 and moving the `next' fields into a CGEN_KEYWORD_LIST struct. */
383 /* FIXME: Not used yet. */
384 CGEN_ATTR_TYPE (CGEN_KEYWORD_MAX_ATTRS
) attrs
;
386 /* Next name hash table entry. */
387 struct cgen_keyword_entry
*next_name
;
388 /* Next value hash table entry. */
389 struct cgen_keyword_entry
*next_value
;
390 } CGEN_KEYWORD_ENTRY
;
392 /* Top level struct for describing a set of related keywords
393 (e.g. register names).
395 This struct supports runtime entry of new values, and hashed lookups. */
397 typedef struct cgen_keyword
399 /* Pointer to initial [compiled in] values. */
400 CGEN_KEYWORD_ENTRY
* init_entries
;
402 /* Number of entries in `init_entries'. */
403 unsigned int num_init_entries
;
405 /* Hash table used for name lookup. */
406 CGEN_KEYWORD_ENTRY
** name_hash_table
;
408 /* Hash table used for value lookup. */
409 CGEN_KEYWORD_ENTRY
** value_hash_table
;
411 /* Number of entries in the hash_tables. */
412 unsigned int hash_table_size
;
414 /* Pointer to null keyword "" entry if present. */
415 const CGEN_KEYWORD_ENTRY
* null_entry
;
418 /* Structure used for searching. */
422 /* Table being searched. */
423 const CGEN_KEYWORD
* table
;
425 /* Specification of what is being searched for. */
428 /* Current index in hash table. */
429 unsigned int current_hash
;
431 /* Current element in current hash chain. */
432 CGEN_KEYWORD_ENTRY
* current_entry
;
433 } CGEN_KEYWORD_SEARCH
;
435 /* Lookup a keyword from its name. */
436 const CGEN_KEYWORD_ENTRY
* cgen_keyword_lookup_name
437 PARAMS ((CGEN_KEYWORD
*, const char *));
438 /* Lookup a keyword from its value. */
439 const CGEN_KEYWORD_ENTRY
* cgen_keyword_lookup_value
440 PARAMS ((CGEN_KEYWORD
*, int));
442 void cgen_keyword_add
PARAMS ((CGEN_KEYWORD
*, CGEN_KEYWORD_ENTRY
*));
443 /* Keyword searching.
444 This can be used to retrieve every keyword, or a subset. */
445 CGEN_KEYWORD_SEARCH cgen_keyword_search_init
446 PARAMS ((CGEN_KEYWORD
*, const char *));
447 const CGEN_KEYWORD_ENTRY
*cgen_keyword_search_next
448 PARAMS ((CGEN_KEYWORD_SEARCH
*));
450 /* Operand value support routines. */
451 /* FIXME: some of the long's here will need to be bfd_vma or some such. */
453 const char * cgen_parse_keyword
PARAMS ((const char **,
456 const char * cgen_parse_signed_integer
PARAMS ((const char **, int, long *));
457 const char * cgen_parse_unsigned_integer
PARAMS ((const char **, int,
459 const char * cgen_parse_address
PARAMS ((const char **, int, int,
460 enum cgen_parse_operand_result
*,
462 const char * cgen_validate_signed_integer
PARAMS ((long, long, long));
463 const char * cgen_validate_unsigned_integer
PARAMS ((unsigned long,
469 /* ??? This duplicates the values in arch.h. Revisit.
470 These however need the CGEN_ prefix [as does everything in this file]. */
471 /* ??? Targets may need to add their own modes so we may wish to move this
472 to <arch>-opc.h, or add a hook. */
475 CGEN_MODE_VOID
, /* FIXME: rename simulator's VM to VOID */
476 CGEN_MODE_BI
, CGEN_MODE_QI
, CGEN_MODE_HI
, CGEN_MODE_SI
, CGEN_MODE_DI
,
477 CGEN_MODE_UBI
, CGEN_MODE_UQI
, CGEN_MODE_UHI
, CGEN_MODE_USI
, CGEN_MODE_UDI
,
478 CGEN_MODE_SF
, CGEN_MODE_DF
, CGEN_MODE_XF
, CGEN_MODE_TF
,
482 /* FIXME: Until simulator is updated. */
483 #define CGEN_MODE_VM CGEN_MODE_VOID
485 /* This struct defines each entry in the operand table. */
487 #ifndef CGEN_OPERAND_MAX_ATTRS
488 #define CGEN_OPERAND_MAX_ATTRS 1
491 typedef struct cgen_operand
493 /* Name as it appears in the syntax string. */
496 /* The hardware element associated with this operand. */
497 const CGEN_HW_ENTRY
*hw
;
499 /* FIXME: We don't yet record ifield definitions, which we should.
500 When we do it might make sense to delete start/length (since they will
501 be duplicated in the ifield's definition) and replace them with a
502 pointer to the ifield entry. Note that as more complicated situations
503 need to be handled, going more and more with an OOP paradigm will help
504 keep the complication under control. Of course, this was the goal from
505 the start, but getting there in one step was too much too soon. */
507 /* Bit position (msb of first byte = bit 0).
508 This is just a hint, and may be unused in more complex operands.
509 May be unused for a modifier. */
512 /* The number of bits in the operand.
513 This is just a hint, and may be unused in more complex operands.
514 May be unused for a modifier. */
515 unsigned char length
;
517 #if 0 /* ??? Interesting idea but relocs tend to get too complicated,
518 and ABI dependent, for simple table lookups to work. */
519 /* Ideally this would be the internal (external?) reloc type. */
524 This should, but technically needn't, appear last. It is a variable sized
525 array in that one architecture may have 1 nonbool attribute and another
526 may have more. Having this last means the non-architecture specific code
527 needn't care, now or tomorrow. */
528 CGEN_ATTR_TYPE (CGEN_OPERAND_MAX_ATTRS
) attrs
;
529 #define CGEN_OPERAND_ATTRS(operand) (&(operand)->attrs)
532 /* Return value of attribute ATTR in OPERAND. */
533 #define CGEN_OPERAND_ATTR(operand, attr) \
534 CGEN_ATTR_VALUE (operand, CGEN_OPERAND_ATTRS (operand), attr)
536 /* The operand table is currently a very static entity. */
537 extern const CGEN_OPERAND
CGEN_SYM (operand_table
)[];
539 enum cgen_operand_type
;
541 #define CGEN_OPERAND_INDEX(operand) ((int) ((operand) - CGEN_SYM (operand_table)))
542 /* FIXME: Rename, cpu-opc.h defines this as the typedef of the enum. */
543 #define CGEN_OPERAND_TYPE(operand) ((enum cgen_operand_type) CGEN_OPERAND_INDEX (operand))
544 #define CGEN_OPERAND_ENTRY(n) (& CGEN_SYM (operand_table) [n])
546 /* Types of parse/insert/extract/print cover-fn handlers. */
547 /* FIXME: move opindex first to match caller. */
548 /* FIXME: also need types of insert/extract/print fns. */
549 /* FIXME: not currently used as type of 3rd arg varies. */
550 typedef const char * (CGEN_PARSE_OPERAND_FN
) PARAMS ((const char **, int,
553 /* Instruction operand instances.
555 For each instruction, a list of the hardware elements that are read and
556 written are recorded. */
558 /* The type of the instance. */
559 enum cgen_operand_instance_type
{
560 /* End of table marker. */
561 CGEN_OPERAND_INSTANCE_END
= 0,
562 CGEN_OPERAND_INSTANCE_INPUT
, CGEN_OPERAND_INSTANCE_OUTPUT
567 /* The type of this operand. */
568 enum cgen_operand_instance_type type
;
569 #define CGEN_OPERAND_INSTANCE_TYPE(opinst) ((opinst)->type)
571 /* The hardware element referenced. */
572 const CGEN_HW_ENTRY
*hw
;
573 #define CGEN_OPERAND_INSTANCE_HW(opinst) ((opinst)->hw)
575 /* The mode in which the operand is being used. */
577 #define CGEN_OPERAND_INSTANCE_MODE(opinst) ((opinst)->mode)
579 /* The operand table entry or NULL if there is none (i.e. an explicit
580 hardware reference). */
581 const CGEN_OPERAND
*operand
;
582 #define CGEN_OPERAND_INSTANCE_OPERAND(opinst) ((opinst)->operand)
584 /* If `operand' is NULL, the index (e.g. into array of registers). */
586 #define CGEN_OPERAND_INSTANCE_INDEX(opinst) ((opinst)->index)
587 } CGEN_OPERAND_INSTANCE
;
591 Each insn format and subexpression has one of these.
593 The syntax "string" consists of characters (n > 0 && n < 128), and operand
594 values (n >= 128), and is terminated by 0. Operand values are 128 + index
595 into the operand table. The operand table doesn't exist in C, per se, as
596 the data is recorded in the parse/insert/extract/print switch statements. */
598 #ifndef CGEN_MAX_SYNTAX_BYTES
599 #define CGEN_MAX_SYNTAX_BYTES 16
604 unsigned char syntax
[CGEN_MAX_SYNTAX_BYTES
];
607 #define CGEN_SYNTAX_STRING(syn) (syn->syntax)
608 #define CGEN_SYNTAX_CHAR_P(c) ((c) < 128)
609 #define CGEN_SYNTAX_CHAR(c) (c)
610 #define CGEN_SYNTAX_FIELD(c) ((c) - 128)
611 #define CGEN_SYNTAX_MAKE_FIELD(c) ((c) + 128)
613 /* ??? I can't currently think of any case where the mnemonic doesn't come
614 first [and if one ever doesn't building the hash tables will be tricky].
615 However, we treat mnemonics as just another operand of the instruction.
616 A value of 1 means "this is where the mnemonic appears". 1 isn't
617 special other than it's a non-printable ASCII char. */
618 #define CGEN_SYNTAX_MNEMONIC_P(ch) ((ch) == 1)
620 /* Instruction formats.
622 Instructions are grouped by format. Associated with an instruction is its
623 format. Each opcode table entry contains a pointer into the format table.
624 This cuts down on the size of the opcode table as there are relatively few
625 formats compared with the number of instructions. */
629 /* Length that MASK and VALUE have been calculated to
630 [VALUE is recorded elsewhere].
631 Normally it is CGEN_BASE_INSN_BITSIZE. On [V]LIW architectures where
632 the base insn size may be larger than the size of an insn, this field is
633 less than CGEN_BASE_INSN_BITSIZE. */
634 unsigned char mask_length
;
636 /* Total length of instruction. */
637 unsigned char length
;
639 /* Mask to apply to the first BASE_LENGTH bits.
640 Each insn's value is stored with the insn.
641 The first step in recognizing an insn for disassembly is
642 (opcode & mask) == value. */
646 /* This struct defines each entry in the instruction table. */
650 /* ??? Further table size reductions can be had by moving this element
651 either to the format table or to a separate table of its own. Not
652 sure this is desirable yet. */
653 struct cgen_base base
;
655 /* Given a pointer to a cgen_insn struct, return a pointer to `base'. */
656 #define CGEN_INSN_BASE(insn) (&(insn)->base)
658 /* Name of entry (that distinguishes it from all other entries).
659 This is used, for example, in simulator profiling results. */
660 /* ??? If mnemonics have operands, try to print full mnemonic. */
662 #define CGEN_INSN_NAME(insn) ((insn)->name)
664 /* Mnemonic. This is used when parsing and printing the insn.
665 In the case of insns that have operands on the mnemonics, this is
666 only the constant part. E.g. for conditional execution of an `add' insn,
667 where the full mnemonic is addeq, addne, etc., this is only "add". */
668 const char * mnemonic
;
669 #define CGEN_INSN_MNEMONIC(insn) ((insn)->mnemonic)
672 For now this only points to CGEN_SYNTAX elements, but it can point
673 to other things (e.g. something different for macros?). */
674 const CGEN_SYNTAX
* syntax
;
675 #define CGEN_INSN_SYNTAX(insn) ((CGEN_SYNTAX *) (insn)->syntax)
678 For now this only points to CGEN_FORMAT elements, but it can point
679 to other things (e.g. something different for macros?). */
680 const CGEN_FORMAT
* format
;
681 #define CGEN_INSN_MASK_BITSIZE(insn) (((CGEN_FORMAT *) (insn)->format)->mask_length)
682 #define CGEN_INSN_BITSIZE(insn) (((CGEN_FORMAT *) (insn)->format)->length)
684 /* Instruction opcode value. */
686 #define CGEN_INSN_VALUE(insn) ((insn)->value)
687 #define CGEN_INSN_MASK(insn) (((CGEN_FORMAT *) (insn)->format)->mask)
689 /* Pointer to NULL entry terminated table of operands used,
691 const CGEN_OPERAND_INSTANCE
*operands
;
692 #define CGEN_INSN_OPERANDS(insn) ((insn)->operands)
695 This must appear last. It is a variable sized array in that one
696 architecture may have 1 nonbool attribute and another may have more.
697 Having this last means the non-architecture specific code needn't
699 CGEN_ATTR_TYPE (CGEN_INSN_MAX_ATTRS
) attrs
;
700 #define CGEN_INSN_ATTRS(insn) (&(insn)->attrs)
701 /* Return value of attribute ATTR in INSN. */
702 #define CGEN_INSN_ATTR(insn, attr) \
703 CGEN_ATTR_VALUE (insn, CGEN_INSN_ATTRS (insn), attr)
706 /* Instruction lists.
707 This is used for adding new entries and for creating the hash lists. */
709 typedef struct cgen_insn_list
711 struct cgen_insn_list
* next
;
712 const CGEN_INSN
* insn
;
715 /* The table of instructions. */
719 /* Pointer to initial [compiled in] entries. */
720 const CGEN_INSN
* init_entries
;
722 /* Size of an entry (since the attribute member is variable sized). */
723 unsigned int entry_size
;
725 /* Number of entries in `init_entries', including trailing NULL entry. */
726 unsigned int num_init_entries
;
728 /* Values added at runtime. */
729 CGEN_INSN_LIST
* new_entries
;
731 /* Assembler hash function. */
732 unsigned int (* asm_hash
) PARAMS ((const char *));
734 /* Number of entries in assembler hash table. */
735 unsigned int asm_hash_table_size
;
737 /* Disassembler hash function. */
738 unsigned int (* dis_hash
) PARAMS ((const char *, unsigned long));
740 /* Number of entries in disassembler hash table. */
741 unsigned int dis_hash_table_size
;
744 /* ??? This is currently used by the simulator.
745 We want this to be fast and the simulator currently doesn't handle
746 runtime added instructions so this is ok. An alternative would be to
747 store the index in the table. */
748 extern const CGEN_INSN
CGEN_SYM (insn_table_entries
)[];
749 #define CGEN_INSN_INDEX(insn) ((int) ((insn) - CGEN_SYM (insn_table_entries)))
750 #define CGEN_INSN_ENTRY(n) (& CGEN_SYM (insn_table_entries) [n])
752 /* Return number of instructions. This includes any added at runtime. */
754 int cgen_insn_count
PARAMS ((void));
756 /* The assembler insn table is hashed based on some function of the mnemonic
757 (the actually hashing done is up to the target, but we provide a few
758 examples like the first letter or a function of the entire mnemonic).
759 The index of each entry is the index of the corresponding table entry.
760 The value of each entry is the index of the next entry, with a 0
761 terminating (thus the first entry is reserved). */
763 #ifndef CGEN_ASM_HASH
764 #ifdef CGEN_MNEMONIC_OPERANDS
765 #define CGEN_ASM_HASH_SIZE 127
766 #define CGEN_ASM_HASH(string) (*(unsigned char *) (string) % CGEN_ASM_HASH_SIZE)
768 #define CGEN_ASM_HASH_SIZE 128
769 #define CGEN_ASM_HASH(string) (*(unsigned char *) (string) % CGEN_ASM_HASH_SIZE) /*FIXME*/
773 unsigned int CGEN_SYM (asm_hash_insn
) PARAMS ((const char *));
774 CGEN_INSN_LIST
* cgen_asm_lookup_insn
PARAMS ((const char *));
775 #define CGEN_ASM_LOOKUP_INSN(insn) cgen_asm_lookup_insn (insn)
776 #define CGEN_ASM_NEXT_INSN(insn) ((insn)->next)
778 /* The disassembler insn table is hashed based on some function of machine
779 instruction (the actually hashing done is up to the target). */
781 /* It doesn't make much sense to provide a default here,
782 but while this is under development we do.
783 BUFFER is a pointer to the bytes of the insn.
784 INSN is the first CGEN_BASE_INSN_SIZE bytes as an int in host order. */
785 #ifndef CGEN_DIS_HASH
786 #define CGEN_DIS_HASH_SIZE 256
787 #define CGEN_DIS_HASH(buffer, insn) (*(unsigned char *) (buffer))
790 unsigned int CGEN_SYM (dis_hash_insn
) PARAMS ((const char *, unsigned long));
791 CGEN_INSN_LIST
* cgen_dis_lookup_insn
PARAMS ((const char *, unsigned long));
792 #define CGEN_DIS_LOOKUP_INSN(buf, insn) cgen_dis_lookup_insn (buf, insn)
793 #define CGEN_DIS_NEXT_INSN(insn) ((insn)->next)
795 /* Top level structures and functions. */
799 const CGEN_HW_ENTRY
* hw_list
;
800 /*CGEN_OPERAND_TABLE * operand_table; - FIXME:wip */
801 CGEN_INSN_TABLE
* insn_table
;
804 /* Each CPU has one of these. */
805 extern CGEN_OPCODE_DATA
CGEN_SYM (opcode_data
);
807 /* Global state access macros.
808 Some of these are tucked away and accessed with cover fns.
809 Simpler things like the current machine and endian are not. */
811 extern int cgen_current_machine
;
812 #define CGEN_CURRENT_MACHINE cgen_current_machine
814 extern enum cgen_endian cgen_current_endian
;
815 #define CGEN_CURRENT_ENDIAN cgen_current_endian
817 /* Prototypes of major functions. */
819 /* Set the current cpu (+ mach number, endian, etc.). */
820 void cgen_set_cpu
PARAMS ((CGEN_OPCODE_DATA
*, int, enum cgen_endian
));
822 /* Initialize the assembler, disassembler. */
823 void cgen_asm_init
PARAMS ((void));
824 void cgen_dis_init
PARAMS ((void));
826 /* `init_tables' must be called before `xxx_supported'. */
827 void CGEN_SYM (init_tables
) PARAMS ((int));
828 void CGEN_SYM (init_asm
) PARAMS ((int, enum cgen_endian
));
829 void CGEN_SYM (init_dis
) PARAMS ((int, enum cgen_endian
));
830 void CGEN_SYM (init_parse
) PARAMS ((void));
831 void CGEN_SYM (init_print
) PARAMS ((void));
832 void CGEN_SYM (init_insert
) PARAMS ((void));
833 void CGEN_SYM (init_extract
) PARAMS ((void));
835 /* FIXME: This prototype is wrong ifndef CGEN_INT_INSN.
836 Furthermore, ifdef CGEN_INT_INSN, the insn is created in
837 target byte order (in which case why use int's at all).
838 Perhaps replace cgen_insn_t * with char *? */
839 const struct cgen_insn
*
840 CGEN_SYM (assemble_insn
) PARAMS ((const char *, CGEN_FIELDS
*,
841 cgen_insn_t
*, char **));
843 int CGEN_SYM (insn_supported
) PARAMS ((const struct cgen_insn
*));
844 int CGEN_SYM (opval_supported
) PARAMS ((const struct cgen_opval
*));
847 extern const CGEN_KEYWORD
CGEN_SYM (operand_mach
);
848 int CGEN_SYM (get_mach
) PARAMS ((const char *));
851 CGEN_SYM (get_insn_operands
) PARAMS ((const CGEN_INSN
*, cgen_insn_t
,
854 CGEN_SYM (lookup_insn
) PARAMS ((const CGEN_INSN
*, cgen_insn_t
,
855 int, CGEN_FIELDS
*, int));
858 CGEN_SYM (put_operand
) PARAMS ((int, const long *,
861 CGEN_SYM (get_operand
) PARAMS ((int, const CGEN_FIELDS
*));
864 CGEN_SYM (parse_operand
) PARAMS ((int, const char **, CGEN_FIELDS
*));
867 CGEN_SYM (insert_operand
) PARAMS ((int, CGEN_FIELDS
*, char *));
869 /* Default insn parser, printer. */
870 extern cgen_parse_fn
CGEN_SYM (parse_insn
);
871 extern cgen_insert_fn
CGEN_SYM (insert_insn
);
872 extern cgen_extract_fn
CGEN_SYM (extract_insn
);
873 extern cgen_print_fn
CGEN_SYM (print_insn
);
875 /* Read in a cpu description file. */
876 const char * cgen_read_cpu_file
PARAMS ((const char *));