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 2008, 2010 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 /* Print an operand with a "." prefix.
64 NOTE: This prints the operand in hex.
65 ??? This exists to maintain disassembler compatibility with previous
66 versions. Ideally we'd print the "." in print_dot. */
69 print_with_dot_prefix (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
72 unsigned attrs ATTRIBUTE_UNUSED,
73 bfd_vma pc ATTRIBUTE_UNUSED,
74 int length ATTRIBUTE_UNUSED)
76 disassemble_info *info = (disassemble_info *) dis_info;
78 info->fprintf_func (info->stream, ".");
79 info->fprintf_func (info->stream, "0x%lx", value);
82 /* Print an operand with a "#pof:" prefix.
83 NOTE: This prints the operand as an address.
84 ??? This exists to maintain disassembler compatibility with previous
85 versions. Ideally we'd print "#pof:" in print_pof. */
88 print_with_pof_prefix (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
91 unsigned attrs ATTRIBUTE_UNUSED,
92 bfd_vma pc ATTRIBUTE_UNUSED,
93 int length ATTRIBUTE_UNUSED)
95 disassemble_info *info = (disassemble_info *) dis_info;
97 info->fprintf_func (info->stream, "#pof:");
98 info->fprintf_func (info->stream, "0x%lx", (long) value);
101 /* Print an operand with a "#pag:" prefix.
102 NOTE: This prints the operand in hex.
103 ??? This exists to maintain disassembler compatibility with previous
104 versions. Ideally we'd print "#pag:" in print_pag. */
107 print_with_pag_prefix (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
110 unsigned attrs ATTRIBUTE_UNUSED,
111 bfd_vma pc ATTRIBUTE_UNUSED,
112 int length ATTRIBUTE_UNUSED)
114 disassemble_info *info = (disassemble_info *) dis_info;
116 info->fprintf_func (info->stream, "#pag:");
117 info->fprintf_func (info->stream, "0x%lx", value);
120 /* Print a 'pof:' prefix to an operand. */
123 print_pof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
124 void * dis_info ATTRIBUTE_UNUSED,
125 long value ATTRIBUTE_UNUSED,
126 unsigned int attrs ATTRIBUTE_UNUSED,
127 bfd_vma pc ATTRIBUTE_UNUSED,
128 int length ATTRIBUTE_UNUSED)
132 /* Print a 'pag:' prefix to an operand. */
135 print_pag (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
136 void * dis_info ATTRIBUTE_UNUSED,
137 long value ATTRIBUTE_UNUSED,
138 unsigned int attrs ATTRIBUTE_UNUSED,
139 bfd_vma pc ATTRIBUTE_UNUSED,
140 int length ATTRIBUTE_UNUSED)
144 /* Print a 'sof:' prefix to an operand. */
147 print_sof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
149 long value ATTRIBUTE_UNUSED,
150 unsigned int attrs ATTRIBUTE_UNUSED,
151 bfd_vma pc ATTRIBUTE_UNUSED,
152 int length ATTRIBUTE_UNUSED)
154 disassemble_info *info = (disassemble_info *) dis_info;
156 info->fprintf_func (info->stream, "sof:");
159 /* Print a 'seg:' prefix to an operand. */
162 print_seg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
164 long value ATTRIBUTE_UNUSED,
165 unsigned int attrs ATTRIBUTE_UNUSED,
166 bfd_vma pc ATTRIBUTE_UNUSED,
167 int length ATTRIBUTE_UNUSED)
169 disassemble_info *info = (disassemble_info *) dis_info;
171 info->fprintf_func (info->stream, "seg:");
174 /* Print a '#' prefix to an operand. */
177 print_hash (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
179 long value ATTRIBUTE_UNUSED,
180 unsigned int attrs ATTRIBUTE_UNUSED,
181 bfd_vma pc ATTRIBUTE_UNUSED,
182 int length ATTRIBUTE_UNUSED)
184 disassemble_info *info = (disassemble_info *) dis_info;
186 info->fprintf_func (info->stream, "#");
189 /* Print a '.' prefix to an operand. */
192 print_dot (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
193 void * dis_info ATTRIBUTE_UNUSED,
194 long value ATTRIBUTE_UNUSED,
195 unsigned int attrs ATTRIBUTE_UNUSED,
196 bfd_vma pc ATTRIBUTE_UNUSED,
197 int length ATTRIBUTE_UNUSED)
203 void xc16x_cgen_print_operand
204 (CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *, void const *, bfd_vma, int);
206 /* Main entry point for printing operands.
207 XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
208 of dis-asm.h on cgen.h.
210 This function is basically just a big switch statement. Earlier versions
211 used tables to look up the function to use, but
212 - if the table contains both assembler and disassembler functions then
213 the disassembler contains much of the assembler and vice-versa,
214 - there's a lot of inlining possibilities as things grow,
215 - using a switch statement avoids the function call overhead.
217 This function could be moved into `print_insn_normal', but keeping it
218 separate makes clear the interface between `print_insn_normal' and each of
222 xc16x_cgen_print_operand (CGEN_CPU_DESC cd,
226 void const *attrs ATTRIBUTE_UNUSED,
230 disassemble_info *info = (disassemble_info *) xinfo;
234 case XC16X_OPERAND_REGNAM :
235 print_keyword (cd, info, & xc16x_cgen_opval_psw_names, fields->f_reg8, 0);
237 case XC16X_OPERAND_BIT01 :
238 print_normal (cd, info, fields->f_op_1bit, 0, pc, length);
240 case XC16X_OPERAND_BIT1 :
241 print_normal (cd, info, fields->f_op_bit1, 0, pc, length);
243 case XC16X_OPERAND_BIT2 :
244 print_normal (cd, info, fields->f_op_bit2, 0, pc, length);
246 case XC16X_OPERAND_BIT4 :
247 print_normal (cd, info, fields->f_op_bit4, 0, pc, length);
249 case XC16X_OPERAND_BIT8 :
250 print_normal (cd, info, fields->f_op_bit8, 0, pc, length);
252 case XC16X_OPERAND_BITONE :
253 print_normal (cd, info, fields->f_op_onebit, 0, pc, length);
255 case XC16X_OPERAND_CADDR :
256 print_address (cd, info, fields->f_offset16, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
258 case XC16X_OPERAND_COND :
259 print_keyword (cd, info, & xc16x_cgen_opval_conditioncode_names, fields->f_condcode, 0);
261 case XC16X_OPERAND_DATA8 :
262 print_normal (cd, info, fields->f_data8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
264 case XC16X_OPERAND_DATAHI8 :
265 print_normal (cd, info, fields->f_datahi8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
267 case XC16X_OPERAND_DOT :
268 print_dot (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
270 case XC16X_OPERAND_DR :
271 print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r1, 0);
273 case XC16X_OPERAND_DRB :
274 print_keyword (cd, info, & xc16x_cgen_opval_grb_names, fields->f_r1, 0);
276 case XC16X_OPERAND_DRI :
277 print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r4, 0);
279 case XC16X_OPERAND_EXTCOND :
280 print_keyword (cd, info, & xc16x_cgen_opval_extconditioncode_names, fields->f_extccode, 0);
282 case XC16X_OPERAND_GENREG :
283 print_keyword (cd, info, & xc16x_cgen_opval_r8_names, fields->f_regb8, 0);
285 case XC16X_OPERAND_HASH :
286 print_hash (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
288 case XC16X_OPERAND_ICOND :
289 print_keyword (cd, info, & xc16x_cgen_opval_conditioncode_names, fields->f_icondcode, 0);
291 case XC16X_OPERAND_LBIT2 :
292 print_normal (cd, info, fields->f_op_lbit2, 0, pc, length);
294 case XC16X_OPERAND_LBIT4 :
295 print_normal (cd, info, fields->f_op_lbit4, 0, pc, length);
297 case XC16X_OPERAND_MASK8 :
298 print_normal (cd, info, fields->f_mask8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
300 case XC16X_OPERAND_MASKLO8 :
301 print_normal (cd, info, fields->f_datahi8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
303 case XC16X_OPERAND_MEMGR8 :
304 print_keyword (cd, info, & xc16x_cgen_opval_memgr8_names, fields->f_memgr8, 0);
306 case XC16X_OPERAND_MEMORY :
307 print_address (cd, info, fields->f_memory, 0, pc, length);
309 case XC16X_OPERAND_PAG :
310 print_pag (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
312 case XC16X_OPERAND_PAGENUM :
313 print_normal (cd, info, fields->f_pagenum, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
315 case XC16X_OPERAND_POF :
316 print_pof (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
318 case XC16X_OPERAND_QBIT :
319 print_with_dot_prefix (cd, info, fields->f_qbit, 0|(1<<CGEN_OPERAND_DOT_PREFIX), pc, length);
321 case XC16X_OPERAND_QHIBIT :
322 print_with_dot_prefix (cd, info, fields->f_qhibit, 0|(1<<CGEN_OPERAND_DOT_PREFIX), pc, length);
324 case XC16X_OPERAND_QLOBIT :
325 print_with_dot_prefix (cd, info, fields->f_qlobit, 0|(1<<CGEN_OPERAND_DOT_PREFIX), pc, length);
327 case XC16X_OPERAND_REG8 :
328 print_keyword (cd, info, & xc16x_cgen_opval_r8_names, fields->f_reg8, 0);
330 case XC16X_OPERAND_REGB8 :
331 print_keyword (cd, info, & xc16x_cgen_opval_grb8_names, fields->f_regb8, 0);
333 case XC16X_OPERAND_REGBMEM8 :
334 print_keyword (cd, info, & xc16x_cgen_opval_regbmem8_names, fields->f_regmem8, 0);
336 case XC16X_OPERAND_REGHI8 :
337 print_keyword (cd, info, & xc16x_cgen_opval_r8_names, fields->f_reghi8, 0);
339 case XC16X_OPERAND_REGMEM8 :
340 print_keyword (cd, info, & xc16x_cgen_opval_regmem8_names, fields->f_regmem8, 0);
342 case XC16X_OPERAND_REGOFF8 :
343 print_keyword (cd, info, & xc16x_cgen_opval_r8_names, fields->f_regoff8, 0);
345 case XC16X_OPERAND_REL :
346 print_normal (cd, info, fields->f_rel8, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
348 case XC16X_OPERAND_RELHI :
349 print_normal (cd, info, fields->f_relhi8, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
351 case XC16X_OPERAND_SEG :
352 print_normal (cd, info, fields->f_seg8, 0, pc, length);
354 case XC16X_OPERAND_SEGHI8 :
355 print_normal (cd, info, fields->f_segnum8, 0, pc, length);
357 case XC16X_OPERAND_SEGM :
358 print_seg (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
360 case XC16X_OPERAND_SOF :
361 print_sof (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
363 case XC16X_OPERAND_SR :
364 print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r2, 0);
366 case XC16X_OPERAND_SR2 :
367 print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r0, 0);
369 case XC16X_OPERAND_SRB :
370 print_keyword (cd, info, & xc16x_cgen_opval_grb_names, fields->f_r2, 0);
372 case XC16X_OPERAND_SRC1 :
373 print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r1, 0);
375 case XC16X_OPERAND_SRC2 :
376 print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r2, 0);
378 case XC16X_OPERAND_SRDIV :
379 print_keyword (cd, info, & xc16x_cgen_opval_regdiv8_names, fields->f_reg8, 0);
381 case XC16X_OPERAND_U4 :
382 print_keyword (cd, info, & xc16x_cgen_opval_reg0_name, fields->f_uimm4, 0);
384 case XC16X_OPERAND_UIMM16 :
385 print_normal (cd, info, fields->f_uimm16, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
387 case XC16X_OPERAND_UIMM2 :
388 print_keyword (cd, info, & xc16x_cgen_opval_ext_names, fields->f_uimm2, 0|(1<<CGEN_OPERAND_HASH_PREFIX));
390 case XC16X_OPERAND_UIMM3 :
391 print_keyword (cd, info, & xc16x_cgen_opval_reg0_name1, fields->f_uimm3, 0|(1<<CGEN_OPERAND_HASH_PREFIX));
393 case XC16X_OPERAND_UIMM4 :
394 print_normal (cd, info, fields->f_uimm4, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
396 case XC16X_OPERAND_UIMM7 :
397 print_normal (cd, info, fields->f_uimm7, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
399 case XC16X_OPERAND_UIMM8 :
400 print_normal (cd, info, fields->f_uimm8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
402 case XC16X_OPERAND_UPAG16 :
403 print_with_pag_prefix (cd, info, fields->f_uimm16, 0|(1<<CGEN_OPERAND_PAG_PREFIX), pc, length);
405 case XC16X_OPERAND_UPOF16 :
406 print_with_pof_prefix (cd, info, fields->f_memory, 0|(1<<CGEN_OPERAND_POF_PREFIX), pc, length);
408 case XC16X_OPERAND_USEG16 :
409 print_normal (cd, info, fields->f_offset16, 0|(1<<CGEN_OPERAND_SEG_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
411 case XC16X_OPERAND_USEG8 :
412 print_normal (cd, info, fields->f_seg8, 0|(1<<CGEN_OPERAND_SEG_PREFIX), pc, length);
414 case XC16X_OPERAND_USOF16 :
415 print_normal (cd, info, fields->f_offset16, 0|(1<<CGEN_OPERAND_SOF_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
419 /* xgettext:c-format */
420 fprintf (stderr, _("Unrecognized field %d while printing insn.\n"),
426 cgen_print_fn * const xc16x_cgen_print_handlers[] =
433 xc16x_cgen_init_dis (CGEN_CPU_DESC cd)
435 xc16x_cgen_init_opcode_table (cd);
436 xc16x_cgen_init_ibld_table (cd);
437 cd->print_handlers = & xc16x_cgen_print_handlers[0];
438 cd->print_operand = xc16x_cgen_print_operand;
442 /* Default print handler. */
445 print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
449 bfd_vma pc ATTRIBUTE_UNUSED,
450 int length ATTRIBUTE_UNUSED)
452 disassemble_info *info = (disassemble_info *) dis_info;
454 /* Print the operand as directed by the attributes. */
455 if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
456 ; /* nothing to do */
457 else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
458 (*info->fprintf_func) (info->stream, "%ld", value);
460 (*info->fprintf_func) (info->stream, "0x%lx", value);
463 /* Default address handler. */
466 print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
470 bfd_vma pc ATTRIBUTE_UNUSED,
471 int length ATTRIBUTE_UNUSED)
473 disassemble_info *info = (disassemble_info *) dis_info;
475 /* Print the operand as directed by the attributes. */
476 if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
477 ; /* Nothing to do. */
478 else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
479 (*info->print_address_func) (value, info);
480 else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
481 (*info->print_address_func) (value, info);
482 else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
483 (*info->fprintf_func) (info->stream, "%ld", (long) value);
485 (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
488 /* Keyword print handler. */
491 print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
493 CGEN_KEYWORD *keyword_table,
495 unsigned int attrs ATTRIBUTE_UNUSED)
497 disassemble_info *info = (disassemble_info *) dis_info;
498 const CGEN_KEYWORD_ENTRY *ke;
500 ke = cgen_keyword_lookup_value (keyword_table, value);
502 (*info->fprintf_func) (info->stream, "%s", ke->name);
504 (*info->fprintf_func) (info->stream, "???");
507 /* Default insn printer.
509 DIS_INFO is defined as `void *' so the disassembler needn't know anything
510 about disassemble_info. */
513 print_insn_normal (CGEN_CPU_DESC cd,
515 const CGEN_INSN *insn,
520 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
521 disassemble_info *info = (disassemble_info *) dis_info;
522 const CGEN_SYNTAX_CHAR_TYPE *syn;
524 CGEN_INIT_PRINT (cd);
526 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
528 if (CGEN_SYNTAX_MNEMONIC_P (*syn))
530 (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
533 if (CGEN_SYNTAX_CHAR_P (*syn))
535 (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
539 /* We have an operand. */
540 xc16x_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
541 fields, CGEN_INSN_ATTRS (insn), pc, length);
545 /* Subroutine of print_insn. Reads an insn into the given buffers and updates
547 Returns 0 if all is well, non-zero otherwise. */
550 read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
552 disassemble_info *info,
555 CGEN_EXTRACT_INFO *ex_info,
556 unsigned long *insn_value)
558 int status = (*info->read_memory_func) (pc, buf, buflen, info);
562 (*info->memory_error_func) (status, pc, info);
566 ex_info->dis_info = info;
567 ex_info->valid = (1 << buflen) - 1;
568 ex_info->insn_bytes = buf;
570 *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG);
574 /* Utility to print an insn.
575 BUF is the base part of the insn, target byte order, BUFLEN bytes long.
576 The result is the size of the insn in bytes or zero for an unknown insn
577 or -1 if an error occurs fetching data (memory_error_func will have
581 print_insn (CGEN_CPU_DESC cd,
583 disassemble_info *info,
587 CGEN_INSN_INT insn_value;
588 const CGEN_INSN_LIST *insn_list;
589 CGEN_EXTRACT_INFO ex_info;
592 /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
593 basesize = cd->base_insn_bitsize < buflen * 8 ?
594 cd->base_insn_bitsize : buflen * 8;
595 insn_value = cgen_get_insn_value (cd, buf, basesize);
598 /* Fill in ex_info fields like read_insn would. Don't actually call
599 read_insn, since the incoming buffer is already read (and possibly
600 modified a la m32r). */
601 ex_info.valid = (1 << buflen) - 1;
602 ex_info.dis_info = info;
603 ex_info.insn_bytes = buf;
605 /* The instructions are stored in hash lists.
606 Pick the first one and keep trying until we find the right one. */
608 insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
609 while (insn_list != NULL)
611 const CGEN_INSN *insn = insn_list->insn;
614 unsigned long insn_value_cropped;
616 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
617 /* Not needed as insn shouldn't be in hash lists if not supported. */
618 /* Supported by this cpu? */
619 if (! xc16x_cgen_insn_supported (cd, insn))
621 insn_list = CGEN_DIS_NEXT_INSN (insn_list);
626 /* Basic bit mask must be correct. */
627 /* ??? May wish to allow target to defer this check until the extract
630 /* Base size may exceed this instruction's size. Extract the
631 relevant part from the buffer. */
632 if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen &&
633 (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
634 insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn),
635 info->endian == BFD_ENDIAN_BIG);
637 insn_value_cropped = insn_value;
639 if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn))
640 == CGEN_INSN_BASE_VALUE (insn))
642 /* Printing is handled in two passes. The first pass parses the
643 machine insn and extracts the fields. The second pass prints
646 /* Make sure the entire insn is loaded into insn_value, if it
648 if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) &&
649 (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
651 unsigned long full_insn_value;
652 int rc = read_insn (cd, pc, info, buf,
653 CGEN_INSN_BITSIZE (insn) / 8,
654 & ex_info, & full_insn_value);
657 length = CGEN_EXTRACT_FN (cd, insn)
658 (cd, insn, &ex_info, full_insn_value, &fields, pc);
661 length = CGEN_EXTRACT_FN (cd, insn)
662 (cd, insn, &ex_info, insn_value_cropped, &fields, pc);
664 /* Length < 0 -> error. */
669 CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
670 /* Length is in bits, result is in bytes. */
675 insn_list = CGEN_DIS_NEXT_INSN (insn_list);
681 /* Default value for CGEN_PRINT_INSN.
682 The result is the size of the insn in bytes or zero for an unknown insn
683 or -1 if an error occured fetching bytes. */
685 #ifndef CGEN_PRINT_INSN
686 #define CGEN_PRINT_INSN default_print_insn
690 default_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
692 bfd_byte buf[CGEN_MAX_INSN_SIZE];
696 /* Attempt to read the base part of the insn. */
697 buflen = cd->base_insn_bitsize / 8;
698 status = (*info->read_memory_func) (pc, buf, buflen, info);
700 /* Try again with the minimum part, if min < base. */
701 if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
703 buflen = cd->min_insn_bitsize / 8;
704 status = (*info->read_memory_func) (pc, buf, buflen, info);
709 (*info->memory_error_func) (status, pc, info);
713 return print_insn (cd, pc, info, buf, buflen);
717 Print one instruction from PC on INFO->STREAM.
718 Return the size of the instruction (in bytes). */
720 typedef struct cpu_desc_list
722 struct cpu_desc_list *next;
730 print_insn_xc16x (bfd_vma pc, disassemble_info *info)
732 static cpu_desc_list *cd_list = 0;
733 cpu_desc_list *cl = 0;
734 static CGEN_CPU_DESC cd = 0;
735 static CGEN_BITSET *prev_isa;
736 static int prev_mach;
737 static int prev_endian;
741 int endian = (info->endian == BFD_ENDIAN_BIG
743 : CGEN_ENDIAN_LITTLE);
744 enum bfd_architecture arch;
746 /* ??? gdb will set mach but leave the architecture as "unknown" */
747 #ifndef CGEN_BFD_ARCH
748 #define CGEN_BFD_ARCH bfd_arch_xc16x
751 if (arch == bfd_arch_unknown)
752 arch = CGEN_BFD_ARCH;
754 /* There's no standard way to compute the machine or isa number
755 so we leave it to the target. */
756 #ifdef CGEN_COMPUTE_MACH
757 mach = CGEN_COMPUTE_MACH (info);
762 #ifdef CGEN_COMPUTE_ISA
764 static CGEN_BITSET *permanent_isa;
767 permanent_isa = cgen_bitset_create (MAX_ISAS);
769 cgen_bitset_clear (isa);
770 cgen_bitset_add (isa, CGEN_COMPUTE_ISA (info));
773 isa = info->insn_sets;
776 /* If we've switched cpu's, try to find a handle we've used before */
778 && (cgen_bitset_compare (isa, prev_isa) != 0
780 || endian != prev_endian))
783 for (cl = cd_list; cl; cl = cl->next)
785 if (cgen_bitset_compare (cl->isa, isa) == 0 &&
787 cl->endian == endian)
796 /* If we haven't initialized yet, initialize the opcode table. */
799 const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
800 const char *mach_name;
804 mach_name = arch_type->printable_name;
806 prev_isa = cgen_bitset_copy (isa);
808 prev_endian = endian;
809 cd = xc16x_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
810 CGEN_CPU_OPEN_BFDMACH, mach_name,
811 CGEN_CPU_OPEN_ENDIAN, prev_endian,
816 /* Save this away for future reference. */
817 cl = xmalloc (sizeof (struct cpu_desc_list));
825 xc16x_cgen_init_dis (cd);
828 /* We try to have as much common code as possible.
829 But at this point some targets need to take over. */
830 /* ??? Some targets may need a hook elsewhere. Try to avoid this,
831 but if not possible try to move this hook elsewhere rather than
833 length = CGEN_PRINT_INSN (cd, pc, info);
839 (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
840 return cd->default_insn_bitsize / 8;