1 /* Print vax instructions for GDB, the GNU debugger.
2 Copyright (C) 1986, 1989 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "vax-opcode.h"
27 /* Vax instructions are never longer than this. */
30 /* Number of elements in the opcode table. */
31 #define NOPCODES (sizeof votstrs / sizeof votstrs[0])
33 extern char *reg_names[];
35 static unsigned char *print_insn_arg ();
37 /* Print the vax instruction at address MEMADDR in debugged memory,
38 on STREAM. Returns length of the instruction, in bytes. */
41 print_insn (memaddr, stream)
45 unsigned char buffer[MAXLEN];
47 register unsigned char *p;
50 read_memory (memaddr, buffer, MAXLEN);
52 for (i = 0; i < NOPCODES; i++)
53 if (votstrs[i].detail.code == buffer[0]
54 || votstrs[i].detail.code == *(unsigned short *)buffer)
57 /* Handle undefined instructions. */
60 fprintf (stream, "0%o", buffer[0]);
64 fprintf (stream, "%s", votstrs[i].name);
66 /* Point at first byte of argument data,
67 and at descriptor for first argument. */
68 p = buffer + 1 + (votstrs[i].detail.code >= 0x100);
69 d = votstrs[i].detail.args;
76 p = print_insn_arg (d, p, memaddr + (p - buffer), stream);
79 fprintf (stream, ",");
84 static unsigned char *
85 print_insn_arg (d, p, addr, stream)
91 register int regnum = *p & 0xf;
97 fprintf (stream, "0x%x", addr + *p++ + 1);
100 fprintf (stream, "0x%x", addr + *(short *)p + 2);
105 switch ((*p++ >> 4) & 0xf)
110 case 3: /* Literal mode */
111 if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
113 *(int *)&floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4);
114 fprintf (stream, "$%f", floatlitbuf);
117 fprintf (stream, "$%d", p[-1] & 0x3f);
120 case 4: /* Indexed */
121 p = (char *) print_insn_arg (d, p, addr + 1, stream);
122 fprintf (stream, "[%s]", reg_names[regnum]);
125 case 5: /* Register */
126 fprintf (stream, reg_names[regnum]);
129 case 7: /* Autodecrement */
131 case 6: /* Register deferred */
132 fprintf (stream, "(%s)", reg_names[regnum]);
135 case 9: /* Autoincrement deferred */
137 if (regnum == PC_REGNUM)
140 print_address (*(long *)p, stream);
144 case 8: /* Autoincrement */
145 if (regnum == PC_REGNUM)
151 fprintf (stream, "%d", *p++);
155 fprintf (stream, "%d", *(short *)p);
160 fprintf (stream, "%d", *(long *)p);
165 fprintf (stream, "0x%x%08x", ((long *)p)[1], ((long *)p)[0]);
170 fprintf (stream, "0x%x%08x%08x%08x",
171 ((long *)p)[3], ((long *)p)[2],
172 ((long *)p)[1], ((long *)p)[0]);
177 if (INVALID_FLOAT (p, 4))
178 fprintf (stream, "<<invalid float 0x%x>>", *(int *) p);
180 fprintf (stream, "%f", *(float *) p);
185 if (INVALID_FLOAT (p, 8))
186 fprintf (stream, "<<invalid float 0x%x%08x>>",
187 ((long *)p)[1], ((long *)p)[0]);
189 fprintf (stream, "%f", *(double *) p);
194 fprintf (stream, "g-float");
199 fprintf (stream, "h-float");
206 fprintf (stream, "(%s)+", reg_names[regnum]);
209 case 11: /* Byte displacement deferred */
211 case 10: /* Byte displacement */
212 if (regnum == PC_REGNUM)
213 print_address (addr + *p + 2, stream);
215 fprintf (stream, "%d(%s)", *p, reg_names[regnum]);
219 case 13: /* Word displacement deferred */
221 case 12: /* Word displacement */
222 if (regnum == PC_REGNUM)
223 print_address (addr + *(short *)p + 3, stream);
225 fprintf (stream, "%d(%s)", *(short *)p, reg_names[regnum]);
229 case 15: /* Long displacement deferred */
231 case 14: /* Long displacement */
232 if (regnum == PC_REGNUM)
233 print_address (addr + *(long *)p + 5, stream);
235 fprintf (stream, "%d(%s)", *(long *)p, reg_names[regnum]);
239 return (unsigned char *) p;