* ada-lang.c (user_select_syms): Use SYMBOL_SYMTAB.
[deliverable/binutils-gdb.git] / gdb / sparc-linux-tdep.c
CommitLineData
386c036b
MK
1/* Target-dependent code for GNU/Linux SPARC.
2
0b302171 3 Copyright (C) 2003-2005, 2007-2012 Free Software Foundation, Inc.
386c036b
MK
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
386c036b
MK
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
386c036b
MK
19
20#include "defs.h"
faea95b1 21#include "dwarf2-frame.h"
386c036b
MK
22#include "frame.h"
23#include "frame-unwind.h"
e6bb342a 24#include "gdbtypes.h"
07c5f590 25#include "regset.h"
386c036b
MK
26#include "gdbarch.h"
27#include "gdbcore.h"
28#include "osabi.h"
29#include "regcache.h"
30#include "solib-svr4.h"
31#include "symtab.h"
32#include "trad-frame.h"
70f1dc74 33#include "tramp-frame.h"
09de9781 34#include "xml-syscall.h"
a5ee0f0c 35#include "linux-tdep.h"
09de9781
DM
36
37/* The syscall's XML filename for sparc 32-bit. */
38#define XML_SYSCALL_FILENAME_SPARC32 "syscalls/sparc-linux.xml"
386c036b 39
386c036b
MK
40#include "sparc-tdep.h"
41
81f726ab 42/* Signal trampoline support. */
386c036b 43
70f1dc74 44static void sparc32_linux_sigframe_init (const struct tramp_frame *self,
5366653e 45 struct frame_info *this_frame,
70f1dc74
MK
46 struct trad_frame_cache *this_cache,
47 CORE_ADDR func);
48
386c036b
MK
49/* GNU/Linux has two flavors of signals. Normal signal handlers, and
50 "realtime" (RT) signals. The RT signals can provide additional
51 information to the signal handler if the SA_SIGINFO flag is set
52 when establishing a signal handler using `sigaction'. It is not
53 unlikely that future versions of GNU/Linux will support SA_SIGINFO
54 for normal signals too. */
55
56/* When the sparc Linux kernel calls a signal handler and the
57 SA_RESTORER flag isn't set, the return address points to a bit of
70f1dc74
MK
58 code on the stack. This code checks whether the PC appears to be
59 within this bit of code.
386c036b 60
70f1dc74 61 The instruction sequence for normal signals is encoded below.
386c036b
MK
62 Checking for the code sequence should be somewhat reliable, because
63 the effect is to call the system call sigreturn. This is unlikely
70f1dc74 64 to occur anywhere other than a signal trampoline. */
386c036b 65
70f1dc74
MK
66static const struct tramp_frame sparc32_linux_sigframe =
67{
81f726ab
DM
68 SIGTRAMP_FRAME,
69 4,
70 {
70f1dc74
MK
71 { 0x821020d8, -1 }, /* mov __NR_sugreturn, %g1 */
72 { 0x91d02010, -1 }, /* ta 0x10 */
81f726ab
DM
73 { TRAMP_SENTINEL_INSN, -1 }
74 },
75 sparc32_linux_sigframe_init
76};
386c036b 77
70f1dc74
MK
78/* The instruction sequence for RT signals is slightly different. The
79 effect is to call the system call rt_sigreturn. */
80
81static const struct tramp_frame sparc32_linux_rt_sigframe =
82{
81f726ab
DM
83 SIGTRAMP_FRAME,
84 4,
85 {
70f1dc74
MK
86 { 0x82102065, -1 }, /* mov __NR_rt_sigreturn, %g1 */
87 { 0x91d02010, -1 }, /* ta 0x10 */
81f726ab
DM
88 { TRAMP_SENTINEL_INSN, -1 }
89 },
90 sparc32_linux_sigframe_init
91};
386c036b 92
81f726ab
DM
93static void
94sparc32_linux_sigframe_init (const struct tramp_frame *self,
5366653e 95 struct frame_info *this_frame,
81f726ab
DM
96 struct trad_frame_cache *this_cache,
97 CORE_ADDR func)
386c036b 98{
80f9e3aa 99 CORE_ADDR base, addr, sp_addr;
386c036b
MK
100 int regnum;
101
5366653e 102 base = get_frame_register_unsigned (this_frame, SPARC_O1_REGNUM);
81f726ab
DM
103 if (self == &sparc32_linux_rt_sigframe)
104 base += 128;
386c036b 105
70f1dc74 106 /* Offsets from <bits/sigcontext.h>. */
78a0fd57 107
70f1dc74
MK
108 trad_frame_set_reg_addr (this_cache, SPARC32_PSR_REGNUM, base + 0);
109 trad_frame_set_reg_addr (this_cache, SPARC32_PC_REGNUM, base + 4);
110 trad_frame_set_reg_addr (this_cache, SPARC32_NPC_REGNUM, base + 8);
111 trad_frame_set_reg_addr (this_cache, SPARC32_Y_REGNUM, base + 12);
386c036b
MK
112
113 /* Since %g0 is always zero, keep the identity encoding. */
70f1dc74 114 addr = base + 20;
80f9e3aa 115 sp_addr = base + 16 + ((SPARC_SP_REGNUM - SPARC_G0_REGNUM) * 4);
81f726ab
DM
116 for (regnum = SPARC_G1_REGNUM; regnum <= SPARC_O7_REGNUM; regnum++)
117 {
118 trad_frame_set_reg_addr (this_cache, regnum, addr);
119 addr += 4;
120 }
386c036b 121
5366653e
DJ
122 base = get_frame_register_unsigned (this_frame, SPARC_SP_REGNUM);
123 addr = get_frame_memory_unsigned (this_frame, sp_addr, 4);
80f9e3aa 124
81f726ab
DM
125 for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
126 {
127 trad_frame_set_reg_addr (this_cache, regnum, addr);
128 addr += 4;
129 }
130 trad_frame_set_id (this_cache, frame_id_build (base, func));
386c036b 131}
386c036b 132\f
0b4294d3
DM
133/* Return the address of a system call's alternative return
134 address. */
135
136static CORE_ADDR
0b1b3e42 137sparc32_linux_step_trap (struct frame_info *frame, unsigned long insn)
0b4294d3
DM
138{
139 if (insn == 0x91d02010)
140 {
0b1b3e42 141 ULONGEST sc_num = get_frame_register_unsigned (frame, SPARC_G1_REGNUM);
0b4294d3 142
c378eb4e 143 /* __NR_rt_sigreturn is 101 and __NR_sigreturn is 216. */
0b4294d3
DM
144 if (sc_num == 101 || sc_num == 216)
145 {
e17a4113
UW
146 struct gdbarch *gdbarch = get_frame_arch (frame);
147 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
148
0b4294d3
DM
149 ULONGEST sp, pc_offset;
150
0b1b3e42 151 sp = get_frame_register_unsigned (frame, SPARC_SP_REGNUM);
0b4294d3
DM
152
153 /* The kernel puts the sigreturn registers on the stack,
154 and this is where the signal unwinding state is take from
155 when returning from a signal.
156
157 For __NR_sigreturn, this register area sits 96 bytes from
158 the base of the stack. The saved PC sits 4 bytes into the
159 sigreturn register save area.
160
161 For __NR_rt_sigreturn a siginfo_t, which is 128 bytes, sits
162 right before the sigreturn register save area. */
163
164 pc_offset = 96 + 4;
165 if (sc_num == 101)
166 pc_offset += 128;
167
e17a4113 168 return read_memory_unsigned_integer (sp + pc_offset, 4, byte_order);
0b4294d3
DM
169 }
170 }
171
172 return 0;
173}
174\f
386c036b 175
07c5f590
DM
176const struct sparc_gregset sparc32_linux_core_gregset =
177{
178 32 * 4, /* %psr */
179 33 * 4, /* %pc */
180 34 * 4, /* %npc */
181 35 * 4, /* %y */
182 -1, /* %wim */
183 -1, /* %tbr */
184 1 * 4, /* %g1 */
185 16 * 4, /* %l0 */
186 4, /* y size */
187};
188\f
189
190static void
191sparc32_linux_supply_core_gregset (const struct regset *regset,
192 struct regcache *regcache,
193 int regnum, const void *gregs, size_t len)
194{
c378eb4e
MS
195 sparc32_supply_gregset (&sparc32_linux_core_gregset,
196 regcache, regnum, gregs);
07c5f590
DM
197}
198
199static void
200sparc32_linux_collect_core_gregset (const struct regset *regset,
201 const struct regcache *regcache,
202 int regnum, void *gregs, size_t len)
203{
c378eb4e
MS
204 sparc32_collect_gregset (&sparc32_linux_core_gregset,
205 regcache, regnum, gregs);
07c5f590
DM
206}
207
208static void
209sparc32_linux_supply_core_fpregset (const struct regset *regset,
210 struct regcache *regcache,
211 int regnum, const void *fpregs, size_t len)
212{
db75c717 213 sparc32_supply_fpregset (&sparc32_bsd_fpregset, regcache, regnum, fpregs);
07c5f590
DM
214}
215
216static void
217sparc32_linux_collect_core_fpregset (const struct regset *regset,
218 const struct regcache *regcache,
219 int regnum, void *fpregs, size_t len)
220{
db75c717 221 sparc32_collect_fpregset (&sparc32_bsd_fpregset, regcache, regnum, fpregs);
07c5f590
DM
222}
223
e8467b5a
DM
224/* Set the program counter for process PTID to PC. */
225
226#define PSR_SYSCALL 0x00004000
227
228static void
229sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
230{
231 struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
232 ULONGEST psr;
233
234 regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
235 regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4);
236
237 /* Clear the "in syscall" bit to prevent the kernel from
238 messing with the PCs we just installed, if we happen to be
239 within an interrupted system call that the kernel wants to
240 restart.
241
242 Note that after we return from the dummy call, the PSR et al.
243 registers will be automatically restored, and the kernel
244 continues to restart the system call at this point. */
245 regcache_cooked_read_unsigned (regcache, SPARC32_PSR_REGNUM, &psr);
246 psr &= ~PSR_SYSCALL;
247 regcache_cooked_write_unsigned (regcache, SPARC32_PSR_REGNUM, psr);
248}
249
09de9781
DM
250static LONGEST
251sparc32_linux_get_syscall_number (struct gdbarch *gdbarch,
252 ptid_t ptid)
253{
254 struct regcache *regcache = get_thread_regcache (ptid);
255 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
256 /* The content of a register. */
257 gdb_byte buf[4];
258 /* The result. */
259 LONGEST ret;
260
261 /* Getting the system call number from the register.
262 When dealing with the sparc architecture, this information
263 is stored at the %g1 register. */
264 regcache_cooked_read (regcache, SPARC_G1_REGNUM, buf);
265
266 ret = extract_signed_integer (buf, 4, byte_order);
267
268 return ret;
269}
270
07c5f590
DM
271\f
272
386c036b
MK
273static void
274sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
275{
a33e488c
MK
276 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
277
a5ee0f0c
PA
278 linux_init_abi (info, gdbarch);
279
07c5f590
DM
280 tdep->gregset = regset_alloc (gdbarch, sparc32_linux_supply_core_gregset,
281 sparc32_linux_collect_core_gregset);
282 tdep->sizeof_gregset = 152;
283
284 tdep->fpregset = regset_alloc (gdbarch, sparc32_linux_supply_core_fpregset,
285 sparc32_linux_collect_core_fpregset);
286 tdep->sizeof_fpregset = 396;
287
81f726ab
DM
288 tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_sigframe);
289 tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_rt_sigframe);
290
a33e488c
MK
291 /* GNU/Linux has SVR4-style shared libraries... */
292 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
293 set_solib_svr4_fetch_link_map_offsets
294 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
386c036b 295
a33e488c
MK
296 /* ...which means that we need some special handling when doing
297 prologue analysis. */
298 tdep->plt_entry_size = 12;
386c036b 299
b2756930
KB
300 /* Enable TLS support. */
301 set_gdbarch_fetch_tls_load_module_address (gdbarch,
302 svr4_fetch_objfile_link_map);
faea95b1 303
0b4294d3
DM
304 /* Make sure we can single-step over signal return system calls. */
305 tdep->step_trap = sparc32_linux_step_trap;
306
faea95b1 307 /* Hook in the DWARF CFI frame unwinder. */
87a7da84 308 dwarf2_append_unwinders (gdbarch);
e8467b5a
DM
309
310 set_gdbarch_write_pc (gdbarch, sparc_linux_write_pc);
09de9781
DM
311
312 /* Functions for 'catch syscall'. */
313 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_SPARC32);
314 set_gdbarch_get_syscall_number (gdbarch,
315 sparc32_linux_get_syscall_number);
386c036b
MK
316}
317
318/* Provide a prototype to silence -Wmissing-prototypes. */
319extern void _initialize_sparc_linux_tdep (void);
320
321void
322_initialize_sparc_linux_tdep (void)
323{
324 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_LINUX,
325 sparc32_linux_init_abi);
326}
This page took 0.835847 seconds and 4 git commands to generate.