* cgen-asm.c (cgen_current_opcode_table): Renamed from ..._data.
[deliverable/binutils-gdb.git] / opcodes / cgen-opc.in
1 /* Generic opcode table support for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
3
4 This file is used to generate @arch@-opc.c.
5
6 Copyright (C) 1998 Free Software Foundation, Inc.
7
8 This file is part of the GNU Binutils and GDB, the GNU debugger.
9
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)
13 any later version.
14
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.
19
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
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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"
30 #include "@arch@-opc.h"
31
32 /* Look up instruction INSN_VALUE and extract its fields.
33 INSN, if non-null, is the insn table entry.
34 Otherwise INSN_VALUE is examined to compute it.
35 LENGTH is the bit length of INSN_VALUE if known, otherwise 0.
36 0 is only valid if `insn == NULL && ! defined (CGEN_INT_INSN)'.
37 If INSN != NULL, LENGTH must be valid.
38 ALIAS_P is non-zero if alias insns are to be included in the search.
39
40 The result a pointer to the insn table entry, or NULL if the instruction
41 wasn't recognized. */
42
43 const CGEN_INSN *
44 @arch@_cgen_lookup_insn (insn, insn_value, length, fields, alias_p)
45 const CGEN_INSN *insn;
46 cgen_insn_t insn_value;
47 int length;
48 CGEN_FIELDS *fields;
49 int alias_p;
50 {
51 char buf[16];
52
53 if (!insn)
54 {
55 const CGEN_INSN_LIST *insn_list;
56
57 #ifdef CGEN_INT_INSN
58 switch (length)
59 {
60 case 8:
61 buf[0] = insn_value;
62 break;
63 case 16:
64 if (cgen_current_endian == CGEN_ENDIAN_BIG)
65 bfd_putb16 (insn_value, buf);
66 else
67 bfd_putl16 (insn_value, buf);
68 break;
69 case 32:
70 if (cgen_current_endian == CGEN_ENDIAN_BIG)
71 bfd_putb32 (insn_value, buf);
72 else
73 bfd_putl32 (insn_value, buf);
74 break;
75 default:
76 abort ();
77 }
78 #else
79 abort (); /* FIXME: unfinished */
80 #endif
81
82 /* The instructions are stored in hash lists.
83 Pick the first one and keep trying until we find the right one. */
84
85 insn_list = CGEN_DIS_LOOKUP_INSN (buf, insn_value);
86 while (insn_list != NULL)
87 {
88 insn = insn_list->insn;
89
90 if (alias_p
91 || ! CGEN_INSN_ATTR (insn, CGEN_INSN_ALIAS))
92 {
93 /* Basic bit mask must be correct. */
94 /* ??? May wish to allow target to defer this check until the
95 extract handler. */
96 if ((insn_value & CGEN_INSN_MASK (insn)) == CGEN_INSN_VALUE (insn))
97 {
98 int elength = (*CGEN_EXTRACT_FN (insn)) (insn, NULL,
99 insn_value, fields);
100 if (elength > 0)
101 {
102 /* sanity check */
103 if (length != 0 && length != elength)
104 abort ();
105 return insn;
106 }
107 }
108 }
109
110 insn_list = CGEN_DIS_NEXT_INSN (insn_list);
111 }
112 }
113 else
114 {
115 /* Sanity check: can't pass an alias insn if ! alias_p. */
116 if (! alias_p
117 && CGEN_INSN_ATTR (insn, CGEN_INSN_ALIAS))
118 abort ();
119 /* Sanity check: length must be correct. */
120 if (length != CGEN_INSN_BITSIZE (insn))
121 abort ();
122
123 length = (*CGEN_EXTRACT_FN (insn)) (insn, NULL, insn_value, fields);
124 /* Sanity check: must succeed.
125 Could relax this later if it ever proves useful. */
126 if (length == 0)
127 abort ();
128 return insn;
129 }
130
131 return NULL;
132 }
133
134 /* Fill in the operand instances used by INSN whose operands are FIELDS.
135 INDICES is a pointer to a buffer of MAX_OPERAND_INSTANCES ints to be filled
136 in. */
137
138 void
139 @arch@_cgen_get_insn_operands (insn, fields, indices)
140 const CGEN_INSN * insn;
141 const CGEN_FIELDS * fields;
142 int *indices;
143 {
144 const CGEN_OPERAND_INSTANCE *opinst;
145 int i;
146
147 for (i = 0, opinst = CGEN_INSN_OPERANDS (insn);
148 opinst != NULL
149 && CGEN_OPERAND_INSTANCE_TYPE (opinst) != CGEN_OPERAND_INSTANCE_END;
150 ++i, ++opinst)
151 {
152 const CGEN_OPERAND *op = CGEN_OPERAND_INSTANCE_OPERAND (opinst);
153 if (op == NULL)
154 indices[i] = CGEN_OPERAND_INSTANCE_INDEX (opinst);
155 else
156 indices[i] = @arch@_cgen_get_operand (CGEN_OPERAND_INDEX (op), fields);
157 }
158 }
159
160 /* Cover function to @arch@_cgen_get_insn_operands when either INSN or FIELDS
161 isn't known.
162 The INSN, INSN_VALUE, and LENGTH arguments are passed to
163 @arch@_cgen_lookup_insn unchanged.
164
165 The result is the insn table entry or NULL if the instruction wasn't
166 recognized. */
167
168 const CGEN_INSN *
169 @arch@_cgen_lookup_get_insn_operands (insn, insn_value, length, indices)
170 const CGEN_INSN *insn;
171 cgen_insn_t insn_value;
172 int length;
173 int *indices;
174 {
175 CGEN_FIELDS fields;
176
177 /* Pass non-zero for ALIAS_P only if INSN != NULL.
178 If INSN == NULL, we want a real insn. */
179 insn = @arch@_cgen_lookup_insn (insn, insn_value, length, &fields,
180 insn != NULL);
181 if (! insn)
182 return NULL;
183
184 @arch@_cgen_get_insn_operands (insn, &fields, indices);
185 return insn;
186 }
This page took 0.036247 seconds and 4 git commands to generate.