1 /* Target-dependent code for GNU/Linux SPARC.
3 Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "floatformat.h"
25 #include "frame-unwind.h"
26 #include "tramp-frame.h"
31 #include "solib-svr4.h"
33 #include "trad-frame.h"
35 #include "sparc-tdep.h"
37 /* Signal trampoline support. */
39 /* GNU/Linux has two flavors of signals. Normal signal handlers, and
40 "realtime" (RT) signals. The RT signals can provide additional
41 information to the signal handler if the SA_SIGINFO flag is set
42 when establishing a signal handler using `sigaction'. It is not
43 unlikely that future versions of GNU/Linux will support SA_SIGINFO
44 for normal signals too. */
46 /* When the sparc Linux kernel calls a signal handler and the
47 SA_RESTORER flag isn't set, the return address points to a bit of
48 code on the stack. This function returns whether the PC appears to
49 be within this bit of code.
51 The instruction sequence for normal signals is
52 mov __NR_sigreturn, %g1 ! hex: 0x821020d8
53 ta 0x10 ! hex: 0x91d02010
55 Checking for the code sequence should be somewhat reliable, because
56 the effect is to call the system call sigreturn. This is unlikely
57 to occur anywhere other than a signal trampoline.
59 It kind of sucks that we have to read memory from the process in
60 order to identify a signal trampoline, but there doesn't seem to be
61 any other way. However, sparc32_linux_pc_in_sigtramp arranges to
62 only call us if no function name could be identified, which should
63 be the case since the code is on the stack. */
65 #define LINUX32_SIGTRAMP_INSN0 0x821020d8 /* mov __NR_sigreturn, %g1 */
66 #define LINUX32_SIGTRAMP_INSN1 0x91d02010 /* ta 0x10 */
68 /* The instruction sequence for RT signals is
69 mov __NR_rt_sigreturn, %g1 ! hex: 0x82102065
70 ta {0x10,0x6d} ! hex: 0x91d02010
72 The effect is to call the system call rt_sigreturn.
73 Note that 64-bit binaries only use this RT signal return method. */
75 #define LINUX32_RT_SIGTRAMP_INSN0 0x82102065
76 #define LINUX32_RT_SIGTRAMP_INSN1 0x91d02010
78 static void sparc32_linux_sigframe_init (const struct tramp_frame *self,
79 struct frame_info *next_frame,
80 struct trad_frame_cache *this_cache,
83 static const struct tramp_frame sparc32_linux_sigframe = {
87 { LINUX32_SIGTRAMP_INSN0, -1 },
88 { LINUX32_SIGTRAMP_INSN1, -1 },
89 { TRAMP_SENTINEL_INSN, -1 }
91 sparc32_linux_sigframe_init
94 static const struct tramp_frame sparc32_linux_rt_sigframe = {
98 { LINUX32_RT_SIGTRAMP_INSN0, -1 },
99 { LINUX32_RT_SIGTRAMP_INSN1, -1 },
100 { TRAMP_SENTINEL_INSN, -1 }
102 sparc32_linux_sigframe_init
106 sparc32_linux_sigframe_init (const struct tramp_frame *self,
107 struct frame_info *next_frame,
108 struct trad_frame_cache *this_cache,
111 CORE_ADDR base, addr;
114 base = frame_unwind_register_unsigned (next_frame, SPARC_O1_REGNUM);
115 if (self == &sparc32_linux_rt_sigframe)
118 /* Offsets from <bits/sigcontext.h> */
120 trad_frame_set_reg_addr (this_cache, SPARC32_PSR_REGNUM, base + 0x00);
121 trad_frame_set_reg_addr (this_cache, SPARC32_PC_REGNUM, base + 0x04);
122 trad_frame_set_reg_addr (this_cache, SPARC32_NPC_REGNUM, base + 0x08);
123 trad_frame_set_reg_addr (this_cache, SPARC32_Y_REGNUM, base + 0x0c);
125 /* Since %g0 is always zero, keep the identity encoding. */
127 for (regnum = SPARC_G1_REGNUM; regnum <= SPARC_O7_REGNUM; regnum++)
129 trad_frame_set_reg_addr (this_cache, regnum, addr);
133 base = addr = frame_unwind_register_unsigned (next_frame, SPARC_SP_REGNUM);
134 for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
136 trad_frame_set_reg_addr (this_cache, regnum, addr);
139 trad_frame_set_id (this_cache, frame_id_build (base, func));
145 sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
147 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
149 tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_sigframe);
150 tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_rt_sigframe);
152 /* GNU/Linux has SVR4-style shared libraries... */
153 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
154 set_solib_svr4_fetch_link_map_offsets
155 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
157 /* ...which means that we need some special handling when doing
158 prologue analysis. */
159 tdep->plt_entry_size = 12;
161 /* GNU/Linux doesn't support the 128-bit `long double' from the psABI. */
162 set_gdbarch_long_double_bit (gdbarch, 64);
163 set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big);
165 /* Enable TLS support. */
166 set_gdbarch_fetch_tls_load_module_address (gdbarch,
167 svr4_fetch_objfile_link_map);
170 /* Provide a prototype to silence -Wmissing-prototypes. */
171 extern void _initialize_sparc_linux_tdep (void);
174 _initialize_sparc_linux_tdep (void)
176 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_LINUX,
177 sparc32_linux_init_abi);