1 /* Disassembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS MACHINE GENERATED WITH CGEN.
5 - the resultant file is machine generated, cgen-dis.in isn't
7 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007
8 Free Software Foundation, Inc.
10 This file is part of libopcodes.
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)
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.
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. */
26 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
35 #include "libiberty.h"
36 #include "xc16x-desc.h"
37 #include "xc16x-opc.h"
40 /* Default text to print if an instruction isn't recognized. */
41 #define UNKNOWN_INSN_MSG _("*unknown*")
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);
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
;
56 (CGEN_CPU_DESC
, bfd_vma
, disassemble_info
*, bfd_byte
*, int, CGEN_EXTRACT_INFO
*,
59 /* -- disassembler routines inserted here. */
63 #define CGEN_PRINT_NORMAL(cd, info, value, attrs, pc, length) \
66 if (CGEN_BOOL_ATTR ((attrs), CGEN_OPERAND_DOT_PREFIX)) \
67 info->fprintf_func (info->stream, "."); \
68 if (CGEN_BOOL_ATTR ((attrs), CGEN_OPERAND_POF_PREFIX)) \
69 info->fprintf_func (info->stream, "#pof:"); \
70 if (CGEN_BOOL_ATTR ((attrs), CGEN_OPERAND_PAG_PREFIX)) \
71 info->fprintf_func (info->stream, "#pag:"); \
75 /* Print a 'pof:' prefix to an operand. */
78 print_pof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
79 void * dis_info ATTRIBUTE_UNUSED
,
80 long value ATTRIBUTE_UNUSED
,
81 unsigned int attrs ATTRIBUTE_UNUSED
,
82 bfd_vma pc ATTRIBUTE_UNUSED
,
83 int length ATTRIBUTE_UNUSED
)
87 /* Print a 'pag:' prefix to an operand. */
90 print_pag (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
91 void * dis_info ATTRIBUTE_UNUSED
,
92 long value ATTRIBUTE_UNUSED
,
93 unsigned int attrs ATTRIBUTE_UNUSED
,
94 bfd_vma pc ATTRIBUTE_UNUSED
,
95 int length ATTRIBUTE_UNUSED
)
99 /* Print a 'sof:' prefix to an operand. */
102 print_sof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
104 long value ATTRIBUTE_UNUSED
,
105 unsigned int attrs ATTRIBUTE_UNUSED
,
106 bfd_vma pc ATTRIBUTE_UNUSED
,
107 int length ATTRIBUTE_UNUSED
)
109 disassemble_info
*info
= (disassemble_info
*) dis_info
;
111 info
->fprintf_func (info
->stream
, "sof:");
114 /* Print a 'seg:' prefix to an operand. */
117 print_seg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
119 long value ATTRIBUTE_UNUSED
,
120 unsigned int attrs ATTRIBUTE_UNUSED
,
121 bfd_vma pc ATTRIBUTE_UNUSED
,
122 int length ATTRIBUTE_UNUSED
)
124 disassemble_info
*info
= (disassemble_info
*) dis_info
;
126 info
->fprintf_func (info
->stream
, "seg:");
129 /* Print a '#' prefix to an operand. */
132 print_hash (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
134 long value ATTRIBUTE_UNUSED
,
135 unsigned int attrs ATTRIBUTE_UNUSED
,
136 bfd_vma pc ATTRIBUTE_UNUSED
,
137 int length ATTRIBUTE_UNUSED
)
139 disassemble_info
*info
= (disassemble_info
*) dis_info
;
141 info
->fprintf_func (info
->stream
, "#");
144 /* Print a '.' prefix to an operand. */
147 print_dot (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
148 void * dis_info ATTRIBUTE_UNUSED
,
149 long value ATTRIBUTE_UNUSED
,
150 unsigned int attrs ATTRIBUTE_UNUSED
,
151 bfd_vma pc ATTRIBUTE_UNUSED
,
152 int length ATTRIBUTE_UNUSED
)
158 void xc16x_cgen_print_operand
159 (CGEN_CPU_DESC
, int, PTR
, CGEN_FIELDS
*, void const *, bfd_vma
, int);
161 /* Main entry point for printing operands.
162 XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
163 of dis-asm.h on cgen.h.
165 This function is basically just a big switch statement. Earlier versions
166 used tables to look up the function to use, but
167 - if the table contains both assembler and disassembler functions then
168 the disassembler contains much of the assembler and vice-versa,
169 - there's a lot of inlining possibilities as things grow,
170 - using a switch statement avoids the function call overhead.
172 This function could be moved into `print_insn_normal', but keeping it
173 separate makes clear the interface between `print_insn_normal' and each of
177 xc16x_cgen_print_operand (CGEN_CPU_DESC cd
,
181 void const *attrs ATTRIBUTE_UNUSED
,
185 disassemble_info
*info
= (disassemble_info
*) xinfo
;
189 case XC16X_OPERAND_REGNAM
:
190 print_keyword (cd
, info
, & xc16x_cgen_opval_psw_names
, fields
->f_reg8
, 0);
192 case XC16X_OPERAND_BIT01
:
193 print_normal (cd
, info
, fields
->f_op_1bit
, 0, pc
, length
);
195 case XC16X_OPERAND_BIT1
:
196 print_normal (cd
, info
, fields
->f_op_bit1
, 0, pc
, length
);
198 case XC16X_OPERAND_BIT2
:
199 print_normal (cd
, info
, fields
->f_op_bit2
, 0, pc
, length
);
201 case XC16X_OPERAND_BIT4
:
202 print_normal (cd
, info
, fields
->f_op_bit4
, 0, pc
, length
);
204 case XC16X_OPERAND_BIT8
:
205 print_normal (cd
, info
, fields
->f_op_bit8
, 0, pc
, length
);
207 case XC16X_OPERAND_BITONE
:
208 print_normal (cd
, info
, fields
->f_op_onebit
, 0, pc
, length
);
210 case XC16X_OPERAND_CADDR
:
211 print_address (cd
, info
, fields
->f_offset16
, 0|(1<<CGEN_OPERAND_RELOC
)|(1<<CGEN_OPERAND_ABS_ADDR
), pc
, length
);
213 case XC16X_OPERAND_COND
:
214 print_keyword (cd
, info
, & xc16x_cgen_opval_conditioncode_names
, fields
->f_condcode
, 0);
216 case XC16X_OPERAND_DATA8
:
217 print_normal (cd
, info
, fields
->f_data8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
219 case XC16X_OPERAND_DATAHI8
:
220 print_normal (cd
, info
, fields
->f_datahi8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
222 case XC16X_OPERAND_DOT
:
223 print_dot (cd
, info
, 0, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
225 case XC16X_OPERAND_DR
:
226 print_keyword (cd
, info
, & xc16x_cgen_opval_gr_names
, fields
->f_r1
, 0);
228 case XC16X_OPERAND_DRB
:
229 print_keyword (cd
, info
, & xc16x_cgen_opval_grb_names
, fields
->f_r1
, 0);
231 case XC16X_OPERAND_DRI
:
232 print_keyword (cd
, info
, & xc16x_cgen_opval_gr_names
, fields
->f_r4
, 0);
234 case XC16X_OPERAND_EXTCOND
:
235 print_keyword (cd
, info
, & xc16x_cgen_opval_extconditioncode_names
, fields
->f_extccode
, 0);
237 case XC16X_OPERAND_GENREG
:
238 print_keyword (cd
, info
, & xc16x_cgen_opval_r8_names
, fields
->f_regb8
, 0);
240 case XC16X_OPERAND_HASH
:
241 print_hash (cd
, info
, 0, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
243 case XC16X_OPERAND_ICOND
:
244 print_keyword (cd
, info
, & xc16x_cgen_opval_conditioncode_names
, fields
->f_icondcode
, 0);
246 case XC16X_OPERAND_LBIT2
:
247 print_normal (cd
, info
, fields
->f_op_lbit2
, 0, pc
, length
);
249 case XC16X_OPERAND_LBIT4
:
250 print_normal (cd
, info
, fields
->f_op_lbit4
, 0, pc
, length
);
252 case XC16X_OPERAND_MASK8
:
253 print_normal (cd
, info
, fields
->f_mask8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
255 case XC16X_OPERAND_MASKLO8
:
256 print_normal (cd
, info
, fields
->f_datahi8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
258 case XC16X_OPERAND_MEMGR8
:
259 print_keyword (cd
, info
, & xc16x_cgen_opval_memgr8_names
, fields
->f_memgr8
, 0);
261 case XC16X_OPERAND_MEMORY
:
262 print_address (cd
, info
, fields
->f_memory
, 0, pc
, length
);
264 case XC16X_OPERAND_PAG
:
265 print_pag (cd
, info
, 0, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
267 case XC16X_OPERAND_PAGENUM
:
268 print_normal (cd
, info
, fields
->f_pagenum
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
270 case XC16X_OPERAND_POF
:
271 print_pof (cd
, info
, 0, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
273 case XC16X_OPERAND_QBIT
:
274 print_normal (cd
, info
, fields
->f_qbit
, 0|(1<<CGEN_OPERAND_DOT_PREFIX
), pc
, length
);
276 case XC16X_OPERAND_QHIBIT
:
277 print_normal (cd
, info
, fields
->f_qhibit
, 0|(1<<CGEN_OPERAND_DOT_PREFIX
), pc
, length
);
279 case XC16X_OPERAND_QLOBIT
:
280 print_normal (cd
, info
, fields
->f_qlobit
, 0|(1<<CGEN_OPERAND_DOT_PREFIX
), pc
, length
);
282 case XC16X_OPERAND_REG8
:
283 print_keyword (cd
, info
, & xc16x_cgen_opval_r8_names
, fields
->f_reg8
, 0);
285 case XC16X_OPERAND_REGB8
:
286 print_keyword (cd
, info
, & xc16x_cgen_opval_grb8_names
, fields
->f_regb8
, 0);
288 case XC16X_OPERAND_REGBMEM8
:
289 print_keyword (cd
, info
, & xc16x_cgen_opval_regbmem8_names
, fields
->f_regmem8
, 0);
291 case XC16X_OPERAND_REGHI8
:
292 print_keyword (cd
, info
, & xc16x_cgen_opval_r8_names
, fields
->f_reghi8
, 0);
294 case XC16X_OPERAND_REGMEM8
:
295 print_keyword (cd
, info
, & xc16x_cgen_opval_regmem8_names
, fields
->f_regmem8
, 0);
297 case XC16X_OPERAND_REGOFF8
:
298 print_keyword (cd
, info
, & xc16x_cgen_opval_r8_names
, fields
->f_regoff8
, 0);
300 case XC16X_OPERAND_REL
:
301 print_normal (cd
, info
, fields
->f_rel8
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_RELOC
)|(1<<CGEN_OPERAND_PCREL_ADDR
), pc
, length
);
303 case XC16X_OPERAND_RELHI
:
304 print_normal (cd
, info
, fields
->f_relhi8
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_RELOC
)|(1<<CGEN_OPERAND_PCREL_ADDR
), pc
, length
);
306 case XC16X_OPERAND_SEG
:
307 print_normal (cd
, info
, fields
->f_seg8
, 0, pc
, length
);
309 case XC16X_OPERAND_SEGHI8
:
310 print_normal (cd
, info
, fields
->f_segnum8
, 0, pc
, length
);
312 case XC16X_OPERAND_SEGM
:
313 print_seg (cd
, info
, 0, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
315 case XC16X_OPERAND_SOF
:
316 print_sof (cd
, info
, 0, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
318 case XC16X_OPERAND_SR
:
319 print_keyword (cd
, info
, & xc16x_cgen_opval_gr_names
, fields
->f_r2
, 0);
321 case XC16X_OPERAND_SR2
:
322 print_keyword (cd
, info
, & xc16x_cgen_opval_gr_names
, fields
->f_r0
, 0);
324 case XC16X_OPERAND_SRB
:
325 print_keyword (cd
, info
, & xc16x_cgen_opval_grb_names
, fields
->f_r2
, 0);
327 case XC16X_OPERAND_SRC1
:
328 print_keyword (cd
, info
, & xc16x_cgen_opval_gr_names
, fields
->f_r1
, 0);
330 case XC16X_OPERAND_SRC2
:
331 print_keyword (cd
, info
, & xc16x_cgen_opval_gr_names
, fields
->f_r2
, 0);
333 case XC16X_OPERAND_SRDIV
:
334 print_keyword (cd
, info
, & xc16x_cgen_opval_regdiv8_names
, fields
->f_reg8
, 0);
336 case XC16X_OPERAND_U4
:
337 print_keyword (cd
, info
, & xc16x_cgen_opval_reg0_name
, fields
->f_uimm4
, 0);
339 case XC16X_OPERAND_UIMM16
:
340 print_normal (cd
, info
, fields
->f_uimm16
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
342 case XC16X_OPERAND_UIMM2
:
343 print_keyword (cd
, info
, & xc16x_cgen_opval_ext_names
, fields
->f_uimm2
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
));
345 case XC16X_OPERAND_UIMM3
:
346 print_keyword (cd
, info
, & xc16x_cgen_opval_reg0_name1
, fields
->f_uimm3
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
));
348 case XC16X_OPERAND_UIMM4
:
349 print_normal (cd
, info
, fields
->f_uimm4
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
351 case XC16X_OPERAND_UIMM7
:
352 print_normal (cd
, info
, fields
->f_uimm7
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_RELOC
)|(1<<CGEN_OPERAND_PCREL_ADDR
), pc
, length
);
354 case XC16X_OPERAND_UIMM8
:
355 print_normal (cd
, info
, fields
->f_uimm8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
357 case XC16X_OPERAND_UPAG16
:
358 print_normal (cd
, info
, fields
->f_uimm16
, 0|(1<<CGEN_OPERAND_PAG_PREFIX
), pc
, length
);
360 case XC16X_OPERAND_UPOF16
:
361 print_address (cd
, info
, fields
->f_memory
, 0|(1<<CGEN_OPERAND_POF_PREFIX
), pc
, length
);
363 case XC16X_OPERAND_USEG16
:
364 print_normal (cd
, info
, fields
->f_offset16
, 0|(1<<CGEN_OPERAND_SEG_PREFIX
)|(1<<CGEN_OPERAND_RELOC
)|(1<<CGEN_OPERAND_ABS_ADDR
), pc
, length
);
366 case XC16X_OPERAND_USEG8
:
367 print_normal (cd
, info
, fields
->f_seg8
, 0|(1<<CGEN_OPERAND_SEG_PREFIX
), pc
, length
);
369 case XC16X_OPERAND_USOF16
:
370 print_normal (cd
, info
, fields
->f_offset16
, 0|(1<<CGEN_OPERAND_SOF_PREFIX
)|(1<<CGEN_OPERAND_RELOC
)|(1<<CGEN_OPERAND_ABS_ADDR
), pc
, length
);
374 /* xgettext:c-format */
375 fprintf (stderr
, _("Unrecognized field %d while printing insn.\n"),
381 cgen_print_fn
* const xc16x_cgen_print_handlers
[] =
388 xc16x_cgen_init_dis (CGEN_CPU_DESC cd
)
390 xc16x_cgen_init_opcode_table (cd
);
391 xc16x_cgen_init_ibld_table (cd
);
392 cd
->print_handlers
= & xc16x_cgen_print_handlers
[0];
393 cd
->print_operand
= xc16x_cgen_print_operand
;
397 /* Default print handler. */
400 print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
404 bfd_vma pc ATTRIBUTE_UNUSED
,
405 int length ATTRIBUTE_UNUSED
)
407 disassemble_info
*info
= (disassemble_info
*) dis_info
;
409 #ifdef CGEN_PRINT_NORMAL
410 CGEN_PRINT_NORMAL (cd
, info
, value
, attrs
, pc
, length
);
413 /* Print the operand as directed by the attributes. */
414 if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SEM_ONLY
))
415 ; /* nothing to do */
416 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SIGNED
))
417 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
419 (*info
->fprintf_func
) (info
->stream
, "0x%lx", value
);
422 /* Default address handler. */
425 print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
429 bfd_vma pc ATTRIBUTE_UNUSED
,
430 int length ATTRIBUTE_UNUSED
)
432 disassemble_info
*info
= (disassemble_info
*) dis_info
;
434 #ifdef CGEN_PRINT_ADDRESS
435 CGEN_PRINT_ADDRESS (cd
, info
, value
, attrs
, pc
, length
);
438 /* Print the operand as directed by the attributes. */
439 if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SEM_ONLY
))
440 ; /* Nothing to do. */
441 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_PCREL_ADDR
))
442 (*info
->print_address_func
) (value
, info
);
443 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_ABS_ADDR
))
444 (*info
->print_address_func
) (value
, info
);
445 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SIGNED
))
446 (*info
->fprintf_func
) (info
->stream
, "%ld", (long) value
);
448 (*info
->fprintf_func
) (info
->stream
, "0x%lx", (long) value
);
451 /* Keyword print handler. */
454 print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
456 CGEN_KEYWORD
*keyword_table
,
458 unsigned int attrs ATTRIBUTE_UNUSED
)
460 disassemble_info
*info
= (disassemble_info
*) dis_info
;
461 const CGEN_KEYWORD_ENTRY
*ke
;
463 ke
= cgen_keyword_lookup_value (keyword_table
, value
);
465 (*info
->fprintf_func
) (info
->stream
, "%s", ke
->name
);
467 (*info
->fprintf_func
) (info
->stream
, "???");
470 /* Default insn printer.
472 DIS_INFO is defined as `void *' so the disassembler needn't know anything
473 about disassemble_info. */
476 print_insn_normal (CGEN_CPU_DESC cd
,
478 const CGEN_INSN
*insn
,
483 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
484 disassemble_info
*info
= (disassemble_info
*) dis_info
;
485 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
487 CGEN_INIT_PRINT (cd
);
489 for (syn
= CGEN_SYNTAX_STRING (syntax
); *syn
; ++syn
)
491 if (CGEN_SYNTAX_MNEMONIC_P (*syn
))
493 (*info
->fprintf_func
) (info
->stream
, "%s", CGEN_INSN_MNEMONIC (insn
));
496 if (CGEN_SYNTAX_CHAR_P (*syn
))
498 (*info
->fprintf_func
) (info
->stream
, "%c", CGEN_SYNTAX_CHAR (*syn
));
502 /* We have an operand. */
503 xc16x_cgen_print_operand (cd
, CGEN_SYNTAX_FIELD (*syn
), info
,
504 fields
, CGEN_INSN_ATTRS (insn
), pc
, length
);
508 /* Subroutine of print_insn. Reads an insn into the given buffers and updates
510 Returns 0 if all is well, non-zero otherwise. */
513 read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
515 disassemble_info
*info
,
518 CGEN_EXTRACT_INFO
*ex_info
,
519 unsigned long *insn_value
)
521 int status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
525 (*info
->memory_error_func
) (status
, pc
, info
);
529 ex_info
->dis_info
= info
;
530 ex_info
->valid
= (1 << buflen
) - 1;
531 ex_info
->insn_bytes
= buf
;
533 *insn_value
= bfd_get_bits (buf
, buflen
* 8, info
->endian
== BFD_ENDIAN_BIG
);
537 /* Utility to print an insn.
538 BUF is the base part of the insn, target byte order, BUFLEN bytes long.
539 The result is the size of the insn in bytes or zero for an unknown insn
540 or -1 if an error occurs fetching data (memory_error_func will have
544 print_insn (CGEN_CPU_DESC cd
,
546 disassemble_info
*info
,
550 CGEN_INSN_INT insn_value
;
551 const CGEN_INSN_LIST
*insn_list
;
552 CGEN_EXTRACT_INFO ex_info
;
555 /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
556 basesize
= cd
->base_insn_bitsize
< buflen
* 8 ?
557 cd
->base_insn_bitsize
: buflen
* 8;
558 insn_value
= cgen_get_insn_value (cd
, buf
, basesize
);
561 /* Fill in ex_info fields like read_insn would. Don't actually call
562 read_insn, since the incoming buffer is already read (and possibly
563 modified a la m32r). */
564 ex_info
.valid
= (1 << buflen
) - 1;
565 ex_info
.dis_info
= info
;
566 ex_info
.insn_bytes
= buf
;
568 /* The instructions are stored in hash lists.
569 Pick the first one and keep trying until we find the right one. */
571 insn_list
= CGEN_DIS_LOOKUP_INSN (cd
, (char *) buf
, insn_value
);
572 while (insn_list
!= NULL
)
574 const CGEN_INSN
*insn
= insn_list
->insn
;
577 unsigned long insn_value_cropped
;
579 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
580 /* Not needed as insn shouldn't be in hash lists if not supported. */
581 /* Supported by this cpu? */
582 if (! xc16x_cgen_insn_supported (cd
, insn
))
584 insn_list
= CGEN_DIS_NEXT_INSN (insn_list
);
589 /* Basic bit mask must be correct. */
590 /* ??? May wish to allow target to defer this check until the extract
593 /* Base size may exceed this instruction's size. Extract the
594 relevant part from the buffer. */
595 if ((unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) < buflen
&&
596 (unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) <= sizeof (unsigned long))
597 insn_value_cropped
= bfd_get_bits (buf
, CGEN_INSN_BITSIZE (insn
),
598 info
->endian
== BFD_ENDIAN_BIG
);
600 insn_value_cropped
= insn_value
;
602 if ((insn_value_cropped
& CGEN_INSN_BASE_MASK (insn
))
603 == CGEN_INSN_BASE_VALUE (insn
))
605 /* Printing is handled in two passes. The first pass parses the
606 machine insn and extracts the fields. The second pass prints
609 /* Make sure the entire insn is loaded into insn_value, if it
611 if (((unsigned) CGEN_INSN_BITSIZE (insn
) > cd
->base_insn_bitsize
) &&
612 (unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) <= sizeof (unsigned long))
614 unsigned long full_insn_value
;
615 int rc
= read_insn (cd
, pc
, info
, buf
,
616 CGEN_INSN_BITSIZE (insn
) / 8,
617 & ex_info
, & full_insn_value
);
620 length
= CGEN_EXTRACT_FN (cd
, insn
)
621 (cd
, insn
, &ex_info
, full_insn_value
, &fields
, pc
);
624 length
= CGEN_EXTRACT_FN (cd
, insn
)
625 (cd
, insn
, &ex_info
, insn_value_cropped
, &fields
, pc
);
627 /* Length < 0 -> error. */
632 CGEN_PRINT_FN (cd
, insn
) (cd
, info
, insn
, &fields
, pc
, length
);
633 /* Length is in bits, result is in bytes. */
638 insn_list
= CGEN_DIS_NEXT_INSN (insn_list
);
644 /* Default value for CGEN_PRINT_INSN.
645 The result is the size of the insn in bytes or zero for an unknown insn
646 or -1 if an error occured fetching bytes. */
648 #ifndef CGEN_PRINT_INSN
649 #define CGEN_PRINT_INSN default_print_insn
653 default_print_insn (CGEN_CPU_DESC cd
, bfd_vma pc
, disassemble_info
*info
)
655 bfd_byte buf
[CGEN_MAX_INSN_SIZE
];
659 /* Attempt to read the base part of the insn. */
660 buflen
= cd
->base_insn_bitsize
/ 8;
661 status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
663 /* Try again with the minimum part, if min < base. */
664 if (status
!= 0 && (cd
->min_insn_bitsize
< cd
->base_insn_bitsize
))
666 buflen
= cd
->min_insn_bitsize
/ 8;
667 status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
672 (*info
->memory_error_func
) (status
, pc
, info
);
676 return print_insn (cd
, pc
, info
, buf
, buflen
);
680 Print one instruction from PC on INFO->STREAM.
681 Return the size of the instruction (in bytes). */
683 typedef struct cpu_desc_list
685 struct cpu_desc_list
*next
;
693 print_insn_xc16x (bfd_vma pc
, disassemble_info
*info
)
695 static cpu_desc_list
*cd_list
= 0;
696 cpu_desc_list
*cl
= 0;
697 static CGEN_CPU_DESC cd
= 0;
698 static CGEN_BITSET
*prev_isa
;
699 static int prev_mach
;
700 static int prev_endian
;
704 int endian
= (info
->endian
== BFD_ENDIAN_BIG
706 : CGEN_ENDIAN_LITTLE
);
707 enum bfd_architecture arch
;
709 /* ??? gdb will set mach but leave the architecture as "unknown" */
710 #ifndef CGEN_BFD_ARCH
711 #define CGEN_BFD_ARCH bfd_arch_xc16x
714 if (arch
== bfd_arch_unknown
)
715 arch
= CGEN_BFD_ARCH
;
717 /* There's no standard way to compute the machine or isa number
718 so we leave it to the target. */
719 #ifdef CGEN_COMPUTE_MACH
720 mach
= CGEN_COMPUTE_MACH (info
);
725 #ifdef CGEN_COMPUTE_ISA
727 static CGEN_BITSET
*permanent_isa
;
730 permanent_isa
= cgen_bitset_create (MAX_ISAS
);
732 cgen_bitset_clear (isa
);
733 cgen_bitset_add (isa
, CGEN_COMPUTE_ISA (info
));
736 isa
= info
->insn_sets
;
739 /* If we've switched cpu's, try to find a handle we've used before */
741 && (cgen_bitset_compare (isa
, prev_isa
) != 0
743 || endian
!= prev_endian
))
746 for (cl
= cd_list
; cl
; cl
= cl
->next
)
748 if (cgen_bitset_compare (cl
->isa
, isa
) == 0 &&
750 cl
->endian
== endian
)
759 /* If we haven't initialized yet, initialize the opcode table. */
762 const bfd_arch_info_type
*arch_type
= bfd_lookup_arch (arch
, mach
);
763 const char *mach_name
;
767 mach_name
= arch_type
->printable_name
;
769 prev_isa
= cgen_bitset_copy (isa
);
771 prev_endian
= endian
;
772 cd
= xc16x_cgen_cpu_open (CGEN_CPU_OPEN_ISAS
, prev_isa
,
773 CGEN_CPU_OPEN_BFDMACH
, mach_name
,
774 CGEN_CPU_OPEN_ENDIAN
, prev_endian
,
779 /* Save this away for future reference. */
780 cl
= xmalloc (sizeof (struct cpu_desc_list
));
788 xc16x_cgen_init_dis (cd
);
791 /* We try to have as much common code as possible.
792 But at this point some targets need to take over. */
793 /* ??? Some targets may need a hook elsewhere. Try to avoid this,
794 but if not possible try to move this hook elsewhere rather than
796 length
= CGEN_PRINT_INSN (cd
, pc
, info
);
802 (*info
->fprintf_func
) (info
->stream
, UNKNOWN_INSN_MSG
);
803 return cd
->default_insn_bitsize
/ 8;