]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/sparc-linux-tdep.c
* sparc-linux-tdep.c: Update copyright year.
[thirdparty/binutils-gdb.git] / gdb / sparc-linux-tdep.c
1 /* Target-dependent code for GNU/Linux SPARC.
2
3 Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 2 of the License, or
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
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. */
21
22 #include "defs.h"
23 #include "floatformat.h"
24 #include "frame.h"
25 #include "frame-unwind.h"
26 #include "tramp-frame.h"
27 #include "gdbarch.h"
28 #include "gdbcore.h"
29 #include "osabi.h"
30 #include "regcache.h"
31 #include "solib-svr4.h"
32 #include "symtab.h"
33 #include "trad-frame.h"
34
35 #include "sparc-tdep.h"
36
37 /* Signal trampoline support. */
38
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. */
45
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.
50
51 The instruction sequence for normal signals is
52 mov __NR_sigreturn, %g1 ! hex: 0x821020d8
53 ta 0x10 ! hex: 0x91d02010
54
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.
58
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. */
64
65 #define LINUX32_SIGTRAMP_INSN0 0x821020d8 /* mov __NR_sigreturn, %g1 */
66 #define LINUX32_SIGTRAMP_INSN1 0x91d02010 /* ta 0x10 */
67
68 /* The instruction sequence for RT signals is
69 mov __NR_rt_sigreturn, %g1 ! hex: 0x82102065
70 ta {0x10,0x6d} ! hex: 0x91d02010
71
72 The effect is to call the system call rt_sigreturn.
73 Note that 64-bit binaries only use this RT signal return method. */
74
75 #define LINUX32_RT_SIGTRAMP_INSN0 0x82102065
76 #define LINUX32_RT_SIGTRAMP_INSN1 0x91d02010
77
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,
81 CORE_ADDR func);
82
83 static const struct tramp_frame sparc32_linux_sigframe = {
84 SIGTRAMP_FRAME,
85 4,
86 {
87 { LINUX32_SIGTRAMP_INSN0, -1 },
88 { LINUX32_SIGTRAMP_INSN1, -1 },
89 { TRAMP_SENTINEL_INSN, -1 }
90 },
91 sparc32_linux_sigframe_init
92 };
93
94 static const struct tramp_frame sparc32_linux_rt_sigframe = {
95 SIGTRAMP_FRAME,
96 4,
97 {
98 { LINUX32_RT_SIGTRAMP_INSN0, -1 },
99 { LINUX32_RT_SIGTRAMP_INSN1, -1 },
100 { TRAMP_SENTINEL_INSN, -1 }
101 },
102 sparc32_linux_sigframe_init
103 };
104
105 static void
106 sparc32_linux_sigframe_init (const struct tramp_frame *self,
107 struct frame_info *next_frame,
108 struct trad_frame_cache *this_cache,
109 CORE_ADDR func)
110 {
111 CORE_ADDR base, addr;
112 int regnum;
113
114 base = frame_unwind_register_unsigned (next_frame, SPARC_O1_REGNUM);
115 if (self == &sparc32_linux_rt_sigframe)
116 base += 128;
117
118 /* Offsets from <bits/sigcontext.h> */
119
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);
124
125 /* Since %g0 is always zero, keep the identity encoding. */
126 addr = base + 0x14;
127 for (regnum = SPARC_G1_REGNUM; regnum <= SPARC_O7_REGNUM; regnum++)
128 {
129 trad_frame_set_reg_addr (this_cache, regnum, addr);
130 addr += 4;
131 }
132
133 base = addr = frame_unwind_register_unsigned (next_frame, SPARC_SP_REGNUM);
134 for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
135 {
136 trad_frame_set_reg_addr (this_cache, regnum, addr);
137 addr += 4;
138 }
139 trad_frame_set_id (this_cache, frame_id_build (base, func));
140 }
141
142 \f
143
144 static void
145 sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
146 {
147 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
148
149 tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_sigframe);
150 tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_rt_sigframe);
151
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);
156
157 /* ...which means that we need some special handling when doing
158 prologue analysis. */
159 tdep->plt_entry_size = 12;
160
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);
164
165 /* Enable TLS support. */
166 set_gdbarch_fetch_tls_load_module_address (gdbarch,
167 svr4_fetch_objfile_link_map);
168 }
169
170 /* Provide a prototype to silence -Wmissing-prototypes. */
171 extern void _initialize_sparc_linux_tdep (void);
172
173 void
174 _initialize_sparc_linux_tdep (void)
175 {
176 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_LINUX,
177 sparc32_linux_init_abi);
178 }