From Richard Henderson <rth@redhat.com>:
[deliverable/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"
36a6271d 23#include "gdbcore.h"
3379287a 24#include "value.h"
4be87837 25#include "osabi.h"
d2427a71 26#include "gdb_assert.h"
3379287a
JT
27
28#include "alpha-tdep.h"
29
d2427a71
RH
30/* Under GNU/Linux, signal handler invocations can be identified by
31 the designated code sequence that is used to return from a signal
3379287a 32 handler. In particular, the return address of a signal handler
d2427a71
RH
33 points to a sequence that copies $sp to $16, loads $0 with the
34 appropriate syscall number, and finally enters the kernel.
35
36 This is somewhat complicated in that:
37 (1) the expansion of the "mov" assembler macro has changed over
38 time, from "bis src,src,dst" to "bis zero,src,dst",
39 (2) the kernel has changed from using "addq" to "lda" to load the
40 syscall number,
41 (3) there is a "normal" sigreturn and an "rt" sigreturn which
42 has a different stack layout.
43*/
44
45static long
46alpha_linux_sigtramp_offset_1 (CORE_ADDR pc)
3379287a 47{
d2427a71
RH
48 switch (alpha_read_insn (pc))
49 {
50 case 0x47de0410: /* bis $30,$30,$16 */
51 case 0x47fe0410: /* bis $31,$30,$16 */
52 return 0;
3379287a 53
d2427a71
RH
54 case 0x43ecf400: /* addq $31,103,$0 */
55 case 0x201f0067: /* lda $0,103($31) */
56 case 0x201f015f: /* lda $0,351($31) */
57 return 4;
58
59 case 0x00000083: /* call_pal callsys */
60 return 8;
3379287a 61
3379287a
JT
62 default:
63 return -1;
64 }
d2427a71
RH
65}
66
67static LONGEST
68alpha_linux_sigtramp_offset (CORE_ADDR pc)
69{
70 long i, off;
71
72 if (pc & 3)
73 return -1;
74
75 /* Guess where we might be in the sequence. */
76 off = alpha_linux_sigtramp_offset_1 (pc);
77 if (off < 0)
78 return -1;
79
80 /* Verify that the other two insns of the sequence are as we expect. */
3379287a 81 pc -= off;
d2427a71 82 for (i = 0; i < 12; i += 4)
3379287a 83 {
d2427a71
RH
84 if (i == off)
85 continue;
86 if (alpha_linux_sigtramp_offset_1 (pc + i) != i)
87 return -1;
3379287a 88 }
3379287a 89
d2427a71 90 return off;
3379287a
JT
91}
92
6c72f9f9
JT
93static int
94alpha_linux_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
95{
d2427a71 96 return alpha_linux_sigtramp_offset (pc) >= 0;
6c72f9f9
JT
97}
98
5868c862 99static CORE_ADDR
d2427a71 100alpha_linux_sigcontext_addr (struct frame_info *next_frame)
5868c862 101{
d2427a71
RH
102 CORE_ADDR pc;
103 ULONGEST sp;
104 long off;
105
106 pc = frame_pc_unwind (next_frame);
107 frame_unwind_unsigned_register (next_frame, ALPHA_SP_REGNUM, &sp);
108
109 off = alpha_linux_sigtramp_offset (pc);
110 gdb_assert (off >= 0);
111
112 /* __NR_rt_sigreturn has a couple of structures on the stack. This is:
113
114 struct rt_sigframe {
115 struct siginfo info;
116 struct ucontext uc;
117 };
118
119 offsetof (struct rt_sigframe, uc.uc_mcontext);
120 */
121 if (alpha_read_insn (pc - off + 4) == 0x201f015f)
122 return sp + 176;
123
124 /* __NR_sigreturn has the sigcontext structure at the top of the stack. */
125 return sp;
5868c862
JT
126}
127
3379287a
JT
128static void
129alpha_linux_init_abi (struct gdbarch_info info,
130 struct gdbarch *gdbarch)
131{
d2427a71
RH
132 struct gdbarch_tdep *tdep;
133
134 alpha_mdebug_init_abi (info, gdbarch);
36a6271d 135
6c72f9f9
JT
136 set_gdbarch_pc_in_sigtramp (gdbarch, alpha_linux_pc_in_sigtramp);
137
d2427a71 138 tdep = gdbarch_tdep (gdbarch);
36a6271d 139 tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
5868c862 140 tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
accc6d1f
JT
141 tdep->jb_pc = 2;
142 tdep->jb_elt_size = 8;
3379287a
JT
143}
144
145void
146_initialize_alpha_linux_tdep (void)
147{
05816f70 148 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_LINUX,
70f80edf 149 alpha_linux_init_abi);
3379287a 150}
This page took 0.106153 seconds and 4 git commands to generate.