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