xref: /openbsd-src/gnu/usr.bin/binutils/opcodes/tic4x-dis.c (revision d2201f2f89f0be1a0be6f7568000ed297414a06d)
1*d2201f2fSdrahn /* Print instructions for the Texas TMS320C[34]X, for GDB and GNU Binutils.
2*d2201f2fSdrahn 
3*d2201f2fSdrahn    Copyright 2002, 2003 Free Software Foundation, Inc.
4*d2201f2fSdrahn 
5*d2201f2fSdrahn    Contributed by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz)
6*d2201f2fSdrahn 
7*d2201f2fSdrahn    This program is free software; you can redistribute it and/or modify
8*d2201f2fSdrahn    it under the terms of the GNU General Public License as published by
9*d2201f2fSdrahn    the Free Software Foundation; either version 2 of the License, or
10*d2201f2fSdrahn    (at your option) any later version.
11*d2201f2fSdrahn 
12*d2201f2fSdrahn    This program is distributed in the hope that it will be useful,
13*d2201f2fSdrahn    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*d2201f2fSdrahn    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*d2201f2fSdrahn    GNU General Public License for more details.
16*d2201f2fSdrahn 
17*d2201f2fSdrahn    You should have received a copy of the GNU General Public License
18*d2201f2fSdrahn    along with this program; if not, write to the Free Software
19*d2201f2fSdrahn    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20*d2201f2fSdrahn 
21*d2201f2fSdrahn #include <math.h>
22*d2201f2fSdrahn #include "libiberty.h"
23*d2201f2fSdrahn #include "dis-asm.h"
24*d2201f2fSdrahn #include "opcode/tic4x.h"
25*d2201f2fSdrahn 
26*d2201f2fSdrahn #define TIC4X_DEBUG 0
27*d2201f2fSdrahn 
28*d2201f2fSdrahn #define TIC4X_HASH_SIZE   11   /* 11 (bits) and above should give unique entries.  */
29*d2201f2fSdrahn #define TIC4X_SPESOP_SIZE 8    /* Max 8. ops for special instructions */
30*d2201f2fSdrahn 
31*d2201f2fSdrahn typedef enum
32*d2201f2fSdrahn   {
33*d2201f2fSdrahn     IMMED_SINT,
34*d2201f2fSdrahn     IMMED_SUINT,
35*d2201f2fSdrahn     IMMED_SFLOAT,
36*d2201f2fSdrahn     IMMED_INT,
37*d2201f2fSdrahn     IMMED_UINT,
38*d2201f2fSdrahn     IMMED_FLOAT
39*d2201f2fSdrahn   }
40*d2201f2fSdrahn immed_t;
41*d2201f2fSdrahn 
42*d2201f2fSdrahn typedef enum
43*d2201f2fSdrahn   {
44*d2201f2fSdrahn     INDIRECT_SHORT,
45*d2201f2fSdrahn     INDIRECT_LONG,
46*d2201f2fSdrahn     INDIRECT_TIC4X
47*d2201f2fSdrahn   }
48*d2201f2fSdrahn indirect_t;
49*d2201f2fSdrahn 
50*d2201f2fSdrahn static int tic4x_version = 0;
51*d2201f2fSdrahn static int tic4x_dp = 0;
52*d2201f2fSdrahn 
53*d2201f2fSdrahn static int tic4x_pc_offset
54*d2201f2fSdrahn   PARAMS ((unsigned int));
55*d2201f2fSdrahn static int tic4x_print_char
56*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, char));
57*d2201f2fSdrahn static int tic4x_print_str
58*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, char *));
59*d2201f2fSdrahn static int tic4x_print_register
60*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, unsigned long));
61*d2201f2fSdrahn static int tic4x_print_addr
62*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, unsigned long));
63*d2201f2fSdrahn static int tic4x_print_relative
64*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, unsigned long, long, unsigned long));
65*d2201f2fSdrahn void tic4x_print_ftoa
66*d2201f2fSdrahn   PARAMS ((unsigned int, FILE *, fprintf_ftype));
67*d2201f2fSdrahn static int tic4x_print_direct
68*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, unsigned long));
69*d2201f2fSdrahn static int tic4x_print_immed
70*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, immed_t, unsigned long));
71*d2201f2fSdrahn static int tic4x_print_cond
72*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, unsigned int));
73*d2201f2fSdrahn static int tic4x_print_indirect
74*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, indirect_t, unsigned long));
75*d2201f2fSdrahn static int tic4x_print_op
76*d2201f2fSdrahn   PARAMS ((struct disassemble_info *, unsigned long, tic4x_inst_t *, unsigned long));
77*d2201f2fSdrahn static void tic4x_hash_opcode_special
78*d2201f2fSdrahn   PARAMS ((tic4x_inst_t **, const tic4x_inst_t *));
79*d2201f2fSdrahn static void tic4x_hash_opcode
80*d2201f2fSdrahn   PARAMS ((tic4x_inst_t **, tic4x_inst_t **, const tic4x_inst_t *, unsigned long));
81*d2201f2fSdrahn static int tic4x_disassemble
82*d2201f2fSdrahn   PARAMS ((unsigned long, unsigned long, struct disassemble_info *));
83*d2201f2fSdrahn int print_insn_tic4x
84*d2201f2fSdrahn   PARAMS ((bfd_vma, struct disassemble_info *));
85*d2201f2fSdrahn 
86*d2201f2fSdrahn 
87*d2201f2fSdrahn static int
tic4x_pc_offset(op)88*d2201f2fSdrahn tic4x_pc_offset (op)
89*d2201f2fSdrahn      unsigned int op;
90*d2201f2fSdrahn {
91*d2201f2fSdrahn   /* Determine the PC offset for a C[34]x instruction.
92*d2201f2fSdrahn      This could be simplified using some boolean algebra
93*d2201f2fSdrahn      but at the expense of readability.  */
94*d2201f2fSdrahn   switch (op >> 24)
95*d2201f2fSdrahn     {
96*d2201f2fSdrahn     case 0x60:	/* br */
97*d2201f2fSdrahn     case 0x62:	/* call  (C4x) */
98*d2201f2fSdrahn     case 0x64:	/* rptb  (C4x) */
99*d2201f2fSdrahn       return 1;
100*d2201f2fSdrahn     case 0x61: 	/* brd */
101*d2201f2fSdrahn     case 0x63: 	/* laj */
102*d2201f2fSdrahn     case 0x65:	/* rptbd (C4x) */
103*d2201f2fSdrahn       return 3;
104*d2201f2fSdrahn     case 0x66: 	/* swi */
105*d2201f2fSdrahn     case 0x67:
106*d2201f2fSdrahn       return 0;
107*d2201f2fSdrahn     default:
108*d2201f2fSdrahn       break;
109*d2201f2fSdrahn     }
110*d2201f2fSdrahn 
111*d2201f2fSdrahn   switch ((op & 0xffe00000) >> 20)
112*d2201f2fSdrahn     {
113*d2201f2fSdrahn     case 0x6a0:	/* bB */
114*d2201f2fSdrahn     case 0x720: /* callB */
115*d2201f2fSdrahn     case 0x740: /* trapB */
116*d2201f2fSdrahn       return 1;
117*d2201f2fSdrahn 
118*d2201f2fSdrahn     case 0x6a2: /* bBd */
119*d2201f2fSdrahn     case 0x6a6: /* bBat */
120*d2201f2fSdrahn     case 0x6aa: /* bBaf */
121*d2201f2fSdrahn     case 0x722:	/* lajB */
122*d2201f2fSdrahn     case 0x748: /* latB */
123*d2201f2fSdrahn     case 0x798: /* rptbd */
124*d2201f2fSdrahn       return 3;
125*d2201f2fSdrahn 
126*d2201f2fSdrahn     default:
127*d2201f2fSdrahn       break;
128*d2201f2fSdrahn     }
129*d2201f2fSdrahn 
130*d2201f2fSdrahn   switch ((op & 0xfe200000) >> 20)
131*d2201f2fSdrahn     {
132*d2201f2fSdrahn     case 0x6e0:	/* dbB */
133*d2201f2fSdrahn       return 1;
134*d2201f2fSdrahn 
135*d2201f2fSdrahn     case 0x6e2:	/* dbBd */
136*d2201f2fSdrahn       return 3;
137*d2201f2fSdrahn 
138*d2201f2fSdrahn     default:
139*d2201f2fSdrahn       break;
140*d2201f2fSdrahn     }
141*d2201f2fSdrahn 
142*d2201f2fSdrahn   return 0;
143*d2201f2fSdrahn }
144*d2201f2fSdrahn 
145*d2201f2fSdrahn static int
tic4x_print_char(info,ch)146*d2201f2fSdrahn tic4x_print_char (info, ch)
147*d2201f2fSdrahn      struct disassemble_info * info;
148*d2201f2fSdrahn      char ch;
149*d2201f2fSdrahn {
150*d2201f2fSdrahn   if (info != NULL)
151*d2201f2fSdrahn     (*info->fprintf_func) (info->stream, "%c", ch);
152*d2201f2fSdrahn   return 1;
153*d2201f2fSdrahn }
154*d2201f2fSdrahn 
155*d2201f2fSdrahn static int
tic4x_print_str(info,str)156*d2201f2fSdrahn tic4x_print_str (info, str)
157*d2201f2fSdrahn      struct disassemble_info *info;
158*d2201f2fSdrahn      char *str;
159*d2201f2fSdrahn {
160*d2201f2fSdrahn   if (info != NULL)
161*d2201f2fSdrahn     (*info->fprintf_func) (info->stream, "%s", str);
162*d2201f2fSdrahn   return 1;
163*d2201f2fSdrahn }
164*d2201f2fSdrahn 
165*d2201f2fSdrahn static int
tic4x_print_register(info,regno)166*d2201f2fSdrahn tic4x_print_register (info, regno)
167*d2201f2fSdrahn      struct disassemble_info *info;
168*d2201f2fSdrahn      unsigned long regno;
169*d2201f2fSdrahn {
170*d2201f2fSdrahn   static tic4x_register_t **registertable = NULL;
171*d2201f2fSdrahn   unsigned int i;
172*d2201f2fSdrahn 
173*d2201f2fSdrahn   if (registertable == NULL)
174*d2201f2fSdrahn     {
175*d2201f2fSdrahn       registertable = (tic4x_register_t **)
176*d2201f2fSdrahn 	xmalloc (sizeof (tic4x_register_t *) * REG_TABLE_SIZE);
177*d2201f2fSdrahn       for (i = 0; i < tic3x_num_registers; i++)
178*d2201f2fSdrahn 	registertable[tic3x_registers[i].regno] = (void *)&tic3x_registers[i];
179*d2201f2fSdrahn       if (IS_CPU_TIC4X (tic4x_version))
180*d2201f2fSdrahn 	{
181*d2201f2fSdrahn 	  /* Add C4x additional registers, overwriting
182*d2201f2fSdrahn 	     any C3x registers if necessary.  */
183*d2201f2fSdrahn 	  for (i = 0; i < tic4x_num_registers; i++)
184*d2201f2fSdrahn 	    registertable[tic4x_registers[i].regno] = (void *)&tic4x_registers[i];
185*d2201f2fSdrahn 	}
186*d2201f2fSdrahn     }
187*d2201f2fSdrahn   if ((int) regno > (IS_CPU_TIC4X (tic4x_version) ? TIC4X_REG_MAX : TIC3X_REG_MAX))
188*d2201f2fSdrahn     return 0;
189*d2201f2fSdrahn   if (info != NULL)
190*d2201f2fSdrahn     (*info->fprintf_func) (info->stream, "%s", registertable[regno]->name);
191*d2201f2fSdrahn   return 1;
192*d2201f2fSdrahn }
193*d2201f2fSdrahn 
194*d2201f2fSdrahn static int
tic4x_print_addr(info,addr)195*d2201f2fSdrahn tic4x_print_addr (info, addr)
196*d2201f2fSdrahn      struct disassemble_info *info;
197*d2201f2fSdrahn      unsigned long addr;
198*d2201f2fSdrahn {
199*d2201f2fSdrahn   if (info != NULL)
200*d2201f2fSdrahn     (*info->print_address_func)(addr, info);
201*d2201f2fSdrahn   return 1;
202*d2201f2fSdrahn }
203*d2201f2fSdrahn 
204*d2201f2fSdrahn static int
tic4x_print_relative(info,pc,offset,opcode)205*d2201f2fSdrahn tic4x_print_relative (info, pc, offset, opcode)
206*d2201f2fSdrahn      struct disassemble_info *info;
207*d2201f2fSdrahn      unsigned long pc;
208*d2201f2fSdrahn      long offset;
209*d2201f2fSdrahn      unsigned long opcode;
210*d2201f2fSdrahn {
211*d2201f2fSdrahn   return tic4x_print_addr (info, pc + offset + tic4x_pc_offset (opcode));
212*d2201f2fSdrahn }
213*d2201f2fSdrahn 
214*d2201f2fSdrahn static int
tic4x_print_direct(info,arg)215*d2201f2fSdrahn tic4x_print_direct (info, arg)
216*d2201f2fSdrahn      struct disassemble_info *info;
217*d2201f2fSdrahn      unsigned long arg;
218*d2201f2fSdrahn {
219*d2201f2fSdrahn   if (info != NULL)
220*d2201f2fSdrahn     {
221*d2201f2fSdrahn       (*info->fprintf_func) (info->stream, "@");
222*d2201f2fSdrahn       tic4x_print_addr (info, arg + (tic4x_dp << 16));
223*d2201f2fSdrahn     }
224*d2201f2fSdrahn   return 1;
225*d2201f2fSdrahn }
226*d2201f2fSdrahn 
227*d2201f2fSdrahn /* FIXME: make the floating point stuff not rely on host
228*d2201f2fSdrahn    floating point arithmetic.  */
229*d2201f2fSdrahn void
tic4x_print_ftoa(val,stream,pfunc)230*d2201f2fSdrahn tic4x_print_ftoa (val, stream, pfunc)
231*d2201f2fSdrahn      unsigned int val;
232*d2201f2fSdrahn      FILE *stream;
233*d2201f2fSdrahn      fprintf_ftype pfunc;
234*d2201f2fSdrahn {
235*d2201f2fSdrahn   int e;
236*d2201f2fSdrahn   int s;
237*d2201f2fSdrahn   int f;
238*d2201f2fSdrahn   double num = 0.0;
239*d2201f2fSdrahn 
240*d2201f2fSdrahn   e = EXTRS (val, 31, 24);	/* exponent */
241*d2201f2fSdrahn   if (e != -128)
242*d2201f2fSdrahn     {
243*d2201f2fSdrahn       s = EXTRU (val, 23, 23);	/* sign bit */
244*d2201f2fSdrahn       f = EXTRU (val, 22, 0);	/* mantissa */
245*d2201f2fSdrahn       if (s)
246*d2201f2fSdrahn 	f += -2 * (1 << 23);
247*d2201f2fSdrahn       else
248*d2201f2fSdrahn 	f += (1 << 23);
249*d2201f2fSdrahn       num = f / (double)(1 << 23);
250*d2201f2fSdrahn       num = ldexp (num, e);
251*d2201f2fSdrahn     }
252*d2201f2fSdrahn   (*pfunc)(stream, "%.9g", num);
253*d2201f2fSdrahn }
254*d2201f2fSdrahn 
255*d2201f2fSdrahn static int
tic4x_print_immed(info,type,arg)256*d2201f2fSdrahn tic4x_print_immed (info, type, arg)
257*d2201f2fSdrahn      struct disassemble_info *info;
258*d2201f2fSdrahn      immed_t type;
259*d2201f2fSdrahn      unsigned long arg;
260*d2201f2fSdrahn {
261*d2201f2fSdrahn   int s;
262*d2201f2fSdrahn   int f;
263*d2201f2fSdrahn   int e;
264*d2201f2fSdrahn   double num = 0.0;
265*d2201f2fSdrahn 
266*d2201f2fSdrahn   if (info == NULL)
267*d2201f2fSdrahn     return 1;
268*d2201f2fSdrahn   switch (type)
269*d2201f2fSdrahn     {
270*d2201f2fSdrahn     case IMMED_SINT:
271*d2201f2fSdrahn     case IMMED_INT:
272*d2201f2fSdrahn       (*info->fprintf_func) (info->stream, "%d", (long)arg);
273*d2201f2fSdrahn       break;
274*d2201f2fSdrahn 
275*d2201f2fSdrahn     case IMMED_SUINT:
276*d2201f2fSdrahn     case IMMED_UINT:
277*d2201f2fSdrahn       (*info->fprintf_func) (info->stream, "%u", arg);
278*d2201f2fSdrahn       break;
279*d2201f2fSdrahn 
280*d2201f2fSdrahn     case IMMED_SFLOAT:
281*d2201f2fSdrahn       e = EXTRS (arg, 15, 12);
282*d2201f2fSdrahn       if (e != -8)
283*d2201f2fSdrahn 	{
284*d2201f2fSdrahn 	  s = EXTRU (arg, 11, 11);
285*d2201f2fSdrahn 	  f = EXTRU (arg, 10, 0);
286*d2201f2fSdrahn 	  if (s)
287*d2201f2fSdrahn 	    f += -2 * (1 << 11);
288*d2201f2fSdrahn 	  else
289*d2201f2fSdrahn 	    f += (1 << 11);
290*d2201f2fSdrahn 	  num = f / (double)(1 << 11);
291*d2201f2fSdrahn 	  num = ldexp (num, e);
292*d2201f2fSdrahn 	}
293*d2201f2fSdrahn       (*info->fprintf_func) (info->stream, "%f", num);
294*d2201f2fSdrahn       break;
295*d2201f2fSdrahn     case IMMED_FLOAT:
296*d2201f2fSdrahn       e = EXTRS (arg, 31, 24);
297*d2201f2fSdrahn       if (e != -128)
298*d2201f2fSdrahn 	{
299*d2201f2fSdrahn 	  s = EXTRU (arg, 23, 23);
300*d2201f2fSdrahn 	  f = EXTRU (arg, 22, 0);
301*d2201f2fSdrahn 	  if (s)
302*d2201f2fSdrahn 	    f += -2 * (1 << 23);
303*d2201f2fSdrahn 	  else
304*d2201f2fSdrahn 	    f += (1 << 23);
305*d2201f2fSdrahn 	  num = f / (double)(1 << 23);
306*d2201f2fSdrahn 	  num = ldexp (num, e);
307*d2201f2fSdrahn 	}
308*d2201f2fSdrahn       (*info->fprintf_func) (info->stream, "%f", num);
309*d2201f2fSdrahn       break;
310*d2201f2fSdrahn     }
311*d2201f2fSdrahn   return 1;
312*d2201f2fSdrahn }
313*d2201f2fSdrahn 
314*d2201f2fSdrahn static int
tic4x_print_cond(info,cond)315*d2201f2fSdrahn tic4x_print_cond (info, cond)
316*d2201f2fSdrahn      struct disassemble_info *info;
317*d2201f2fSdrahn      unsigned int cond;
318*d2201f2fSdrahn {
319*d2201f2fSdrahn   static tic4x_cond_t **condtable = NULL;
320*d2201f2fSdrahn   unsigned int i;
321*d2201f2fSdrahn 
322*d2201f2fSdrahn   if (condtable == NULL)
323*d2201f2fSdrahn     {
324*d2201f2fSdrahn       condtable = (tic4x_cond_t **)xmalloc (sizeof (tic4x_cond_t *) * 32);
325*d2201f2fSdrahn       for (i = 0; i < tic4x_num_conds; i++)
326*d2201f2fSdrahn 	condtable[tic4x_conds[i].cond] = (void *)&tic4x_conds[i];
327*d2201f2fSdrahn     }
328*d2201f2fSdrahn   if (cond > 31 || condtable[cond] == NULL)
329*d2201f2fSdrahn     return 0;
330*d2201f2fSdrahn   if (info != NULL)
331*d2201f2fSdrahn     (*info->fprintf_func) (info->stream, "%s", condtable[cond]->name);
332*d2201f2fSdrahn   return 1;
333*d2201f2fSdrahn }
334*d2201f2fSdrahn 
335*d2201f2fSdrahn static int
tic4x_print_indirect(info,type,arg)336*d2201f2fSdrahn tic4x_print_indirect (info, type, arg)
337*d2201f2fSdrahn      struct disassemble_info *info;
338*d2201f2fSdrahn      indirect_t type;
339*d2201f2fSdrahn      unsigned long arg;
340*d2201f2fSdrahn {
341*d2201f2fSdrahn   unsigned int aregno;
342*d2201f2fSdrahn   unsigned int modn;
343*d2201f2fSdrahn   unsigned int disp;
344*d2201f2fSdrahn   char *a;
345*d2201f2fSdrahn 
346*d2201f2fSdrahn   aregno = 0;
347*d2201f2fSdrahn   modn = 0;
348*d2201f2fSdrahn   disp = 1;
349*d2201f2fSdrahn   switch(type)
350*d2201f2fSdrahn     {
351*d2201f2fSdrahn     case INDIRECT_TIC4X:		/* *+ARn(disp) */
352*d2201f2fSdrahn       disp = EXTRU (arg, 7, 3);
353*d2201f2fSdrahn       aregno = EXTRU (arg, 2, 0) + REG_AR0;
354*d2201f2fSdrahn       modn = 0;
355*d2201f2fSdrahn       break;
356*d2201f2fSdrahn     case INDIRECT_SHORT:
357*d2201f2fSdrahn       disp = 1;
358*d2201f2fSdrahn       aregno = EXTRU (arg, 2, 0) + REG_AR0;
359*d2201f2fSdrahn       modn = EXTRU (arg, 7, 3);
360*d2201f2fSdrahn       break;
361*d2201f2fSdrahn     case INDIRECT_LONG:
362*d2201f2fSdrahn       disp = EXTRU (arg, 7, 0);
363*d2201f2fSdrahn       aregno = EXTRU (arg, 10, 8) + REG_AR0;
364*d2201f2fSdrahn       modn = EXTRU (arg, 15, 11);
365*d2201f2fSdrahn       if (modn > 7 && disp != 0)
366*d2201f2fSdrahn 	return 0;
367*d2201f2fSdrahn       break;
368*d2201f2fSdrahn     default:
369*d2201f2fSdrahn         (*info->fprintf_func)(info->stream, "# internal error: Unknown indirect type %d", type);
370*d2201f2fSdrahn         return 0;
371*d2201f2fSdrahn     }
372*d2201f2fSdrahn   if (modn > TIC3X_MODN_MAX)
373*d2201f2fSdrahn     return 0;
374*d2201f2fSdrahn   a = tic4x_indirects[modn].name;
375*d2201f2fSdrahn   while (*a)
376*d2201f2fSdrahn     {
377*d2201f2fSdrahn       switch (*a)
378*d2201f2fSdrahn 	{
379*d2201f2fSdrahn 	case 'a':
380*d2201f2fSdrahn 	  tic4x_print_register (info, aregno);
381*d2201f2fSdrahn 	  break;
382*d2201f2fSdrahn 	case 'd':
383*d2201f2fSdrahn 	  tic4x_print_immed (info, IMMED_UINT, disp);
384*d2201f2fSdrahn 	  break;
385*d2201f2fSdrahn 	case 'y':
386*d2201f2fSdrahn 	  tic4x_print_str (info, "ir0");
387*d2201f2fSdrahn 	  break;
388*d2201f2fSdrahn 	case 'z':
389*d2201f2fSdrahn 	  tic4x_print_str (info, "ir1");
390*d2201f2fSdrahn 	  break;
391*d2201f2fSdrahn 	default:
392*d2201f2fSdrahn 	  tic4x_print_char (info, *a);
393*d2201f2fSdrahn 	  break;
394*d2201f2fSdrahn 	}
395*d2201f2fSdrahn       a++;
396*d2201f2fSdrahn     }
397*d2201f2fSdrahn   return 1;
398*d2201f2fSdrahn }
399*d2201f2fSdrahn 
400*d2201f2fSdrahn static int
tic4x_print_op(info,instruction,p,pc)401*d2201f2fSdrahn tic4x_print_op (info, instruction, p, pc)
402*d2201f2fSdrahn      struct disassemble_info *info;
403*d2201f2fSdrahn      unsigned long instruction;
404*d2201f2fSdrahn      tic4x_inst_t *p;
405*d2201f2fSdrahn      unsigned long pc;
406*d2201f2fSdrahn {
407*d2201f2fSdrahn   int val;
408*d2201f2fSdrahn   char *s;
409*d2201f2fSdrahn   char *parallel = NULL;
410*d2201f2fSdrahn 
411*d2201f2fSdrahn   /* Print instruction name.  */
412*d2201f2fSdrahn   s = p->name;
413*d2201f2fSdrahn   while (*s && parallel == NULL)
414*d2201f2fSdrahn     {
415*d2201f2fSdrahn       switch (*s)
416*d2201f2fSdrahn 	{
417*d2201f2fSdrahn 	case 'B':
418*d2201f2fSdrahn 	  if (! tic4x_print_cond (info, EXTRU (instruction, 20, 16)))
419*d2201f2fSdrahn 	    return 0;
420*d2201f2fSdrahn 	  break;
421*d2201f2fSdrahn 	case 'C':
422*d2201f2fSdrahn 	  if (! tic4x_print_cond (info, EXTRU (instruction, 27, 23)))
423*d2201f2fSdrahn 	    return 0;
424*d2201f2fSdrahn 	  break;
425*d2201f2fSdrahn 	case '_':
426*d2201f2fSdrahn 	  parallel = s + 1;	/* Skip past `_' in name */
427*d2201f2fSdrahn 	  break;
428*d2201f2fSdrahn 	default:
429*d2201f2fSdrahn 	  tic4x_print_char (info, *s);
430*d2201f2fSdrahn 	  break;
431*d2201f2fSdrahn 	}
432*d2201f2fSdrahn       s++;
433*d2201f2fSdrahn     }
434*d2201f2fSdrahn 
435*d2201f2fSdrahn   /* Print arguments.  */
436*d2201f2fSdrahn   s = p->args;
437*d2201f2fSdrahn   if (*s)
438*d2201f2fSdrahn     tic4x_print_char (info, ' ');
439*d2201f2fSdrahn 
440*d2201f2fSdrahn   while (*s)
441*d2201f2fSdrahn     {
442*d2201f2fSdrahn       switch (*s)
443*d2201f2fSdrahn 	{
444*d2201f2fSdrahn 	case '*': /* indirect 0--15 */
445*d2201f2fSdrahn 	  if (! tic4x_print_indirect (info, INDIRECT_LONG,
446*d2201f2fSdrahn 				    EXTRU (instruction, 15, 0)))
447*d2201f2fSdrahn 	    return 0;
448*d2201f2fSdrahn 	  break;
449*d2201f2fSdrahn 
450*d2201f2fSdrahn 	case '#': /* only used for ldp, ldpk */
451*d2201f2fSdrahn 	  tic4x_print_immed (info, IMMED_UINT, EXTRU (instruction, 15, 0));
452*d2201f2fSdrahn 	  break;
453*d2201f2fSdrahn 
454*d2201f2fSdrahn 	case '@': /* direct 0--15 */
455*d2201f2fSdrahn 	  tic4x_print_direct (info, EXTRU (instruction, 15, 0));
456*d2201f2fSdrahn 	  break;
457*d2201f2fSdrahn 
458*d2201f2fSdrahn 	case 'A': /* address register 24--22 */
459*d2201f2fSdrahn 	  if (! tic4x_print_register (info, EXTRU (instruction, 24, 22) +
460*d2201f2fSdrahn 				    REG_AR0))
461*d2201f2fSdrahn 	    return 0;
462*d2201f2fSdrahn 	  break;
463*d2201f2fSdrahn 
464*d2201f2fSdrahn 	case 'B': /* 24-bit unsigned int immediate br(d)/call/rptb
465*d2201f2fSdrahn 		     address 0--23.  */
466*d2201f2fSdrahn 	  if (IS_CPU_TIC4X (tic4x_version))
467*d2201f2fSdrahn 	    tic4x_print_relative (info, pc, EXTRS (instruction, 23, 0),
468*d2201f2fSdrahn 				p->opcode);
469*d2201f2fSdrahn 	  else
470*d2201f2fSdrahn 	    tic4x_print_addr (info, EXTRU (instruction, 23, 0));
471*d2201f2fSdrahn 	  break;
472*d2201f2fSdrahn 
473*d2201f2fSdrahn 	case 'C': /* indirect (short C4x) 0--7 */
474*d2201f2fSdrahn 	  if (! IS_CPU_TIC4X (tic4x_version))
475*d2201f2fSdrahn 	    return 0;
476*d2201f2fSdrahn 	  if (! tic4x_print_indirect (info, INDIRECT_TIC4X,
477*d2201f2fSdrahn 				    EXTRU (instruction, 7, 0)))
478*d2201f2fSdrahn 	    return 0;
479*d2201f2fSdrahn 	  break;
480*d2201f2fSdrahn 
481*d2201f2fSdrahn 	case 'D':
482*d2201f2fSdrahn 	  /* Cockup if get here...  */
483*d2201f2fSdrahn 	  break;
484*d2201f2fSdrahn 
485*d2201f2fSdrahn 	case 'E': /* register 0--7 */
486*d2201f2fSdrahn         case 'e':
487*d2201f2fSdrahn 	  if (! tic4x_print_register (info, EXTRU (instruction, 7, 0)))
488*d2201f2fSdrahn 	    return 0;
489*d2201f2fSdrahn 	  break;
490*d2201f2fSdrahn 
491*d2201f2fSdrahn 	case 'F': /* 16-bit float immediate 0--15 */
492*d2201f2fSdrahn 	  tic4x_print_immed (info, IMMED_SFLOAT,
493*d2201f2fSdrahn 			   EXTRU (instruction, 15, 0));
494*d2201f2fSdrahn 	  break;
495*d2201f2fSdrahn 
496*d2201f2fSdrahn         case 'i': /* Extended indirect 0--7 */
497*d2201f2fSdrahn           if ( EXTRU (instruction, 7, 5) == 7 )
498*d2201f2fSdrahn             {
499*d2201f2fSdrahn               if( !tic4x_print_register (info, EXTRU (instruction, 4, 0)) )
500*d2201f2fSdrahn                 return 0;
501*d2201f2fSdrahn               break;
502*d2201f2fSdrahn             }
503*d2201f2fSdrahn           /* Fallthrough */
504*d2201f2fSdrahn 
505*d2201f2fSdrahn 	case 'I': /* indirect (short) 0--7 */
506*d2201f2fSdrahn 	  if (! tic4x_print_indirect (info, INDIRECT_SHORT,
507*d2201f2fSdrahn 				    EXTRU (instruction, 7, 0)))
508*d2201f2fSdrahn 	    return 0;
509*d2201f2fSdrahn 	  break;
510*d2201f2fSdrahn 
511*d2201f2fSdrahn         case 'j': /* Extended indirect 8--15 */
512*d2201f2fSdrahn           if ( EXTRU (instruction, 15, 13) == 7 )
513*d2201f2fSdrahn             {
514*d2201f2fSdrahn               if( !tic4x_print_register (info, EXTRU (instruction, 12, 8)) )
515*d2201f2fSdrahn                 return 0;
516*d2201f2fSdrahn               break;
517*d2201f2fSdrahn             }
518*d2201f2fSdrahn 
519*d2201f2fSdrahn 	case 'J': /* indirect (short) 8--15 */
520*d2201f2fSdrahn 	  if (! tic4x_print_indirect (info, INDIRECT_SHORT,
521*d2201f2fSdrahn 				    EXTRU (instruction, 15, 8)))
522*d2201f2fSdrahn 	    return 0;
523*d2201f2fSdrahn 	  break;
524*d2201f2fSdrahn 
525*d2201f2fSdrahn 	case 'G': /* register 8--15 */
526*d2201f2fSdrahn         case 'g':
527*d2201f2fSdrahn 	  if (! tic4x_print_register (info, EXTRU (instruction, 15, 8)))
528*d2201f2fSdrahn 	    return 0;
529*d2201f2fSdrahn 	  break;
530*d2201f2fSdrahn 
531*d2201f2fSdrahn 	case 'H': /* register 16--18 */
532*d2201f2fSdrahn 	  if (! tic4x_print_register (info, EXTRU (instruction, 18, 16)))
533*d2201f2fSdrahn 	    return 0;
534*d2201f2fSdrahn 	  break;
535*d2201f2fSdrahn 
536*d2201f2fSdrahn 	case 'K': /* register 19--21 */
537*d2201f2fSdrahn 	  if (! tic4x_print_register (info, EXTRU (instruction, 21, 19)))
538*d2201f2fSdrahn 	    return 0;
539*d2201f2fSdrahn 	  break;
540*d2201f2fSdrahn 
541*d2201f2fSdrahn 	case 'L': /* register 22--24 */
542*d2201f2fSdrahn 	  if (! tic4x_print_register (info, EXTRU (instruction, 24, 22)))
543*d2201f2fSdrahn 	    return 0;
544*d2201f2fSdrahn 	  break;
545*d2201f2fSdrahn 
546*d2201f2fSdrahn 	case 'M': /* register 22--22 */
547*d2201f2fSdrahn 	  tic4x_print_register (info, EXTRU (instruction, 22, 22) + REG_R2);
548*d2201f2fSdrahn 	  break;
549*d2201f2fSdrahn 
550*d2201f2fSdrahn 	case 'N': /* register 23--23 */
551*d2201f2fSdrahn 	  tic4x_print_register (info, EXTRU (instruction, 23, 23) + REG_R0);
552*d2201f2fSdrahn 	  break;
553*d2201f2fSdrahn 
554*d2201f2fSdrahn 	case 'O': /* indirect (short C4x) 8--15 */
555*d2201f2fSdrahn 	  if (! IS_CPU_TIC4X (tic4x_version))
556*d2201f2fSdrahn 	    return 0;
557*d2201f2fSdrahn 	  if (! tic4x_print_indirect (info, INDIRECT_TIC4X,
558*d2201f2fSdrahn 				    EXTRU (instruction, 15, 8)))
559*d2201f2fSdrahn 	    return 0;
560*d2201f2fSdrahn 	  break;
561*d2201f2fSdrahn 
562*d2201f2fSdrahn 	case 'P': /* displacement 0--15 (used by Bcond and BcondD) */
563*d2201f2fSdrahn 	  tic4x_print_relative (info, pc, EXTRS (instruction, 15, 0),
564*d2201f2fSdrahn 			      p->opcode);
565*d2201f2fSdrahn 	  break;
566*d2201f2fSdrahn 
567*d2201f2fSdrahn 	case 'Q': /* register 0--15 */
568*d2201f2fSdrahn         case 'q':
569*d2201f2fSdrahn 	  if (! tic4x_print_register (info, EXTRU (instruction, 15, 0)))
570*d2201f2fSdrahn 	    return 0;
571*d2201f2fSdrahn 	  break;
572*d2201f2fSdrahn 
573*d2201f2fSdrahn 	case 'R': /* register 16--20 */
574*d2201f2fSdrahn         case 'r':
575*d2201f2fSdrahn 	  if (! tic4x_print_register (info, EXTRU (instruction, 20, 16)))
576*d2201f2fSdrahn 	    return 0;
577*d2201f2fSdrahn 	  break;
578*d2201f2fSdrahn 
579*d2201f2fSdrahn 	case 'S': /* 16-bit signed immediate 0--15 */
580*d2201f2fSdrahn 	  tic4x_print_immed (info, IMMED_SINT,
581*d2201f2fSdrahn 			   EXTRS (instruction, 15, 0));
582*d2201f2fSdrahn 	  break;
583*d2201f2fSdrahn 
584*d2201f2fSdrahn 	case 'T': /* 5-bit signed immediate 16--20  (C4x stik) */
585*d2201f2fSdrahn 	  if (! IS_CPU_TIC4X (tic4x_version))
586*d2201f2fSdrahn 	    return 0;
587*d2201f2fSdrahn 	  if (! tic4x_print_immed (info, IMMED_SUINT,
588*d2201f2fSdrahn 				 EXTRU (instruction, 20, 16)))
589*d2201f2fSdrahn 	    return 0;
590*d2201f2fSdrahn 	  break;
591*d2201f2fSdrahn 
592*d2201f2fSdrahn 	case 'U': /* 16-bit unsigned int immediate 0--15 */
593*d2201f2fSdrahn 	  tic4x_print_immed (info, IMMED_SUINT, EXTRU (instruction, 15, 0));
594*d2201f2fSdrahn 	  break;
595*d2201f2fSdrahn 
596*d2201f2fSdrahn 	case 'V': /* 5/9-bit unsigned vector 0--4/8 */
597*d2201f2fSdrahn 	  tic4x_print_immed (info, IMMED_SUINT,
598*d2201f2fSdrahn 			   IS_CPU_TIC4X (tic4x_version) ?
599*d2201f2fSdrahn 			   EXTRU (instruction, 8, 0) :
600*d2201f2fSdrahn 			   EXTRU (instruction, 4, 0) & ~0x20);
601*d2201f2fSdrahn 	  break;
602*d2201f2fSdrahn 
603*d2201f2fSdrahn 	case 'W': /* 8-bit signed immediate 0--7 */
604*d2201f2fSdrahn 	  if (! IS_CPU_TIC4X (tic4x_version))
605*d2201f2fSdrahn 	    return 0;
606*d2201f2fSdrahn 	  tic4x_print_immed (info, IMMED_SINT, EXTRS (instruction, 7, 0));
607*d2201f2fSdrahn 	  break;
608*d2201f2fSdrahn 
609*d2201f2fSdrahn 	case 'X': /* expansion register 4--0 */
610*d2201f2fSdrahn 	  val = EXTRU (instruction, 4, 0) + REG_IVTP;
611*d2201f2fSdrahn 	  if (val < REG_IVTP || val > REG_TVTP)
612*d2201f2fSdrahn 	    return 0;
613*d2201f2fSdrahn 	  if (! tic4x_print_register (info, val))
614*d2201f2fSdrahn 	    return 0;
615*d2201f2fSdrahn 	  break;
616*d2201f2fSdrahn 
617*d2201f2fSdrahn 	case 'Y': /* address register 16--20 */
618*d2201f2fSdrahn 	  val = EXTRU (instruction, 20, 16);
619*d2201f2fSdrahn 	  if (val < REG_AR0 || val > REG_SP)
620*d2201f2fSdrahn 	    return 0;
621*d2201f2fSdrahn 	  if (! tic4x_print_register (info, val))
622*d2201f2fSdrahn 	    return 0;
623*d2201f2fSdrahn 	  break;
624*d2201f2fSdrahn 
625*d2201f2fSdrahn 	case 'Z': /* expansion register 16--20 */
626*d2201f2fSdrahn 	  val = EXTRU (instruction, 20, 16) + REG_IVTP;
627*d2201f2fSdrahn 	  if (val < REG_IVTP || val > REG_TVTP)
628*d2201f2fSdrahn 	    return 0;
629*d2201f2fSdrahn 	  if (! tic4x_print_register (info, val))
630*d2201f2fSdrahn 	    return 0;
631*d2201f2fSdrahn 	  break;
632*d2201f2fSdrahn 
633*d2201f2fSdrahn 	case '|':		/* Parallel instruction */
634*d2201f2fSdrahn 	  tic4x_print_str (info, " || ");
635*d2201f2fSdrahn 	  tic4x_print_str (info, parallel);
636*d2201f2fSdrahn 	  tic4x_print_char (info, ' ');
637*d2201f2fSdrahn 	  break;
638*d2201f2fSdrahn 
639*d2201f2fSdrahn 	case ';':
640*d2201f2fSdrahn 	  tic4x_print_char (info, ',');
641*d2201f2fSdrahn 	  break;
642*d2201f2fSdrahn 
643*d2201f2fSdrahn 	default:
644*d2201f2fSdrahn 	  tic4x_print_char (info, *s);
645*d2201f2fSdrahn 	  break;
646*d2201f2fSdrahn 	}
647*d2201f2fSdrahn       s++;
648*d2201f2fSdrahn     }
649*d2201f2fSdrahn   return 1;
650*d2201f2fSdrahn }
651*d2201f2fSdrahn 
652*d2201f2fSdrahn static void
tic4x_hash_opcode_special(optable_special,inst)653*d2201f2fSdrahn tic4x_hash_opcode_special (optable_special, inst)
654*d2201f2fSdrahn      tic4x_inst_t **optable_special;
655*d2201f2fSdrahn      const tic4x_inst_t *inst;
656*d2201f2fSdrahn {
657*d2201f2fSdrahn   int i;
658*d2201f2fSdrahn 
659*d2201f2fSdrahn   for( i=0; i<TIC4X_SPESOP_SIZE; i++ )
660*d2201f2fSdrahn     if( optable_special[i] != NULL
661*d2201f2fSdrahn         && optable_special[i]->opcode == inst->opcode )
662*d2201f2fSdrahn       {
663*d2201f2fSdrahn         /* Collision (we have it already) - overwrite */
664*d2201f2fSdrahn         optable_special[i] = (void *)inst;
665*d2201f2fSdrahn         return;
666*d2201f2fSdrahn       }
667*d2201f2fSdrahn 
668*d2201f2fSdrahn   for( i=0; i<TIC4X_SPESOP_SIZE; i++ )
669*d2201f2fSdrahn     if( optable_special[i] == NULL )
670*d2201f2fSdrahn       {
671*d2201f2fSdrahn         /* Add the new opcode */
672*d2201f2fSdrahn         optable_special[i] = (void *)inst;
673*d2201f2fSdrahn         return;
674*d2201f2fSdrahn       }
675*d2201f2fSdrahn 
676*d2201f2fSdrahn   /* This should never occur. This happens if the number of special
677*d2201f2fSdrahn      instructions exceeds TIC4X_SPESOP_SIZE. Please increase the variable
678*d2201f2fSdrahn      of this variable */
679*d2201f2fSdrahn #if TIC4X_DEBUG
680*d2201f2fSdrahn   printf("optable_special[] is full, please increase TIC4X_SPESOP_SIZE!\n");
681*d2201f2fSdrahn #endif
682*d2201f2fSdrahn }
683*d2201f2fSdrahn 
684*d2201f2fSdrahn static void
tic4x_hash_opcode(optable,optable_special,inst,tic4x_oplevel)685*d2201f2fSdrahn tic4x_hash_opcode (optable, optable_special, inst, tic4x_oplevel)
686*d2201f2fSdrahn      tic4x_inst_t **optable;
687*d2201f2fSdrahn      tic4x_inst_t **optable_special;
688*d2201f2fSdrahn      const tic4x_inst_t *inst;
689*d2201f2fSdrahn      const unsigned long tic4x_oplevel;
690*d2201f2fSdrahn {
691*d2201f2fSdrahn   int j;
692*d2201f2fSdrahn   int opcode = inst->opcode >> (32 - TIC4X_HASH_SIZE);
693*d2201f2fSdrahn   int opmask = inst->opmask >> (32 - TIC4X_HASH_SIZE);
694*d2201f2fSdrahn 
695*d2201f2fSdrahn   /* Use a TIC4X_HASH_SIZE bit index as a hash index.  We should
696*d2201f2fSdrahn      have unique entries so there's no point having a linked list
697*d2201f2fSdrahn      for each entry? */
698*d2201f2fSdrahn   for (j = opcode; j < opmask; j++)
699*d2201f2fSdrahn     if ( (j & opmask) == opcode
700*d2201f2fSdrahn          && inst->oplevel & tic4x_oplevel )
701*d2201f2fSdrahn       {
702*d2201f2fSdrahn #if TIC4X_DEBUG
703*d2201f2fSdrahn 	/* We should only have collisions for synonyms like
704*d2201f2fSdrahn 	   ldp for ldi.  */
705*d2201f2fSdrahn 	if (optable[j] != NULL)
706*d2201f2fSdrahn 	  printf("Collision at index %d, %s and %s\n",
707*d2201f2fSdrahn 		 j, optable[j]->name, inst->name);
708*d2201f2fSdrahn #endif
709*d2201f2fSdrahn         /* Catch those ops that collide with others already inside the
710*d2201f2fSdrahn            hash, and have a opmask greater than the one we use in the
711*d2201f2fSdrahn            hash. Store them in a special-list, that will handle full
712*d2201f2fSdrahn            32-bit INSN, not only the first 11-bit (or so). */
713*d2201f2fSdrahn         if ( optable[j] != NULL
714*d2201f2fSdrahn              && inst->opmask & ~(opmask << (32 - TIC4X_HASH_SIZE)) )
715*d2201f2fSdrahn           {
716*d2201f2fSdrahn             /* Add the instruction already on the list */
717*d2201f2fSdrahn             tic4x_hash_opcode_special(optable_special, optable[j]);
718*d2201f2fSdrahn 
719*d2201f2fSdrahn             /* Add the new instruction */
720*d2201f2fSdrahn             tic4x_hash_opcode_special(optable_special, inst);
721*d2201f2fSdrahn           }
722*d2201f2fSdrahn 
723*d2201f2fSdrahn         optable[j] = (void *)inst;
724*d2201f2fSdrahn       }
725*d2201f2fSdrahn }
726*d2201f2fSdrahn 
727*d2201f2fSdrahn /* Disassemble the instruction in 'instruction'.
728*d2201f2fSdrahn    'pc' should be the address of this instruction, it will
729*d2201f2fSdrahn    be used to print the target address if this is a relative jump or call
730*d2201f2fSdrahn    the disassembled instruction is written to 'info'.
731*d2201f2fSdrahn    The function returns the length of this instruction in words.  */
732*d2201f2fSdrahn 
733*d2201f2fSdrahn static int
tic4x_disassemble(pc,instruction,info)734*d2201f2fSdrahn tic4x_disassemble (pc, instruction, info)
735*d2201f2fSdrahn      unsigned long pc;
736*d2201f2fSdrahn      unsigned long instruction;
737*d2201f2fSdrahn      struct disassemble_info *info;
738*d2201f2fSdrahn {
739*d2201f2fSdrahn   static tic4x_inst_t **optable = NULL;
740*d2201f2fSdrahn   static tic4x_inst_t **optable_special = NULL;
741*d2201f2fSdrahn   tic4x_inst_t *p;
742*d2201f2fSdrahn   int i;
743*d2201f2fSdrahn   unsigned long tic4x_oplevel;
744*d2201f2fSdrahn 
745*d2201f2fSdrahn   tic4x_version = info->mach;
746*d2201f2fSdrahn 
747*d2201f2fSdrahn   tic4x_oplevel  = (IS_CPU_TIC4X (tic4x_version)) ? OP_C4X : 0;
748*d2201f2fSdrahn   tic4x_oplevel |= OP_C3X|OP_LPWR|OP_IDLE2|OP_ENH;
749*d2201f2fSdrahn 
750*d2201f2fSdrahn   if (optable == NULL)
751*d2201f2fSdrahn     {
752*d2201f2fSdrahn       optable = (tic4x_inst_t **)
753*d2201f2fSdrahn 	xcalloc (sizeof (tic4x_inst_t *), (1 << TIC4X_HASH_SIZE));
754*d2201f2fSdrahn 
755*d2201f2fSdrahn       optable_special = (tic4x_inst_t **)
756*d2201f2fSdrahn         xcalloc (sizeof (tic4x_inst_t *), TIC4X_SPESOP_SIZE );
757*d2201f2fSdrahn 
758*d2201f2fSdrahn       /* Install opcodes in reverse order so that preferred
759*d2201f2fSdrahn 	 forms overwrite synonyms.  */
760*d2201f2fSdrahn       for (i = tic4x_num_insts - 1; i >= 0; i--)
761*d2201f2fSdrahn         tic4x_hash_opcode (optable, optable_special, &tic4x_insts[i], tic4x_oplevel);
762*d2201f2fSdrahn 
763*d2201f2fSdrahn       /* We now need to remove the insn that are special from the
764*d2201f2fSdrahn          "normal" optable, to make the disasm search this extra list
765*d2201f2fSdrahn          for them.
766*d2201f2fSdrahn       */
767*d2201f2fSdrahn       for (i=0; i<TIC4X_SPESOP_SIZE; i++)
768*d2201f2fSdrahn         if ( optable_special[i] != NULL )
769*d2201f2fSdrahn           optable[optable_special[i]->opcode >> (32 - TIC4X_HASH_SIZE)] = NULL;
770*d2201f2fSdrahn     }
771*d2201f2fSdrahn 
772*d2201f2fSdrahn   /* See if we can pick up any loading of the DP register...  */
773*d2201f2fSdrahn   if ((instruction >> 16) == 0x5070 || (instruction >> 16) == 0x1f70)
774*d2201f2fSdrahn     tic4x_dp = EXTRU (instruction, 15, 0);
775*d2201f2fSdrahn 
776*d2201f2fSdrahn   p = optable[instruction >> (32 - TIC4X_HASH_SIZE)];
777*d2201f2fSdrahn   if ( p != NULL )
778*d2201f2fSdrahn     {
779*d2201f2fSdrahn       if ( ((instruction & p->opmask) == p->opcode)
780*d2201f2fSdrahn            && tic4x_print_op (NULL, instruction, p, pc) )
781*d2201f2fSdrahn         tic4x_print_op (info, instruction, p, pc);
782*d2201f2fSdrahn       else
783*d2201f2fSdrahn         (*info->fprintf_func) (info->stream, "%08x", instruction);
784*d2201f2fSdrahn     }
785*d2201f2fSdrahn   else
786*d2201f2fSdrahn     {
787*d2201f2fSdrahn       for (i = 0; i<TIC4X_SPESOP_SIZE; i++)
788*d2201f2fSdrahn         if (optable_special[i] != NULL
789*d2201f2fSdrahn             && optable_special[i]->opcode == instruction )
790*d2201f2fSdrahn           {
791*d2201f2fSdrahn             (*info->fprintf_func)(info->stream, "%s", optable_special[i]->name);
792*d2201f2fSdrahn             break;
793*d2201f2fSdrahn           }
794*d2201f2fSdrahn       if (i==TIC4X_SPESOP_SIZE)
795*d2201f2fSdrahn         (*info->fprintf_func) (info->stream, "%08x", instruction);
796*d2201f2fSdrahn     }
797*d2201f2fSdrahn 
798*d2201f2fSdrahn   /* Return size of insn in words.  */
799*d2201f2fSdrahn   return 1;
800*d2201f2fSdrahn }
801*d2201f2fSdrahn 
802*d2201f2fSdrahn /* The entry point from objdump and gdb.  */
803*d2201f2fSdrahn int
print_insn_tic4x(memaddr,info)804*d2201f2fSdrahn print_insn_tic4x (memaddr, info)
805*d2201f2fSdrahn      bfd_vma memaddr;
806*d2201f2fSdrahn      struct disassemble_info *info;
807*d2201f2fSdrahn {
808*d2201f2fSdrahn   int status;
809*d2201f2fSdrahn   unsigned long pc;
810*d2201f2fSdrahn   unsigned long op;
811*d2201f2fSdrahn   bfd_byte buffer[4];
812*d2201f2fSdrahn 
813*d2201f2fSdrahn   status = (*info->read_memory_func) (memaddr, buffer, 4, info);
814*d2201f2fSdrahn   if (status != 0)
815*d2201f2fSdrahn     {
816*d2201f2fSdrahn       (*info->memory_error_func) (status, memaddr, info);
817*d2201f2fSdrahn       return -1;
818*d2201f2fSdrahn     }
819*d2201f2fSdrahn 
820*d2201f2fSdrahn   pc = memaddr;
821*d2201f2fSdrahn   op = bfd_getl32 (buffer);
822*d2201f2fSdrahn   info->bytes_per_line = 4;
823*d2201f2fSdrahn   info->bytes_per_chunk = 4;
824*d2201f2fSdrahn   info->octets_per_byte = 4;
825*d2201f2fSdrahn   info->display_endian = BFD_ENDIAN_LITTLE;
826*d2201f2fSdrahn   return tic4x_disassemble (pc, op, info) * 4;
827*d2201f2fSdrahn }
828