1 /* Print VAX instructions for GDB, the GNU debugger.
2 Copyright 1986, 1989, 1991, 1992, 1995, 1996, 1998, 1999, 2000, 2002
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "opcode/vax.h"
30 /* Return 1 if P points to an invalid floating point value.
31 LEN is the length in bytes -- not relevant on the Vax. */
33 /* FIXME: cagney/2002-01-19: The macro below was originally defined in
34 tm-vax.h and used in values.c. Two problems. Firstly this is a
35 very non-portable and secondly it is wrong. The VAX should be
36 using floatformat and associated methods to identify and handle
37 invalid floating-point values. Adding to the poor target's woes
38 there is no floatformat_vax_{f,d} and no TARGET_FLOAT_FORMAT
41 /* FIXME: cagney/2002-01-19: It turns out that the only thing that
42 uses this macro is the vax disassembler code (so how old is this
43 target?). This target should instead be using the opcodes
44 disassembler. That allowing the macro to be eliminated. */
46 #define INVALID_FLOAT(p, len) ((*(short *) p & 0xff80) == 0x8000)
48 /* Vax instructions are never longer than this. */
51 /* Number of elements in the opcode table. */
52 #define NOPCODES (sizeof votstrs / sizeof votstrs[0])
54 static unsigned char *print_insn_arg ();
57 vax_register_name (int regno)
59 static char *register_names[] =
61 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
62 "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc",
68 if (regno >= (sizeof(register_names) / sizeof(*register_names)))
70 return (register_names[regno]);
74 vax_register_byte (int regno)
80 vax_register_raw_size (int regno)
86 vax_register_virtual_size (int regno)
92 vax_register_virtual_type (int regno)
94 return (builtin_type_int);
98 vax_frame_init_saved_regs (struct frame_info *frame)
103 if (frame->saved_regs)
106 frame_saved_regs_zalloc (frame);
108 regmask = read_memory_integer (frame->frame + 4, 4) >> 16;
110 next_addr = frame->frame + 16;
112 /* regmask's low bit is for register 0, which is the first one
113 what would be pushed. */
114 for (regnum = 0; regnum < AP_REGNUM; regnum++)
116 if (regmask & (1 << regnum))
117 frame->saved_regs[regnum] = next_addr += 4;
120 frame->saved_regs[SP_REGNUM] = next_addr + 4;
121 if (regmask & (1 << FP_REGNUM))
122 frame->saved_regs[SP_REGNUM] +=
123 4 + (4 * read_memory_integer (next_addr + 4, 4));
125 frame->saved_regs[PC_REGNUM] = frame->frame + 16;
126 frame->saved_regs[FP_REGNUM] = frame->frame + 12;
127 frame->saved_regs[AP_REGNUM] = frame->frame + 8;
128 frame->saved_regs[PS_REGNUM] = frame->frame + 4;
132 vax_frame_saved_pc (struct frame_info *frame)
134 if (frame->signal_handler_caller)
135 return (sigtramp_saved_pc (frame)); /* XXXJRT */
137 return (read_memory_integer (frame->frame + 16, 4));
141 vax_frame_args_address_correct (struct frame_info *frame)
143 /* Cannot find the AP register value directly from the FP value. Must
144 find it saved in the frame called by this one, or in the AP register
145 for the innermost frame. However, there is no way to tell the
146 difference between the innermost frame and a frame for which we
147 just don't know the frame that it called (e.g. "info frame 0x7ffec789").
148 For the sake of argument, suppose that the stack is somewhat trashed
149 (which is one reason that "info frame" exists). So, return 0 (indicating
150 we don't know the address of the arglist) if we don't know what frame
153 return (read_memory_integer (frame->next->frame + 8, 4));
159 vax_frame_args_address (struct frame_info *frame)
161 /* In most of GDB, getting the args address is too important to
162 just say "I don't know". This is sometimes wrong for functions
163 that aren't on top of the stack, but c'est la vie. */
165 return (read_memory_integer (frame->next->frame + 8, 4));
167 return (read_register (AP_REGNUM));
171 vax_frame_locals_address (struct frame_info *frame)
173 return (frame->frame);
177 vax_frame_num_args (struct frame_info *fi)
179 return (0xff & read_memory_integer (FRAME_ARGS_ADDRESS (fi), 1));
183 vax_frame_chain (struct frame_info *frame)
185 /* In the case of the VAX, the frame's nominal address is the FP value,
186 and 12 bytes later comes the saved previous FP value as a 4-byte word. */
187 if (inside_entry_file (frame->pc))
190 return (read_memory_integer (frame->frame + 12, 4));
194 vax_push_dummy_frame (void)
196 CORE_ADDR sp = read_register (SP_REGNUM);
199 sp = push_word (sp, 0); /* arglist */
200 for (regnum = 11; regnum >= 0; regnum--)
201 sp = push_word (sp, read_register (regnum));
202 sp = push_word (sp, read_register (PC_REGNUM));
203 sp = push_word (sp, read_register (FP_REGNUM));
204 sp = push_word (sp, read_register (AP_REGNUM));
205 sp = push_word (sp, (read_register (PS_REGNUM) & 0xffef) + 0x2fff0000);
206 sp = push_word (sp, 0);
207 write_register (SP_REGNUM, sp);
208 write_register (FP_REGNUM, sp);
209 write_register (AP_REGNUM, sp + (17 * 4));
215 CORE_ADDR fp = read_register (FP_REGNUM);
217 int regmask = read_memory_integer (fp + 4, 4);
219 write_register (PS_REGNUM,
221 | (read_register (PS_REGNUM) & 0xffff0000));
222 write_register (PC_REGNUM, read_memory_integer (fp + 16, 4));
223 write_register (FP_REGNUM, read_memory_integer (fp + 12, 4));
224 write_register (AP_REGNUM, read_memory_integer (fp + 8, 4));
226 for (regnum = 0; regnum < 12; regnum++)
227 if (regmask & (0x10000 << regnum))
228 write_register (regnum, read_memory_integer (fp += 4, 4));
229 fp = fp + 4 + ((regmask >> 30) & 3);
230 if (regmask & 0x20000000)
232 regnum = read_memory_integer (fp, 4);
233 fp += (regnum + 1) * 4;
235 write_register (SP_REGNUM, fp);
236 flush_cached_frames ();
239 /* The VAX call dummy sequence:
241 calls #69, @#32323232
244 It is 8 bytes long. The address and argc are patched by
245 vax_fix_call_dummy(). */
246 LONGEST vax_call_dummy_words[] = { 0x329f69fb, 0x03323232 };
247 int sizeof_vax_call_dummy_words = sizeof(vax_call_dummy_words);
250 vax_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
251 struct value **args, struct type *type, int gcc_p)
254 store_unsigned_integer (dummy + 3, 4, fun);
258 vax_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
260 write_register (1, addr);
264 vax_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
266 memcpy (valbuf, regbuf + REGISTER_BYTE (0), TYPE_LENGTH (valtype));
270 vax_store_return_value (struct type *valtype, char *valbuf)
272 write_register_bytes (0, valbuf, TYPE_LENGTH (valtype));
276 vax_extract_struct_value_address (char *regbuf)
278 return (extract_address (regbuf + REGISTER_BYTE (0), REGISTER_RAW_SIZE (0)));
281 /* Advance PC across any function entry prologue instructions
282 to reach some "real" code. */
285 vax_skip_prologue (CORE_ADDR pc)
287 register int op = (unsigned char) read_memory_integer (pc, 1);
289 pc += 2; /* skip brb */
291 pc += 3; /* skip brw */
293 && ((unsigned char) read_memory_integer (pc + 2, 1)) == 0x5E)
294 pc += 3; /* skip subl2 */
296 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xAE
297 && ((unsigned char) read_memory_integer (pc + 3, 1)) == 0x5E)
298 pc += 4; /* skip movab */
300 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xCE
301 && ((unsigned char) read_memory_integer (pc + 4, 1)) == 0x5E)
302 pc += 5; /* skip movab */
304 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xEE
305 && ((unsigned char) read_memory_integer (pc + 6, 1)) == 0x5E)
306 pc += 7; /* skip movab */
311 vax_saved_pc_after_call (struct frame_info *frame)
313 return (FRAME_SAVED_PC(frame));
316 /* Print the vax instruction at address MEMADDR in debugged memory,
317 from disassembler info INFO.
318 Returns length of the instruction, in bytes. */
321 vax_print_insn (CORE_ADDR memaddr, disassemble_info *info)
323 unsigned char buffer[MAXLEN];
325 register unsigned char *p;
328 int status = (*info->read_memory_func) (memaddr, buffer, MAXLEN, info);
331 (*info->memory_error_func) (status, memaddr, info);
335 for (i = 0; i < NOPCODES; i++)
336 if (votstrs[i].detail.code == buffer[0]
337 || votstrs[i].detail.code == *(unsigned short *) buffer)
340 /* Handle undefined instructions. */
343 (*info->fprintf_func) (info->stream, "0%o", buffer[0]);
347 (*info->fprintf_func) (info->stream, "%s", votstrs[i].name);
349 /* Point at first byte of argument data,
350 and at descriptor for first argument. */
351 p = buffer + 1 + (votstrs[i].detail.code >= 0x100);
352 d = votstrs[i].detail.args;
355 (*info->fprintf_func) (info->stream, " ");
359 p = print_insn_arg (d, p, memaddr + (p - buffer), info);
362 (*info->fprintf_func) (info->stream, ",");
367 static unsigned char *
368 print_insn_arg (char *d, register char *p, CORE_ADDR addr,
369 disassemble_info *info)
371 register int regnum = *p & 0xf;
377 (*info->fprintf_func) (info->stream, "0x%x", addr + *p++ + 1);
380 (*info->fprintf_func) (info->stream, "0x%x", addr + *(short *) p + 2);
385 switch ((*p++ >> 4) & 0xf)
390 case 3: /* Literal mode */
391 if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
393 *(int *) &floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4);
394 (*info->fprintf_func) (info->stream, "$%f", floatlitbuf);
397 (*info->fprintf_func) (info->stream, "$%d", p[-1] & 0x3f);
400 case 4: /* Indexed */
401 p = (char *) print_insn_arg (d, p, addr + 1, info);
402 (*info->fprintf_func) (info->stream, "[%s]", REGISTER_NAME (regnum));
405 case 5: /* Register */
406 (*info->fprintf_func) (info->stream, REGISTER_NAME (regnum));
409 case 7: /* Autodecrement */
410 (*info->fprintf_func) (info->stream, "-");
411 case 6: /* Register deferred */
412 (*info->fprintf_func) (info->stream, "(%s)", REGISTER_NAME (regnum));
415 case 9: /* Autoincrement deferred */
416 (*info->fprintf_func) (info->stream, "@");
417 if (regnum == PC_REGNUM)
419 (*info->fprintf_func) (info->stream, "#");
420 info->target = *(long *) p;
421 (*info->print_address_func) (info->target, info);
425 case 8: /* Autoincrement */
426 if (regnum == PC_REGNUM)
428 (*info->fprintf_func) (info->stream, "#");
432 (*info->fprintf_func) (info->stream, "%d", *p++);
436 (*info->fprintf_func) (info->stream, "%d", *(short *) p);
441 (*info->fprintf_func) (info->stream, "%d", *(long *) p);
446 (*info->fprintf_func) (info->stream, "0x%x%08x",
447 ((long *) p)[1], ((long *) p)[0]);
452 (*info->fprintf_func) (info->stream, "0x%x%08x%08x%08x",
453 ((long *) p)[3], ((long *) p)[2],
454 ((long *) p)[1], ((long *) p)[0]);
459 if (INVALID_FLOAT (p, 4))
460 (*info->fprintf_func) (info->stream,
461 "<<invalid float 0x%x>>",
464 (*info->fprintf_func) (info->stream, "%f", *(float *) p);
469 if (INVALID_FLOAT (p, 8))
470 (*info->fprintf_func) (info->stream,
471 "<<invalid float 0x%x%08x>>",
472 ((long *) p)[1], ((long *) p)[0]);
474 (*info->fprintf_func) (info->stream, "%f", *(double *) p);
479 (*info->fprintf_func) (info->stream, "g-float");
484 (*info->fprintf_func) (info->stream, "h-float");
491 (*info->fprintf_func) (info->stream, "(%s)+", REGISTER_NAME (regnum));
494 case 11: /* Byte displacement deferred */
495 (*info->fprintf_func) (info->stream, "@");
496 case 10: /* Byte displacement */
497 if (regnum == PC_REGNUM)
499 info->target = addr + *p + 2;
500 (*info->print_address_func) (info->target, info);
503 (*info->fprintf_func) (info->stream, "%d(%s)", *p, REGISTER_NAME (regnum));
507 case 13: /* Word displacement deferred */
508 (*info->fprintf_func) (info->stream, "@");
509 case 12: /* Word displacement */
510 if (regnum == PC_REGNUM)
512 info->target = addr + *(short *) p + 3;
513 (*info->print_address_func) (info->target, info);
516 (*info->fprintf_func) (info->stream, "%d(%s)",
517 *(short *) p, REGISTER_NAME (regnum));
521 case 15: /* Long displacement deferred */
522 (*info->fprintf_func) (info->stream, "@");
523 case 14: /* Long displacement */
524 if (regnum == PC_REGNUM)
526 info->target = addr + *(short *) p + 5;
527 (*info->print_address_func) (info->target, info);
530 (*info->fprintf_func) (info->stream, "%d(%s)",
531 *(long *) p, REGISTER_NAME (regnum));
535 return (unsigned char *) p;
539 _initialize_vax_tdep (void)
541 tm_print_insn = vax_print_insn;