1 /* Generic opcode table support for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS USED TO GENERATE @prefix@-opc.c.
6 Copyright (C) 1998 Free Software Foundation, Inc.
8 This file is part of the GNU Binutils and GDB, the GNU debugger.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "libiberty.h"
30 #include "@prefix@-opc.h"
33 /* The hash functions are recorded here to help keep assembler code out of
34 the disassembler and vice versa. */
36 static int asm_hash_insn_p PARAMS ((const CGEN_INSN *));
37 static unsigned int asm_hash_insn PARAMS ((const char *));
38 static int dis_hash_insn_p PARAMS ((const CGEN_INSN *));
39 static unsigned int dis_hash_insn PARAMS ((const char *, unsigned long));
41 /* Look up instruction INSN_VALUE and extract its fields.
42 INSN, if non-null, is the insn table entry.
43 Otherwise INSN_VALUE is examined to compute it.
44 LENGTH is the bit length of INSN_VALUE if known, otherwise 0.
45 0 is only valid if `insn == NULL && ! defined (CGEN_INT_INSN)'.
46 If INSN != NULL, LENGTH must be valid.
47 ALIAS_P is non-zero if alias insns are to be included in the search.
49 The result a pointer to the insn table entry, or NULL if the instruction
53 @arch@_cgen_lookup_insn (od, insn, insn_value, length, fields, alias_p)
55 const CGEN_INSN *insn;
56 cgen_insn_t insn_value;
65 const CGEN_INSN_LIST *insn_list;
74 if (CGEN_OPCODE_ENDIAN (od) == CGEN_ENDIAN_BIG)
75 bfd_putb16 (insn_value, buf);
77 bfd_putl16 (insn_value, buf);
80 if (CGEN_OPCODE_ENDIAN (od) == CGEN_ENDIAN_BIG)
81 bfd_putb32 (insn_value, buf);
83 bfd_putl32 (insn_value, buf);
89 abort (); /* FIXME: unfinished */
92 /* The instructions are stored in hash lists.
93 Pick the first one and keep trying until we find the right one. */
95 insn_list = CGEN_DIS_LOOKUP_INSN (od, buf, insn_value);
96 while (insn_list != NULL)
98 insn = insn_list->insn;
101 || ! CGEN_INSN_ATTR (insn, CGEN_INSN_ALIAS))
103 /* Basic bit mask must be correct. */
104 /* ??? May wish to allow target to defer this check until the
106 if ((insn_value & CGEN_INSN_MASK (insn)) == CGEN_INSN_VALUE (insn))
108 /* ??? 0 is passed for `pc' */
109 int elength = (*CGEN_EXTRACT_FN (insn)) (od, insn, NULL,
115 if (length != 0 && length != elength)
122 insn_list = CGEN_DIS_NEXT_INSN (insn_list);
127 /* Sanity check: can't pass an alias insn if ! alias_p. */
129 && CGEN_INSN_ATTR (insn, CGEN_INSN_ALIAS))
131 /* Sanity check: length must be correct. */
132 if (length != CGEN_INSN_BITSIZE (insn))
135 /* ??? 0 is passed for `pc' */
136 length = (*CGEN_EXTRACT_FN (insn)) (od, insn, NULL, insn_value, fields,
138 /* Sanity check: must succeed.
139 Could relax this later if it ever proves useful. */
148 /* Fill in the operand instances used by INSN whose operands are FIELDS.
149 INDICES is a pointer to a buffer of MAX_OPERAND_INSTANCES ints to be filled
153 @arch@_cgen_get_insn_operands (od, insn, fields, indices)
155 const CGEN_INSN * insn;
156 const CGEN_FIELDS * fields;
159 const CGEN_OPERAND_INSTANCE *opinst;
162 for (i = 0, opinst = CGEN_INSN_OPERANDS (insn);
164 && CGEN_OPERAND_INSTANCE_TYPE (opinst) != CGEN_OPERAND_INSTANCE_END;
167 const CGEN_OPERAND *op = CGEN_OPERAND_INSTANCE_OPERAND (opinst);
169 indices[i] = CGEN_OPERAND_INSTANCE_INDEX (opinst);
171 indices[i] = @arch@_cgen_get_int_operand (CGEN_OPERAND_INDEX (op),
176 /* Cover function to @arch@_cgen_get_insn_operands when either INSN or FIELDS
178 The INSN, INSN_VALUE, and LENGTH arguments are passed to
179 @arch@_cgen_lookup_insn unchanged.
181 The result is the insn table entry or NULL if the instruction wasn't
185 @arch@_cgen_lookup_get_insn_operands (od, insn, insn_value, length, indices)
187 const CGEN_INSN *insn;
188 cgen_insn_t insn_value;
194 /* Pass non-zero for ALIAS_P only if INSN != NULL.
195 If INSN == NULL, we want a real insn. */
196 insn = @arch@_cgen_lookup_insn (od, insn, insn_value, length, &fields,
201 @arch@_cgen_get_insn_operands (od, insn, &fields, indices);