1 /* Target-dependent code for the VAX.
3 Copyright (C) 1986, 1989, 1991, 1992, 1995, 1996, 1998, 1999, 2000, 2002,
4 2003, 2004, 2005, 2007, 2008, 2009 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 3 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, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
24 #include "floatformat.h"
26 #include "frame-base.h"
27 #include "frame-unwind.h"
33 #include "trad-frame.h"
36 #include "gdb_string.h"
40 /* Return the name of register REGNUM. */
43 vax_register_name (struct gdbarch
*gdbarch
, int regnum
)
45 static char *register_names
[] =
47 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
48 "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc",
52 if (regnum
>= 0 && regnum
< ARRAY_SIZE (register_names
))
53 return register_names
[regnum
];
58 /* Return the GDB type object for the "standard" data type of data in
62 vax_register_type (struct gdbarch
*gdbarch
, int regnum
)
64 return builtin_type (gdbarch
)->builtin_int
;
67 /* Core file support. */
69 /* Supply register REGNUM from the buffer specified by GREGS and LEN
70 in the general-purpose register set REGSET to register cache
71 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
74 vax_supply_gregset (const struct regset
*regset
, struct regcache
*regcache
,
75 int regnum
, const void *gregs
, size_t len
)
77 const gdb_byte
*regs
= gregs
;
80 for (i
= 0; i
< VAX_NUM_REGS
; i
++)
82 if (regnum
== i
|| regnum
== -1)
83 regcache_raw_supply (regcache
, i
, regs
+ i
* 4);
87 /* VAX register set. */
89 static struct regset vax_gregset
=
95 /* Return the appropriate register set for the core section identified
96 by SECT_NAME and SECT_SIZE. */
98 static const struct regset
*
99 vax_regset_from_core_section (struct gdbarch
*gdbarch
,
100 const char *sect_name
, size_t sect_size
)
102 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= VAX_NUM_REGS
* 4)
108 /* The VAX UNIX calling convention uses R1 to pass a structure return
109 value address instead of passing it as a first (hidden) argument as
110 the VMS calling convention suggests. */
113 vax_store_arguments (struct regcache
*regcache
, int nargs
,
114 struct value
**args
, CORE_ADDR sp
)
120 /* We create an argument list on the stack, and make the argument
123 /* Push arguments in reverse order. */
124 for (i
= nargs
- 1; i
>= 0; i
--)
126 int len
= TYPE_LENGTH (value_enclosing_type (args
[i
]));
128 sp
-= (len
+ 3) & ~3;
129 count
+= (len
+ 3) / 4;
130 write_memory (sp
, value_contents_all (args
[i
]), len
);
133 /* Push argument count. */
135 store_unsigned_integer (buf
, 4, count
);
136 write_memory (sp
, buf
, 4);
138 /* Update the argument pointer. */
139 store_unsigned_integer (buf
, 4, sp
);
140 regcache_cooked_write (regcache
, VAX_AP_REGNUM
, buf
);
146 vax_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
147 struct regcache
*regcache
, CORE_ADDR bp_addr
, int nargs
,
148 struct value
**args
, CORE_ADDR sp
, int struct_return
,
149 CORE_ADDR struct_addr
)
154 /* Set up the function arguments. */
155 sp
= vax_store_arguments (regcache
, nargs
, args
, sp
);
157 /* Store return value address. */
159 regcache_cooked_write_unsigned (regcache
, VAX_R1_REGNUM
, struct_addr
);
161 /* Store return address in the PC slot. */
163 store_unsigned_integer (buf
, 4, bp_addr
);
164 write_memory (sp
, buf
, 4);
166 /* Store the (fake) frame pointer in the FP slot. */
168 store_unsigned_integer (buf
, 4, fp
);
169 write_memory (sp
, buf
, 4);
171 /* Skip the AP slot. */
174 /* Store register save mask and control bits. */
176 store_unsigned_integer (buf
, 4, 0);
177 write_memory (sp
, buf
, 4);
179 /* Store condition handler. */
181 store_unsigned_integer (buf
, 4, 0);
182 write_memory (sp
, buf
, 4);
184 /* Update the stack pointer and frame pointer. */
185 store_unsigned_integer (buf
, 4, sp
);
186 regcache_cooked_write (regcache
, VAX_SP_REGNUM
, buf
);
187 regcache_cooked_write (regcache
, VAX_FP_REGNUM
, buf
);
189 /* Return the saved (fake) frame pointer. */
193 static struct frame_id
194 vax_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
198 fp
= get_frame_register_unsigned (this_frame
, VAX_FP_REGNUM
);
199 return frame_id_build (fp
, get_frame_pc (this_frame
));
203 static enum return_value_convention
204 vax_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
205 struct type
*type
, struct regcache
*regcache
,
206 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
208 int len
= TYPE_LENGTH (type
);
211 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
212 || TYPE_CODE (type
) == TYPE_CODE_UNION
213 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
215 /* The default on VAX is to return structures in static memory.
216 Consequently a function must return the address where we can
217 find the return value. */
223 regcache_raw_read_unsigned (regcache
, VAX_R0_REGNUM
, &addr
);
224 read_memory (addr
, readbuf
, len
);
227 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
232 /* Read the contents of R0 and (if necessary) R1. */
233 regcache_cooked_read (regcache
, VAX_R0_REGNUM
, buf
);
235 regcache_cooked_read (regcache
, VAX_R1_REGNUM
, buf
+ 4);
236 memcpy (readbuf
, buf
, len
);
240 /* Read the contents to R0 and (if necessary) R1. */
241 memcpy (buf
, writebuf
, len
);
242 regcache_cooked_write (regcache
, VAX_R0_REGNUM
, buf
);
244 regcache_cooked_write (regcache
, VAX_R1_REGNUM
, buf
+ 4);
247 return RETURN_VALUE_REGISTER_CONVENTION
;
251 /* Use the program counter to determine the contents and size of a
252 breakpoint instruction. Return a pointer to a string of bytes that
253 encode a breakpoint instruction, store the length of the string in
254 *LEN and optionally adjust *PC to point to the correct memory
255 location for inserting the breakpoint. */
257 static const gdb_byte
*
258 vax_breakpoint_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pc
, int *len
)
260 static gdb_byte break_insn
[] = { 3 };
262 *len
= sizeof (break_insn
);
266 /* Advance PC across any function entry prologue instructions
267 to reach some "real" code. */
270 vax_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
272 gdb_byte op
= read_memory_unsigned_integer (pc
, 1);
275 pc
+= 2; /* skip brb */
277 pc
+= 3; /* skip brw */
279 && (read_memory_unsigned_integer (pc
+ 2, 1)) == 0x5E)
280 pc
+= 3; /* skip subl2 */
282 && (read_memory_unsigned_integer (pc
+ 1, 1)) == 0xAE
283 && (read_memory_unsigned_integer (pc
+ 3, 1)) == 0x5E)
284 pc
+= 4; /* skip movab */
286 && (read_memory_unsigned_integer (pc
+ 1, 1)) == 0xCE
287 && (read_memory_unsigned_integer (pc
+ 4, 1)) == 0x5E)
288 pc
+= 5; /* skip movab */
290 && (read_memory_unsigned_integer (pc
+ 1, 1)) == 0xEE
291 && (read_memory_unsigned_integer (pc
+ 6, 1)) == 0x5E)
292 pc
+= 7; /* skip movab */
298 /* Unwinding the stack is relatively easy since the VAX has a
299 dedicated frame pointer, and frames are set up automatically as the
300 result of a function call. Most of the relevant information can be
301 inferred from the documentation of the Procedure Call Instructions
302 in the VAX MACRO and Instruction Set Reference Manual. */
304 struct vax_frame_cache
309 /* Table of saved registers. */
310 struct trad_frame_saved_reg
*saved_regs
;
313 static struct vax_frame_cache
*
314 vax_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
316 struct vax_frame_cache
*cache
;
324 /* Allocate a new cache. */
325 cache
= FRAME_OBSTACK_ZALLOC (struct vax_frame_cache
);
326 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
328 /* The frame pointer is used as the base for the frame. */
329 cache
->base
= get_frame_register_unsigned (this_frame
, VAX_FP_REGNUM
);
330 if (cache
->base
== 0)
333 /* The register save mask and control bits determine the layout of
335 mask
= get_frame_memory_unsigned (this_frame
, cache
->base
+ 4, 4) >> 16;
337 /* These are always saved. */
338 cache
->saved_regs
[VAX_PC_REGNUM
].addr
= cache
->base
+ 16;
339 cache
->saved_regs
[VAX_FP_REGNUM
].addr
= cache
->base
+ 12;
340 cache
->saved_regs
[VAX_AP_REGNUM
].addr
= cache
->base
+ 8;
341 cache
->saved_regs
[VAX_PS_REGNUM
].addr
= cache
->base
+ 4;
343 /* Scan the register save mask and record the location of the saved
345 addr
= cache
->base
+ 20;
346 for (regnum
= 0; regnum
< VAX_AP_REGNUM
; regnum
++)
348 if (mask
& (1 << regnum
))
350 cache
->saved_regs
[regnum
].addr
= addr
;
355 /* The CALLS/CALLG flag determines whether this frame has a General
356 Argument List or a Stack Argument List. */
357 if (mask
& (1 << 13))
361 /* This is a procedure with Stack Argument List. Adjust the
362 stack address for the arguments that were pushed onto the
363 stack. The return instruction will automatically pop the
364 arguments from the stack. */
365 numarg
= get_frame_memory_unsigned (this_frame
, addr
, 1);
366 addr
+= 4 + numarg
* 4;
369 /* Bits 1:0 of the stack pointer were saved in the control bits. */
370 trad_frame_set_value (cache
->saved_regs
, VAX_SP_REGNUM
, addr
+ (mask
>> 14));
376 vax_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
377 struct frame_id
*this_id
)
379 struct vax_frame_cache
*cache
= vax_frame_cache (this_frame
, this_cache
);
381 /* This marks the outermost frame. */
382 if (cache
->base
== 0)
385 (*this_id
) = frame_id_build (cache
->base
, get_frame_func (this_frame
));
388 static struct value
*
389 vax_frame_prev_register (struct frame_info
*this_frame
,
390 void **this_cache
, int regnum
)
392 struct vax_frame_cache
*cache
= vax_frame_cache (this_frame
, this_cache
);
394 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
, regnum
);
397 static const struct frame_unwind vax_frame_unwind
=
401 vax_frame_prev_register
,
403 default_frame_sniffer
408 vax_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
410 struct vax_frame_cache
*cache
= vax_frame_cache (this_frame
, this_cache
);
416 vax_frame_args_address (struct frame_info
*this_frame
, void **this_cache
)
418 return get_frame_register_unsigned (this_frame
, VAX_AP_REGNUM
);
421 static const struct frame_base vax_frame_base
=
424 vax_frame_base_address
,
425 vax_frame_base_address
,
426 vax_frame_args_address
429 /* Return number of arguments for FRAME. */
432 vax_frame_num_args (struct frame_info
*frame
)
436 /* Assume that the argument pointer for the outermost frame is
437 hosed, as is the case on NetBSD/vax ELF. */
438 if (get_frame_base_address (frame
) == 0)
441 args
= get_frame_register_unsigned (frame
, VAX_AP_REGNUM
);
442 return get_frame_memory_unsigned (frame
, args
, 1);
446 vax_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
448 return frame_unwind_register_unsigned (next_frame
, VAX_PC_REGNUM
);
452 /* Initialize the current architecture based on INFO. If possible, re-use an
453 architecture from ARCHES, which is a list of architectures already created
454 during this debugging session.
456 Called e.g. at program startup, when reading a core file, and when reading
459 static struct gdbarch
*
460 vax_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
462 struct gdbarch
*gdbarch
;
464 /* If there is already a candidate, use it. */
465 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
467 return arches
->gdbarch
;
469 gdbarch
= gdbarch_alloc (&info
, NULL
);
471 set_gdbarch_float_format (gdbarch
, floatformats_vax_f
);
472 set_gdbarch_double_format (gdbarch
, floatformats_vax_d
);
473 set_gdbarch_long_double_format (gdbarch
, floatformats_vax_d
);
474 set_gdbarch_long_double_bit (gdbarch
, 64);
477 set_gdbarch_num_regs (gdbarch
, VAX_NUM_REGS
);
478 set_gdbarch_register_name (gdbarch
, vax_register_name
);
479 set_gdbarch_register_type (gdbarch
, vax_register_type
);
480 set_gdbarch_sp_regnum (gdbarch
, VAX_SP_REGNUM
);
481 set_gdbarch_pc_regnum (gdbarch
, VAX_PC_REGNUM
);
482 set_gdbarch_ps_regnum (gdbarch
, VAX_PS_REGNUM
);
484 set_gdbarch_regset_from_core_section
485 (gdbarch
, vax_regset_from_core_section
);
487 /* Frame and stack info */
488 set_gdbarch_skip_prologue (gdbarch
, vax_skip_prologue
);
489 set_gdbarch_frame_num_args (gdbarch
, vax_frame_num_args
);
490 set_gdbarch_frame_args_skip (gdbarch
, 4);
492 /* Stack grows downward. */
493 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
495 /* Return value info */
496 set_gdbarch_return_value (gdbarch
, vax_return_value
);
498 /* Call dummy code. */
499 set_gdbarch_push_dummy_call (gdbarch
, vax_push_dummy_call
);
500 set_gdbarch_dummy_id (gdbarch
, vax_dummy_id
);
502 /* Breakpoint info */
503 set_gdbarch_breakpoint_from_pc (gdbarch
, vax_breakpoint_from_pc
);
506 set_gdbarch_deprecated_function_start_offset (gdbarch
, 2);
507 set_gdbarch_believe_pcc_promotion (gdbarch
, 1);
509 set_gdbarch_print_insn (gdbarch
, print_insn_vax
);
511 set_gdbarch_unwind_pc (gdbarch
, vax_unwind_pc
);
513 frame_base_set_default (gdbarch
, &vax_frame_base
);
515 /* Hook in ABI-specific overrides, if they have been registered. */
516 gdbarch_init_osabi (info
, gdbarch
);
518 frame_unwind_append_unwinder (gdbarch
, &vax_frame_unwind
);
523 /* Provide a prototype to silence -Wmissing-prototypes. */
524 void _initialize_vax_tdep (void);
527 _initialize_vax_tdep (void)
529 gdbarch_register (bfd_arch_vax
, vax_gdbarch_init
, NULL
);