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