backout m32rx stuff, not ready to be checked in
[deliverable/binutils-gdb.git] / opcodes / m32r-dis.c
CommitLineData
9c03036a
DE
1/* Disassembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
3
4This file is used to generate m32r-dis.c.
5
6Copyright (C) 1996, 1997 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
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
23cf992f 24#include "sysdep.h"
9c03036a
DE
25#include <stdio.h>
26#include "ansidecl.h"
27#include "dis-asm.h"
9c03036a 28#include "bfd.h"
23cf992f 29#include "m32r-opc.h"
9c03036a
DE
30
31/* ??? The layout of this stuff is still work in progress.
32 For speed in assembly/disassembly, we use inline functions. That of course
33 will only work for GCC. When this stuff is finished, we can decide whether
34 to keep the inline functions (and only get the performance increase when
35 compiled with GCC), or switch to macros, or use something else.
36*/
37
38/* Default text to print if an instruction isn't recognized. */
39#define UNKNOWN_INSN_MSG "*unknown*"
40
41/* FIXME: Machine generate. */
42#ifndef CGEN_PCREL_OFFSET
43#define CGEN_PCREL_OFFSET 0
44#endif
45
46static int print_insn PARAMS ((bfd_vma, disassemble_info *, char *, int));
47
48static int extract_insn_normal
23cf992f 49 PARAMS ((const CGEN_INSN *, void *, cgen_insn_t, CGEN_FIELDS *));
9c03036a 50static void print_insn_normal
23cf992f 51 PARAMS ((void *, const CGEN_INSN *, CGEN_FIELDS *, bfd_vma, int));
9c03036a
DE
52\f
53/* Default extraction routine.
54
55 ATTRS is a mask of the boolean attributes. We only need `unsigned',
56 but for generality we take a bitmask of all of them. */
57
58static int
59extract_normal (buf_ctrl, insn_value, attrs, start, length, shift, total_length, valuep)
853713a7
DE
60 void *buf_ctrl;
61 cgen_insn_t insn_value;
9c03036a 62 unsigned int attrs;
853713a7
DE
63 int start, length, shift, total_length;
64 long *valuep;
9c03036a
DE
65{
66 long value;
67
68#ifdef CGEN_INT_INSN
69#if 0
70 value = ((insn_value >> (CGEN_BASE_INSN_BITSIZE - (start + length)))
71 & ((1 << length) - 1));
72#else
73 value = ((insn_value >> (total_length - (start + length)))
74 & ((1 << length) - 1));
75#endif
76 if (! (attrs & CGEN_ATTR_MASK (CGEN_OPERAND_UNSIGNED))
77 && (value & (1 << (length - 1))))
78 value -= 1 << length;
79#else
80 /* FIXME: unfinished */
81#endif
82
83 /* This is backwards as we undo the effects of insert_normal. */
84 if (shift < 0)
85 value >>= -shift;
86 else
87 value <<= shift;
88
853713a7 89 *valuep = value;
9c03036a
DE
90 return 1;
91}
92
93/* Default print handler. */
94
95static void
96print_normal (dis_info, value, attrs, pc, length)
853713a7
DE
97 void *dis_info;
98 long value;
99 unsigned int attrs;
9c03036a 100 unsigned long pc; /* FIXME: should be bfd_vma */
853713a7 101 int length;
9c03036a 102{
853713a7 103 disassemble_info *info = dis_info;
9c03036a
DE
104
105 /* Print the operand as directed by the attributes. */
106 if (attrs & CGEN_ATTR_MASK (CGEN_OPERAND_FAKE))
107 ; /* nothing to do (??? at least not yet) */
108 else if (attrs & CGEN_ATTR_MASK (CGEN_OPERAND_PCREL_ADDR))
109 (*info->print_address_func) (pc + CGEN_PCREL_OFFSET + value, info);
110 /* ??? Not all cases of this are currently caught. */
111 else if (attrs & CGEN_ATTR_MASK (CGEN_OPERAND_ABS_ADDR))
112 /* FIXME: Why & 0xffffffff? */
113 (*info->print_address_func) ((bfd_vma) value & 0xffffffff, info);
114 else if (attrs & CGEN_ATTR_MASK (CGEN_OPERAND_UNSIGNED))
115 (*info->fprintf_func) (info->stream, "0x%lx", value);
116 else
117 (*info->fprintf_func) (info->stream, "%ld", value);
118}
119
120/* Keyword print handler. */
121
122static void
123print_keyword (dis_info, keyword_table, value, attrs)
853713a7
DE
124 void *dis_info;
125 CGEN_KEYWORD *keyword_table;
126 long value;
127 CGEN_ATTR *attrs;
9c03036a 128{
853713a7
DE
129 disassemble_info *info = dis_info;
130 const CGEN_KEYWORD_ENTRY *ke;
9c03036a
DE
131
132 ke = cgen_keyword_lookup_value (keyword_table, value);
853713a7
DE
133 if (ke != NULL)
134 (*info->fprintf_func) (info->stream, "%s", ke->name);
135 else
136 (*info->fprintf_func) (info->stream, "???");
9c03036a
DE
137}
138\f
139/* -- disassembler routines inserted here */
853713a7
DE
140/* -- dis.c */
141
142#undef CGEN_PRINT_INSN
143#define CGEN_PRINT_INSN my_print_insn
144
145static int
146my_print_insn (pc, info, buf, buflen)
147 bfd_vma pc;
148 disassemble_info *info;
149 char *buf;
150 int buflen;
151{
152 /* 32 bit insn? */
153 if ((pc & 3) == 0 && (buf[0] & 0x80) != 0)
154 return print_insn (pc, info, buf, buflen);
155
156 /* Print the first insn. */
157 if ((pc & 3) == 0)
158 {
159 if (print_insn (pc, info, buf, 16) == 0)
160 (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
161 buf += 2;
162 }
163
164 if (buf[0] & 0x80)
165 {
166 /* Parallel. */
167 (*info->fprintf_func) (info->stream, " || ");
168 buf[0] &= 0x7f;
169 }
170 else
171 (*info->fprintf_func) (info->stream, " -> ");
172
173 /* The "& 3" is to ensure the branch address is computed correctly
174 [if it is a branch]. */
175 if (print_insn (pc & ~ (bfd_vma) 3, info, buf, 16) == 0)
176 (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
177
178 return (pc & 3) ? 2 : 4;
179}
180
181/* -- */
182
183/* Main entry point for operand extraction.
184
185 This function is basically just a big switch statement. Earlier versions
186 used tables to look up the function to use, but
187 - if the table contains both assembler and disassembler functions then
188 the disassembler contains much of the assembler and vice-versa,
189 - there's a lot of inlining possibilities as things grow,
190 - using a switch statement avoids the function call overhead.
191
192 This function could be moved into `print_insn_normal', but keeping it
193 separate makes clear the interface between `print_insn_normal' and each of
194 the handlers.
195*/
196
197CGEN_INLINE int
198m32r_cgen_extract_operand (opindex, buf_ctrl, insn_value, fields)
199 int opindex;
200 void * buf_ctrl;
201 cgen_insn_t insn_value;
202 CGEN_FIELDS * fields;
203{
204 int length;
205
206 switch (opindex)
207 {
208 case M32R_OPERAND_SR :
209 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_r2);
210 break;
211 case M32R_OPERAND_DR :
212 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_r1);
213 break;
214 case M32R_OPERAND_SRC1 :
215 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_r1);
216 break;
217 case M32R_OPERAND_SRC2 :
218 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_r2);
219 break;
220 case M32R_OPERAND_SCR :
221 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_r2);
222 break;
223 case M32R_OPERAND_DCR :
224 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_r1);
225 break;
226 case M32R_OPERAND_SIMM8 :
227 length = extract_normal (NULL /*FIXME*/, insn_value, 0, 8, 8, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_simm8);
228 break;
229 case M32R_OPERAND_SIMM16 :
230 length = extract_normal (NULL /*FIXME*/, insn_value, 0, 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_simm16);
231 break;
232 case M32R_OPERAND_UIMM4 :
233 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_uimm4);
234 break;
235 case M32R_OPERAND_UIMM5 :
236 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 11, 5, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_uimm5);
237 break;
238 case M32R_OPERAND_UIMM16 :
239 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_uimm16);
240 break;
241 case M32R_OPERAND_HI16 :
242 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_SIGN_OPT)|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_hi16);
243 break;
244 case M32R_OPERAND_SLO16 :
245 length = extract_normal (NULL /*FIXME*/, insn_value, 0, 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_simm16);
246 break;
247 case M32R_OPERAND_ULO16 :
248 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 16, 16, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_uimm16);
249 break;
250 case M32R_OPERAND_UIMM24 :
251 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR)|(1<<CGEN_OPERAND_UNSIGNED), 8, 24, 0, CGEN_FIELDS_BITSIZE (fields), & fields->f_uimm24);
252 break;
253 case M32R_OPERAND_DISP8 :
254 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 8, 8, 2, CGEN_FIELDS_BITSIZE (fields), & fields->f_disp8);
255 break;
256 case M32R_OPERAND_DISP16 :
257 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 16, 16, 2, CGEN_FIELDS_BITSIZE (fields), & fields->f_disp16);
258 break;
259 case M32R_OPERAND_DISP24 :
260 length = extract_normal (NULL /*FIXME*/, insn_value, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 8, 24, 2, CGEN_FIELDS_BITSIZE (fields), & fields->f_disp24);
261 break;
262
263 default :
264 fprintf (stderr, "Unrecognized field %d while decoding insn.\n",
265 opindex);
266 abort ();
267 }
268
269 return length;
270}
271
272/* Main entry point for printing operands.
273
274 This function is basically just a big switch statement. Earlier versions
275 used tables to look up the function to use, but
276 - if the table contains both assembler and disassembler functions then
277 the disassembler contains much of the assembler and vice-versa,
278 - there's a lot of inlining possibilities as things grow,
279 - using a switch statement avoids the function call overhead.
280
281 This function could be moved into `print_insn_normal', but keeping it
282 separate makes clear the interface between `print_insn_normal' and each of
283 the handlers.
284*/
285
286CGEN_INLINE void
287m32r_cgen_print_operand (opindex, info, fields, attrs, pc, length)
288 int opindex;
289 disassemble_info * info;
290 CGEN_FIELDS * fields;
291 void const * attrs;
292 bfd_vma pc;
293 int length;
294{
295 switch (opindex)
296 {
297 case M32R_OPERAND_SR :
298 print_keyword (info, & m32r_cgen_opval_h_gr, fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED));
299 break;
300 case M32R_OPERAND_DR :
301 print_keyword (info, & m32r_cgen_opval_h_gr, fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED));
302 break;
303 case M32R_OPERAND_SRC1 :
304 print_keyword (info, & m32r_cgen_opval_h_gr, fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED));
305 break;
306 case M32R_OPERAND_SRC2 :
307 print_keyword (info, & m32r_cgen_opval_h_gr, fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED));
308 break;
309 case M32R_OPERAND_SCR :
310 print_keyword (info, & m32r_cgen_opval_h_cr, fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED));
311 break;
312 case M32R_OPERAND_DCR :
313 print_keyword (info, & m32r_cgen_opval_h_cr, fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED));
314 break;
315 case M32R_OPERAND_SIMM8 :
316 print_normal (info, fields->f_simm8, 0, pc, length);
317 break;
318 case M32R_OPERAND_SIMM16 :
319 print_normal (info, fields->f_simm16, 0, pc, length);
320 break;
321 case M32R_OPERAND_UIMM4 :
322 print_normal (info, fields->f_uimm4, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
323 break;
324 case M32R_OPERAND_UIMM5 :
325 print_normal (info, fields->f_uimm5, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
326 break;
327 case M32R_OPERAND_UIMM16 :
328 print_normal (info, fields->f_uimm16, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
329 break;
330 case M32R_OPERAND_HI16 :
331 print_normal (info, fields->f_hi16, 0|(1<<CGEN_OPERAND_SIGN_OPT)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
332 break;
333 case M32R_OPERAND_SLO16 :
334 print_normal (info, fields->f_simm16, 0, pc, length);
335 break;
336 case M32R_OPERAND_ULO16 :
337 print_normal (info, fields->f_uimm16, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
338 break;
339 case M32R_OPERAND_UIMM24 :
340 print_normal (info, fields->f_uimm24, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
341 break;
342 case M32R_OPERAND_DISP8 :
343 print_normal (info, fields->f_disp8, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
344 break;
345 case M32R_OPERAND_DISP16 :
346 print_normal (info, fields->f_disp16, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
347 break;
348 case M32R_OPERAND_DISP24 :
349 print_normal (info, fields->f_disp24, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
350 break;
351
352 default :
353 fprintf (stderr, "Unrecognized field %d while printing insn.\n",
354 opindex);
355 abort ();
356 }
357}
358
359cgen_extract_fn * m32r_cgen_extract_handlers[] =
360{ 0, /* default */
361 extract_insn_normal,
362};
363
364cgen_print_fn * m32r_cgen_print_handlers[] =
365{ 0, /* default */
366 print_insn_normal,
367};
368
369
370void
371m32r_cgen_init_dis (mach, endian)
372 int mach;
373 enum cgen_endian endian;
374{
375 m32r_cgen_init_tables (mach);
376 cgen_set_cpu (& m32r_cgen_opcode_data, mach, endian);
377 cgen_dis_init ();
378}
379
9c03036a
DE
380\f
381/* Default insn extractor.
382
383 The extracted fields are stored in DIS_FLDS.
384 BUF_CTRL is used to handle reading variable length insns (FIXME: not done).
385 Return the length of the insn in bits, or 0 if no match. */
386
387static int
388extract_insn_normal (insn, buf_ctrl, insn_value, fields)
853713a7
DE
389 const CGEN_INSN *insn;
390 void *buf_ctrl;
391 cgen_insn_t insn_value;
392 CGEN_FIELDS *fields;
9c03036a 393{
853713a7
DE
394 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
395 const unsigned char *syn;
9c03036a 396
9c03036a
DE
397 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
398
399 CGEN_INIT_EXTRACT ();
400
853713a7 401 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
9c03036a
DE
402 {
403 int length;
404
853713a7 405 if (CGEN_SYNTAX_CHAR_P (*syn))
9c03036a
DE
406 continue;
407
853713a7 408 length = m32r_cgen_extract_operand (CGEN_SYNTAX_FIELD (*syn),
9c03036a
DE
409 buf_ctrl, insn_value, fields);
410 if (length == 0)
411 return 0;
412 }
413
23cf992f
NC
414 /* We recognized and successfully extracted this insn. */
415 return CGEN_INSN_BITSIZE (insn);
9c03036a
DE
416}
417
418/* Default insn printer.
419
420 DIS_INFO is defined as `void *' so the disassembler needn't know anything
421 about disassemble_info.
422*/
423
424static void
425print_insn_normal (dis_info, insn, fields, pc, length)
853713a7
DE
426 void *dis_info;
427 const CGEN_INSN *insn;
428 CGEN_FIELDS *fields;
429 bfd_vma pc;
430 int length;
9c03036a 431{
853713a7
DE
432 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
433 disassemble_info *info = dis_info;
434 const unsigned char *syn;
9c03036a
DE
435
436 CGEN_INIT_PRINT ();
437
853713a7 438 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
9c03036a 439 {
853713a7 440 if (CGEN_SYNTAX_MNEMONIC_P (*syn))
23cf992f 441 {
853713a7 442 (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
23cf992f
NC
443 continue;
444 }
853713a7 445 if (CGEN_SYNTAX_CHAR_P (*syn))
9c03036a 446 {
853713a7 447 (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
9c03036a
DE
448 continue;
449 }
450
451 /* We have an operand. */
853713a7 452 m32r_cgen_print_operand (CGEN_SYNTAX_FIELD (*syn), info,
9c03036a
DE
453 fields, CGEN_INSN_ATTRS (insn), pc, length);
454 }
455}
456\f
457/* Default value for CGEN_PRINT_INSN.
458 Given BUFLEN bytes (target byte order) read into BUF, look up the
459 insn in the instruction table and disassemble it.
460
461 The result is the size of the insn in bytes. */
462
463#ifndef CGEN_PRINT_INSN
464#define CGEN_PRINT_INSN print_insn
465#endif
466
467static int
468print_insn (pc, info, buf, buflen)
853713a7
DE
469 bfd_vma pc;
470 disassemble_info *info;
471 char *buf;
472 int buflen;
9c03036a 473{
853713a7
DE
474 int i;
475 unsigned long insn_value;
476 const CGEN_INSN_LIST *insn_list;
477
9c03036a
DE
478 switch (buflen)
479 {
480 case 8:
481 insn_value = buf[0];
482 break;
483 case 16:
484 insn_value = info->endian == BFD_ENDIAN_BIG ? bfd_getb16 (buf) : bfd_getl16 (buf);
485 break;
486 case 32:
487 insn_value = info->endian == BFD_ENDIAN_BIG ? bfd_getb32 (buf) : bfd_getl32 (buf);
488 break;
489 default:
490 abort ();
491 }
492
493 /* The instructions are stored in hash lists.
494 Pick the first one and keep trying until we find the right one. */
495
496 insn_list = CGEN_DIS_LOOKUP_INSN (buf, insn_value);
497 while (insn_list != NULL)
498 {
853713a7
DE
499 const CGEN_INSN *insn = insn_list->insn;
500 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
501 CGEN_FIELDS fields;
502 int length;
9c03036a
DE
503
504#if 0 /* not needed as insn shouldn't be in hash lists if not supported */
505 /* Supported by this cpu? */
506 if (! m32r_cgen_insn_supported (insn))
507 continue;
508#endif
509
510 /* Basic bit mask must be correct. */
511 /* ??? May wish to allow target to defer this check until the extract
512 handler. */
853713a7 513 if ((insn_value & CGEN_INSN_MASK (insn)) == CGEN_INSN_VALUE (insn))
9c03036a
DE
514 {
515 /* Printing is handled in two passes. The first pass parses the
516 machine insn and extracts the fields. The second pass prints
517 them. */
518
853713a7 519 length = (*CGEN_EXTRACT_FN (insn)) (insn, NULL, insn_value, &fields);
9c03036a
DE
520 if (length > 0)
521 {
853713a7 522 (*CGEN_PRINT_FN (insn)) (info, insn, &fields, pc, length);
9c03036a 523 /* length is in bits, result is in bytes */
853713a7 524 return length / 8;
9c03036a
DE
525 }
526 }
853713a7 527
9c03036a
DE
528 insn_list = CGEN_DIS_NEXT_INSN (insn_list);
529 }
530
853713a7 531 return 0;
9c03036a
DE
532}
533
534/* Main entry point.
535 Print one instruction from PC on INFO->STREAM.
536 Return the size of the instruction (in bytes). */
537
538int
539print_insn_m32r (pc, info)
853713a7
DE
540 bfd_vma pc;
541 disassemble_info *info;
9c03036a 542{
853713a7
DE
543 char buffer[CGEN_MAX_INSN_SIZE];
544 int status, length;
545 static int initialized = 0;
546 static int current_mach = 0;
547 static int current_big_p = 0;
548 int mach = info->mach;
549 int big_p = info->endian == BFD_ENDIAN_BIG;
9c03036a
DE
550
551 /* If we haven't initialized yet, or if we've switched cpu's, initialize. */
853713a7 552 if (!initialized || mach != current_mach || big_p != current_big_p)
9c03036a 553 {
853713a7
DE
554 initialized = 1;
555 current_mach = mach;
556 current_big_p = big_p;
557 m32r_cgen_init_dis (mach, big_p ? CGEN_ENDIAN_BIG : CGEN_ENDIAN_LITTLE);
9c03036a
DE
558 }
559
560 /* Read enough of the insn so we can look it up in the hash lists. */
561
853713a7 562 status = (*info->read_memory_func) (pc, buffer, CGEN_BASE_INSN_SIZE, info);
9c03036a
DE
563 if (status != 0)
564 {
853713a7 565 (*info->memory_error_func) (status, pc, info);
9c03036a
DE
566 return -1;
567 }
568
569 /* We try to have as much common code as possible.
570 But at this point some targets need to take over. */
571 /* ??? Some targets may need a hook elsewhere. Try to avoid this,
23cf992f 572 but if not possible try to move this hook elsewhere rather than
9c03036a
DE
573 have two hooks. */
574 length = CGEN_PRINT_INSN (pc, info, buffer, CGEN_BASE_INSN_BITSIZE);
575 if (length)
576 return length;
577
853713a7 578 (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
9c03036a
DE
579 return CGEN_DEFAULT_INSN_SIZE;
580}
This page took 0.064372 seconds and 4 git commands to generate.