1 /* Print VAX instructions.
2 Copyright 1995, 1998, 2000, 2001, 2002, 2005
3 Free Software Foundation, Inc.
4 Contributed by Pauline Middelink <middelin@polyware.iaf.nl>
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. */
21 #include "opcode/vax.h"
24 /* Local function prototypes */
25 static int fetch_data
PARAMS ((struct disassemble_info
*, bfd_byte
*));
26 static int print_insn_arg
27 PARAMS ((const char *, unsigned char *, bfd_vma
, disassemble_info
*));
28 static int print_insn_mode
29 PARAMS ((const char *, int, unsigned char *, bfd_vma
, disassemble_info
*));
32 static char *reg_names
[] =
34 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
35 "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc"
38 /* Definitions for the function entry mask bits. */
39 static char *entry_mask_bit
[] =
41 /* Registers 0 and 1 shall not be saved, since they're used to pass back
42 a function's result to it's caller... */
44 /* Registers 2 .. 11 are normal registers. */
45 "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11",
46 /* Registers 12 and 13 are argument and frame pointer and must not
47 be saved by using the entry mask. */
49 /* Bits 14 and 15 control integer and decimal overflow. */
53 /* Sign-extend an (unsigned char). */
55 #define COERCE_SIGNED_CHAR(ch) ((signed char)(ch))
57 #define COERCE_SIGNED_CHAR(ch) ((int)(((ch) ^ 0x80) & 0xFF) - 128)
60 /* Get a 1 byte signed integer. */
62 (p += 1, FETCH_DATA (info, p), \
63 COERCE_SIGNED_CHAR(p[-1]))
65 /* Get a 2 byte signed integer. */
66 #define COERCE16(x) ((int) (((x) ^ 0x8000) - 0x8000))
68 (p += 2, FETCH_DATA (info, p), \
69 COERCE16 ((p[-1] << 8) + p[-2]))
71 /* Get a 4 byte signed integer. */
72 #define COERCE32(x) ((int) (((x) ^ 0x80000000) - 0x80000000))
74 (p += 4, FETCH_DATA (info, p), \
75 (COERCE32 ((((((p[-1] << 8) + p[-2]) << 8) + p[-3]) << 8) + p[-4])))
77 /* Maximum length of an instruction. */
84 /* Points to first byte not fetched. */
85 bfd_byte
*max_fetched
;
86 bfd_byte the_buffer
[MAXLEN
];
91 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
92 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
94 #define FETCH_DATA(info, addr) \
95 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
96 ? 1 : fetch_data ((info), (addr)))
99 fetch_data (info
, addr
)
100 struct disassemble_info
*info
;
104 struct private *priv
= (struct private *) info
->private_data
;
105 bfd_vma start
= priv
->insn_start
+ (priv
->max_fetched
- priv
->the_buffer
);
107 status
= (*info
->read_memory_func
) (start
,
109 addr
- priv
->max_fetched
,
113 (*info
->memory_error_func
) (status
, start
, info
);
114 longjmp (priv
->bailout
, 1);
117 priv
->max_fetched
= addr
;
122 /* Print the vax instruction at address MEMADDR in debugged memory,
123 on INFO->STREAM. Returns length of the instruction, in bytes. */
126 print_insn_vax (memaddr
, info
)
128 disassemble_info
*info
;
130 const struct vot
*votp
;
134 bfd_byte
*buffer
= priv
.the_buffer
;
136 info
->private_data
= (PTR
) &priv
;
137 priv
.max_fetched
= priv
.the_buffer
;
138 priv
.insn_start
= memaddr
;
140 if (setjmp (priv
.bailout
) != 0)
147 /* Check if the info buffer has more than one byte left since
148 the last opcode might be a single byte with no argument data. */
149 if (info
->buffer_length
- (memaddr
- info
->buffer_vma
) > 1)
151 FETCH_DATA (info
, buffer
+ 2);
155 FETCH_DATA (info
, buffer
+ 1);
159 /* Decode function entry mask. */
162 && (info
->symbols
[0]->flags
& BSF_FUNCTION
)
163 && memaddr
== bfd_asymbol_value (info
->symbols
[0]))
166 int register_mask
= buffer
[1] << 8 | buffer
[0];
168 (*info
->fprintf_func
) (info
->stream
, "Entry mask 0x%04x = <",
171 for (i
= 15; i
>= 0; i
--)
172 if (register_mask
& (1 << i
))
173 (*info
->fprintf_func
) (info
->stream
, " %s", entry_mask_bit
[i
]);
175 (*info
->fprintf_func
) (info
->stream
, " >");
180 for (votp
= &votstrs
[0]; votp
->name
[0]; votp
++)
182 register vax_opcodeT opcode
= votp
->detail
.code
;
184 /* 2 byte codes match 2 buffer pos. */
185 if ((bfd_byte
) opcode
== buffer
[0]
186 && (opcode
>> 8 == 0 || opcode
>> 8 == buffer
[1]))
188 argp
= votp
->detail
.args
;
194 /* Handle undefined instructions. */
195 (*info
->fprintf_func
) (info
->stream
, ".word 0x%x",
196 (buffer
[0] << 8) + buffer
[1]);
200 /* Point at first byte of argument data, and at descriptor for first
202 arg
= buffer
+ ((votp
->detail
.code
>> 8) ? 2 : 1);
204 /* Make sure we have it in mem */
205 FETCH_DATA (info
, arg
);
207 (*info
->fprintf_func
) (info
->stream
, "%s", votp
->name
);
209 (*info
->fprintf_func
) (info
->stream
, " ");
213 arg
+= print_insn_arg (argp
, arg
, memaddr
+ arg
- buffer
, info
);
216 (*info
->fprintf_func
) (info
->stream
, ",");
222 /* Returns number of bytes "eaten" by the operand, or return -1 if an
223 invalid operand was found, or -2 if an opcode tabel error was
227 print_insn_arg (d
, p0
, addr
, info
)
230 bfd_vma addr
; /* PC for this arg to be relative to */
231 disassemble_info
*info
;
235 /* check validity of addressing length */
238 case 'b' : arg_len
= 1; break;
239 case 'd' : arg_len
= 8; break;
240 case 'f' : arg_len
= 4; break;
241 case 'g' : arg_len
= 8; break;
242 case 'h' : arg_len
= 16; break;
243 case 'l' : arg_len
= 4; break;
244 case 'o' : arg_len
= 16; break;
245 case 'w' : arg_len
= 2; break;
246 case 'q' : arg_len
= 8; break;
250 /* branches have no mode byte */
253 unsigned char *p
= p0
;
256 (*info
->print_address_func
) (addr
+ 1 + NEXTBYTE (p
), info
);
258 (*info
->print_address_func
) (addr
+ 2 + NEXTWORD (p
), info
);
263 return print_insn_mode (d
, arg_len
, p0
, addr
, info
);
267 print_insn_mode (d
, size
, p0
, addr
, info
)
271 bfd_vma addr
; /* PC for this arg to be relative to */
272 disassemble_info
*info
;
274 unsigned char *p
= p0
;
275 unsigned char mode
, reg
;
277 /* fetch and interpret mode byte */
278 mode
= (unsigned char) NEXTBYTE (p
);
285 case 0x30: /* literal mode $number */
286 if (d
[1] == 'd' || d
[1] == 'f' || d
[1] == 'g' || d
[1] == 'h')
287 (*info
->fprintf_func
) (info
->stream
, "$0x%x [%c-float]", mode
, d
[1]);
289 (*info
->fprintf_func
) (info
->stream
, "$0x%x", mode
);
291 case 0x40: /* index: base-addr[Rn] */
292 p
+= print_insn_mode (d
, size
, p0
+ 1, addr
+ 1, info
);
293 (*info
->fprintf_func
) (info
->stream
, "[%s]", reg_names
[reg
]);
295 case 0x50: /* register: Rn */
296 (*info
->fprintf_func
) (info
->stream
, "%s", reg_names
[reg
]);
298 case 0x60: /* register deferred: (Rn) */
299 (*info
->fprintf_func
) (info
->stream
, "(%s)", reg_names
[reg
]);
301 case 0x70: /* autodecrement: -(Rn) */
302 (*info
->fprintf_func
) (info
->stream
, "-(%s)", reg_names
[reg
]);
304 case 0x80: /* autoincrement: (Rn)+ */
309 FETCH_DATA (info
, p
+ size
);
310 (*info
->fprintf_func
) (info
->stream
, "$0x");
311 if (d
[1] == 'd' || d
[1] == 'f' || d
[1] == 'g' || d
[1] == 'h')
315 float_word
= p
[0] | (p
[1] << 8);
316 if ((d
[1] == 'd' || d
[1] == 'f')
317 && (float_word
& 0xff80) == 0x8000)
319 (*info
->fprintf_func
) (info
->stream
, "[invalid %c-float]",
324 for (i
= 0; i
< size
; i
++)
325 (*info
->fprintf_func
) (info
->stream
, "%02x",
327 (*info
->fprintf_func
) (info
->stream
, " [%c-float]", d
[1]);
332 for (i
= 0; i
< size
; i
++)
333 (*info
->fprintf_func
) (info
->stream
, "%02x", p
[size
- i
- 1]);
338 (*info
->fprintf_func
) (info
->stream
, "(%s)+", reg_names
[reg
]);
340 case 0x90: /* autoincrement deferred: @(Rn)+ */
342 (*info
->fprintf_func
) (info
->stream
, "*0x%x", NEXTLONG (p
));
344 (*info
->fprintf_func
) (info
->stream
, "@(%s)+", reg_names
[reg
]);
346 case 0xB0: /* displacement byte deferred: *displ(Rn) */
347 (*info
->fprintf_func
) (info
->stream
, "*");
348 case 0xA0: /* displacement byte: displ(Rn) */
350 (*info
->print_address_func
) (addr
+ 2 + NEXTBYTE (p
), info
);
352 (*info
->fprintf_func
) (info
->stream
, "0x%x(%s)", NEXTBYTE (p
),
355 case 0xD0: /* displacement word deferred: *displ(Rn) */
356 (*info
->fprintf_func
) (info
->stream
, "*");
357 case 0xC0: /* displacement word: displ(Rn) */
359 (*info
->print_address_func
) (addr
+ 3 + NEXTWORD (p
), info
);
361 (*info
->fprintf_func
) (info
->stream
, "0x%x(%s)", NEXTWORD (p
),
364 case 0xF0: /* displacement long deferred: *displ(Rn) */
365 (*info
->fprintf_func
) (info
->stream
, "*");
366 case 0xE0: /* displacement long: displ(Rn) */
368 (*info
->print_address_func
) (addr
+ 5 + NEXTLONG (p
), info
);
370 (*info
->fprintf_func
) (info
->stream
, "0x%x(%s)", NEXTLONG (p
),
This page took 0.042762 seconds and 4 git commands to generate.