1*3d8817e4Smiod /* Disassembler interface for targets using CGEN. -*- C -*-
2*3d8817e4Smiod CGEN: Cpu tools GENerator
3*3d8817e4Smiod
4*3d8817e4Smiod THIS FILE IS MACHINE GENERATED WITH CGEN.
5*3d8817e4Smiod - the resultant file is machine generated, cgen-dis.in isn't
6*3d8817e4Smiod
7*3d8817e4Smiod Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005
8*3d8817e4Smiod Free Software Foundation, Inc.
9*3d8817e4Smiod
10*3d8817e4Smiod This file is part of the GNU Binutils and GDB, the GNU debugger.
11*3d8817e4Smiod
12*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
13*3d8817e4Smiod it under the terms of the GNU General Public License as published by
14*3d8817e4Smiod the Free Software Foundation; either version 2, or (at your option)
15*3d8817e4Smiod any later version.
16*3d8817e4Smiod
17*3d8817e4Smiod This program is distributed in the hope that it will be useful,
18*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
19*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20*3d8817e4Smiod GNU General Public License for more details.
21*3d8817e4Smiod
22*3d8817e4Smiod You should have received a copy of the GNU General Public License
23*3d8817e4Smiod along with this program; if not, write to the Free Software Foundation, Inc.,
24*3d8817e4Smiod 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25*3d8817e4Smiod
26*3d8817e4Smiod /* ??? Eventually more and more of this stuff can go to cpu-independent files.
27*3d8817e4Smiod Keep that in mind. */
28*3d8817e4Smiod
29*3d8817e4Smiod #include "sysdep.h"
30*3d8817e4Smiod #include <stdio.h>
31*3d8817e4Smiod #include "ansidecl.h"
32*3d8817e4Smiod #include "dis-asm.h"
33*3d8817e4Smiod #include "bfd.h"
34*3d8817e4Smiod #include "symcat.h"
35*3d8817e4Smiod #include "libiberty.h"
36*3d8817e4Smiod #include "xc16x-desc.h"
37*3d8817e4Smiod #include "xc16x-opc.h"
38*3d8817e4Smiod #include "opintl.h"
39*3d8817e4Smiod
40*3d8817e4Smiod /* Default text to print if an instruction isn't recognized. */
41*3d8817e4Smiod #define UNKNOWN_INSN_MSG _("*unknown*")
42*3d8817e4Smiod
43*3d8817e4Smiod static void print_normal
44*3d8817e4Smiod (CGEN_CPU_DESC, void *, long, unsigned int, bfd_vma, int);
45*3d8817e4Smiod static void print_address
46*3d8817e4Smiod (CGEN_CPU_DESC, void *, bfd_vma, unsigned int, bfd_vma, int) ATTRIBUTE_UNUSED;
47*3d8817e4Smiod static void print_keyword
48*3d8817e4Smiod (CGEN_CPU_DESC, void *, CGEN_KEYWORD *, long, unsigned int) ATTRIBUTE_UNUSED;
49*3d8817e4Smiod static void print_insn_normal
50*3d8817e4Smiod (CGEN_CPU_DESC, void *, const CGEN_INSN *, CGEN_FIELDS *, bfd_vma, int);
51*3d8817e4Smiod static int print_insn
52*3d8817e4Smiod (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, unsigned);
53*3d8817e4Smiod static int default_print_insn
54*3d8817e4Smiod (CGEN_CPU_DESC, bfd_vma, disassemble_info *) ATTRIBUTE_UNUSED;
55*3d8817e4Smiod static int read_insn
56*3d8817e4Smiod (CGEN_CPU_DESC, bfd_vma, disassemble_info *, bfd_byte *, int, CGEN_EXTRACT_INFO *,
57*3d8817e4Smiod unsigned long *);
58*3d8817e4Smiod
59*3d8817e4Smiod /* -- disassembler routines inserted here. */
60*3d8817e4Smiod
61*3d8817e4Smiod /* -- dis.c */
62*3d8817e4Smiod
63*3d8817e4Smiod #define CGEN_PRINT_NORMAL(cd, info, value, attrs, pc, length) \
64*3d8817e4Smiod do \
65*3d8817e4Smiod { \
66*3d8817e4Smiod if (CGEN_BOOL_ATTR ((attrs), CGEN_OPERAND_DOT_PREFIX)) \
67*3d8817e4Smiod info->fprintf_func (info->stream, "."); \
68*3d8817e4Smiod if (CGEN_BOOL_ATTR ((attrs), CGEN_OPERAND_POF_PREFIX)) \
69*3d8817e4Smiod info->fprintf_func (info->stream, "#pof:"); \
70*3d8817e4Smiod if (CGEN_BOOL_ATTR ((attrs), CGEN_OPERAND_PAG_PREFIX)) \
71*3d8817e4Smiod info->fprintf_func (info->stream, "#pag:"); \
72*3d8817e4Smiod } \
73*3d8817e4Smiod while (0)
74*3d8817e4Smiod
75*3d8817e4Smiod /* Print a 'pof:' prefix to an operand. */
76*3d8817e4Smiod
77*3d8817e4Smiod static void
print_pof(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info ATTRIBUTE_UNUSED,long value ATTRIBUTE_UNUSED,unsigned int attrs ATTRIBUTE_UNUSED,bfd_vma pc ATTRIBUTE_UNUSED,int length ATTRIBUTE_UNUSED)78*3d8817e4Smiod print_pof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
79*3d8817e4Smiod void * dis_info ATTRIBUTE_UNUSED,
80*3d8817e4Smiod long value ATTRIBUTE_UNUSED,
81*3d8817e4Smiod unsigned int attrs ATTRIBUTE_UNUSED,
82*3d8817e4Smiod bfd_vma pc ATTRIBUTE_UNUSED,
83*3d8817e4Smiod int length ATTRIBUTE_UNUSED)
84*3d8817e4Smiod {
85*3d8817e4Smiod }
86*3d8817e4Smiod
87*3d8817e4Smiod /* Print a 'pag:' prefix to an operand. */
88*3d8817e4Smiod
89*3d8817e4Smiod static void
print_pag(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info ATTRIBUTE_UNUSED,long value ATTRIBUTE_UNUSED,unsigned int attrs ATTRIBUTE_UNUSED,bfd_vma pc ATTRIBUTE_UNUSED,int length ATTRIBUTE_UNUSED)90*3d8817e4Smiod print_pag (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
91*3d8817e4Smiod void * dis_info ATTRIBUTE_UNUSED,
92*3d8817e4Smiod long value ATTRIBUTE_UNUSED,
93*3d8817e4Smiod unsigned int attrs ATTRIBUTE_UNUSED,
94*3d8817e4Smiod bfd_vma pc ATTRIBUTE_UNUSED,
95*3d8817e4Smiod int length ATTRIBUTE_UNUSED)
96*3d8817e4Smiod {
97*3d8817e4Smiod }
98*3d8817e4Smiod
99*3d8817e4Smiod /* Print a 'sof:' prefix to an operand. */
100*3d8817e4Smiod
101*3d8817e4Smiod static void
print_sof(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info,long value ATTRIBUTE_UNUSED,unsigned int attrs ATTRIBUTE_UNUSED,bfd_vma pc ATTRIBUTE_UNUSED,int length ATTRIBUTE_UNUSED)102*3d8817e4Smiod print_sof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
103*3d8817e4Smiod void * dis_info,
104*3d8817e4Smiod long value ATTRIBUTE_UNUSED,
105*3d8817e4Smiod unsigned int attrs ATTRIBUTE_UNUSED,
106*3d8817e4Smiod bfd_vma pc ATTRIBUTE_UNUSED,
107*3d8817e4Smiod int length ATTRIBUTE_UNUSED)
108*3d8817e4Smiod {
109*3d8817e4Smiod disassemble_info *info = (disassemble_info *) dis_info;
110*3d8817e4Smiod
111*3d8817e4Smiod info->fprintf_func (info->stream, "sof:");
112*3d8817e4Smiod }
113*3d8817e4Smiod
114*3d8817e4Smiod /* Print a 'seg:' prefix to an operand. */
115*3d8817e4Smiod
116*3d8817e4Smiod static void
print_seg(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info,long value ATTRIBUTE_UNUSED,unsigned int attrs ATTRIBUTE_UNUSED,bfd_vma pc ATTRIBUTE_UNUSED,int length ATTRIBUTE_UNUSED)117*3d8817e4Smiod print_seg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
118*3d8817e4Smiod void * dis_info,
119*3d8817e4Smiod long value ATTRIBUTE_UNUSED,
120*3d8817e4Smiod unsigned int attrs ATTRIBUTE_UNUSED,
121*3d8817e4Smiod bfd_vma pc ATTRIBUTE_UNUSED,
122*3d8817e4Smiod int length ATTRIBUTE_UNUSED)
123*3d8817e4Smiod {
124*3d8817e4Smiod disassemble_info *info = (disassemble_info *) dis_info;
125*3d8817e4Smiod
126*3d8817e4Smiod info->fprintf_func (info->stream, "seg:");
127*3d8817e4Smiod }
128*3d8817e4Smiod
129*3d8817e4Smiod /* Print a '#' prefix to an operand. */
130*3d8817e4Smiod
131*3d8817e4Smiod static void
print_hash(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info,long value ATTRIBUTE_UNUSED,unsigned int attrs ATTRIBUTE_UNUSED,bfd_vma pc ATTRIBUTE_UNUSED,int length ATTRIBUTE_UNUSED)132*3d8817e4Smiod print_hash (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
133*3d8817e4Smiod void * dis_info,
134*3d8817e4Smiod long value ATTRIBUTE_UNUSED,
135*3d8817e4Smiod unsigned int attrs ATTRIBUTE_UNUSED,
136*3d8817e4Smiod bfd_vma pc ATTRIBUTE_UNUSED,
137*3d8817e4Smiod int length ATTRIBUTE_UNUSED)
138*3d8817e4Smiod {
139*3d8817e4Smiod disassemble_info *info = (disassemble_info *) dis_info;
140*3d8817e4Smiod
141*3d8817e4Smiod info->fprintf_func (info->stream, "#");
142*3d8817e4Smiod }
143*3d8817e4Smiod
144*3d8817e4Smiod /* Print a '.' prefix to an operand. */
145*3d8817e4Smiod
146*3d8817e4Smiod static void
print_dot(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info ATTRIBUTE_UNUSED,long value ATTRIBUTE_UNUSED,unsigned int attrs ATTRIBUTE_UNUSED,bfd_vma pc ATTRIBUTE_UNUSED,int length ATTRIBUTE_UNUSED)147*3d8817e4Smiod print_dot (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
148*3d8817e4Smiod void * dis_info ATTRIBUTE_UNUSED,
149*3d8817e4Smiod long value ATTRIBUTE_UNUSED,
150*3d8817e4Smiod unsigned int attrs ATTRIBUTE_UNUSED,
151*3d8817e4Smiod bfd_vma pc ATTRIBUTE_UNUSED,
152*3d8817e4Smiod int length ATTRIBUTE_UNUSED)
153*3d8817e4Smiod {
154*3d8817e4Smiod }
155*3d8817e4Smiod
156*3d8817e4Smiod /* -- */
157*3d8817e4Smiod
158*3d8817e4Smiod void xc16x_cgen_print_operand
159*3d8817e4Smiod (CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *, void const *, bfd_vma, int);
160*3d8817e4Smiod
161*3d8817e4Smiod /* Main entry point for printing operands.
162*3d8817e4Smiod XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
163*3d8817e4Smiod of dis-asm.h on cgen.h.
164*3d8817e4Smiod
165*3d8817e4Smiod This function is basically just a big switch statement. Earlier versions
166*3d8817e4Smiod used tables to look up the function to use, but
167*3d8817e4Smiod - if the table contains both assembler and disassembler functions then
168*3d8817e4Smiod the disassembler contains much of the assembler and vice-versa,
169*3d8817e4Smiod - there's a lot of inlining possibilities as things grow,
170*3d8817e4Smiod - using a switch statement avoids the function call overhead.
171*3d8817e4Smiod
172*3d8817e4Smiod This function could be moved into `print_insn_normal', but keeping it
173*3d8817e4Smiod separate makes clear the interface between `print_insn_normal' and each of
174*3d8817e4Smiod the handlers. */
175*3d8817e4Smiod
176*3d8817e4Smiod void
xc16x_cgen_print_operand(CGEN_CPU_DESC cd,int opindex,void * xinfo,CGEN_FIELDS * fields,void const * attrs ATTRIBUTE_UNUSED,bfd_vma pc,int length)177*3d8817e4Smiod xc16x_cgen_print_operand (CGEN_CPU_DESC cd,
178*3d8817e4Smiod int opindex,
179*3d8817e4Smiod void * xinfo,
180*3d8817e4Smiod CGEN_FIELDS *fields,
181*3d8817e4Smiod void const *attrs ATTRIBUTE_UNUSED,
182*3d8817e4Smiod bfd_vma pc,
183*3d8817e4Smiod int length)
184*3d8817e4Smiod {
185*3d8817e4Smiod disassemble_info *info = (disassemble_info *) xinfo;
186*3d8817e4Smiod
187*3d8817e4Smiod switch (opindex)
188*3d8817e4Smiod {
189*3d8817e4Smiod case XC16X_OPERAND_REGNAM :
190*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_psw_names, fields->f_reg8, 0);
191*3d8817e4Smiod break;
192*3d8817e4Smiod case XC16X_OPERAND_BIT01 :
193*3d8817e4Smiod print_normal (cd, info, fields->f_op_1bit, 0, pc, length);
194*3d8817e4Smiod break;
195*3d8817e4Smiod case XC16X_OPERAND_BIT1 :
196*3d8817e4Smiod print_normal (cd, info, fields->f_op_bit1, 0, pc, length);
197*3d8817e4Smiod break;
198*3d8817e4Smiod case XC16X_OPERAND_BIT2 :
199*3d8817e4Smiod print_normal (cd, info, fields->f_op_bit2, 0, pc, length);
200*3d8817e4Smiod break;
201*3d8817e4Smiod case XC16X_OPERAND_BIT4 :
202*3d8817e4Smiod print_normal (cd, info, fields->f_op_bit4, 0, pc, length);
203*3d8817e4Smiod break;
204*3d8817e4Smiod case XC16X_OPERAND_BIT8 :
205*3d8817e4Smiod print_normal (cd, info, fields->f_op_bit8, 0, pc, length);
206*3d8817e4Smiod break;
207*3d8817e4Smiod case XC16X_OPERAND_BITONE :
208*3d8817e4Smiod print_normal (cd, info, fields->f_op_onebit, 0, pc, length);
209*3d8817e4Smiod break;
210*3d8817e4Smiod case XC16X_OPERAND_CADDR :
211*3d8817e4Smiod print_address (cd, info, fields->f_offset16, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
212*3d8817e4Smiod break;
213*3d8817e4Smiod case XC16X_OPERAND_COND :
214*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_conditioncode_names, fields->f_condcode, 0);
215*3d8817e4Smiod break;
216*3d8817e4Smiod case XC16X_OPERAND_DATA8 :
217*3d8817e4Smiod print_normal (cd, info, fields->f_data8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
218*3d8817e4Smiod break;
219*3d8817e4Smiod case XC16X_OPERAND_DATAHI8 :
220*3d8817e4Smiod print_normal (cd, info, fields->f_datahi8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
221*3d8817e4Smiod break;
222*3d8817e4Smiod case XC16X_OPERAND_DOT :
223*3d8817e4Smiod print_dot (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
224*3d8817e4Smiod break;
225*3d8817e4Smiod case XC16X_OPERAND_DR :
226*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r1, 0);
227*3d8817e4Smiod break;
228*3d8817e4Smiod case XC16X_OPERAND_DRB :
229*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_grb_names, fields->f_r1, 0);
230*3d8817e4Smiod break;
231*3d8817e4Smiod case XC16X_OPERAND_DRI :
232*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r4, 0);
233*3d8817e4Smiod break;
234*3d8817e4Smiod case XC16X_OPERAND_EXTCOND :
235*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_extconditioncode_names, fields->f_extccode, 0);
236*3d8817e4Smiod break;
237*3d8817e4Smiod case XC16X_OPERAND_GENREG :
238*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_r8_names, fields->f_regb8, 0);
239*3d8817e4Smiod break;
240*3d8817e4Smiod case XC16X_OPERAND_HASH :
241*3d8817e4Smiod print_hash (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
242*3d8817e4Smiod break;
243*3d8817e4Smiod case XC16X_OPERAND_ICOND :
244*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_conditioncode_names, fields->f_icondcode, 0);
245*3d8817e4Smiod break;
246*3d8817e4Smiod case XC16X_OPERAND_LBIT2 :
247*3d8817e4Smiod print_normal (cd, info, fields->f_op_lbit2, 0, pc, length);
248*3d8817e4Smiod break;
249*3d8817e4Smiod case XC16X_OPERAND_LBIT4 :
250*3d8817e4Smiod print_normal (cd, info, fields->f_op_lbit4, 0, pc, length);
251*3d8817e4Smiod break;
252*3d8817e4Smiod case XC16X_OPERAND_MASK8 :
253*3d8817e4Smiod print_normal (cd, info, fields->f_mask8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
254*3d8817e4Smiod break;
255*3d8817e4Smiod case XC16X_OPERAND_MASKLO8 :
256*3d8817e4Smiod print_normal (cd, info, fields->f_datahi8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
257*3d8817e4Smiod break;
258*3d8817e4Smiod case XC16X_OPERAND_MEMGR8 :
259*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_memgr8_names, fields->f_memgr8, 0);
260*3d8817e4Smiod break;
261*3d8817e4Smiod case XC16X_OPERAND_MEMORY :
262*3d8817e4Smiod print_address (cd, info, fields->f_memory, 0, pc, length);
263*3d8817e4Smiod break;
264*3d8817e4Smiod case XC16X_OPERAND_PAG :
265*3d8817e4Smiod print_pag (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
266*3d8817e4Smiod break;
267*3d8817e4Smiod case XC16X_OPERAND_PAGENUM :
268*3d8817e4Smiod print_normal (cd, info, fields->f_pagenum, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
269*3d8817e4Smiod break;
270*3d8817e4Smiod case XC16X_OPERAND_POF :
271*3d8817e4Smiod print_pof (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
272*3d8817e4Smiod break;
273*3d8817e4Smiod case XC16X_OPERAND_QBIT :
274*3d8817e4Smiod print_normal (cd, info, fields->f_qbit, 0|(1<<CGEN_OPERAND_DOT_PREFIX), pc, length);
275*3d8817e4Smiod break;
276*3d8817e4Smiod case XC16X_OPERAND_QHIBIT :
277*3d8817e4Smiod print_normal (cd, info, fields->f_qhibit, 0|(1<<CGEN_OPERAND_DOT_PREFIX), pc, length);
278*3d8817e4Smiod break;
279*3d8817e4Smiod case XC16X_OPERAND_QLOBIT :
280*3d8817e4Smiod print_normal (cd, info, fields->f_qlobit, 0|(1<<CGEN_OPERAND_DOT_PREFIX), pc, length);
281*3d8817e4Smiod break;
282*3d8817e4Smiod case XC16X_OPERAND_REG8 :
283*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_r8_names, fields->f_reg8, 0);
284*3d8817e4Smiod break;
285*3d8817e4Smiod case XC16X_OPERAND_REGB8 :
286*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_grb8_names, fields->f_regb8, 0);
287*3d8817e4Smiod break;
288*3d8817e4Smiod case XC16X_OPERAND_REGBMEM8 :
289*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_regbmem8_names, fields->f_regmem8, 0);
290*3d8817e4Smiod break;
291*3d8817e4Smiod case XC16X_OPERAND_REGHI8 :
292*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_r8_names, fields->f_reghi8, 0);
293*3d8817e4Smiod break;
294*3d8817e4Smiod case XC16X_OPERAND_REGMEM8 :
295*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_regmem8_names, fields->f_regmem8, 0);
296*3d8817e4Smiod break;
297*3d8817e4Smiod case XC16X_OPERAND_REGOFF8 :
298*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_r8_names, fields->f_regoff8, 0);
299*3d8817e4Smiod break;
300*3d8817e4Smiod case XC16X_OPERAND_REL :
301*3d8817e4Smiod print_normal (cd, info, fields->f_rel8, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
302*3d8817e4Smiod break;
303*3d8817e4Smiod case XC16X_OPERAND_RELHI :
304*3d8817e4Smiod print_normal (cd, info, fields->f_relhi8, 0|(1<<CGEN_OPERAND_SIGNED)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
305*3d8817e4Smiod break;
306*3d8817e4Smiod case XC16X_OPERAND_SEG :
307*3d8817e4Smiod print_normal (cd, info, fields->f_seg8, 0, pc, length);
308*3d8817e4Smiod break;
309*3d8817e4Smiod case XC16X_OPERAND_SEGHI8 :
310*3d8817e4Smiod print_normal (cd, info, fields->f_segnum8, 0, pc, length);
311*3d8817e4Smiod break;
312*3d8817e4Smiod case XC16X_OPERAND_SEGM :
313*3d8817e4Smiod print_seg (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
314*3d8817e4Smiod break;
315*3d8817e4Smiod case XC16X_OPERAND_SOF :
316*3d8817e4Smiod print_sof (cd, info, 0, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
317*3d8817e4Smiod break;
318*3d8817e4Smiod case XC16X_OPERAND_SR :
319*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r2, 0);
320*3d8817e4Smiod break;
321*3d8817e4Smiod case XC16X_OPERAND_SR2 :
322*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r0, 0);
323*3d8817e4Smiod break;
324*3d8817e4Smiod case XC16X_OPERAND_SRB :
325*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_grb_names, fields->f_r2, 0);
326*3d8817e4Smiod break;
327*3d8817e4Smiod case XC16X_OPERAND_SRC1 :
328*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r1, 0);
329*3d8817e4Smiod break;
330*3d8817e4Smiod case XC16X_OPERAND_SRC2 :
331*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_gr_names, fields->f_r2, 0);
332*3d8817e4Smiod break;
333*3d8817e4Smiod case XC16X_OPERAND_SRDIV :
334*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_regdiv8_names, fields->f_reg8, 0);
335*3d8817e4Smiod break;
336*3d8817e4Smiod case XC16X_OPERAND_U4 :
337*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_reg0_name, fields->f_uimm4, 0);
338*3d8817e4Smiod break;
339*3d8817e4Smiod case XC16X_OPERAND_UIMM16 :
340*3d8817e4Smiod print_normal (cd, info, fields->f_uimm16, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
341*3d8817e4Smiod break;
342*3d8817e4Smiod case XC16X_OPERAND_UIMM2 :
343*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_ext_names, fields->f_uimm2, 0|(1<<CGEN_OPERAND_HASH_PREFIX));
344*3d8817e4Smiod break;
345*3d8817e4Smiod case XC16X_OPERAND_UIMM3 :
346*3d8817e4Smiod print_keyword (cd, info, & xc16x_cgen_opval_reg0_name1, fields->f_uimm3, 0|(1<<CGEN_OPERAND_HASH_PREFIX));
347*3d8817e4Smiod break;
348*3d8817e4Smiod case XC16X_OPERAND_UIMM4 :
349*3d8817e4Smiod print_normal (cd, info, fields->f_uimm4, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
350*3d8817e4Smiod break;
351*3d8817e4Smiod case XC16X_OPERAND_UIMM7 :
352*3d8817e4Smiod print_normal (cd, info, fields->f_uimm7, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), pc, length);
353*3d8817e4Smiod break;
354*3d8817e4Smiod case XC16X_OPERAND_UIMM8 :
355*3d8817e4Smiod print_normal (cd, info, fields->f_uimm8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), pc, length);
356*3d8817e4Smiod break;
357*3d8817e4Smiod case XC16X_OPERAND_UPAG16 :
358*3d8817e4Smiod print_normal (cd, info, fields->f_uimm16, 0|(1<<CGEN_OPERAND_PAG_PREFIX), pc, length);
359*3d8817e4Smiod break;
360*3d8817e4Smiod case XC16X_OPERAND_UPOF16 :
361*3d8817e4Smiod print_address (cd, info, fields->f_memory, 0|(1<<CGEN_OPERAND_POF_PREFIX), pc, length);
362*3d8817e4Smiod break;
363*3d8817e4Smiod case XC16X_OPERAND_USEG16 :
364*3d8817e4Smiod print_normal (cd, info, fields->f_offset16, 0|(1<<CGEN_OPERAND_SEG_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
365*3d8817e4Smiod break;
366*3d8817e4Smiod case XC16X_OPERAND_USEG8 :
367*3d8817e4Smiod print_normal (cd, info, fields->f_seg8, 0|(1<<CGEN_OPERAND_SEG_PREFIX), pc, length);
368*3d8817e4Smiod break;
369*3d8817e4Smiod case XC16X_OPERAND_USOF16 :
370*3d8817e4Smiod print_normal (cd, info, fields->f_offset16, 0|(1<<CGEN_OPERAND_SOF_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
371*3d8817e4Smiod break;
372*3d8817e4Smiod
373*3d8817e4Smiod default :
374*3d8817e4Smiod /* xgettext:c-format */
375*3d8817e4Smiod fprintf (stderr, _("Unrecognized field %d while printing insn.\n"),
376*3d8817e4Smiod opindex);
377*3d8817e4Smiod abort ();
378*3d8817e4Smiod }
379*3d8817e4Smiod }
380*3d8817e4Smiod
381*3d8817e4Smiod cgen_print_fn * const xc16x_cgen_print_handlers[] =
382*3d8817e4Smiod {
383*3d8817e4Smiod print_insn_normal,
384*3d8817e4Smiod };
385*3d8817e4Smiod
386*3d8817e4Smiod
387*3d8817e4Smiod void
xc16x_cgen_init_dis(CGEN_CPU_DESC cd)388*3d8817e4Smiod xc16x_cgen_init_dis (CGEN_CPU_DESC cd)
389*3d8817e4Smiod {
390*3d8817e4Smiod xc16x_cgen_init_opcode_table (cd);
391*3d8817e4Smiod xc16x_cgen_init_ibld_table (cd);
392*3d8817e4Smiod cd->print_handlers = & xc16x_cgen_print_handlers[0];
393*3d8817e4Smiod cd->print_operand = xc16x_cgen_print_operand;
394*3d8817e4Smiod }
395*3d8817e4Smiod
396*3d8817e4Smiod
397*3d8817e4Smiod /* Default print handler. */
398*3d8817e4Smiod
399*3d8817e4Smiod static void
print_normal(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info,long value,unsigned int attrs,bfd_vma pc ATTRIBUTE_UNUSED,int length ATTRIBUTE_UNUSED)400*3d8817e4Smiod print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
401*3d8817e4Smiod void *dis_info,
402*3d8817e4Smiod long value,
403*3d8817e4Smiod unsigned int attrs,
404*3d8817e4Smiod bfd_vma pc ATTRIBUTE_UNUSED,
405*3d8817e4Smiod int length ATTRIBUTE_UNUSED)
406*3d8817e4Smiod {
407*3d8817e4Smiod disassemble_info *info = (disassemble_info *) dis_info;
408*3d8817e4Smiod
409*3d8817e4Smiod #ifdef CGEN_PRINT_NORMAL
410*3d8817e4Smiod CGEN_PRINT_NORMAL (cd, info, value, attrs, pc, length);
411*3d8817e4Smiod #endif
412*3d8817e4Smiod
413*3d8817e4Smiod /* Print the operand as directed by the attributes. */
414*3d8817e4Smiod if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
415*3d8817e4Smiod ; /* nothing to do */
416*3d8817e4Smiod else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
417*3d8817e4Smiod (*info->fprintf_func) (info->stream, "%ld", value);
418*3d8817e4Smiod else
419*3d8817e4Smiod (*info->fprintf_func) (info->stream, "0x%lx", value);
420*3d8817e4Smiod }
421*3d8817e4Smiod
422*3d8817e4Smiod /* Default address handler. */
423*3d8817e4Smiod
424*3d8817e4Smiod static void
print_address(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info,bfd_vma value,unsigned int attrs,bfd_vma pc ATTRIBUTE_UNUSED,int length ATTRIBUTE_UNUSED)425*3d8817e4Smiod print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
426*3d8817e4Smiod void *dis_info,
427*3d8817e4Smiod bfd_vma value,
428*3d8817e4Smiod unsigned int attrs,
429*3d8817e4Smiod bfd_vma pc ATTRIBUTE_UNUSED,
430*3d8817e4Smiod int length ATTRIBUTE_UNUSED)
431*3d8817e4Smiod {
432*3d8817e4Smiod disassemble_info *info = (disassemble_info *) dis_info;
433*3d8817e4Smiod
434*3d8817e4Smiod #ifdef CGEN_PRINT_ADDRESS
435*3d8817e4Smiod CGEN_PRINT_ADDRESS (cd, info, value, attrs, pc, length);
436*3d8817e4Smiod #endif
437*3d8817e4Smiod
438*3d8817e4Smiod /* Print the operand as directed by the attributes. */
439*3d8817e4Smiod if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
440*3d8817e4Smiod ; /* Nothing to do. */
441*3d8817e4Smiod else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
442*3d8817e4Smiod (*info->print_address_func) (value, info);
443*3d8817e4Smiod else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
444*3d8817e4Smiod (*info->print_address_func) (value, info);
445*3d8817e4Smiod else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
446*3d8817e4Smiod (*info->fprintf_func) (info->stream, "%ld", (long) value);
447*3d8817e4Smiod else
448*3d8817e4Smiod (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
449*3d8817e4Smiod }
450*3d8817e4Smiod
451*3d8817e4Smiod /* Keyword print handler. */
452*3d8817e4Smiod
453*3d8817e4Smiod static void
print_keyword(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,void * dis_info,CGEN_KEYWORD * keyword_table,long value,unsigned int attrs ATTRIBUTE_UNUSED)454*3d8817e4Smiod print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
455*3d8817e4Smiod void *dis_info,
456*3d8817e4Smiod CGEN_KEYWORD *keyword_table,
457*3d8817e4Smiod long value,
458*3d8817e4Smiod unsigned int attrs ATTRIBUTE_UNUSED)
459*3d8817e4Smiod {
460*3d8817e4Smiod disassemble_info *info = (disassemble_info *) dis_info;
461*3d8817e4Smiod const CGEN_KEYWORD_ENTRY *ke;
462*3d8817e4Smiod
463*3d8817e4Smiod ke = cgen_keyword_lookup_value (keyword_table, value);
464*3d8817e4Smiod if (ke != NULL)
465*3d8817e4Smiod (*info->fprintf_func) (info->stream, "%s", ke->name);
466*3d8817e4Smiod else
467*3d8817e4Smiod (*info->fprintf_func) (info->stream, "???");
468*3d8817e4Smiod }
469*3d8817e4Smiod
470*3d8817e4Smiod /* Default insn printer.
471*3d8817e4Smiod
472*3d8817e4Smiod DIS_INFO is defined as `void *' so the disassembler needn't know anything
473*3d8817e4Smiod about disassemble_info. */
474*3d8817e4Smiod
475*3d8817e4Smiod static void
print_insn_normal(CGEN_CPU_DESC cd,void * dis_info,const CGEN_INSN * insn,CGEN_FIELDS * fields,bfd_vma pc,int length)476*3d8817e4Smiod print_insn_normal (CGEN_CPU_DESC cd,
477*3d8817e4Smiod void *dis_info,
478*3d8817e4Smiod const CGEN_INSN *insn,
479*3d8817e4Smiod CGEN_FIELDS *fields,
480*3d8817e4Smiod bfd_vma pc,
481*3d8817e4Smiod int length)
482*3d8817e4Smiod {
483*3d8817e4Smiod const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
484*3d8817e4Smiod disassemble_info *info = (disassemble_info *) dis_info;
485*3d8817e4Smiod const CGEN_SYNTAX_CHAR_TYPE *syn;
486*3d8817e4Smiod
487*3d8817e4Smiod CGEN_INIT_PRINT (cd);
488*3d8817e4Smiod
489*3d8817e4Smiod for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
490*3d8817e4Smiod {
491*3d8817e4Smiod if (CGEN_SYNTAX_MNEMONIC_P (*syn))
492*3d8817e4Smiod {
493*3d8817e4Smiod (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
494*3d8817e4Smiod continue;
495*3d8817e4Smiod }
496*3d8817e4Smiod if (CGEN_SYNTAX_CHAR_P (*syn))
497*3d8817e4Smiod {
498*3d8817e4Smiod (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
499*3d8817e4Smiod continue;
500*3d8817e4Smiod }
501*3d8817e4Smiod
502*3d8817e4Smiod /* We have an operand. */
503*3d8817e4Smiod xc16x_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
504*3d8817e4Smiod fields, CGEN_INSN_ATTRS (insn), pc, length);
505*3d8817e4Smiod }
506*3d8817e4Smiod }
507*3d8817e4Smiod
508*3d8817e4Smiod /* Subroutine of print_insn. Reads an insn into the given buffers and updates
509*3d8817e4Smiod the extract info.
510*3d8817e4Smiod Returns 0 if all is well, non-zero otherwise. */
511*3d8817e4Smiod
512*3d8817e4Smiod static int
read_insn(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,bfd_vma pc,disassemble_info * info,bfd_byte * buf,int buflen,CGEN_EXTRACT_INFO * ex_info,unsigned long * insn_value)513*3d8817e4Smiod read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
514*3d8817e4Smiod bfd_vma pc,
515*3d8817e4Smiod disassemble_info *info,
516*3d8817e4Smiod bfd_byte *buf,
517*3d8817e4Smiod int buflen,
518*3d8817e4Smiod CGEN_EXTRACT_INFO *ex_info,
519*3d8817e4Smiod unsigned long *insn_value)
520*3d8817e4Smiod {
521*3d8817e4Smiod int status = (*info->read_memory_func) (pc, buf, buflen, info);
522*3d8817e4Smiod
523*3d8817e4Smiod if (status != 0)
524*3d8817e4Smiod {
525*3d8817e4Smiod (*info->memory_error_func) (status, pc, info);
526*3d8817e4Smiod return -1;
527*3d8817e4Smiod }
528*3d8817e4Smiod
529*3d8817e4Smiod ex_info->dis_info = info;
530*3d8817e4Smiod ex_info->valid = (1 << buflen) - 1;
531*3d8817e4Smiod ex_info->insn_bytes = buf;
532*3d8817e4Smiod
533*3d8817e4Smiod *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG);
534*3d8817e4Smiod return 0;
535*3d8817e4Smiod }
536*3d8817e4Smiod
537*3d8817e4Smiod /* Utility to print an insn.
538*3d8817e4Smiod BUF is the base part of the insn, target byte order, BUFLEN bytes long.
539*3d8817e4Smiod The result is the size of the insn in bytes or zero for an unknown insn
540*3d8817e4Smiod or -1 if an error occurs fetching data (memory_error_func will have
541*3d8817e4Smiod been called). */
542*3d8817e4Smiod
543*3d8817e4Smiod static int
print_insn(CGEN_CPU_DESC cd,bfd_vma pc,disassemble_info * info,bfd_byte * buf,unsigned int buflen)544*3d8817e4Smiod print_insn (CGEN_CPU_DESC cd,
545*3d8817e4Smiod bfd_vma pc,
546*3d8817e4Smiod disassemble_info *info,
547*3d8817e4Smiod bfd_byte *buf,
548*3d8817e4Smiod unsigned int buflen)
549*3d8817e4Smiod {
550*3d8817e4Smiod CGEN_INSN_INT insn_value;
551*3d8817e4Smiod const CGEN_INSN_LIST *insn_list;
552*3d8817e4Smiod CGEN_EXTRACT_INFO ex_info;
553*3d8817e4Smiod int basesize;
554*3d8817e4Smiod
555*3d8817e4Smiod /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
556*3d8817e4Smiod basesize = cd->base_insn_bitsize < buflen * 8 ?
557*3d8817e4Smiod cd->base_insn_bitsize : buflen * 8;
558*3d8817e4Smiod insn_value = cgen_get_insn_value (cd, buf, basesize);
559*3d8817e4Smiod
560*3d8817e4Smiod
561*3d8817e4Smiod /* Fill in ex_info fields like read_insn would. Don't actually call
562*3d8817e4Smiod read_insn, since the incoming buffer is already read (and possibly
563*3d8817e4Smiod modified a la m32r). */
564*3d8817e4Smiod ex_info.valid = (1 << buflen) - 1;
565*3d8817e4Smiod ex_info.dis_info = info;
566*3d8817e4Smiod ex_info.insn_bytes = buf;
567*3d8817e4Smiod
568*3d8817e4Smiod /* The instructions are stored in hash lists.
569*3d8817e4Smiod Pick the first one and keep trying until we find the right one. */
570*3d8817e4Smiod
571*3d8817e4Smiod insn_list = CGEN_DIS_LOOKUP_INSN (cd, (char *) buf, insn_value);
572*3d8817e4Smiod while (insn_list != NULL)
573*3d8817e4Smiod {
574*3d8817e4Smiod const CGEN_INSN *insn = insn_list->insn;
575*3d8817e4Smiod CGEN_FIELDS fields;
576*3d8817e4Smiod int length;
577*3d8817e4Smiod unsigned long insn_value_cropped;
578*3d8817e4Smiod
579*3d8817e4Smiod #ifdef CGEN_VALIDATE_INSN_SUPPORTED
580*3d8817e4Smiod /* Not needed as insn shouldn't be in hash lists if not supported. */
581*3d8817e4Smiod /* Supported by this cpu? */
582*3d8817e4Smiod if (! xc16x_cgen_insn_supported (cd, insn))
583*3d8817e4Smiod {
584*3d8817e4Smiod insn_list = CGEN_DIS_NEXT_INSN (insn_list);
585*3d8817e4Smiod continue;
586*3d8817e4Smiod }
587*3d8817e4Smiod #endif
588*3d8817e4Smiod
589*3d8817e4Smiod /* Basic bit mask must be correct. */
590*3d8817e4Smiod /* ??? May wish to allow target to defer this check until the extract
591*3d8817e4Smiod handler. */
592*3d8817e4Smiod
593*3d8817e4Smiod /* Base size may exceed this instruction's size. Extract the
594*3d8817e4Smiod relevant part from the buffer. */
595*3d8817e4Smiod if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen &&
596*3d8817e4Smiod (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
597*3d8817e4Smiod insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn),
598*3d8817e4Smiod info->endian == BFD_ENDIAN_BIG);
599*3d8817e4Smiod else
600*3d8817e4Smiod insn_value_cropped = insn_value;
601*3d8817e4Smiod
602*3d8817e4Smiod if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn))
603*3d8817e4Smiod == CGEN_INSN_BASE_VALUE (insn))
604*3d8817e4Smiod {
605*3d8817e4Smiod /* Printing is handled in two passes. The first pass parses the
606*3d8817e4Smiod machine insn and extracts the fields. The second pass prints
607*3d8817e4Smiod them. */
608*3d8817e4Smiod
609*3d8817e4Smiod /* Make sure the entire insn is loaded into insn_value, if it
610*3d8817e4Smiod can fit. */
611*3d8817e4Smiod if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) &&
612*3d8817e4Smiod (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
613*3d8817e4Smiod {
614*3d8817e4Smiod unsigned long full_insn_value;
615*3d8817e4Smiod int rc = read_insn (cd, pc, info, buf,
616*3d8817e4Smiod CGEN_INSN_BITSIZE (insn) / 8,
617*3d8817e4Smiod & ex_info, & full_insn_value);
618*3d8817e4Smiod if (rc != 0)
619*3d8817e4Smiod return rc;
620*3d8817e4Smiod length = CGEN_EXTRACT_FN (cd, insn)
621*3d8817e4Smiod (cd, insn, &ex_info, full_insn_value, &fields, pc);
622*3d8817e4Smiod }
623*3d8817e4Smiod else
624*3d8817e4Smiod length = CGEN_EXTRACT_FN (cd, insn)
625*3d8817e4Smiod (cd, insn, &ex_info, insn_value_cropped, &fields, pc);
626*3d8817e4Smiod
627*3d8817e4Smiod /* Length < 0 -> error. */
628*3d8817e4Smiod if (length < 0)
629*3d8817e4Smiod return length;
630*3d8817e4Smiod if (length > 0)
631*3d8817e4Smiod {
632*3d8817e4Smiod CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
633*3d8817e4Smiod /* Length is in bits, result is in bytes. */
634*3d8817e4Smiod return length / 8;
635*3d8817e4Smiod }
636*3d8817e4Smiod }
637*3d8817e4Smiod
638*3d8817e4Smiod insn_list = CGEN_DIS_NEXT_INSN (insn_list);
639*3d8817e4Smiod }
640*3d8817e4Smiod
641*3d8817e4Smiod return 0;
642*3d8817e4Smiod }
643*3d8817e4Smiod
644*3d8817e4Smiod /* Default value for CGEN_PRINT_INSN.
645*3d8817e4Smiod The result is the size of the insn in bytes or zero for an unknown insn
646*3d8817e4Smiod or -1 if an error occured fetching bytes. */
647*3d8817e4Smiod
648*3d8817e4Smiod #ifndef CGEN_PRINT_INSN
649*3d8817e4Smiod #define CGEN_PRINT_INSN default_print_insn
650*3d8817e4Smiod #endif
651*3d8817e4Smiod
652*3d8817e4Smiod static int
default_print_insn(CGEN_CPU_DESC cd,bfd_vma pc,disassemble_info * info)653*3d8817e4Smiod default_print_insn (CGEN_CPU_DESC cd, bfd_vma pc, disassemble_info *info)
654*3d8817e4Smiod {
655*3d8817e4Smiod bfd_byte buf[CGEN_MAX_INSN_SIZE];
656*3d8817e4Smiod int buflen;
657*3d8817e4Smiod int status;
658*3d8817e4Smiod
659*3d8817e4Smiod /* Attempt to read the base part of the insn. */
660*3d8817e4Smiod buflen = cd->base_insn_bitsize / 8;
661*3d8817e4Smiod status = (*info->read_memory_func) (pc, buf, buflen, info);
662*3d8817e4Smiod
663*3d8817e4Smiod /* Try again with the minimum part, if min < base. */
664*3d8817e4Smiod if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
665*3d8817e4Smiod {
666*3d8817e4Smiod buflen = cd->min_insn_bitsize / 8;
667*3d8817e4Smiod status = (*info->read_memory_func) (pc, buf, buflen, info);
668*3d8817e4Smiod }
669*3d8817e4Smiod
670*3d8817e4Smiod if (status != 0)
671*3d8817e4Smiod {
672*3d8817e4Smiod (*info->memory_error_func) (status, pc, info);
673*3d8817e4Smiod return -1;
674*3d8817e4Smiod }
675*3d8817e4Smiod
676*3d8817e4Smiod return print_insn (cd, pc, info, buf, buflen);
677*3d8817e4Smiod }
678*3d8817e4Smiod
679*3d8817e4Smiod /* Main entry point.
680*3d8817e4Smiod Print one instruction from PC on INFO->STREAM.
681*3d8817e4Smiod Return the size of the instruction (in bytes). */
682*3d8817e4Smiod
683*3d8817e4Smiod typedef struct cpu_desc_list
684*3d8817e4Smiod {
685*3d8817e4Smiod struct cpu_desc_list *next;
686*3d8817e4Smiod CGEN_BITSET *isa;
687*3d8817e4Smiod int mach;
688*3d8817e4Smiod int endian;
689*3d8817e4Smiod CGEN_CPU_DESC cd;
690*3d8817e4Smiod } cpu_desc_list;
691*3d8817e4Smiod
692*3d8817e4Smiod int
print_insn_xc16x(bfd_vma pc,disassemble_info * info)693*3d8817e4Smiod print_insn_xc16x (bfd_vma pc, disassemble_info *info)
694*3d8817e4Smiod {
695*3d8817e4Smiod static cpu_desc_list *cd_list = 0;
696*3d8817e4Smiod cpu_desc_list *cl = 0;
697*3d8817e4Smiod static CGEN_CPU_DESC cd = 0;
698*3d8817e4Smiod static CGEN_BITSET *prev_isa;
699*3d8817e4Smiod static int prev_mach;
700*3d8817e4Smiod static int prev_endian;
701*3d8817e4Smiod int length;
702*3d8817e4Smiod CGEN_BITSET *isa;
703*3d8817e4Smiod int mach;
704*3d8817e4Smiod int endian = (info->endian == BFD_ENDIAN_BIG
705*3d8817e4Smiod ? CGEN_ENDIAN_BIG
706*3d8817e4Smiod : CGEN_ENDIAN_LITTLE);
707*3d8817e4Smiod enum bfd_architecture arch;
708*3d8817e4Smiod
709*3d8817e4Smiod /* ??? gdb will set mach but leave the architecture as "unknown" */
710*3d8817e4Smiod #ifndef CGEN_BFD_ARCH
711*3d8817e4Smiod #define CGEN_BFD_ARCH bfd_arch_xc16x
712*3d8817e4Smiod #endif
713*3d8817e4Smiod arch = info->arch;
714*3d8817e4Smiod if (arch == bfd_arch_unknown)
715*3d8817e4Smiod arch = CGEN_BFD_ARCH;
716*3d8817e4Smiod
717*3d8817e4Smiod /* There's no standard way to compute the machine or isa number
718*3d8817e4Smiod so we leave it to the target. */
719*3d8817e4Smiod #ifdef CGEN_COMPUTE_MACH
720*3d8817e4Smiod mach = CGEN_COMPUTE_MACH (info);
721*3d8817e4Smiod #else
722*3d8817e4Smiod mach = info->mach;
723*3d8817e4Smiod #endif
724*3d8817e4Smiod
725*3d8817e4Smiod #ifdef CGEN_COMPUTE_ISA
726*3d8817e4Smiod {
727*3d8817e4Smiod static CGEN_BITSET *permanent_isa;
728*3d8817e4Smiod
729*3d8817e4Smiod if (!permanent_isa)
730*3d8817e4Smiod permanent_isa = cgen_bitset_create (MAX_ISAS);
731*3d8817e4Smiod isa = permanent_isa;
732*3d8817e4Smiod cgen_bitset_clear (isa);
733*3d8817e4Smiod cgen_bitset_add (isa, CGEN_COMPUTE_ISA (info));
734*3d8817e4Smiod }
735*3d8817e4Smiod #else
736*3d8817e4Smiod isa = info->insn_sets;
737*3d8817e4Smiod #endif
738*3d8817e4Smiod
739*3d8817e4Smiod /* If we've switched cpu's, try to find a handle we've used before */
740*3d8817e4Smiod if (cd
741*3d8817e4Smiod && (cgen_bitset_compare (isa, prev_isa) != 0
742*3d8817e4Smiod || mach != prev_mach
743*3d8817e4Smiod || endian != prev_endian))
744*3d8817e4Smiod {
745*3d8817e4Smiod cd = 0;
746*3d8817e4Smiod for (cl = cd_list; cl; cl = cl->next)
747*3d8817e4Smiod {
748*3d8817e4Smiod if (cgen_bitset_compare (cl->isa, isa) == 0 &&
749*3d8817e4Smiod cl->mach == mach &&
750*3d8817e4Smiod cl->endian == endian)
751*3d8817e4Smiod {
752*3d8817e4Smiod cd = cl->cd;
753*3d8817e4Smiod prev_isa = cd->isas;
754*3d8817e4Smiod break;
755*3d8817e4Smiod }
756*3d8817e4Smiod }
757*3d8817e4Smiod }
758*3d8817e4Smiod
759*3d8817e4Smiod /* If we haven't initialized yet, initialize the opcode table. */
760*3d8817e4Smiod if (! cd)
761*3d8817e4Smiod {
762*3d8817e4Smiod const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
763*3d8817e4Smiod const char *mach_name;
764*3d8817e4Smiod
765*3d8817e4Smiod if (!arch_type)
766*3d8817e4Smiod abort ();
767*3d8817e4Smiod mach_name = arch_type->printable_name;
768*3d8817e4Smiod
769*3d8817e4Smiod prev_isa = cgen_bitset_copy (isa);
770*3d8817e4Smiod prev_mach = mach;
771*3d8817e4Smiod prev_endian = endian;
772*3d8817e4Smiod cd = xc16x_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
773*3d8817e4Smiod CGEN_CPU_OPEN_BFDMACH, mach_name,
774*3d8817e4Smiod CGEN_CPU_OPEN_ENDIAN, prev_endian,
775*3d8817e4Smiod CGEN_CPU_OPEN_END);
776*3d8817e4Smiod if (!cd)
777*3d8817e4Smiod abort ();
778*3d8817e4Smiod
779*3d8817e4Smiod /* Save this away for future reference. */
780*3d8817e4Smiod cl = xmalloc (sizeof (struct cpu_desc_list));
781*3d8817e4Smiod cl->cd = cd;
782*3d8817e4Smiod cl->isa = prev_isa;
783*3d8817e4Smiod cl->mach = mach;
784*3d8817e4Smiod cl->endian = endian;
785*3d8817e4Smiod cl->next = cd_list;
786*3d8817e4Smiod cd_list = cl;
787*3d8817e4Smiod
788*3d8817e4Smiod xc16x_cgen_init_dis (cd);
789*3d8817e4Smiod }
790*3d8817e4Smiod
791*3d8817e4Smiod /* We try to have as much common code as possible.
792*3d8817e4Smiod But at this point some targets need to take over. */
793*3d8817e4Smiod /* ??? Some targets may need a hook elsewhere. Try to avoid this,
794*3d8817e4Smiod but if not possible try to move this hook elsewhere rather than
795*3d8817e4Smiod have two hooks. */
796*3d8817e4Smiod length = CGEN_PRINT_INSN (cd, pc, info);
797*3d8817e4Smiod if (length > 0)
798*3d8817e4Smiod return length;
799*3d8817e4Smiod if (length < 0)
800*3d8817e4Smiod return -1;
801*3d8817e4Smiod
802*3d8817e4Smiod (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
803*3d8817e4Smiod return cd->default_insn_bitsize / 8;
804*3d8817e4Smiod }
805