1 /* Print VAX instructions.
2 Copyright (C) 1995, 1998 Free Software Foundation, Inc.
3 Contributed by Pauline Middelink <middelin@polyware.iaf.nl>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #include "opcode/vax.h"
22 /* Local function prototypes */
24 print_insn_arg PARAMS ((const char *, unsigned char *, bfd_vma,
28 print_insn_mode PARAMS ((int, unsigned char *, bfd_vma, disassemble_info *));
30 static char *reg_names[] =
32 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
33 "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc"
36 /* Sign-extend an (unsigned char). */
38 #define COERCE_SIGNED_CHAR(ch) ((signed char)(ch))
40 #define COERCE_SIGNED_CHAR(ch) ((int)(((ch) ^ 0x80) & 0xFF) - 128)
43 /* Get a 1 byte signed integer. */
45 (p += 1, FETCH_DATA (info, p), \
46 COERCE_SIGNED_CHAR(p[-1]))
48 /* Get a 2 byte signed integer. */
49 #define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
51 (p += 2, FETCH_DATA (info, p), \
52 COERCE16 ((p[-1] << 8) + p[-2]))
54 /* Get a 4 byte signed integer. */
55 #define COERCE32(x) ((int) (((x) ^ 0x80000000) - 0x80000000))
57 (p += 4, FETCH_DATA (info, p), \
58 (COERCE32 ((((((p[-1] << 8) + p[-2]) << 8) + p[-3]) << 8) + p[-4])))
60 /* Maximum length of an instruction. */
67 /* Points to first byte not fetched. */
68 bfd_byte *max_fetched;
69 bfd_byte the_buffer[MAXLEN];
74 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
75 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
77 #define FETCH_DATA(info, addr) \
78 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
79 ? 1 : fetch_data ((info), (addr)))
82 fetch_data (info, addr)
83 struct disassemble_info *info;
87 struct private *priv = (struct private *) info->private_data;
88 bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
90 status = (*info->read_memory_func) (start,
92 addr - priv->max_fetched,
96 (*info->memory_error_func) (status, start, info);
97 longjmp (priv->bailout, 1);
100 priv->max_fetched = addr;
105 /* Print the vax instruction at address MEMADDR in debugged memory,
106 on INFO->STREAM. Returns length of the instruction, in bytes. */
109 print_insn_vax (memaddr, info)
111 disassemble_info *info;
113 const struct vot *votp;
114 const char *argp = NULL;
117 bfd_byte *buffer = priv.the_buffer;
119 info->private_data = (PTR) &priv;
120 priv.max_fetched = priv.the_buffer;
121 priv.insn_start = memaddr;
122 if (setjmp (priv.bailout) != 0)
128 FETCH_DATA (info, buffer + 2);
129 for (votp = &votstrs[0]; votp->name[0]; votp++)
131 register vax_opcodeT opcode = votp->detail.code;
133 /* 2 byte codes match 2 buffer pos. */
134 if ((bfd_byte) opcode == buffer[0]
135 && (opcode >> 8 == 0 || opcode >> 8 == buffer[1]))
137 argp = votp->detail.args;
143 /* Handle undefined instructions. */
144 (*info->fprintf_func) (info->stream, ".word 0x%x",
145 (buffer[0] << 8) + buffer[1]);
149 /* Point at first byte of argument data, and at descriptor for first
151 arg = buffer + ((votp->detail.code >> 8) ? 2 : 1);
153 /* Make sure we have it in mem */
154 FETCH_DATA (info, arg);
156 (*info->fprintf_func) (info->stream, "%s", votp->name);
158 (*info->fprintf_func) (info->stream, " ");
162 arg += print_insn_arg (argp, arg, memaddr + arg - buffer, info);
165 (*info->fprintf_func) (info->stream, ",");
171 /* Returns number of bytes "eaten" by the operand, or return -1 if an
172 invalid operand was found, or -2 if an opcode tabel error was
176 print_insn_arg (d, p0, addr, info)
179 bfd_vma addr; /* PC for this arg to be relative to */
180 disassemble_info *info;
184 /* check validity of addressing length */
187 case 'b' : arg_len = 1; break;
188 case 'd' : arg_len = 8; break;
189 case 'f' : arg_len = 4; break;
190 case 'g' : arg_len = 8; break;
191 case 'h' : arg_len = 16; break;
192 case 'l' : arg_len = 4; break;
193 case 'o' : arg_len = 16; break;
194 case 'w' : arg_len = 2; break;
195 case 'q' : arg_len = 8; break;
199 /* branches have no mode byte */
202 unsigned char *p = p0;
205 (*info->print_address_func) (addr + 1 + NEXTBYTE (p), info);
207 (*info->print_address_func) (addr + 2 + NEXTWORD (p), info);
212 return print_insn_mode (arg_len, p0, addr, info);
216 print_insn_mode (size, p0, addr, info)
219 bfd_vma addr; /* PC for this arg to be relative to */
220 disassemble_info *info;
222 unsigned char *p = p0;
223 unsigned char mode, reg;
225 /* fetch and interpret mode byte */
226 mode = (unsigned char) NEXTBYTE (p);
233 case 0x30: /* literal mode $number */
234 (*info->fprintf_func) (info->stream, "$0x%x", mode);
236 case 0x40: /* index: base-addr[Rn] */
237 p += print_insn_mode (size, p0 + 1, addr + 1, info);
238 (*info->fprintf_func) (info->stream, "[%s]", reg_names[reg]);
240 case 0x50: /* register: Rn */
241 (*info->fprintf_func) (info->stream, "%s", reg_names[reg]);
243 case 0x60: /* register deferred: (Rn) */
244 (*info->fprintf_func) (info->stream, "(%s)", reg_names[reg]);
246 case 0x70: /* autodecrement: -(Rn) */
247 (*info->fprintf_func) (info->stream, "-(%s)", reg_names[reg]);
249 case 0x80: /* autoincrement: (Rn)+ */
254 FETCH_DATA (info, p + size);
255 (*info->fprintf_func) (info->stream, "$0x");
256 for (i = 0; i < size; i++)
257 (*info->fprintf_func) (info->stream, "%02x", p[size - i - 1]);
261 (*info->fprintf_func) (info->stream, "(%s)+", reg_names[reg]);
263 case 0x90: /* autoincrement deferred: @(Rn)+ */
265 (*info->fprintf_func) (info->stream, "*0x%x", NEXTLONG (p));
267 (*info->fprintf_func) (info->stream, "@(%s)+", reg_names[reg]);
269 case 0xB0: /* displacement byte deferred: *displ(Rn) */
270 (*info->fprintf_func) (info->stream, "*");
271 case 0xA0: /* displacement byte: displ(Rn) */
273 (*info->print_address_func) (addr + 2 + NEXTBYTE (p), info);
275 (*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTBYTE (p),
278 case 0xD0: /* displacement word deferred: *displ(Rn) */
279 (*info->fprintf_func) (info->stream, "*");
280 case 0xC0: /* displacement word: displ(Rn) */
282 (*info->print_address_func) (addr + 3 + NEXTWORD (p), info);
284 (*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTWORD (p),
287 case 0xF0: /* displacement long deferred: *displ(Rn) */
288 (*info->fprintf_func) (info->stream, "*");
289 case 0xE0: /* displacement long: displ(Rn) */
291 (*info->print_address_func) (addr + 5 + NEXTLONG (p), info);
293 (*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTLONG (p),