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