1 /* Print VAX instructions for GDB, the GNU debugger.
3 Copyright 1986, 1989, 1991, 1992, 1995, 1996, 1998, 1999, 2000,
4 2002, 2003, 2004 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "opcode/vax.h"
30 #include "frame-base.h"
31 #include "frame-unwind.h"
32 #include "trad-frame.h"
34 #include "arch-utils.h"
35 #include "gdb_string.h"
41 /* Return the name of register REGNUM. */
44 vax_register_name (int regnum)
46 static char *register_names[] =
48 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
49 "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc",
53 if (regnum >= 0 && regnum < ARRAY_SIZE (register_names))
54 return register_names[regnum];
59 /* Return the GDB type object for the "standard" data type of data in
63 vax_register_type (struct gdbarch *gdbarch, int regnum)
65 return builtin_type_int;
70 vax_push_dummy_frame (void)
72 CORE_ADDR sp = read_register (SP_REGNUM);
75 sp = push_word (sp, 0); /* arglist */
76 for (regnum = 11; regnum >= 0; regnum--)
77 sp = push_word (sp, read_register (regnum));
78 sp = push_word (sp, read_register (PC_REGNUM));
79 sp = push_word (sp, read_register (VAX_FP_REGNUM));
80 sp = push_word (sp, read_register (VAX_AP_REGNUM));
81 sp = push_word (sp, (read_register (PS_REGNUM) & 0xffef) + 0x2fff0000);
82 sp = push_word (sp, 0);
83 write_register (SP_REGNUM, sp);
84 write_register (VAX_FP_REGNUM, sp);
85 write_register (VAX_AP_REGNUM, sp + (17 * 4));
91 CORE_ADDR fp = read_register (VAX_FP_REGNUM);
93 int regmask = read_memory_integer (fp + 4, 4);
95 write_register (PS_REGNUM,
97 | (read_register (PS_REGNUM) & 0xffff0000));
98 write_register (PC_REGNUM, read_memory_integer (fp + 16, 4));
99 write_register (VAX_FP_REGNUM, read_memory_integer (fp + 12, 4));
100 write_register (VAX_AP_REGNUM, read_memory_integer (fp + 8, 4));
102 for (regnum = 0; regnum < 12; regnum++)
103 if (regmask & (0x10000 << regnum))
104 write_register (regnum, read_memory_integer (fp += 4, 4));
105 fp = fp + 4 + ((regmask >> 30) & 3);
106 if (regmask & 0x20000000)
108 regnum = read_memory_integer (fp, 4);
109 fp += (regnum + 1) * 4;
111 write_register (SP_REGNUM, fp);
112 flush_cached_frames ();
115 /* The VAX call dummy sequence:
117 calls #69, @#32323232
120 It is 8 bytes long. The address and argc are patched by
121 vax_fix_call_dummy(). */
122 static LONGEST vax_call_dummy_words[] = { 0x329f69fb, 0x03323232 };
123 static int sizeof_vax_call_dummy_words = sizeof(vax_call_dummy_words);
126 vax_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
127 struct value **args, struct type *type, int gcc_p)
130 store_unsigned_integer (dummy + 3, 4, fun);
134 vax_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
136 write_register (1, addr);
140 vax_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
142 memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (0), TYPE_LENGTH (valtype));
146 vax_store_return_value (struct type *valtype, char *valbuf)
148 deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (valtype));
152 /* Use the program counter to determine the contents and size of a
153 breakpoint instruction. Return a pointer to a string of bytes that
154 encode a breakpoint instruction, store the length of the string in
155 *LEN and optionally adjust *PC to point to the correct memory
156 location for inserting the breakpoint. */
158 static const unsigned char *
159 vax_breakpoint_from_pc (CORE_ADDR *pc, int *len)
161 static unsigned char break_insn[] = { 3 };
163 *len = sizeof (break_insn);
167 /* Advance PC across any function entry prologue instructions
168 to reach some "real" code. */
171 vax_skip_prologue (CORE_ADDR pc)
173 int op = (unsigned char) read_memory_integer (pc, 1);
175 pc += 2; /* skip brb */
177 pc += 3; /* skip brw */
179 && ((unsigned char) read_memory_integer (pc + 2, 1)) == 0x5E)
180 pc += 3; /* skip subl2 */
182 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xAE
183 && ((unsigned char) read_memory_integer (pc + 3, 1)) == 0x5E)
184 pc += 4; /* skip movab */
186 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xCE
187 && ((unsigned char) read_memory_integer (pc + 4, 1)) == 0x5E)
188 pc += 5; /* skip movab */
190 && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xEE
191 && ((unsigned char) read_memory_integer (pc + 6, 1)) == 0x5E)
192 pc += 7; /* skip movab */
197 /* Unwinding the stack is relatively easy since the VAX has a
198 dedicated frame pointer, and frames are set up automatically as the
199 result of a function call. Most of the relevant information can be
200 inferred from the documentation of the Procedure Call Instructions
201 in the VAX MACRO and Instruction Set Reference Manual. */
203 struct vax_frame_cache
208 /* Table of saved registers. */
209 struct trad_frame_saved_reg *saved_regs;
212 struct vax_frame_cache *
213 vax_frame_cache (struct frame_info *next_frame, void **this_cache)
215 struct vax_frame_cache *cache;
223 /* Allocate a new cache. */
224 cache = FRAME_OBSTACK_ZALLOC (struct vax_frame_cache);
225 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
227 /* The frame pointer is used as the base for the frame. */
228 cache->base = frame_unwind_register_unsigned (next_frame, VAX_FP_REGNUM);
229 if (cache->base == 0)
232 /* The register save mask and control bits determine the layout of
234 mask = get_frame_memory_unsigned (next_frame, cache->base + 4, 4) >> 16;
236 /* These are always saved. */
237 cache->saved_regs[VAX_PC_REGNUM].addr = cache->base + 16;
238 cache->saved_regs[VAX_FP_REGNUM].addr = cache->base + 12;
239 cache->saved_regs[VAX_AP_REGNUM].addr = cache->base + 8;
240 cache->saved_regs[VAX_PS_REGNUM].addr = cache->base + 4;
242 /* Scan the register save mask and record the location of the saved
244 addr = cache->base + 20;
245 for (regnum = 0; regnum < VAX_AP_REGNUM; regnum++)
247 if (mask & (1 << regnum))
249 cache->saved_regs[regnum].addr = addr;
254 /* The CALLS/CALLG flag determines whether this frame has a General
255 Argument List or a Stack Argument List. */
256 if (mask & (1 << 13))
260 /* This is a procedure with Stack Argument List. Adjust the
261 stack address for the arguments thet were pushed onto the
262 stack. The return instruction will automatically pop the
263 arguments from the stack. */
264 numarg = get_frame_memory_unsigned (next_frame, addr, 1);
265 addr += 4 + numarg * 4;
268 /* Bits 1:0 of the stack pointer were saved in the control bits. */
269 trad_frame_set_value (cache->saved_regs, VAX_SP_REGNUM, addr + (mask >> 14));
275 vax_frame_this_id (struct frame_info *next_frame, void **this_cache,
276 struct frame_id *this_id)
278 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
280 /* This marks the outermost frame. */
281 if (cache->base == 0)
284 (*this_id) = frame_id_build (cache->base, frame_pc_unwind (next_frame));
288 vax_frame_prev_register (struct frame_info *next_frame, void **this_cache,
289 int regnum, int *optimizedp,
290 enum lval_type *lvalp, CORE_ADDR *addrp,
291 int *realnump, void *valuep)
293 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
295 trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
296 optimizedp, lvalp, addrp, realnump, valuep);
299 static const struct frame_unwind vax_frame_unwind =
303 vax_frame_prev_register
306 static const struct frame_unwind *
307 vax_frame_sniffer (struct frame_info *next_frame)
309 return &vax_frame_unwind;
314 vax_frame_base_address (struct frame_info *next_frame, void **this_cache)
316 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
322 vax_frame_args_address (struct frame_info *next_frame, void **this_cache)
324 return frame_unwind_register_unsigned (next_frame, VAX_AP_REGNUM);
327 static const struct frame_base vax_frame_base =
330 vax_frame_base_address,
331 vax_frame_base_address,
332 vax_frame_args_address
335 /* Return number of arguments for FRAME. */
338 vax_frame_num_args (struct frame_info *frame)
342 /* Assume that the argument pointer for the outermost frame is
343 hosed, as is the case on NetBSD/vax ELF. */
344 if (get_frame_base (frame) == 0)
347 args = get_frame_register_unsigned (frame, VAX_AP_REGNUM);
348 return get_frame_memory_unsigned (frame, args, 1);
352 vax_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
354 return frame_unwind_register_unsigned (next_frame, VAX_PC_REGNUM);
358 /* Initialize the current architecture based on INFO. If possible, re-use an
359 architecture from ARCHES, which is a list of architectures already created
360 during this debugging session.
362 Called e.g. at program startup, when reading a core file, and when reading
365 static struct gdbarch *
366 vax_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
368 struct gdbarch *gdbarch;
370 /* If there is already a candidate, use it. */
371 arches = gdbarch_list_lookup_by_info (arches, &info);
373 return arches->gdbarch;
375 gdbarch = gdbarch_alloc (&info, NULL);
378 set_gdbarch_num_regs (gdbarch, VAX_NUM_REGS);
379 set_gdbarch_register_name (gdbarch, vax_register_name);
380 set_gdbarch_register_type (gdbarch, vax_register_type);
381 set_gdbarch_sp_regnum (gdbarch, VAX_SP_REGNUM);
382 set_gdbarch_pc_regnum (gdbarch, VAX_PC_REGNUM);
383 set_gdbarch_ps_regnum (gdbarch, VAX_PS_REGNUM);
385 /* Frame and stack info */
386 set_gdbarch_skip_prologue (gdbarch, vax_skip_prologue);
387 set_gdbarch_frame_num_args (gdbarch, vax_frame_num_args);
389 set_gdbarch_frame_args_skip (gdbarch, 4);
391 /* Stack grows downward. */
392 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
394 /* Return value info */
395 set_gdbarch_deprecated_store_struct_return (gdbarch, vax_store_struct_return);
396 set_gdbarch_deprecated_extract_return_value (gdbarch, vax_extract_return_value);
397 set_gdbarch_deprecated_store_return_value (gdbarch, vax_store_return_value);
399 /* Call dummy info */
400 set_gdbarch_deprecated_push_dummy_frame (gdbarch, vax_push_dummy_frame);
401 set_gdbarch_deprecated_pop_frame (gdbarch, vax_pop_frame);
402 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
403 set_gdbarch_deprecated_call_dummy_words (gdbarch, vax_call_dummy_words);
404 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, sizeof_vax_call_dummy_words);
405 set_gdbarch_deprecated_fix_call_dummy (gdbarch, vax_fix_call_dummy);
406 set_gdbarch_deprecated_call_dummy_breakpoint_offset (gdbarch, 7);
407 set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch, 0);
408 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_on_stack);
410 /* Breakpoint info */
411 set_gdbarch_breakpoint_from_pc (gdbarch, vax_breakpoint_from_pc);
414 set_gdbarch_function_start_offset (gdbarch, 2);
415 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
417 /* Should be using push_dummy_call. */
418 set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
420 set_gdbarch_unwind_pc (gdbarch, vax_unwind_pc);
422 frame_base_set_default (gdbarch, &vax_frame_base);
424 /* Hook in ABI-specific overrides, if they have been registered. */
425 gdbarch_init_osabi (info, gdbarch);
427 frame_unwind_append_sniffer (gdbarch, vax_frame_sniffer);
429 set_gdbarch_print_insn (gdbarch, print_insn_vax);
434 extern initialize_file_ftype _initialize_vax_tdep; /* -Wmissing-prototypes */
437 _initialize_vax_tdep (void)
439 gdbarch_register (bfd_arch_vax, vax_gdbarch_init, NULL);