]>
Commit | Line | Data |
---|---|---|
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 | 43 | static const char * |
5e6b39ff | 44 | vax_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 | 62 | static struct type * |
5e6b39ff | 63 | vax_register_type (struct gdbarch *gdbarch, int regnum) |
51eb8b08 | 64 | { |
5e6b39ff | 65 | return builtin_type_int; |
51eb8b08 JT |
66 | } |
67 | \f | |
52efde73 | 68 | |
7346c184 MK |
69 | static CORE_ADDR |
70 | vax_store_arguments (struct regcache *regcache, int nargs, | |
71 | struct value **args, CORE_ADDR sp, | |
72 | int struct_return, CORE_ADDR struct_addr) | |
52efde73 | 73 | { |
7346c184 MK |
74 | char buf[4]; |
75 | int count = 0; | |
76 | int i; | |
52efde73 | 77 | |
7346c184 MK |
78 | /* We create an argument list on the stack, and make the argument |
79 | pointer to it. */ | |
52efde73 | 80 | |
7346c184 MK |
81 | /* Push arguments in reverse order. */ |
82 | for (i = nargs - 1; i >= 0; i--) | |
52efde73 | 83 | { |
7346c184 MK |
84 | int len = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (args[i])); |
85 | ||
86 | sp -= (len + 3) & ~3; | |
87 | count += (len + 3) / 4; | |
88 | write_memory (sp, VALUE_CONTENTS_ALL (args[i]), len); | |
52efde73 | 89 | } |
a33f7558 | 90 | |
7346c184 MK |
91 | /* Push value address. */ |
92 | if (struct_return) | |
93 | { | |
94 | sp -= 4; | |
95 | count++; | |
96 | store_unsigned_integer (buf, 4, struct_addr); | |
97 | write_memory (sp, buf, 4); | |
98 | } | |
a33f7558 | 99 | |
7346c184 MK |
100 | /* Push argument count. */ |
101 | sp -= 4; | |
102 | store_unsigned_integer (buf, 4, count); | |
103 | write_memory (sp, buf, 4); | |
a33f7558 | 104 | |
7346c184 MK |
105 | /* Update the argument pointer. */ |
106 | store_unsigned_integer (buf, 4, sp); | |
107 | regcache_cooked_write (regcache, VAX_AP_REGNUM, buf); | |
a33f7558 | 108 | |
7346c184 MK |
109 | return sp; |
110 | } | |
111 | ||
112 | static CORE_ADDR | |
113 | vax_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr, | |
114 | struct regcache *regcache, CORE_ADDR bp_addr, int nargs, | |
115 | struct value **args, CORE_ADDR sp, int struct_return, | |
116 | CORE_ADDR struct_addr) | |
117 | { | |
118 | CORE_ADDR fp = sp; | |
119 | char buf[4]; | |
120 | ||
121 | /* Set up the function arguments. */ | |
122 | sp = vax_store_arguments (regcache, nargs, args, sp, | |
123 | struct_return, struct_addr); | |
124 | ||
125 | /* Store return address in the PC slot. */ | |
126 | sp -= 4; | |
127 | store_unsigned_integer (buf, 4, bp_addr); | |
128 | write_memory (sp, buf, 4); | |
129 | ||
130 | /* Store the (fake) frame pointer in the FP slot. */ | |
131 | sp -= 4; | |
132 | store_unsigned_integer (buf, 4, fp); | |
133 | write_memory (sp, buf, 4); | |
134 | ||
135 | /* Skip the AP slot. */ | |
136 | sp -= 4; | |
137 | ||
138 | /* Store register save mask and control bits. */ | |
139 | sp -= 4; | |
140 | store_unsigned_integer (buf, 4, 0); | |
141 | write_memory (sp, buf, 4); | |
142 | ||
143 | /* Store condition handler. */ | |
144 | sp -= 4; | |
145 | store_unsigned_integer (buf, 4, 0); | |
146 | write_memory (sp, buf, 4); | |
147 | ||
148 | /* Update the stack pointer and frame pointer. */ | |
149 | store_unsigned_integer (buf, 4, sp); | |
150 | regcache_cooked_write (regcache, VAX_SP_REGNUM, buf); | |
151 | regcache_cooked_write (regcache, VAX_FP_REGNUM, buf); | |
152 | ||
153 | /* Return the saved (fake) frame pointer. */ | |
154 | return fp; | |
155 | } | |
156 | ||
157 | static struct frame_id | |
158 | vax_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
a33f7558 | 159 | { |
7346c184 MK |
160 | CORE_ADDR fp; |
161 | ||
162 | fp = frame_unwind_register_unsigned (next_frame, VAX_FP_REGNUM); | |
163 | return frame_id_build (fp, frame_pc_unwind (next_frame)); | |
a33f7558 | 164 | } |
ab62c900 | 165 | \f |
7346c184 | 166 | |
f267bd6a | 167 | static void |
ea74468c JT |
168 | vax_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) |
169 | { | |
170 | write_register (1, addr); | |
171 | } | |
172 | ||
f267bd6a | 173 | static void |
ea74468c JT |
174 | vax_extract_return_value (struct type *valtype, char *regbuf, char *valbuf) |
175 | { | |
62700349 | 176 | memcpy (valbuf, regbuf + DEPRECATED_REGISTER_BYTE (0), TYPE_LENGTH (valtype)); |
ea74468c JT |
177 | } |
178 | ||
f267bd6a | 179 | static void |
ea74468c JT |
180 | vax_store_return_value (struct type *valtype, char *valbuf) |
181 | { | |
73937e03 | 182 | deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (valtype)); |
ea74468c | 183 | } |
ea74468c | 184 | \f |
5e6b39ff MK |
185 | |
186 | /* Use the program counter to determine the contents and size of a | |
187 | breakpoint instruction. Return a pointer to a string of bytes that | |
188 | encode a breakpoint instruction, store the length of the string in | |
189 | *LEN and optionally adjust *PC to point to the correct memory | |
190 | location for inserting the breakpoint. */ | |
191 | ||
1d049c5e | 192 | static const unsigned char * |
5e6b39ff | 193 | vax_breakpoint_from_pc (CORE_ADDR *pc, int *len) |
1d049c5e | 194 | { |
5e6b39ff | 195 | static unsigned char break_insn[] = { 3 }; |
1d049c5e | 196 | |
5e6b39ff MK |
197 | *len = sizeof (break_insn); |
198 | return break_insn; | |
1d049c5e JT |
199 | } |
200 | \f | |
b83266a0 SS |
201 | /* Advance PC across any function entry prologue instructions |
202 | to reach some "real" code. */ | |
203 | ||
f267bd6a | 204 | static CORE_ADDR |
fba45db2 | 205 | vax_skip_prologue (CORE_ADDR pc) |
b83266a0 | 206 | { |
52f0bd74 | 207 | int op = (unsigned char) read_memory_integer (pc, 1); |
b83266a0 | 208 | if (op == 0x11) |
c5aa993b | 209 | pc += 2; /* skip brb */ |
b83266a0 | 210 | if (op == 0x31) |
c5aa993b | 211 | pc += 3; /* skip brw */ |
b83266a0 | 212 | if (op == 0xC2 |
c5aa993b JM |
213 | && ((unsigned char) read_memory_integer (pc + 2, 1)) == 0x5E) |
214 | pc += 3; /* skip subl2 */ | |
b83266a0 | 215 | if (op == 0x9E |
c5aa993b JM |
216 | && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xAE |
217 | && ((unsigned char) read_memory_integer (pc + 3, 1)) == 0x5E) | |
218 | pc += 4; /* skip movab */ | |
b83266a0 | 219 | if (op == 0x9E |
c5aa993b JM |
220 | && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xCE |
221 | && ((unsigned char) read_memory_integer (pc + 4, 1)) == 0x5E) | |
222 | pc += 5; /* skip movab */ | |
b83266a0 | 223 | if (op == 0x9E |
c5aa993b JM |
224 | && ((unsigned char) read_memory_integer (pc + 1, 1)) == 0xEE |
225 | && ((unsigned char) read_memory_integer (pc + 6, 1)) == 0x5E) | |
226 | pc += 7; /* skip movab */ | |
b83266a0 SS |
227 | return pc; |
228 | } | |
7def7fef MK |
229 | \f |
230 | ||
231 | /* Unwinding the stack is relatively easy since the VAX has a | |
232 | dedicated frame pointer, and frames are set up automatically as the | |
233 | result of a function call. Most of the relevant information can be | |
234 | inferred from the documentation of the Procedure Call Instructions | |
235 | in the VAX MACRO and Instruction Set Reference Manual. */ | |
236 | ||
237 | struct vax_frame_cache | |
238 | { | |
239 | /* Base address. */ | |
240 | CORE_ADDR base; | |
241 | ||
242 | /* Table of saved registers. */ | |
243 | struct trad_frame_saved_reg *saved_regs; | |
244 | }; | |
245 | ||
246 | struct vax_frame_cache * | |
247 | vax_frame_cache (struct frame_info *next_frame, void **this_cache) | |
248 | { | |
249 | struct vax_frame_cache *cache; | |
250 | CORE_ADDR addr; | |
251 | ULONGEST mask; | |
252 | int regnum; | |
253 | ||
254 | if (*this_cache) | |
255 | return *this_cache; | |
256 | ||
257 | /* Allocate a new cache. */ | |
258 | cache = FRAME_OBSTACK_ZALLOC (struct vax_frame_cache); | |
259 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
260 | ||
261 | /* The frame pointer is used as the base for the frame. */ | |
262 | cache->base = frame_unwind_register_unsigned (next_frame, VAX_FP_REGNUM); | |
263 | if (cache->base == 0) | |
264 | return cache; | |
265 | ||
266 | /* The register save mask and control bits determine the layout of | |
267 | the stack frame. */ | |
268 | mask = get_frame_memory_unsigned (next_frame, cache->base + 4, 4) >> 16; | |
269 | ||
270 | /* These are always saved. */ | |
271 | cache->saved_regs[VAX_PC_REGNUM].addr = cache->base + 16; | |
272 | cache->saved_regs[VAX_FP_REGNUM].addr = cache->base + 12; | |
273 | cache->saved_regs[VAX_AP_REGNUM].addr = cache->base + 8; | |
274 | cache->saved_regs[VAX_PS_REGNUM].addr = cache->base + 4; | |
275 | ||
276 | /* Scan the register save mask and record the location of the saved | |
277 | registers. */ | |
278 | addr = cache->base + 20; | |
279 | for (regnum = 0; regnum < VAX_AP_REGNUM; regnum++) | |
280 | { | |
281 | if (mask & (1 << regnum)) | |
282 | { | |
283 | cache->saved_regs[regnum].addr = addr; | |
284 | addr += 4; | |
285 | } | |
286 | } | |
287 | ||
288 | /* The CALLS/CALLG flag determines whether this frame has a General | |
289 | Argument List or a Stack Argument List. */ | |
290 | if (mask & (1 << 13)) | |
291 | { | |
292 | ULONGEST numarg; | |
293 | ||
294 | /* This is a procedure with Stack Argument List. Adjust the | |
295 | stack address for the arguments thet were pushed onto the | |
296 | stack. The return instruction will automatically pop the | |
297 | arguments from the stack. */ | |
298 | numarg = get_frame_memory_unsigned (next_frame, addr, 1); | |
299 | addr += 4 + numarg * 4; | |
300 | } | |
301 | ||
302 | /* Bits 1:0 of the stack pointer were saved in the control bits. */ | |
303 | trad_frame_set_value (cache->saved_regs, VAX_SP_REGNUM, addr + (mask >> 14)); | |
304 | ||
305 | return cache; | |
306 | } | |
307 | ||
308 | static void | |
309 | vax_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
310 | struct frame_id *this_id) | |
311 | { | |
312 | struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache); | |
313 | ||
314 | /* This marks the outermost frame. */ | |
315 | if (cache->base == 0) | |
316 | return; | |
317 | ||
318 | (*this_id) = frame_id_build (cache->base, frame_pc_unwind (next_frame)); | |
319 | } | |
320 | ||
321 | static void | |
322 | vax_frame_prev_register (struct frame_info *next_frame, void **this_cache, | |
323 | int regnum, int *optimizedp, | |
324 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
325 | int *realnump, void *valuep) | |
326 | { | |
327 | struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache); | |
328 | ||
329 | trad_frame_prev_register (next_frame, cache->saved_regs, regnum, | |
330 | optimizedp, lvalp, addrp, realnump, valuep); | |
331 | } | |
332 | ||
333 | static const struct frame_unwind vax_frame_unwind = | |
334 | { | |
335 | NORMAL_FRAME, | |
336 | vax_frame_this_id, | |
337 | vax_frame_prev_register | |
338 | }; | |
339 | ||
340 | static const struct frame_unwind * | |
341 | vax_frame_sniffer (struct frame_info *next_frame) | |
342 | { | |
343 | return &vax_frame_unwind; | |
344 | } | |
345 | \f | |
346 | ||
347 | static CORE_ADDR | |
348 | vax_frame_base_address (struct frame_info *next_frame, void **this_cache) | |
349 | { | |
350 | struct vax_frame_cache *cache = vax_frame_cache (next_frame, this_cache); | |
351 | ||
352 | return cache->base; | |
353 | } | |
b83266a0 | 354 | |
f267bd6a | 355 | static CORE_ADDR |
7def7fef MK |
356 | vax_frame_args_address (struct frame_info *next_frame, void **this_cache) |
357 | { | |
358 | return frame_unwind_register_unsigned (next_frame, VAX_AP_REGNUM); | |
359 | } | |
360 | ||
361 | static const struct frame_base vax_frame_base = | |
a33f7558 | 362 | { |
7def7fef MK |
363 | &vax_frame_unwind, |
364 | vax_frame_base_address, | |
365 | vax_frame_base_address, | |
366 | vax_frame_args_address | |
367 | }; | |
368 | ||
369 | /* Return number of arguments for FRAME. */ | |
370 | ||
371 | static int | |
372 | vax_frame_num_args (struct frame_info *frame) | |
373 | { | |
374 | CORE_ADDR args; | |
375 | ||
376 | /* Assume that the argument pointer for the outermost frame is | |
377 | hosed, as is the case on NetBSD/vax ELF. */ | |
378 | if (get_frame_base (frame) == 0) | |
379 | return 0; | |
380 | ||
381 | args = get_frame_register_unsigned (frame, VAX_AP_REGNUM); | |
382 | return get_frame_memory_unsigned (frame, args, 1); | |
383 | } | |
384 | ||
385 | static CORE_ADDR | |
386 | vax_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
387 | { | |
388 | return frame_unwind_register_unsigned (next_frame, VAX_PC_REGNUM); | |
a33f7558 JT |
389 | } |
390 | \f | |
7def7fef | 391 | |
f267bd6a JT |
392 | /* Initialize the current architecture based on INFO. If possible, re-use an |
393 | architecture from ARCHES, which is a list of architectures already created | |
394 | during this debugging session. | |
395 | ||
396 | Called e.g. at program startup, when reading a core file, and when reading | |
397 | a binary file. */ | |
398 | ||
399 | static struct gdbarch * | |
400 | vax_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
401 | { | |
402 | struct gdbarch *gdbarch; | |
403 | ||
4be87837 DJ |
404 | /* If there is already a candidate, use it. */ |
405 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
406 | if (arches != NULL) | |
407 | return arches->gdbarch; | |
f267bd6a | 408 | |
4be87837 | 409 | gdbarch = gdbarch_alloc (&info, NULL); |
4791e091 | 410 | |
f267bd6a JT |
411 | /* Register info */ |
412 | set_gdbarch_num_regs (gdbarch, VAX_NUM_REGS); | |
5e6b39ff MK |
413 | set_gdbarch_register_name (gdbarch, vax_register_name); |
414 | set_gdbarch_register_type (gdbarch, vax_register_type); | |
f267bd6a | 415 | set_gdbarch_sp_regnum (gdbarch, VAX_SP_REGNUM); |
f267bd6a JT |
416 | set_gdbarch_pc_regnum (gdbarch, VAX_PC_REGNUM); |
417 | set_gdbarch_ps_regnum (gdbarch, VAX_PS_REGNUM); | |
418 | ||
f267bd6a JT |
419 | /* Frame and stack info */ |
420 | set_gdbarch_skip_prologue (gdbarch, vax_skip_prologue); | |
f267bd6a | 421 | set_gdbarch_frame_num_args (gdbarch, vax_frame_num_args); |
f267bd6a | 422 | |
f267bd6a JT |
423 | set_gdbarch_frame_args_skip (gdbarch, 4); |
424 | ||
5e6b39ff | 425 | /* Stack grows downward. */ |
f267bd6a JT |
426 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
427 | ||
428 | /* Return value info */ | |
4183d812 | 429 | set_gdbarch_deprecated_store_struct_return (gdbarch, vax_store_struct_return); |
26e9b323 | 430 | set_gdbarch_deprecated_extract_return_value (gdbarch, vax_extract_return_value); |
ebba8386 | 431 | set_gdbarch_deprecated_store_return_value (gdbarch, vax_store_return_value); |
f267bd6a | 432 | |
7346c184 MK |
433 | /* Call dummy code. */ |
434 | set_gdbarch_push_dummy_call (gdbarch, vax_push_dummy_call); | |
435 | set_gdbarch_unwind_dummy_id (gdbarch, vax_unwind_dummy_id); | |
f267bd6a JT |
436 | |
437 | /* Breakpoint info */ | |
1d049c5e | 438 | set_gdbarch_breakpoint_from_pc (gdbarch, vax_breakpoint_from_pc); |
f267bd6a JT |
439 | |
440 | /* Misc info */ | |
441 | set_gdbarch_function_start_offset (gdbarch, 2); | |
1d049c5e | 442 | set_gdbarch_believe_pcc_promotion (gdbarch, 1); |
f267bd6a | 443 | |
7def7fef MK |
444 | set_gdbarch_unwind_pc (gdbarch, vax_unwind_pc); |
445 | ||
446 | frame_base_set_default (gdbarch, &vax_frame_base); | |
447 | ||
4791e091 | 448 | /* Hook in ABI-specific overrides, if they have been registered. */ |
4be87837 | 449 | gdbarch_init_osabi (info, gdbarch); |
4791e091 | 450 | |
7def7fef MK |
451 | frame_unwind_append_sniffer (gdbarch, vax_frame_sniffer); |
452 | ||
ee2842e2 ILT |
453 | set_gdbarch_print_insn (gdbarch, print_insn_vax); |
454 | ||
f267bd6a JT |
455 | return (gdbarch); |
456 | } | |
c906108c | 457 | |
a78f21af AC |
458 | extern initialize_file_ftype _initialize_vax_tdep; /* -Wmissing-prototypes */ |
459 | ||
c906108c | 460 | void |
fba45db2 | 461 | _initialize_vax_tdep (void) |
c906108c | 462 | { |
4be87837 | 463 | gdbarch_register (bfd_arch_vax, vax_gdbarch_init, NULL); |
c906108c | 464 | } |