Commit | Line | Data |
---|---|---|
386c036b MK |
1 | /* Target-dependent code for GNU/Linux SPARC. |
2 | ||
0fb0cc75 JB |
3 | Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 |
4 | Free Software Foundation, Inc. | |
386c036b MK |
5 | |
6 | This file is part of GDB. | |
7 | ||
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
386c036b MK |
11 | (at your option) any later version. |
12 | ||
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. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
386c036b MK |
20 | |
21 | #include "defs.h" | |
faea95b1 | 22 | #include "dwarf2-frame.h" |
386c036b MK |
23 | #include "frame.h" |
24 | #include "frame-unwind.h" | |
e6bb342a | 25 | #include "gdbtypes.h" |
07c5f590 | 26 | #include "regset.h" |
386c036b MK |
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" | |
70f1dc74 | 34 | #include "tramp-frame.h" |
386c036b | 35 | |
386c036b MK |
36 | #include "sparc-tdep.h" |
37 | ||
81f726ab | 38 | /* Signal trampoline support. */ |
386c036b | 39 | |
70f1dc74 | 40 | static void sparc32_linux_sigframe_init (const struct tramp_frame *self, |
5366653e | 41 | struct frame_info *this_frame, |
70f1dc74 MK |
42 | struct trad_frame_cache *this_cache, |
43 | CORE_ADDR func); | |
44 | ||
386c036b MK |
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. */ | |
51 | ||
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 | |
70f1dc74 MK |
54 | code on the stack. This code checks whether the PC appears to be |
55 | within this bit of code. | |
386c036b | 56 | |
70f1dc74 | 57 | The instruction sequence for normal signals is encoded below. |
386c036b MK |
58 | Checking for the code sequence should be somewhat reliable, because |
59 | the effect is to call the system call sigreturn. This is unlikely | |
70f1dc74 | 60 | to occur anywhere other than a signal trampoline. */ |
386c036b | 61 | |
70f1dc74 MK |
62 | static const struct tramp_frame sparc32_linux_sigframe = |
63 | { | |
81f726ab DM |
64 | SIGTRAMP_FRAME, |
65 | 4, | |
66 | { | |
70f1dc74 MK |
67 | { 0x821020d8, -1 }, /* mov __NR_sugreturn, %g1 */ |
68 | { 0x91d02010, -1 }, /* ta 0x10 */ | |
81f726ab DM |
69 | { TRAMP_SENTINEL_INSN, -1 } |
70 | }, | |
71 | sparc32_linux_sigframe_init | |
72 | }; | |
386c036b | 73 | |
70f1dc74 MK |
74 | /* The instruction sequence for RT signals is slightly different. The |
75 | effect is to call the system call rt_sigreturn. */ | |
76 | ||
77 | static const struct tramp_frame sparc32_linux_rt_sigframe = | |
78 | { | |
81f726ab DM |
79 | SIGTRAMP_FRAME, |
80 | 4, | |
81 | { | |
70f1dc74 MK |
82 | { 0x82102065, -1 }, /* mov __NR_rt_sigreturn, %g1 */ |
83 | { 0x91d02010, -1 }, /* ta 0x10 */ | |
81f726ab DM |
84 | { TRAMP_SENTINEL_INSN, -1 } |
85 | }, | |
86 | sparc32_linux_sigframe_init | |
87 | }; | |
386c036b | 88 | |
81f726ab DM |
89 | static void |
90 | sparc32_linux_sigframe_init (const struct tramp_frame *self, | |
5366653e | 91 | struct frame_info *this_frame, |
81f726ab DM |
92 | struct trad_frame_cache *this_cache, |
93 | CORE_ADDR func) | |
386c036b | 94 | { |
80f9e3aa | 95 | CORE_ADDR base, addr, sp_addr; |
386c036b MK |
96 | int regnum; |
97 | ||
5366653e | 98 | base = get_frame_register_unsigned (this_frame, SPARC_O1_REGNUM); |
81f726ab DM |
99 | if (self == &sparc32_linux_rt_sigframe) |
100 | base += 128; | |
386c036b | 101 | |
70f1dc74 | 102 | /* Offsets from <bits/sigcontext.h>. */ |
78a0fd57 | 103 | |
70f1dc74 MK |
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); | |
386c036b MK |
108 | |
109 | /* Since %g0 is always zero, keep the identity encoding. */ | |
70f1dc74 | 110 | addr = base + 20; |
80f9e3aa | 111 | sp_addr = base + 16 + ((SPARC_SP_REGNUM - SPARC_G0_REGNUM) * 4); |
81f726ab DM |
112 | for (regnum = SPARC_G1_REGNUM; regnum <= SPARC_O7_REGNUM; regnum++) |
113 | { | |
114 | trad_frame_set_reg_addr (this_cache, regnum, addr); | |
115 | addr += 4; | |
116 | } | |
386c036b | 117 | |
5366653e DJ |
118 | base = get_frame_register_unsigned (this_frame, SPARC_SP_REGNUM); |
119 | addr = get_frame_memory_unsigned (this_frame, sp_addr, 4); | |
80f9e3aa | 120 | |
81f726ab DM |
121 | for (regnum = SPARC_L0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++) |
122 | { | |
123 | trad_frame_set_reg_addr (this_cache, regnum, addr); | |
124 | addr += 4; | |
125 | } | |
126 | trad_frame_set_id (this_cache, frame_id_build (base, func)); | |
386c036b | 127 | } |
386c036b | 128 | \f |
0b4294d3 DM |
129 | /* Return the address of a system call's alternative return |
130 | address. */ | |
131 | ||
132 | static CORE_ADDR | |
0b1b3e42 | 133 | sparc32_linux_step_trap (struct frame_info *frame, unsigned long insn) |
0b4294d3 DM |
134 | { |
135 | if (insn == 0x91d02010) | |
136 | { | |
0b1b3e42 | 137 | ULONGEST sc_num = get_frame_register_unsigned (frame, SPARC_G1_REGNUM); |
0b4294d3 DM |
138 | |
139 | /* __NR_rt_sigreturn is 101 and __NR_sigreturn is 216 */ | |
140 | if (sc_num == 101 || sc_num == 216) | |
141 | { | |
e17a4113 UW |
142 | struct gdbarch *gdbarch = get_frame_arch (frame); |
143 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
144 | ||
0b4294d3 DM |
145 | ULONGEST sp, pc_offset; |
146 | ||
0b1b3e42 | 147 | sp = get_frame_register_unsigned (frame, SPARC_SP_REGNUM); |
0b4294d3 DM |
148 | |
149 | /* The kernel puts the sigreturn registers on the stack, | |
150 | and this is where the signal unwinding state is take from | |
151 | when returning from a signal. | |
152 | ||
153 | For __NR_sigreturn, this register area sits 96 bytes from | |
154 | the base of the stack. The saved PC sits 4 bytes into the | |
155 | sigreturn register save area. | |
156 | ||
157 | For __NR_rt_sigreturn a siginfo_t, which is 128 bytes, sits | |
158 | right before the sigreturn register save area. */ | |
159 | ||
160 | pc_offset = 96 + 4; | |
161 | if (sc_num == 101) | |
162 | pc_offset += 128; | |
163 | ||
e17a4113 | 164 | return read_memory_unsigned_integer (sp + pc_offset, 4, byte_order); |
0b4294d3 DM |
165 | } |
166 | } | |
167 | ||
168 | return 0; | |
169 | } | |
170 | \f | |
386c036b | 171 | |
07c5f590 DM |
172 | const struct sparc_gregset sparc32_linux_core_gregset = |
173 | { | |
174 | 32 * 4, /* %psr */ | |
175 | 33 * 4, /* %pc */ | |
176 | 34 * 4, /* %npc */ | |
177 | 35 * 4, /* %y */ | |
178 | -1, /* %wim */ | |
179 | -1, /* %tbr */ | |
180 | 1 * 4, /* %g1 */ | |
181 | 16 * 4, /* %l0 */ | |
182 | 4, /* y size */ | |
183 | }; | |
184 | \f | |
185 | ||
186 | static void | |
187 | sparc32_linux_supply_core_gregset (const struct regset *regset, | |
188 | struct regcache *regcache, | |
189 | int regnum, const void *gregs, size_t len) | |
190 | { | |
191 | sparc32_supply_gregset (&sparc32_linux_core_gregset, regcache, regnum, gregs); | |
192 | } | |
193 | ||
194 | static void | |
195 | sparc32_linux_collect_core_gregset (const struct regset *regset, | |
196 | const struct regcache *regcache, | |
197 | int regnum, void *gregs, size_t len) | |
198 | { | |
199 | sparc32_collect_gregset (&sparc32_linux_core_gregset, regcache, regnum, gregs); | |
200 | } | |
201 | ||
202 | static void | |
203 | sparc32_linux_supply_core_fpregset (const struct regset *regset, | |
204 | struct regcache *regcache, | |
205 | int regnum, const void *fpregs, size_t len) | |
206 | { | |
207 | sparc32_supply_fpregset (regcache, regnum, fpregs); | |
208 | } | |
209 | ||
210 | static void | |
211 | sparc32_linux_collect_core_fpregset (const struct regset *regset, | |
212 | const struct regcache *regcache, | |
213 | int regnum, void *fpregs, size_t len) | |
214 | { | |
215 | sparc32_collect_fpregset (regcache, regnum, fpregs); | |
216 | } | |
217 | ||
e8467b5a DM |
218 | /* Set the program counter for process PTID to PC. */ |
219 | ||
220 | #define PSR_SYSCALL 0x00004000 | |
221 | ||
222 | static void | |
223 | sparc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) | |
224 | { | |
225 | struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache)); | |
226 | ULONGEST psr; | |
227 | ||
228 | regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc); | |
229 | regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4); | |
230 | ||
231 | /* Clear the "in syscall" bit to prevent the kernel from | |
232 | messing with the PCs we just installed, if we happen to be | |
233 | within an interrupted system call that the kernel wants to | |
234 | restart. | |
235 | ||
236 | Note that after we return from the dummy call, the PSR et al. | |
237 | registers will be automatically restored, and the kernel | |
238 | continues to restart the system call at this point. */ | |
239 | regcache_cooked_read_unsigned (regcache, SPARC32_PSR_REGNUM, &psr); | |
240 | psr &= ~PSR_SYSCALL; | |
241 | regcache_cooked_write_unsigned (regcache, SPARC32_PSR_REGNUM, psr); | |
242 | } | |
243 | ||
07c5f590 DM |
244 | \f |
245 | ||
386c036b MK |
246 | static void |
247 | sparc32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
248 | { | |
a33e488c MK |
249 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
250 | ||
07c5f590 DM |
251 | tdep->gregset = regset_alloc (gdbarch, sparc32_linux_supply_core_gregset, |
252 | sparc32_linux_collect_core_gregset); | |
253 | tdep->sizeof_gregset = 152; | |
254 | ||
255 | tdep->fpregset = regset_alloc (gdbarch, sparc32_linux_supply_core_fpregset, | |
256 | sparc32_linux_collect_core_fpregset); | |
257 | tdep->sizeof_fpregset = 396; | |
258 | ||
81f726ab DM |
259 | tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_sigframe); |
260 | tramp_frame_prepend_unwinder (gdbarch, &sparc32_linux_rt_sigframe); | |
261 | ||
a33e488c MK |
262 | /* GNU/Linux has SVR4-style shared libraries... */ |
263 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); | |
264 | set_solib_svr4_fetch_link_map_offsets | |
265 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); | |
386c036b | 266 | |
a33e488c MK |
267 | /* ...which means that we need some special handling when doing |
268 | prologue analysis. */ | |
269 | tdep->plt_entry_size = 12; | |
386c036b | 270 | |
b2756930 KB |
271 | /* Enable TLS support. */ |
272 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
273 | svr4_fetch_objfile_link_map); | |
faea95b1 | 274 | |
0b4294d3 DM |
275 | /* Make sure we can single-step over signal return system calls. */ |
276 | tdep->step_trap = sparc32_linux_step_trap; | |
277 | ||
faea95b1 | 278 | /* Hook in the DWARF CFI frame unwinder. */ |
87a7da84 | 279 | dwarf2_append_unwinders (gdbarch); |
e8467b5a DM |
280 | |
281 | set_gdbarch_write_pc (gdbarch, sparc_linux_write_pc); | |
386c036b MK |
282 | } |
283 | ||
284 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
285 | extern void _initialize_sparc_linux_tdep (void); | |
286 | ||
287 | void | |
288 | _initialize_sparc_linux_tdep (void) | |
289 | { | |
290 | gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_LINUX, | |
291 | sparc32_linux_init_abi); | |
292 | } |