1 /* Print VAX instructions for GDB, the GNU debugger.
2 Copyright 1986, 1989, 1991, 1992, 1996 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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "opcode/vax.h"
25 /* Vax instructions are never longer than this. */
28 /* Number of elements in the opcode table. */
29 #define NOPCODES (sizeof votstrs / sizeof votstrs[0])
31 static unsigned char *print_insn_arg ();
33 /* Advance PC across any function entry prologue instructions
34 to reach some "real" code. */
37 vax_skip_prologue (CORE_ADDR pc)
39 register int op = (unsigned char) read_memory_integer (pc, 1);
41 pc += 2; /* skip brb */
43 pc += 3; /* skip brw */
45 && ((unsigned char) read_memory_integer (pc + 2, 1)) == 0x5E)
46 pc += 3; /* skip subl2 */
48 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xAE
49 && ((unsigned char) read_memory_integer (pc + 3, 1)) == 0x5E)
50 pc += 4; /* skip movab */
52 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xCE
53 && ((unsigned char) read_memory_integer (pc + 4, 1)) == 0x5E)
54 pc += 5; /* skip movab */
56 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xEE
57 && ((unsigned char) read_memory_integer (pc + 6, 1)) == 0x5E)
58 pc += 7; /* skip movab */
62 /* Return number of args passed to a frame.
63 Can return -1, meaning no way to tell. */
66 vax_frame_num_args (struct frame_info *fi)
68 return (0xff & read_memory_integer (FRAME_ARGS_ADDRESS (fi), 1));
73 /* Print the vax instruction at address MEMADDR in debugged memory,
74 from disassembler info INFO.
75 Returns length of the instruction, in bytes. */
78 vax_print_insn (CORE_ADDR memaddr, disassemble_info *info)
80 unsigned char buffer[MAXLEN];
82 register unsigned char *p;
85 int status = (*info->read_memory_func) (memaddr, buffer, MAXLEN, info);
88 (*info->memory_error_func) (status, memaddr, info);
92 for (i = 0; i < NOPCODES; i++)
93 if (votstrs[i].detail.code == buffer[0]
94 || votstrs[i].detail.code == *(unsigned short *) buffer)
97 /* Handle undefined instructions. */
100 (*info->fprintf_func) (info->stream, "0%o", buffer[0]);
104 (*info->fprintf_func) (info->stream, "%s", votstrs[i].name);
106 /* Point at first byte of argument data,
107 and at descriptor for first argument. */
108 p = buffer + 1 + (votstrs[i].detail.code >= 0x100);
109 d = votstrs[i].detail.args;
112 (*info->fprintf_func) (info->stream, " ");
116 p = print_insn_arg (d, p, memaddr + (p - buffer), info);
119 (*info->fprintf_func) (info->stream, ",");
124 static unsigned char *
125 print_insn_arg (char *d, register char *p, CORE_ADDR addr,
126 disassemble_info *info)
128 register int regnum = *p & 0xf;
134 (*info->fprintf_func) (info->stream, "0x%x", addr + *p++ + 1);
137 (*info->fprintf_func) (info->stream, "0x%x", addr + *(short *) p + 2);
142 switch ((*p++ >> 4) & 0xf)
147 case 3: /* Literal mode */
148 if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
150 *(int *) &floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4);
151 (*info->fprintf_func) (info->stream, "$%f", floatlitbuf);
154 (*info->fprintf_func) (info->stream, "$%d", p[-1] & 0x3f);
157 case 4: /* Indexed */
158 p = (char *) print_insn_arg (d, p, addr + 1, info);
159 (*info->fprintf_func) (info->stream, "[%s]", REGISTER_NAME (regnum));
162 case 5: /* Register */
163 (*info->fprintf_func) (info->stream, REGISTER_NAME (regnum));
166 case 7: /* Autodecrement */
167 (*info->fprintf_func) (info->stream, "-");
168 case 6: /* Register deferred */
169 (*info->fprintf_func) (info->stream, "(%s)", REGISTER_NAME (regnum));
172 case 9: /* Autoincrement deferred */
173 (*info->fprintf_func) (info->stream, "@");
174 if (regnum == PC_REGNUM)
176 (*info->fprintf_func) (info->stream, "#");
177 info->target = *(long *) p;
178 (*info->print_address_func) (info->target, info);
182 case 8: /* Autoincrement */
183 if (regnum == PC_REGNUM)
185 (*info->fprintf_func) (info->stream, "#");
189 (*info->fprintf_func) (info->stream, "%d", *p++);
193 (*info->fprintf_func) (info->stream, "%d", *(short *) p);
198 (*info->fprintf_func) (info->stream, "%d", *(long *) p);
203 (*info->fprintf_func) (info->stream, "0x%x%08x",
204 ((long *) p)[1], ((long *) p)[0]);
209 (*info->fprintf_func) (info->stream, "0x%x%08x%08x%08x",
210 ((long *) p)[3], ((long *) p)[2],
211 ((long *) p)[1], ((long *) p)[0]);
216 if (INVALID_FLOAT (p, 4))
217 (*info->fprintf_func) (info->stream,
218 "<<invalid float 0x%x>>",
221 (*info->fprintf_func) (info->stream, "%f", *(float *) p);
226 if (INVALID_FLOAT (p, 8))
227 (*info->fprintf_func) (info->stream,
228 "<<invalid float 0x%x%08x>>",
229 ((long *) p)[1], ((long *) p)[0]);
231 (*info->fprintf_func) (info->stream, "%f", *(double *) p);
236 (*info->fprintf_func) (info->stream, "g-float");
241 (*info->fprintf_func) (info->stream, "h-float");
248 (*info->fprintf_func) (info->stream, "(%s)+", REGISTER_NAME (regnum));
251 case 11: /* Byte displacement deferred */
252 (*info->fprintf_func) (info->stream, "@");
253 case 10: /* Byte displacement */
254 if (regnum == PC_REGNUM)
256 info->target = addr + *p + 2;
257 (*info->print_address_func) (info->target, info);
260 (*info->fprintf_func) (info->stream, "%d(%s)", *p, REGISTER_NAME (regnum));
264 case 13: /* Word displacement deferred */
265 (*info->fprintf_func) (info->stream, "@");
266 case 12: /* Word displacement */
267 if (regnum == PC_REGNUM)
269 info->target = addr + *(short *) p + 3;
270 (*info->print_address_func) (info->target, info);
273 (*info->fprintf_func) (info->stream, "%d(%s)",
274 *(short *) p, REGISTER_NAME (regnum));
278 case 15: /* Long displacement deferred */
279 (*info->fprintf_func) (info->stream, "@");
280 case 14: /* Long displacement */
281 if (regnum == PC_REGNUM)
283 info->target = addr + *(short *) p + 5;
284 (*info->print_address_func) (info->target, info);
287 (*info->fprintf_func) (info->stream, "%d(%s)",
288 *(long *) p, REGISTER_NAME (regnum));
292 return (unsigned char *) p;
296 _initialize_vax_tdep (void)
298 tm_print_insn = vax_print_insn;