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. */
20 #include "opcode/vax.h"
23 /* Local function prototypes */
25 print_insn_arg PARAMS ((const char *, unsigned char *, bfd_vma,
29 print_insn_mode PARAMS ((int, unsigned char *, bfd_vma, disassemble_info *));
31 static char *reg_names[] =
33 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
34 "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc"
37 /* Sign-extend an (unsigned char). */
39 #define COERCE_SIGNED_CHAR(ch) ((signed char)(ch))
41 #define COERCE_SIGNED_CHAR(ch) ((int)(((ch) ^ 0x80) & 0xFF) - 128)
44 /* Get a 1 byte signed integer. */
46 (p += 1, FETCH_DATA (info, p), \
47 COERCE_SIGNED_CHAR(p[-1]))
49 /* Get a 2 byte signed integer. */
50 #define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
52 (p += 2, FETCH_DATA (info, p), \
53 COERCE16 ((p[-1] << 8) + p[-2]))
55 /* Get a 4 byte signed integer. */
56 #define COERCE32(x) ((int) (((x) ^ 0x80000000) - 0x80000000))
58 (p += 4, FETCH_DATA (info, p), \
59 (COERCE32 ((((((p[-1] << 8) + p[-2]) << 8) + p[-3]) << 8) + p[-4])))
61 /* Maximum length of an instruction. */
68 /* Points to first byte not fetched. */
69 bfd_byte *max_fetched;
70 bfd_byte the_buffer[MAXLEN];
75 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
76 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
78 #define FETCH_DATA(info, addr) \
79 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
80 ? 1 : fetch_data ((info), (addr)))
83 fetch_data (info, addr)
84 struct disassemble_info *info;
88 struct private *priv = (struct private *) info->private_data;
89 bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
91 status = (*info->read_memory_func) (start,
93 addr - priv->max_fetched,
97 (*info->memory_error_func) (status, start, info);
98 longjmp (priv->bailout, 1);
101 priv->max_fetched = addr;
106 /* Print the vax instruction at address MEMADDR in debugged memory,
107 on INFO->STREAM. Returns length of the instruction, in bytes. */
110 print_insn_vax (memaddr, info)
112 disassemble_info *info;
114 const struct vot *votp;
115 const char *argp = NULL;
118 bfd_byte *buffer = priv.the_buffer;
120 info->private_data = (PTR) &priv;
121 priv.max_fetched = priv.the_buffer;
122 priv.insn_start = memaddr;
123 if (setjmp (priv.bailout) != 0)
129 FETCH_DATA (info, buffer + 2);
130 for (votp = &votstrs[0]; votp->name[0]; votp++)
132 register vax_opcodeT opcode = votp->detail.code;
134 /* 2 byte codes match 2 buffer pos. */
135 if ((bfd_byte) opcode == buffer[0]
136 && (opcode >> 8 == 0 || opcode >> 8 == buffer[1]))
138 argp = votp->detail.args;
144 /* Handle undefined instructions. */
145 (*info->fprintf_func) (info->stream, ".word 0x%x",
146 (buffer[0] << 8) + buffer[1]);
150 /* Point at first byte of argument data, and at descriptor for first
152 arg = buffer + ((votp->detail.code >> 8) ? 2 : 1);
154 /* Make sure we have it in mem */
155 FETCH_DATA (info, arg);
157 (*info->fprintf_func) (info->stream, "%s", votp->name);
159 (*info->fprintf_func) (info->stream, " ");
163 arg += print_insn_arg (argp, arg, memaddr + arg - buffer, info);
166 (*info->fprintf_func) (info->stream, ",");
172 /* Returns number of bytes "eaten" by the operand, or return -1 if an
173 invalid operand was found, or -2 if an opcode tabel error was
177 print_insn_arg (d, p0, addr, info)
180 bfd_vma addr; /* PC for this arg to be relative to */
181 disassemble_info *info;
185 /* check validity of addressing length */
188 case 'b' : arg_len = 1; break;
189 case 'd' : arg_len = 8; break;
190 case 'f' : arg_len = 4; break;
191 case 'g' : arg_len = 8; break;
192 case 'h' : arg_len = 16; break;
193 case 'l' : arg_len = 4; break;
194 case 'o' : arg_len = 16; break;
195 case 'w' : arg_len = 2; break;
196 case 'q' : arg_len = 8; break;
200 /* branches have no mode byte */
203 unsigned char *p = p0;
206 (*info->print_address_func) (addr + 1 + NEXTBYTE (p), info);
208 (*info->print_address_func) (addr + 2 + NEXTWORD (p), info);
213 return print_insn_mode (arg_len, p0, addr, info);
217 print_insn_mode (size, p0, addr, info)
220 bfd_vma addr; /* PC for this arg to be relative to */
221 disassemble_info *info;
223 unsigned char *p = p0;
224 unsigned char mode, reg;
226 /* fetch and interpret mode byte */
227 mode = (unsigned char) NEXTBYTE (p);
234 case 0x30: /* literal mode $number */
235 (*info->fprintf_func) (info->stream, "$0x%x", mode);
237 case 0x40: /* index: base-addr[Rn] */
238 p += print_insn_mode (size, p0 + 1, addr + 1, info);
239 (*info->fprintf_func) (info->stream, "[%s]", reg_names[reg]);
241 case 0x50: /* register: Rn */
242 (*info->fprintf_func) (info->stream, "%s", reg_names[reg]);
244 case 0x60: /* register deferred: (Rn) */
245 (*info->fprintf_func) (info->stream, "(%s)", reg_names[reg]);
247 case 0x70: /* autodecrement: -(Rn) */
248 (*info->fprintf_func) (info->stream, "-(%s)", reg_names[reg]);
250 case 0x80: /* autoincrement: (Rn)+ */
255 FETCH_DATA (info, p + size);
256 (*info->fprintf_func) (info->stream, "$0x");
257 for (i = 0; i < size; i++)
258 (*info->fprintf_func) (info->stream, "%02x", p[size - i - 1]);
262 (*info->fprintf_func) (info->stream, "(%s)+", reg_names[reg]);
264 case 0x90: /* autoincrement deferred: @(Rn)+ */
266 (*info->fprintf_func) (info->stream, "*0x%x", NEXTLONG (p));
268 (*info->fprintf_func) (info->stream, "@(%s)+", reg_names[reg]);
270 case 0xB0: /* displacement byte deferred: *displ(Rn) */
271 (*info->fprintf_func) (info->stream, "*");
272 case 0xA0: /* displacement byte: displ(Rn) */
274 (*info->print_address_func) (addr + 2 + NEXTBYTE (p), info);
276 (*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTBYTE (p),
279 case 0xD0: /* displacement word deferred: *displ(Rn) */
280 (*info->fprintf_func) (info->stream, "*");
281 case 0xC0: /* displacement word: displ(Rn) */
283 (*info->print_address_func) (addr + 3 + NEXTWORD (p), info);
285 (*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTWORD (p),
288 case 0xF0: /* displacement long deferred: *displ(Rn) */
289 (*info->fprintf_func) (info->stream, "*");
290 case 0xE0: /* displacement long: displ(Rn) */
292 (*info->print_address_func) (addr + 5 + NEXTLONG (p), info);
294 (*info->fprintf_func) (info->stream, "0x%x(%s)", NEXTLONG (p),