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