1 | /* Disassembler interface for targets using CGEN. -*- C -*-
|
---|
2 | CGEN: Cpu tools GENerator
|
---|
3 |
|
---|
4 | THIS FILE IS MACHINE GENERATED WITH CGEN.
|
---|
5 | - the resultant file is machine generated, cgen-dis.in isn't
|
---|
6 |
|
---|
7 | Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
---|
8 |
|
---|
9 | This file is part of the GNU Binutils and GDB, the GNU debugger.
|
---|
10 |
|
---|
11 | This program is free software; you can redistribute it and/or modify
|
---|
12 | it under the terms of the GNU General Public License as published by
|
---|
13 | the Free Software Foundation; either version 2, or (at your option)
|
---|
14 | any later version.
|
---|
15 |
|
---|
16 | This program is distributed in the hope that it will be useful,
|
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | GNU General Public License for more details.
|
---|
20 |
|
---|
21 | You should have received a copy of the GNU General Public License
|
---|
22 | along with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
23 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
24 |
|
---|
25 | /* ??? Eventually more and more of this stuff can go to cpu-independent files.
|
---|
26 | Keep that in mind. */
|
---|
27 |
|
---|
28 | #include "sysdep.h"
|
---|
29 | #include <stdio.h>
|
---|
30 | #include "ansidecl.h"
|
---|
31 | #include "dis-asm.h"
|
---|
32 | #include "bfd.h"
|
---|
33 | #include "symcat.h"
|
---|
34 | #include "m32r-desc.h"
|
---|
35 | #include "m32r-opc.h"
|
---|
36 | #include "opintl.h"
|
---|
37 |
|
---|
38 | /* Default text to print if an instruction isn't recognized. */
|
---|
39 | #define UNKNOWN_INSN_MSG _("*unknown*")
|
---|
40 |
|
---|
41 | static void print_normal
|
---|
42 | PARAMS ((CGEN_CPU_DESC, PTR, long, unsigned int, bfd_vma, int));
|
---|
43 | static void print_address
|
---|
44 | PARAMS ((CGEN_CPU_DESC, PTR, bfd_vma, unsigned int, bfd_vma, int));
|
---|
45 | static void print_keyword
|
---|
46 | PARAMS ((CGEN_CPU_DESC, PTR, CGEN_KEYWORD *, long, unsigned int));
|
---|
47 | static void print_insn_normal
|
---|
48 | PARAMS ((CGEN_CPU_DESC, PTR, const CGEN_INSN *, CGEN_FIELDS *,
|
---|
49 | bfd_vma, int));
|
---|
50 | static int print_insn PARAMS ((CGEN_CPU_DESC, bfd_vma,
|
---|
51 | disassemble_info *, char *, int));
|
---|
52 | static int default_print_insn
|
---|
53 | PARAMS ((CGEN_CPU_DESC, bfd_vma, disassemble_info *));
|
---|
54 | |
---|
55 |
|
---|
56 | /* -- disassembler routines inserted here */
|
---|
57 |
|
---|
58 | /* -- dis.c */
|
---|
59 |
|
---|
60 | /* Immediate values are prefixed with '#'. */
|
---|
61 |
|
---|
62 | #define CGEN_PRINT_NORMAL(cd, info, value, attrs, pc, length) \
|
---|
63 | do { \
|
---|
64 | if (CGEN_BOOL_ATTR ((attrs), CGEN_OPERAND_HASH_PREFIX)) \
|
---|
65 | (*info->fprintf_func) (info->stream, "#"); \
|
---|
66 | } while (0)
|
---|
67 |
|
---|
68 | /* Handle '#' prefixes as operands. */
|
---|
69 |
|
---|
70 | static void
|
---|
71 | print_hash (cd, dis_info, value, attrs, pc, length)
|
---|
72 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
73 | PTR dis_info;
|
---|
74 | long value ATTRIBUTE_UNUSED;
|
---|
75 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
76 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
77 | int length ATTRIBUTE_UNUSED;
|
---|
78 | {
|
---|
79 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
80 | (*info->fprintf_func) (info->stream, "#");
|
---|
81 | }
|
---|
82 |
|
---|
83 | #undef CGEN_PRINT_INSN
|
---|
84 | #define CGEN_PRINT_INSN my_print_insn
|
---|
85 |
|
---|
86 | static int
|
---|
87 | my_print_insn (cd, pc, info)
|
---|
88 | CGEN_CPU_DESC cd;
|
---|
89 | bfd_vma pc;
|
---|
90 | disassemble_info *info;
|
---|
91 | {
|
---|
92 | char buffer[CGEN_MAX_INSN_SIZE];
|
---|
93 | char *buf = buffer;
|
---|
94 | int status;
|
---|
95 | int buflen = (pc & 3) == 0 ? 4 : 2;
|
---|
96 |
|
---|
97 | /* Read the base part of the insn. */
|
---|
98 |
|
---|
99 | status = (*info->read_memory_func) (pc, buf, buflen, info);
|
---|
100 | if (status != 0)
|
---|
101 | {
|
---|
102 | (*info->memory_error_func) (status, pc, info);
|
---|
103 | return -1;
|
---|
104 | }
|
---|
105 |
|
---|
106 | /* 32 bit insn? */
|
---|
107 | if ((pc & 3) == 0 && (buf[0] & 0x80) != 0)
|
---|
108 | return print_insn (cd, pc, info, buf, buflen);
|
---|
109 |
|
---|
110 | /* Print the first insn. */
|
---|
111 | if ((pc & 3) == 0)
|
---|
112 | {
|
---|
113 | if (print_insn (cd, pc, info, buf, 2) == 0)
|
---|
114 | (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
|
---|
115 | buf += 2;
|
---|
116 | }
|
---|
117 |
|
---|
118 | if (buf[0] & 0x80)
|
---|
119 | {
|
---|
120 | /* Parallel. */
|
---|
121 | (*info->fprintf_func) (info->stream, " || ");
|
---|
122 | buf[0] &= 0x7f;
|
---|
123 | }
|
---|
124 | else
|
---|
125 | (*info->fprintf_func) (info->stream, " -> ");
|
---|
126 |
|
---|
127 | /* The "& 3" is to pass a consistent address.
|
---|
128 | Parallel insns arguably both begin on the word boundary.
|
---|
129 | Also, branch insns are calculated relative to the word boundary. */
|
---|
130 | if (print_insn (cd, pc & ~ (bfd_vma) 3, info, buf, 2) == 0)
|
---|
131 | (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
|
---|
132 |
|
---|
133 | return (pc & 3) ? 2 : 4;
|
---|
134 | }
|
---|
135 |
|
---|
136 | /* -- */
|
---|
137 |
|
---|
138 | /* Main entry point for printing operands.
|
---|
139 | XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
|
---|
140 | of dis-asm.h on cgen.h.
|
---|
141 |
|
---|
142 | This function is basically just a big switch statement. Earlier versions
|
---|
143 | used tables to look up the function to use, but
|
---|
144 | - if the table contains both assembler and disassembler functions then
|
---|
145 | the disassembler contains much of the assembler and vice-versa,
|
---|
146 | - there's a lot of inlining possibilities as things grow,
|
---|
147 | - using a switch statement avoids the function call overhead.
|
---|
148 |
|
---|
149 | This function could be moved into `print_insn_normal', but keeping it
|
---|
150 | separate makes clear the interface between `print_insn_normal' and each of
|
---|
151 | the handlers.
|
---|
152 | */
|
---|
153 |
|
---|
154 | void
|
---|
155 | m32r_cgen_print_operand (cd, opindex, xinfo, fields, attrs, pc, length)
|
---|
156 | CGEN_CPU_DESC cd;
|
---|
157 | int opindex;
|
---|
158 | PTR xinfo;
|
---|
159 | CGEN_FIELDS *fields;
|
---|
160 | void const *attrs ATTRIBUTE_UNUSED;
|
---|
161 | bfd_vma pc;
|
---|
162 | int length;
|
---|
163 | {
|
---|
164 | disassemble_info *info = (disassemble_info *) xinfo;
|
---|
165 |
|
---|
166 | switch (opindex)
|
---|
167 | {
|
---|
168 | case M32R_OPERAND_ACC :
|
---|
169 | print_keyword (cd, info, & m32r_cgen_opval_h_accums, fields->f_acc, 0);
|
---|
170 | break;
|
---|
171 | case M32R_OPERAND_ACCD :
|
---|
172 | print_keyword (cd, info, & m32r_cgen_opval_h_accums, fields->f_accd, 0);
|
---|
173 | break;
|
---|
174 | case M32R_OPERAND_ACCS :
|
---|
175 | print_keyword (cd, info, & m32r_cgen_opval_h_accums, fields->f_accs, 0);
|
---|
176 | break;
|
---|
177 | case M32R_OPERAND_DCR :
|
---|
178 | print_keyword (cd, info, & m32r_cgen_opval_cr_names, fields->f_r1, 0);
|
---|
179 | break;
|
---|
180 | case M32R_OPERAND_DISP16 :
|
---|
181 | print_address (cd, info, fields->f_disp16, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
|
---|
182 | break;
|
---|
183 | case M32R_OPERAND_DISP24 :
|
---|
184 | print_address (cd, info, fields->f_disp24, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
|
---|
185 | break;
|
---|
186 | case M32R_OPERAND_DISP8 :
|
---|
187 | print_address (cd, info, fields->f_disp8, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
|
---|
188 | break;
|
---|
189 | case M32R_OPERAND_DR :
|
---|
190 | print_keyword (cd, info, & m32r_cgen_opval_gr_names, fields->f_r1, 0);
|
---|
191 | break;
|
---|
192 | case M32R_OPERAND_HASH :
|
---|
193 | print_hash (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
|
---|
194 | break;
|
---|
195 | case M32R_OPERAND_HI16 :
|
---|
196 | print_normal (cd, info, fields->f_hi16, 0|(1<<CGEN_OPERAND_SIGN_OPT), pc, length);
|
---|
197 | break;
|
---|
198 | case M32R_OPERAND_IMM1 :
|
---|
199 | print_normal (cd, info, fields->f_imm1, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
|
---|
200 | break;
|
---|
201 | case M32R_OPERAND_SCR :
|
---|
202 | print_keyword (cd, info, & m32r_cgen_opval_cr_names, fields->f_r2, 0);
|
---|
203 | break;
|
---|
204 | case M32R_OPERAND_SIMM16 :
|
---|
205 | print_normal (cd, info, fields->f_simm16, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
|
---|
206 | break;
|
---|
207 | case M32R_OPERAND_SIMM8 :
|
---|
208 | print_normal (cd, info, fields->f_simm8, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
|
---|
209 | break;
|
---|
210 | case M32R_OPERAND_SLO16 :
|
---|
211 | print_normal (cd, info, fields->f_simm16, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
|
---|
212 | break;
|
---|
213 | case M32R_OPERAND_SR :
|
---|
214 | print_keyword (cd, info, & m32r_cgen_opval_gr_names, fields->f_r2, 0);
|
---|
215 | break;
|
---|
216 | case M32R_OPERAND_SRC1 :
|
---|
217 | print_keyword (cd, info, & m32r_cgen_opval_gr_names, fields->f_r1, 0);
|
---|
218 | break;
|
---|
219 | case M32R_OPERAND_SRC2 :
|
---|
220 | print_keyword (cd, info, & m32r_cgen_opval_gr_names, fields->f_r2, 0);
|
---|
221 | break;
|
---|
222 | case M32R_OPERAND_UIMM16 :
|
---|
223 | print_normal (cd, info, fields->f_uimm16, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
|
---|
224 | break;
|
---|
225 | case M32R_OPERAND_UIMM24 :
|
---|
226 | print_address (cd, info, fields->f_uimm24, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
|
---|
227 | break;
|
---|
228 | case M32R_OPERAND_UIMM4 :
|
---|
229 | print_normal (cd, info, fields->f_uimm4, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
|
---|
230 | break;
|
---|
231 | case M32R_OPERAND_UIMM5 :
|
---|
232 | print_normal (cd, info, fields->f_uimm5, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
|
---|
233 | break;
|
---|
234 | case M32R_OPERAND_ULO16 :
|
---|
235 | print_normal (cd, info, fields->f_uimm16, 0, pc, length);
|
---|
236 | break;
|
---|
237 |
|
---|
238 | default :
|
---|
239 | /* xgettext:c-format */
|
---|
240 | fprintf (stderr, _("Unrecognized field %d while printing insn.\n"),
|
---|
241 | opindex);
|
---|
242 | abort ();
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | cgen_print_fn * const m32r_cgen_print_handlers[] =
|
---|
247 | {
|
---|
248 | print_insn_normal,
|
---|
249 | };
|
---|
250 |
|
---|
251 |
|
---|
252 | void
|
---|
253 | m32r_cgen_init_dis (cd)
|
---|
254 | CGEN_CPU_DESC cd;
|
---|
255 | {
|
---|
256 | m32r_cgen_init_opcode_table (cd);
|
---|
257 | m32r_cgen_init_ibld_table (cd);
|
---|
258 | cd->print_handlers = & m32r_cgen_print_handlers[0];
|
---|
259 | cd->print_operand = m32r_cgen_print_operand;
|
---|
260 | }
|
---|
261 |
|
---|
262 | |
---|
263 |
|
---|
264 | /* Default print handler. */
|
---|
265 |
|
---|
266 | static void
|
---|
267 | print_normal (cd, dis_info, value, attrs, pc, length)
|
---|
268 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
269 | PTR dis_info;
|
---|
270 | long value;
|
---|
271 | unsigned int attrs;
|
---|
272 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
273 | int length ATTRIBUTE_UNUSED;
|
---|
274 | {
|
---|
275 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
276 |
|
---|
277 | #ifdef CGEN_PRINT_NORMAL
|
---|
278 | CGEN_PRINT_NORMAL (cd, info, value, attrs, pc, length);
|
---|
279 | #endif
|
---|
280 |
|
---|
281 | /* Print the operand as directed by the attributes. */
|
---|
282 | if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
|
---|
283 | ; /* nothing to do */
|
---|
284 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
|
---|
285 | (*info->fprintf_func) (info->stream, "%ld", value);
|
---|
286 | else
|
---|
287 | (*info->fprintf_func) (info->stream, "0x%lx", value);
|
---|
288 | }
|
---|
289 |
|
---|
290 | /* Default address handler. */
|
---|
291 |
|
---|
292 | static void
|
---|
293 | print_address (cd, dis_info, value, attrs, pc, length)
|
---|
294 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
295 | PTR dis_info;
|
---|
296 | bfd_vma value;
|
---|
297 | unsigned int attrs;
|
---|
298 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
299 | int length ATTRIBUTE_UNUSED;
|
---|
300 | {
|
---|
301 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
302 |
|
---|
303 | #ifdef CGEN_PRINT_ADDRESS
|
---|
304 | CGEN_PRINT_ADDRESS (cd, info, value, attrs, pc, length);
|
---|
305 | #endif
|
---|
306 |
|
---|
307 | /* Print the operand as directed by the attributes. */
|
---|
308 | if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
|
---|
309 | ; /* nothing to do */
|
---|
310 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
|
---|
311 | (*info->print_address_func) (value, info);
|
---|
312 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
|
---|
313 | (*info->print_address_func) (value, info);
|
---|
314 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
|
---|
315 | (*info->fprintf_func) (info->stream, "%ld", (long) value);
|
---|
316 | else
|
---|
317 | (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
|
---|
318 | }
|
---|
319 |
|
---|
320 | /* Keyword print handler. */
|
---|
321 |
|
---|
322 | static void
|
---|
323 | print_keyword (cd, dis_info, keyword_table, value, attrs)
|
---|
324 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
325 | PTR dis_info;
|
---|
326 | CGEN_KEYWORD *keyword_table;
|
---|
327 | long value;
|
---|
328 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
329 | {
|
---|
330 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
331 | const CGEN_KEYWORD_ENTRY *ke;
|
---|
332 |
|
---|
333 | ke = cgen_keyword_lookup_value (keyword_table, value);
|
---|
334 | if (ke != NULL)
|
---|
335 | (*info->fprintf_func) (info->stream, "%s", ke->name);
|
---|
336 | else
|
---|
337 | (*info->fprintf_func) (info->stream, "???");
|
---|
338 | }
|
---|
339 | |
---|
340 |
|
---|
341 | /* Default insn printer.
|
---|
342 |
|
---|
343 | DIS_INFO is defined as `PTR' so the disassembler needn't know anything
|
---|
344 | about disassemble_info. */
|
---|
345 |
|
---|
346 | static void
|
---|
347 | print_insn_normal (cd, dis_info, insn, fields, pc, length)
|
---|
348 | CGEN_CPU_DESC cd;
|
---|
349 | PTR dis_info;
|
---|
350 | const CGEN_INSN *insn;
|
---|
351 | CGEN_FIELDS *fields;
|
---|
352 | bfd_vma pc;
|
---|
353 | int length;
|
---|
354 | {
|
---|
355 | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
|
---|
356 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
357 | const unsigned char *syn;
|
---|
358 |
|
---|
359 | CGEN_INIT_PRINT (cd);
|
---|
360 |
|
---|
361 | for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
|
---|
362 | {
|
---|
363 | if (CGEN_SYNTAX_MNEMONIC_P (*syn))
|
---|
364 | {
|
---|
365 | (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
|
---|
366 | continue;
|
---|
367 | }
|
---|
368 | if (CGEN_SYNTAX_CHAR_P (*syn))
|
---|
369 | {
|
---|
370 | (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
|
---|
371 | continue;
|
---|
372 | }
|
---|
373 |
|
---|
374 | /* We have an operand. */
|
---|
375 | m32r_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
|
---|
376 | fields, CGEN_INSN_ATTRS (insn), pc, length);
|
---|
377 | }
|
---|
378 | }
|
---|
379 | |
---|
380 |
|
---|
381 | /* Subroutine of print_insn. Reads an insn into the given buffers and updates
|
---|
382 | the extract info.
|
---|
383 | Returns 0 if all is well, non-zero otherwise. */
|
---|
384 | static int
|
---|
385 | read_insn (cd, pc, info, buf, buflen, ex_info, insn_value)
|
---|
386 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
387 | bfd_vma pc;
|
---|
388 | disassemble_info *info;
|
---|
389 | char *buf;
|
---|
390 | int buflen;
|
---|
391 | CGEN_EXTRACT_INFO *ex_info;
|
---|
392 | unsigned long *insn_value;
|
---|
393 | {
|
---|
394 | int status = (*info->read_memory_func) (pc, buf, buflen, info);
|
---|
395 | if (status != 0)
|
---|
396 | {
|
---|
397 | (*info->memory_error_func) (status, pc, info);
|
---|
398 | return -1;
|
---|
399 | }
|
---|
400 |
|
---|
401 | ex_info->dis_info = info;
|
---|
402 | ex_info->valid = (1 << buflen) - 1;
|
---|
403 | ex_info->insn_bytes = buf;
|
---|
404 |
|
---|
405 | switch (buflen)
|
---|
406 | {
|
---|
407 | case 1:
|
---|
408 | *insn_value = buf[0];
|
---|
409 | break;
|
---|
410 | case 2:
|
---|
411 | *insn_value = info->endian == BFD_ENDIAN_BIG ? bfd_getb16 (buf) : bfd_getl16 (buf);
|
---|
412 | break;
|
---|
413 | case 4:
|
---|
414 | *insn_value = info->endian == BFD_ENDIAN_BIG ? bfd_getb32 (buf) : bfd_getl32 (buf);
|
---|
415 | break;
|
---|
416 | default:
|
---|
417 | abort ();
|
---|
418 | }
|
---|
419 |
|
---|
420 | return 0;
|
---|
421 | }
|
---|
422 |
|
---|
423 | /* Utility to print an insn.
|
---|
424 | BUF is the base part of the insn, target byte order, BUFLEN bytes long.
|
---|
425 | The result is the size of the insn in bytes or zero for an unknown insn
|
---|
426 | or -1 if an error occurs fetching data (memory_error_func will have
|
---|
427 | been called). */
|
---|
428 |
|
---|
429 | static int
|
---|
430 | print_insn (cd, pc, info, buf, buflen)
|
---|
431 | CGEN_CPU_DESC cd;
|
---|
432 | bfd_vma pc;
|
---|
433 | disassemble_info *info;
|
---|
434 | char *buf;
|
---|
435 | int buflen;
|
---|
436 | {
|
---|
437 | unsigned long insn_value;
|
---|
438 | const CGEN_INSN_LIST *insn_list;
|
---|
439 | CGEN_EXTRACT_INFO ex_info;
|
---|
440 | #if 0
|
---|
441 | int rc = read_insn (cd, pc, info, buf, buflen, & ex_info, & insn_value);
|
---|
442 | if (rc != 0)
|
---|
443 | return rc;
|
---|
444 | #else
|
---|
445 | ex_info.dis_info = info;
|
---|
446 | ex_info.valid = (1 << buflen) - 1;
|
---|
447 | ex_info.insn_bytes = buf;
|
---|
448 |
|
---|
449 | switch (buflen)
|
---|
450 | {
|
---|
451 | case 1:
|
---|
452 | insn_value = buf[0];
|
---|
453 | break;
|
---|
454 | case 2:
|
---|
455 | insn_value = info->endian == BFD_ENDIAN_BIG ? bfd_getb16 (buf) : bfd_getl16 (buf);
|
---|
456 | break;
|
---|
457 | case 4:
|
---|
458 | insn_value = info->endian == BFD_ENDIAN_BIG ? bfd_getb32 (buf) : bfd_getl32 (buf);
|
---|
459 | break;
|
---|
460 | default:
|
---|
461 | abort ();
|
---|
462 | }
|
---|
463 | #endif
|
---|
464 | /* The instructions are stored in hash lists.
|
---|
465 | Pick the first one and keep trying until we find the right one. */
|
---|
466 |
|
---|
467 | insn_list = CGEN_DIS_LOOKUP_INSN (cd, buf, insn_value);
|
---|
468 | while (insn_list != NULL)
|
---|
469 | {
|
---|
470 | const CGEN_INSN *insn = insn_list->insn;
|
---|
471 | CGEN_FIELDS fields;
|
---|
472 | int length;
|
---|
473 |
|
---|
474 | #ifdef CGEN_VALIDATE_INSN_SUPPORTED
|
---|
475 | /* not needed as insn shouldn't be in hash lists if not supported */
|
---|
476 | /* Supported by this cpu? */
|
---|
477 | if (! m32r_cgen_insn_supported (cd, insn))
|
---|
478 | {
|
---|
479 | insn_list = CGEN_DIS_NEXT_INSN (insn_list);
|
---|
480 | continue;
|
---|
481 | }
|
---|
482 | #endif
|
---|
483 |
|
---|
484 | /* Basic bit mask must be correct. */
|
---|
485 | /* ??? May wish to allow target to defer this check until the extract
|
---|
486 | handler. */
|
---|
487 | if ((insn_value & CGEN_INSN_BASE_MASK (insn))
|
---|
488 | == CGEN_INSN_BASE_VALUE (insn))
|
---|
489 | {
|
---|
490 | /* Printing is handled in two passes. The first pass parses the
|
---|
491 | machine insn and extracts the fields. The second pass prints
|
---|
492 | them. */
|
---|
493 |
|
---|
494 | /* Make sure the entire insn is loaded into insn_value, if it
|
---|
495 | can fit. */
|
---|
496 | if ((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize &&
|
---|
497 | (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
|
---|
498 | {
|
---|
499 | unsigned long full_insn_value;
|
---|
500 | int rc = read_insn (cd, pc, info, buf,
|
---|
501 | CGEN_INSN_BITSIZE (insn) / 8,
|
---|
502 | & ex_info, & full_insn_value);
|
---|
503 | if (rc != 0)
|
---|
504 | return rc;
|
---|
505 | length = CGEN_EXTRACT_FN (cd, insn)
|
---|
506 | (cd, insn, &ex_info, full_insn_value, &fields, pc);
|
---|
507 | }
|
---|
508 | else
|
---|
509 | length = CGEN_EXTRACT_FN (cd, insn)
|
---|
510 | (cd, insn, &ex_info, insn_value, &fields, pc);
|
---|
511 | /* length < 0 -> error */
|
---|
512 | if (length < 0)
|
---|
513 | return length;
|
---|
514 | if (length > 0)
|
---|
515 | {
|
---|
516 | CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
|
---|
517 | /* length is in bits, result is in bytes */
|
---|
518 | return length / 8;
|
---|
519 | }
|
---|
520 | }
|
---|
521 |
|
---|
522 | insn_list = CGEN_DIS_NEXT_INSN (insn_list);
|
---|
523 | }
|
---|
524 |
|
---|
525 | return 0;
|
---|
526 | }
|
---|
527 |
|
---|
528 | /* Default value for CGEN_PRINT_INSN.
|
---|
529 | The result is the size of the insn in bytes or zero for an unknown insn
|
---|
530 | or -1 if an error occured fetching bytes. */
|
---|
531 |
|
---|
532 | #ifndef CGEN_PRINT_INSN
|
---|
533 | #define CGEN_PRINT_INSN default_print_insn
|
---|
534 |
|
---|
535 | static int
|
---|
536 | default_print_insn (cd, pc, info)
|
---|
537 | CGEN_CPU_DESC cd;
|
---|
538 | bfd_vma pc;
|
---|
539 | disassemble_info *info;
|
---|
540 | {
|
---|
541 | char buf[CGEN_MAX_INSN_SIZE];
|
---|
542 | int status;
|
---|
543 |
|
---|
544 | /* Read the base part of the insn. */
|
---|
545 |
|
---|
546 | status = (*info->read_memory_func) (pc, buf, cd->base_insn_bitsize / 8, info);
|
---|
547 | if (status != 0)
|
---|
548 | {
|
---|
549 | (*info->memory_error_func) (status, pc, info);
|
---|
550 | return -1;
|
---|
551 | }
|
---|
552 |
|
---|
553 | return print_insn (cd, pc, info, buf, cd->base_insn_bitsize / 8);
|
---|
554 | }
|
---|
555 | #endif
|
---|
556 |
|
---|
557 | /* Main entry point.
|
---|
558 | Print one instruction from PC on INFO->STREAM.
|
---|
559 | Return the size of the instruction (in bytes). */
|
---|
560 |
|
---|
561 | int
|
---|
562 | print_insn_m32r (pc, info)
|
---|
563 | bfd_vma pc;
|
---|
564 | disassemble_info *info;
|
---|
565 | {
|
---|
566 | static CGEN_CPU_DESC cd = 0;
|
---|
567 | static int prev_isa;
|
---|
568 | static int prev_mach;
|
---|
569 | static int prev_endian;
|
---|
570 | int length;
|
---|
571 | int isa,mach;
|
---|
572 | int endian = (info->endian == BFD_ENDIAN_BIG
|
---|
573 | ? CGEN_ENDIAN_BIG
|
---|
574 | : CGEN_ENDIAN_LITTLE);
|
---|
575 | enum bfd_architecture arch;
|
---|
576 |
|
---|
577 | /* ??? gdb will set mach but leave the architecture as "unknown" */
|
---|
578 | #ifndef CGEN_BFD_ARCH
|
---|
579 | #define CGEN_BFD_ARCH bfd_arch_m32r
|
---|
580 | #endif
|
---|
581 | arch = info->arch;
|
---|
582 | if (arch == bfd_arch_unknown)
|
---|
583 | arch = CGEN_BFD_ARCH;
|
---|
584 |
|
---|
585 | /* There's no standard way to compute the isa number (e.g. for arm thumb)
|
---|
586 | so we leave it to the target. */
|
---|
587 | #ifdef CGEN_COMPUTE_ISA
|
---|
588 | isa = CGEN_COMPUTE_ISA (info);
|
---|
589 | #else
|
---|
590 | isa = 0;
|
---|
591 | #endif
|
---|
592 |
|
---|
593 | mach = info->mach;
|
---|
594 |
|
---|
595 | /* If we've switched cpu's, close the current table and open a new one. */
|
---|
596 | if (cd
|
---|
597 | && (isa != prev_isa
|
---|
598 | || mach != prev_mach
|
---|
599 | || endian != prev_endian))
|
---|
600 | {
|
---|
601 | m32r_cgen_cpu_close (cd);
|
---|
602 | cd = 0;
|
---|
603 | }
|
---|
604 |
|
---|
605 | /* If we haven't initialized yet, initialize the opcode table. */
|
---|
606 | if (! cd)
|
---|
607 | {
|
---|
608 | const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
|
---|
609 | const char *mach_name;
|
---|
610 |
|
---|
611 | if (!arch_type)
|
---|
612 | abort ();
|
---|
613 | mach_name = arch_type->printable_name;
|
---|
614 |
|
---|
615 | prev_isa = isa;
|
---|
616 | prev_mach = mach;
|
---|
617 | prev_endian = endian;
|
---|
618 | cd = m32r_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
|
---|
619 | CGEN_CPU_OPEN_BFDMACH, mach_name,
|
---|
620 | CGEN_CPU_OPEN_ENDIAN, prev_endian,
|
---|
621 | CGEN_CPU_OPEN_END);
|
---|
622 | if (!cd)
|
---|
623 | abort ();
|
---|
624 | m32r_cgen_init_dis (cd);
|
---|
625 | }
|
---|
626 |
|
---|
627 | /* We try to have as much common code as possible.
|
---|
628 | But at this point some targets need to take over. */
|
---|
629 | /* ??? Some targets may need a hook elsewhere. Try to avoid this,
|
---|
630 | but if not possible try to move this hook elsewhere rather than
|
---|
631 | have two hooks. */
|
---|
632 | length = CGEN_PRINT_INSN (cd, pc, info);
|
---|
633 | if (length > 0)
|
---|
634 | return length;
|
---|
635 | if (length < 0)
|
---|
636 | return -1;
|
---|
637 |
|
---|
638 | (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
|
---|
639 | return cd->default_insn_bitsize / 8;
|
---|
640 | }
|
---|