]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/vax-tdep.c
* elf32-sparc.c (elf32_sparc_relocate_section): Don't abort
[thirdparty/binutils-gdb.git] / gdb / vax-tdep.c
CommitLineData
c906108c 1/* Print VAX instructions for GDB, the GNU debugger.
464e0365
AC
2
3 Copyright 1986, 1989, 1991, 1992, 1995, 1996, 1998, 1999, 2000,
4 2002, 2003, 2004 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"
24#include "symtab.h"
25#include "opcode/vax.h"
c11c3a98 26#include "gdbcore.h"
f267bd6a 27#include "inferior.h"
a33f7558 28#include "regcache.h"
c11c3a98 29#include "frame.h"
7def7fef
MK
30#include "frame-base.h"
31#include "frame-unwind.h"
32#include "trad-frame.h"
c11c3a98 33#include "value.h"
f267bd6a 34#include "arch-utils.h"
9bbe19fb 35#include "gdb_string.h"
4be87837 36#include "osabi.h"
a89aa300 37#include "dis-asm.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
52efde73 68
f267bd6a 69static void
52efde73
JT
70vax_push_dummy_frame (void)
71{
72 CORE_ADDR sp = read_register (SP_REGNUM);
73 int regnum;
74
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));
7def7fef 79 sp = push_word (sp, read_register (VAX_FP_REGNUM));
1d049c5e 80 sp = push_word (sp, read_register (VAX_AP_REGNUM));
52efde73
JT
81 sp = push_word (sp, (read_register (PS_REGNUM) & 0xffef) + 0x2fff0000);
82 sp = push_word (sp, 0);
83 write_register (SP_REGNUM, sp);
7def7fef 84 write_register (VAX_FP_REGNUM, sp);
1d049c5e 85 write_register (VAX_AP_REGNUM, sp + (17 * 4));
52efde73
JT
86}
87
f267bd6a 88static void
52efde73
JT
89vax_pop_frame (void)
90{
7def7fef 91 CORE_ADDR fp = read_register (VAX_FP_REGNUM);
52efde73
JT
92 int regnum;
93 int regmask = read_memory_integer (fp + 4, 4);
94
95 write_register (PS_REGNUM,
96 (regmask & 0xffff)
97 | (read_register (PS_REGNUM) & 0xffff0000));
98 write_register (PC_REGNUM, read_memory_integer (fp + 16, 4));
7def7fef 99 write_register (VAX_FP_REGNUM, read_memory_integer (fp + 12, 4));
1d049c5e 100 write_register (VAX_AP_REGNUM, read_memory_integer (fp + 8, 4));
52efde73
JT
101 fp += 16;
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)
107 {
108 regnum = read_memory_integer (fp, 4);
109 fp += (regnum + 1) * 4;
110 }
111 write_register (SP_REGNUM, fp);
112 flush_cached_frames ();
113}
a33f7558
JT
114
115/* The VAX call dummy sequence:
116
117 calls #69, @#32323232
118 bpt
119
120 It is 8 bytes long. The address and argc are patched by
121 vax_fix_call_dummy(). */
f267bd6a
JT
122static LONGEST vax_call_dummy_words[] = { 0x329f69fb, 0x03323232 };
123static int sizeof_vax_call_dummy_words = sizeof(vax_call_dummy_words);
a33f7558 124
f267bd6a 125static void
a33f7558
JT
126vax_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
127 struct value **args, struct type *type, int gcc_p)
128{
129 dummy[1] = nargs;
130 store_unsigned_integer (dummy + 3, 4, fun);
131}
ab62c900 132\f
f267bd6a 133static void
ea74468c
JT
134vax_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
135{
136 write_register (1, addr);
137}
138
f267bd6a 139static void
ea74468c
JT
140vax_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
141{
62700349 142 memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (0), TYPE_LENGTH (valtype));
ea74468c
JT
143}
144
f267bd6a 145static void
ea74468c
JT
146vax_store_return_value (struct type *valtype, char *valbuf)
147{
73937e03 148 deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (valtype));
ea74468c 149}
ea74468c 150\f
5e6b39ff
MK
151
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. */
157
1d049c5e 158static const unsigned char *
5e6b39ff 159vax_breakpoint_from_pc (CORE_ADDR *pc, int *len)
1d049c5e 160{
5e6b39ff 161 static unsigned char break_insn[] = { 3 };
1d049c5e 162
5e6b39ff
MK
163 *len = sizeof (break_insn);
164 return break_insn;
1d049c5e
JT
165}
166\f
b83266a0
SS
167/* Advance PC across any function entry prologue instructions
168 to reach some "real" code. */
169
f267bd6a 170static CORE_ADDR
fba45db2 171vax_skip_prologue (CORE_ADDR pc)
b83266a0 172{
52f0bd74 173 int op = (unsigned char) read_memory_integer (pc, 1);
b83266a0 174 if (op == 0x11)
c5aa993b 175 pc += 2; /* skip brb */
b83266a0 176 if (op == 0x31)
c5aa993b 177 pc += 3; /* skip brw */
b83266a0 178 if (op == 0xC2
c5aa993b
JM
179 && ((unsigned char) read_memory_integer (pc + 2, 1)) == 0x5E)
180 pc += 3; /* skip subl2 */
b83266a0 181 if (op == 0x9E
c5aa993b
JM
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 */
b83266a0 185 if (op == 0x9E
c5aa993b
JM
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 */
b83266a0 189 if (op == 0x9E
c5aa993b
JM
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 */
b83266a0
SS
193 return pc;
194}
7def7fef
MK
195\f
196
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. */
202
203struct vax_frame_cache
204{
205 /* Base address. */
206 CORE_ADDR base;
207
208 /* Table of saved registers. */
209 struct trad_frame_saved_reg *saved_regs;
210};
211
212struct vax_frame_cache *
213vax_frame_cache (struct frame_info *next_frame, void **this_cache)
214{
215 struct vax_frame_cache *cache;
216 CORE_ADDR addr;
217 ULONGEST mask;
218 int regnum;
219
220 if (*this_cache)
221 return *this_cache;
222
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);
226
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)
230 return cache;
231
232 /* The register save mask and control bits determine the layout of
233 the stack frame. */
234 mask = get_frame_memory_unsigned (next_frame, cache->base + 4, 4) >> 16;
235
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;
241
242 /* Scan the register save mask and record the location of the saved
243 registers. */
244 addr = cache->base + 20;
245 for (regnum = 0; regnum < VAX_AP_REGNUM; regnum++)
246 {
247 if (mask & (1 << regnum))
248 {
249 cache->saved_regs[regnum].addr = addr;
250 addr += 4;
251 }
252 }
253
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))
257 {
258 ULONGEST numarg;
259
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;
266 }
267
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));
270
271 return cache;
272}
273
274static void
275vax_frame_this_id (struct frame_info *next_frame, void **this_cache,
276 struct frame_id *this_id)
277{
278 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
279
280 /* This marks the outermost frame. */
281 if (cache->base == 0)
282 return;
283
284 (*this_id) = frame_id_build (cache->base, frame_pc_unwind (next_frame));
285}
286
287static void
288vax_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)
292{
293 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
294
295 trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
296 optimizedp, lvalp, addrp, realnump, valuep);
297}
298
299static const struct frame_unwind vax_frame_unwind =
300{
301 NORMAL_FRAME,
302 vax_frame_this_id,
303 vax_frame_prev_register
304};
305
306static const struct frame_unwind *
307vax_frame_sniffer (struct frame_info *next_frame)
308{
309 return &vax_frame_unwind;
310}
311\f
312
313static CORE_ADDR
314vax_frame_base_address (struct frame_info *next_frame, void **this_cache)
315{
316 struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache);
317
318 return cache->base;
319}
b83266a0 320
f267bd6a 321static CORE_ADDR
7def7fef
MK
322vax_frame_args_address (struct frame_info *next_frame, void **this_cache)
323{
324 return frame_unwind_register_unsigned (next_frame, VAX_AP_REGNUM);
325}
326
327static const struct frame_base vax_frame_base =
a33f7558 328{
7def7fef
MK
329 &vax_frame_unwind,
330 vax_frame_base_address,
331 vax_frame_base_address,
332 vax_frame_args_address
333};
334
335/* Return number of arguments for FRAME. */
336
337static int
338vax_frame_num_args (struct frame_info *frame)
339{
340 CORE_ADDR args;
341
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)
345 return 0;
346
347 args = get_frame_register_unsigned (frame, VAX_AP_REGNUM);
348 return get_frame_memory_unsigned (frame, args, 1);
349}
350
351static CORE_ADDR
352vax_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
353{
354 return frame_unwind_register_unsigned (next_frame, VAX_PC_REGNUM);
a33f7558
JT
355}
356\f
7def7fef 357
f267bd6a
JT
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.
361
362 Called e.g. at program startup, when reading a core file, and when reading
363 a binary file. */
364
365static struct gdbarch *
366vax_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
367{
368 struct gdbarch *gdbarch;
369
4be87837
DJ
370 /* If there is already a candidate, use it. */
371 arches = gdbarch_list_lookup_by_info (arches, &info);
372 if (arches != NULL)
373 return arches->gdbarch;
f267bd6a 374
4be87837 375 gdbarch = gdbarch_alloc (&info, NULL);
4791e091 376
f267bd6a
JT
377 /* Register info */
378 set_gdbarch_num_regs (gdbarch, VAX_NUM_REGS);
5e6b39ff
MK
379 set_gdbarch_register_name (gdbarch, vax_register_name);
380 set_gdbarch_register_type (gdbarch, vax_register_type);
f267bd6a 381 set_gdbarch_sp_regnum (gdbarch, VAX_SP_REGNUM);
f267bd6a
JT
382 set_gdbarch_pc_regnum (gdbarch, VAX_PC_REGNUM);
383 set_gdbarch_ps_regnum (gdbarch, VAX_PS_REGNUM);
384
f267bd6a
JT
385 /* Frame and stack info */
386 set_gdbarch_skip_prologue (gdbarch, vax_skip_prologue);
f267bd6a 387 set_gdbarch_frame_num_args (gdbarch, vax_frame_num_args);
f267bd6a 388
f267bd6a
JT
389 set_gdbarch_frame_args_skip (gdbarch, 4);
390
5e6b39ff 391 /* Stack grows downward. */
f267bd6a
JT
392 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
393
394 /* Return value info */
4183d812 395 set_gdbarch_deprecated_store_struct_return (gdbarch, vax_store_struct_return);
26e9b323 396 set_gdbarch_deprecated_extract_return_value (gdbarch, vax_extract_return_value);
ebba8386 397 set_gdbarch_deprecated_store_return_value (gdbarch, vax_store_return_value);
f267bd6a
JT
398
399 /* Call dummy info */
f3824013 400 set_gdbarch_deprecated_push_dummy_frame (gdbarch, vax_push_dummy_frame);
749b82f6 401 set_gdbarch_deprecated_pop_frame (gdbarch, vax_pop_frame);
f267bd6a 402 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
b1e29e33
AC
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);
07555a72 407 set_gdbarch_deprecated_use_generic_dummy_frames (gdbarch, 0);
ae45cd16 408 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_on_stack);
f267bd6a
JT
409
410 /* Breakpoint info */
1d049c5e 411 set_gdbarch_breakpoint_from_pc (gdbarch, vax_breakpoint_from_pc);
f267bd6a
JT
412
413 /* Misc info */
414 set_gdbarch_function_start_offset (gdbarch, 2);
1d049c5e 415 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
f267bd6a 416
6c0e89ed 417 /* Should be using push_dummy_call. */
b46e02f6 418 set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
6c0e89ed 419
7def7fef
MK
420 set_gdbarch_unwind_pc (gdbarch, vax_unwind_pc);
421
422 frame_base_set_default (gdbarch, &vax_frame_base);
423
4791e091 424 /* Hook in ABI-specific overrides, if they have been registered. */
4be87837 425 gdbarch_init_osabi (info, gdbarch);
4791e091 426
7def7fef
MK
427 frame_unwind_append_sniffer (gdbarch, vax_frame_sniffer);
428
ee2842e2
ILT
429 set_gdbarch_print_insn (gdbarch, print_insn_vax);
430
f267bd6a
JT
431 return (gdbarch);
432}
c906108c 433
a78f21af
AC
434extern initialize_file_ftype _initialize_vax_tdep; /* -Wmissing-prototypes */
435
c906108c 436void
fba45db2 437_initialize_vax_tdep (void)
c906108c 438{
4be87837 439 gdbarch_register (bfd_arch_vax, vax_gdbarch_init, NULL);
c906108c 440}