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 #include "arch-utils.h"
34 static gdbarch_register_name_ftype vax_register_name;
35 static gdbarch_register_byte_ftype vax_register_byte;
36 static gdbarch_register_raw_size_ftype vax_register_raw_size;
37 static gdbarch_register_virtual_size_ftype vax_register_virtual_size;
38 static gdbarch_register_virtual_type_ftype vax_register_virtual_type;
40 static gdbarch_skip_prologue_ftype vax_skip_prologue;
41 static gdbarch_saved_pc_after_call_ftype vax_saved_pc_after_call;
42 static gdbarch_frame_num_args_ftype vax_frame_num_args;
43 static gdbarch_frame_chain_ftype vax_frame_chain;
44 static gdbarch_frame_saved_pc_ftype vax_frame_saved_pc;
45 static gdbarch_frame_args_address_ftype vax_frame_args_address;
46 static gdbarch_frame_locals_address_ftype vax_frame_locals_address;
47 static gdbarch_frame_init_saved_regs_ftype vax_frame_init_saved_regs;
48 static gdbarch_get_saved_register_ftype vax_get_saved_register;
50 static gdbarch_store_struct_return_ftype vax_store_struct_return;
51 static gdbarch_deprecated_extract_return_value_ftype vax_extract_return_value;
52 static gdbarch_store_return_value_ftype vax_store_return_value;
53 static gdbarch_deprecated_extract_struct_value_address_ftype
54 vax_extract_struct_value_address;
56 static gdbarch_push_dummy_frame_ftype vax_push_dummy_frame;
57 static gdbarch_pop_frame_ftype vax_pop_frame;
58 static gdbarch_fix_call_dummy_ftype vax_fix_call_dummy;
60 /* Return 1 if P points to an invalid floating point value.
61 LEN is the length in bytes -- not relevant on the Vax. */
63 /* FIXME: cagney/2002-01-19: The macro below was originally defined in
64 tm-vax.h and used in values.c. Two problems. Firstly this is a
65 very non-portable and secondly it is wrong. The VAX should be
66 using floatformat and associated methods to identify and handle
67 invalid floating-point values. Adding to the poor target's woes
68 there is no floatformat_vax_{f,d} and no TARGET_FLOAT_FORMAT
71 /* FIXME: cagney/2002-01-19: It turns out that the only thing that
72 uses this macro is the vax disassembler code (so how old is this
73 target?). This target should instead be using the opcodes
74 disassembler. That allowing the macro to be eliminated. */
76 #define INVALID_FLOAT(p, len) ((*(short *) p & 0xff80) == 0x8000)
78 /* Vax instructions are never longer than this. */
81 /* Number of elements in the opcode table. */
82 #define NOPCODES (sizeof votstrs / sizeof votstrs[0])
84 static unsigned char *print_insn_arg ();
87 vax_register_name (int regno)
89 static char *register_names[] =
91 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
92 "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc",
98 if (regno >= (sizeof(register_names) / sizeof(*register_names)))
100 return (register_names[regno]);
104 vax_register_byte (int regno)
110 vax_register_raw_size (int regno)
116 vax_register_virtual_size (int regno)
122 vax_register_virtual_type (int regno)
124 return (builtin_type_int);
128 vax_get_saved_register (char *raw_buffer, int *optimized, CORE_ADDR *addrp,
129 struct frame_info *frame, int regnum,
130 enum lval_type *lval)
134 if (!target_has_registers)
135 error ("No registers.");
137 /* Normal systems don't optimize out things with register numbers. */
138 if (optimized != NULL)
140 addr = find_saved_register (frame, regnum);
145 if (regnum == SP_REGNUM)
147 if (raw_buffer != NULL)
149 /* Put it back in target format. */
150 store_address (raw_buffer, REGISTER_RAW_SIZE (regnum),
157 if (raw_buffer != NULL)
158 target_read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum));
163 *lval = lval_register;
164 addr = REGISTER_BYTE (regnum);
165 if (raw_buffer != NULL)
166 read_register_gen (regnum, raw_buffer);
173 vax_frame_init_saved_regs (struct frame_info *frame)
178 if (frame->saved_regs)
181 frame_saved_regs_zalloc (frame);
183 regmask = read_memory_integer (frame->frame + 4, 4) >> 16;
185 next_addr = frame->frame + 16;
187 /* regmask's low bit is for register 0, which is the first one
188 what would be pushed. */
189 for (regnum = 0; regnum < AP_REGNUM; regnum++)
191 if (regmask & (1 << regnum))
192 frame->saved_regs[regnum] = next_addr += 4;
195 frame->saved_regs[SP_REGNUM] = next_addr + 4;
196 if (regmask & (1 << FP_REGNUM))
197 frame->saved_regs[SP_REGNUM] +=
198 4 + (4 * read_memory_integer (next_addr + 4, 4));
200 frame->saved_regs[PC_REGNUM] = frame->frame + 16;
201 frame->saved_regs[FP_REGNUM] = frame->frame + 12;
202 frame->saved_regs[AP_REGNUM] = frame->frame + 8;
203 frame->saved_regs[PS_REGNUM] = frame->frame + 4;
207 vax_frame_saved_pc (struct frame_info *frame)
209 if (frame->signal_handler_caller)
210 return (sigtramp_saved_pc (frame)); /* XXXJRT */
212 return (read_memory_integer (frame->frame + 16, 4));
216 vax_frame_args_address_correct (struct frame_info *frame)
218 /* Cannot find the AP register value directly from the FP value. Must
219 find it saved in the frame called by this one, or in the AP register
220 for the innermost frame. However, there is no way to tell the
221 difference between the innermost frame and a frame for which we
222 just don't know the frame that it called (e.g. "info frame 0x7ffec789").
223 For the sake of argument, suppose that the stack is somewhat trashed
224 (which is one reason that "info frame" exists). So, return 0 (indicating
225 we don't know the address of the arglist) if we don't know what frame
228 return (read_memory_integer (frame->next->frame + 8, 4));
234 vax_frame_args_address (struct frame_info *frame)
236 /* In most of GDB, getting the args address is too important to
237 just say "I don't know". This is sometimes wrong for functions
238 that aren't on top of the stack, but c'est la vie. */
240 return (read_memory_integer (frame->next->frame + 8, 4));
242 return (read_register (AP_REGNUM));
246 vax_frame_locals_address (struct frame_info *frame)
248 return (frame->frame);
252 vax_frame_num_args (struct frame_info *fi)
254 return (0xff & read_memory_integer (FRAME_ARGS_ADDRESS (fi), 1));
258 vax_frame_chain (struct frame_info *frame)
260 /* In the case of the VAX, the frame's nominal address is the FP value,
261 and 12 bytes later comes the saved previous FP value as a 4-byte word. */
262 if (inside_entry_file (frame->pc))
265 return (read_memory_integer (frame->frame + 12, 4));
269 vax_push_dummy_frame (void)
271 CORE_ADDR sp = read_register (SP_REGNUM);
274 sp = push_word (sp, 0); /* arglist */
275 for (regnum = 11; regnum >= 0; regnum--)
276 sp = push_word (sp, read_register (regnum));
277 sp = push_word (sp, read_register (PC_REGNUM));
278 sp = push_word (sp, read_register (FP_REGNUM));
279 sp = push_word (sp, read_register (AP_REGNUM));
280 sp = push_word (sp, (read_register (PS_REGNUM) & 0xffef) + 0x2fff0000);
281 sp = push_word (sp, 0);
282 write_register (SP_REGNUM, sp);
283 write_register (FP_REGNUM, sp);
284 write_register (AP_REGNUM, sp + (17 * 4));
290 CORE_ADDR fp = read_register (FP_REGNUM);
292 int regmask = read_memory_integer (fp + 4, 4);
294 write_register (PS_REGNUM,
296 | (read_register (PS_REGNUM) & 0xffff0000));
297 write_register (PC_REGNUM, read_memory_integer (fp + 16, 4));
298 write_register (FP_REGNUM, read_memory_integer (fp + 12, 4));
299 write_register (AP_REGNUM, read_memory_integer (fp + 8, 4));
301 for (regnum = 0; regnum < 12; regnum++)
302 if (regmask & (0x10000 << regnum))
303 write_register (regnum, read_memory_integer (fp += 4, 4));
304 fp = fp + 4 + ((regmask >> 30) & 3);
305 if (regmask & 0x20000000)
307 regnum = read_memory_integer (fp, 4);
308 fp += (regnum + 1) * 4;
310 write_register (SP_REGNUM, fp);
311 flush_cached_frames ();
314 /* The VAX call dummy sequence:
316 calls #69, @#32323232
319 It is 8 bytes long. The address and argc are patched by
320 vax_fix_call_dummy(). */
321 static LONGEST vax_call_dummy_words[] = { 0x329f69fb, 0x03323232 };
322 static int sizeof_vax_call_dummy_words = sizeof(vax_call_dummy_words);
325 vax_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
326 struct value **args, struct type *type, int gcc_p)
329 store_unsigned_integer (dummy + 3, 4, fun);
333 vax_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
335 write_register (1, addr);
339 vax_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
341 memcpy (valbuf, regbuf + REGISTER_BYTE (0), TYPE_LENGTH (valtype));
345 vax_store_return_value (struct type *valtype, char *valbuf)
347 write_register_bytes (0, valbuf, TYPE_LENGTH (valtype));
351 vax_extract_struct_value_address (char *regbuf)
353 return (extract_address (regbuf + REGISTER_BYTE (0), REGISTER_RAW_SIZE (0)));
356 /* Advance PC across any function entry prologue instructions
357 to reach some "real" code. */
360 vax_skip_prologue (CORE_ADDR pc)
362 register int op = (unsigned char) read_memory_integer (pc, 1);
364 pc += 2; /* skip brb */
366 pc += 3; /* skip brw */
368 && ((unsigned char) read_memory_integer (pc + 2, 1)) == 0x5E)
369 pc += 3; /* skip subl2 */
371 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xAE
372 && ((unsigned char) read_memory_integer (pc + 3, 1)) == 0x5E)
373 pc += 4; /* skip movab */
375 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xCE
376 && ((unsigned char) read_memory_integer (pc + 4, 1)) == 0x5E)
377 pc += 5; /* skip movab */
379 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xEE
380 && ((unsigned char) read_memory_integer (pc + 6, 1)) == 0x5E)
381 pc += 7; /* skip movab */
386 vax_saved_pc_after_call (struct frame_info *frame)
388 return (FRAME_SAVED_PC(frame));
391 /* Print the vax instruction at address MEMADDR in debugged memory,
392 from disassembler info INFO.
393 Returns length of the instruction, in bytes. */
396 vax_print_insn (CORE_ADDR memaddr, disassemble_info *info)
398 unsigned char buffer[MAXLEN];
400 register unsigned char *p;
403 int status = (*info->read_memory_func) (memaddr, buffer, MAXLEN, info);
406 (*info->memory_error_func) (status, memaddr, info);
410 for (i = 0; i < NOPCODES; i++)
411 if (votstrs[i].detail.code == buffer[0]
412 || votstrs[i].detail.code == *(unsigned short *) buffer)
415 /* Handle undefined instructions. */
418 (*info->fprintf_func) (info->stream, "0%o", buffer[0]);
422 (*info->fprintf_func) (info->stream, "%s", votstrs[i].name);
424 /* Point at first byte of argument data,
425 and at descriptor for first argument. */
426 p = buffer + 1 + (votstrs[i].detail.code >= 0x100);
427 d = votstrs[i].detail.args;
430 (*info->fprintf_func) (info->stream, " ");
434 p = print_insn_arg (d, p, memaddr + (p - buffer), info);
437 (*info->fprintf_func) (info->stream, ",");
442 static unsigned char *
443 print_insn_arg (char *d, register char *p, CORE_ADDR addr,
444 disassemble_info *info)
446 register int regnum = *p & 0xf;
452 (*info->fprintf_func) (info->stream, "0x%x", addr + *p++ + 1);
455 (*info->fprintf_func) (info->stream, "0x%x", addr + *(short *) p + 2);
460 switch ((*p++ >> 4) & 0xf)
465 case 3: /* Literal mode */
466 if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
468 *(int *) &floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4);
469 (*info->fprintf_func) (info->stream, "$%f", floatlitbuf);
472 (*info->fprintf_func) (info->stream, "$%d", p[-1] & 0x3f);
475 case 4: /* Indexed */
476 p = (char *) print_insn_arg (d, p, addr + 1, info);
477 (*info->fprintf_func) (info->stream, "[%s]", REGISTER_NAME (regnum));
480 case 5: /* Register */
481 (*info->fprintf_func) (info->stream, REGISTER_NAME (regnum));
484 case 7: /* Autodecrement */
485 (*info->fprintf_func) (info->stream, "-");
486 case 6: /* Register deferred */
487 (*info->fprintf_func) (info->stream, "(%s)", REGISTER_NAME (regnum));
490 case 9: /* Autoincrement deferred */
491 (*info->fprintf_func) (info->stream, "@");
492 if (regnum == PC_REGNUM)
494 (*info->fprintf_func) (info->stream, "#");
495 info->target = *(long *) p;
496 (*info->print_address_func) (info->target, info);
500 case 8: /* Autoincrement */
501 if (regnum == PC_REGNUM)
503 (*info->fprintf_func) (info->stream, "#");
507 (*info->fprintf_func) (info->stream, "%d", *p++);
511 (*info->fprintf_func) (info->stream, "%d", *(short *) p);
516 (*info->fprintf_func) (info->stream, "%d", *(long *) p);
521 (*info->fprintf_func) (info->stream, "0x%x%08x",
522 ((long *) p)[1], ((long *) p)[0]);
527 (*info->fprintf_func) (info->stream, "0x%x%08x%08x%08x",
528 ((long *) p)[3], ((long *) p)[2],
529 ((long *) p)[1], ((long *) p)[0]);
534 if (INVALID_FLOAT (p, 4))
535 (*info->fprintf_func) (info->stream,
536 "<<invalid float 0x%x>>",
539 (*info->fprintf_func) (info->stream, "%f", *(float *) p);
544 if (INVALID_FLOAT (p, 8))
545 (*info->fprintf_func) (info->stream,
546 "<<invalid float 0x%x%08x>>",
547 ((long *) p)[1], ((long *) p)[0]);
549 (*info->fprintf_func) (info->stream, "%f", *(double *) p);
554 (*info->fprintf_func) (info->stream, "g-float");
559 (*info->fprintf_func) (info->stream, "h-float");
566 (*info->fprintf_func) (info->stream, "(%s)+", REGISTER_NAME (regnum));
569 case 11: /* Byte displacement deferred */
570 (*info->fprintf_func) (info->stream, "@");
571 case 10: /* Byte displacement */
572 if (regnum == PC_REGNUM)
574 info->target = addr + *p + 2;
575 (*info->print_address_func) (info->target, info);
578 (*info->fprintf_func) (info->stream, "%d(%s)", *p, REGISTER_NAME (regnum));
582 case 13: /* Word displacement deferred */
583 (*info->fprintf_func) (info->stream, "@");
584 case 12: /* Word displacement */
585 if (regnum == PC_REGNUM)
587 info->target = addr + *(short *) p + 3;
588 (*info->print_address_func) (info->target, info);
591 (*info->fprintf_func) (info->stream, "%d(%s)",
592 *(short *) p, REGISTER_NAME (regnum));
596 case 15: /* Long displacement deferred */
597 (*info->fprintf_func) (info->stream, "@");
598 case 14: /* Long displacement */
599 if (regnum == PC_REGNUM)
601 info->target = addr + *(short *) p + 5;
602 (*info->print_address_func) (info->target, info);
605 (*info->fprintf_func) (info->stream, "%d(%s)",
606 *(long *) p, REGISTER_NAME (regnum));
610 return (unsigned char *) p;
613 /* Initialize the current architecture based on INFO. If possible, re-use an
614 architecture from ARCHES, which is a list of architectures already created
615 during this debugging session.
617 Called e.g. at program startup, when reading a core file, and when reading
620 static struct gdbarch *
621 vax_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
623 struct gdbarch_tdep *tdep;
624 struct gdbarch *gdbarch;
625 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
627 /* Try to determine the ABI of the object we are loading. */
629 if (info.abfd != NULL)
630 osabi = gdbarch_lookup_osabi (info.abfd);
632 /* Find a candidate among extant architectures. */
633 for (arches = gdbarch_list_lookup_by_info (arches, &info);
635 arches = gdbarch_list_lookup_by_info (arches->next, &info))
637 /* Make sure the ABI selection matches. */
638 tdep = gdbarch_tdep (arches->gdbarch);
639 if (tdep && tdep->osabi == osabi)
640 return arches->gdbarch;
643 tdep = xmalloc (sizeof (struct gdbarch_tdep));
644 gdbarch = gdbarch_alloc (&info, tdep);
649 set_gdbarch_num_regs (gdbarch, VAX_NUM_REGS);
650 set_gdbarch_sp_regnum (gdbarch, VAX_SP_REGNUM);
651 set_gdbarch_fp_regnum (gdbarch, VAX_FP_REGNUM);
652 set_gdbarch_pc_regnum (gdbarch, VAX_PC_REGNUM);
653 set_gdbarch_ps_regnum (gdbarch, VAX_PS_REGNUM);
655 set_gdbarch_register_name (gdbarch, vax_register_name);
656 set_gdbarch_register_size (gdbarch, VAX_REGISTER_SIZE);
657 set_gdbarch_register_bytes (gdbarch, VAX_REGISTER_BYTES);
658 set_gdbarch_register_byte (gdbarch, vax_register_byte);
659 set_gdbarch_register_raw_size (gdbarch, vax_register_raw_size);
660 set_gdbarch_max_register_raw_size (gdbarch, VAX_MAX_REGISTER_RAW_SIZE);
661 set_gdbarch_register_virtual_size (gdbarch, vax_register_virtual_size);
662 set_gdbarch_max_register_virtual_size (gdbarch,
663 VAX_MAX_REGISTER_VIRTUAL_SIZE);
664 set_gdbarch_register_virtual_type (gdbarch, vax_register_virtual_type);
666 /* Frame and stack info */
667 set_gdbarch_skip_prologue (gdbarch, vax_skip_prologue);
668 set_gdbarch_saved_pc_after_call (gdbarch, vax_saved_pc_after_call);
670 set_gdbarch_frame_num_args (gdbarch, vax_frame_num_args);
671 set_gdbarch_frameless_function_invocation (gdbarch,
672 generic_frameless_function_invocation_not);
674 set_gdbarch_frame_chain (gdbarch, vax_frame_chain);
675 set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid);
676 set_gdbarch_frame_saved_pc (gdbarch, vax_frame_saved_pc);
678 set_gdbarch_frame_args_address (gdbarch, vax_frame_args_address);
679 set_gdbarch_frame_locals_address (gdbarch, vax_frame_locals_address);
681 set_gdbarch_frame_init_saved_regs (gdbarch, vax_frame_init_saved_regs);
683 set_gdbarch_frame_args_skip (gdbarch, 4);
685 set_gdbarch_get_saved_register (gdbarch, vax_get_saved_register);
687 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
689 /* Return value info */
690 set_gdbarch_store_struct_return (gdbarch, vax_store_struct_return);
691 set_gdbarch_deprecated_extract_return_value (gdbarch, vax_extract_return_value);
692 set_gdbarch_store_return_value (gdbarch, vax_store_return_value);
693 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, vax_extract_struct_value_address);
695 /* Call dummy info */
696 set_gdbarch_push_dummy_frame (gdbarch, vax_push_dummy_frame);
697 set_gdbarch_pop_frame (gdbarch, vax_pop_frame);
698 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
699 set_gdbarch_call_dummy_p (gdbarch, 1);
700 set_gdbarch_call_dummy_words (gdbarch, vax_call_dummy_words);
701 set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof_vax_call_dummy_words);
702 set_gdbarch_fix_call_dummy (gdbarch, vax_fix_call_dummy);
703 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
704 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
705 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 7);
706 set_gdbarch_use_generic_dummy_frames (gdbarch, 0);
707 set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_on_stack);
708 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
710 /* Breakpoint info */
711 set_gdbarch_decr_pc_after_break (gdbarch, 0);
714 set_gdbarch_function_start_offset (gdbarch, 2);
716 /* Hook in ABI-specific overrides, if they have been registered. */
717 gdbarch_init_osabi (info, gdbarch, osabi);
723 vax_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file)
725 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
730 fprintf_unfiltered (file, "vax_dump_tdep: OS ABI = %s\n",
731 gdbarch_osabi_name (tdep->osabi));
735 _initialize_vax_tdep (void)
737 gdbarch_register (bfd_arch_vax, vax_gdbarch_init, vax_dump_tdep);
739 tm_print_insn = vax_print_insn;