Rename target_{stop,continue}_ptid
[deliverable/binutils-gdb.git] / gdb / alpha-linux-tdep.c
CommitLineData
3379287a 1/* Target-dependent code for GNU/Linux on Alpha.
ecd75fc8 2 Copyright (C) 2002-2014 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
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
3379287a
JT
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
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
3379287a
JT
18
19#include "defs.h"
5868c862 20#include "frame.h"
f1a559ae 21#include "osabi.h"
b2756930 22#include "solib-svr4.h"
982e9687 23#include "symtab.h"
b02f9d57
UW
24#include "regset.h"
25#include "regcache.h"
a5ee0f0c 26#include "linux-tdep.h"
3379287a
JT
27#include "alpha-tdep.h"
28
eb14d406
SDJ
29/* This enum represents the signals' numbers on the Alpha
30 architecture. It just contains the signal definitions which are
31 different from the generic implementation.
32
33 It is derived from the file <arch/alpha/include/uapi/asm/signal.h>,
34 from the Linux kernel tree. */
35
36enum
37 {
38 /* SIGABRT is the same as in the generic implementation, but is
39 defined here because SIGIOT depends on it. */
40 ALPHA_LINUX_SIGABRT = 6,
41 ALPHA_LINUX_SIGEMT = 7,
42 ALPHA_LINUX_SIGBUS = 10,
43 ALPHA_LINUX_SIGSYS = 12,
44 ALPHA_LINUX_SIGURG = 16,
45 ALPHA_LINUX_SIGSTOP = 17,
46 ALPHA_LINUX_SIGTSTP = 18,
47 ALPHA_LINUX_SIGCONT = 19,
48 ALPHA_LINUX_SIGCHLD = 20,
49 ALPHA_LINUX_SIGIO = 23,
50 ALPHA_LINUX_SIGINFO = 29,
51 ALPHA_LINUX_SIGUSR1 = 30,
52 ALPHA_LINUX_SIGUSR2 = 31,
53 ALPHA_LINUX_SIGPOLL = ALPHA_LINUX_SIGIO,
54 ALPHA_LINUX_SIGPWR = ALPHA_LINUX_SIGINFO,
55 ALPHA_LINUX_SIGIOT = ALPHA_LINUX_SIGABRT,
56 };
57
d2427a71
RH
58/* Under GNU/Linux, signal handler invocations can be identified by
59 the designated code sequence that is used to return from a signal
3379287a 60 handler. In particular, the return address of a signal handler
d2427a71
RH
61 points to a sequence that copies $sp to $16, loads $0 with the
62 appropriate syscall number, and finally enters the kernel.
63
64 This is somewhat complicated in that:
65 (1) the expansion of the "mov" assembler macro has changed over
66 time, from "bis src,src,dst" to "bis zero,src,dst",
67 (2) the kernel has changed from using "addq" to "lda" to load the
68 syscall number,
69 (3) there is a "normal" sigreturn and an "rt" sigreturn which
0963b4bd 70 has a different stack layout. */
d2427a71
RH
71
72static long
e17a4113 73alpha_linux_sigtramp_offset_1 (struct gdbarch *gdbarch, CORE_ADDR pc)
3379287a 74{
e17a4113 75 switch (alpha_read_insn (gdbarch, pc))
d2427a71
RH
76 {
77 case 0x47de0410: /* bis $30,$30,$16 */
78 case 0x47fe0410: /* bis $31,$30,$16 */
79 return 0;
3379287a 80
d2427a71
RH
81 case 0x43ecf400: /* addq $31,103,$0 */
82 case 0x201f0067: /* lda $0,103($31) */
83 case 0x201f015f: /* lda $0,351($31) */
84 return 4;
85
86 case 0x00000083: /* call_pal callsys */
87 return 8;
3379287a 88
3379287a
JT
89 default:
90 return -1;
91 }
d2427a71
RH
92}
93
94static LONGEST
e17a4113 95alpha_linux_sigtramp_offset (struct gdbarch *gdbarch, CORE_ADDR pc)
d2427a71
RH
96{
97 long i, off;
98
99 if (pc & 3)
100 return -1;
101
102 /* Guess where we might be in the sequence. */
e17a4113 103 off = alpha_linux_sigtramp_offset_1 (gdbarch, pc);
d2427a71
RH
104 if (off < 0)
105 return -1;
106
107 /* Verify that the other two insns of the sequence are as we expect. */
3379287a 108 pc -= off;
d2427a71 109 for (i = 0; i < 12; i += 4)
3379287a 110 {
d2427a71
RH
111 if (i == off)
112 continue;
e17a4113 113 if (alpha_linux_sigtramp_offset_1 (gdbarch, pc + i) != i)
d2427a71 114 return -1;
3379287a 115 }
3379287a 116
d2427a71 117 return off;
3379287a
JT
118}
119
6c72f9f9 120static int
e17a4113 121alpha_linux_pc_in_sigtramp (struct gdbarch *gdbarch,
2c02bd72 122 CORE_ADDR pc, const char *func_name)
6c72f9f9 123{
e17a4113 124 return alpha_linux_sigtramp_offset (gdbarch, pc) >= 0;
6c72f9f9
JT
125}
126
5868c862 127static CORE_ADDR
94afd7a6 128alpha_linux_sigcontext_addr (struct frame_info *this_frame)
5868c862 129{
e17a4113 130 struct gdbarch *gdbarch = get_frame_arch (this_frame);
d2427a71
RH
131 CORE_ADDR pc;
132 ULONGEST sp;
133 long off;
134
94afd7a6
UW
135 pc = get_frame_pc (this_frame);
136 sp = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM);
d2427a71 137
e17a4113 138 off = alpha_linux_sigtramp_offset (gdbarch, pc);
d2427a71
RH
139 gdb_assert (off >= 0);
140
141 /* __NR_rt_sigreturn has a couple of structures on the stack. This is:
142
143 struct rt_sigframe {
144 struct siginfo info;
145 struct ucontext uc;
146 };
147
0963b4bd
MS
148 offsetof (struct rt_sigframe, uc.uc_mcontext); */
149
e17a4113 150 if (alpha_read_insn (gdbarch, pc - off + 4) == 0x201f015f)
d2427a71
RH
151 return sp + 176;
152
153 /* __NR_sigreturn has the sigcontext structure at the top of the stack. */
154 return sp;
5868c862
JT
155}
156
b02f9d57
UW
157/* Supply register REGNUM from the buffer specified by GREGS and LEN
158 in the general-purpose register set REGSET to register cache
159 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
160
161static void
162alpha_linux_supply_gregset (const struct regset *regset,
163 struct regcache *regcache,
164 int regnum, const void *gregs, size_t len)
165{
166 const gdb_byte *regs = gregs;
1d6e7555 167
b02f9d57 168 gdb_assert (len >= 32 * 8);
1d6e7555
AA
169 alpha_supply_int_regs (regcache, regnum, regs, regs + 31 * 8,
170 len >= 33 * 8 ? regs + 32 * 8 : NULL);
171}
b02f9d57 172
1d6e7555
AA
173/* Collect register REGNUM from the register cache REGCACHE and store
174 it in the buffer specified by GREGS and LEN as described by the
175 general-purpose register set REGSET. If REGNUM is -1, do this for
176 all registers in REGSET. */
b02f9d57 177
1d6e7555
AA
178static void
179alpha_linux_collect_gregset (const struct regset *regset,
180 const struct regcache *regcache,
181 int regnum, void *gregs, size_t len)
182{
183 gdb_byte *regs = gregs;
b02f9d57 184
1d6e7555
AA
185 gdb_assert (len >= 32 * 8);
186 alpha_fill_int_regs (regcache, regnum, regs, regs + 31 * 8,
187 len >= 33 * 8 ? regs + 32 * 8 : NULL);
b02f9d57
UW
188}
189
190/* Supply register REGNUM from the buffer specified by FPREGS and LEN
191 in the floating-point register set REGSET to register cache
192 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
193
194static void
195alpha_linux_supply_fpregset (const struct regset *regset,
196 struct regcache *regcache,
197 int regnum, const void *fpregs, size_t len)
198{
199 const gdb_byte *regs = fpregs;
1d6e7555 200
b02f9d57 201 gdb_assert (len >= 32 * 8);
1d6e7555
AA
202 alpha_supply_fp_regs (regcache, regnum, regs, regs + 31 * 8);
203}
b02f9d57 204
1d6e7555
AA
205/* Collect register REGNUM from the register cache REGCACHE and store
206 it in the buffer specified by FPREGS and LEN as described by the
207 general-purpose register set REGSET. If REGNUM is -1, do this for
208 all registers in REGSET. */
b02f9d57 209
1d6e7555
AA
210static void
211alpha_linux_collect_fpregset (const struct regset *regset,
212 const struct regcache *regcache,
213 int regnum, void *fpregs, size_t len)
214{
215 gdb_byte *regs = fpregs;
216
217 gdb_assert (len >= 32 * 8);
218 alpha_fill_fp_regs (regcache, regnum, regs, regs + 31 * 8);
b02f9d57
UW
219}
220
3ca7dae4 221static const struct regset alpha_linux_gregset =
b02f9d57
UW
222{
223 NULL,
1d6e7555 224 alpha_linux_supply_gregset, alpha_linux_collect_gregset
b02f9d57
UW
225};
226
3ca7dae4 227static const struct regset alpha_linux_fpregset =
b02f9d57
UW
228{
229 NULL,
1d6e7555 230 alpha_linux_supply_fpregset, alpha_linux_collect_fpregset
b02f9d57
UW
231};
232
233/* Return the appropriate register set for the core section identified
234 by SECT_NAME and SECT_SIZE. */
235
63807e1d 236static const struct regset *
b02f9d57
UW
237alpha_linux_regset_from_core_section (struct gdbarch *gdbarch,
238 const char *sect_name, size_t sect_size)
239{
240 if (strcmp (sect_name, ".reg") == 0 && sect_size >= 32 * 8)
241 return &alpha_linux_gregset;
242
243 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 32 * 8)
244 return &alpha_linux_fpregset;
245
246 return NULL;
247}
248
eb14d406
SDJ
249/* Implementation of `gdbarch_gdb_signal_from_target', as defined in
250 gdbarch.h. */
251
252static enum gdb_signal
253alpha_linux_gdb_signal_from_target (struct gdbarch *gdbarch,
254 int signal)
255{
256 switch (signal)
257 {
258 case ALPHA_LINUX_SIGEMT:
259 return GDB_SIGNAL_EMT;
260
261 case ALPHA_LINUX_SIGBUS:
262 return GDB_SIGNAL_BUS;
263
264 case ALPHA_LINUX_SIGSYS:
265 return GDB_SIGNAL_SYS;
266
267 case ALPHA_LINUX_SIGURG:
268 return GDB_SIGNAL_URG;
269
270 case ALPHA_LINUX_SIGSTOP:
271 return GDB_SIGNAL_STOP;
272
273 case ALPHA_LINUX_SIGTSTP:
274 return GDB_SIGNAL_TSTP;
275
276 case ALPHA_LINUX_SIGCONT:
277 return GDB_SIGNAL_CONT;
278
279 case ALPHA_LINUX_SIGCHLD:
280 return GDB_SIGNAL_CHLD;
281
282 /* No way to differentiate between SIGIO and SIGPOLL.
283 Therefore, we just handle the first one. */
284 case ALPHA_LINUX_SIGIO:
285 return GDB_SIGNAL_IO;
286
287 /* No way to differentiate between SIGINFO and SIGPWR.
288 Therefore, we just handle the first one. */
289 case ALPHA_LINUX_SIGINFO:
290 return GDB_SIGNAL_INFO;
291
292 case ALPHA_LINUX_SIGUSR1:
293 return GDB_SIGNAL_USR1;
294
295 case ALPHA_LINUX_SIGUSR2:
296 return GDB_SIGNAL_USR2;
297 }
298
299 return linux_gdb_signal_from_target (gdbarch, signal);
300}
301
302/* Implementation of `gdbarch_gdb_signal_to_target', as defined in
303 gdbarch.h. */
304
305static int
306alpha_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
307 enum gdb_signal signal)
308{
309 switch (signal)
310 {
311 case GDB_SIGNAL_EMT:
312 return ALPHA_LINUX_SIGEMT;
313
314 case GDB_SIGNAL_BUS:
315 return ALPHA_LINUX_SIGBUS;
316
317 case GDB_SIGNAL_SYS:
318 return ALPHA_LINUX_SIGSYS;
319
320 case GDB_SIGNAL_URG:
321 return ALPHA_LINUX_SIGURG;
322
323 case GDB_SIGNAL_STOP:
324 return ALPHA_LINUX_SIGSTOP;
325
326 case GDB_SIGNAL_TSTP:
327 return ALPHA_LINUX_SIGTSTP;
328
329 case GDB_SIGNAL_CONT:
330 return ALPHA_LINUX_SIGCONT;
331
332 case GDB_SIGNAL_CHLD:
333 return ALPHA_LINUX_SIGCHLD;
334
335 case GDB_SIGNAL_IO:
336 return ALPHA_LINUX_SIGIO;
337
338 case GDB_SIGNAL_INFO:
339 return ALPHA_LINUX_SIGINFO;
340
341 case GDB_SIGNAL_USR1:
342 return ALPHA_LINUX_SIGUSR1;
343
344 case GDB_SIGNAL_USR2:
345 return ALPHA_LINUX_SIGUSR2;
346
347 case GDB_SIGNAL_POLL:
348 return ALPHA_LINUX_SIGPOLL;
349
350 case GDB_SIGNAL_PWR:
351 return ALPHA_LINUX_SIGPWR;
352 }
353
354 return linux_gdb_signal_to_target (gdbarch, signal);
355}
356
3379287a 357static void
baa490c4 358alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
3379287a 359{
d2427a71
RH
360 struct gdbarch_tdep *tdep;
361
a5ee0f0c
PA
362 linux_init_abi (info, gdbarch);
363
f1a559ae 364 /* Hook into the DWARF CFI frame unwinder. */
baa490c4 365 alpha_dwarf2_init_abi (info, gdbarch);
f1a559ae
RH
366
367 /* Hook into the MDEBUG frame unwinder. */
d2427a71 368 alpha_mdebug_init_abi (info, gdbarch);
36a6271d 369
d2427a71 370 tdep = gdbarch_tdep (gdbarch);
36a6271d 371 tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
5868c862 372 tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
f2524b93 373 tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
accc6d1f
JT
374 tdep->jb_pc = 2;
375 tdep->jb_elt_size = 8;
b2756930 376
982e9687
UW
377 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
378
8d005789
UW
379 set_solib_svr4_fetch_link_map_offsets
380 (gdbarch, svr4_lp64_fetch_link_map_offsets);
381
b2756930
KB
382 /* Enable TLS support. */
383 set_gdbarch_fetch_tls_load_module_address (gdbarch,
384 svr4_fetch_objfile_link_map);
b02f9d57
UW
385
386 set_gdbarch_regset_from_core_section
387 (gdbarch, alpha_linux_regset_from_core_section);
eb14d406
SDJ
388
389 set_gdbarch_gdb_signal_from_target (gdbarch,
390 alpha_linux_gdb_signal_from_target);
391 set_gdbarch_gdb_signal_to_target (gdbarch,
392 alpha_linux_gdb_signal_to_target);
3379287a
JT
393}
394
63807e1d
PA
395/* Provide a prototype to silence -Wmissing-prototypes. */
396extern initialize_file_ftype _initialize_alpha_linux_tdep;
397
3379287a
JT
398void
399_initialize_alpha_linux_tdep (void)
400{
05816f70 401 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_LINUX,
70f80edf 402 alpha_linux_init_abi);
3379287a 403}
This page took 0.760788 seconds and 4 git commands to generate.