New test for interpreter-exec command.
[deliverable/binutils-gdb.git] / gdb / vax-tdep.c
CommitLineData
0543f387 1/* Target-dependent code for the VAX.
464e0365
AC
2
3 Copyright 1986, 1989, 1991, 1992, 1995, 1996, 1998, 1999, 2000,
4754a64e 4 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b
JM
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. */
c906108c
SS
22
23#include "defs.h"
0543f387
MK
24#include "arch-utils.h"
25#include "dis-asm.h"
c11c3a98 26#include "frame.h"
7def7fef
MK
27#include "frame-base.h"
28#include "frame-unwind.h"
0543f387
MK
29#include "gdbcore.h"
30#include "gdbtypes.h"
4be87837 31#include "osabi.h"
0543f387 32#include "regcache.h"
8b910bab 33#include "regset.h"
0543f387
MK
34#include "trad-frame.h"
35#include "value.h"
8b910bab
MK
36
37#include "gdb_string.h"
f267bd6a
JT
38
39#include "vax-tdep.h"
40
5e6b39ff
MK
41/* Return the name of register REGNUM. */
42
fa88f677 43static const char *
5e6b39ff 44vax_register_name (int regnum)
51eb8b08
JT
45{
46 static char *register_names[] =
47 {
5e6b39ff
MK
48 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
49 "r8", "r9", "r10", "r11", "ap", "fp", "sp", "pc",
51eb8b08
JT
50 "ps",
51 };
52
5e6b39ff
MK
53 if (regnum >= 0 && regnum < ARRAY_SIZE (register_names))
54 return register_names[regnum];
51eb8b08 55
5e6b39ff 56 return NULL;
51eb8b08
JT
57}
58
5e6b39ff
MK
59/* Return the GDB type object for the "standard" data type of data in
60 register REGNUM. */
51eb8b08 61
f267bd6a 62static struct type *
5e6b39ff 63vax_register_type (struct gdbarch *gdbarch, int regnum)
51eb8b08 64{
5e6b39ff 65 return builtin_type_int;
51eb8b08
JT
66}
67\f
8b910bab
MK
68/* Core file support. */
69
70/* Supply register REGNUM from the buffer specified by GREGS and LEN
71 in the general-purpose register set REGSET to register cache
72 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
73
74static void
75vax_supply_gregset (const struct regset *regset, struct regcache *regcache,
76 int regnum, const void *gregs, size_t len)
77{
78 const char *regs = gregs;
79 int i;
80
81 for (i = 0; i < VAX_NUM_REGS; i++)
82 {
83 if (regnum == i || regnum == -1)
84 regcache_raw_supply (regcache, i, regs + i * 4);
85 }
86}
52efde73 87
8b910bab
MK
88/* VAX register set. */
89
90static struct regset vax_gregset =
91{
92 NULL,
93 vax_supply_gregset
94};
95
96/* Return the appropriate register set for the core section identified
97 by SECT_NAME and SECT_SIZE. */
98
99static const struct regset *
100vax_regset_from_core_section (struct gdbarch *gdbarch,
101 const char *sect_name, size_t sect_size)
102{
103 if (strcmp (sect_name, ".reg") == 0 && sect_size >= VAX_NUM_REGS * 4)
104 return &vax_gregset;
105
106 return NULL;
107}
108\f
4cd80476 109/* The VAX UNIX calling convention uses R1 to pass a structure return
67b441e1
MK
110 value address instead of passing it as a first (hidden) argument as
111 the VMS calling convention suggests. */
112
7346c184
MK
113static CORE_ADDR
114vax_store_arguments (struct regcache *regcache, int nargs,
67b441e1 115 struct value **args, CORE_ADDR sp)
52efde73 116{
7346c184
MK
117 char buf[4];
118 int count = 0;
119 int i;
52efde73 120
7346c184
MK
121 /* We create an argument list on the stack, and make the argument
122 pointer to it. */
52efde73 123
7346c184
MK
124 /* Push arguments in reverse order. */
125 for (i = nargs - 1; i >= 0; i--)
52efde73 126 {
4754a64e 127 int len = TYPE_LENGTH (value_enclosing_type (args[i]));
7346c184
MK
128
129 sp -= (len + 3) & ~3;
130 count += (len + 3) / 4;
131 write_memory (sp, VALUE_CONTENTS_ALL (args[i]), len);
52efde73 132 }
a33f7558 133
7346c184
MK
134 /* Push argument count. */
135 sp -= 4;
136 store_unsigned_integer (buf, 4, count);
137 write_memory (sp, buf, 4);
a33f7558 138
7346c184
MK
139 /* Update the argument pointer. */
140 store_unsigned_integer (buf, 4, sp);
141 regcache_cooked_write (regcache, VAX_AP_REGNUM, buf);
a33f7558 142
7346c184
MK
143 return sp;
144}
145
146static CORE_ADDR
7d9b040b 147vax_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
7346c184
MK
148 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
149 struct value **args, CORE_ADDR sp, int struct_return,
150 CORE_ADDR struct_addr)
151{
152 CORE_ADDR fp = sp;
153 char buf[4];
154
155 /* Set up the function arguments. */
67b441e1
MK
156 sp = vax_store_arguments (regcache, nargs, args, sp);
157
158 /* Store return value address. */
159 if (struct_return)
160 regcache_cooked_write_unsigned (regcache, VAX_R1_REGNUM, struct_addr);
7346c184
MK
161
162 /* Store return address in the PC slot. */
163 sp -= 4;
164 store_unsigned_integer (buf, 4, bp_addr);
165 write_memory (sp, buf, 4);
166
167 /* Store the (fake) frame pointer in the FP slot. */
168 sp -= 4;
169 store_unsigned_integer (buf, 4, fp);
170 write_memory (sp, buf, 4);
171
172 /* Skip the AP slot. */
173 sp -= 4;
174
175 /* Store register save mask and control bits. */
176 sp -= 4;
177 store_unsigned_integer (buf, 4, 0);
178 write_memory (sp, buf, 4);
179
180 /* Store condition handler. */
181 sp -= 4;
182 store_unsigned_integer (buf, 4, 0);
183 write_memory (sp, buf, 4);
184
185 /* Update the stack pointer and frame pointer. */
186 store_unsigned_integer (buf, 4, sp);
187 regcache_cooked_write (regcache, VAX_SP_REGNUM, buf);
188 regcache_cooked_write (regcache, VAX_FP_REGNUM, buf);
189
190 /* Return the saved (fake) frame pointer. */
191 return fp;
192}
193
194static struct frame_id
195vax_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
a33f7558 196{
7346c184
MK
197 CORE_ADDR fp;
198
199 fp = frame_unwind_register_unsigned (next_frame, VAX_FP_REGNUM);
200 return frame_id_build (fp, frame_pc_unwind (next_frame));
a33f7558 201}
ab62c900 202\f
7346c184 203
67b441e1
MK
204static enum return_value_convention
205vax_return_value (struct gdbarch *gdbarch, struct type *type,
206 struct regcache *regcache, void *readbuf,
207 const void *writebuf)
ea74468c 208{
67b441e1
MK
209 int len = TYPE_LENGTH (type);
210 char buf[8];
ea74468c 211
67b441e1 212 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
caed1a45 213 || TYPE_CODE (type) == TYPE_CODE_UNION
67b441e1 214 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
e5483145
MK
215 {
216 /* The default on VAX is to return structures in static memory.
217 Consequently a function must return the address where we can
218 find the return value. */
219
220 if (readbuf)
221 {
222 ULONGEST addr;
223
224 regcache_raw_read_unsigned (regcache, VAX_R0_REGNUM, &addr);
225 read_memory (addr, readbuf, len);
226 }
227
228 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
229 }
ea74468c 230
67b441e1
MK
231 if (readbuf)
232 {
233 /* Read the contents of R0 and (if necessary) R1. */
234 regcache_cooked_read (regcache, VAX_R0_REGNUM, buf);
235 if (len > 4)
236 regcache_cooked_read (regcache, VAX_R1_REGNUM, buf + 4);
237 memcpy (readbuf, buf, len);
238 }
239 if (writebuf)
240 {
241 /* Read the contents to R0 and (if necessary) R1. */
242 memcpy (buf, writebuf, len);
243 regcache_cooked_write (regcache, VAX_R0_REGNUM, buf);
244 if (len > 4)
245 regcache_cooked_write (regcache, VAX_R1_REGNUM, buf + 4);
246 }
247
248 return RETURN_VALUE_REGISTER_CONVENTION;
ea74468c 249}
ea74468c 250\f
5e6b39ff
MK
251
252/* Use the program counter to determine the contents and size of a
253 breakpoint instruction. Return a pointer to a string of bytes that
254 encode a breakpoint instruction, store the length of the string in
255 *LEN and optionally adjust *PC to point to the correct memory
256 location for inserting the breakpoint. */
257
1d049c5e 258static const unsigned char *
5e6b39ff 259vax_breakpoint_from_pc (CORE_ADDR *pc, int *len)
1d049c5e 260{
5e6b39ff 261 static unsigned char break_insn[] = { 3 };
1d049c5e 262
5e6b39ff
MK
263 *len = sizeof (break_insn);
264 return break_insn;
1d049c5e
JT
265}
266\f
b83266a0
SS
267/* Advance PC across any function entry prologue instructions
268 to reach some "real" code. */
269
f267bd6a 270static CORE_ADDR
fba45db2 271vax_skip_prologue (CORE_ADDR pc)
b83266a0 272{
0543f387
MK
273 unsigned char op = read_memory_unsigned_integer (pc, 1);
274
b83266a0 275 if (op == 0x11)
c5aa993b 276 pc += 2; /* skip brb */
b83266a0 277 if (op == 0x31)
c5aa993b 278 pc += 3; /* skip brw */
b83266a0 279 if (op == 0xC2
0543f387 280 && (read_memory_unsigned_integer (pc + 2, 1)) == 0x5E)
c5aa993b 281 pc += 3; /* skip subl2 */
b83266a0 282 if (op == 0x9E
0543f387
MK
283 && (read_memory_unsigned_integer (pc + 1, 1)) == 0xAE
284 && (read_memory_unsigned_integer (pc + 3, 1)) == 0x5E)
c5aa993b 285 pc += 4; /* skip movab */
b83266a0 286 if (op == 0x9E
0543f387
MK
287 && (read_memory_unsigned_integer (pc + 1, 1)) == 0xCE
288 && (read_memory_unsigned_integer (pc + 4, 1)) == 0x5E)
c5aa993b 289 pc += 5; /* skip movab */
b83266a0 290 if (op == 0x9E
0543f387
MK
291 && (read_memory_unsigned_integer (pc + 1, 1)) == 0xEE
292 && (read_memory_unsigned_integer (pc + 6, 1)) == 0x5E)
c5aa993b 293 pc += 7; /* skip movab */
0543f387 294
b83266a0
SS
295 return pc;
296}
7def7fef
MK
297\f
298
299/* Unwinding the stack is relatively easy since the VAX has a
300 dedicated frame pointer, and frames are set up automatically as the
301 result of a function call. Most of the relevant information can be
302 inferred from the documentation of the Procedure Call Instructions
303 in the VAX MACRO and Instruction Set Reference Manual. */
304
305struct vax_frame_cache
306{
307 /* Base address. */
308 CORE_ADDR base;
309
310 /* Table of saved registers. */
311 struct trad_frame_saved_reg *saved_regs;
312};
313
314struct vax_frame_cache *
315vax_frame_cache (struct frame_info *next_frame, void **this_cache)
316{
317 struct vax_frame_cache *cache;
318 CORE_ADDR addr;
319 ULONGEST mask;
320 int regnum;
321
322 if (*this_cache)
323 return *this_cache;
324
325 /* Allocate a new cache. */
326 cache = FRAME_OBSTACK_ZALLOC (struct vax_frame_cache);
327 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
328
329 /* The frame pointer is used as the base for the frame. */
330 cache->base = frame_unwind_register_unsigned (next_frame, VAX_FP_REGNUM);
331 if (cache->base == 0)
332 return cache;
333
334 /* The register save mask and control bits determine the layout of
335 the stack frame. */
336 mask = get_frame_memory_unsigned (next_frame, cache->base + 4, 4) >> 16;
337
338 /* These are always saved. */
339 cache->saved_regs[VAX_PC_REGNUM].addr = cache->base + 16;
340 cache->saved_regs[VAX_FP_REGNUM].addr = cache->base + 12;
341 cache->saved_regs[VAX_AP_REGNUM].addr = cache->base + 8;
342 cache->saved_regs[VAX_PS_REGNUM].addr = cache->base + 4;
343
344 /* Scan the register save mask and record the location of the saved
345 registers. */
346 addr = cache->base + 20;
347 for (regnum = 0; regnum < VAX_AP_REGNUM; regnum++)
348 {
349 if (mask & (1 << regnum))
350 {
351 cache->saved_regs[regnum].addr = addr;
352 addr += 4;
353 }
354 }
355
356 /* The CALLS/CALLG flag determines whether this frame has a General
357 Argument List or a Stack Argument List. */
358 if (mask & (1 << 13))
359 {
360 ULONGEST numarg;
361
362 /* This is a procedure with Stack Argument List. Adjust the
e36ad527 363 stack address for the arguments that were pushed onto the
7def7fef
MK
364 stack. The return instruction will automatically pop the
365 arguments from the stack. */
366 numarg = get_frame_memory_unsigned (next_frame, addr, 1);
367 addr += 4 + numarg * 4;
368 }
369
370 /* Bits 1:0 of the stack pointer were saved in the control bits. */
371 trad_frame_set_value (cache->saved_regs, VAX_SP_REGNUM, addr + (mask >> 14));
372
373 return cache;
374}
375
376static void
377vax_frame_this_id (struct frame_info *next_frame, void **this_cache,
378 struct frame_id *this_id)
379{
380 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
381
382 /* This marks the outermost frame. */
383 if (cache->base == 0)
384 return;
385
17777823 386 (*this_id) = frame_id_build (cache->base, frame_func_unwind (next_frame));
7def7fef
MK
387}
388
389static void
390vax_frame_prev_register (struct frame_info *next_frame, void **this_cache,
391 int regnum, int *optimizedp,
392 enum lval_type *lvalp, CORE_ADDR *addrp,
393 int *realnump, void *valuep)
394{
395 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
396
1f67027d
AC
397 trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum,
398 optimizedp, lvalp, addrp, realnump, valuep);
7def7fef
MK
399}
400
401static const struct frame_unwind vax_frame_unwind =
402{
403 NORMAL_FRAME,
404 vax_frame_this_id,
405 vax_frame_prev_register
406};
407
408static const struct frame_unwind *
409vax_frame_sniffer (struct frame_info *next_frame)
410{
411 return &vax_frame_unwind;
412}
413\f
414
415static CORE_ADDR
416vax_frame_base_address (struct frame_info *next_frame, void **this_cache)
417{
418 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
419
420 return cache->base;
421}
b83266a0 422
f267bd6a 423static CORE_ADDR
7def7fef
MK
424vax_frame_args_address (struct frame_info *next_frame, void **this_cache)
425{
426 return frame_unwind_register_unsigned (next_frame, VAX_AP_REGNUM);
427}
428
429static const struct frame_base vax_frame_base =
a33f7558 430{
7def7fef
MK
431 &vax_frame_unwind,
432 vax_frame_base_address,
433 vax_frame_base_address,
434 vax_frame_args_address
435};
436
437/* Return number of arguments for FRAME. */
438
439static int
440vax_frame_num_args (struct frame_info *frame)
441{
442 CORE_ADDR args;
443
444 /* Assume that the argument pointer for the outermost frame is
445 hosed, as is the case on NetBSD/vax ELF. */
a54f9a00 446 if (get_frame_base_address (frame) == 0)
7def7fef
MK
447 return 0;
448
449 args = get_frame_register_unsigned (frame, VAX_AP_REGNUM);
450 return get_frame_memory_unsigned (frame, args, 1);
451}
452
453static CORE_ADDR
454vax_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
455{
456 return frame_unwind_register_unsigned (next_frame, VAX_PC_REGNUM);
a33f7558
JT
457}
458\f
7def7fef 459
f267bd6a
JT
460/* Initialize the current architecture based on INFO. If possible, re-use an
461 architecture from ARCHES, which is a list of architectures already created
462 during this debugging session.
463
464 Called e.g. at program startup, when reading a core file, and when reading
465 a binary file. */
466
467static struct gdbarch *
468vax_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
469{
470 struct gdbarch *gdbarch;
471
4be87837
DJ
472 /* If there is already a candidate, use it. */
473 arches = gdbarch_list_lookup_by_info (arches, &info);
474 if (arches != NULL)
475 return arches->gdbarch;
f267bd6a 476
4be87837 477 gdbarch = gdbarch_alloc (&info, NULL);
4791e091 478
f267bd6a
JT
479 /* Register info */
480 set_gdbarch_num_regs (gdbarch, VAX_NUM_REGS);
5e6b39ff
MK
481 set_gdbarch_register_name (gdbarch, vax_register_name);
482 set_gdbarch_register_type (gdbarch, vax_register_type);
f267bd6a 483 set_gdbarch_sp_regnum (gdbarch, VAX_SP_REGNUM);
f267bd6a
JT
484 set_gdbarch_pc_regnum (gdbarch, VAX_PC_REGNUM);
485 set_gdbarch_ps_regnum (gdbarch, VAX_PS_REGNUM);
486
8b910bab
MK
487 set_gdbarch_regset_from_core_section
488 (gdbarch, vax_regset_from_core_section);
489
f267bd6a
JT
490 /* Frame and stack info */
491 set_gdbarch_skip_prologue (gdbarch, vax_skip_prologue);
f267bd6a 492 set_gdbarch_frame_num_args (gdbarch, vax_frame_num_args);
f267bd6a
JT
493 set_gdbarch_frame_args_skip (gdbarch, 4);
494
5e6b39ff 495 /* Stack grows downward. */
f267bd6a
JT
496 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
497
498 /* Return value info */
67b441e1 499 set_gdbarch_return_value (gdbarch, vax_return_value);
f267bd6a 500
7346c184
MK
501 /* Call dummy code. */
502 set_gdbarch_push_dummy_call (gdbarch, vax_push_dummy_call);
503 set_gdbarch_unwind_dummy_id (gdbarch, vax_unwind_dummy_id);
f267bd6a
JT
504
505 /* Breakpoint info */
1d049c5e 506 set_gdbarch_breakpoint_from_pc (gdbarch, vax_breakpoint_from_pc);
f267bd6a
JT
507
508 /* Misc info */
782263ab 509 set_gdbarch_deprecated_function_start_offset (gdbarch, 2);
1d049c5e 510 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
f267bd6a 511
0543f387
MK
512 set_gdbarch_print_insn (gdbarch, print_insn_vax);
513
7def7fef
MK
514 set_gdbarch_unwind_pc (gdbarch, vax_unwind_pc);
515
516 frame_base_set_default (gdbarch, &vax_frame_base);
517
4791e091 518 /* Hook in ABI-specific overrides, if they have been registered. */
4be87837 519 gdbarch_init_osabi (info, gdbarch);
4791e091 520
7def7fef
MK
521 frame_unwind_append_sniffer (gdbarch, vax_frame_sniffer);
522
f267bd6a
JT
523 return (gdbarch);
524}
c906108c 525
0543f387
MK
526/* Provide a prototype to silence -Wmissing-prototypes. */
527void _initialize_vax_tdep (void);
a78f21af 528
c906108c 529void
fba45db2 530_initialize_vax_tdep (void)
c906108c 531{
4be87837 532 gdbarch_register (bfd_arch_vax, vax_gdbarch_init, NULL);
c906108c 533}
This page took 0.606425 seconds and 4 git commands to generate.