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