1 /* Target-dependent code for GNU/Linux SPARC.
3 Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "dwarf2-frame.h"
24 #include "frame-unwind.h"
31 #include "solib-svr4.h"
33 #include "trad-frame.h"
34 #include "tramp-frame.h"
36 #include "sparc-tdep.h"
38 /* Signal trampoline support. */
40 static void sparc32_linux_sigframe_init (const struct tramp_frame
*self
,
41 struct frame_info
*this_frame
,
42 struct trad_frame_cache
*this_cache
,
45 /* GNU/Linux has two flavors of signals. Normal signal handlers, and
46 "realtime" (RT) signals. The RT signals can provide additional
47 information to the signal handler if the SA_SIGINFO flag is set
48 when establishing a signal handler using `sigaction'. It is not
49 unlikely that future versions of GNU/Linux will support SA_SIGINFO
50 for normal signals too. */
52 /* When the sparc Linux kernel calls a signal handler and the
53 SA_RESTORER flag isn't set, the return address points to a bit of
54 code on the stack. This code checks whether the PC appears to be
55 within this bit of code.
57 The instruction sequence for normal signals is encoded below.
58 Checking for the code sequence should be somewhat reliable, because
59 the effect is to call the system call sigreturn. This is unlikely
60 to occur anywhere other than a signal trampoline. */
62 static const struct tramp_frame sparc32_linux_sigframe
=
67 { 0x821020d8, -1 }, /* mov __NR_sugreturn, %g1 */
68 { 0x91d02010, -1 }, /* ta 0x10 */
69 { TRAMP_SENTINEL_INSN
, -1 }
71 sparc32_linux_sigframe_init
74 /* The instruction sequence for RT signals is slightly different. The
75 effect is to call the system call rt_sigreturn. */
77 static const struct tramp_frame sparc32_linux_rt_sigframe
=
82 { 0x82102065, -1 }, /* mov __NR_rt_sigreturn, %g1 */
83 { 0x91d02010, -1 }, /* ta 0x10 */
84 { TRAMP_SENTINEL_INSN
, -1 }
86 sparc32_linux_sigframe_init
90 sparc32_linux_sigframe_init (const struct tramp_frame
*self
,
91 struct frame_info
*this_frame
,
92 struct trad_frame_cache
*this_cache
,
95 CORE_ADDR base
, addr
, sp_addr
;
98 base
= get_frame_register_unsigned (this_frame
, SPARC_O1_REGNUM
);
99 if (self
== &sparc32_linux_rt_sigframe
)
102 /* Offsets from <bits/sigcontext.h>. */
104 trad_frame_set_reg_addr (this_cache
, SPARC32_PSR_REGNUM
, base
+ 0);
105 trad_frame_set_reg_addr (this_cache
, SPARC32_PC_REGNUM
, base
+ 4);
106 trad_frame_set_reg_addr (this_cache
, SPARC32_NPC_REGNUM
, base
+ 8);
107 trad_frame_set_reg_addr (this_cache
, SPARC32_Y_REGNUM
, base
+ 12);
109 /* Since %g0 is always zero, keep the identity encoding. */
111 sp_addr
= base
+ 16 + ((SPARC_SP_REGNUM
- SPARC_G0_REGNUM
) * 4);
112 for (regnum
= SPARC_G1_REGNUM
; regnum
<= SPARC_O7_REGNUM
; regnum
++)
114 trad_frame_set_reg_addr (this_cache
, regnum
, addr
);
118 base
= get_frame_register_unsigned (this_frame
, SPARC_SP_REGNUM
);
119 addr
= get_frame_memory_unsigned (this_frame
, sp_addr
, 4);
121 for (regnum
= SPARC_L0_REGNUM
; regnum
<= SPARC_I7_REGNUM
; regnum
++)
123 trad_frame_set_reg_addr (this_cache
, regnum
, addr
);
126 trad_frame_set_id (this_cache
, frame_id_build (base
, func
));
129 /* Return the address of a system call's alternative return
133 sparc32_linux_step_trap (struct frame_info
*frame
, unsigned long insn
)
135 if (insn
== 0x91d02010)
137 ULONGEST sc_num
= get_frame_register_unsigned (frame
, SPARC_G1_REGNUM
);
139 /* __NR_rt_sigreturn is 101 and __NR_sigreturn is 216 */
140 if (sc_num
== 101 || sc_num
== 216)
142 ULONGEST sp
, pc_offset
;
144 sp
= get_frame_register_unsigned (frame
, SPARC_SP_REGNUM
);
146 /* The kernel puts the sigreturn registers on the stack,
147 and this is where the signal unwinding state is take from
148 when returning from a signal.
150 For __NR_sigreturn, this register area sits 96 bytes from
151 the base of the stack. The saved PC sits 4 bytes into the
152 sigreturn register save area.
154 For __NR_rt_sigreturn a siginfo_t, which is 128 bytes, sits
155 right before the sigreturn register save area. */
161 return read_memory_unsigned_integer (sp
+ pc_offset
, 4);
169 const struct sparc_gregset sparc32_linux_core_gregset
=
184 sparc32_linux_supply_core_gregset (const struct regset
*regset
,
185 struct regcache
*regcache
,
186 int regnum
, const void *gregs
, size_t len
)
188 sparc32_supply_gregset (&sparc32_linux_core_gregset
, regcache
, regnum
, gregs
);
192 sparc32_linux_collect_core_gregset (const struct regset
*regset
,
193 const struct regcache
*regcache
,
194 int regnum
, void *gregs
, size_t len
)
196 sparc32_collect_gregset (&sparc32_linux_core_gregset
, regcache
, regnum
, gregs
);
200 sparc32_linux_supply_core_fpregset (const struct regset
*regset
,
201 struct regcache
*regcache
,
202 int regnum
, const void *fpregs
, size_t len
)
204 sparc32_supply_fpregset (regcache
, regnum
, fpregs
);
208 sparc32_linux_collect_core_fpregset (const struct regset
*regset
,
209 const struct regcache
*regcache
,
210 int regnum
, void *fpregs
, size_t len
)
212 sparc32_collect_fpregset (regcache
, regnum
, fpregs
);
215 /* Set the program counter for process PTID to PC. */
217 #define PSR_SYSCALL 0x00004000
220 sparc_linux_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
222 struct gdbarch_tdep
*tdep
= gdbarch_tdep (get_regcache_arch (regcache
));
225 regcache_cooked_write_unsigned (regcache
, tdep
->pc_regnum
, pc
);
226 regcache_cooked_write_unsigned (regcache
, tdep
->npc_regnum
, pc
+ 4);
228 /* Clear the "in syscall" bit to prevent the kernel from
229 messing with the PCs we just installed, if we happen to be
230 within an interrupted system call that the kernel wants to
233 Note that after we return from the dummy call, the PSR et al.
234 registers will be automatically restored, and the kernel
235 continues to restart the system call at this point. */
236 regcache_cooked_read_unsigned (regcache
, SPARC32_PSR_REGNUM
, &psr
);
238 regcache_cooked_write_unsigned (regcache
, SPARC32_PSR_REGNUM
, psr
);
244 sparc32_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
246 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
248 tdep
->gregset
= regset_alloc (gdbarch
, sparc32_linux_supply_core_gregset
,
249 sparc32_linux_collect_core_gregset
);
250 tdep
->sizeof_gregset
= 152;
252 tdep
->fpregset
= regset_alloc (gdbarch
, sparc32_linux_supply_core_fpregset
,
253 sparc32_linux_collect_core_fpregset
);
254 tdep
->sizeof_fpregset
= 396;
256 tramp_frame_prepend_unwinder (gdbarch
, &sparc32_linux_sigframe
);
257 tramp_frame_prepend_unwinder (gdbarch
, &sparc32_linux_rt_sigframe
);
259 /* GNU/Linux has SVR4-style shared libraries... */
260 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
261 set_solib_svr4_fetch_link_map_offsets
262 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
264 /* ...which means that we need some special handling when doing
265 prologue analysis. */
266 tdep
->plt_entry_size
= 12;
268 /* Enable TLS support. */
269 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
270 svr4_fetch_objfile_link_map
);
272 /* Make sure we can single-step over signal return system calls. */
273 tdep
->step_trap
= sparc32_linux_step_trap
;
275 /* Hook in the DWARF CFI frame unwinder. */
276 dwarf2_append_unwinders (gdbarch
);
278 set_gdbarch_write_pc (gdbarch
, sparc_linux_write_pc
);
281 /* Provide a prototype to silence -Wmissing-prototypes. */
282 extern void _initialize_sparc_linux_tdep (void);
285 _initialize_sparc_linux_tdep (void)
287 gdbarch_register_osabi (bfd_arch_sparc
, 0, GDB_OSABI_LINUX
,
288 sparc32_linux_init_abi
);