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