]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/alpha-linux-tdep.c
* alphabsd-tdep.c (alphabsd_supply_fpreg): Fix typo last change.
[thirdparty/binutils-gdb.git] / gdb / alpha-linux-tdep.c
CommitLineData
3379287a 1/* Target-dependent code for GNU/Linux on Alpha.
4be87837 2 Copyright 2002, 2003 Free Software Foundation, Inc.
3379287a
JT
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
5868c862 22#include "frame.h"
f1a559ae
RH
23#include "frame-base.h"
24#include "frame-unwind.h"
25#include "dwarf2-frame.h"
36a6271d 26#include "gdbcore.h"
d2427a71 27#include "gdb_assert.h"
f1a559ae
RH
28#include "osabi.h"
29#include "symtab.h"
30#include "symfile.h"
31#include "value.h"
3379287a
JT
32
33#include "alpha-tdep.h"
34
d2427a71
RH
35/* Under GNU/Linux, signal handler invocations can be identified by
36 the designated code sequence that is used to return from a signal
3379287a 37 handler. In particular, the return address of a signal handler
d2427a71
RH
38 points to a sequence that copies $sp to $16, loads $0 with the
39 appropriate syscall number, and finally enters the kernel.
40
41 This is somewhat complicated in that:
42 (1) the expansion of the "mov" assembler macro has changed over
43 time, from "bis src,src,dst" to "bis zero,src,dst",
44 (2) the kernel has changed from using "addq" to "lda" to load the
45 syscall number,
46 (3) there is a "normal" sigreturn and an "rt" sigreturn which
47 has a different stack layout.
48*/
49
50static long
51alpha_linux_sigtramp_offset_1 (CORE_ADDR pc)
3379287a 52{
d2427a71
RH
53 switch (alpha_read_insn (pc))
54 {
55 case 0x47de0410: /* bis $30,$30,$16 */
56 case 0x47fe0410: /* bis $31,$30,$16 */
57 return 0;
3379287a 58
d2427a71
RH
59 case 0x43ecf400: /* addq $31,103,$0 */
60 case 0x201f0067: /* lda $0,103($31) */
61 case 0x201f015f: /* lda $0,351($31) */
62 return 4;
63
64 case 0x00000083: /* call_pal callsys */
65 return 8;
3379287a 66
3379287a
JT
67 default:
68 return -1;
69 }
d2427a71
RH
70}
71
72static LONGEST
73alpha_linux_sigtramp_offset (CORE_ADDR pc)
74{
75 long i, off;
76
77 if (pc & 3)
78 return -1;
79
80 /* Guess where we might be in the sequence. */
81 off = alpha_linux_sigtramp_offset_1 (pc);
82 if (off < 0)
83 return -1;
84
85 /* Verify that the other two insns of the sequence are as we expect. */
3379287a 86 pc -= off;
d2427a71 87 for (i = 0; i < 12; i += 4)
3379287a 88 {
d2427a71
RH
89 if (i == off)
90 continue;
91 if (alpha_linux_sigtramp_offset_1 (pc + i) != i)
92 return -1;
3379287a 93 }
3379287a 94
d2427a71 95 return off;
3379287a
JT
96}
97
6c72f9f9
JT
98static int
99alpha_linux_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
100{
d2427a71 101 return alpha_linux_sigtramp_offset (pc) >= 0;
6c72f9f9
JT
102}
103
5868c862 104static CORE_ADDR
d2427a71 105alpha_linux_sigcontext_addr (struct frame_info *next_frame)
5868c862 106{
d2427a71
RH
107 CORE_ADDR pc;
108 ULONGEST sp;
109 long off;
110
111 pc = frame_pc_unwind (next_frame);
112 frame_unwind_unsigned_register (next_frame, ALPHA_SP_REGNUM, &sp);
113
114 off = alpha_linux_sigtramp_offset (pc);
115 gdb_assert (off >= 0);
116
117 /* __NR_rt_sigreturn has a couple of structures on the stack. This is:
118
119 struct rt_sigframe {
120 struct siginfo info;
121 struct ucontext uc;
122 };
123
124 offsetof (struct rt_sigframe, uc.uc_mcontext);
125 */
126 if (alpha_read_insn (pc - off + 4) == 0x201f015f)
127 return sp + 176;
128
129 /* __NR_sigreturn has the sigcontext structure at the top of the stack. */
130 return sp;
5868c862
JT
131}
132
3379287a
JT
133static void
134alpha_linux_init_abi (struct gdbarch_info info,
135 struct gdbarch *gdbarch)
136{
d2427a71
RH
137 struct gdbarch_tdep *tdep;
138
f1a559ae
RH
139 /* Hook into the DWARF CFI frame unwinder. */
140 frame_unwind_append_predicate (gdbarch, dwarf2_frame_p);
141 frame_base_append_predicate (gdbarch, dwarf2_frame_base_p);
142 set_gdbarch_dwarf2_build_frame_info (gdbarch, dwarf2_build_frame_info);
143
144 /* Hook into the MDEBUG frame unwinder. */
d2427a71 145 alpha_mdebug_init_abi (info, gdbarch);
36a6271d 146
6c72f9f9
JT
147 set_gdbarch_pc_in_sigtramp (gdbarch, alpha_linux_pc_in_sigtramp);
148
d2427a71 149 tdep = gdbarch_tdep (gdbarch);
36a6271d 150 tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
5868c862 151 tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
accc6d1f
JT
152 tdep->jb_pc = 2;
153 tdep->jb_elt_size = 8;
3379287a
JT
154}
155
156void
157_initialize_alpha_linux_tdep (void)
158{
05816f70 159 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_LINUX,
70f80edf 160 alpha_linux_init_abi);
3379287a 161}