Fic PR 17045: Add FLAG_JSR attribute to DBT, REIT, RTD and TRAP insns.
[deliverable/binutils-gdb.git] / opcodes / cgen-opc.in
CommitLineData
ab0bd049
DE
1/* Generic opcode table support for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
3
0499462e 4THIS FILE IS USED TO GENERATE @prefix@-opc.c.
ab0bd049
DE
5
6Copyright (C) 1998 Free Software Foundation, Inc.
7
8This file is part of the GNU Binutils and GDB, the GNU debugger.
9
10This program is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2, or (at your option)
13any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
0499462e
DE
21along with this program; if not, write to the Free Software Foundation, Inc.,
2259 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
ab0bd049
DE
23
24#include "sysdep.h"
25#include <stdio.h>
26#include "ansidecl.h"
27#include "libiberty.h"
28#include "bfd.h"
29#include "symcat.h"
0499462e 30#include "@prefix@-opc.h"
1e74d15c 31#include "opintl.h"
ab0bd049 32
c2009f4a
DE
33/* The hash functions are recorded here to help keep assembler code out of
34 the disassembler and vice versa. */
35
36static int asm_hash_insn_p PARAMS ((const CGEN_INSN *));
37static unsigned int asm_hash_insn PARAMS ((const char *));
38static int dis_hash_insn_p PARAMS ((const CGEN_INSN *));
39static unsigned int dis_hash_insn PARAMS ((const char *, unsigned long));
40
ab0bd049 41/* Look up instruction INSN_VALUE and extract its fields.
2613b5e6 42 INSN, if non-null, is the insn table entry.
ab0bd049
DE
43 Otherwise INSN_VALUE is examined to compute it.
44 LENGTH is the bit length of INSN_VALUE if known, otherwise 0.
2613b5e6
DE
45 0 is only valid if `insn == NULL && ! defined (CGEN_INT_INSN)'.
46 If INSN != NULL, LENGTH must be valid.
390bd87d 47 ALIAS_P is non-zero if alias insns are to be included in the search.
2613b5e6 48
ab0bd049
DE
49 The result a pointer to the insn table entry, or NULL if the instruction
50 wasn't recognized. */
51
52const CGEN_INSN *
c2009f4a
DE
53@arch@_cgen_lookup_insn (od, insn, insn_value, length, fields, alias_p)
54 CGEN_OPCODE_DESC od;
ab0bd049
DE
55 const CGEN_INSN *insn;
56 cgen_insn_t insn_value;
57 int length;
58 CGEN_FIELDS *fields;
2613b5e6 59 int alias_p;
ab0bd049 60{
390bd87d 61 char buf[16];
ab0bd049
DE
62
63 if (!insn)
64 {
65 const CGEN_INSN_LIST *insn_list;
66
67#ifdef CGEN_INT_INSN
68 switch (length)
69 {
70 case 8:
71 buf[0] = insn_value;
72 break;
73 case 16:
c2009f4a 74 if (CGEN_OPCODE_ENDIAN (od) == CGEN_ENDIAN_BIG)
ab0bd049
DE
75 bfd_putb16 (insn_value, buf);
76 else
77 bfd_putl16 (insn_value, buf);
78 break;
79 case 32:
c2009f4a 80 if (CGEN_OPCODE_ENDIAN (od) == CGEN_ENDIAN_BIG)
ab0bd049
DE
81 bfd_putb32 (insn_value, buf);
82 else
83 bfd_putl32 (insn_value, buf);
84 break;
85 default:
86 abort ();
87 }
88#else
89 abort (); /* FIXME: unfinished */
90#endif
91
92 /* The instructions are stored in hash lists.
93 Pick the first one and keep trying until we find the right one. */
94
c2009f4a 95 insn_list = CGEN_DIS_LOOKUP_INSN (od, buf, insn_value);
ab0bd049
DE
96 while (insn_list != NULL)
97 {
98 insn = insn_list->insn;
99
390bd87d
DE
100 if (alias_p
101 || ! CGEN_INSN_ATTR (insn, CGEN_INSN_ALIAS))
ab0bd049 102 {
390bd87d
DE
103 /* Basic bit mask must be correct. */
104 /* ??? May wish to allow target to defer this check until the
105 extract handler. */
106 if ((insn_value & CGEN_INSN_MASK (insn)) == CGEN_INSN_VALUE (insn))
107 {
fbc8134d 108 /* ??? 0 is passed for `pc' */
c2009f4a 109 int elength = (*CGEN_EXTRACT_FN (insn)) (od, insn, NULL,
fbc8134d
DE
110 insn_value, fields,
111 (bfd_vma) 0);
2613b5e6
DE
112 if (elength > 0)
113 {
114 /* sanity check */
115 if (length != 0 && length != elength)
116 abort ();
117 return insn;
118 }
390bd87d 119 }
ab0bd049
DE
120 }
121
122 insn_list = CGEN_DIS_NEXT_INSN (insn_list);
123 }
124 }
125 else
126 {
390bd87d
DE
127 /* Sanity check: can't pass an alias insn if ! alias_p. */
128 if (! alias_p
129 && CGEN_INSN_ATTR (insn, CGEN_INSN_ALIAS))
130 abort ();
2613b5e6
DE
131 /* Sanity check: length must be correct. */
132 if (length != CGEN_INSN_BITSIZE (insn))
133 abort ();
390bd87d 134
fbc8134d 135 /* ??? 0 is passed for `pc' */
c2009f4a 136 length = (*CGEN_EXTRACT_FN (insn)) (od, insn, NULL, insn_value, fields,
fbc8134d 137 (bfd_vma) 0);
2613b5e6
DE
138 /* Sanity check: must succeed.
139 Could relax this later if it ever proves useful. */
140 if (length == 0)
141 abort ();
142 return insn;
ab0bd049
DE
143 }
144
145 return NULL;
146}
147
2613b5e6 148/* Fill in the operand instances used by INSN whose operands are FIELDS.
bed9a23c 149 INDICES is a pointer to a buffer of MAX_OPERAND_INSTANCES ints to be filled
2613b5e6 150 in. */
ab0bd049 151
2613b5e6 152void
c2009f4a
DE
153@arch@_cgen_get_insn_operands (od, insn, fields, indices)
154 CGEN_OPCODE_DESC od;
2613b5e6
DE
155 const CGEN_INSN * insn;
156 const CGEN_FIELDS * fields;
ab0bd049
DE
157 int *indices;
158{
ab0bd049
DE
159 const CGEN_OPERAND_INSTANCE *opinst;
160 int i;
161
ab0bd049 162 for (i = 0, opinst = CGEN_INSN_OPERANDS (insn);
b2f18612
DE
163 opinst != NULL
164 && CGEN_OPERAND_INSTANCE_TYPE (opinst) != CGEN_OPERAND_INSTANCE_END;
ab0bd049
DE
165 ++i, ++opinst)
166 {
167 const CGEN_OPERAND *op = CGEN_OPERAND_INSTANCE_OPERAND (opinst);
168 if (op == NULL)
169 indices[i] = CGEN_OPERAND_INSTANCE_INDEX (opinst);
170 else
fbc8134d
DE
171 indices[i] = @arch@_cgen_get_int_operand (CGEN_OPERAND_INDEX (op),
172 fields);
ab0bd049 173 }
2613b5e6
DE
174}
175
176/* Cover function to @arch@_cgen_get_insn_operands when either INSN or FIELDS
177 isn't known.
178 The INSN, INSN_VALUE, and LENGTH arguments are passed to
179 @arch@_cgen_lookup_insn unchanged.
180
181 The result is the insn table entry or NULL if the instruction wasn't
182 recognized. */
183
184const CGEN_INSN *
c2009f4a
DE
185@arch@_cgen_lookup_get_insn_operands (od, insn, insn_value, length, indices)
186 CGEN_OPCODE_DESC od;
2613b5e6
DE
187 const CGEN_INSN *insn;
188 cgen_insn_t insn_value;
189 int length;
190 int *indices;
191{
192 CGEN_FIELDS fields;
193
194 /* Pass non-zero for ALIAS_P only if INSN != NULL.
195 If INSN == NULL, we want a real insn. */
c2009f4a 196 insn = @arch@_cgen_lookup_insn (od, insn, insn_value, length, &fields,
2613b5e6
DE
197 insn != NULL);
198 if (! insn)
199 return NULL;
ab0bd049 200
c2009f4a 201 @arch@_cgen_get_insn_operands (od, insn, &fields, indices);
ab0bd049
DE
202 return insn;
203}
This page took 0.051143 seconds and 4 git commands to generate.