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, Boston, MA 02111-1307, USA. */
22 #include "opcode/vax.h"
24 /* Vax instructions are never longer than this. */
27 /* Number of elements in the opcode table. */
28 #define NOPCODES (sizeof votstrs / sizeof votstrs[0])
30 static unsigned char *print_insn_arg ();
32 /* Advance PC across any function entry prologue instructions
33 to reach some "real" code. */
36 vax_skip_prologue (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 (fi
)
67 struct frame_info
*fi
;
69 return (0xff & read_memory_integer (FRAME_ARGS_ADDRESS (fi
), 1));
74 /* Print the vax instruction at address MEMADDR in debugged memory,
75 from disassembler info INFO.
76 Returns length of the instruction, in bytes. */
79 vax_print_insn (memaddr
, info
)
81 disassemble_info
*info
;
83 unsigned char buffer
[MAXLEN
];
85 register unsigned char *p
;
88 int status
= (*info
->read_memory_func
) (memaddr
, buffer
, MAXLEN
, info
);
91 (*info
->memory_error_func
) (status
, memaddr
, info
);
95 for (i
= 0; i
< NOPCODES
; i
++)
96 if (votstrs
[i
].detail
.code
== buffer
[0]
97 || votstrs
[i
].detail
.code
== *(unsigned short *)buffer
)
100 /* Handle undefined instructions. */
103 (*info
->fprintf_func
) (info
->stream
, "0%o", buffer
[0]);
107 (*info
->fprintf_func
) (info
->stream
, "%s", votstrs
[i
].name
);
109 /* Point at first byte of argument data,
110 and at descriptor for first argument. */
111 p
= buffer
+ 1 + (votstrs
[i
].detail
.code
>= 0x100);
112 d
= votstrs
[i
].detail
.args
;
115 (*info
->fprintf_func
) (info
->stream
, " ");
119 p
= print_insn_arg (d
, p
, memaddr
+ (p
- buffer
), info
);
122 (*info
->fprintf_func
) (info
->stream
, ",");
127 static unsigned char *
128 print_insn_arg (d
, p
, addr
, info
)
132 disassemble_info
*info
;
134 register int regnum
= *p
& 0xf;
140 (*info
->fprintf_func
) (info
->stream
, "0x%x", addr
+ *p
++ + 1);
143 (*info
->fprintf_func
) (info
->stream
, "0x%x", addr
+ *(short *)p
+ 2);
148 switch ((*p
++ >> 4) & 0xf)
153 case 3: /* Literal mode */
154 if (d
[1] == 'd' || d
[1] == 'f' || d
[1] == 'g' || d
[1] == 'h')
156 *(int *)&floatlitbuf
= 0x4000 + ((p
[-1] & 0x3f) << 4);
157 (*info
->fprintf_func
) (info
->stream
, "$%f", floatlitbuf
);
160 (*info
->fprintf_func
) (info
->stream
, "$%d", p
[-1] & 0x3f);
163 case 4: /* Indexed */
164 p
= (char *) print_insn_arg (d
, p
, addr
+ 1, info
);
165 (*info
->fprintf_func
) (info
->stream
, "[%s]", REGISTER_NAME (regnum
));
168 case 5: /* Register */
169 (*info
->fprintf_func
) (info
->stream
, REGISTER_NAME (regnum
));
172 case 7: /* Autodecrement */
173 (*info
->fprintf_func
) (info
->stream
, "-");
174 case 6: /* Register deferred */
175 (*info
->fprintf_func
) (info
->stream
, "(%s)", REGISTER_NAME (regnum
));
178 case 9: /* Autoincrement deferred */
179 (*info
->fprintf_func
) (info
->stream
, "@");
180 if (regnum
== PC_REGNUM
)
182 (*info
->fprintf_func
) (info
->stream
, "#");
183 info
->target
= *(long *)p
;
184 (*info
->print_address_func
) (info
->target
, info
);
188 case 8: /* Autoincrement */
189 if (regnum
== PC_REGNUM
)
191 (*info
->fprintf_func
) (info
->stream
, "#");
195 (*info
->fprintf_func
) (info
->stream
, "%d", *p
++);
199 (*info
->fprintf_func
) (info
->stream
, "%d", *(short *)p
);
204 (*info
->fprintf_func
) (info
->stream
, "%d", *(long *)p
);
209 (*info
->fprintf_func
) (info
->stream
, "0x%x%08x",
210 ((long *)p
)[1], ((long *)p
)[0]);
215 (*info
->fprintf_func
) (info
->stream
, "0x%x%08x%08x%08x",
216 ((long *)p
)[3], ((long *)p
)[2],
217 ((long *)p
)[1], ((long *)p
)[0]);
222 if (INVALID_FLOAT (p
, 4))
223 (*info
->fprintf_func
) (info
->stream
,
224 "<<invalid float 0x%x>>",
227 (*info
->fprintf_func
) (info
->stream
, "%f", *(float *) p
);
232 if (INVALID_FLOAT (p
, 8))
233 (*info
->fprintf_func
) (info
->stream
,
234 "<<invalid float 0x%x%08x>>",
235 ((long *)p
)[1], ((long *)p
)[0]);
237 (*info
->fprintf_func
) (info
->stream
, "%f", *(double *) p
);
242 (*info
->fprintf_func
) (info
->stream
, "g-float");
247 (*info
->fprintf_func
) (info
->stream
, "h-float");
254 (*info
->fprintf_func
) (info
->stream
, "(%s)+", REGISTER_NAME (regnum
));
257 case 11: /* Byte displacement deferred */
258 (*info
->fprintf_func
) (info
->stream
, "@");
259 case 10: /* Byte displacement */
260 if (regnum
== PC_REGNUM
)
262 info
->target
= addr
+ *p
+ 2;
263 (*info
->print_address_func
) (info
->target
, info
);
266 (*info
->fprintf_func
) (info
->stream
, "%d(%s)", *p
, REGISTER_NAME (regnum
));
270 case 13: /* Word displacement deferred */
271 (*info
->fprintf_func
) (info
->stream
, "@");
272 case 12: /* Word displacement */
273 if (regnum
== PC_REGNUM
)
275 info
->target
= addr
+ *(short *)p
+ 3;
276 (*info
->print_address_func
) (info
->target
, info
);
279 (*info
->fprintf_func
) (info
->stream
, "%d(%s)",
280 *(short *)p
, REGISTER_NAME (regnum
));
284 case 15: /* Long displacement deferred */
285 (*info
->fprintf_func
) (info
->stream
, "@");
286 case 14: /* Long displacement */
287 if (regnum
== PC_REGNUM
)
289 info
->target
= addr
+ *(short *)p
+ 5;
290 (*info
->print_address_func
) (info
->target
, info
);
293 (*info
->fprintf_func
) (info
->stream
, "%d(%s)",
294 *(long *)p
, REGISTER_NAME (regnum
));
298 return (unsigned char *) p
;
302 _initialize_vax_tdep ()
304 tm_print_insn
= vax_print_insn
;