1 /* Target-dependent code for GNU/Linux on Alpha.
2 Copyright (C) 2002-2019 Free Software Foundation, Inc.
4 This file is part of GDB.
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 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "solib-svr4.h"
26 #include "linux-tdep.h"
27 #include "alpha-tdep.h"
30 /* This enum represents the signals' numbers on the Alpha
31 architecture. It just contains the signal definitions which are
32 different from the generic implementation.
34 It is derived from the file <arch/alpha/include/uapi/asm/signal.h>,
35 from the Linux kernel tree. */
39 /* SIGABRT is the same as in the generic implementation, but is
40 defined here because SIGIOT depends on it. */
41 ALPHA_LINUX_SIGABRT = 6,
42 ALPHA_LINUX_SIGEMT = 7,
43 ALPHA_LINUX_SIGBUS = 10,
44 ALPHA_LINUX_SIGSYS = 12,
45 ALPHA_LINUX_SIGURG = 16,
46 ALPHA_LINUX_SIGSTOP = 17,
47 ALPHA_LINUX_SIGTSTP = 18,
48 ALPHA_LINUX_SIGCONT = 19,
49 ALPHA_LINUX_SIGCHLD = 20,
50 ALPHA_LINUX_SIGIO = 23,
51 ALPHA_LINUX_SIGINFO = 29,
52 ALPHA_LINUX_SIGUSR1 = 30,
53 ALPHA_LINUX_SIGUSR2 = 31,
54 ALPHA_LINUX_SIGPOLL = ALPHA_LINUX_SIGIO,
55 ALPHA_LINUX_SIGPWR = ALPHA_LINUX_SIGINFO,
56 ALPHA_LINUX_SIGIOT = ALPHA_LINUX_SIGABRT,
59 /* Under GNU/Linux, signal handler invocations can be identified by
60 the designated code sequence that is used to return from a signal
61 handler. In particular, the return address of a signal handler
62 points to a sequence that copies $sp to $16, loads $0 with the
63 appropriate syscall number, and finally enters the kernel.
65 This is somewhat complicated in that:
66 (1) the expansion of the "mov" assembler macro has changed over
67 time, from "bis src,src,dst" to "bis zero,src,dst",
68 (2) the kernel has changed from using "addq" to "lda" to load the
70 (3) there is a "normal" sigreturn and an "rt" sigreturn which
71 has a different stack layout. */
74 alpha_linux_sigtramp_offset_1 (struct gdbarch *gdbarch, CORE_ADDR pc)
76 switch (alpha_read_insn (gdbarch, pc))
78 case 0x47de0410: /* bis $30,$30,$16 */
79 case 0x47fe0410: /* bis $31,$30,$16 */
82 case 0x43ecf400: /* addq $31,103,$0 */
83 case 0x201f0067: /* lda $0,103($31) */
84 case 0x201f015f: /* lda $0,351($31) */
87 case 0x00000083: /* call_pal callsys */
96 alpha_linux_sigtramp_offset (struct gdbarch *gdbarch, CORE_ADDR pc)
103 /* Guess where we might be in the sequence. */
104 off = alpha_linux_sigtramp_offset_1 (gdbarch, pc);
108 /* Verify that the other two insns of the sequence are as we expect. */
110 for (i = 0; i < 12; i += 4)
114 if (alpha_linux_sigtramp_offset_1 (gdbarch, pc + i) != i)
122 alpha_linux_pc_in_sigtramp (struct gdbarch *gdbarch,
123 CORE_ADDR pc, const char *func_name)
125 return alpha_linux_sigtramp_offset (gdbarch, pc) >= 0;
129 alpha_linux_sigcontext_addr (struct frame_info *this_frame)
131 struct gdbarch *gdbarch = get_frame_arch (this_frame);
136 pc = get_frame_pc (this_frame);
137 sp = get_frame_register_unsigned (this_frame, ALPHA_SP_REGNUM);
139 off = alpha_linux_sigtramp_offset (gdbarch, pc);
140 gdb_assert (off >= 0);
142 /* __NR_rt_sigreturn has a couple of structures on the stack. This is:
149 offsetof (struct rt_sigframe, uc.uc_mcontext); */
151 if (alpha_read_insn (gdbarch, pc - off + 4) == 0x201f015f)
154 /* __NR_sigreturn has the sigcontext structure at the top of the stack. */
158 /* Supply register REGNUM from the buffer specified by GREGS and LEN
159 in the general-purpose register set REGSET to register cache
160 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
163 alpha_linux_supply_gregset (const struct regset *regset,
164 struct regcache *regcache,
165 int regnum, const void *gregs, size_t len)
167 const gdb_byte *regs = (const gdb_byte *) gregs;
169 gdb_assert (len >= 32 * 8);
170 alpha_supply_int_regs (regcache, regnum, regs, regs + 31 * 8,
171 len >= 33 * 8 ? regs + 32 * 8 : NULL);
174 /* Collect register REGNUM from the register cache REGCACHE and store
175 it in the buffer specified by GREGS and LEN as described by the
176 general-purpose register set REGSET. If REGNUM is -1, do this for
177 all registers in REGSET. */
180 alpha_linux_collect_gregset (const struct regset *regset,
181 const struct regcache *regcache,
182 int regnum, void *gregs, size_t len)
184 gdb_byte *regs = (gdb_byte *) gregs;
186 gdb_assert (len >= 32 * 8);
187 alpha_fill_int_regs (regcache, regnum, regs, regs + 31 * 8,
188 len >= 33 * 8 ? regs + 32 * 8 : NULL);
191 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
192 in the floating-point register set REGSET to register cache
193 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
196 alpha_linux_supply_fpregset (const struct regset *regset,
197 struct regcache *regcache,
198 int regnum, const void *fpregs, size_t len)
200 const gdb_byte *regs = (const gdb_byte *) fpregs;
202 gdb_assert (len >= 32 * 8);
203 alpha_supply_fp_regs (regcache, regnum, regs, regs + 31 * 8);
206 /* Collect register REGNUM from the register cache REGCACHE and store
207 it in the buffer specified by FPREGS and LEN as described by the
208 general-purpose register set REGSET. If REGNUM is -1, do this for
209 all registers in REGSET. */
212 alpha_linux_collect_fpregset (const struct regset *regset,
213 const struct regcache *regcache,
214 int regnum, void *fpregs, size_t len)
216 gdb_byte *regs = (gdb_byte *) fpregs;
218 gdb_assert (len >= 32 * 8);
219 alpha_fill_fp_regs (regcache, regnum, regs, regs + 31 * 8);
222 static const struct regset alpha_linux_gregset =
225 alpha_linux_supply_gregset, alpha_linux_collect_gregset
228 static const struct regset alpha_linux_fpregset =
231 alpha_linux_supply_fpregset, alpha_linux_collect_fpregset
234 /* Iterate over core file register note sections. */
237 alpha_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
238 iterate_over_regset_sections_cb *cb,
240 const struct regcache *regcache)
242 cb (".reg", 32 * 8, 32 * 8, &alpha_linux_gregset, NULL, cb_data);
243 cb (".reg2", 32 * 8, 32 * 8, &alpha_linux_fpregset, NULL, cb_data);
246 /* Implementation of `gdbarch_gdb_signal_from_target', as defined in
249 static enum gdb_signal
250 alpha_linux_gdb_signal_from_target (struct gdbarch *gdbarch,
255 case ALPHA_LINUX_SIGEMT:
256 return GDB_SIGNAL_EMT;
258 case ALPHA_LINUX_SIGBUS:
259 return GDB_SIGNAL_BUS;
261 case ALPHA_LINUX_SIGSYS:
262 return GDB_SIGNAL_SYS;
264 case ALPHA_LINUX_SIGURG:
265 return GDB_SIGNAL_URG;
267 case ALPHA_LINUX_SIGSTOP:
268 return GDB_SIGNAL_STOP;
270 case ALPHA_LINUX_SIGTSTP:
271 return GDB_SIGNAL_TSTP;
273 case ALPHA_LINUX_SIGCONT:
274 return GDB_SIGNAL_CONT;
276 case ALPHA_LINUX_SIGCHLD:
277 return GDB_SIGNAL_CHLD;
279 /* No way to differentiate between SIGIO and SIGPOLL.
280 Therefore, we just handle the first one. */
281 case ALPHA_LINUX_SIGIO:
282 return GDB_SIGNAL_IO;
284 /* No way to differentiate between SIGINFO and SIGPWR.
285 Therefore, we just handle the first one. */
286 case ALPHA_LINUX_SIGINFO:
287 return GDB_SIGNAL_INFO;
289 case ALPHA_LINUX_SIGUSR1:
290 return GDB_SIGNAL_USR1;
292 case ALPHA_LINUX_SIGUSR2:
293 return GDB_SIGNAL_USR2;
296 return linux_gdb_signal_from_target (gdbarch, signal);
299 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
303 alpha_linux_gdb_signal_to_target (struct gdbarch *gdbarch,
304 enum gdb_signal signal)
309 return ALPHA_LINUX_SIGEMT;
312 return ALPHA_LINUX_SIGBUS;
315 return ALPHA_LINUX_SIGSYS;
318 return ALPHA_LINUX_SIGURG;
320 case GDB_SIGNAL_STOP:
321 return ALPHA_LINUX_SIGSTOP;
323 case GDB_SIGNAL_TSTP:
324 return ALPHA_LINUX_SIGTSTP;
326 case GDB_SIGNAL_CONT:
327 return ALPHA_LINUX_SIGCONT;
329 case GDB_SIGNAL_CHLD:
330 return ALPHA_LINUX_SIGCHLD;
333 return ALPHA_LINUX_SIGIO;
335 case GDB_SIGNAL_INFO:
336 return ALPHA_LINUX_SIGINFO;
338 case GDB_SIGNAL_USR1:
339 return ALPHA_LINUX_SIGUSR1;
341 case GDB_SIGNAL_USR2:
342 return ALPHA_LINUX_SIGUSR2;
344 case GDB_SIGNAL_POLL:
345 return ALPHA_LINUX_SIGPOLL;
348 return ALPHA_LINUX_SIGPWR;
351 return linux_gdb_signal_to_target (gdbarch, signal);
355 alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
357 struct gdbarch_tdep *tdep;
359 linux_init_abi (info, gdbarch);
361 /* Hook into the DWARF CFI frame unwinder. */
362 alpha_dwarf2_init_abi (info, gdbarch);
364 /* Hook into the MDEBUG frame unwinder. */
365 alpha_mdebug_init_abi (info, gdbarch);
367 tdep = gdbarch_tdep (gdbarch);
368 tdep->dynamic_sigtramp_offset = alpha_linux_sigtramp_offset;
369 tdep->sigcontext_addr = alpha_linux_sigcontext_addr;
370 tdep->pc_in_sigtramp = alpha_linux_pc_in_sigtramp;
372 tdep->jb_elt_size = 8;
374 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
376 set_solib_svr4_fetch_link_map_offsets
377 (gdbarch, svr4_lp64_fetch_link_map_offsets);
379 /* Enable TLS support. */
380 set_gdbarch_fetch_tls_load_module_address (gdbarch,
381 svr4_fetch_objfile_link_map);
383 set_gdbarch_iterate_over_regset_sections
384 (gdbarch, alpha_linux_iterate_over_regset_sections);
386 set_gdbarch_gdb_signal_from_target (gdbarch,
387 alpha_linux_gdb_signal_from_target);
388 set_gdbarch_gdb_signal_to_target (gdbarch,
389 alpha_linux_gdb_signal_to_target);
393 _initialize_alpha_linux_tdep (void)
395 gdbarch_register_osabi (bfd_arch_alpha, 0, GDB_OSABI_LINUX,
396 alpha_linux_init_abi);