Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger. |
0fd88904 | 2 | |
6aba47ca | 3 | Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
4c38e0a4 | 4 | 2003, 2005, 2006, 2007, 2008, 2009, 2010 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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 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 | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
20 | |
21 | #include "defs.h" | |
615967cb | 22 | #include "doublest.h" |
c906108c | 23 | #include "frame.h" |
d2427a71 RH |
24 | #include "frame-unwind.h" |
25 | #include "frame-base.h" | |
baa490c4 | 26 | #include "dwarf2-frame.h" |
c906108c SS |
27 | #include "inferior.h" |
28 | #include "symtab.h" | |
29 | #include "value.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "gdbcore.h" | |
32 | #include "dis-asm.h" | |
33 | #include "symfile.h" | |
34 | #include "objfiles.h" | |
35 | #include "gdb_string.h" | |
c5f0f3d0 | 36 | #include "linespec.h" |
4e052eda | 37 | #include "regcache.h" |
615967cb | 38 | #include "reggroups.h" |
dc129d82 | 39 | #include "arch-utils.h" |
4be87837 | 40 | #include "osabi.h" |
fe898f56 | 41 | #include "block.h" |
7d9b040b | 42 | #include "infcall.h" |
07ea644b | 43 | #include "trad-frame.h" |
dc129d82 JT |
44 | |
45 | #include "elf-bfd.h" | |
46 | ||
47 | #include "alpha-tdep.h" | |
48 | ||
3a48e6ff JG |
49 | /* Instruction decoding. The notations for registers, immediates and |
50 | opcodes are the same as the one used in Compaq's Alpha architecture | |
51 | handbook. */ | |
52 | ||
53 | #define INSN_OPCODE(insn) ((insn & 0xfc000000) >> 26) | |
54 | ||
55 | /* Memory instruction format */ | |
56 | #define MEM_RA(insn) ((insn & 0x03e00000) >> 21) | |
57 | #define MEM_RB(insn) ((insn & 0x001f0000) >> 16) | |
58 | #define MEM_DISP(insn) \ | |
59 | (((insn & 0x8000) == 0) ? (insn & 0xffff) : -((-insn) & 0xffff)) | |
60 | ||
61 | static const int lda_opcode = 0x08; | |
62 | static const int stq_opcode = 0x2d; | |
63 | ||
64 | /* Branch instruction format */ | |
65 | #define BR_RA(insn) MEM_RA(insn) | |
66 | ||
67 | static const int bne_opcode = 0x3d; | |
68 | ||
69 | /* Operate instruction format */ | |
70 | #define OPR_FUNCTION(insn) ((insn & 0xfe0) >> 5) | |
71 | #define OPR_HAS_IMMEDIATE(insn) ((insn & 0x1000) == 0x1000) | |
72 | #define OPR_RA(insn) MEM_RA(insn) | |
73 | #define OPR_RC(insn) ((insn & 0x1f)) | |
74 | #define OPR_LIT(insn) ((insn & 0x1fe000) >> 13) | |
75 | ||
76 | static const int subq_opcode = 0x10; | |
77 | static const int subq_function = 0x29; | |
78 | ||
c906108c | 79 | \f |
515921d7 JB |
80 | /* Return the name of the REGNO register. |
81 | ||
82 | An empty name corresponds to a register number that used to | |
83 | be used for a virtual register. That virtual register has | |
84 | been removed, but the index is still reserved to maintain | |
85 | compatibility with existing remote alpha targets. */ | |
86 | ||
fa88f677 | 87 | static const char * |
d93859e2 | 88 | alpha_register_name (struct gdbarch *gdbarch, int regno) |
636a6dfc | 89 | { |
5ab84872 | 90 | static const char * const register_names[] = |
636a6dfc JT |
91 | { |
92 | "v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6", | |
93 | "t7", "s0", "s1", "s2", "s3", "s4", "s5", "fp", | |
94 | "a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9", | |
95 | "t10", "t11", "ra", "t12", "at", "gp", "sp", "zero", | |
96 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
97 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
98 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
99 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "fpcr", | |
44d88583 | 100 | "pc", "", "unique" |
636a6dfc JT |
101 | }; |
102 | ||
103 | if (regno < 0) | |
5ab84872 | 104 | return NULL; |
e8d2d628 | 105 | if (regno >= ARRAY_SIZE(register_names)) |
5ab84872 RH |
106 | return NULL; |
107 | return register_names[regno]; | |
636a6dfc | 108 | } |
d734c450 | 109 | |
dc129d82 | 110 | static int |
64a3914f | 111 | alpha_cannot_fetch_register (struct gdbarch *gdbarch, int regno) |
d734c450 | 112 | { |
515921d7 | 113 | return (regno == ALPHA_ZERO_REGNUM |
64a3914f | 114 | || strlen (alpha_register_name (gdbarch, regno)) == 0); |
d734c450 JT |
115 | } |
116 | ||
dc129d82 | 117 | static int |
64a3914f | 118 | alpha_cannot_store_register (struct gdbarch *gdbarch, int regno) |
d734c450 | 119 | { |
515921d7 | 120 | return (regno == ALPHA_ZERO_REGNUM |
64a3914f | 121 | || strlen (alpha_register_name (gdbarch, regno)) == 0); |
d734c450 JT |
122 | } |
123 | ||
dc129d82 | 124 | static struct type * |
c483c494 | 125 | alpha_register_type (struct gdbarch *gdbarch, int regno) |
0d056799 | 126 | { |
72667056 | 127 | if (regno == ALPHA_SP_REGNUM || regno == ALPHA_GP_REGNUM) |
0dfff4cb | 128 | return builtin_type (gdbarch)->builtin_data_ptr; |
72667056 | 129 | if (regno == ALPHA_PC_REGNUM) |
0dfff4cb | 130 | return builtin_type (gdbarch)->builtin_func_ptr; |
72667056 RH |
131 | |
132 | /* Don't need to worry about little vs big endian until | |
133 | some jerk tries to port to alpha-unicosmk. */ | |
b38b6be2 | 134 | if (regno >= ALPHA_FP0_REGNUM && regno < ALPHA_FP0_REGNUM + 31) |
27067745 | 135 | return builtin_type (gdbarch)->builtin_double; |
72667056 | 136 | |
df4df182 | 137 | return builtin_type (gdbarch)->builtin_int64; |
0d056799 | 138 | } |
f8453e34 | 139 | |
615967cb RH |
140 | /* Is REGNUM a member of REGGROUP? */ |
141 | ||
142 | static int | |
143 | alpha_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
144 | struct reggroup *group) | |
145 | { | |
146 | /* Filter out any registers eliminated, but whose regnum is | |
147 | reserved for backward compatibility, e.g. the vfp. */ | |
ec7cc0e8 UW |
148 | if (gdbarch_register_name (gdbarch, regnum) == NULL |
149 | || *gdbarch_register_name (gdbarch, regnum) == '\0') | |
615967cb RH |
150 | return 0; |
151 | ||
df4a182b RH |
152 | if (group == all_reggroup) |
153 | return 1; | |
154 | ||
155 | /* Zero should not be saved or restored. Technically it is a general | |
156 | register (just as $f31 would be a float if we represented it), but | |
157 | there's no point displaying it during "info regs", so leave it out | |
158 | of all groups except for "all". */ | |
159 | if (regnum == ALPHA_ZERO_REGNUM) | |
160 | return 0; | |
161 | ||
162 | /* All other registers are saved and restored. */ | |
163 | if (group == save_reggroup || group == restore_reggroup) | |
615967cb RH |
164 | return 1; |
165 | ||
166 | /* All other groups are non-overlapping. */ | |
167 | ||
168 | /* Since this is really a PALcode memory slot... */ | |
169 | if (regnum == ALPHA_UNIQUE_REGNUM) | |
170 | return group == system_reggroup; | |
171 | ||
172 | /* Force the FPCR to be considered part of the floating point state. */ | |
173 | if (regnum == ALPHA_FPCR_REGNUM) | |
174 | return group == float_reggroup; | |
175 | ||
176 | if (regnum >= ALPHA_FP0_REGNUM && regnum < ALPHA_FP0_REGNUM + 31) | |
177 | return group == float_reggroup; | |
178 | else | |
179 | return group == general_reggroup; | |
180 | } | |
181 | ||
c483c494 RH |
182 | /* The following represents exactly the conversion performed by |
183 | the LDS instruction. This applies to both single-precision | |
184 | floating point and 32-bit integers. */ | |
185 | ||
186 | static void | |
e17a4113 | 187 | alpha_lds (struct gdbarch *gdbarch, void *out, const void *in) |
c483c494 | 188 | { |
e17a4113 UW |
189 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
190 | ULONGEST mem = extract_unsigned_integer (in, 4, byte_order); | |
c483c494 RH |
191 | ULONGEST frac = (mem >> 0) & 0x7fffff; |
192 | ULONGEST sign = (mem >> 31) & 1; | |
193 | ULONGEST exp_msb = (mem >> 30) & 1; | |
194 | ULONGEST exp_low = (mem >> 23) & 0x7f; | |
195 | ULONGEST exp, reg; | |
196 | ||
197 | exp = (exp_msb << 10) | exp_low; | |
198 | if (exp_msb) | |
199 | { | |
200 | if (exp_low == 0x7f) | |
201 | exp = 0x7ff; | |
202 | } | |
203 | else | |
204 | { | |
205 | if (exp_low != 0x00) | |
206 | exp |= 0x380; | |
207 | } | |
208 | ||
209 | reg = (sign << 63) | (exp << 52) | (frac << 29); | |
e17a4113 | 210 | store_unsigned_integer (out, 8, byte_order, reg); |
c483c494 RH |
211 | } |
212 | ||
213 | /* Similarly, this represents exactly the conversion performed by | |
214 | the STS instruction. */ | |
215 | ||
39efb398 | 216 | static void |
e17a4113 | 217 | alpha_sts (struct gdbarch *gdbarch, void *out, const void *in) |
c483c494 | 218 | { |
e17a4113 | 219 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
c483c494 RH |
220 | ULONGEST reg, mem; |
221 | ||
e17a4113 | 222 | reg = extract_unsigned_integer (in, 8, byte_order); |
c483c494 | 223 | mem = ((reg >> 32) & 0xc0000000) | ((reg >> 29) & 0x3fffffff); |
e17a4113 | 224 | store_unsigned_integer (out, 4, byte_order, mem); |
c483c494 RH |
225 | } |
226 | ||
d2427a71 RH |
227 | /* The alpha needs a conversion between register and memory format if the |
228 | register is a floating point register and memory format is float, as the | |
229 | register format must be double or memory format is an integer with 4 | |
230 | bytes or less, as the representation of integers in floating point | |
231 | registers is different. */ | |
232 | ||
c483c494 | 233 | static int |
0abe36f5 | 234 | alpha_convert_register_p (struct gdbarch *gdbarch, int regno, struct type *type) |
14696584 | 235 | { |
83acabca DJ |
236 | return (regno >= ALPHA_FP0_REGNUM && regno < ALPHA_FP0_REGNUM + 31 |
237 | && TYPE_LENGTH (type) != 8); | |
14696584 RH |
238 | } |
239 | ||
d2427a71 | 240 | static void |
ff2e87ac | 241 | alpha_register_to_value (struct frame_info *frame, int regnum, |
5b819568 | 242 | struct type *valtype, gdb_byte *out) |
5868c862 | 243 | { |
2a1ce6ec MK |
244 | gdb_byte in[MAX_REGISTER_SIZE]; |
245 | ||
ff2e87ac | 246 | frame_register_read (frame, regnum, in); |
c483c494 | 247 | switch (TYPE_LENGTH (valtype)) |
d2427a71 | 248 | { |
c483c494 | 249 | case 4: |
e17a4113 | 250 | alpha_sts (get_frame_arch (frame), out, in); |
c483c494 | 251 | break; |
c483c494 | 252 | default: |
323e0a4a | 253 | error (_("Cannot retrieve value from floating point register")); |
d2427a71 | 254 | } |
d2427a71 | 255 | } |
5868c862 | 256 | |
d2427a71 | 257 | static void |
ff2e87ac | 258 | alpha_value_to_register (struct frame_info *frame, int regnum, |
5b819568 | 259 | struct type *valtype, const gdb_byte *in) |
d2427a71 | 260 | { |
2a1ce6ec MK |
261 | gdb_byte out[MAX_REGISTER_SIZE]; |
262 | ||
c483c494 | 263 | switch (TYPE_LENGTH (valtype)) |
d2427a71 | 264 | { |
c483c494 | 265 | case 4: |
e17a4113 | 266 | alpha_lds (get_frame_arch (frame), out, in); |
c483c494 | 267 | break; |
c483c494 | 268 | default: |
323e0a4a | 269 | error (_("Cannot store value in floating point register")); |
d2427a71 | 270 | } |
ff2e87ac | 271 | put_frame_register (frame, regnum, out); |
5868c862 JT |
272 | } |
273 | ||
d2427a71 RH |
274 | \f |
275 | /* The alpha passes the first six arguments in the registers, the rest on | |
c88e30c0 RH |
276 | the stack. The register arguments are stored in ARG_REG_BUFFER, and |
277 | then moved into the register file; this simplifies the passing of a | |
278 | large struct which extends from the registers to the stack, plus avoids | |
279 | three ptrace invocations per word. | |
280 | ||
281 | We don't bother tracking which register values should go in integer | |
282 | regs or fp regs; we load the same values into both. | |
283 | ||
d2427a71 RH |
284 | If the called function is returning a structure, the address of the |
285 | structure to be returned is passed as a hidden first argument. */ | |
c906108c | 286 | |
d2427a71 | 287 | static CORE_ADDR |
7d9b040b | 288 | alpha_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
c88e30c0 RH |
289 | struct regcache *regcache, CORE_ADDR bp_addr, |
290 | int nargs, struct value **args, CORE_ADDR sp, | |
291 | int struct_return, CORE_ADDR struct_addr) | |
c906108c | 292 | { |
e17a4113 | 293 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
d2427a71 RH |
294 | int i; |
295 | int accumulate_size = struct_return ? 8 : 0; | |
d2427a71 | 296 | struct alpha_arg |
c906108c | 297 | { |
f42a0a33 | 298 | const gdb_byte *contents; |
d2427a71 RH |
299 | int len; |
300 | int offset; | |
301 | }; | |
c88e30c0 RH |
302 | struct alpha_arg *alpha_args |
303 | = (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg)); | |
52f0bd74 | 304 | struct alpha_arg *m_arg; |
2a1ce6ec | 305 | gdb_byte arg_reg_buffer[ALPHA_REGISTER_SIZE * ALPHA_NUM_ARG_REGS]; |
d2427a71 | 306 | int required_arg_regs; |
7d9b040b | 307 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
c906108c | 308 | |
c88e30c0 RH |
309 | /* The ABI places the address of the called function in T12. */ |
310 | regcache_cooked_write_signed (regcache, ALPHA_T12_REGNUM, func_addr); | |
311 | ||
312 | /* Set the return address register to point to the entry point | |
313 | of the program, where a breakpoint lies in wait. */ | |
314 | regcache_cooked_write_signed (regcache, ALPHA_RA_REGNUM, bp_addr); | |
315 | ||
316 | /* Lay out the arguments in memory. */ | |
d2427a71 RH |
317 | for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++) |
318 | { | |
319 | struct value *arg = args[i]; | |
4991999e | 320 | struct type *arg_type = check_typedef (value_type (arg)); |
c88e30c0 | 321 | |
d2427a71 RH |
322 | /* Cast argument to long if necessary as the compiler does it too. */ |
323 | switch (TYPE_CODE (arg_type)) | |
c906108c | 324 | { |
d2427a71 RH |
325 | case TYPE_CODE_INT: |
326 | case TYPE_CODE_BOOL: | |
327 | case TYPE_CODE_CHAR: | |
328 | case TYPE_CODE_RANGE: | |
329 | case TYPE_CODE_ENUM: | |
0ede8eca | 330 | if (TYPE_LENGTH (arg_type) == 4) |
d2427a71 | 331 | { |
0ede8eca RH |
332 | /* 32-bit values must be sign-extended to 64 bits |
333 | even if the base data type is unsigned. */ | |
df4df182 | 334 | arg_type = builtin_type (gdbarch)->builtin_int32; |
0ede8eca RH |
335 | arg = value_cast (arg_type, arg); |
336 | } | |
337 | if (TYPE_LENGTH (arg_type) < ALPHA_REGISTER_SIZE) | |
338 | { | |
df4df182 | 339 | arg_type = builtin_type (gdbarch)->builtin_int64; |
d2427a71 RH |
340 | arg = value_cast (arg_type, arg); |
341 | } | |
342 | break; | |
7b5e1cb3 | 343 | |
c88e30c0 RH |
344 | case TYPE_CODE_FLT: |
345 | /* "float" arguments loaded in registers must be passed in | |
346 | register format, aka "double". */ | |
347 | if (accumulate_size < sizeof (arg_reg_buffer) | |
348 | && TYPE_LENGTH (arg_type) == 4) | |
349 | { | |
27067745 | 350 | arg_type = builtin_type (gdbarch)->builtin_double; |
c88e30c0 RH |
351 | arg = value_cast (arg_type, arg); |
352 | } | |
353 | /* Tru64 5.1 has a 128-bit long double, and passes this by | |
354 | invisible reference. No one else uses this data type. */ | |
355 | else if (TYPE_LENGTH (arg_type) == 16) | |
356 | { | |
357 | /* Allocate aligned storage. */ | |
358 | sp = (sp & -16) - 16; | |
359 | ||
360 | /* Write the real data into the stack. */ | |
0fd88904 | 361 | write_memory (sp, value_contents (arg), 16); |
c88e30c0 RH |
362 | |
363 | /* Construct the indirection. */ | |
364 | arg_type = lookup_pointer_type (arg_type); | |
365 | arg = value_from_pointer (arg_type, sp); | |
366 | } | |
367 | break; | |
7b5e1cb3 RH |
368 | |
369 | case TYPE_CODE_COMPLEX: | |
370 | /* ??? The ABI says that complex values are passed as two | |
371 | separate scalar values. This distinction only matters | |
372 | for complex float. However, GCC does not implement this. */ | |
373 | ||
374 | /* Tru64 5.1 has a 128-bit long double, and passes this by | |
375 | invisible reference. */ | |
376 | if (TYPE_LENGTH (arg_type) == 32) | |
377 | { | |
378 | /* Allocate aligned storage. */ | |
379 | sp = (sp & -16) - 16; | |
380 | ||
381 | /* Write the real data into the stack. */ | |
0fd88904 | 382 | write_memory (sp, value_contents (arg), 32); |
7b5e1cb3 RH |
383 | |
384 | /* Construct the indirection. */ | |
385 | arg_type = lookup_pointer_type (arg_type); | |
386 | arg = value_from_pointer (arg_type, sp); | |
387 | } | |
388 | break; | |
389 | ||
d2427a71 RH |
390 | default: |
391 | break; | |
c906108c | 392 | } |
d2427a71 RH |
393 | m_arg->len = TYPE_LENGTH (arg_type); |
394 | m_arg->offset = accumulate_size; | |
395 | accumulate_size = (accumulate_size + m_arg->len + 7) & ~7; | |
f42a0a33 | 396 | m_arg->contents = value_contents (arg); |
c906108c SS |
397 | } |
398 | ||
d2427a71 RH |
399 | /* Determine required argument register loads, loading an argument register |
400 | is expensive as it uses three ptrace calls. */ | |
401 | required_arg_regs = accumulate_size / 8; | |
402 | if (required_arg_regs > ALPHA_NUM_ARG_REGS) | |
403 | required_arg_regs = ALPHA_NUM_ARG_REGS; | |
c906108c | 404 | |
d2427a71 | 405 | /* Make room for the arguments on the stack. */ |
c88e30c0 RH |
406 | if (accumulate_size < sizeof(arg_reg_buffer)) |
407 | accumulate_size = 0; | |
408 | else | |
409 | accumulate_size -= sizeof(arg_reg_buffer); | |
d2427a71 | 410 | sp -= accumulate_size; |
c906108c | 411 | |
c88e30c0 | 412 | /* Keep sp aligned to a multiple of 16 as the ABI requires. */ |
d2427a71 | 413 | sp &= ~15; |
c906108c | 414 | |
d2427a71 RH |
415 | /* `Push' arguments on the stack. */ |
416 | for (i = nargs; m_arg--, --i >= 0;) | |
c906108c | 417 | { |
f42a0a33 | 418 | const gdb_byte *contents = m_arg->contents; |
c88e30c0 RH |
419 | int offset = m_arg->offset; |
420 | int len = m_arg->len; | |
421 | ||
422 | /* Copy the bytes destined for registers into arg_reg_buffer. */ | |
423 | if (offset < sizeof(arg_reg_buffer)) | |
424 | { | |
425 | if (offset + len <= sizeof(arg_reg_buffer)) | |
426 | { | |
427 | memcpy (arg_reg_buffer + offset, contents, len); | |
428 | continue; | |
429 | } | |
430 | else | |
431 | { | |
432 | int tlen = sizeof(arg_reg_buffer) - offset; | |
433 | memcpy (arg_reg_buffer + offset, contents, tlen); | |
434 | offset += tlen; | |
435 | contents += tlen; | |
436 | len -= tlen; | |
437 | } | |
438 | } | |
439 | ||
440 | /* Everything else goes to the stack. */ | |
441 | write_memory (sp + offset - sizeof(arg_reg_buffer), contents, len); | |
c906108c | 442 | } |
c88e30c0 | 443 | if (struct_return) |
e17a4113 UW |
444 | store_unsigned_integer (arg_reg_buffer, ALPHA_REGISTER_SIZE, |
445 | byte_order, struct_addr); | |
c906108c | 446 | |
d2427a71 RH |
447 | /* Load the argument registers. */ |
448 | for (i = 0; i < required_arg_regs; i++) | |
449 | { | |
09cc52fd RH |
450 | regcache_cooked_write (regcache, ALPHA_A0_REGNUM + i, |
451 | arg_reg_buffer + i*ALPHA_REGISTER_SIZE); | |
452 | regcache_cooked_write (regcache, ALPHA_FPA0_REGNUM + i, | |
453 | arg_reg_buffer + i*ALPHA_REGISTER_SIZE); | |
d2427a71 | 454 | } |
c906108c | 455 | |
09cc52fd RH |
456 | /* Finally, update the stack pointer. */ |
457 | regcache_cooked_write_signed (regcache, ALPHA_SP_REGNUM, sp); | |
458 | ||
c88e30c0 | 459 | return sp; |
c906108c SS |
460 | } |
461 | ||
5ec2bb99 RH |
462 | /* Extract from REGCACHE the value about to be returned from a function |
463 | and copy it into VALBUF. */ | |
d2427a71 | 464 | |
dc129d82 | 465 | static void |
5ec2bb99 | 466 | alpha_extract_return_value (struct type *valtype, struct regcache *regcache, |
5b819568 | 467 | gdb_byte *valbuf) |
140f9984 | 468 | { |
e17a4113 UW |
469 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
470 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
7b5e1cb3 | 471 | int length = TYPE_LENGTH (valtype); |
2a1ce6ec | 472 | gdb_byte raw_buffer[ALPHA_REGISTER_SIZE]; |
5ec2bb99 RH |
473 | ULONGEST l; |
474 | ||
475 | switch (TYPE_CODE (valtype)) | |
476 | { | |
477 | case TYPE_CODE_FLT: | |
7b5e1cb3 | 478 | switch (length) |
5ec2bb99 RH |
479 | { |
480 | case 4: | |
481 | regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, raw_buffer); | |
e17a4113 | 482 | alpha_sts (gdbarch, valbuf, raw_buffer); |
5ec2bb99 RH |
483 | break; |
484 | ||
485 | case 8: | |
486 | regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf); | |
487 | break; | |
488 | ||
24064b5c RH |
489 | case 16: |
490 | regcache_cooked_read_unsigned (regcache, ALPHA_V0_REGNUM, &l); | |
491 | read_memory (l, valbuf, 16); | |
492 | break; | |
493 | ||
5ec2bb99 | 494 | default: |
323e0a4a | 495 | internal_error (__FILE__, __LINE__, _("unknown floating point width")); |
5ec2bb99 RH |
496 | } |
497 | break; | |
498 | ||
7b5e1cb3 RH |
499 | case TYPE_CODE_COMPLEX: |
500 | switch (length) | |
501 | { | |
502 | case 8: | |
503 | /* ??? This isn't correct wrt the ABI, but it's what GCC does. */ | |
504 | regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf); | |
505 | break; | |
506 | ||
507 | case 16: | |
508 | regcache_cooked_read (regcache, ALPHA_FP0_REGNUM, valbuf); | |
2a1ce6ec | 509 | regcache_cooked_read (regcache, ALPHA_FP0_REGNUM + 1, valbuf + 8); |
7b5e1cb3 RH |
510 | break; |
511 | ||
512 | case 32: | |
513 | regcache_cooked_read_signed (regcache, ALPHA_V0_REGNUM, &l); | |
514 | read_memory (l, valbuf, 32); | |
515 | break; | |
516 | ||
517 | default: | |
323e0a4a | 518 | internal_error (__FILE__, __LINE__, _("unknown floating point width")); |
7b5e1cb3 RH |
519 | } |
520 | break; | |
521 | ||
5ec2bb99 RH |
522 | default: |
523 | /* Assume everything else degenerates to an integer. */ | |
524 | regcache_cooked_read_unsigned (regcache, ALPHA_V0_REGNUM, &l); | |
e17a4113 | 525 | store_unsigned_integer (valbuf, length, byte_order, l); |
5ec2bb99 RH |
526 | break; |
527 | } | |
140f9984 JT |
528 | } |
529 | ||
5ec2bb99 RH |
530 | /* Insert the given value into REGCACHE as if it was being |
531 | returned by a function. */ | |
0d056799 | 532 | |
d2427a71 | 533 | static void |
5ec2bb99 | 534 | alpha_store_return_value (struct type *valtype, struct regcache *regcache, |
5b819568 | 535 | const gdb_byte *valbuf) |
c906108c | 536 | { |
df4df182 | 537 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
d2427a71 | 538 | int length = TYPE_LENGTH (valtype); |
2a1ce6ec | 539 | gdb_byte raw_buffer[ALPHA_REGISTER_SIZE]; |
5ec2bb99 | 540 | ULONGEST l; |
d2427a71 | 541 | |
5ec2bb99 | 542 | switch (TYPE_CODE (valtype)) |
c906108c | 543 | { |
5ec2bb99 RH |
544 | case TYPE_CODE_FLT: |
545 | switch (length) | |
546 | { | |
547 | case 4: | |
e17a4113 | 548 | alpha_lds (gdbarch, raw_buffer, valbuf); |
f75d70cc RH |
549 | regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, raw_buffer); |
550 | break; | |
5ec2bb99 RH |
551 | |
552 | case 8: | |
553 | regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf); | |
554 | break; | |
555 | ||
24064b5c RH |
556 | case 16: |
557 | /* FIXME: 128-bit long doubles are returned like structures: | |
558 | by writing into indirect storage provided by the caller | |
559 | as the first argument. */ | |
323e0a4a | 560 | error (_("Cannot set a 128-bit long double return value.")); |
24064b5c | 561 | |
5ec2bb99 | 562 | default: |
323e0a4a | 563 | internal_error (__FILE__, __LINE__, _("unknown floating point width")); |
5ec2bb99 RH |
564 | } |
565 | break; | |
d2427a71 | 566 | |
7b5e1cb3 RH |
567 | case TYPE_CODE_COMPLEX: |
568 | switch (length) | |
569 | { | |
570 | case 8: | |
571 | /* ??? This isn't correct wrt the ABI, but it's what GCC does. */ | |
572 | regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf); | |
573 | break; | |
574 | ||
575 | case 16: | |
576 | regcache_cooked_write (regcache, ALPHA_FP0_REGNUM, valbuf); | |
2a1ce6ec | 577 | regcache_cooked_write (regcache, ALPHA_FP0_REGNUM + 1, valbuf + 8); |
7b5e1cb3 RH |
578 | break; |
579 | ||
580 | case 32: | |
581 | /* FIXME: 128-bit long doubles are returned like structures: | |
582 | by writing into indirect storage provided by the caller | |
583 | as the first argument. */ | |
323e0a4a | 584 | error (_("Cannot set a 128-bit long double return value.")); |
7b5e1cb3 RH |
585 | |
586 | default: | |
323e0a4a | 587 | internal_error (__FILE__, __LINE__, _("unknown floating point width")); |
7b5e1cb3 RH |
588 | } |
589 | break; | |
590 | ||
5ec2bb99 RH |
591 | default: |
592 | /* Assume everything else degenerates to an integer. */ | |
0ede8eca RH |
593 | /* 32-bit values must be sign-extended to 64 bits |
594 | even if the base data type is unsigned. */ | |
595 | if (length == 4) | |
df4df182 | 596 | valtype = builtin_type (gdbarch)->builtin_int32; |
5ec2bb99 RH |
597 | l = unpack_long (valtype, valbuf); |
598 | regcache_cooked_write_unsigned (regcache, ALPHA_V0_REGNUM, l); | |
599 | break; | |
600 | } | |
c906108c SS |
601 | } |
602 | ||
9823e921 | 603 | static enum return_value_convention |
c055b101 CV |
604 | alpha_return_value (struct gdbarch *gdbarch, struct type *func_type, |
605 | struct type *type, struct regcache *regcache, | |
606 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
9823e921 RH |
607 | { |
608 | enum type_code code = TYPE_CODE (type); | |
609 | ||
610 | if ((code == TYPE_CODE_STRUCT | |
611 | || code == TYPE_CODE_UNION | |
612 | || code == TYPE_CODE_ARRAY) | |
613 | && gdbarch_tdep (gdbarch)->return_in_memory (type)) | |
614 | { | |
615 | if (readbuf) | |
616 | { | |
617 | ULONGEST addr; | |
618 | regcache_raw_read_unsigned (regcache, ALPHA_V0_REGNUM, &addr); | |
619 | read_memory (addr, readbuf, TYPE_LENGTH (type)); | |
620 | } | |
621 | ||
622 | return RETURN_VALUE_ABI_RETURNS_ADDRESS; | |
623 | } | |
624 | ||
625 | if (readbuf) | |
626 | alpha_extract_return_value (type, regcache, readbuf); | |
627 | if (writebuf) | |
628 | alpha_store_return_value (type, regcache, writebuf); | |
629 | ||
630 | return RETURN_VALUE_REGISTER_CONVENTION; | |
631 | } | |
632 | ||
633 | static int | |
634 | alpha_return_in_memory_always (struct type *type) | |
635 | { | |
636 | return 1; | |
637 | } | |
d2427a71 | 638 | \f |
2a1ce6ec | 639 | static const gdb_byte * |
67d57894 | 640 | alpha_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pc, int *len) |
c906108c | 641 | { |
2a1ce6ec | 642 | static const gdb_byte break_insn[] = { 0x80, 0, 0, 0 }; /* call_pal bpt */ |
c906108c | 643 | |
2a1ce6ec MK |
644 | *len = sizeof(break_insn); |
645 | return break_insn; | |
d2427a71 | 646 | } |
c906108c | 647 | |
d2427a71 RH |
648 | \f |
649 | /* This returns the PC of the first insn after the prologue. | |
650 | If we can't find the prologue, then return 0. */ | |
c906108c | 651 | |
d2427a71 RH |
652 | CORE_ADDR |
653 | alpha_after_prologue (CORE_ADDR pc) | |
c906108c | 654 | { |
d2427a71 RH |
655 | struct symtab_and_line sal; |
656 | CORE_ADDR func_addr, func_end; | |
c906108c | 657 | |
d2427a71 | 658 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) |
c5aa993b | 659 | return 0; |
c906108c | 660 | |
d2427a71 RH |
661 | sal = find_pc_line (func_addr, 0); |
662 | if (sal.end < func_end) | |
663 | return sal.end; | |
c5aa993b | 664 | |
d2427a71 RH |
665 | /* The line after the prologue is after the end of the function. In this |
666 | case, tell the caller to find the prologue the hard way. */ | |
667 | return 0; | |
c906108c SS |
668 | } |
669 | ||
d2427a71 RH |
670 | /* Read an instruction from memory at PC, looking through breakpoints. */ |
671 | ||
672 | unsigned int | |
e17a4113 | 673 | alpha_read_insn (struct gdbarch *gdbarch, CORE_ADDR pc) |
c906108c | 674 | { |
e17a4113 | 675 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
e8d2d628 | 676 | gdb_byte buf[ALPHA_INSN_SIZE]; |
d2427a71 | 677 | int status; |
c5aa993b | 678 | |
8defab1a | 679 | status = target_read_memory (pc, buf, sizeof (buf)); |
d2427a71 RH |
680 | if (status) |
681 | memory_error (status, pc); | |
e17a4113 | 682 | return extract_unsigned_integer (buf, sizeof (buf), byte_order); |
d2427a71 | 683 | } |
c5aa993b | 684 | |
d2427a71 RH |
685 | /* To skip prologues, I use this predicate. Returns either PC itself |
686 | if the code at PC does not look like a function prologue; otherwise | |
687 | returns an address that (if we're lucky) follows the prologue. If | |
688 | LENIENT, then we must skip everything which is involved in setting | |
689 | up the frame (it's OK to skip more, just so long as we don't skip | |
690 | anything which might clobber the registers which are being saved. */ | |
c906108c | 691 | |
d2427a71 | 692 | static CORE_ADDR |
6093d2eb | 693 | alpha_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) |
d2427a71 RH |
694 | { |
695 | unsigned long inst; | |
696 | int offset; | |
697 | CORE_ADDR post_prologue_pc; | |
e8d2d628 | 698 | gdb_byte buf[ALPHA_INSN_SIZE]; |
c906108c | 699 | |
d2427a71 RH |
700 | /* Silently return the unaltered pc upon memory errors. |
701 | This could happen on OSF/1 if decode_line_1 tries to skip the | |
702 | prologue for quickstarted shared library functions when the | |
703 | shared library is not yet mapped in. | |
704 | Reading target memory is slow over serial lines, so we perform | |
705 | this check only if the target has shared libraries (which all | |
706 | Alpha targets do). */ | |
e8d2d628 | 707 | if (target_read_memory (pc, buf, sizeof (buf))) |
d2427a71 | 708 | return pc; |
c906108c | 709 | |
d2427a71 RH |
710 | /* See if we can determine the end of the prologue via the symbol table. |
711 | If so, then return either PC, or the PC after the prologue, whichever | |
712 | is greater. */ | |
c906108c | 713 | |
d2427a71 RH |
714 | post_prologue_pc = alpha_after_prologue (pc); |
715 | if (post_prologue_pc != 0) | |
716 | return max (pc, post_prologue_pc); | |
c906108c | 717 | |
d2427a71 RH |
718 | /* Can't determine prologue from the symbol table, need to examine |
719 | instructions. */ | |
dc1b0db2 | 720 | |
d2427a71 RH |
721 | /* Skip the typical prologue instructions. These are the stack adjustment |
722 | instruction and the instructions that save registers on the stack | |
723 | or in the gcc frame. */ | |
e8d2d628 | 724 | for (offset = 0; offset < 100; offset += ALPHA_INSN_SIZE) |
d2427a71 | 725 | { |
e17a4113 | 726 | inst = alpha_read_insn (gdbarch, pc + offset); |
c906108c | 727 | |
d2427a71 RH |
728 | if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */ |
729 | continue; | |
730 | if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */ | |
731 | continue; | |
732 | if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */ | |
733 | continue; | |
734 | if ((inst & 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */ | |
735 | continue; | |
c906108c | 736 | |
d2427a71 RH |
737 | if (((inst & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */ |
738 | || (inst & 0xfc1f0000) == 0x9c1e0000) /* stt reg,n($sp) */ | |
739 | && (inst & 0x03e00000) != 0x03e00000) /* reg != $zero */ | |
740 | continue; | |
c906108c | 741 | |
d2427a71 RH |
742 | if (inst == 0x47de040f) /* bis sp,sp,fp */ |
743 | continue; | |
744 | if (inst == 0x47fe040f) /* bis zero,sp,fp */ | |
745 | continue; | |
c906108c | 746 | |
d2427a71 | 747 | break; |
c906108c | 748 | } |
d2427a71 RH |
749 | return pc + offset; |
750 | } | |
c906108c | 751 | |
d2427a71 RH |
752 | \f |
753 | /* Figure out where the longjmp will land. | |
754 | We expect the first arg to be a pointer to the jmp_buf structure from | |
755 | which we extract the PC (JB_PC) that we will land at. The PC is copied | |
756 | into the "pc". This routine returns true on success. */ | |
c906108c SS |
757 | |
758 | static int | |
60ade65d | 759 | alpha_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) |
c906108c | 760 | { |
e17a4113 UW |
761 | struct gdbarch *gdbarch = get_frame_arch (frame); |
762 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
763 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
d2427a71 | 764 | CORE_ADDR jb_addr; |
2a1ce6ec | 765 | gdb_byte raw_buffer[ALPHA_REGISTER_SIZE]; |
c906108c | 766 | |
60ade65d | 767 | jb_addr = get_frame_register_unsigned (frame, ALPHA_A0_REGNUM); |
c906108c | 768 | |
d2427a71 RH |
769 | if (target_read_memory (jb_addr + (tdep->jb_pc * tdep->jb_elt_size), |
770 | raw_buffer, tdep->jb_elt_size)) | |
c906108c | 771 | return 0; |
d2427a71 | 772 | |
e17a4113 | 773 | *pc = extract_unsigned_integer (raw_buffer, tdep->jb_elt_size, byte_order); |
d2427a71 | 774 | return 1; |
c906108c SS |
775 | } |
776 | ||
d2427a71 RH |
777 | \f |
778 | /* Frame unwinder for signal trampolines. We use alpha tdep bits that | |
779 | describe the location and shape of the sigcontext structure. After | |
780 | that, all registers are in memory, so it's easy. */ | |
781 | /* ??? Shouldn't we be able to do this generically, rather than with | |
782 | OSABI data specific to Alpha? */ | |
783 | ||
784 | struct alpha_sigtramp_unwind_cache | |
c906108c | 785 | { |
d2427a71 RH |
786 | CORE_ADDR sigcontext_addr; |
787 | }; | |
c906108c | 788 | |
d2427a71 | 789 | static struct alpha_sigtramp_unwind_cache * |
6834c9bb | 790 | alpha_sigtramp_frame_unwind_cache (struct frame_info *this_frame, |
d2427a71 RH |
791 | void **this_prologue_cache) |
792 | { | |
793 | struct alpha_sigtramp_unwind_cache *info; | |
794 | struct gdbarch_tdep *tdep; | |
c906108c | 795 | |
d2427a71 RH |
796 | if (*this_prologue_cache) |
797 | return *this_prologue_cache; | |
c906108c | 798 | |
d2427a71 RH |
799 | info = FRAME_OBSTACK_ZALLOC (struct alpha_sigtramp_unwind_cache); |
800 | *this_prologue_cache = info; | |
c906108c | 801 | |
6834c9bb JB |
802 | tdep = gdbarch_tdep (get_frame_arch (this_frame)); |
803 | info->sigcontext_addr = tdep->sigcontext_addr (this_frame); | |
c906108c | 804 | |
d2427a71 | 805 | return info; |
c906108c SS |
806 | } |
807 | ||
138e7be5 MK |
808 | /* Return the address of REGNUM in a sigtramp frame. Since this is |
809 | all arithmetic, it doesn't seem worthwhile to cache it. */ | |
c5aa993b | 810 | |
d2427a71 | 811 | static CORE_ADDR |
be8626e0 MD |
812 | alpha_sigtramp_register_address (struct gdbarch *gdbarch, |
813 | CORE_ADDR sigcontext_addr, int regnum) | |
d2427a71 | 814 | { |
be8626e0 | 815 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
138e7be5 MK |
816 | |
817 | if (regnum >= 0 && regnum < 32) | |
818 | return sigcontext_addr + tdep->sc_regs_offset + regnum * 8; | |
819 | else if (regnum >= ALPHA_FP0_REGNUM && regnum < ALPHA_FP0_REGNUM + 32) | |
820 | return sigcontext_addr + tdep->sc_fpregs_offset + regnum * 8; | |
821 | else if (regnum == ALPHA_PC_REGNUM) | |
822 | return sigcontext_addr + tdep->sc_pc_offset; | |
c5aa993b | 823 | |
d2427a71 | 824 | return 0; |
c906108c SS |
825 | } |
826 | ||
d2427a71 RH |
827 | /* Given a GDB frame, determine the address of the calling function's |
828 | frame. This will be used to create a new GDB frame struct. */ | |
140f9984 | 829 | |
dc129d82 | 830 | static void |
6834c9bb | 831 | alpha_sigtramp_frame_this_id (struct frame_info *this_frame, |
d2427a71 RH |
832 | void **this_prologue_cache, |
833 | struct frame_id *this_id) | |
c906108c | 834 | { |
6834c9bb | 835 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
be8626e0 | 836 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
d2427a71 | 837 | struct alpha_sigtramp_unwind_cache *info |
6834c9bb | 838 | = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache); |
d2427a71 RH |
839 | CORE_ADDR stack_addr, code_addr; |
840 | ||
841 | /* If the OSABI couldn't locate the sigcontext, give up. */ | |
842 | if (info->sigcontext_addr == 0) | |
843 | return; | |
844 | ||
845 | /* If we have dynamic signal trampolines, find their start. | |
846 | If we do not, then we must assume there is a symbol record | |
847 | that can provide the start address. */ | |
d2427a71 | 848 | if (tdep->dynamic_sigtramp_offset) |
c906108c | 849 | { |
d2427a71 | 850 | int offset; |
6834c9bb | 851 | code_addr = get_frame_pc (this_frame); |
e17a4113 | 852 | offset = tdep->dynamic_sigtramp_offset (gdbarch, code_addr); |
d2427a71 RH |
853 | if (offset >= 0) |
854 | code_addr -= offset; | |
c906108c | 855 | else |
d2427a71 | 856 | code_addr = 0; |
c906108c | 857 | } |
d2427a71 | 858 | else |
6834c9bb | 859 | code_addr = get_frame_func (this_frame); |
c906108c | 860 | |
d2427a71 | 861 | /* The stack address is trivially read from the sigcontext. */ |
be8626e0 | 862 | stack_addr = alpha_sigtramp_register_address (gdbarch, info->sigcontext_addr, |
d2427a71 | 863 | ALPHA_SP_REGNUM); |
6834c9bb | 864 | stack_addr = get_frame_memory_unsigned (this_frame, stack_addr, |
b21fd293 | 865 | ALPHA_REGISTER_SIZE); |
c906108c | 866 | |
d2427a71 | 867 | *this_id = frame_id_build (stack_addr, code_addr); |
c906108c SS |
868 | } |
869 | ||
d2427a71 | 870 | /* Retrieve the value of REGNUM in FRAME. Don't give up! */ |
c906108c | 871 | |
6834c9bb JB |
872 | static struct value * |
873 | alpha_sigtramp_frame_prev_register (struct frame_info *this_frame, | |
874 | void **this_prologue_cache, int regnum) | |
c906108c | 875 | { |
d2427a71 | 876 | struct alpha_sigtramp_unwind_cache *info |
6834c9bb | 877 | = alpha_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache); |
d2427a71 | 878 | CORE_ADDR addr; |
c906108c | 879 | |
d2427a71 | 880 | if (info->sigcontext_addr != 0) |
c906108c | 881 | { |
d2427a71 | 882 | /* All integer and fp registers are stored in memory. */ |
6834c9bb | 883 | addr = alpha_sigtramp_register_address (get_frame_arch (this_frame), |
be8626e0 | 884 | info->sigcontext_addr, regnum); |
d2427a71 | 885 | if (addr != 0) |
6834c9bb | 886 | return frame_unwind_got_memory (this_frame, regnum, addr); |
c906108c SS |
887 | } |
888 | ||
d2427a71 RH |
889 | /* This extra register may actually be in the sigcontext, but our |
890 | current description of it in alpha_sigtramp_frame_unwind_cache | |
891 | doesn't include it. Too bad. Fall back on whatever's in the | |
892 | outer frame. */ | |
6834c9bb | 893 | return frame_unwind_got_register (this_frame, regnum, regnum); |
d2427a71 | 894 | } |
c906108c | 895 | |
6834c9bb JB |
896 | static int |
897 | alpha_sigtramp_frame_sniffer (const struct frame_unwind *self, | |
898 | struct frame_info *this_frame, | |
899 | void **this_prologue_cache) | |
d2427a71 | 900 | { |
6834c9bb JB |
901 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
902 | CORE_ADDR pc = get_frame_pc (this_frame); | |
d2427a71 | 903 | char *name; |
c906108c | 904 | |
f2524b93 AC |
905 | /* NOTE: cagney/2004-04-30: Do not copy/clone this code. Instead |
906 | look at tramp-frame.h and other simplier per-architecture | |
907 | sigtramp unwinders. */ | |
908 | ||
909 | /* We shouldn't even bother to try if the OSABI didn't register a | |
910 | sigcontext_addr handler or pc_in_sigtramp hander. */ | |
ec7cc0e8 | 911 | if (gdbarch_tdep (gdbarch)->sigcontext_addr == NULL) |
6834c9bb | 912 | return 0; |
ec7cc0e8 | 913 | if (gdbarch_tdep (gdbarch)->pc_in_sigtramp == NULL) |
6834c9bb | 914 | return 0; |
c906108c | 915 | |
d2427a71 RH |
916 | /* Otherwise we should be in a signal frame. */ |
917 | find_pc_partial_function (pc, &name, NULL, NULL); | |
e17a4113 | 918 | if (gdbarch_tdep (gdbarch)->pc_in_sigtramp (gdbarch, pc, name)) |
6834c9bb | 919 | return 1; |
c906108c | 920 | |
6834c9bb | 921 | return 0; |
c906108c | 922 | } |
6834c9bb JB |
923 | |
924 | static const struct frame_unwind alpha_sigtramp_frame_unwind = { | |
925 | SIGTRAMP_FRAME, | |
926 | alpha_sigtramp_frame_this_id, | |
927 | alpha_sigtramp_frame_prev_register, | |
928 | NULL, | |
929 | alpha_sigtramp_frame_sniffer | |
930 | }; | |
931 | ||
d2427a71 | 932 | \f |
c906108c | 933 | |
d2427a71 RH |
934 | /* Heuristic_proc_start may hunt through the text section for a long |
935 | time across a 2400 baud serial line. Allows the user to limit this | |
936 | search. */ | |
937 | static unsigned int heuristic_fence_post = 0; | |
c906108c | 938 | |
d2427a71 RH |
939 | /* Attempt to locate the start of the function containing PC. We assume that |
940 | the previous function ends with an about_to_return insn. Not foolproof by | |
941 | any means, since gcc is happy to put the epilogue in the middle of a | |
942 | function. But we're guessing anyway... */ | |
c906108c | 943 | |
d2427a71 | 944 | static CORE_ADDR |
be8626e0 | 945 | alpha_heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc) |
d2427a71 | 946 | { |
be8626e0 | 947 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
d2427a71 RH |
948 | CORE_ADDR last_non_nop = pc; |
949 | CORE_ADDR fence = pc - heuristic_fence_post; | |
950 | CORE_ADDR orig_pc = pc; | |
fbe586ae | 951 | CORE_ADDR func; |
d6b48e9c | 952 | struct inferior *inf; |
9e0b60a8 | 953 | |
d2427a71 RH |
954 | if (pc == 0) |
955 | return 0; | |
9e0b60a8 | 956 | |
fbe586ae RH |
957 | /* First see if we can find the start of the function from minimal |
958 | symbol information. This can succeed with a binary that doesn't | |
959 | have debug info, but hasn't been stripped. */ | |
960 | func = get_pc_function_start (pc); | |
961 | if (func) | |
962 | return func; | |
963 | ||
d2427a71 RH |
964 | if (heuristic_fence_post == UINT_MAX |
965 | || fence < tdep->vm_min_address) | |
966 | fence = tdep->vm_min_address; | |
c906108c | 967 | |
d2427a71 RH |
968 | /* Search back for previous return; also stop at a 0, which might be |
969 | seen for instance before the start of a code section. Don't include | |
970 | nops, since this usually indicates padding between functions. */ | |
e8d2d628 | 971 | for (pc -= ALPHA_INSN_SIZE; pc >= fence; pc -= ALPHA_INSN_SIZE) |
c906108c | 972 | { |
e17a4113 | 973 | unsigned int insn = alpha_read_insn (gdbarch, pc); |
d2427a71 | 974 | switch (insn) |
c906108c | 975 | { |
d2427a71 RH |
976 | case 0: /* invalid insn */ |
977 | case 0x6bfa8001: /* ret $31,($26),1 */ | |
978 | return last_non_nop; | |
979 | ||
980 | case 0x2ffe0000: /* unop: ldq_u $31,0($30) */ | |
981 | case 0x47ff041f: /* nop: bis $31,$31,$31 */ | |
982 | break; | |
983 | ||
984 | default: | |
985 | last_non_nop = pc; | |
986 | break; | |
c906108c | 987 | } |
d2427a71 | 988 | } |
c906108c | 989 | |
d6b48e9c PA |
990 | inf = current_inferior (); |
991 | ||
d2427a71 RH |
992 | /* It's not clear to me why we reach this point when stopping quietly, |
993 | but with this test, at least we don't print out warnings for every | |
994 | child forked (eg, on decstation). 22apr93 rich@cygnus.com. */ | |
d6b48e9c | 995 | if (inf->stop_soon == NO_STOP_QUIETLY) |
d2427a71 RH |
996 | { |
997 | static int blurb_printed = 0; | |
c906108c | 998 | |
d2427a71 | 999 | if (fence == tdep->vm_min_address) |
323e0a4a | 1000 | warning (_("Hit beginning of text section without finding \ |
5af949e3 | 1001 | enclosing function for address %s"), paddress (gdbarch, orig_pc)); |
c906108c | 1002 | else |
323e0a4a | 1003 | warning (_("Hit heuristic-fence-post without finding \ |
5af949e3 | 1004 | enclosing function for address %s"), paddress (gdbarch, orig_pc)); |
c906108c | 1005 | |
d2427a71 RH |
1006 | if (!blurb_printed) |
1007 | { | |
323e0a4a | 1008 | printf_filtered (_("\ |
d2427a71 RH |
1009 | This warning occurs if you are debugging a function without any symbols\n\ |
1010 | (for example, in a stripped executable). In that case, you may wish to\n\ | |
1011 | increase the size of the search with the `set heuristic-fence-post' command.\n\ | |
1012 | \n\ | |
1013 | Otherwise, you told GDB there was a function where there isn't one, or\n\ | |
323e0a4a | 1014 | (more likely) you have encountered a bug in GDB.\n")); |
d2427a71 RH |
1015 | blurb_printed = 1; |
1016 | } | |
1017 | } | |
c906108c | 1018 | |
d2427a71 RH |
1019 | return 0; |
1020 | } | |
c906108c | 1021 | |
07ea644b MD |
1022 | /* Fallback alpha frame unwinder. Uses instruction scanning and knows |
1023 | something about the traditional layout of alpha stack frames. */ | |
1024 | ||
1025 | struct alpha_heuristic_unwind_cache | |
1026 | { | |
1027 | CORE_ADDR vfp; | |
1028 | CORE_ADDR start_pc; | |
1029 | struct trad_frame_saved_reg *saved_regs; | |
1030 | int return_reg; | |
1031 | }; | |
1032 | ||
3a48e6ff JG |
1033 | /* If a probing loop sequence starts at PC, simulate it and compute |
1034 | FRAME_SIZE and PC after its execution. Otherwise, return with PC and | |
1035 | FRAME_SIZE unchanged. */ | |
1036 | ||
1037 | static void | |
1038 | alpha_heuristic_analyze_probing_loop (struct gdbarch *gdbarch, CORE_ADDR *pc, | |
1039 | int *frame_size) | |
1040 | { | |
1041 | CORE_ADDR cur_pc = *pc; | |
1042 | int cur_frame_size = *frame_size; | |
1043 | int nb_of_iterations, reg_index, reg_probe; | |
1044 | unsigned int insn; | |
1045 | ||
1046 | /* The following pattern is recognized as a probing loop: | |
1047 | ||
1048 | lda REG_INDEX,NB_OF_ITERATIONS | |
1049 | lda REG_PROBE,<immediate>(sp) | |
1050 | ||
1051 | LOOP_START: | |
1052 | stq zero,<immediate>(REG_PROBE) | |
1053 | subq REG_INDEX,0x1,REG_INDEX | |
1054 | lda REG_PROBE,<immediate>(REG_PROBE) | |
1055 | bne REG_INDEX, LOOP_START | |
1056 | ||
1057 | lda sp,<immediate>(REG_PROBE) | |
1058 | ||
1059 | If anything different is found, the function returns without | |
1060 | changing PC and FRAME_SIZE. Otherwise, PC will point immediately | |
1061 | after this sequence, and FRAME_SIZE will be updated. | |
1062 | */ | |
1063 | ||
1064 | /* lda REG_INDEX,NB_OF_ITERATIONS */ | |
1065 | ||
1066 | insn = alpha_read_insn (gdbarch, cur_pc); | |
1067 | if (INSN_OPCODE (insn) != lda_opcode) | |
1068 | return; | |
1069 | reg_index = MEM_RA (insn); | |
1070 | nb_of_iterations = MEM_DISP (insn); | |
1071 | ||
1072 | /* lda REG_PROBE,<immediate>(sp) */ | |
1073 | ||
1074 | cur_pc += ALPHA_INSN_SIZE; | |
1075 | insn = alpha_read_insn (gdbarch, cur_pc); | |
1076 | if (INSN_OPCODE (insn) != lda_opcode | |
1077 | || MEM_RB (insn) != ALPHA_SP_REGNUM) | |
1078 | return; | |
1079 | reg_probe = MEM_RA (insn); | |
1080 | cur_frame_size -= MEM_DISP (insn); | |
1081 | ||
1082 | /* stq zero,<immediate>(REG_PROBE) */ | |
1083 | ||
1084 | cur_pc += ALPHA_INSN_SIZE; | |
1085 | insn = alpha_read_insn (gdbarch, cur_pc); | |
1086 | if (INSN_OPCODE (insn) != stq_opcode | |
1087 | || MEM_RA (insn) != 0x1f | |
1088 | || MEM_RB (insn) != reg_probe) | |
1089 | return; | |
1090 | ||
1091 | /* subq REG_INDEX,0x1,REG_INDEX */ | |
1092 | ||
1093 | cur_pc += ALPHA_INSN_SIZE; | |
1094 | insn = alpha_read_insn (gdbarch, cur_pc); | |
1095 | if (INSN_OPCODE (insn) != subq_opcode | |
1096 | || !OPR_HAS_IMMEDIATE (insn) | |
1097 | || OPR_FUNCTION (insn) != subq_function | |
1098 | || OPR_LIT(insn) != 1 | |
1099 | || OPR_RA (insn) != reg_index | |
1100 | || OPR_RC (insn) != reg_index) | |
1101 | return; | |
1102 | ||
1103 | /* lda REG_PROBE,<immediate>(REG_PROBE) */ | |
1104 | ||
1105 | cur_pc += ALPHA_INSN_SIZE; | |
1106 | insn = alpha_read_insn (gdbarch, cur_pc); | |
1107 | if (INSN_OPCODE (insn) != lda_opcode | |
1108 | || MEM_RA (insn) != reg_probe | |
1109 | || MEM_RB (insn) != reg_probe) | |
1110 | return; | |
1111 | cur_frame_size -= MEM_DISP (insn) * nb_of_iterations; | |
1112 | ||
1113 | /* bne REG_INDEX, LOOP_START */ | |
1114 | ||
1115 | cur_pc += ALPHA_INSN_SIZE; | |
1116 | insn = alpha_read_insn (gdbarch, cur_pc); | |
1117 | if (INSN_OPCODE (insn) != bne_opcode | |
1118 | || MEM_RA (insn) != reg_index) | |
1119 | return; | |
1120 | ||
1121 | /* lda sp,<immediate>(REG_PROBE) */ | |
1122 | ||
1123 | cur_pc += ALPHA_INSN_SIZE; | |
1124 | insn = alpha_read_insn (gdbarch, cur_pc); | |
1125 | if (INSN_OPCODE (insn) != lda_opcode | |
1126 | || MEM_RA (insn) != ALPHA_SP_REGNUM | |
1127 | || MEM_RB (insn) != reg_probe) | |
1128 | return; | |
1129 | cur_frame_size -= MEM_DISP (insn); | |
1130 | ||
1131 | *pc = cur_pc; | |
1132 | *frame_size = cur_frame_size; | |
1133 | } | |
1134 | ||
fbe586ae | 1135 | static struct alpha_heuristic_unwind_cache * |
6834c9bb | 1136 | alpha_heuristic_frame_unwind_cache (struct frame_info *this_frame, |
d2427a71 RH |
1137 | void **this_prologue_cache, |
1138 | CORE_ADDR start_pc) | |
1139 | { | |
6834c9bb | 1140 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
d2427a71 RH |
1141 | struct alpha_heuristic_unwind_cache *info; |
1142 | ULONGEST val; | |
1143 | CORE_ADDR limit_pc, cur_pc; | |
1144 | int frame_reg, frame_size, return_reg, reg; | |
c906108c | 1145 | |
d2427a71 RH |
1146 | if (*this_prologue_cache) |
1147 | return *this_prologue_cache; | |
c906108c | 1148 | |
d2427a71 RH |
1149 | info = FRAME_OBSTACK_ZALLOC (struct alpha_heuristic_unwind_cache); |
1150 | *this_prologue_cache = info; | |
6834c9bb | 1151 | info->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
c906108c | 1152 | |
6834c9bb | 1153 | limit_pc = get_frame_pc (this_frame); |
d2427a71 | 1154 | if (start_pc == 0) |
be8626e0 | 1155 | start_pc = alpha_heuristic_proc_start (gdbarch, limit_pc); |
d2427a71 | 1156 | info->start_pc = start_pc; |
c906108c | 1157 | |
d2427a71 RH |
1158 | frame_reg = ALPHA_SP_REGNUM; |
1159 | frame_size = 0; | |
1160 | return_reg = -1; | |
c906108c | 1161 | |
d2427a71 RH |
1162 | /* If we've identified a likely place to start, do code scanning. */ |
1163 | if (start_pc != 0) | |
c5aa993b | 1164 | { |
d2427a71 RH |
1165 | /* Limit the forward search to 50 instructions. */ |
1166 | if (start_pc + 200 < limit_pc) | |
1167 | limit_pc = start_pc + 200; | |
c5aa993b | 1168 | |
e8d2d628 | 1169 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += ALPHA_INSN_SIZE) |
d2427a71 | 1170 | { |
e17a4113 | 1171 | unsigned int word = alpha_read_insn (gdbarch, cur_pc); |
c5aa993b | 1172 | |
d2427a71 RH |
1173 | if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */ |
1174 | { | |
1175 | if (word & 0x8000) | |
1176 | { | |
1177 | /* Consider only the first stack allocation instruction | |
1178 | to contain the static size of the frame. */ | |
1179 | if (frame_size == 0) | |
1180 | frame_size = (-word) & 0xffff; | |
1181 | } | |
1182 | else | |
1183 | { | |
1184 | /* Exit loop if a positive stack adjustment is found, which | |
1185 | usually means that the stack cleanup code in the function | |
1186 | epilogue is reached. */ | |
1187 | break; | |
1188 | } | |
1189 | } | |
1190 | else if ((word & 0xfc1f0000) == 0xb41e0000) /* stq reg,n($sp) */ | |
1191 | { | |
1192 | reg = (word & 0x03e00000) >> 21; | |
1193 | ||
d15bfd3a AC |
1194 | /* Ignore this instruction if we have already encountered |
1195 | an instruction saving the same register earlier in the | |
1196 | function code. The current instruction does not tell | |
1197 | us where the original value upon function entry is saved. | |
1198 | All it says is that the function we are scanning reused | |
1199 | that register for some computation of its own, and is now | |
1200 | saving its result. */ | |
07ea644b | 1201 | if (trad_frame_addr_p(info->saved_regs, reg)) |
d15bfd3a AC |
1202 | continue; |
1203 | ||
d2427a71 RH |
1204 | if (reg == 31) |
1205 | continue; | |
1206 | ||
1207 | /* Do not compute the address where the register was saved yet, | |
1208 | because we don't know yet if the offset will need to be | |
1209 | relative to $sp or $fp (we can not compute the address | |
1210 | relative to $sp if $sp is updated during the execution of | |
1211 | the current subroutine, for instance when doing some alloca). | |
1212 | So just store the offset for the moment, and compute the | |
1213 | address later when we know whether this frame has a frame | |
1214 | pointer or not. */ | |
1215 | /* Hack: temporarily add one, so that the offset is non-zero | |
1216 | and we can tell which registers have save offsets below. */ | |
07ea644b | 1217 | info->saved_regs[reg].addr = (word & 0xffff) + 1; |
d2427a71 RH |
1218 | |
1219 | /* Starting with OSF/1-3.2C, the system libraries are shipped | |
1220 | without local symbols, but they still contain procedure | |
1221 | descriptors without a symbol reference. GDB is currently | |
1222 | unable to find these procedure descriptors and uses | |
1223 | heuristic_proc_desc instead. | |
1224 | As some low level compiler support routines (__div*, __add*) | |
1225 | use a non-standard return address register, we have to | |
1226 | add some heuristics to determine the return address register, | |
1227 | or stepping over these routines will fail. | |
1228 | Usually the return address register is the first register | |
1229 | saved on the stack, but assembler optimization might | |
1230 | rearrange the register saves. | |
1231 | So we recognize only a few registers (t7, t9, ra) within | |
1232 | the procedure prologue as valid return address registers. | |
1233 | If we encounter a return instruction, we extract the | |
1234 | the return address register from it. | |
1235 | ||
1236 | FIXME: Rewriting GDB to access the procedure descriptors, | |
1237 | e.g. via the minimal symbol table, might obviate this hack. */ | |
1238 | if (return_reg == -1 | |
1239 | && cur_pc < (start_pc + 80) | |
1240 | && (reg == ALPHA_T7_REGNUM | |
1241 | || reg == ALPHA_T9_REGNUM | |
1242 | || reg == ALPHA_RA_REGNUM)) | |
1243 | return_reg = reg; | |
1244 | } | |
1245 | else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */ | |
1246 | return_reg = (word >> 16) & 0x1f; | |
1247 | else if (word == 0x47de040f) /* bis sp,sp,fp */ | |
1248 | frame_reg = ALPHA_GCC_FP_REGNUM; | |
1249 | else if (word == 0x47fe040f) /* bis zero,sp,fp */ | |
1250 | frame_reg = ALPHA_GCC_FP_REGNUM; | |
3a48e6ff JG |
1251 | |
1252 | alpha_heuristic_analyze_probing_loop (gdbarch, &cur_pc, &frame_size); | |
d2427a71 | 1253 | } |
c5aa993b | 1254 | |
d2427a71 RH |
1255 | /* If we haven't found a valid return address register yet, keep |
1256 | searching in the procedure prologue. */ | |
1257 | if (return_reg == -1) | |
1258 | { | |
1259 | while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80)) | |
1260 | { | |
e17a4113 | 1261 | unsigned int word = alpha_read_insn (gdbarch, cur_pc); |
c5aa993b | 1262 | |
d2427a71 RH |
1263 | if ((word & 0xfc1f0000) == 0xb41e0000) /* stq reg,n($sp) */ |
1264 | { | |
1265 | reg = (word & 0x03e00000) >> 21; | |
1266 | if (reg == ALPHA_T7_REGNUM | |
1267 | || reg == ALPHA_T9_REGNUM | |
1268 | || reg == ALPHA_RA_REGNUM) | |
1269 | { | |
1270 | return_reg = reg; | |
1271 | break; | |
1272 | } | |
1273 | } | |
1274 | else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */ | |
1275 | { | |
1276 | return_reg = (word >> 16) & 0x1f; | |
1277 | break; | |
1278 | } | |
85b32d22 | 1279 | |
e8d2d628 | 1280 | cur_pc += ALPHA_INSN_SIZE; |
d2427a71 RH |
1281 | } |
1282 | } | |
c906108c | 1283 | } |
c906108c | 1284 | |
d2427a71 RH |
1285 | /* Failing that, do default to the customary RA. */ |
1286 | if (return_reg == -1) | |
1287 | return_reg = ALPHA_RA_REGNUM; | |
1288 | info->return_reg = return_reg; | |
f8453e34 | 1289 | |
6834c9bb | 1290 | val = get_frame_register_unsigned (this_frame, frame_reg); |
d2427a71 | 1291 | info->vfp = val + frame_size; |
c906108c | 1292 | |
d2427a71 RH |
1293 | /* Convert offsets to absolute addresses. See above about adding |
1294 | one to the offsets to make all detected offsets non-zero. */ | |
1295 | for (reg = 0; reg < ALPHA_NUM_REGS; ++reg) | |
07ea644b MD |
1296 | if (trad_frame_addr_p(info->saved_regs, reg)) |
1297 | info->saved_regs[reg].addr += val - 1; | |
d2427a71 | 1298 | |
bfd66dd9 JB |
1299 | /* The stack pointer of the previous frame is computed by popping |
1300 | the current stack frame. */ | |
1301 | if (!trad_frame_addr_p (info->saved_regs, ALPHA_SP_REGNUM)) | |
1302 | trad_frame_set_value (info->saved_regs, ALPHA_SP_REGNUM, info->vfp); | |
1303 | ||
d2427a71 | 1304 | return info; |
c906108c | 1305 | } |
c906108c | 1306 | |
d2427a71 RH |
1307 | /* Given a GDB frame, determine the address of the calling function's |
1308 | frame. This will be used to create a new GDB frame struct. */ | |
1309 | ||
fbe586ae | 1310 | static void |
6834c9bb JB |
1311 | alpha_heuristic_frame_this_id (struct frame_info *this_frame, |
1312 | void **this_prologue_cache, | |
1313 | struct frame_id *this_id) | |
c906108c | 1314 | { |
d2427a71 | 1315 | struct alpha_heuristic_unwind_cache *info |
6834c9bb | 1316 | = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0); |
c906108c | 1317 | |
d2427a71 | 1318 | *this_id = frame_id_build (info->vfp, info->start_pc); |
c906108c SS |
1319 | } |
1320 | ||
d2427a71 RH |
1321 | /* Retrieve the value of REGNUM in FRAME. Don't give up! */ |
1322 | ||
6834c9bb JB |
1323 | static struct value * |
1324 | alpha_heuristic_frame_prev_register (struct frame_info *this_frame, | |
1325 | void **this_prologue_cache, int regnum) | |
c906108c | 1326 | { |
d2427a71 | 1327 | struct alpha_heuristic_unwind_cache *info |
6834c9bb | 1328 | = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0); |
d2427a71 RH |
1329 | |
1330 | /* The PC of the previous frame is stored in the link register of | |
1331 | the current frame. Frob regnum so that we pull the value from | |
1332 | the correct place. */ | |
1333 | if (regnum == ALPHA_PC_REGNUM) | |
1334 | regnum = info->return_reg; | |
1335 | ||
6834c9bb | 1336 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); |
95b80706 JT |
1337 | } |
1338 | ||
d2427a71 RH |
1339 | static const struct frame_unwind alpha_heuristic_frame_unwind = { |
1340 | NORMAL_FRAME, | |
1341 | alpha_heuristic_frame_this_id, | |
6834c9bb JB |
1342 | alpha_heuristic_frame_prev_register, |
1343 | NULL, | |
1344 | default_frame_sniffer | |
d2427a71 | 1345 | }; |
c906108c | 1346 | |
fbe586ae | 1347 | static CORE_ADDR |
6834c9bb | 1348 | alpha_heuristic_frame_base_address (struct frame_info *this_frame, |
d2427a71 | 1349 | void **this_prologue_cache) |
c906108c | 1350 | { |
d2427a71 | 1351 | struct alpha_heuristic_unwind_cache *info |
6834c9bb | 1352 | = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0); |
c906108c | 1353 | |
d2427a71 | 1354 | return info->vfp; |
c906108c SS |
1355 | } |
1356 | ||
d2427a71 RH |
1357 | static const struct frame_base alpha_heuristic_frame_base = { |
1358 | &alpha_heuristic_frame_unwind, | |
1359 | alpha_heuristic_frame_base_address, | |
1360 | alpha_heuristic_frame_base_address, | |
1361 | alpha_heuristic_frame_base_address | |
1362 | }; | |
1363 | ||
c906108c | 1364 | /* Just like reinit_frame_cache, but with the right arguments to be |
d2427a71 | 1365 | callable as an sfunc. Used by the "set heuristic-fence-post" command. */ |
c906108c SS |
1366 | |
1367 | static void | |
fba45db2 | 1368 | reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c) |
c906108c SS |
1369 | { |
1370 | reinit_frame_cache (); | |
1371 | } | |
1372 | ||
d2427a71 | 1373 | \f |
d2427a71 RH |
1374 | /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that |
1375 | dummy frame. The frame ID's base needs to match the TOS value | |
1376 | saved by save_dummy_frame_tos(), and the PC match the dummy frame's | |
1377 | breakpoint. */ | |
d734c450 | 1378 | |
d2427a71 | 1379 | static struct frame_id |
6834c9bb | 1380 | alpha_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) |
0d056799 | 1381 | { |
d2427a71 | 1382 | ULONGEST base; |
6834c9bb JB |
1383 | base = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM); |
1384 | return frame_id_build (base, get_frame_pc (this_frame)); | |
0d056799 JT |
1385 | } |
1386 | ||
dc129d82 | 1387 | static CORE_ADDR |
d2427a71 | 1388 | alpha_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) |
accc6d1f | 1389 | { |
d2427a71 | 1390 | ULONGEST pc; |
11411de3 | 1391 | pc = frame_unwind_register_unsigned (next_frame, ALPHA_PC_REGNUM); |
d2427a71 | 1392 | return pc; |
accc6d1f JT |
1393 | } |
1394 | ||
98a8e1e5 RH |
1395 | \f |
1396 | /* Helper routines for alpha*-nat.c files to move register sets to and | |
1397 | from core files. The UNIQUE pointer is allowed to be NULL, as most | |
1398 | targets don't supply this value in their core files. */ | |
1399 | ||
1400 | void | |
390c1522 UW |
1401 | alpha_supply_int_regs (struct regcache *regcache, int regno, |
1402 | const void *r0_r30, const void *pc, const void *unique) | |
98a8e1e5 | 1403 | { |
2a1ce6ec | 1404 | const gdb_byte *regs = r0_r30; |
98a8e1e5 RH |
1405 | int i; |
1406 | ||
1407 | for (i = 0; i < 31; ++i) | |
1408 | if (regno == i || regno == -1) | |
390c1522 | 1409 | regcache_raw_supply (regcache, i, regs + i * 8); |
98a8e1e5 RH |
1410 | |
1411 | if (regno == ALPHA_ZERO_REGNUM || regno == -1) | |
390c1522 | 1412 | regcache_raw_supply (regcache, ALPHA_ZERO_REGNUM, NULL); |
98a8e1e5 RH |
1413 | |
1414 | if (regno == ALPHA_PC_REGNUM || regno == -1) | |
390c1522 | 1415 | regcache_raw_supply (regcache, ALPHA_PC_REGNUM, pc); |
98a8e1e5 RH |
1416 | |
1417 | if (regno == ALPHA_UNIQUE_REGNUM || regno == -1) | |
390c1522 | 1418 | regcache_raw_supply (regcache, ALPHA_UNIQUE_REGNUM, unique); |
98a8e1e5 RH |
1419 | } |
1420 | ||
1421 | void | |
390c1522 UW |
1422 | alpha_fill_int_regs (const struct regcache *regcache, |
1423 | int regno, void *r0_r30, void *pc, void *unique) | |
98a8e1e5 | 1424 | { |
2a1ce6ec | 1425 | gdb_byte *regs = r0_r30; |
98a8e1e5 RH |
1426 | int i; |
1427 | ||
1428 | for (i = 0; i < 31; ++i) | |
1429 | if (regno == i || regno == -1) | |
390c1522 | 1430 | regcache_raw_collect (regcache, i, regs + i * 8); |
98a8e1e5 RH |
1431 | |
1432 | if (regno == ALPHA_PC_REGNUM || regno == -1) | |
390c1522 | 1433 | regcache_raw_collect (regcache, ALPHA_PC_REGNUM, pc); |
98a8e1e5 RH |
1434 | |
1435 | if (unique && (regno == ALPHA_UNIQUE_REGNUM || regno == -1)) | |
390c1522 | 1436 | regcache_raw_collect (regcache, ALPHA_UNIQUE_REGNUM, unique); |
98a8e1e5 RH |
1437 | } |
1438 | ||
1439 | void | |
390c1522 UW |
1440 | alpha_supply_fp_regs (struct regcache *regcache, int regno, |
1441 | const void *f0_f30, const void *fpcr) | |
98a8e1e5 | 1442 | { |
2a1ce6ec | 1443 | const gdb_byte *regs = f0_f30; |
98a8e1e5 RH |
1444 | int i; |
1445 | ||
1446 | for (i = ALPHA_FP0_REGNUM; i < ALPHA_FP0_REGNUM + 31; ++i) | |
1447 | if (regno == i || regno == -1) | |
390c1522 | 1448 | regcache_raw_supply (regcache, i, |
2a1ce6ec | 1449 | regs + (i - ALPHA_FP0_REGNUM) * 8); |
98a8e1e5 RH |
1450 | |
1451 | if (regno == ALPHA_FPCR_REGNUM || regno == -1) | |
390c1522 | 1452 | regcache_raw_supply (regcache, ALPHA_FPCR_REGNUM, fpcr); |
98a8e1e5 RH |
1453 | } |
1454 | ||
1455 | void | |
390c1522 UW |
1456 | alpha_fill_fp_regs (const struct regcache *regcache, |
1457 | int regno, void *f0_f30, void *fpcr) | |
98a8e1e5 | 1458 | { |
2a1ce6ec | 1459 | gdb_byte *regs = f0_f30; |
98a8e1e5 RH |
1460 | int i; |
1461 | ||
1462 | for (i = ALPHA_FP0_REGNUM; i < ALPHA_FP0_REGNUM + 31; ++i) | |
1463 | if (regno == i || regno == -1) | |
390c1522 | 1464 | regcache_raw_collect (regcache, i, |
2a1ce6ec | 1465 | regs + (i - ALPHA_FP0_REGNUM) * 8); |
98a8e1e5 RH |
1466 | |
1467 | if (regno == ALPHA_FPCR_REGNUM || regno == -1) | |
390c1522 | 1468 | regcache_raw_collect (regcache, ALPHA_FPCR_REGNUM, fpcr); |
98a8e1e5 RH |
1469 | } |
1470 | ||
d2427a71 | 1471 | \f |
0de94d4b JB |
1472 | |
1473 | /* Return nonzero if the G_floating register value in REG is equal to | |
1474 | zero for FP control instructions. */ | |
1475 | ||
1476 | static int | |
1477 | fp_register_zero_p (LONGEST reg) | |
1478 | { | |
1479 | /* Check that all bits except the sign bit are zero. */ | |
1480 | const LONGEST zero_mask = ((LONGEST) 1 << 63) ^ -1; | |
1481 | ||
1482 | return ((reg & zero_mask) == 0); | |
1483 | } | |
1484 | ||
1485 | /* Return the value of the sign bit for the G_floating register | |
1486 | value held in REG. */ | |
1487 | ||
1488 | static int | |
1489 | fp_register_sign_bit (LONGEST reg) | |
1490 | { | |
1491 | const LONGEST sign_mask = (LONGEST) 1 << 63; | |
1492 | ||
1493 | return ((reg & sign_mask) != 0); | |
1494 | } | |
1495 | ||
ec32e4be JT |
1496 | /* alpha_software_single_step() is called just before we want to resume |
1497 | the inferior, if we want to single-step it but there is no hardware | |
1498 | or kernel single-step support (NetBSD on Alpha, for example). We find | |
e0cd558a | 1499 | the target of the coming instruction and breakpoint it. */ |
ec32e4be JT |
1500 | |
1501 | static CORE_ADDR | |
0b1b3e42 | 1502 | alpha_next_pc (struct frame_info *frame, CORE_ADDR pc) |
ec32e4be | 1503 | { |
e17a4113 | 1504 | struct gdbarch *gdbarch = get_frame_arch (frame); |
ec32e4be JT |
1505 | unsigned int insn; |
1506 | unsigned int op; | |
551e4f2e | 1507 | int regno; |
ec32e4be JT |
1508 | int offset; |
1509 | LONGEST rav; | |
1510 | ||
e17a4113 | 1511 | insn = alpha_read_insn (gdbarch, pc); |
ec32e4be JT |
1512 | |
1513 | /* Opcode is top 6 bits. */ | |
1514 | op = (insn >> 26) & 0x3f; | |
1515 | ||
1516 | if (op == 0x1a) | |
1517 | { | |
1518 | /* Jump format: target PC is: | |
1519 | RB & ~3 */ | |
0b1b3e42 | 1520 | return (get_frame_register_unsigned (frame, (insn >> 16) & 0x1f) & ~3); |
ec32e4be JT |
1521 | } |
1522 | ||
1523 | if ((op & 0x30) == 0x30) | |
1524 | { | |
1525 | /* Branch format: target PC is: | |
1526 | (new PC) + (4 * sext(displacement)) */ | |
f8bf5763 PM |
1527 | if (op == 0x30 /* BR */ |
1528 | || op == 0x34) /* BSR */ | |
ec32e4be JT |
1529 | { |
1530 | branch_taken: | |
1531 | offset = (insn & 0x001fffff); | |
1532 | if (offset & 0x00100000) | |
1533 | offset |= 0xffe00000; | |
e8d2d628 MK |
1534 | offset *= ALPHA_INSN_SIZE; |
1535 | return (pc + ALPHA_INSN_SIZE + offset); | |
ec32e4be JT |
1536 | } |
1537 | ||
1538 | /* Need to determine if branch is taken; read RA. */ | |
551e4f2e JB |
1539 | regno = (insn >> 21) & 0x1f; |
1540 | switch (op) | |
1541 | { | |
1542 | case 0x31: /* FBEQ */ | |
1543 | case 0x36: /* FBGE */ | |
1544 | case 0x37: /* FBGT */ | |
1545 | case 0x33: /* FBLE */ | |
1546 | case 0x32: /* FBLT */ | |
1547 | case 0x35: /* FBNE */ | |
e17a4113 | 1548 | regno += gdbarch_fp0_regnum (gdbarch); |
551e4f2e JB |
1549 | } |
1550 | ||
0b1b3e42 | 1551 | rav = get_frame_register_signed (frame, regno); |
0de94d4b | 1552 | |
ec32e4be JT |
1553 | switch (op) |
1554 | { | |
1555 | case 0x38: /* BLBC */ | |
1556 | if ((rav & 1) == 0) | |
1557 | goto branch_taken; | |
1558 | break; | |
1559 | case 0x3c: /* BLBS */ | |
1560 | if (rav & 1) | |
1561 | goto branch_taken; | |
1562 | break; | |
1563 | case 0x39: /* BEQ */ | |
1564 | if (rav == 0) | |
1565 | goto branch_taken; | |
1566 | break; | |
1567 | case 0x3d: /* BNE */ | |
1568 | if (rav != 0) | |
1569 | goto branch_taken; | |
1570 | break; | |
1571 | case 0x3a: /* BLT */ | |
1572 | if (rav < 0) | |
1573 | goto branch_taken; | |
1574 | break; | |
1575 | case 0x3b: /* BLE */ | |
1576 | if (rav <= 0) | |
1577 | goto branch_taken; | |
1578 | break; | |
1579 | case 0x3f: /* BGT */ | |
1580 | if (rav > 0) | |
1581 | goto branch_taken; | |
1582 | break; | |
1583 | case 0x3e: /* BGE */ | |
1584 | if (rav >= 0) | |
1585 | goto branch_taken; | |
1586 | break; | |
d2427a71 | 1587 | |
0de94d4b JB |
1588 | /* Floating point branches. */ |
1589 | ||
1590 | case 0x31: /* FBEQ */ | |
1591 | if (fp_register_zero_p (rav)) | |
1592 | goto branch_taken; | |
1593 | break; | |
1594 | case 0x36: /* FBGE */ | |
1595 | if (fp_register_sign_bit (rav) == 0 || fp_register_zero_p (rav)) | |
1596 | goto branch_taken; | |
1597 | break; | |
1598 | case 0x37: /* FBGT */ | |
1599 | if (fp_register_sign_bit (rav) == 0 && ! fp_register_zero_p (rav)) | |
1600 | goto branch_taken; | |
1601 | break; | |
1602 | case 0x33: /* FBLE */ | |
1603 | if (fp_register_sign_bit (rav) == 1 || fp_register_zero_p (rav)) | |
1604 | goto branch_taken; | |
1605 | break; | |
1606 | case 0x32: /* FBLT */ | |
1607 | if (fp_register_sign_bit (rav) == 1 && ! fp_register_zero_p (rav)) | |
1608 | goto branch_taken; | |
1609 | break; | |
1610 | case 0x35: /* FBNE */ | |
1611 | if (! fp_register_zero_p (rav)) | |
1612 | goto branch_taken; | |
1613 | break; | |
ec32e4be JT |
1614 | } |
1615 | } | |
1616 | ||
1617 | /* Not a branch or branch not taken; target PC is: | |
1618 | pc + 4 */ | |
e8d2d628 | 1619 | return (pc + ALPHA_INSN_SIZE); |
ec32e4be JT |
1620 | } |
1621 | ||
e6590a1b | 1622 | int |
0b1b3e42 | 1623 | alpha_software_single_step (struct frame_info *frame) |
ec32e4be | 1624 | { |
a6d9a66e | 1625 | struct gdbarch *gdbarch = get_frame_arch (frame); |
6c95b8df | 1626 | struct address_space *aspace = get_frame_address_space (frame); |
e0cd558a | 1627 | CORE_ADDR pc, next_pc; |
ec32e4be | 1628 | |
0b1b3e42 UW |
1629 | pc = get_frame_pc (frame); |
1630 | next_pc = alpha_next_pc (frame, pc); | |
ec32e4be | 1631 | |
6c95b8df | 1632 | insert_single_step_breakpoint (gdbarch, aspace, next_pc); |
e6590a1b | 1633 | return 1; |
c906108c SS |
1634 | } |
1635 | ||
dc129d82 | 1636 | \f |
dc129d82 JT |
1637 | /* Initialize the current architecture based on INFO. If possible, re-use an |
1638 | architecture from ARCHES, which is a list of architectures already created | |
1639 | during this debugging session. | |
1640 | ||
1641 | Called e.g. at program startup, when reading a core file, and when reading | |
1642 | a binary file. */ | |
1643 | ||
1644 | static struct gdbarch * | |
1645 | alpha_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1646 | { | |
1647 | struct gdbarch_tdep *tdep; | |
1648 | struct gdbarch *gdbarch; | |
dc129d82 JT |
1649 | |
1650 | /* Try to determine the ABI of the object we are loading. */ | |
4be87837 | 1651 | if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN) |
dc129d82 | 1652 | { |
4be87837 DJ |
1653 | /* If it's an ECOFF file, assume it's OSF/1. */ |
1654 | if (bfd_get_flavour (info.abfd) == bfd_target_ecoff_flavour) | |
aff87235 | 1655 | info.osabi = GDB_OSABI_OSF1; |
dc129d82 JT |
1656 | } |
1657 | ||
1658 | /* Find a candidate among extant architectures. */ | |
4be87837 DJ |
1659 | arches = gdbarch_list_lookup_by_info (arches, &info); |
1660 | if (arches != NULL) | |
1661 | return arches->gdbarch; | |
dc129d82 JT |
1662 | |
1663 | tdep = xmalloc (sizeof (struct gdbarch_tdep)); | |
1664 | gdbarch = gdbarch_alloc (&info, tdep); | |
1665 | ||
d2427a71 RH |
1666 | /* Lowest text address. This is used by heuristic_proc_start() |
1667 | to decide when to stop looking. */ | |
594706e6 | 1668 | tdep->vm_min_address = (CORE_ADDR) 0x120000000LL; |
d9b023cc | 1669 | |
36a6271d | 1670 | tdep->dynamic_sigtramp_offset = NULL; |
5868c862 | 1671 | tdep->sigcontext_addr = NULL; |
138e7be5 MK |
1672 | tdep->sc_pc_offset = 2 * 8; |
1673 | tdep->sc_regs_offset = 4 * 8; | |
1674 | tdep->sc_fpregs_offset = tdep->sc_regs_offset + 32 * 8 + 8; | |
36a6271d | 1675 | |
accc6d1f JT |
1676 | tdep->jb_pc = -1; /* longjmp support not enabled by default */ |
1677 | ||
9823e921 RH |
1678 | tdep->return_in_memory = alpha_return_in_memory_always; |
1679 | ||
dc129d82 JT |
1680 | /* Type sizes */ |
1681 | set_gdbarch_short_bit (gdbarch, 16); | |
1682 | set_gdbarch_int_bit (gdbarch, 32); | |
1683 | set_gdbarch_long_bit (gdbarch, 64); | |
1684 | set_gdbarch_long_long_bit (gdbarch, 64); | |
1685 | set_gdbarch_float_bit (gdbarch, 32); | |
1686 | set_gdbarch_double_bit (gdbarch, 64); | |
1687 | set_gdbarch_long_double_bit (gdbarch, 64); | |
1688 | set_gdbarch_ptr_bit (gdbarch, 64); | |
1689 | ||
1690 | /* Register info */ | |
1691 | set_gdbarch_num_regs (gdbarch, ALPHA_NUM_REGS); | |
1692 | set_gdbarch_sp_regnum (gdbarch, ALPHA_SP_REGNUM); | |
dc129d82 JT |
1693 | set_gdbarch_pc_regnum (gdbarch, ALPHA_PC_REGNUM); |
1694 | set_gdbarch_fp0_regnum (gdbarch, ALPHA_FP0_REGNUM); | |
1695 | ||
1696 | set_gdbarch_register_name (gdbarch, alpha_register_name); | |
c483c494 | 1697 | set_gdbarch_register_type (gdbarch, alpha_register_type); |
dc129d82 JT |
1698 | |
1699 | set_gdbarch_cannot_fetch_register (gdbarch, alpha_cannot_fetch_register); | |
1700 | set_gdbarch_cannot_store_register (gdbarch, alpha_cannot_store_register); | |
1701 | ||
c483c494 RH |
1702 | set_gdbarch_convert_register_p (gdbarch, alpha_convert_register_p); |
1703 | set_gdbarch_register_to_value (gdbarch, alpha_register_to_value); | |
1704 | set_gdbarch_value_to_register (gdbarch, alpha_value_to_register); | |
dc129d82 | 1705 | |
615967cb RH |
1706 | set_gdbarch_register_reggroup_p (gdbarch, alpha_register_reggroup_p); |
1707 | ||
d2427a71 | 1708 | /* Prologue heuristics. */ |
dc129d82 JT |
1709 | set_gdbarch_skip_prologue (gdbarch, alpha_skip_prologue); |
1710 | ||
5ef165c2 RH |
1711 | /* Disassembler. */ |
1712 | set_gdbarch_print_insn (gdbarch, print_insn_alpha); | |
1713 | ||
d2427a71 | 1714 | /* Call info. */ |
dc129d82 | 1715 | |
9823e921 | 1716 | set_gdbarch_return_value (gdbarch, alpha_return_value); |
dc129d82 JT |
1717 | |
1718 | /* Settings for calling functions in the inferior. */ | |
c88e30c0 | 1719 | set_gdbarch_push_dummy_call (gdbarch, alpha_push_dummy_call); |
d2427a71 RH |
1720 | |
1721 | /* Methods for saving / extracting a dummy frame's ID. */ | |
6834c9bb | 1722 | set_gdbarch_dummy_id (gdbarch, alpha_dummy_id); |
d2427a71 RH |
1723 | |
1724 | /* Return the unwound PC value. */ | |
1725 | set_gdbarch_unwind_pc (gdbarch, alpha_unwind_pc); | |
dc129d82 JT |
1726 | |
1727 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
36a6271d | 1728 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
dc129d82 | 1729 | |
95b80706 | 1730 | set_gdbarch_breakpoint_from_pc (gdbarch, alpha_breakpoint_from_pc); |
e8d2d628 | 1731 | set_gdbarch_decr_pc_after_break (gdbarch, ALPHA_INSN_SIZE); |
9d519230 | 1732 | set_gdbarch_cannot_step_breakpoint (gdbarch, 1); |
95b80706 | 1733 | |
44dffaac | 1734 | /* Hook in ABI-specific overrides, if they have been registered. */ |
4be87837 | 1735 | gdbarch_init_osabi (info, gdbarch); |
44dffaac | 1736 | |
accc6d1f JT |
1737 | /* Now that we have tuned the configuration, set a few final things |
1738 | based on what the OS ABI has told us. */ | |
1739 | ||
1740 | if (tdep->jb_pc >= 0) | |
1741 | set_gdbarch_get_longjmp_target (gdbarch, alpha_get_longjmp_target); | |
1742 | ||
6834c9bb JB |
1743 | frame_unwind_append_unwinder (gdbarch, &alpha_sigtramp_frame_unwind); |
1744 | frame_unwind_append_unwinder (gdbarch, &alpha_heuristic_frame_unwind); | |
dc129d82 | 1745 | |
d2427a71 | 1746 | frame_base_set_default (gdbarch, &alpha_heuristic_frame_base); |
accc6d1f | 1747 | |
d2427a71 | 1748 | return gdbarch; |
dc129d82 JT |
1749 | } |
1750 | ||
baa490c4 RH |
1751 | void |
1752 | alpha_dwarf2_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1753 | { | |
6834c9bb | 1754 | dwarf2_append_unwinders (gdbarch); |
336d1bba | 1755 | frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer); |
baa490c4 RH |
1756 | } |
1757 | ||
a78f21af AC |
1758 | extern initialize_file_ftype _initialize_alpha_tdep; /* -Wmissing-prototypes */ |
1759 | ||
c906108c | 1760 | void |
fba45db2 | 1761 | _initialize_alpha_tdep (void) |
c906108c SS |
1762 | { |
1763 | struct cmd_list_element *c; | |
1764 | ||
d2427a71 | 1765 | gdbarch_register (bfd_arch_alpha, alpha_gdbarch_init, NULL); |
c906108c SS |
1766 | |
1767 | /* Let the user set the fence post for heuristic_proc_start. */ | |
1768 | ||
1769 | /* We really would like to have both "0" and "unlimited" work, but | |
1770 | command.c doesn't deal with that. So make it a var_zinteger | |
1771 | because the user can always use "999999" or some such for unlimited. */ | |
edefbb7c AC |
1772 | /* We need to throw away the frame cache when we set this, since it |
1773 | might change our ability to get backtraces. */ | |
1774 | add_setshow_zinteger_cmd ("heuristic-fence-post", class_support, | |
7915a72c AC |
1775 | &heuristic_fence_post, _("\ |
1776 | Set the distance searched for the start of a function."), _("\ | |
1777 | Show the distance searched for the start of a function."), _("\ | |
c906108c SS |
1778 | If you are debugging a stripped executable, GDB needs to search through the\n\ |
1779 | program for the start of a function. This command sets the distance of the\n\ | |
323e0a4a | 1780 | search. The only need to set it is when debugging a stripped executable."), |
2c5b56ce | 1781 | reinit_frame_cache_sfunc, |
7915a72c | 1782 | NULL, /* FIXME: i18n: The distance searched for the start of a function is \"%d\". */ |
edefbb7c | 1783 | &setlist, &showlist); |
c906108c | 1784 | } |