xref: /openbsd-src/gnu/usr.bin/binutils/opcodes/dlx-dis.c (revision d2201f2f89f0be1a0be6f7568000ed297414a06d)
1*d2201f2fSdrahn /* Instruction printing code for the DLX Microprocessor
2*d2201f2fSdrahn    Copyright 2002 Free Software Foundation, Inc.
3*d2201f2fSdrahn    Contributed by Kuang Hwa Lin.  Written by Kuang Hwa Lin, 03/2002.
4*d2201f2fSdrahn 
5*d2201f2fSdrahn    This program is free software; you can redistribute it and/or modify
6*d2201f2fSdrahn    it under the terms of the GNU General Public License as published by
7*d2201f2fSdrahn    the Free Software Foundation; either version 2 of the License, or
8*d2201f2fSdrahn    (at your option) any later version.
9*d2201f2fSdrahn 
10*d2201f2fSdrahn    This program is distributed in the hope that it will be useful,
11*d2201f2fSdrahn    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*d2201f2fSdrahn    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*d2201f2fSdrahn    GNU General Public License for more details.
14*d2201f2fSdrahn 
15*d2201f2fSdrahn    You should have received a copy of the GNU General Public License
16*d2201f2fSdrahn    along with this program; if not, write to the Free Software
17*d2201f2fSdrahn    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18*d2201f2fSdrahn 
19*d2201f2fSdrahn #include "sysdep.h"
20*d2201f2fSdrahn #include "dis-asm.h"
21*d2201f2fSdrahn #include "opcode/dlx.h"
22*d2201f2fSdrahn 
23*d2201f2fSdrahn #define R_ERROR     0x1
24*d2201f2fSdrahn #define R_TYPE      0x2
25*d2201f2fSdrahn #define ILD_TYPE    0x3
26*d2201f2fSdrahn #define IST_TYPE    0x4
27*d2201f2fSdrahn #define IAL_TYPE    0x5
28*d2201f2fSdrahn #define IBR_TYPE    0x6
29*d2201f2fSdrahn #define IJ_TYPE     0x7
30*d2201f2fSdrahn #define IJR_TYPE    0x8
31*d2201f2fSdrahn #define NIL         0x9
32*d2201f2fSdrahn 
33*d2201f2fSdrahn #define OPC(x)      ((x >> 26) & 0x3F)
34*d2201f2fSdrahn #define FUNC(x)     (x & 0x7FF)
35*d2201f2fSdrahn 
36*d2201f2fSdrahn unsigned char opc, rs1, rs2, rd;
37*d2201f2fSdrahn unsigned long imm26, imm16, func, current_insn_addr;
38*d2201f2fSdrahn 
39*d2201f2fSdrahn static unsigned char dlx_get_opcode PARAMS ((unsigned long));
40*d2201f2fSdrahn static unsigned char dlx_get_rs1    PARAMS ((unsigned long));
41*d2201f2fSdrahn static unsigned char dlx_get_rs2    PARAMS ((unsigned long));
42*d2201f2fSdrahn static unsigned char dlx_get_rdR    PARAMS ((unsigned long));
43*d2201f2fSdrahn static unsigned long dlx_get_func   PARAMS ((unsigned long));
44*d2201f2fSdrahn static unsigned long dlx_get_imm16  PARAMS ((unsigned long));
45*d2201f2fSdrahn static unsigned long dlx_get_imm26  PARAMS ((unsigned long));
46*d2201f2fSdrahn static void     operand_deliminator PARAMS ((struct disassemble_info *, char *));
47*d2201f2fSdrahn static unsigned char dlx_r_type     PARAMS ((struct disassemble_info *));
48*d2201f2fSdrahn static unsigned char dlx_load_type  PARAMS ((struct disassemble_info *));
49*d2201f2fSdrahn static unsigned char dlx_store_type PARAMS ((struct disassemble_info *));
50*d2201f2fSdrahn static unsigned char dlx_aluI_type  PARAMS ((struct disassemble_info *));
51*d2201f2fSdrahn static unsigned char dlx_br_type    PARAMS ((struct disassemble_info *));
52*d2201f2fSdrahn static unsigned char dlx_jmp_type   PARAMS ((struct disassemble_info *));
53*d2201f2fSdrahn static unsigned char dlx_jr_type    PARAMS ((struct disassemble_info *));
54*d2201f2fSdrahn 
55*d2201f2fSdrahn /* Print one instruction from MEMADDR on INFO->STREAM.
56*d2201f2fSdrahn    Return the size of the instruction (always 4 on dlx).  */
57*d2201f2fSdrahn 
58*d2201f2fSdrahn static unsigned char
dlx_get_opcode(opcode)59*d2201f2fSdrahn dlx_get_opcode (opcode)
60*d2201f2fSdrahn      unsigned long opcode;
61*d2201f2fSdrahn {
62*d2201f2fSdrahn   return (unsigned char) ((opcode >> 26) & 0x3F);
63*d2201f2fSdrahn }
64*d2201f2fSdrahn 
65*d2201f2fSdrahn static unsigned char
dlx_get_rs1(opcode)66*d2201f2fSdrahn dlx_get_rs1 (opcode)
67*d2201f2fSdrahn      unsigned long opcode;
68*d2201f2fSdrahn {
69*d2201f2fSdrahn   return (unsigned char) ((opcode >> 21) & 0x1F);
70*d2201f2fSdrahn }
71*d2201f2fSdrahn 
72*d2201f2fSdrahn static unsigned char
dlx_get_rs2(opcode)73*d2201f2fSdrahn dlx_get_rs2 (opcode)
74*d2201f2fSdrahn      unsigned long opcode;
75*d2201f2fSdrahn {
76*d2201f2fSdrahn   return (unsigned char) ((opcode >> 16) & 0x1F);
77*d2201f2fSdrahn }
78*d2201f2fSdrahn 
79*d2201f2fSdrahn static unsigned char
dlx_get_rdR(opcode)80*d2201f2fSdrahn dlx_get_rdR (opcode)
81*d2201f2fSdrahn      unsigned long opcode;
82*d2201f2fSdrahn {
83*d2201f2fSdrahn   return (unsigned char) ((opcode >> 11) & 0x1F);
84*d2201f2fSdrahn }
85*d2201f2fSdrahn 
86*d2201f2fSdrahn static unsigned long
dlx_get_func(opcode)87*d2201f2fSdrahn dlx_get_func (opcode)
88*d2201f2fSdrahn      unsigned long opcode;
89*d2201f2fSdrahn {
90*d2201f2fSdrahn   return (unsigned char) (opcode & 0x7FF);
91*d2201f2fSdrahn }
92*d2201f2fSdrahn 
93*d2201f2fSdrahn static unsigned long
dlx_get_imm16(opcode)94*d2201f2fSdrahn dlx_get_imm16 (opcode)
95*d2201f2fSdrahn      unsigned long opcode;
96*d2201f2fSdrahn {
97*d2201f2fSdrahn   return (unsigned long) (opcode & 0xFFFF);
98*d2201f2fSdrahn }
99*d2201f2fSdrahn 
100*d2201f2fSdrahn static unsigned long
dlx_get_imm26(opcode)101*d2201f2fSdrahn dlx_get_imm26 (opcode)
102*d2201f2fSdrahn      unsigned long opcode;
103*d2201f2fSdrahn {
104*d2201f2fSdrahn   return (unsigned long) (opcode & 0x03FFFFFF);
105*d2201f2fSdrahn }
106*d2201f2fSdrahn 
107*d2201f2fSdrahn /* Fill the opcode to the max length.  */
108*d2201f2fSdrahn static void
operand_deliminator(info,ptr)109*d2201f2fSdrahn operand_deliminator (info, ptr)
110*d2201f2fSdrahn      struct disassemble_info *info;
111*d2201f2fSdrahn      char *ptr;
112*d2201f2fSdrahn {
113*d2201f2fSdrahn   int difft = 8 - (int) strlen (ptr);
114*d2201f2fSdrahn 
115*d2201f2fSdrahn   while (difft > 0)
116*d2201f2fSdrahn     {
117*d2201f2fSdrahn       (*info->fprintf_func) (info->stream, "%c", ' ');
118*d2201f2fSdrahn       difft -= 1;
119*d2201f2fSdrahn     }
120*d2201f2fSdrahn }
121*d2201f2fSdrahn 
122*d2201f2fSdrahn /* Process the R-type opcode.  */
123*d2201f2fSdrahn static unsigned char
dlx_r_type(info)124*d2201f2fSdrahn dlx_r_type (info)
125*d2201f2fSdrahn      struct disassemble_info *info;
126*d2201f2fSdrahn {
127*d2201f2fSdrahn   unsigned char r_opc[] = { OPC(ALUOP) }; /* Fix ME */
128*d2201f2fSdrahn   int r_opc_num = (sizeof r_opc) / (sizeof (char));
129*d2201f2fSdrahn   struct _r_opcode
130*d2201f2fSdrahn   {
131*d2201f2fSdrahn     unsigned long func;
132*d2201f2fSdrahn     char *name;
133*d2201f2fSdrahn   }
134*d2201f2fSdrahn   dlx_r_opcode[] =
135*d2201f2fSdrahn     {
136*d2201f2fSdrahn     { NOPF,     "nop"    },  /* NOP                          */
137*d2201f2fSdrahn     { ADDF,     "add"    },  /* Add                          */
138*d2201f2fSdrahn     { ADDUF,    "addu"   },  /* Add Unsigned                 */
139*d2201f2fSdrahn     { SUBF,     "sub"    },  /* SUB                          */
140*d2201f2fSdrahn     { SUBUF,    "subu"   },  /* Sub Unsigned                 */
141*d2201f2fSdrahn     { MULTF,    "mult"   },  /* MULTIPLY                     */
142*d2201f2fSdrahn     { MULTUF,   "multu"  },  /* MULTIPLY Unsigned            */
143*d2201f2fSdrahn     { DIVF,     "div"    },  /* DIVIDE                       */
144*d2201f2fSdrahn     { DIVUF,    "divu"   },  /* DIVIDE Unsigned              */
145*d2201f2fSdrahn     { ANDF,     "and"    },  /* AND                          */
146*d2201f2fSdrahn     { ORF,      "or"     },  /* OR                           */
147*d2201f2fSdrahn     { XORF,     "xor"    },  /* Exclusive OR                 */
148*d2201f2fSdrahn     { SLLF,     "sll"    },  /* SHIFT LEFT LOGICAL           */
149*d2201f2fSdrahn     { SRAF,     "sra"    },  /* SHIFT RIGHT ARITHMETIC       */
150*d2201f2fSdrahn     { SRLF,     "srl"    },  /* SHIFT RIGHT LOGICAL          */
151*d2201f2fSdrahn     { SEQF,     "seq"    },  /* Set if equal                 */
152*d2201f2fSdrahn     { SNEF,     "sne"    },  /* Set if not equal             */
153*d2201f2fSdrahn     { SLTF,     "slt"    },  /* Set if less                  */
154*d2201f2fSdrahn     { SGTF,     "sgt"    },  /* Set if greater               */
155*d2201f2fSdrahn     { SLEF,     "sle"    },  /* Set if less or equal         */
156*d2201f2fSdrahn     { SGEF,     "sge"    },  /* Set if greater or equal      */
157*d2201f2fSdrahn     { SEQUF,    "sequ"   },  /* Set if equal                 */
158*d2201f2fSdrahn     { SNEUF,    "sneu"   },  /* Set if not equal             */
159*d2201f2fSdrahn     { SLTUF,    "sltu"   },  /* Set if less                  */
160*d2201f2fSdrahn     { SGTUF,    "sgtu"   },  /* Set if greater               */
161*d2201f2fSdrahn     { SLEUF,    "sleu"   },  /* Set if less or equal         */
162*d2201f2fSdrahn     { SGEUF,    "sgeu"   },  /* Set if greater or equal      */
163*d2201f2fSdrahn     { MVTSF,    "mvts"   },  /* Move to special register     */
164*d2201f2fSdrahn     { MVFSF,    "mvfs"   },  /* Move from special register   */
165*d2201f2fSdrahn     { BSWAPF,   "bswap"  },  /* Byte swap ??                 */
166*d2201f2fSdrahn     { LUTF,     "lut"    }   /* ????????? ??                 */
167*d2201f2fSdrahn   };
168*d2201f2fSdrahn   int dlx_r_opcode_num = (sizeof dlx_r_opcode) / (sizeof dlx_r_opcode[0]);
169*d2201f2fSdrahn   int idx;
170*d2201f2fSdrahn 
171*d2201f2fSdrahn   for (idx = 0; idx < r_opc_num; idx++)
172*d2201f2fSdrahn     {
173*d2201f2fSdrahn       if (r_opc[idx] != opc)
174*d2201f2fSdrahn 	continue;
175*d2201f2fSdrahn       else
176*d2201f2fSdrahn 	break;
177*d2201f2fSdrahn   }
178*d2201f2fSdrahn 
179*d2201f2fSdrahn   if (idx == r_opc_num)
180*d2201f2fSdrahn     return NIL;
181*d2201f2fSdrahn 
182*d2201f2fSdrahn   for (idx = 0 ; idx < dlx_r_opcode_num; idx++)
183*d2201f2fSdrahn     if (dlx_r_opcode[idx].func == func)
184*d2201f2fSdrahn       {
185*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "%s", dlx_r_opcode[idx].name);
186*d2201f2fSdrahn 
187*d2201f2fSdrahn 	if (func != NOPF)
188*d2201f2fSdrahn 	  {
189*d2201f2fSdrahn 	    /* This is not a nop.  */
190*d2201f2fSdrahn 	    operand_deliminator (info, dlx_r_opcode[idx].name);
191*d2201f2fSdrahn 	    (*info->fprintf_func) (info->stream, "r%d,", (int)rd);
192*d2201f2fSdrahn 	    (*info->fprintf_func) (info->stream, "r%d", (int)rs1);
193*d2201f2fSdrahn 	    if (func != MVTSF && func != MVFSF)
194*d2201f2fSdrahn 	      (*info->fprintf_func) (info->stream, ",r%d", (int)rs2);
195*d2201f2fSdrahn 	  }
196*d2201f2fSdrahn 	return (unsigned char) R_TYPE;
197*d2201f2fSdrahn       }
198*d2201f2fSdrahn 
199*d2201f2fSdrahn   return (unsigned char) R_ERROR;
200*d2201f2fSdrahn }
201*d2201f2fSdrahn 
202*d2201f2fSdrahn /* Process the memory read opcode.  */
203*d2201f2fSdrahn 
204*d2201f2fSdrahn static unsigned char
dlx_load_type(info)205*d2201f2fSdrahn dlx_load_type (info)
206*d2201f2fSdrahn      struct disassemble_info* info;
207*d2201f2fSdrahn {
208*d2201f2fSdrahn   struct _load_opcode
209*d2201f2fSdrahn   {
210*d2201f2fSdrahn     unsigned long opcode;
211*d2201f2fSdrahn     char *name;
212*d2201f2fSdrahn   }
213*d2201f2fSdrahn   dlx_load_opcode[] =
214*d2201f2fSdrahn     {
215*d2201f2fSdrahn       { OPC(LHIOP),   "lhi" },  /* Load HI to register.           */
216*d2201f2fSdrahn       { OPC(LBOP),     "lb" },  /* load byte sign extended.       */
217*d2201f2fSdrahn       { OPC(LBUOP),   "lbu" },  /* load byte unsigned.            */
218*d2201f2fSdrahn       { OPC(LSBUOP),"ldstbu"},  /* load store byte unsigned.      */
219*d2201f2fSdrahn       { OPC(LHOP),     "lh" },  /* load halfword sign extended.   */
220*d2201f2fSdrahn       { OPC(LHUOP),   "lhu" },  /* load halfword unsigned.        */
221*d2201f2fSdrahn       { OPC(LSHUOP),"ldsthu"},  /* load store halfword unsigned.  */
222*d2201f2fSdrahn       { OPC(LWOP),     "lw" },  /* load word.                     */
223*d2201f2fSdrahn       { OPC(LSWOP), "ldstw" }   /* load store word.               */
224*d2201f2fSdrahn     };
225*d2201f2fSdrahn   int dlx_load_opcode_num =
226*d2201f2fSdrahn     (sizeof dlx_load_opcode) / (sizeof dlx_load_opcode[0]);
227*d2201f2fSdrahn   int idx;
228*d2201f2fSdrahn 
229*d2201f2fSdrahn   for (idx = 0 ; idx < dlx_load_opcode_num; idx++)
230*d2201f2fSdrahn     if (dlx_load_opcode[idx].opcode == opc)
231*d2201f2fSdrahn       {
232*d2201f2fSdrahn 	if (opc == OPC (LHIOP))
233*d2201f2fSdrahn 	  {
234*d2201f2fSdrahn 	    (*info->fprintf_func) (info->stream, "%s", dlx_load_opcode[idx].name);
235*d2201f2fSdrahn 	    operand_deliminator (info, dlx_load_opcode[idx].name);
236*d2201f2fSdrahn 	    (*info->fprintf_func) (info->stream, "r%d,", (int)rs2);
237*d2201f2fSdrahn 	    (*info->fprintf_func) (info->stream, "0x%04x", (int)imm16);
238*d2201f2fSdrahn 	  }
239*d2201f2fSdrahn 	else
240*d2201f2fSdrahn 	  {
241*d2201f2fSdrahn 	    (*info->fprintf_func) (info->stream, "%s", dlx_load_opcode[idx].name);
242*d2201f2fSdrahn 	    operand_deliminator (info, dlx_load_opcode[idx].name);
243*d2201f2fSdrahn 	    (*info->fprintf_func) (info->stream, "r%d,", (int)rs2);
244*d2201f2fSdrahn 	    (*info->fprintf_func) (info->stream, "0x%04x[r%d]", (int)imm16, (int)rs1);
245*d2201f2fSdrahn 	  }
246*d2201f2fSdrahn 
247*d2201f2fSdrahn 	return (unsigned char) ILD_TYPE;
248*d2201f2fSdrahn     }
249*d2201f2fSdrahn 
250*d2201f2fSdrahn   return (unsigned char) NIL;
251*d2201f2fSdrahn }
252*d2201f2fSdrahn 
253*d2201f2fSdrahn /* Process the memory store opcode.  */
254*d2201f2fSdrahn 
255*d2201f2fSdrahn static unsigned char
dlx_store_type(info)256*d2201f2fSdrahn dlx_store_type (info)
257*d2201f2fSdrahn      struct disassemble_info* info;
258*d2201f2fSdrahn {
259*d2201f2fSdrahn   struct _store_opcode
260*d2201f2fSdrahn   {
261*d2201f2fSdrahn     unsigned long opcode;
262*d2201f2fSdrahn     char *name;
263*d2201f2fSdrahn   }
264*d2201f2fSdrahn   dlx_store_opcode[] =
265*d2201f2fSdrahn     {
266*d2201f2fSdrahn       { OPC(SBOP),     "sb" },  /* Store byte.      */
267*d2201f2fSdrahn       { OPC(SHOP),     "sh" },  /* Store halfword.  */
268*d2201f2fSdrahn       { OPC(SWOP),     "sw" },  /* Store word.      */
269*d2201f2fSdrahn     };
270*d2201f2fSdrahn   int dlx_store_opcode_num =
271*d2201f2fSdrahn     (sizeof dlx_store_opcode) / (sizeof dlx_store_opcode[0]);
272*d2201f2fSdrahn   int idx;
273*d2201f2fSdrahn 
274*d2201f2fSdrahn   for (idx = 0 ; idx < dlx_store_opcode_num; idx++)
275*d2201f2fSdrahn     if (dlx_store_opcode[idx].opcode == opc)
276*d2201f2fSdrahn       {
277*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "%s", dlx_store_opcode[idx].name);
278*d2201f2fSdrahn 	operand_deliminator (info, dlx_store_opcode[idx].name);
279*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "0x%04x[r%d],", (int)imm16, (int)rs1);
280*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "r%d", (int)rs2);
281*d2201f2fSdrahn 	return (unsigned char) IST_TYPE;
282*d2201f2fSdrahn       }
283*d2201f2fSdrahn 
284*d2201f2fSdrahn   return (unsigned char) NIL;
285*d2201f2fSdrahn }
286*d2201f2fSdrahn 
287*d2201f2fSdrahn /* Process the Arithmetic and Logical I-TYPE opcode.  */
288*d2201f2fSdrahn 
289*d2201f2fSdrahn static unsigned char
dlx_aluI_type(info)290*d2201f2fSdrahn dlx_aluI_type (info)
291*d2201f2fSdrahn      struct disassemble_info* info;
292*d2201f2fSdrahn {
293*d2201f2fSdrahn   struct _aluI_opcode
294*d2201f2fSdrahn   {
295*d2201f2fSdrahn     unsigned long opcode;
296*d2201f2fSdrahn     char *name;
297*d2201f2fSdrahn   }
298*d2201f2fSdrahn   dlx_aluI_opcode[] =
299*d2201f2fSdrahn     {
300*d2201f2fSdrahn       { OPC(ADDIOP),   "addi"  },  /* Store byte.      */
301*d2201f2fSdrahn       { OPC(ADDUIOP),  "addui" },  /* Store halfword.  */
302*d2201f2fSdrahn       { OPC(SUBIOP),   "subi"  },  /* Store word.      */
303*d2201f2fSdrahn       { OPC(SUBUIOP),  "subui" },  /* Store word.      */
304*d2201f2fSdrahn       { OPC(ANDIOP),   "andi"  },  /* Store word.      */
305*d2201f2fSdrahn       { OPC(ORIOP),    "ori"   },  /* Store word.      */
306*d2201f2fSdrahn       { OPC(XORIOP),   "xori"  },  /* Store word.      */
307*d2201f2fSdrahn       { OPC(SLLIOP),   "slli"  },  /* Store word.      */
308*d2201f2fSdrahn       { OPC(SRAIOP),   "srai"  },  /* Store word.      */
309*d2201f2fSdrahn       { OPC(SRLIOP),   "srli"  },  /* Store word.      */
310*d2201f2fSdrahn       { OPC(SEQIOP),   "seqi"  },  /* Store word.      */
311*d2201f2fSdrahn       { OPC(SNEIOP),   "snei"  },  /* Store word.      */
312*d2201f2fSdrahn       { OPC(SLTIOP),   "slti"  },  /* Store word.      */
313*d2201f2fSdrahn       { OPC(SGTIOP),   "sgti"  },  /* Store word.      */
314*d2201f2fSdrahn       { OPC(SLEIOP),   "slei"  },  /* Store word.      */
315*d2201f2fSdrahn       { OPC(SGEIOP),   "sgei"  },  /* Store word.      */
316*d2201f2fSdrahn       { OPC(SEQUIOP),  "sequi" },  /* Store word.      */
317*d2201f2fSdrahn       { OPC(SNEUIOP),  "sneui" },  /* Store word.      */
318*d2201f2fSdrahn       { OPC(SLTUIOP),  "sltui" },  /* Store word.      */
319*d2201f2fSdrahn       { OPC(SGTUIOP),  "sgtui" },  /* Store word.      */
320*d2201f2fSdrahn       { OPC(SLEUIOP),  "sleui" },  /* Store word.      */
321*d2201f2fSdrahn       { OPC(SGEUIOP),  "sgeui" },  /* Store word.      */
322*d2201f2fSdrahn #if 0
323*d2201f2fSdrahn       { OPC(MVTSOP),   "mvts"  },  /* Store word.      */
324*d2201f2fSdrahn       { OPC(MVFSOP),   "mvfs"  },  /* Store word.      */
325*d2201f2fSdrahn #endif
326*d2201f2fSdrahn     };
327*d2201f2fSdrahn   int dlx_aluI_opcode_num =
328*d2201f2fSdrahn     (sizeof dlx_aluI_opcode) / (sizeof dlx_aluI_opcode[0]);
329*d2201f2fSdrahn   int idx;
330*d2201f2fSdrahn 
331*d2201f2fSdrahn   for (idx = 0 ; idx < dlx_aluI_opcode_num; idx++)
332*d2201f2fSdrahn     if (dlx_aluI_opcode[idx].opcode == opc)
333*d2201f2fSdrahn       {
334*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "%s", dlx_aluI_opcode[idx].name);
335*d2201f2fSdrahn 	operand_deliminator (info, dlx_aluI_opcode[idx].name);
336*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "r%d,", (int)rs2);
337*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "r%d,", (int)rs1);
338*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "0x%04x", (int)imm16);
339*d2201f2fSdrahn 
340*d2201f2fSdrahn 	return (unsigned char) IAL_TYPE;
341*d2201f2fSdrahn       }
342*d2201f2fSdrahn 
343*d2201f2fSdrahn   return (unsigned char) NIL;
344*d2201f2fSdrahn }
345*d2201f2fSdrahn 
346*d2201f2fSdrahn /* Process the branch instruction.  */
347*d2201f2fSdrahn 
348*d2201f2fSdrahn static unsigned char
dlx_br_type(info)349*d2201f2fSdrahn dlx_br_type (info)
350*d2201f2fSdrahn      struct disassemble_info* info;
351*d2201f2fSdrahn {
352*d2201f2fSdrahn   struct _br_opcode
353*d2201f2fSdrahn   {
354*d2201f2fSdrahn     unsigned long opcode;
355*d2201f2fSdrahn     char *name;
356*d2201f2fSdrahn   }
357*d2201f2fSdrahn   dlx_br_opcode[] =
358*d2201f2fSdrahn     {
359*d2201f2fSdrahn       { OPC(BEQOP), "beqz" }, /* Store byte.  */
360*d2201f2fSdrahn       { OPC(BNEOP), "bnez" }  /* Store halfword.  */
361*d2201f2fSdrahn     };
362*d2201f2fSdrahn   int dlx_br_opcode_num =
363*d2201f2fSdrahn     (sizeof dlx_br_opcode) / (sizeof dlx_br_opcode[0]);
364*d2201f2fSdrahn   int idx;
365*d2201f2fSdrahn 
366*d2201f2fSdrahn   for (idx = 0 ; idx < dlx_br_opcode_num; idx++)
367*d2201f2fSdrahn     if (dlx_br_opcode[idx].opcode == opc)
368*d2201f2fSdrahn       {
369*d2201f2fSdrahn 	if (imm16 & 0x00008000)
370*d2201f2fSdrahn 	  imm16 |= 0xFFFF0000;
371*d2201f2fSdrahn 
372*d2201f2fSdrahn 	imm16 += (current_insn_addr + 4);
373*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "%s", dlx_br_opcode[idx].name);
374*d2201f2fSdrahn 	operand_deliminator (info, dlx_br_opcode[idx].name);
375*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "r%d,", (int)rs1);
376*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "0x%08x", (int)imm16);
377*d2201f2fSdrahn 
378*d2201f2fSdrahn 	return (unsigned char) IBR_TYPE;
379*d2201f2fSdrahn       }
380*d2201f2fSdrahn 
381*d2201f2fSdrahn   return (unsigned char) NIL;
382*d2201f2fSdrahn }
383*d2201f2fSdrahn 
384*d2201f2fSdrahn /* Process the jump instruction.  */
385*d2201f2fSdrahn 
386*d2201f2fSdrahn static unsigned char
dlx_jmp_type(info)387*d2201f2fSdrahn dlx_jmp_type (info)
388*d2201f2fSdrahn      struct disassemble_info* info;
389*d2201f2fSdrahn {
390*d2201f2fSdrahn   struct _jmp_opcode
391*d2201f2fSdrahn   {
392*d2201f2fSdrahn     unsigned long opcode;
393*d2201f2fSdrahn     char *name;
394*d2201f2fSdrahn   }
395*d2201f2fSdrahn   dlx_jmp_opcode[] =
396*d2201f2fSdrahn     {
397*d2201f2fSdrahn       { OPC(JOP),         "j" },  /* Store byte.      */
398*d2201f2fSdrahn       { OPC(JALOP),     "jal" },  /* Store halfword.  */
399*d2201f2fSdrahn       { OPC(BREAKOP), "break" },  /* Store halfword.  */
400*d2201f2fSdrahn       { OPC(TRAPOP),   "trap" },  /* Store halfword.  */
401*d2201f2fSdrahn       { OPC(RFEOP),     "rfe" }   /* Store halfword.  */
402*d2201f2fSdrahn     };
403*d2201f2fSdrahn   int dlx_jmp_opcode_num =
404*d2201f2fSdrahn     (sizeof dlx_jmp_opcode) / (sizeof dlx_jmp_opcode[0]);
405*d2201f2fSdrahn   int idx;
406*d2201f2fSdrahn 
407*d2201f2fSdrahn   for (idx = 0 ; idx < dlx_jmp_opcode_num; idx++)
408*d2201f2fSdrahn     if (dlx_jmp_opcode[idx].opcode == opc)
409*d2201f2fSdrahn       {
410*d2201f2fSdrahn 	if (imm26 & 0x02000000)
411*d2201f2fSdrahn 	  imm26 |= 0xFC000000;
412*d2201f2fSdrahn 
413*d2201f2fSdrahn 	imm26 += (current_insn_addr + 4);
414*d2201f2fSdrahn 
415*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "%s", dlx_jmp_opcode[idx].name);
416*d2201f2fSdrahn 	operand_deliminator (info, dlx_jmp_opcode[idx].name);
417*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "0x%08x", (int)imm26);
418*d2201f2fSdrahn 
419*d2201f2fSdrahn 	return (unsigned char) IJ_TYPE;
420*d2201f2fSdrahn       }
421*d2201f2fSdrahn 
422*d2201f2fSdrahn   return (unsigned char) NIL;
423*d2201f2fSdrahn }
424*d2201f2fSdrahn 
425*d2201f2fSdrahn /* Process the jump register instruction.  */
426*d2201f2fSdrahn 
427*d2201f2fSdrahn static unsigned char
dlx_jr_type(info)428*d2201f2fSdrahn dlx_jr_type (info)
429*d2201f2fSdrahn      struct disassemble_info* info;
430*d2201f2fSdrahn {
431*d2201f2fSdrahn   struct _jr_opcode
432*d2201f2fSdrahn   {
433*d2201f2fSdrahn     unsigned long opcode;
434*d2201f2fSdrahn     char *name;
435*d2201f2fSdrahn   }
436*d2201f2fSdrahn   dlx_jr_opcode[] = {
437*d2201f2fSdrahn     { OPC(JROP),   "jr"    },  /* Store byte.  */
438*d2201f2fSdrahn     { OPC(JALROP), "jalr"  }   /* Store halfword.  */
439*d2201f2fSdrahn   };
440*d2201f2fSdrahn   int dlx_jr_opcode_num =
441*d2201f2fSdrahn     (sizeof dlx_jr_opcode) / (sizeof dlx_jr_opcode[0]);
442*d2201f2fSdrahn   int idx;
443*d2201f2fSdrahn 
444*d2201f2fSdrahn   for (idx = 0 ; idx < dlx_jr_opcode_num; idx++)
445*d2201f2fSdrahn     if (dlx_jr_opcode[idx].opcode == opc)
446*d2201f2fSdrahn       {
447*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "%s", dlx_jr_opcode[idx].name);
448*d2201f2fSdrahn 	operand_deliminator (info, dlx_jr_opcode[idx].name);
449*d2201f2fSdrahn 	(*info->fprintf_func) (info->stream, "r%d", (int)rs1);
450*d2201f2fSdrahn 	return (unsigned char) IJR_TYPE;
451*d2201f2fSdrahn       }
452*d2201f2fSdrahn 
453*d2201f2fSdrahn   return (unsigned char) NIL;
454*d2201f2fSdrahn }
455*d2201f2fSdrahn 
456*d2201f2fSdrahn typedef unsigned char (* dlx_insn) PARAMS ((struct disassemble_info *));
457*d2201f2fSdrahn 
458*d2201f2fSdrahn /* This is the main DLX insn handling routine.  */
459*d2201f2fSdrahn 
460*d2201f2fSdrahn int
print_insn_dlx(memaddr,info)461*d2201f2fSdrahn print_insn_dlx (memaddr, info)
462*d2201f2fSdrahn      bfd_vma memaddr;
463*d2201f2fSdrahn      struct disassemble_info* info;
464*d2201f2fSdrahn {
465*d2201f2fSdrahn   bfd_byte buffer[4];
466*d2201f2fSdrahn   int insn_idx;
467*d2201f2fSdrahn   unsigned long insn_word;
468*d2201f2fSdrahn   unsigned char rtn_code;
469*d2201f2fSdrahn   unsigned long dlx_insn_type[] =
470*d2201f2fSdrahn     {
471*d2201f2fSdrahn       (unsigned long) dlx_r_type,
472*d2201f2fSdrahn       (unsigned long) dlx_load_type,
473*d2201f2fSdrahn       (unsigned long) dlx_store_type,
474*d2201f2fSdrahn       (unsigned long) dlx_aluI_type,
475*d2201f2fSdrahn       (unsigned long) dlx_br_type,
476*d2201f2fSdrahn       (unsigned long) dlx_jmp_type,
477*d2201f2fSdrahn       (unsigned long) dlx_jr_type,
478*d2201f2fSdrahn       (unsigned long) NULL
479*d2201f2fSdrahn   };
480*d2201f2fSdrahn   int dlx_insn_type_num = ((sizeof dlx_insn_type) / (sizeof (unsigned long))) - 1;
481*d2201f2fSdrahn   int status =
482*d2201f2fSdrahn     (*info->read_memory_func) (memaddr, (bfd_byte *) &buffer[0], 4, info);
483*d2201f2fSdrahn 
484*d2201f2fSdrahn   if (status != 0)
485*d2201f2fSdrahn     {
486*d2201f2fSdrahn       (*info->memory_error_func) (status, memaddr, info);
487*d2201f2fSdrahn       return -1;
488*d2201f2fSdrahn     }
489*d2201f2fSdrahn 
490*d2201f2fSdrahn   /* Now decode the insn    */
491*d2201f2fSdrahn   insn_word = bfd_getb32 (buffer);
492*d2201f2fSdrahn   opc  = dlx_get_opcode (insn_word);
493*d2201f2fSdrahn   rs1  = dlx_get_rs1 (insn_word);
494*d2201f2fSdrahn   rs2  = dlx_get_rs2 (insn_word);
495*d2201f2fSdrahn   rd   = dlx_get_rdR (insn_word);
496*d2201f2fSdrahn   func = dlx_get_func (insn_word);
497*d2201f2fSdrahn   imm16= dlx_get_imm16 (insn_word);
498*d2201f2fSdrahn   imm26= dlx_get_imm26 (insn_word);
499*d2201f2fSdrahn 
500*d2201f2fSdrahn #if 0
501*d2201f2fSdrahn   printf ("print_insn_big_dlx: opc = 0x%02x\n"
502*d2201f2fSdrahn 	  "                    rs1 = 0x%02x\n"
503*d2201f2fSdrahn 	  "                    rs2 = 0x%02x\n"
504*d2201f2fSdrahn 	  "                    rd  = 0x%02x\n"
505*d2201f2fSdrahn 	  "                  func  = 0x%08x\n"
506*d2201f2fSdrahn 	  "                 imm16  = 0x%08x\n"
507*d2201f2fSdrahn 	  "                 imm26  = 0x%08x\n",
508*d2201f2fSdrahn 	  opc, rs1, rs2, rd, func, imm16, imm26);
509*d2201f2fSdrahn #endif
510*d2201f2fSdrahn 
511*d2201f2fSdrahn   /* Scan through all the insn type and print the insn out.  */
512*d2201f2fSdrahn   rtn_code = 0;
513*d2201f2fSdrahn   current_insn_addr = (unsigned long) memaddr;
514*d2201f2fSdrahn 
515*d2201f2fSdrahn   for (insn_idx = 0; dlx_insn_type[insn_idx] != 0x0; insn_idx++)
516*d2201f2fSdrahn     switch (((dlx_insn) (dlx_insn_type[insn_idx])) (info))
517*d2201f2fSdrahn       {
518*d2201f2fSdrahn 	/* Found the correct opcode   */
519*d2201f2fSdrahn       case R_TYPE:
520*d2201f2fSdrahn       case ILD_TYPE:
521*d2201f2fSdrahn       case IST_TYPE:
522*d2201f2fSdrahn       case IAL_TYPE:
523*d2201f2fSdrahn       case IBR_TYPE:
524*d2201f2fSdrahn       case IJ_TYPE:
525*d2201f2fSdrahn       case IJR_TYPE:
526*d2201f2fSdrahn 	return 4;
527*d2201f2fSdrahn 
528*d2201f2fSdrahn 	/* Wrong insn type check next one. */
529*d2201f2fSdrahn       default:
530*d2201f2fSdrahn       case NIL:
531*d2201f2fSdrahn 	continue;
532*d2201f2fSdrahn 
533*d2201f2fSdrahn 	/* All rest of the return code are not recongnized, treat it as error */
534*d2201f2fSdrahn 	/* we should never get here,  I hope! */
535*d2201f2fSdrahn       case R_ERROR:
536*d2201f2fSdrahn 	return -1;
537*d2201f2fSdrahn       }
538*d2201f2fSdrahn 
539*d2201f2fSdrahn   if (insn_idx ==  dlx_insn_type_num)
540*d2201f2fSdrahn     /* Well, does not recoganize this opcode.  */
541*d2201f2fSdrahn     (*info->fprintf_func) (info->stream, "<%s>", "Unrecognized Opcode");
542*d2201f2fSdrahn 
543*d2201f2fSdrahn   return 4;
544*d2201f2fSdrahn }
545