/src/binutils-gdb/opcodes/frv-dis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */ |
2 | | /* Disassembler interface for targets using CGEN. -*- C -*- |
3 | | CGEN: Cpu tools GENerator |
4 | | |
5 | | THIS FILE IS MACHINE GENERATED WITH CGEN. |
6 | | - the resultant file is machine generated, cgen-dis.in isn't |
7 | | |
8 | | Copyright (C) 1996-2025 Free Software Foundation, Inc. |
9 | | |
10 | | This file is part of libopcodes. |
11 | | |
12 | | This library is free software; you can redistribute it and/or modify |
13 | | it under the terms of the GNU General Public License as published by |
14 | | the Free Software Foundation; either version 3, or (at your option) |
15 | | any later version. |
16 | | |
17 | | It is distributed in the hope that it will be useful, but WITHOUT |
18 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
19 | | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
20 | | License for more details. |
21 | | |
22 | | You should have received a copy of the GNU General Public License |
23 | | along with this program; if not, write to the Free Software Foundation, Inc., |
24 | | 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
25 | | |
26 | | /* ??? Eventually more and more of this stuff can go to cpu-independent files. |
27 | | Keep that in mind. */ |
28 | | |
29 | | #include "sysdep.h" |
30 | | #include <stdio.h> |
31 | | #include "ansidecl.h" |
32 | | #include "disassemble.h" |
33 | | #include "bfd.h" |
34 | | #include "symcat.h" |
35 | | #include "libiberty.h" |
36 | | #include "frv-desc.h" |
37 | | #include "frv-opc.h" |
38 | | #include "opintl.h" |
39 | | |
40 | | /* Default text to print if an instruction isn't recognized. */ |
41 | 24.9k | #define UNKNOWN_INSN_MSG _("*unknown*") |
42 | | |
43 | | static void print_normal |
44 | | (CGEN_CPU_DESC, void *, long, unsigned int, bfd_vma, int); |
45 | | static void print_address |
46 | | (CGEN_CPU_DESC, void *, bfd_vma, unsigned int, bfd_vma, int) ATTRIBUTE_UNUSED; |
47 | | static void print_keyword |
48 | | (CGEN_CPU_DESC, void *, CGEN_KEYWORD *, long, unsigned int) ATTRIBUTE_UNUSED; |
49 | | static void print_insn_normal |
50 | | (CGEN_CPU_DESC, void *, const CGEN_INSN *, CGEN_FIELDS *, bfd_vma, int); |
51 | | static int print_insn |
52 | | (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, unsigned); |
53 | | static int default_print_insn |
54 | | (CGEN_CPU_DESC, bfd_vma, disassemble_info *) ATTRIBUTE_UNUSED; |
55 | | static int read_insn |
56 | | (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, int, CGEN_EXTRACT_INFO *, |
57 | | unsigned long *); |
58 | | |
59 | | /* -- disassembler routines inserted here. */ |
60 | | |
61 | | /* -- dis.c */ |
62 | | static void |
63 | | print_at (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
64 | | void * dis_info, |
65 | | long reloc_ann ATTRIBUTE_UNUSED, |
66 | | long value ATTRIBUTE_UNUSED, |
67 | | bfd_vma pc ATTRIBUTE_UNUSED, |
68 | | int length ATTRIBUTE_UNUSED) |
69 | 217 | { |
70 | 217 | disassemble_info *info = (disassemble_info *) dis_info; |
71 | | |
72 | 217 | (*info->fprintf_func) (info->stream, "@"); |
73 | 217 | } |
74 | | |
75 | | static void |
76 | | print_spr (CGEN_CPU_DESC cd, |
77 | | void * dis_info, |
78 | | CGEN_KEYWORD *names, |
79 | | long regno, |
80 | | unsigned int attrs) |
81 | 164 | { |
82 | | /* Use the register index format for any unnamed registers. */ |
83 | 164 | if (cgen_keyword_lookup_value (names, regno) == NULL) |
84 | 32 | { |
85 | 32 | disassemble_info *info = (disassemble_info *) dis_info; |
86 | 32 | (*info->fprintf_func) (info->stream, "spr[%ld]", regno); |
87 | 32 | } |
88 | 132 | else |
89 | 132 | print_keyword (cd, dis_info, names, regno, attrs); |
90 | 164 | } |
91 | | |
92 | | static void |
93 | | print_hi (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
94 | | void * dis_info, |
95 | | long value, |
96 | | unsigned int attrs ATTRIBUTE_UNUSED, |
97 | | bfd_vma pc ATTRIBUTE_UNUSED, |
98 | | int length ATTRIBUTE_UNUSED) |
99 | 553 | { |
100 | 553 | disassemble_info *info = (disassemble_info *) dis_info; |
101 | | |
102 | 553 | (*info->fprintf_func) (info->stream, value ? "0x%lx" : "hi(0x%lx)", value); |
103 | 553 | } |
104 | | |
105 | | static void |
106 | | print_lo (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
107 | | void * dis_info, |
108 | | long value, |
109 | | unsigned int attrs ATTRIBUTE_UNUSED, |
110 | | bfd_vma pc ATTRIBUTE_UNUSED, |
111 | | int length ATTRIBUTE_UNUSED) |
112 | 2.28k | { |
113 | 2.28k | disassemble_info *info = (disassemble_info *) dis_info; |
114 | 2.28k | if (value) |
115 | 2.16k | (*info->fprintf_func) (info->stream, "0x%lx", value); |
116 | 119 | else |
117 | 119 | (*info->fprintf_func) (info->stream, "lo(0x%lx)", value); |
118 | 2.28k | } |
119 | | |
120 | | /* -- */ |
121 | | |
122 | | void frv_cgen_print_operand |
123 | | (CGEN_CPU_DESC, int, void *, CGEN_FIELDS *, void const *, bfd_vma, int); |
124 | | |
125 | | /* Main entry point for printing operands. |
126 | | XINFO is a `void *' and not a `disassemble_info *' to not put a requirement |
127 | | of dis-asm.h on cgen.h. |
128 | | |
129 | | This function is basically just a big switch statement. Earlier versions |
130 | | used tables to look up the function to use, but |
131 | | - if the table contains both assembler and disassembler functions then |
132 | | the disassembler contains much of the assembler and vice-versa, |
133 | | - there's a lot of inlining possibilities as things grow, |
134 | | - using a switch statement avoids the function call overhead. |
135 | | |
136 | | This function could be moved into `print_insn_normal', but keeping it |
137 | | separate makes clear the interface between `print_insn_normal' and each of |
138 | | the handlers. */ |
139 | | |
140 | | void |
141 | | frv_cgen_print_operand (CGEN_CPU_DESC cd, |
142 | | int opindex, |
143 | | void * xinfo, |
144 | | CGEN_FIELDS *fields, |
145 | | void const *attrs ATTRIBUTE_UNUSED, |
146 | | bfd_vma pc, |
147 | | int length) |
148 | 442k | { |
149 | 442k | disassemble_info *info = (disassemble_info *) xinfo; |
150 | | |
151 | 442k | switch (opindex) |
152 | 442k | { |
153 | 1 | case FRV_OPERAND_A0 : |
154 | 1 | print_normal (cd, info, fields->f_A, 0, pc, length); |
155 | 1 | break; |
156 | 7 | case FRV_OPERAND_A1 : |
157 | 7 | print_normal (cd, info, fields->f_A, 0, pc, length); |
158 | 7 | break; |
159 | 151 | case FRV_OPERAND_ACC40SI : |
160 | 151 | print_keyword (cd, info, & frv_cgen_opval_acc_names, fields->f_ACC40Si, 0); |
161 | 151 | break; |
162 | 1.14k | case FRV_OPERAND_ACC40SK : |
163 | 1.14k | print_keyword (cd, info, & frv_cgen_opval_acc_names, fields->f_ACC40Sk, 0); |
164 | 1.14k | break; |
165 | 0 | case FRV_OPERAND_ACC40UI : |
166 | 0 | print_keyword (cd, info, & frv_cgen_opval_acc_names, fields->f_ACC40Ui, 0); |
167 | 0 | break; |
168 | 465 | case FRV_OPERAND_ACC40UK : |
169 | 465 | print_keyword (cd, info, & frv_cgen_opval_acc_names, fields->f_ACC40Uk, 0); |
170 | 465 | break; |
171 | 11 | case FRV_OPERAND_ACCGI : |
172 | 11 | print_keyword (cd, info, & frv_cgen_opval_accg_names, fields->f_ACCGi, 0); |
173 | 11 | break; |
174 | 10 | case FRV_OPERAND_ACCGK : |
175 | 10 | print_keyword (cd, info, & frv_cgen_opval_accg_names, fields->f_ACCGk, 0); |
176 | 10 | break; |
177 | 14.6k | case FRV_OPERAND_CCI : |
178 | 14.6k | print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CCi, 0); |
179 | 14.6k | break; |
180 | 72 | case FRV_OPERAND_CPRDOUBLEK : |
181 | 72 | print_keyword (cd, info, & frv_cgen_opval_cpr_names, fields->f_CPRk, 0); |
182 | 72 | break; |
183 | 9.98k | case FRV_OPERAND_CPRI : |
184 | 9.98k | print_keyword (cd, info, & frv_cgen_opval_cpr_names, fields->f_CPRi, 0); |
185 | 9.98k | break; |
186 | 9.98k | case FRV_OPERAND_CPRJ : |
187 | 9.98k | print_keyword (cd, info, & frv_cgen_opval_cpr_names, fields->f_CPRj, 0); |
188 | 9.98k | break; |
189 | 10.0k | case FRV_OPERAND_CPRK : |
190 | 10.0k | print_keyword (cd, info, & frv_cgen_opval_cpr_names, fields->f_CPRk, 0); |
191 | 10.0k | break; |
192 | 23 | case FRV_OPERAND_CRI : |
193 | 23 | print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRi, 0); |
194 | 23 | break; |
195 | 23 | case FRV_OPERAND_CRJ : |
196 | 23 | print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRj, 0); |
197 | 23 | break; |
198 | 95 | case FRV_OPERAND_CRJ_FLOAT : |
199 | 95 | print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRj_float, 0); |
200 | 95 | break; |
201 | 104 | case FRV_OPERAND_CRJ_INT : |
202 | 104 | print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRj_int, 0); |
203 | 104 | break; |
204 | 23 | case FRV_OPERAND_CRK : |
205 | 23 | print_keyword (cd, info, & frv_cgen_opval_cccr_names, fields->f_CRk, 0); |
206 | 23 | break; |
207 | 0 | case FRV_OPERAND_FCCI_1 : |
208 | 0 | print_keyword (cd, info, & frv_cgen_opval_fccr_names, fields->f_FCCi_1, 0); |
209 | 0 | break; |
210 | 1.20k | case FRV_OPERAND_FCCI_2 : |
211 | 1.20k | print_keyword (cd, info, & frv_cgen_opval_fccr_names, fields->f_FCCi_2, 0); |
212 | 1.20k | break; |
213 | 86 | case FRV_OPERAND_FCCI_3 : |
214 | 86 | print_keyword (cd, info, & frv_cgen_opval_fccr_names, fields->f_FCCi_3, 0); |
215 | 86 | break; |
216 | 39 | case FRV_OPERAND_FCCK : |
217 | 39 | print_keyword (cd, info, & frv_cgen_opval_fccr_names, fields->f_FCCk, 0); |
218 | 39 | break; |
219 | 58 | case FRV_OPERAND_FRDOUBLEI : |
220 | 58 | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRi, 0); |
221 | 58 | break; |
222 | 61 | case FRV_OPERAND_FRDOUBLEJ : |
223 | 61 | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRj, 0); |
224 | 61 | break; |
225 | 3.14k | case FRV_OPERAND_FRDOUBLEK : |
226 | 3.14k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0); |
227 | 3.14k | break; |
228 | 2.09k | case FRV_OPERAND_FRI : |
229 | 2.09k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRi, 0); |
230 | 2.09k | break; |
231 | 2.22k | case FRV_OPERAND_FRINTI : |
232 | 2.22k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRi, 0); |
233 | 2.22k | break; |
234 | 1.68k | case FRV_OPERAND_FRINTIEVEN : |
235 | 1.68k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRi, 0); |
236 | 1.68k | break; |
237 | 1.79k | case FRV_OPERAND_FRINTJ : |
238 | 1.79k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRj, 0); |
239 | 1.79k | break; |
240 | 1.58k | case FRV_OPERAND_FRINTJEVEN : |
241 | 1.58k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRj, 0); |
242 | 1.58k | break; |
243 | 11.7k | case FRV_OPERAND_FRINTK : |
244 | 11.7k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0); |
245 | 11.7k | break; |
246 | 1.33k | case FRV_OPERAND_FRINTKEVEN : |
247 | 1.33k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0); |
248 | 1.33k | break; |
249 | 2.10k | case FRV_OPERAND_FRJ : |
250 | 2.10k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRj, 0); |
251 | 2.10k | break; |
252 | 2.10k | case FRV_OPERAND_FRK : |
253 | 2.10k | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0); |
254 | 2.10k | break; |
255 | 19 | case FRV_OPERAND_FRKHI : |
256 | 19 | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0); |
257 | 19 | break; |
258 | 84 | case FRV_OPERAND_FRKLO : |
259 | 84 | print_keyword (cd, info, & frv_cgen_opval_fr_names, fields->f_FRk, 0); |
260 | 84 | break; |
261 | 6.87k | case FRV_OPERAND_GRDOUBLEK : |
262 | 6.87k | print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRk, 0); |
263 | 6.87k | break; |
264 | 77.0k | case FRV_OPERAND_GRI : |
265 | 77.0k | print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRi, 0); |
266 | 77.0k | break; |
267 | 31.0k | case FRV_OPERAND_GRJ : |
268 | 31.0k | print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRj, 0); |
269 | 31.0k | break; |
270 | 53.2k | case FRV_OPERAND_GRK : |
271 | 53.2k | print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRk, 0); |
272 | 53.2k | break; |
273 | 553 | case FRV_OPERAND_GRKHI : |
274 | 553 | print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRk, 0); |
275 | 553 | break; |
276 | 532 | case FRV_OPERAND_GRKLO : |
277 | 532 | print_keyword (cd, info, & frv_cgen_opval_gr_names, fields->f_GRk, 0); |
278 | 532 | break; |
279 | 13.7k | case FRV_OPERAND_ICCI_1 : |
280 | 13.7k | print_keyword (cd, info, & frv_cgen_opval_iccr_names, fields->f_ICCi_1, 0); |
281 | 13.7k | break; |
282 | 3.65k | case FRV_OPERAND_ICCI_2 : |
283 | 3.65k | print_keyword (cd, info, & frv_cgen_opval_iccr_names, fields->f_ICCi_2, 0); |
284 | 3.65k | break; |
285 | 74 | case FRV_OPERAND_ICCI_3 : |
286 | 74 | print_keyword (cd, info, & frv_cgen_opval_iccr_names, fields->f_ICCi_3, 0); |
287 | 74 | break; |
288 | 0 | case FRV_OPERAND_LI : |
289 | 0 | print_normal (cd, info, fields->f_LI, 0, pc, length); |
290 | 0 | break; |
291 | 106 | case FRV_OPERAND_LRAD : |
292 | 106 | print_normal (cd, info, fields->f_LRAD, 0, pc, length); |
293 | 106 | break; |
294 | 106 | case FRV_OPERAND_LRAE : |
295 | 106 | print_normal (cd, info, fields->f_LRAE, 0, pc, length); |
296 | 106 | break; |
297 | 106 | case FRV_OPERAND_LRAS : |
298 | 106 | print_normal (cd, info, fields->f_LRAS, 0, pc, length); |
299 | 106 | break; |
300 | 12 | case FRV_OPERAND_TLBPRL : |
301 | 12 | print_normal (cd, info, fields->f_TLBPRL, 0, pc, length); |
302 | 12 | break; |
303 | 12 | case FRV_OPERAND_TLBPROPX : |
304 | 12 | print_normal (cd, info, fields->f_TLBPRopx, 0, pc, length); |
305 | 12 | break; |
306 | 116 | case FRV_OPERAND_AE : |
307 | 116 | print_normal (cd, info, fields->f_ae, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
308 | 116 | break; |
309 | 60 | case FRV_OPERAND_CALLANN : |
310 | 60 | print_at (cd, info, fields->f_reloc_ann, 0, pc, length); |
311 | 60 | break; |
312 | 11 | case FRV_OPERAND_CCOND : |
313 | 11 | print_normal (cd, info, fields->f_ccond, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
314 | 11 | break; |
315 | 14.6k | case FRV_OPERAND_COND : |
316 | 14.6k | print_normal (cd, info, fields->f_cond, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
317 | 14.6k | break; |
318 | 26.1k | case FRV_OPERAND_D12 : |
319 | 26.1k | print_normal (cd, info, fields->f_d12, 0|(1<<CGEN_OPERAND_SIGNED), pc, length); |
320 | 26.1k | break; |
321 | 51 | case FRV_OPERAND_DEBUG : |
322 | 51 | print_normal (cd, info, fields->f_debug, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
323 | 51 | break; |
324 | 11 | case FRV_OPERAND_EIR : |
325 | 11 | print_normal (cd, info, fields->f_eir, 0, pc, length); |
326 | 11 | break; |
327 | 1.12k | case FRV_OPERAND_HINT : |
328 | 1.12k | print_normal (cd, info, fields->f_hint, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
329 | 1.12k | break; |
330 | 53 | case FRV_OPERAND_HINT_NOT_TAKEN : |
331 | 53 | print_keyword (cd, info, & frv_cgen_opval_h_hint_not_taken, fields->f_hint, 0); |
332 | 53 | break; |
333 | 82 | case FRV_OPERAND_HINT_TAKEN : |
334 | 82 | print_keyword (cd, info, & frv_cgen_opval_h_hint_taken, fields->f_hint, 0); |
335 | 82 | break; |
336 | 1.19k | case FRV_OPERAND_LABEL16 : |
337 | 1.19k | print_address (cd, info, fields->f_label16, 0|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length); |
338 | 1.19k | break; |
339 | 1.00k | case FRV_OPERAND_LABEL24 : |
340 | 1.00k | print_address (cd, info, fields->f_label24, 0|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_VIRTUAL), pc, length); |
341 | 1.00k | break; |
342 | 111 | case FRV_OPERAND_LDANN : |
343 | 111 | print_at (cd, info, fields->f_reloc_ann, 0, pc, length); |
344 | 111 | break; |
345 | 46 | case FRV_OPERAND_LDDANN : |
346 | 46 | print_at (cd, info, fields->f_reloc_ann, 0, pc, length); |
347 | 46 | break; |
348 | 131 | case FRV_OPERAND_LOCK : |
349 | 131 | print_normal (cd, info, fields->f_lock, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
350 | 131 | break; |
351 | 99.1k | case FRV_OPERAND_PACK : |
352 | 99.1k | print_keyword (cd, info, & frv_cgen_opval_h_pack, fields->f_pack, 0); |
353 | 99.1k | break; |
354 | 8.37k | case FRV_OPERAND_S10 : |
355 | 8.37k | print_normal (cd, info, fields->f_s10, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
356 | 8.37k | break; |
357 | 11.4k | case FRV_OPERAND_S12 : |
358 | 11.4k | print_normal (cd, info, fields->f_d12, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
359 | 11.4k | break; |
360 | 0 | case FRV_OPERAND_S16 : |
361 | 0 | print_normal (cd, info, fields->f_s16, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
362 | 0 | break; |
363 | 58 | case FRV_OPERAND_S5 : |
364 | 58 | print_normal (cd, info, fields->f_s5, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
365 | 58 | break; |
366 | 195 | case FRV_OPERAND_S6 : |
367 | 195 | print_normal (cd, info, fields->f_s6, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
368 | 195 | break; |
369 | 9.98k | case FRV_OPERAND_S6_1 : |
370 | 9.98k | print_normal (cd, info, fields->f_s6_1, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
371 | 9.98k | break; |
372 | 1.74k | case FRV_OPERAND_SLO16 : |
373 | 1.74k | print_lo (cd, info, fields->f_s16, 0|(1<<CGEN_OPERAND_SIGNED), pc, length); |
374 | 1.74k | break; |
375 | 164 | case FRV_OPERAND_SPR : |
376 | 164 | print_spr (cd, info, & frv_cgen_opval_spr_names, fields->f_spr, 0|(1<<CGEN_OPERAND_VIRTUAL)); |
377 | 164 | break; |
378 | 247 | case FRV_OPERAND_U12 : |
379 | 247 | print_normal (cd, info, fields->f_u12, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_VIRTUAL), pc, length); |
380 | 247 | break; |
381 | 0 | case FRV_OPERAND_U16 : |
382 | 0 | print_normal (cd, info, fields->f_u16, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
383 | 0 | break; |
384 | 482 | case FRV_OPERAND_U6 : |
385 | 482 | print_normal (cd, info, fields->f_u6, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length); |
386 | 482 | break; |
387 | 553 | case FRV_OPERAND_UHI16 : |
388 | 553 | print_hi (cd, info, fields->f_u16, 0, pc, length); |
389 | 553 | break; |
390 | 532 | case FRV_OPERAND_ULO16 : |
391 | 532 | print_lo (cd, info, fields->f_u16, 0, pc, length); |
392 | 532 | break; |
393 | | |
394 | 0 | default : |
395 | | /* xgettext:c-format */ |
396 | 0 | opcodes_error_handler |
397 | 0 | (_("internal error: unrecognized field %d while printing insn"), |
398 | 0 | opindex); |
399 | 0 | abort (); |
400 | 442k | } |
401 | 442k | } |
402 | | |
403 | | cgen_print_fn * const frv_cgen_print_handlers[] = |
404 | | { |
405 | | print_insn_normal, |
406 | | }; |
407 | | |
408 | | |
409 | | void |
410 | | frv_cgen_init_dis (CGEN_CPU_DESC cd) |
411 | 7 | { |
412 | 7 | frv_cgen_init_opcode_table (cd); |
413 | 7 | frv_cgen_init_ibld_table (cd); |
414 | 7 | cd->print_handlers = & frv_cgen_print_handlers[0]; |
415 | 7 | cd->print_operand = frv_cgen_print_operand; |
416 | 7 | } |
417 | | |
418 | | |
419 | | /* Default print handler. */ |
420 | | |
421 | | static void |
422 | | print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
423 | | void *dis_info, |
424 | | long value, |
425 | | unsigned int attrs, |
426 | | bfd_vma pc ATTRIBUTE_UNUSED, |
427 | | int length ATTRIBUTE_UNUSED) |
428 | 73.3k | { |
429 | 73.3k | disassemble_info *info = (disassemble_info *) dis_info; |
430 | | |
431 | | /* Print the operand as directed by the attributes. */ |
432 | 73.3k | if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY)) |
433 | 0 | ; /* nothing to do */ |
434 | 73.3k | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED)) |
435 | 56.4k | (*info->fprintf_func) (info->stream, "%ld", value); |
436 | 16.8k | else |
437 | 16.8k | (*info->fprintf_func) (info->stream, "0x%lx", value); |
438 | 73.3k | } |
439 | | |
440 | | /* Default address handler. */ |
441 | | |
442 | | static void |
443 | | print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
444 | | void *dis_info, |
445 | | bfd_vma value, |
446 | | unsigned int attrs, |
447 | | bfd_vma pc ATTRIBUTE_UNUSED, |
448 | | int length ATTRIBUTE_UNUSED) |
449 | 2.19k | { |
450 | 2.19k | disassemble_info *info = (disassemble_info *) dis_info; |
451 | | |
452 | | /* Print the operand as directed by the attributes. */ |
453 | 2.19k | if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY)) |
454 | 0 | ; /* Nothing to do. */ |
455 | 2.19k | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR)) |
456 | 2.19k | (*info->print_address_func) (value, info); |
457 | 0 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR)) |
458 | 0 | (*info->print_address_func) (value, info); |
459 | 0 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED)) |
460 | 0 | (*info->fprintf_func) (info->stream, "%ld", (long) value); |
461 | 0 | else |
462 | 0 | (*info->fprintf_func) (info->stream, "0x%lx", (long) value); |
463 | 2.19k | } |
464 | | |
465 | | /* Keyword print handler. */ |
466 | | |
467 | | static void |
468 | | print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
469 | | void *dis_info, |
470 | | CGEN_KEYWORD *keyword_table, |
471 | | long value, |
472 | | unsigned int attrs ATTRIBUTE_UNUSED) |
473 | 364k | { |
474 | 364k | disassemble_info *info = (disassemble_info *) dis_info; |
475 | 364k | const CGEN_KEYWORD_ENTRY *ke; |
476 | | |
477 | 364k | ke = cgen_keyword_lookup_value (keyword_table, value); |
478 | 364k | if (ke != NULL) |
479 | 364k | (*info->fprintf_func) (info->stream, "%s", ke->name); |
480 | 0 | else |
481 | 0 | (*info->fprintf_func) (info->stream, "???"); |
482 | 364k | } |
483 | | |
484 | | /* Default insn printer. |
485 | | |
486 | | DIS_INFO is defined as `void *' so the disassembler needn't know anything |
487 | | about disassemble_info. */ |
488 | | |
489 | | static void |
490 | | print_insn_normal (CGEN_CPU_DESC cd, |
491 | | void *dis_info, |
492 | | const CGEN_INSN *insn, |
493 | | CGEN_FIELDS *fields, |
494 | | bfd_vma pc, |
495 | | int length) |
496 | 99.1k | { |
497 | 99.1k | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn); |
498 | 99.1k | disassemble_info *info = (disassemble_info *) dis_info; |
499 | 99.1k | const CGEN_SYNTAX_CHAR_TYPE *syn; |
500 | | |
501 | 99.1k | CGEN_INIT_PRINT (cd); |
502 | | |
503 | 1.08M | for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn) |
504 | 986k | { |
505 | 986k | if (CGEN_SYNTAX_MNEMONIC_P (*syn)) |
506 | 99.1k | { |
507 | 99.1k | (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn)); |
508 | 99.1k | continue; |
509 | 99.1k | } |
510 | 887k | if (CGEN_SYNTAX_CHAR_P (*syn)) |
511 | 444k | { |
512 | 444k | (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn)); |
513 | 444k | continue; |
514 | 444k | } |
515 | | |
516 | | /* We have an operand. */ |
517 | 442k | frv_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info, |
518 | 442k | fields, CGEN_INSN_ATTRS (insn), pc, length); |
519 | 442k | } |
520 | 99.1k | } |
521 | | |
522 | | /* Subroutine of print_insn. Reads an insn into the given buffers and updates |
523 | | the extract info. |
524 | | Returns 0 if all is well, non-zero otherwise. */ |
525 | | |
526 | | static int |
527 | | read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, |
528 | | bfd_vma pc, |
529 | | disassemble_info *info, |
530 | | bfd_byte *buf, |
531 | | int buflen, |
532 | | CGEN_EXTRACT_INFO *ex_info, |
533 | | unsigned long *insn_value) |
534 | 0 | { |
535 | 0 | int status = (*info->read_memory_func) (pc, buf, buflen, info); |
536 | |
|
537 | 0 | if (status != 0) |
538 | 0 | { |
539 | 0 | (*info->memory_error_func) (status, pc, info); |
540 | 0 | return -1; |
541 | 0 | } |
542 | | |
543 | 0 | ex_info->dis_info = info; |
544 | 0 | ex_info->valid = (1 << buflen) - 1; |
545 | 0 | ex_info->insn_bytes = buf; |
546 | |
|
547 | 0 | *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG); |
548 | 0 | return 0; |
549 | 0 | } |
550 | | |
551 | | /* Utility to print an insn. |
552 | | BUF is the base part of the insn, target byte order, BUFLEN bytes long. |
553 | | The result is the size of the insn in bytes or zero for an unknown insn |
554 | | or -1 if an error occurs fetching data (memory_error_func will have |
555 | | been called). */ |
556 | | |
557 | | static int |
558 | | print_insn (CGEN_CPU_DESC cd, |
559 | | bfd_vma pc, |
560 | | disassemble_info *info, |
561 | | bfd_byte *buf, |
562 | | unsigned int buflen) |
563 | 124k | { |
564 | 124k | CGEN_INSN_INT insn_value; |
565 | 124k | const CGEN_INSN_LIST *insn_list; |
566 | 124k | CGEN_EXTRACT_INFO ex_info; |
567 | 124k | int basesize; |
568 | | |
569 | | /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */ |
570 | 124k | basesize = cd->base_insn_bitsize < buflen * 8 ? |
571 | 124k | cd->base_insn_bitsize : buflen * 8; |
572 | 124k | insn_value = cgen_get_insn_value (cd, buf, basesize, cd->insn_endian); |
573 | | |
574 | | |
575 | | /* Fill in ex_info fields like read_insn would. Don't actually call |
576 | | read_insn, since the incoming buffer is already read (and possibly |
577 | | modified a la m32r). */ |
578 | 124k | ex_info.valid = (1 << buflen) - 1; |
579 | 124k | ex_info.dis_info = info; |
580 | 124k | ex_info.insn_bytes = buf; |
581 | | |
582 | | /* The instructions are stored in hash lists. |
583 | | Pick the first one and keep trying until we find the right one. */ |
584 | | |
585 | 124k | insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value); |
586 | 747k | while (insn_list != NULL) |
587 | 722k | { |
588 | 722k | const CGEN_INSN *insn = insn_list->insn; |
589 | 722k | CGEN_FIELDS fields; |
590 | 722k | int length; |
591 | 722k | unsigned long insn_value_cropped; |
592 | | |
593 | | #ifdef CGEN_VALIDATE_INSN_SUPPORTED |
594 | | /* Not needed as insn shouldn't be in hash lists if not supported. */ |
595 | | /* Supported by this cpu? */ |
596 | | if (! frv_cgen_insn_supported (cd, insn)) |
597 | | { |
598 | | insn_list = CGEN_DIS_NEXT_INSN (insn_list); |
599 | | continue; |
600 | | } |
601 | | #endif |
602 | | |
603 | | /* Basic bit mask must be correct. */ |
604 | | /* ??? May wish to allow target to defer this check until the extract |
605 | | handler. */ |
606 | | |
607 | | /* Base size may exceed this instruction's size. Extract the |
608 | | relevant part from the buffer. */ |
609 | 722k | if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen && |
610 | 722k | (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long)) |
611 | 0 | insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn), |
612 | 0 | info->endian == BFD_ENDIAN_BIG); |
613 | 722k | else |
614 | 722k | insn_value_cropped = insn_value; |
615 | | |
616 | 722k | if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn)) |
617 | 722k | == CGEN_INSN_BASE_VALUE (insn)) |
618 | 99.1k | { |
619 | | /* Printing is handled in two passes. The first pass parses the |
620 | | machine insn and extracts the fields. The second pass prints |
621 | | them. */ |
622 | | |
623 | | /* Make sure the entire insn is loaded into insn_value, if it |
624 | | can fit. */ |
625 | 99.1k | if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) && |
626 | 99.1k | (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long)) |
627 | 0 | { |
628 | 0 | unsigned long full_insn_value; |
629 | 0 | int rc = read_insn (cd, pc, info, buf, |
630 | 0 | CGEN_INSN_BITSIZE (insn) / 8, |
631 | 0 | & ex_info, & full_insn_value); |
632 | 0 | if (rc != 0) |
633 | 0 | return rc; |
634 | 0 | length = CGEN_EXTRACT_FN (cd, insn) |
635 | 0 | (cd, insn, &ex_info, full_insn_value, &fields, pc); |
636 | 0 | } |
637 | 99.1k | else |
638 | 99.1k | length = CGEN_EXTRACT_FN (cd, insn) |
639 | 99.1k | (cd, insn, &ex_info, insn_value_cropped, &fields, pc); |
640 | | |
641 | | /* Length < 0 -> error. */ |
642 | 99.1k | if (length < 0) |
643 | 0 | return length; |
644 | 99.1k | if (length > 0) |
645 | 99.1k | { |
646 | 99.1k | CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length); |
647 | | /* Length is in bits, result is in bytes. */ |
648 | 99.1k | return length / 8; |
649 | 99.1k | } |
650 | 99.1k | } |
651 | | |
652 | 622k | insn_list = CGEN_DIS_NEXT_INSN (insn_list); |
653 | 622k | } |
654 | | |
655 | 24.9k | return 0; |
656 | 124k | } |
657 | | |
658 | | /* Default value for CGEN_PRINT_INSN. |
659 | | The result is the size of the insn in bytes or zero for an unknown insn |
660 | | or -1 if an error occured fetching bytes. */ |
661 | | |
662 | | #ifndef CGEN_PRINT_INSN |
663 | 124k | #define CGEN_PRINT_INSN default_print_insn |
664 | | #endif |
665 | | |
666 | | static int |
667 | | default_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info) |
668 | 124k | { |
669 | 124k | bfd_byte buf[CGEN_MAX_INSN_SIZE]; |
670 | 124k | int buflen; |
671 | 124k | int status; |
672 | | |
673 | | /* Attempt to read the base part of the insn. */ |
674 | 124k | buflen = cd->base_insn_bitsize / 8; |
675 | 124k | status = (*info->read_memory_func) (pc, buf, buflen, info); |
676 | | |
677 | | /* Try again with the minimum part, if min < base. */ |
678 | 124k | if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize)) |
679 | 0 | { |
680 | 0 | buflen = cd->min_insn_bitsize / 8; |
681 | 0 | status = (*info->read_memory_func) (pc, buf, buflen, info); |
682 | 0 | } |
683 | | |
684 | 124k | if (status != 0) |
685 | 308 | { |
686 | 308 | (*info->memory_error_func) (status, pc, info); |
687 | 308 | return -1; |
688 | 308 | } |
689 | | |
690 | 124k | return print_insn (cd, pc, info, buf, buflen); |
691 | 124k | } |
692 | | |
693 | | /* Main entry point. |
694 | | Print one instruction from PC on INFO->STREAM. |
695 | | Return the size of the instruction (in bytes). */ |
696 | | |
697 | | typedef struct cpu_desc_list |
698 | | { |
699 | | struct cpu_desc_list *next; |
700 | | CGEN_BITSET *isa; |
701 | | int mach; |
702 | | int endian; |
703 | | int insn_endian; |
704 | | CGEN_CPU_DESC cd; |
705 | | } cpu_desc_list; |
706 | | |
707 | | int |
708 | | print_insn_frv (bfd_vma pc, disassemble_info *info) |
709 | 124k | { |
710 | 124k | static cpu_desc_list *cd_list = 0; |
711 | 124k | cpu_desc_list *cl = 0; |
712 | 124k | static CGEN_CPU_DESC cd = 0; |
713 | 124k | static CGEN_BITSET *prev_isa; |
714 | 124k | static int prev_mach; |
715 | 124k | static int prev_endian; |
716 | 124k | static int prev_insn_endian; |
717 | 124k | int length; |
718 | 124k | CGEN_BITSET *isa; |
719 | 124k | int mach; |
720 | 124k | int endian = (info->endian == BFD_ENDIAN_BIG |
721 | 124k | ? CGEN_ENDIAN_BIG |
722 | 124k | : CGEN_ENDIAN_LITTLE); |
723 | 124k | int insn_endian = (info->endian_code == BFD_ENDIAN_BIG |
724 | 124k | ? CGEN_ENDIAN_BIG |
725 | 124k | : CGEN_ENDIAN_LITTLE); |
726 | 124k | enum bfd_architecture arch; |
727 | | |
728 | | /* ??? gdb will set mach but leave the architecture as "unknown" */ |
729 | 124k | #ifndef CGEN_BFD_ARCH |
730 | 124k | #define CGEN_BFD_ARCH bfd_arch_frv |
731 | 124k | #endif |
732 | 124k | arch = info->arch; |
733 | 124k | if (arch == bfd_arch_unknown) |
734 | 0 | arch = CGEN_BFD_ARCH; |
735 | | |
736 | | /* There's no standard way to compute the machine or isa number |
737 | | so we leave it to the target. */ |
738 | | #ifdef CGEN_COMPUTE_MACH |
739 | | mach = CGEN_COMPUTE_MACH (info); |
740 | | #else |
741 | 124k | mach = info->mach; |
742 | 124k | #endif |
743 | | |
744 | | #ifdef CGEN_COMPUTE_ISA |
745 | | { |
746 | | static CGEN_BITSET *permanent_isa; |
747 | | |
748 | | if (!permanent_isa) |
749 | | permanent_isa = cgen_bitset_create (MAX_ISAS); |
750 | | isa = permanent_isa; |
751 | | cgen_bitset_clear (isa); |
752 | | cgen_bitset_add (isa, CGEN_COMPUTE_ISA (info)); |
753 | | } |
754 | | #else |
755 | 124k | isa = info->private_data; |
756 | 124k | #endif |
757 | | |
758 | | /* If we've switched cpu's, try to find a handle we've used before */ |
759 | 124k | if (cd |
760 | 124k | && (cgen_bitset_compare (isa, prev_isa) != 0 |
761 | 124k | || mach != prev_mach |
762 | 124k | || endian != prev_endian)) |
763 | 124k | { |
764 | 124k | cd = 0; |
765 | 812k | for (cl = cd_list; cl; cl = cl->next) |
766 | 812k | { |
767 | 812k | if (cgen_bitset_compare (cl->isa, isa) == 0 && |
768 | 812k | cl->mach == mach && |
769 | 812k | cl->endian == endian) |
770 | 124k | { |
771 | 124k | cd = cl->cd; |
772 | 124k | prev_isa = cd->isas; |
773 | 124k | break; |
774 | 124k | } |
775 | 812k | } |
776 | 124k | } |
777 | | |
778 | | /* If we haven't initialized yet, initialize the opcode table. */ |
779 | 124k | if (! cd) |
780 | 7 | { |
781 | 7 | const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach); |
782 | 7 | const char *mach_name; |
783 | | |
784 | 7 | if (!arch_type) |
785 | 0 | abort (); |
786 | 7 | mach_name = arch_type->printable_name; |
787 | | |
788 | 7 | prev_isa = cgen_bitset_copy (isa); |
789 | 7 | prev_mach = mach; |
790 | 7 | prev_endian = endian; |
791 | 7 | prev_insn_endian = insn_endian; |
792 | 7 | cd = frv_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa, |
793 | 7 | CGEN_CPU_OPEN_BFDMACH, mach_name, |
794 | 7 | CGEN_CPU_OPEN_ENDIAN, prev_endian, |
795 | 7 | CGEN_CPU_OPEN_INSN_ENDIAN, prev_insn_endian, |
796 | 7 | CGEN_CPU_OPEN_END); |
797 | 7 | if (!cd) |
798 | 0 | abort (); |
799 | | |
800 | | /* Save this away for future reference. */ |
801 | 7 | cl = xmalloc (sizeof (struct cpu_desc_list)); |
802 | 7 | cl->cd = cd; |
803 | 7 | cl->isa = prev_isa; |
804 | 7 | cl->mach = mach; |
805 | 7 | cl->endian = endian; |
806 | 7 | cl->next = cd_list; |
807 | 7 | cd_list = cl; |
808 | | |
809 | 7 | frv_cgen_init_dis (cd); |
810 | 7 | } |
811 | | |
812 | | /* We try to have as much common code as possible. |
813 | | But at this point some targets need to take over. */ |
814 | | /* ??? Some targets may need a hook elsewhere. Try to avoid this, |
815 | | but if not possible try to move this hook elsewhere rather than |
816 | | have two hooks. */ |
817 | 124k | length = CGEN_PRINT_INSN (cd, pc, info); |
818 | 124k | if (length > 0) |
819 | 99.1k | return length; |
820 | 25.2k | if (length < 0) |
821 | 308 | return -1; |
822 | | |
823 | 24.9k | (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG); |
824 | 24.9k | return cd->default_insn_bitsize / 8; |
825 | 25.2k | } |