1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "frame-unwind.h"
26 #include "frame-base.h"
27 #include "dwarf2-frame.h"
36 #include "gdb_string.h"
39 #include "reggroups.h"
40 #include "arch-utils.h"
44 #include "trad-frame.h"
48 #include "alpha-tdep.h"
50 /* Instruction decoding. The notations for registers, immediates and
51 opcodes are the same as the one used in Compaq's Alpha architecture
54 #define INSN_OPCODE(insn) ((insn & 0xfc000000) >> 26)
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))
62 static const int lda_opcode
= 0x08;
63 static const int stq_opcode
= 0x2d;
65 /* Branch instruction format */
66 #define BR_RA(insn) MEM_RA(insn)
68 static const int bne_opcode
= 0x3d;
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)
77 static const int subq_opcode
= 0x10;
78 static const int subq_function
= 0x29;
81 /* Return the name of the REGNO register.
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. */
89 alpha_register_name (struct gdbarch
*gdbarch
, int regno
)
91 static const char * const register_names
[] =
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",
106 if (regno
>= ARRAY_SIZE(register_names
))
108 return register_names
[regno
];
112 alpha_cannot_fetch_register (struct gdbarch
*gdbarch
, int regno
)
114 return (regno
== ALPHA_ZERO_REGNUM
115 || strlen (alpha_register_name (gdbarch
, regno
)) == 0);
119 alpha_cannot_store_register (struct gdbarch
*gdbarch
, int regno
)
121 return (regno
== ALPHA_ZERO_REGNUM
122 || strlen (alpha_register_name (gdbarch
, regno
)) == 0);
126 alpha_register_type (struct gdbarch
*gdbarch
, int regno
)
128 if (regno
== ALPHA_SP_REGNUM
|| regno
== ALPHA_GP_REGNUM
)
129 return builtin_type (gdbarch
)->builtin_data_ptr
;
130 if (regno
== ALPHA_PC_REGNUM
)
131 return builtin_type (gdbarch
)->builtin_func_ptr
;
133 /* Don't need to worry about little vs big endian until
134 some jerk tries to port to alpha-unicosmk. */
135 if (regno
>= ALPHA_FP0_REGNUM
&& regno
< ALPHA_FP0_REGNUM
+ 31)
136 return builtin_type (gdbarch
)->builtin_double
;
138 return builtin_type (gdbarch
)->builtin_int64
;
141 /* Is REGNUM a member of REGGROUP? */
144 alpha_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
145 struct reggroup
*group
)
147 /* Filter out any registers eliminated, but whose regnum is
148 reserved for backward compatibility, e.g. the vfp. */
149 if (gdbarch_register_name (gdbarch
, regnum
) == NULL
150 || *gdbarch_register_name (gdbarch
, regnum
) == '\0')
153 if (group
== all_reggroup
)
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
)
163 /* All other registers are saved and restored. */
164 if (group
== save_reggroup
|| group
== restore_reggroup
)
167 /* All other groups are non-overlapping. */
169 /* Since this is really a PALcode memory slot... */
170 if (regnum
== ALPHA_UNIQUE_REGNUM
)
171 return group
== system_reggroup
;
173 /* Force the FPCR to be considered part of the floating point state. */
174 if (regnum
== ALPHA_FPCR_REGNUM
)
175 return group
== float_reggroup
;
177 if (regnum
>= ALPHA_FP0_REGNUM
&& regnum
< ALPHA_FP0_REGNUM
+ 31)
178 return group
== float_reggroup
;
180 return group
== general_reggroup
;
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. */
188 alpha_lds (struct gdbarch
*gdbarch
, void *out
, const void *in
)
190 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
191 ULONGEST mem
= extract_unsigned_integer (in
, 4, byte_order
);
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;
198 exp
= (exp_msb
<< 10) | exp_low
;
210 reg
= (sign
<< 63) | (exp
<< 52) | (frac
<< 29);
211 store_unsigned_integer (out
, 8, byte_order
, reg
);
214 /* Similarly, this represents exactly the conversion performed by
215 the STS instruction. */
218 alpha_sts (struct gdbarch
*gdbarch
, void *out
, const void *in
)
220 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
223 reg
= extract_unsigned_integer (in
, 8, byte_order
);
224 mem
= ((reg
>> 32) & 0xc0000000) | ((reg
>> 29) & 0x3fffffff);
225 store_unsigned_integer (out
, 4, byte_order
, mem
);
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. */
235 alpha_convert_register_p (struct gdbarch
*gdbarch
, int regno
,
238 return (regno
>= ALPHA_FP0_REGNUM
&& regno
< ALPHA_FP0_REGNUM
+ 31
239 && TYPE_LENGTH (type
) != 8);
243 alpha_register_to_value (struct frame_info
*frame
, int regnum
,
244 struct type
*valtype
, gdb_byte
*out
)
246 gdb_byte in
[MAX_REGISTER_SIZE
];
248 frame_register_read (frame
, regnum
, in
);
249 switch (TYPE_LENGTH (valtype
))
252 alpha_sts (get_frame_arch (frame
), out
, in
);
255 error (_("Cannot retrieve value from floating point register"));
260 alpha_value_to_register (struct frame_info
*frame
, int regnum
,
261 struct type
*valtype
, const gdb_byte
*in
)
263 gdb_byte out
[MAX_REGISTER_SIZE
];
265 switch (TYPE_LENGTH (valtype
))
268 alpha_lds (get_frame_arch (frame
), out
, in
);
271 error (_("Cannot store value in floating point register"));
273 put_frame_register (frame
, regnum
, out
);
277 /* The alpha passes the first six arguments in the registers, the rest on
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.
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.
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. */
290 alpha_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
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
)
295 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
297 int accumulate_size
= struct_return
? 8 : 0;
300 const gdb_byte
*contents
;
304 struct alpha_arg
*alpha_args
305 = (struct alpha_arg
*) alloca (nargs
* sizeof (struct alpha_arg
));
306 struct alpha_arg
*m_arg
;
307 gdb_byte arg_reg_buffer
[ALPHA_REGISTER_SIZE
* ALPHA_NUM_ARG_REGS
];
308 int required_arg_regs
;
309 CORE_ADDR func_addr
= find_function_addr (function
, NULL
);
311 /* The ABI places the address of the called function in T12. */
312 regcache_cooked_write_signed (regcache
, ALPHA_T12_REGNUM
, func_addr
);
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
);
318 /* Lay out the arguments in memory. */
319 for (i
= 0, m_arg
= alpha_args
; i
< nargs
; i
++, m_arg
++)
321 struct value
*arg
= args
[i
];
322 struct type
*arg_type
= check_typedef (value_type (arg
));
324 /* Cast argument to long if necessary as the compiler does it too. */
325 switch (TYPE_CODE (arg_type
))
330 case TYPE_CODE_RANGE
:
332 if (TYPE_LENGTH (arg_type
) == 4)
334 /* 32-bit values must be sign-extended to 64 bits
335 even if the base data type is unsigned. */
336 arg_type
= builtin_type (gdbarch
)->builtin_int32
;
337 arg
= value_cast (arg_type
, arg
);
339 if (TYPE_LENGTH (arg_type
) < ALPHA_REGISTER_SIZE
)
341 arg_type
= builtin_type (gdbarch
)->builtin_int64
;
342 arg
= value_cast (arg_type
, arg
);
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)
352 arg_type
= builtin_type (gdbarch
)->builtin_double
;
353 arg
= value_cast (arg_type
, arg
);
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)
359 /* Allocate aligned storage. */
360 sp
= (sp
& -16) - 16;
362 /* Write the real data into the stack. */
363 write_memory (sp
, value_contents (arg
), 16);
365 /* Construct the indirection. */
366 arg_type
= lookup_pointer_type (arg_type
);
367 arg
= value_from_pointer (arg_type
, sp
);
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. */
376 /* Tru64 5.1 has a 128-bit long double, and passes this by
377 invisible reference. */
378 if (TYPE_LENGTH (arg_type
) == 32)
380 /* Allocate aligned storage. */
381 sp
= (sp
& -16) - 16;
383 /* Write the real data into the stack. */
384 write_memory (sp
, value_contents (arg
), 32);
386 /* Construct the indirection. */
387 arg_type
= lookup_pointer_type (arg_type
);
388 arg
= value_from_pointer (arg_type
, sp
);
395 m_arg
->len
= TYPE_LENGTH (arg_type
);
396 m_arg
->offset
= accumulate_size
;
397 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 7) & ~7;
398 m_arg
->contents
= value_contents (arg
);
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
;
407 /* Make room for the arguments on the stack. */
408 if (accumulate_size
< sizeof(arg_reg_buffer
))
411 accumulate_size
-= sizeof(arg_reg_buffer
);
412 sp
-= accumulate_size
;
414 /* Keep sp aligned to a multiple of 16 as the ABI requires. */
417 /* `Push' arguments on the stack. */
418 for (i
= nargs
; m_arg
--, --i
>= 0;)
420 const gdb_byte
*contents
= m_arg
->contents
;
421 int offset
= m_arg
->offset
;
422 int len
= m_arg
->len
;
424 /* Copy the bytes destined for registers into arg_reg_buffer. */
425 if (offset
< sizeof(arg_reg_buffer
))
427 if (offset
+ len
<= sizeof(arg_reg_buffer
))
429 memcpy (arg_reg_buffer
+ offset
, contents
, len
);
434 int tlen
= sizeof(arg_reg_buffer
) - offset
;
435 memcpy (arg_reg_buffer
+ offset
, contents
, tlen
);
442 /* Everything else goes to the stack. */
443 write_memory (sp
+ offset
- sizeof(arg_reg_buffer
), contents
, len
);
446 store_unsigned_integer (arg_reg_buffer
, ALPHA_REGISTER_SIZE
,
447 byte_order
, struct_addr
);
449 /* Load the argument registers. */
450 for (i
= 0; i
< required_arg_regs
; i
++)
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
);
458 /* Finally, update the stack pointer. */
459 regcache_cooked_write_signed (regcache
, ALPHA_SP_REGNUM
, sp
);
464 /* Extract from REGCACHE the value about to be returned from a function
465 and copy it into VALBUF. */
468 alpha_extract_return_value (struct type
*valtype
, struct regcache
*regcache
,
471 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
472 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
473 int length
= TYPE_LENGTH (valtype
);
474 gdb_byte raw_buffer
[ALPHA_REGISTER_SIZE
];
477 switch (TYPE_CODE (valtype
))
483 regcache_cooked_read (regcache
, ALPHA_FP0_REGNUM
, raw_buffer
);
484 alpha_sts (gdbarch
, valbuf
, raw_buffer
);
488 regcache_cooked_read (regcache
, ALPHA_FP0_REGNUM
, valbuf
);
492 regcache_cooked_read_unsigned (regcache
, ALPHA_V0_REGNUM
, &l
);
493 read_memory (l
, valbuf
, 16);
497 internal_error (__FILE__
, __LINE__
,
498 _("unknown floating point width"));
502 case TYPE_CODE_COMPLEX
:
506 /* ??? This isn't correct wrt the ABI, but it's what GCC does. */
507 regcache_cooked_read (regcache
, ALPHA_FP0_REGNUM
, valbuf
);
511 regcache_cooked_read (regcache
, ALPHA_FP0_REGNUM
, valbuf
);
512 regcache_cooked_read (regcache
, ALPHA_FP0_REGNUM
+ 1, valbuf
+ 8);
516 regcache_cooked_read_signed (regcache
, ALPHA_V0_REGNUM
, &l
);
517 read_memory (l
, valbuf
, 32);
521 internal_error (__FILE__
, __LINE__
,
522 _("unknown floating point width"));
527 /* Assume everything else degenerates to an integer. */
528 regcache_cooked_read_unsigned (regcache
, ALPHA_V0_REGNUM
, &l
);
529 store_unsigned_integer (valbuf
, length
, byte_order
, l
);
534 /* Insert the given value into REGCACHE as if it was being
535 returned by a function. */
538 alpha_store_return_value (struct type
*valtype
, struct regcache
*regcache
,
539 const gdb_byte
*valbuf
)
541 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
542 int length
= TYPE_LENGTH (valtype
);
543 gdb_byte raw_buffer
[ALPHA_REGISTER_SIZE
];
546 switch (TYPE_CODE (valtype
))
552 alpha_lds (gdbarch
, raw_buffer
, valbuf
);
553 regcache_cooked_write (regcache
, ALPHA_FP0_REGNUM
, raw_buffer
);
557 regcache_cooked_write (regcache
, ALPHA_FP0_REGNUM
, valbuf
);
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. */
564 error (_("Cannot set a 128-bit long double return value."));
567 internal_error (__FILE__
, __LINE__
,
568 _("unknown floating point width"));
572 case TYPE_CODE_COMPLEX
:
576 /* ??? This isn't correct wrt the ABI, but it's what GCC does. */
577 regcache_cooked_write (regcache
, ALPHA_FP0_REGNUM
, valbuf
);
581 regcache_cooked_write (regcache
, ALPHA_FP0_REGNUM
, valbuf
);
582 regcache_cooked_write (regcache
, ALPHA_FP0_REGNUM
+ 1, valbuf
+ 8);
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. */
589 error (_("Cannot set a 128-bit long double return value."));
592 internal_error (__FILE__
, __LINE__
,
593 _("unknown floating point width"));
598 /* Assume everything else degenerates to an integer. */
599 /* 32-bit values must be sign-extended to 64 bits
600 even if the base data type is unsigned. */
602 valtype
= builtin_type (gdbarch
)->builtin_int32
;
603 l
= unpack_long (valtype
, valbuf
);
604 regcache_cooked_write_unsigned (regcache
, ALPHA_V0_REGNUM
, l
);
609 static enum return_value_convention
610 alpha_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
611 struct type
*type
, struct regcache
*regcache
,
612 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
614 enum type_code code
= TYPE_CODE (type
);
616 if ((code
== TYPE_CODE_STRUCT
617 || code
== TYPE_CODE_UNION
618 || code
== TYPE_CODE_ARRAY
)
619 && gdbarch_tdep (gdbarch
)->return_in_memory (type
))
624 regcache_raw_read_unsigned (regcache
, ALPHA_V0_REGNUM
, &addr
);
625 read_memory (addr
, readbuf
, TYPE_LENGTH (type
));
628 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
632 alpha_extract_return_value (type
, regcache
, readbuf
);
634 alpha_store_return_value (type
, regcache
, writebuf
);
636 return RETURN_VALUE_REGISTER_CONVENTION
;
640 alpha_return_in_memory_always (struct type
*type
)
645 static const gdb_byte
*
646 alpha_breakpoint_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pc
, int *len
)
648 static const gdb_byte break_insn
[] = { 0x80, 0, 0, 0 }; /* call_pal bpt */
650 *len
= sizeof(break_insn
);
655 /* This returns the PC of the first insn after the prologue.
656 If we can't find the prologue, then return 0. */
659 alpha_after_prologue (CORE_ADDR pc
)
661 struct symtab_and_line sal
;
662 CORE_ADDR func_addr
, func_end
;
664 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
667 sal
= find_pc_line (func_addr
, 0);
668 if (sal
.end
< func_end
)
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. */
676 /* Read an instruction from memory at PC, looking through breakpoints. */
679 alpha_read_insn (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
681 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
682 gdb_byte buf
[ALPHA_INSN_SIZE
];
685 status
= target_read_memory (pc
, buf
, sizeof (buf
));
687 memory_error (status
, pc
);
688 return extract_unsigned_integer (buf
, sizeof (buf
), byte_order
);
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. */
699 alpha_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
703 CORE_ADDR post_prologue_pc
;
704 gdb_byte buf
[ALPHA_INSN_SIZE
];
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). */
713 if (target_read_memory (pc
, buf
, sizeof (buf
)))
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
720 post_prologue_pc
= alpha_after_prologue (pc
);
721 if (post_prologue_pc
!= 0)
722 return max (pc
, post_prologue_pc
);
724 /* Can't determine prologue from the symbol table, need to examine
727 /* Skip the typical prologue instructions. These are the stack adjustment
728 instruction and the instructions that save registers on the stack
729 or in the gcc frame. */
730 for (offset
= 0; offset
< 100; offset
+= ALPHA_INSN_SIZE
)
732 inst
= alpha_read_insn (gdbarch
, pc
+ offset
);
734 if ((inst
& 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
736 if ((inst
& 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
738 if ((inst
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
740 if ((inst
& 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
743 if (((inst
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
744 || (inst
& 0xfc1f0000) == 0x9c1e0000) /* stt reg,n($sp) */
745 && (inst
& 0x03e00000) != 0x03e00000) /* reg != $zero */
748 if (inst
== 0x47de040f) /* bis sp,sp,fp */
750 if (inst
== 0x47fe040f) /* bis zero,sp,fp */
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. */
765 alpha_get_longjmp_target (struct frame_info
*frame
, CORE_ADDR
*pc
)
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
);
771 gdb_byte raw_buffer
[ALPHA_REGISTER_SIZE
];
773 jb_addr
= get_frame_register_unsigned (frame
, ALPHA_A0_REGNUM
);
775 if (target_read_memory (jb_addr
+ (tdep
->jb_pc
* tdep
->jb_elt_size
),
776 raw_buffer
, tdep
->jb_elt_size
))
779 *pc
= extract_unsigned_integer (raw_buffer
, tdep
->jb_elt_size
, byte_order
);
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? */
790 struct alpha_sigtramp_unwind_cache
792 CORE_ADDR sigcontext_addr
;
795 static struct alpha_sigtramp_unwind_cache
*
796 alpha_sigtramp_frame_unwind_cache (struct frame_info
*this_frame
,
797 void **this_prologue_cache
)
799 struct alpha_sigtramp_unwind_cache
*info
;
800 struct gdbarch_tdep
*tdep
;
802 if (*this_prologue_cache
)
803 return *this_prologue_cache
;
805 info
= FRAME_OBSTACK_ZALLOC (struct alpha_sigtramp_unwind_cache
);
806 *this_prologue_cache
= info
;
808 tdep
= gdbarch_tdep (get_frame_arch (this_frame
));
809 info
->sigcontext_addr
= tdep
->sigcontext_addr (this_frame
);
814 /* Return the address of REGNUM in a sigtramp frame. Since this is
815 all arithmetic, it doesn't seem worthwhile to cache it. */
818 alpha_sigtramp_register_address (struct gdbarch
*gdbarch
,
819 CORE_ADDR sigcontext_addr
, int regnum
)
821 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
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
;
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. */
837 alpha_sigtramp_frame_this_id (struct frame_info
*this_frame
,
838 void **this_prologue_cache
,
839 struct frame_id
*this_id
)
841 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
842 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
843 struct alpha_sigtramp_unwind_cache
*info
844 = alpha_sigtramp_frame_unwind_cache (this_frame
, this_prologue_cache
);
845 CORE_ADDR stack_addr
, code_addr
;
847 /* If the OSABI couldn't locate the sigcontext, give up. */
848 if (info
->sigcontext_addr
== 0)
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. */
854 if (tdep
->dynamic_sigtramp_offset
)
857 code_addr
= get_frame_pc (this_frame
);
858 offset
= tdep
->dynamic_sigtramp_offset (gdbarch
, code_addr
);
865 code_addr
= get_frame_func (this_frame
);
867 /* The stack address is trivially read from the sigcontext. */
868 stack_addr
= alpha_sigtramp_register_address (gdbarch
, info
->sigcontext_addr
,
870 stack_addr
= get_frame_memory_unsigned (this_frame
, stack_addr
,
871 ALPHA_REGISTER_SIZE
);
873 *this_id
= frame_id_build (stack_addr
, code_addr
);
876 /* Retrieve the value of REGNUM in FRAME. Don't give up! */
878 static struct value
*
879 alpha_sigtramp_frame_prev_register (struct frame_info
*this_frame
,
880 void **this_prologue_cache
, int regnum
)
882 struct alpha_sigtramp_unwind_cache
*info
883 = alpha_sigtramp_frame_unwind_cache (this_frame
, this_prologue_cache
);
886 if (info
->sigcontext_addr
!= 0)
888 /* All integer and fp registers are stored in memory. */
889 addr
= alpha_sigtramp_register_address (get_frame_arch (this_frame
),
890 info
->sigcontext_addr
, regnum
);
892 return frame_unwind_got_memory (this_frame
, regnum
, addr
);
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
899 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
903 alpha_sigtramp_frame_sniffer (const struct frame_unwind
*self
,
904 struct frame_info
*this_frame
,
905 void **this_prologue_cache
)
907 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
908 CORE_ADDR pc
= get_frame_pc (this_frame
);
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. */
915 /* We shouldn't even bother to try if the OSABI didn't register a
916 sigcontext_addr handler or pc_in_sigtramp hander. */
917 if (gdbarch_tdep (gdbarch
)->sigcontext_addr
== NULL
)
919 if (gdbarch_tdep (gdbarch
)->pc_in_sigtramp
== NULL
)
922 /* Otherwise we should be in a signal frame. */
923 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
924 if (gdbarch_tdep (gdbarch
)->pc_in_sigtramp (gdbarch
, pc
, name
))
930 static const struct frame_unwind alpha_sigtramp_frame_unwind
= {
932 alpha_sigtramp_frame_this_id
,
933 alpha_sigtramp_frame_prev_register
,
935 alpha_sigtramp_frame_sniffer
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
943 static unsigned int heuristic_fence_post
= 0;
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... */
951 alpha_heuristic_proc_start (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
953 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
954 CORE_ADDR last_non_nop
= pc
;
955 CORE_ADDR fence
= pc
- heuristic_fence_post
;
956 CORE_ADDR orig_pc
= pc
;
958 struct inferior
*inf
;
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
);
970 if (heuristic_fence_post
== UINT_MAX
971 || fence
< tdep
->vm_min_address
)
972 fence
= tdep
->vm_min_address
;
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. */
977 for (pc
-= ALPHA_INSN_SIZE
; pc
>= fence
; pc
-= ALPHA_INSN_SIZE
)
979 unsigned int insn
= alpha_read_insn (gdbarch
, pc
);
982 case 0: /* invalid insn */
983 case 0x6bfa8001: /* ret $31,($26),1 */
986 case 0x2ffe0000: /* unop: ldq_u $31,0($30) */
987 case 0x47ff041f: /* nop: bis $31,$31,$31 */
996 inf
= current_inferior ();
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. */
1001 if (inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
1003 static int blurb_printed
= 0;
1005 if (fence
== tdep
->vm_min_address
)
1006 warning (_("Hit beginning of text section without finding \
1007 enclosing function for address %s"), paddress (gdbarch
, orig_pc
));
1009 warning (_("Hit heuristic-fence-post without finding \
1010 enclosing function for address %s"), paddress (gdbarch
, orig_pc
));
1014 printf_filtered (_("\
1015 This 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\
1017 increase the size of the search with the `set heuristic-fence-post' command.\n\
1019 Otherwise, you told GDB there was a function where there isn't one, or\n\
1020 (more likely) you have encountered a bug in GDB.\n"));
1028 /* Fallback alpha frame unwinder. Uses instruction scanning and knows
1029 something about the traditional layout of alpha stack frames. */
1031 struct alpha_heuristic_unwind_cache
1035 struct trad_frame_saved_reg
*saved_regs
;
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. */
1044 alpha_heuristic_analyze_probing_loop (struct gdbarch
*gdbarch
, CORE_ADDR
*pc
,
1047 CORE_ADDR cur_pc
= *pc
;
1048 int cur_frame_size
= *frame_size
;
1049 int nb_of_iterations
, reg_index
, reg_probe
;
1052 /* The following pattern is recognized as a probing loop:
1054 lda REG_INDEX,NB_OF_ITERATIONS
1055 lda REG_PROBE,<immediate>(sp)
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
1063 lda sp,<immediate>(REG_PROBE)
1065 If anything different is found, the function returns without
1066 changing PC and FRAME_SIZE. Otherwise, PC will point immediately
1067 after this sequence, and FRAME_SIZE will be updated. */
1069 /* lda REG_INDEX,NB_OF_ITERATIONS */
1071 insn
= alpha_read_insn (gdbarch
, cur_pc
);
1072 if (INSN_OPCODE (insn
) != lda_opcode
)
1074 reg_index
= MEM_RA (insn
);
1075 nb_of_iterations
= MEM_DISP (insn
);
1077 /* lda REG_PROBE,<immediate>(sp) */
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
)
1084 reg_probe
= MEM_RA (insn
);
1085 cur_frame_size
-= MEM_DISP (insn
);
1087 /* stq zero,<immediate>(REG_PROBE) */
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
)
1096 /* subq REG_INDEX,0x1,REG_INDEX */
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
)
1108 /* lda REG_PROBE,<immediate>(REG_PROBE) */
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
)
1116 cur_frame_size
-= MEM_DISP (insn
) * nb_of_iterations
;
1118 /* bne REG_INDEX, LOOP_START */
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
)
1126 /* lda sp,<immediate>(REG_PROBE) */
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
)
1134 cur_frame_size
-= MEM_DISP (insn
);
1137 *frame_size
= cur_frame_size
;
1140 static struct alpha_heuristic_unwind_cache
*
1141 alpha_heuristic_frame_unwind_cache (struct frame_info
*this_frame
,
1142 void **this_prologue_cache
,
1145 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1146 struct alpha_heuristic_unwind_cache
*info
;
1148 CORE_ADDR limit_pc
, cur_pc
;
1149 int frame_reg
, frame_size
, return_reg
, reg
;
1151 if (*this_prologue_cache
)
1152 return *this_prologue_cache
;
1154 info
= FRAME_OBSTACK_ZALLOC (struct alpha_heuristic_unwind_cache
);
1155 *this_prologue_cache
= info
;
1156 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1158 limit_pc
= get_frame_pc (this_frame
);
1160 start_pc
= alpha_heuristic_proc_start (gdbarch
, limit_pc
);
1161 info
->start_pc
= start_pc
;
1163 frame_reg
= ALPHA_SP_REGNUM
;
1167 /* If we've identified a likely place to start, do code scanning. */
1170 /* Limit the forward search to 50 instructions. */
1171 if (start_pc
+ 200 < limit_pc
)
1172 limit_pc
= start_pc
+ 200;
1174 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= ALPHA_INSN_SIZE
)
1176 unsigned int word
= alpha_read_insn (gdbarch
, cur_pc
);
1178 if ((word
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1182 /* Consider only the first stack allocation instruction
1183 to contain the static size of the frame. */
1184 if (frame_size
== 0)
1185 frame_size
= (-word
) & 0xffff;
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. */
1195 else if ((word
& 0xfc1f0000) == 0xb41e0000) /* stq reg,n($sp) */
1197 reg
= (word
& 0x03e00000) >> 21;
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. */
1206 if (trad_frame_addr_p(info
->saved_regs
, reg
))
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
1220 /* Hack: temporarily add one, so that the offset is non-zero
1221 and we can tell which registers have save offsets below. */
1222 info
->saved_regs
[reg
].addr
= (word
& 0xffff) + 1;
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.
1241 FIXME: Rewriting GDB to access the procedure descriptors,
1242 e.g. via the minimal symbol table, might obviate this
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
))
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
;
1258 alpha_heuristic_analyze_probing_loop (gdbarch
, &cur_pc
, &frame_size
);
1261 /* If we haven't found a valid return address register yet, keep
1262 searching in the procedure prologue. */
1263 if (return_reg
== -1)
1265 while (cur_pc
< (limit_pc
+ 80) && cur_pc
< (start_pc
+ 80))
1267 unsigned int word
= alpha_read_insn (gdbarch
, cur_pc
);
1269 if ((word
& 0xfc1f0000) == 0xb41e0000) /* stq reg,n($sp) */
1271 reg
= (word
& 0x03e00000) >> 21;
1272 if (reg
== ALPHA_T7_REGNUM
1273 || reg
== ALPHA_T9_REGNUM
1274 || reg
== ALPHA_RA_REGNUM
)
1280 else if ((word
& 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
1282 return_reg
= (word
>> 16) & 0x1f;
1286 cur_pc
+= ALPHA_INSN_SIZE
;
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
;
1296 val
= get_frame_register_unsigned (this_frame
, frame_reg
);
1297 info
->vfp
= val
+ frame_size
;
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
)
1302 if (trad_frame_addr_p(info
->saved_regs
, reg
))
1303 info
->saved_regs
[reg
].addr
+= val
- 1;
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
);
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. */
1317 alpha_heuristic_frame_this_id (struct frame_info
*this_frame
,
1318 void **this_prologue_cache
,
1319 struct frame_id
*this_id
)
1321 struct alpha_heuristic_unwind_cache
*info
1322 = alpha_heuristic_frame_unwind_cache (this_frame
, this_prologue_cache
, 0);
1324 *this_id
= frame_id_build (info
->vfp
, info
->start_pc
);
1327 /* Retrieve the value of REGNUM in FRAME. Don't give up! */
1329 static struct value
*
1330 alpha_heuristic_frame_prev_register (struct frame_info
*this_frame
,
1331 void **this_prologue_cache
, int regnum
)
1333 struct alpha_heuristic_unwind_cache
*info
1334 = alpha_heuristic_frame_unwind_cache (this_frame
, this_prologue_cache
, 0);
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
;
1342 return trad_frame_get_prev_register (this_frame
, info
->saved_regs
, regnum
);
1345 static const struct frame_unwind alpha_heuristic_frame_unwind
= {
1347 alpha_heuristic_frame_this_id
,
1348 alpha_heuristic_frame_prev_register
,
1350 default_frame_sniffer
1354 alpha_heuristic_frame_base_address (struct frame_info
*this_frame
,
1355 void **this_prologue_cache
)
1357 struct alpha_heuristic_unwind_cache
*info
1358 = alpha_heuristic_frame_unwind_cache (this_frame
, this_prologue_cache
, 0);
1363 static 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
1370 /* Just like reinit_frame_cache, but with the right arguments to be
1371 callable as an sfunc. Used by the "set heuristic-fence-post" command. */
1374 reinit_frame_cache_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
1376 reinit_frame_cache ();
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
1385 static struct frame_id
1386 alpha_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
1389 base
= get_frame_register_unsigned (this_frame
, ALPHA_SP_REGNUM
);
1390 return frame_id_build (base
, get_frame_pc (this_frame
));
1394 alpha_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1397 pc
= frame_unwind_register_unsigned (next_frame
, ALPHA_PC_REGNUM
);
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. */
1407 alpha_supply_int_regs (struct regcache
*regcache
, int regno
,
1408 const void *r0_r30
, const void *pc
, const void *unique
)
1410 const gdb_byte
*regs
= r0_r30
;
1413 for (i
= 0; i
< 31; ++i
)
1414 if (regno
== i
|| regno
== -1)
1415 regcache_raw_supply (regcache
, i
, regs
+ i
* 8);
1417 if (regno
== ALPHA_ZERO_REGNUM
|| regno
== -1)
1418 regcache_raw_supply (regcache
, ALPHA_ZERO_REGNUM
, NULL
);
1420 if (regno
== ALPHA_PC_REGNUM
|| regno
== -1)
1421 regcache_raw_supply (regcache
, ALPHA_PC_REGNUM
, pc
);
1423 if (regno
== ALPHA_UNIQUE_REGNUM
|| regno
== -1)
1424 regcache_raw_supply (regcache
, ALPHA_UNIQUE_REGNUM
, unique
);
1428 alpha_fill_int_regs (const struct regcache
*regcache
,
1429 int regno
, void *r0_r30
, void *pc
, void *unique
)
1431 gdb_byte
*regs
= r0_r30
;
1434 for (i
= 0; i
< 31; ++i
)
1435 if (regno
== i
|| regno
== -1)
1436 regcache_raw_collect (regcache
, i
, regs
+ i
* 8);
1438 if (regno
== ALPHA_PC_REGNUM
|| regno
== -1)
1439 regcache_raw_collect (regcache
, ALPHA_PC_REGNUM
, pc
);
1441 if (unique
&& (regno
== ALPHA_UNIQUE_REGNUM
|| regno
== -1))
1442 regcache_raw_collect (regcache
, ALPHA_UNIQUE_REGNUM
, unique
);
1446 alpha_supply_fp_regs (struct regcache
*regcache
, int regno
,
1447 const void *f0_f30
, const void *fpcr
)
1449 const gdb_byte
*regs
= f0_f30
;
1452 for (i
= ALPHA_FP0_REGNUM
; i
< ALPHA_FP0_REGNUM
+ 31; ++i
)
1453 if (regno
== i
|| regno
== -1)
1454 regcache_raw_supply (regcache
, i
,
1455 regs
+ (i
- ALPHA_FP0_REGNUM
) * 8);
1457 if (regno
== ALPHA_FPCR_REGNUM
|| regno
== -1)
1458 regcache_raw_supply (regcache
, ALPHA_FPCR_REGNUM
, fpcr
);
1462 alpha_fill_fp_regs (const struct regcache
*regcache
,
1463 int regno
, void *f0_f30
, void *fpcr
)
1465 gdb_byte
*regs
= f0_f30
;
1468 for (i
= ALPHA_FP0_REGNUM
; i
< ALPHA_FP0_REGNUM
+ 31; ++i
)
1469 if (regno
== i
|| regno
== -1)
1470 regcache_raw_collect (regcache
, i
,
1471 regs
+ (i
- ALPHA_FP0_REGNUM
) * 8);
1473 if (regno
== ALPHA_FPCR_REGNUM
|| regno
== -1)
1474 regcache_raw_collect (regcache
, ALPHA_FPCR_REGNUM
, fpcr
);
1479 /* Return nonzero if the G_floating register value in REG is equal to
1480 zero for FP control instructions. */
1483 fp_register_zero_p (LONGEST reg
)
1485 /* Check that all bits except the sign bit are zero. */
1486 const LONGEST zero_mask
= ((LONGEST
) 1 << 63) ^ -1;
1488 return ((reg
& zero_mask
) == 0);
1491 /* Return the value of the sign bit for the G_floating register
1492 value held in REG. */
1495 fp_register_sign_bit (LONGEST reg
)
1497 const LONGEST sign_mask
= (LONGEST
) 1 << 63;
1499 return ((reg
& sign_mask
) != 0);
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
1505 the target of the coming instruction and breakpoint it. */
1508 alpha_next_pc (struct frame_info
*frame
, CORE_ADDR pc
)
1510 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1517 insn
= alpha_read_insn (gdbarch
, pc
);
1519 /* Opcode is top 6 bits. */
1520 op
= (insn
>> 26) & 0x3f;
1524 /* Jump format: target PC is:
1526 return (get_frame_register_unsigned (frame
, (insn
>> 16) & 0x1f) & ~3);
1529 if ((op
& 0x30) == 0x30)
1531 /* Branch format: target PC is:
1532 (new PC) + (4 * sext(displacement)) */
1533 if (op
== 0x30 /* BR */
1534 || op
== 0x34) /* BSR */
1537 offset
= (insn
& 0x001fffff);
1538 if (offset
& 0x00100000)
1539 offset
|= 0xffe00000;
1540 offset
*= ALPHA_INSN_SIZE
;
1541 return (pc
+ ALPHA_INSN_SIZE
+ offset
);
1544 /* Need to determine if branch is taken; read RA. */
1545 regno
= (insn
>> 21) & 0x1f;
1548 case 0x31: /* FBEQ */
1549 case 0x36: /* FBGE */
1550 case 0x37: /* FBGT */
1551 case 0x33: /* FBLE */
1552 case 0x32: /* FBLT */
1553 case 0x35: /* FBNE */
1554 regno
+= gdbarch_fp0_regnum (gdbarch
);
1557 rav
= get_frame_register_signed (frame
, regno
);
1561 case 0x38: /* BLBC */
1565 case 0x3c: /* BLBS */
1569 case 0x39: /* BEQ */
1573 case 0x3d: /* BNE */
1577 case 0x3a: /* BLT */
1581 case 0x3b: /* BLE */
1585 case 0x3f: /* BGT */
1589 case 0x3e: /* BGE */
1594 /* Floating point branches. */
1596 case 0x31: /* FBEQ */
1597 if (fp_register_zero_p (rav
))
1600 case 0x36: /* FBGE */
1601 if (fp_register_sign_bit (rav
) == 0 || fp_register_zero_p (rav
))
1604 case 0x37: /* FBGT */
1605 if (fp_register_sign_bit (rav
) == 0 && ! fp_register_zero_p (rav
))
1608 case 0x33: /* FBLE */
1609 if (fp_register_sign_bit (rav
) == 1 || fp_register_zero_p (rav
))
1612 case 0x32: /* FBLT */
1613 if (fp_register_sign_bit (rav
) == 1 && ! fp_register_zero_p (rav
))
1616 case 0x35: /* FBNE */
1617 if (! fp_register_zero_p (rav
))
1623 /* Not a branch or branch not taken; target PC is:
1625 return (pc
+ ALPHA_INSN_SIZE
);
1629 alpha_software_single_step (struct frame_info
*frame
)
1631 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1632 struct address_space
*aspace
= get_frame_address_space (frame
);
1633 CORE_ADDR pc
, next_pc
;
1635 pc
= get_frame_pc (frame
);
1636 next_pc
= alpha_next_pc (frame
, pc
);
1638 insert_single_step_breakpoint (gdbarch
, aspace
, next_pc
);
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.
1647 Called e.g. at program startup, when reading a core file, and when reading
1650 static struct gdbarch
*
1651 alpha_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1653 struct gdbarch_tdep
*tdep
;
1654 struct gdbarch
*gdbarch
;
1656 /* Try to determine the ABI of the object we are loading. */
1657 if (info
.abfd
!= NULL
&& info
.osabi
== GDB_OSABI_UNKNOWN
)
1659 /* If it's an ECOFF file, assume it's OSF/1. */
1660 if (bfd_get_flavour (info
.abfd
) == bfd_target_ecoff_flavour
)
1661 info
.osabi
= GDB_OSABI_OSF1
;
1664 /* Find a candidate among extant architectures. */
1665 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1667 return arches
->gdbarch
;
1669 tdep
= xmalloc (sizeof (struct gdbarch_tdep
));
1670 gdbarch
= gdbarch_alloc (&info
, tdep
);
1672 /* Lowest text address. This is used by heuristic_proc_start()
1673 to decide when to stop looking. */
1674 tdep
->vm_min_address
= (CORE_ADDR
) 0x120000000LL
;
1676 tdep
->dynamic_sigtramp_offset
= NULL
;
1677 tdep
->sigcontext_addr
= NULL
;
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;
1682 tdep
->jb_pc
= -1; /* longjmp support not enabled by default. */
1684 tdep
->return_in_memory
= alpha_return_in_memory_always
;
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);
1697 set_gdbarch_num_regs (gdbarch
, ALPHA_NUM_REGS
);
1698 set_gdbarch_sp_regnum (gdbarch
, ALPHA_SP_REGNUM
);
1699 set_gdbarch_pc_regnum (gdbarch
, ALPHA_PC_REGNUM
);
1700 set_gdbarch_fp0_regnum (gdbarch
, ALPHA_FP0_REGNUM
);
1702 set_gdbarch_register_name (gdbarch
, alpha_register_name
);
1703 set_gdbarch_register_type (gdbarch
, alpha_register_type
);
1705 set_gdbarch_cannot_fetch_register (gdbarch
, alpha_cannot_fetch_register
);
1706 set_gdbarch_cannot_store_register (gdbarch
, alpha_cannot_store_register
);
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
);
1712 set_gdbarch_register_reggroup_p (gdbarch
, alpha_register_reggroup_p
);
1714 /* Prologue heuristics. */
1715 set_gdbarch_skip_prologue (gdbarch
, alpha_skip_prologue
);
1718 set_gdbarch_print_insn (gdbarch
, print_insn_alpha
);
1722 set_gdbarch_return_value (gdbarch
, alpha_return_value
);
1724 /* Settings for calling functions in the inferior. */
1725 set_gdbarch_push_dummy_call (gdbarch
, alpha_push_dummy_call
);
1727 /* Methods for saving / extracting a dummy frame's ID. */
1728 set_gdbarch_dummy_id (gdbarch
, alpha_dummy_id
);
1730 /* Return the unwound PC value. */
1731 set_gdbarch_unwind_pc (gdbarch
, alpha_unwind_pc
);
1733 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1734 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
1736 set_gdbarch_breakpoint_from_pc (gdbarch
, alpha_breakpoint_from_pc
);
1737 set_gdbarch_decr_pc_after_break (gdbarch
, ALPHA_INSN_SIZE
);
1738 set_gdbarch_cannot_step_breakpoint (gdbarch
, 1);
1740 /* Hook in ABI-specific overrides, if they have been registered. */
1741 gdbarch_init_osabi (info
, gdbarch
);
1743 /* Now that we have tuned the configuration, set a few final things
1744 based on what the OS ABI has told us. */
1746 if (tdep
->jb_pc
>= 0)
1747 set_gdbarch_get_longjmp_target (gdbarch
, alpha_get_longjmp_target
);
1749 frame_unwind_append_unwinder (gdbarch
, &alpha_sigtramp_frame_unwind
);
1750 frame_unwind_append_unwinder (gdbarch
, &alpha_heuristic_frame_unwind
);
1752 frame_base_set_default (gdbarch
, &alpha_heuristic_frame_base
);
1758 alpha_dwarf2_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1760 dwarf2_append_unwinders (gdbarch
);
1761 frame_base_append_sniffer (gdbarch
, dwarf2_frame_base_sniffer
);
1764 extern initialize_file_ftype _initialize_alpha_tdep
; /* -Wmissing-prototypes */
1767 _initialize_alpha_tdep (void)
1769 struct cmd_list_element
*c
;
1771 gdbarch_register (bfd_arch_alpha
, alpha_gdbarch_init
, NULL
);
1773 /* Let the user set the fence post for heuristic_proc_start. */
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. */
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
,
1781 &heuristic_fence_post
, _("\
1782 Set the distance searched for the start of a function."), _("\
1783 Show the distance searched for the start of a function."), _("\
1784 If you are debugging a stripped executable, GDB needs to search through the\n\
1785 program for the start of a function. This command sets the distance of the\n\
1786 search. The only need to set it is when debugging a stripped executable."),
1787 reinit_frame_cache_sfunc
,
1788 NULL
, /* FIXME: i18n: The distance searched for
1789 the start of a function is \"%d\". */
1790 &setlist
, &showlist
);