xref: /openbsd-src/gnu/usr.bin/binutils-2.17/opcodes/mmix-dis.c (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod /* mmix-dis.c -- Disassemble MMIX instructions.
2*3d8817e4Smiod    Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
3*3d8817e4Smiod    Written by Hans-Peter Nilsson (hp@bitrange.com)
4*3d8817e4Smiod 
5*3d8817e4Smiod    This file is part of GDB and the GNU binutils.
6*3d8817e4Smiod 
7*3d8817e4Smiod    GDB and the GNU binutils are free software; you can redistribute
8*3d8817e4Smiod    them and/or modify them under the terms of the GNU General Public
9*3d8817e4Smiod    License as published by the Free Software Foundation; either version 2,
10*3d8817e4Smiod    or (at your option) any later version.
11*3d8817e4Smiod 
12*3d8817e4Smiod    GDB and the GNU binutils are distributed in the hope that they
13*3d8817e4Smiod    will be useful, but WITHOUT ANY WARRANTY; without even the implied
14*3d8817e4Smiod    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
15*3d8817e4Smiod    the GNU General Public License for more details.
16*3d8817e4Smiod 
17*3d8817e4Smiod    You should have received a copy of the GNU General Public License
18*3d8817e4Smiod    along with this file; see the file COPYING.  If not, write to the Free
19*3d8817e4Smiod    Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
20*3d8817e4Smiod    MA 02110-1301, USA.  */
21*3d8817e4Smiod 
22*3d8817e4Smiod #include <stdio.h>
23*3d8817e4Smiod #include <string.h>
24*3d8817e4Smiod #include <stdlib.h>
25*3d8817e4Smiod #include "opcode/mmix.h"
26*3d8817e4Smiod #include "dis-asm.h"
27*3d8817e4Smiod #include "libiberty.h"
28*3d8817e4Smiod #include "bfd.h"
29*3d8817e4Smiod #include "opintl.h"
30*3d8817e4Smiod 
31*3d8817e4Smiod #define BAD_CASE(x)				\
32*3d8817e4Smiod  do						\
33*3d8817e4Smiod    {						\
34*3d8817e4Smiod      fprintf (stderr,				\
35*3d8817e4Smiod 	      _("Bad case %d (%s) in %s:%d\n"),	\
36*3d8817e4Smiod 	      x, #x, __FILE__, __LINE__);	\
37*3d8817e4Smiod      abort ();					\
38*3d8817e4Smiod    }						\
39*3d8817e4Smiod  while (0)
40*3d8817e4Smiod 
41*3d8817e4Smiod #define FATAL_DEBUG							\
42*3d8817e4Smiod  do									\
43*3d8817e4Smiod    {									\
44*3d8817e4Smiod      fprintf (stderr,							\
45*3d8817e4Smiod 	      _("Internal: Non-debugged code (test-case missing): %s:%d"),\
46*3d8817e4Smiod 	      __FILE__, __LINE__);					\
47*3d8817e4Smiod      abort ();								\
48*3d8817e4Smiod    }									\
49*3d8817e4Smiod  while (0)
50*3d8817e4Smiod 
51*3d8817e4Smiod #define ROUND_MODE(n)					\
52*3d8817e4Smiod  ((n) == 1 ? "ROUND_OFF" : (n) == 2 ? "ROUND_UP" :	\
53*3d8817e4Smiod   (n) == 3 ? "ROUND_DOWN" : (n) == 4 ? "ROUND_NEAR" :	\
54*3d8817e4Smiod   _("(unknown)"))
55*3d8817e4Smiod 
56*3d8817e4Smiod #define INSN_IMMEDIATE_BIT (IMM_OFFSET_BIT << 24)
57*3d8817e4Smiod #define INSN_BACKWARD_OFFSET_BIT (1 << 24)
58*3d8817e4Smiod 
59*3d8817e4Smiod struct mmix_dis_info
60*3d8817e4Smiod  {
61*3d8817e4Smiod    const char *reg_name[256];
62*3d8817e4Smiod    const char *spec_reg_name[32];
63*3d8817e4Smiod 
64*3d8817e4Smiod    /* Waste a little memory so we don't have to allocate each separately.
65*3d8817e4Smiod       We could have an array with static contents for these, but on the
66*3d8817e4Smiod       other hand, we don't have to.  */
67*3d8817e4Smiod    char basic_reg_name[256][sizeof ("$255")];
68*3d8817e4Smiod  };
69*3d8817e4Smiod 
70*3d8817e4Smiod /* Initialize a target-specific array in INFO.  */
71*3d8817e4Smiod 
72*3d8817e4Smiod static bfd_boolean
initialize_mmix_dis_info(struct disassemble_info * info)73*3d8817e4Smiod initialize_mmix_dis_info (struct disassemble_info *info)
74*3d8817e4Smiod {
75*3d8817e4Smiod   struct mmix_dis_info *minfop = malloc (sizeof (struct mmix_dis_info));
76*3d8817e4Smiod   int i;
77*3d8817e4Smiod 
78*3d8817e4Smiod   if (minfop == NULL)
79*3d8817e4Smiod     return FALSE;
80*3d8817e4Smiod 
81*3d8817e4Smiod   memset (minfop, 0, sizeof (*minfop));
82*3d8817e4Smiod 
83*3d8817e4Smiod   /* Initialize register names from register symbols.  If there's no
84*3d8817e4Smiod      register section, then there are no register symbols.  */
85*3d8817e4Smiod   if ((info->section != NULL && info->section->owner != NULL)
86*3d8817e4Smiod       || (info->symbols != NULL
87*3d8817e4Smiod 	  && info->symbols[0] != NULL
88*3d8817e4Smiod 	  && bfd_asymbol_bfd (info->symbols[0]) != NULL))
89*3d8817e4Smiod     {
90*3d8817e4Smiod       bfd *abfd = info->section && info->section->owner != NULL
91*3d8817e4Smiod 	? info->section->owner
92*3d8817e4Smiod 	: bfd_asymbol_bfd (info->symbols[0]);
93*3d8817e4Smiod       asection *reg_section = bfd_get_section_by_name (abfd, "*REG*");
94*3d8817e4Smiod 
95*3d8817e4Smiod       if (reg_section != NULL)
96*3d8817e4Smiod 	{
97*3d8817e4Smiod 	  /* The returned symcount *does* include the ending NULL.  */
98*3d8817e4Smiod 	  long symsize = bfd_get_symtab_upper_bound (abfd);
99*3d8817e4Smiod 	  asymbol **syms = malloc (symsize);
100*3d8817e4Smiod 	  long nsyms;
101*3d8817e4Smiod 	  long i;
102*3d8817e4Smiod 
103*3d8817e4Smiod 	  if (syms == NULL)
104*3d8817e4Smiod 	    {
105*3d8817e4Smiod 	      FATAL_DEBUG;
106*3d8817e4Smiod 	      free (minfop);
107*3d8817e4Smiod 	      return FALSE;
108*3d8817e4Smiod 	    }
109*3d8817e4Smiod 	  nsyms = bfd_canonicalize_symtab (abfd, syms);
110*3d8817e4Smiod 
111*3d8817e4Smiod 	  /* We use the first name for a register.  If this is MMO, then
112*3d8817e4Smiod 	     it's the name with the first sequence number, presumably the
113*3d8817e4Smiod 	     first in the source.  */
114*3d8817e4Smiod 	  for (i = 0; i < nsyms && syms[i] != NULL; i++)
115*3d8817e4Smiod 	    {
116*3d8817e4Smiod 	      if (syms[i]->section == reg_section
117*3d8817e4Smiod 		  && syms[i]->value < 256
118*3d8817e4Smiod 		  && minfop->reg_name[syms[i]->value] == NULL)
119*3d8817e4Smiod 		minfop->reg_name[syms[i]->value] = syms[i]->name;
120*3d8817e4Smiod 	    }
121*3d8817e4Smiod 	}
122*3d8817e4Smiod     }
123*3d8817e4Smiod 
124*3d8817e4Smiod   /* Fill in the rest with the canonical names.  */
125*3d8817e4Smiod   for (i = 0; i < 256; i++)
126*3d8817e4Smiod     if (minfop->reg_name[i] == NULL)
127*3d8817e4Smiod       {
128*3d8817e4Smiod 	sprintf (minfop->basic_reg_name[i], "$%d", i);
129*3d8817e4Smiod 	minfop->reg_name[i] = minfop->basic_reg_name[i];
130*3d8817e4Smiod       }
131*3d8817e4Smiod 
132*3d8817e4Smiod   /* We assume it's actually a one-to-one mapping of number-to-name.  */
133*3d8817e4Smiod   for (i = 0; mmix_spec_regs[i].name != NULL; i++)
134*3d8817e4Smiod     minfop->spec_reg_name[mmix_spec_regs[i].number] = mmix_spec_regs[i].name;
135*3d8817e4Smiod 
136*3d8817e4Smiod   info->private_data = (void *) minfop;
137*3d8817e4Smiod   return TRUE;
138*3d8817e4Smiod }
139*3d8817e4Smiod 
140*3d8817e4Smiod /* A table indexed by the first byte is constructed as we disassemble each
141*3d8817e4Smiod    tetrabyte.  The contents is a pointer into mmix_insns reflecting the
142*3d8817e4Smiod    first found entry with matching match-bits and lose-bits.  Further
143*3d8817e4Smiod    entries are considered one after one until the operand constraints
144*3d8817e4Smiod    match or the match-bits and lose-bits do not match.  Normally a
145*3d8817e4Smiod    "further entry" will just show that there was no other match.  */
146*3d8817e4Smiod 
147*3d8817e4Smiod static const struct mmix_opcode *
get_opcode(unsigned long insn)148*3d8817e4Smiod get_opcode (unsigned long insn)
149*3d8817e4Smiod {
150*3d8817e4Smiod   static const struct mmix_opcode **opcodes = NULL;
151*3d8817e4Smiod   const struct mmix_opcode *opcodep = mmix_opcodes;
152*3d8817e4Smiod   unsigned int opcode_part = (insn >> 24) & 255;
153*3d8817e4Smiod 
154*3d8817e4Smiod   if (opcodes == NULL)
155*3d8817e4Smiod     opcodes = xcalloc (256, sizeof (struct mmix_opcode *));
156*3d8817e4Smiod 
157*3d8817e4Smiod   opcodep = opcodes[opcode_part];
158*3d8817e4Smiod   if (opcodep == NULL
159*3d8817e4Smiod       || (opcodep->match & insn) != opcodep->match
160*3d8817e4Smiod       || (opcodep->lose & insn) != 0)
161*3d8817e4Smiod     {
162*3d8817e4Smiod       /* Search through the table.  */
163*3d8817e4Smiod       for (opcodep = mmix_opcodes; opcodep->name != NULL; opcodep++)
164*3d8817e4Smiod 	{
165*3d8817e4Smiod 	  /* FIXME: Break out this into an initialization function.  */
166*3d8817e4Smiod 	  if ((opcodep->match & (opcode_part << 24)) == opcode_part
167*3d8817e4Smiod 	      && (opcodep->lose & (opcode_part << 24)) == 0)
168*3d8817e4Smiod 	    opcodes[opcode_part] = opcodep;
169*3d8817e4Smiod 
170*3d8817e4Smiod 	  if ((opcodep->match & insn) == opcodep->match
171*3d8817e4Smiod 	      && (opcodep->lose & insn) == 0)
172*3d8817e4Smiod 	    break;
173*3d8817e4Smiod 	}
174*3d8817e4Smiod     }
175*3d8817e4Smiod 
176*3d8817e4Smiod   if (opcodep->name == NULL)
177*3d8817e4Smiod     return NULL;
178*3d8817e4Smiod 
179*3d8817e4Smiod   /* Check constraints.  If they don't match, loop through the next opcode
180*3d8817e4Smiod      entries.  */
181*3d8817e4Smiod   do
182*3d8817e4Smiod     {
183*3d8817e4Smiod       switch (opcodep->operands)
184*3d8817e4Smiod 	{
185*3d8817e4Smiod 	  /* These have no restraint on what can be in the lower three
186*3d8817e4Smiod 	     bytes.  */
187*3d8817e4Smiod 	case mmix_operands_regs:
188*3d8817e4Smiod 	case mmix_operands_reg_yz:
189*3d8817e4Smiod 	case mmix_operands_regs_z_opt:
190*3d8817e4Smiod 	case mmix_operands_regs_z:
191*3d8817e4Smiod 	case mmix_operands_jmp:
192*3d8817e4Smiod 	case mmix_operands_pushgo:
193*3d8817e4Smiod 	case mmix_operands_pop:
194*3d8817e4Smiod 	case mmix_operands_sync:
195*3d8817e4Smiod 	case mmix_operands_x_regs_z:
196*3d8817e4Smiod 	case mmix_operands_neg:
197*3d8817e4Smiod 	case mmix_operands_pushj:
198*3d8817e4Smiod 	case mmix_operands_regaddr:
199*3d8817e4Smiod 	case mmix_operands_get:
200*3d8817e4Smiod 	case mmix_operands_set:
201*3d8817e4Smiod 	case mmix_operands_save:
202*3d8817e4Smiod 	case mmix_operands_unsave:
203*3d8817e4Smiod 	case mmix_operands_xyz_opt:
204*3d8817e4Smiod 	  return opcodep;
205*3d8817e4Smiod 
206*3d8817e4Smiod 	  /* For a ROUND_MODE, the middle byte must be 0..4.  */
207*3d8817e4Smiod 	case mmix_operands_roundregs_z:
208*3d8817e4Smiod 	case mmix_operands_roundregs:
209*3d8817e4Smiod 	  {
210*3d8817e4Smiod 	    int midbyte = (insn >> 8) & 255;
211*3d8817e4Smiod 
212*3d8817e4Smiod 	    if (midbyte <= 4)
213*3d8817e4Smiod 	      return opcodep;
214*3d8817e4Smiod 	  }
215*3d8817e4Smiod 	break;
216*3d8817e4Smiod 
217*3d8817e4Smiod 	case mmix_operands_put:
218*3d8817e4Smiod 	  /* A "PUT".  If it is "immediate", then no restrictions,
219*3d8817e4Smiod 	     otherwise we have to make sure the register number is < 32.  */
220*3d8817e4Smiod 	  if ((insn & INSN_IMMEDIATE_BIT)
221*3d8817e4Smiod 	      || ((insn >> 16) & 255) < 32)
222*3d8817e4Smiod 	    return opcodep;
223*3d8817e4Smiod 	  break;
224*3d8817e4Smiod 
225*3d8817e4Smiod 	case mmix_operands_resume:
226*3d8817e4Smiod 	  /* Middle bytes must be zero.  */
227*3d8817e4Smiod 	  if ((insn & 0x00ffff00) == 0)
228*3d8817e4Smiod 	    return opcodep;
229*3d8817e4Smiod 	  break;
230*3d8817e4Smiod 
231*3d8817e4Smiod 	default:
232*3d8817e4Smiod 	  BAD_CASE (opcodep->operands);
233*3d8817e4Smiod 	}
234*3d8817e4Smiod 
235*3d8817e4Smiod       opcodep++;
236*3d8817e4Smiod     }
237*3d8817e4Smiod   while ((opcodep->match & insn) == opcodep->match
238*3d8817e4Smiod 	 && (opcodep->lose & insn) == 0);
239*3d8817e4Smiod 
240*3d8817e4Smiod   /* If we got here, we had no match.  */
241*3d8817e4Smiod   return NULL;
242*3d8817e4Smiod }
243*3d8817e4Smiod 
244*3d8817e4Smiod /* The main disassembly function.  */
245*3d8817e4Smiod 
246*3d8817e4Smiod int
print_insn_mmix(bfd_vma memaddr,struct disassemble_info * info)247*3d8817e4Smiod print_insn_mmix (bfd_vma memaddr, struct disassemble_info *info)
248*3d8817e4Smiod {
249*3d8817e4Smiod   unsigned char buffer[4];
250*3d8817e4Smiod   unsigned long insn;
251*3d8817e4Smiod   unsigned int x, y, z;
252*3d8817e4Smiod   const struct mmix_opcode *opcodep;
253*3d8817e4Smiod   int status = (*info->read_memory_func) (memaddr, buffer, 4, info);
254*3d8817e4Smiod   struct mmix_dis_info *minfop;
255*3d8817e4Smiod 
256*3d8817e4Smiod   if (status != 0)
257*3d8817e4Smiod     {
258*3d8817e4Smiod       (*info->memory_error_func) (status, memaddr, info);
259*3d8817e4Smiod       return -1;
260*3d8817e4Smiod     }
261*3d8817e4Smiod 
262*3d8817e4Smiod   /* FIXME: Is -1 suitable?  */
263*3d8817e4Smiod   if (info->private_data == NULL
264*3d8817e4Smiod       && ! initialize_mmix_dis_info (info))
265*3d8817e4Smiod     return -1;
266*3d8817e4Smiod 
267*3d8817e4Smiod   minfop = (struct mmix_dis_info *) info->private_data;
268*3d8817e4Smiod   x = buffer[1];
269*3d8817e4Smiod   y = buffer[2];
270*3d8817e4Smiod   z = buffer[3];
271*3d8817e4Smiod 
272*3d8817e4Smiod   insn = bfd_getb32 (buffer);
273*3d8817e4Smiod 
274*3d8817e4Smiod   opcodep = get_opcode (insn);
275*3d8817e4Smiod 
276*3d8817e4Smiod   if (opcodep == NULL)
277*3d8817e4Smiod     {
278*3d8817e4Smiod       (*info->fprintf_func) (info->stream, _("*unknown*"));
279*3d8817e4Smiod       return 4;
280*3d8817e4Smiod     }
281*3d8817e4Smiod 
282*3d8817e4Smiod   (*info->fprintf_func) (info->stream, "%s ", opcodep->name);
283*3d8817e4Smiod 
284*3d8817e4Smiod   /* Present bytes in the order they are laid out in memory.  */
285*3d8817e4Smiod   info->display_endian = BFD_ENDIAN_BIG;
286*3d8817e4Smiod 
287*3d8817e4Smiod   info->insn_info_valid = 1;
288*3d8817e4Smiod   info->bytes_per_chunk = 4;
289*3d8817e4Smiod   info->branch_delay_insns = 0;
290*3d8817e4Smiod   info->target = 0;
291*3d8817e4Smiod   switch (opcodep->type)
292*3d8817e4Smiod     {
293*3d8817e4Smiod     case mmix_type_normal:
294*3d8817e4Smiod     case mmix_type_memaccess_block:
295*3d8817e4Smiod       info->insn_type = dis_nonbranch;
296*3d8817e4Smiod       break;
297*3d8817e4Smiod 
298*3d8817e4Smiod     case mmix_type_branch:
299*3d8817e4Smiod       info->insn_type = dis_branch;
300*3d8817e4Smiod       break;
301*3d8817e4Smiod 
302*3d8817e4Smiod     case mmix_type_condbranch:
303*3d8817e4Smiod       info->insn_type = dis_condbranch;
304*3d8817e4Smiod       break;
305*3d8817e4Smiod 
306*3d8817e4Smiod     case mmix_type_memaccess_octa:
307*3d8817e4Smiod       info->insn_type = dis_dref;
308*3d8817e4Smiod       info->data_size = 8;
309*3d8817e4Smiod       break;
310*3d8817e4Smiod 
311*3d8817e4Smiod     case mmix_type_memaccess_tetra:
312*3d8817e4Smiod       info->insn_type = dis_dref;
313*3d8817e4Smiod       info->data_size = 4;
314*3d8817e4Smiod       break;
315*3d8817e4Smiod 
316*3d8817e4Smiod     case mmix_type_memaccess_wyde:
317*3d8817e4Smiod       info->insn_type = dis_dref;
318*3d8817e4Smiod       info->data_size = 2;
319*3d8817e4Smiod       break;
320*3d8817e4Smiod 
321*3d8817e4Smiod     case mmix_type_memaccess_byte:
322*3d8817e4Smiod       info->insn_type = dis_dref;
323*3d8817e4Smiod       info->data_size = 1;
324*3d8817e4Smiod       break;
325*3d8817e4Smiod 
326*3d8817e4Smiod     case mmix_type_jsr:
327*3d8817e4Smiod       info->insn_type = dis_jsr;
328*3d8817e4Smiod       break;
329*3d8817e4Smiod 
330*3d8817e4Smiod     default:
331*3d8817e4Smiod       BAD_CASE(opcodep->type);
332*3d8817e4Smiod     }
333*3d8817e4Smiod 
334*3d8817e4Smiod   switch (opcodep->operands)
335*3d8817e4Smiod     {
336*3d8817e4Smiod     case mmix_operands_regs:
337*3d8817e4Smiod       /*  All registers: "$X,$Y,$Z".  */
338*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%s,%s,%s",
339*3d8817e4Smiod 			     minfop->reg_name[x],
340*3d8817e4Smiod 			     minfop->reg_name[y],
341*3d8817e4Smiod 			     minfop->reg_name[z]);
342*3d8817e4Smiod       break;
343*3d8817e4Smiod 
344*3d8817e4Smiod     case mmix_operands_reg_yz:
345*3d8817e4Smiod       /* Like SETH - "$X,YZ".  */
346*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%s,0x%x",
347*3d8817e4Smiod 			     minfop->reg_name[x], y * 256 + z);
348*3d8817e4Smiod       break;
349*3d8817e4Smiod 
350*3d8817e4Smiod     case mmix_operands_regs_z_opt:
351*3d8817e4Smiod     case mmix_operands_regs_z:
352*3d8817e4Smiod     case mmix_operands_pushgo:
353*3d8817e4Smiod       /* The regular "$X,$Y,$Z|Z".  */
354*3d8817e4Smiod       if (insn & INSN_IMMEDIATE_BIT)
355*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,%s,%d",
356*3d8817e4Smiod 			       minfop->reg_name[x], minfop->reg_name[y], z);
357*3d8817e4Smiod       else
358*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,%s,%s",
359*3d8817e4Smiod 			       minfop->reg_name[x],
360*3d8817e4Smiod 			       minfop->reg_name[y],
361*3d8817e4Smiod 			       minfop->reg_name[z]);
362*3d8817e4Smiod       break;
363*3d8817e4Smiod 
364*3d8817e4Smiod     case mmix_operands_jmp:
365*3d8817e4Smiod       /* Address; only JMP.  */
366*3d8817e4Smiod       {
367*3d8817e4Smiod 	bfd_signed_vma offset = (x * 65536 + y * 256 + z) * 4;
368*3d8817e4Smiod 
369*3d8817e4Smiod 	if (insn & INSN_BACKWARD_OFFSET_BIT)
370*3d8817e4Smiod 	  offset -= (256 * 65536) * 4;
371*3d8817e4Smiod 
372*3d8817e4Smiod 	info->target = memaddr + offset;
373*3d8817e4Smiod 	(*info->print_address_func) (memaddr + offset, info);
374*3d8817e4Smiod       }
375*3d8817e4Smiod       break;
376*3d8817e4Smiod 
377*3d8817e4Smiod     case mmix_operands_roundregs_z:
378*3d8817e4Smiod       /* Two registers, like FLOT, possibly with rounding: "$X,$Z|Z"
379*3d8817e4Smiod 	 "$X,ROUND_MODE,$Z|Z".  */
380*3d8817e4Smiod       if (y != 0)
381*3d8817e4Smiod 	{
382*3d8817e4Smiod 	  if (insn & INSN_IMMEDIATE_BIT)
383*3d8817e4Smiod 	    (*info->fprintf_func) (info->stream, "%s,%s,%d",
384*3d8817e4Smiod 				   minfop->reg_name[x],
385*3d8817e4Smiod 				   ROUND_MODE (y), z);
386*3d8817e4Smiod 	  else
387*3d8817e4Smiod 	    (*info->fprintf_func) (info->stream, "%s,%s,%s",
388*3d8817e4Smiod 				   minfop->reg_name[x],
389*3d8817e4Smiod 				   ROUND_MODE (y),
390*3d8817e4Smiod 				   minfop->reg_name[z]);
391*3d8817e4Smiod 	}
392*3d8817e4Smiod       else
393*3d8817e4Smiod 	{
394*3d8817e4Smiod 	  if (insn & INSN_IMMEDIATE_BIT)
395*3d8817e4Smiod 	    (*info->fprintf_func) (info->stream, "%s,%d",
396*3d8817e4Smiod 				   minfop->reg_name[x], z);
397*3d8817e4Smiod 	  else
398*3d8817e4Smiod 	    (*info->fprintf_func) (info->stream, "%s,%s",
399*3d8817e4Smiod 				   minfop->reg_name[x],
400*3d8817e4Smiod 				   minfop->reg_name[z]);
401*3d8817e4Smiod 	}
402*3d8817e4Smiod       break;
403*3d8817e4Smiod 
404*3d8817e4Smiod     case mmix_operands_pop:
405*3d8817e4Smiod       /* Like POP - "X,YZ".  */
406*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%d,%d", x, y*256 + z);
407*3d8817e4Smiod       break;
408*3d8817e4Smiod 
409*3d8817e4Smiod     case mmix_operands_roundregs:
410*3d8817e4Smiod       /* Two registers, possibly with rounding: "$X,$Z" or
411*3d8817e4Smiod 	 "$X,ROUND_MODE,$Z".  */
412*3d8817e4Smiod       if (y != 0)
413*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,%s,%s",
414*3d8817e4Smiod 			       minfop->reg_name[x],
415*3d8817e4Smiod 			       ROUND_MODE (y),
416*3d8817e4Smiod 			       minfop->reg_name[z]);
417*3d8817e4Smiod       else
418*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,%s",
419*3d8817e4Smiod 			       minfop->reg_name[x],
420*3d8817e4Smiod 			       minfop->reg_name[z]);
421*3d8817e4Smiod       break;
422*3d8817e4Smiod 
423*3d8817e4Smiod     case mmix_operands_sync:
424*3d8817e4Smiod 	/* Like SYNC - "XYZ".  */
425*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%u",
426*3d8817e4Smiod 			     x * 65536 + y * 256 + z);
427*3d8817e4Smiod       break;
428*3d8817e4Smiod 
429*3d8817e4Smiod     case mmix_operands_x_regs_z:
430*3d8817e4Smiod       /* Like SYNCD - "X,$Y,$Z|Z".  */
431*3d8817e4Smiod       if (insn & INSN_IMMEDIATE_BIT)
432*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%d,%s,%d",
433*3d8817e4Smiod 			       x, minfop->reg_name[y], z);
434*3d8817e4Smiod       else
435*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%d,%s,%s",
436*3d8817e4Smiod 			       x, minfop->reg_name[y],
437*3d8817e4Smiod 			       minfop->reg_name[z]);
438*3d8817e4Smiod       break;
439*3d8817e4Smiod 
440*3d8817e4Smiod     case mmix_operands_neg:
441*3d8817e4Smiod       /* Like NEG and NEGU - "$X,Y,$Z|Z".  */
442*3d8817e4Smiod       if (insn & INSN_IMMEDIATE_BIT)
443*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,%d,%d",
444*3d8817e4Smiod 			       minfop->reg_name[x], y, z);
445*3d8817e4Smiod       else
446*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,%d,%s",
447*3d8817e4Smiod 			       minfop->reg_name[x], y,
448*3d8817e4Smiod 			       minfop->reg_name[z]);
449*3d8817e4Smiod       break;
450*3d8817e4Smiod 
451*3d8817e4Smiod     case mmix_operands_pushj:
452*3d8817e4Smiod     case mmix_operands_regaddr:
453*3d8817e4Smiod       /* Like GETA or branches - "$X,Address".  */
454*3d8817e4Smiod       {
455*3d8817e4Smiod 	bfd_signed_vma offset = (y * 256 + z) * 4;
456*3d8817e4Smiod 
457*3d8817e4Smiod 	if (insn & INSN_BACKWARD_OFFSET_BIT)
458*3d8817e4Smiod 	  offset -= 65536 * 4;
459*3d8817e4Smiod 
460*3d8817e4Smiod 	info->target = memaddr + offset;
461*3d8817e4Smiod 
462*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,", minfop->reg_name[x]);
463*3d8817e4Smiod 	(*info->print_address_func) (memaddr + offset, info);
464*3d8817e4Smiod       }
465*3d8817e4Smiod       break;
466*3d8817e4Smiod 
467*3d8817e4Smiod     case mmix_operands_get:
468*3d8817e4Smiod       /* GET - "X,spec_reg".  */
469*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%s,%s",
470*3d8817e4Smiod 			     minfop->reg_name[x],
471*3d8817e4Smiod 			     minfop->spec_reg_name[z]);
472*3d8817e4Smiod       break;
473*3d8817e4Smiod 
474*3d8817e4Smiod     case mmix_operands_put:
475*3d8817e4Smiod       /* PUT - "spec_reg,$Z|Z".  */
476*3d8817e4Smiod       if (insn & INSN_IMMEDIATE_BIT)
477*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,%d",
478*3d8817e4Smiod 			       minfop->spec_reg_name[x], z);
479*3d8817e4Smiod       else
480*3d8817e4Smiod 	(*info->fprintf_func) (info->stream, "%s,%s",
481*3d8817e4Smiod 			       minfop->spec_reg_name[x],
482*3d8817e4Smiod 			       minfop->reg_name[z]);
483*3d8817e4Smiod       break;
484*3d8817e4Smiod 
485*3d8817e4Smiod     case mmix_operands_set:
486*3d8817e4Smiod       /*  Two registers, "$X,$Y".  */
487*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%s,%s",
488*3d8817e4Smiod 			     minfop->reg_name[x],
489*3d8817e4Smiod 			     minfop->reg_name[y]);
490*3d8817e4Smiod       break;
491*3d8817e4Smiod 
492*3d8817e4Smiod     case mmix_operands_save:
493*3d8817e4Smiod       /* SAVE - "$X,0".  */
494*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%s,0", minfop->reg_name[x]);
495*3d8817e4Smiod       break;
496*3d8817e4Smiod 
497*3d8817e4Smiod     case mmix_operands_unsave:
498*3d8817e4Smiod       /* UNSAVE - "0,$Z".  */
499*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "0,%s", minfop->reg_name[z]);
500*3d8817e4Smiod       break;
501*3d8817e4Smiod 
502*3d8817e4Smiod     case mmix_operands_xyz_opt:
503*3d8817e4Smiod       /* Like SWYM or TRAP - "X,Y,Z".  */
504*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%d,%d,%d", x, y, z);
505*3d8817e4Smiod       break;
506*3d8817e4Smiod 
507*3d8817e4Smiod     case mmix_operands_resume:
508*3d8817e4Smiod       /* Just "Z", like RESUME.  */
509*3d8817e4Smiod       (*info->fprintf_func) (info->stream, "%d", z);
510*3d8817e4Smiod       break;
511*3d8817e4Smiod 
512*3d8817e4Smiod     default:
513*3d8817e4Smiod       (*info->fprintf_func) (info->stream, _("*unknown operands type: %d*"),
514*3d8817e4Smiod 			     opcodep->operands);
515*3d8817e4Smiod       break;
516*3d8817e4Smiod     }
517*3d8817e4Smiod 
518*3d8817e4Smiod   return 4;
519*3d8817e4Smiod }
520