]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/sparc64obsd-tdep.c
* sparc64obsd-tdep.c: Include "obsd-tdep.h".
[thirdparty/binutils-gdb.git] / gdb / sparc64obsd-tdep.c
1 /* Target-dependent code for OpenBSD/sparc64.
2
3 Copyright (C) 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 #include "defs.h"
23 #include "frame.h"
24 #include "frame-unwind.h"
25 #include "osabi.h"
26 #include "regset.h"
27 #include "symtab.h"
28 #include "objfiles.h"
29 #include "solib-svr4.h"
30 #include "trad-frame.h"
31
32 #include "gdb_assert.h"
33
34 #include "obsd-tdep.h"
35 #include "sparc64-tdep.h"
36
37 /* OpenBSD uses the traditional NetBSD core file format, even for
38 ports that use ELF. The core files don't use multiple register
39 sets. Instead, the general-purpose and floating-point registers
40 are lumped together in a single section. Unlike on NetBSD, OpenBSD
41 uses a different layout for its general-purpose registers than the
42 layout used for ptrace(2). */
43
44 /* From <machine/reg.h>. */
45 const struct sparc_gregset sparc64obsd_core_gregset =
46 {
47 0 * 8, /* "tstate" */
48 1 * 8, /* %pc */
49 2 * 8, /* %npc */
50 3 * 8, /* %y */
51 -1, /* %fprs */
52 -1,
53 7 * 8, /* %g1 */
54 22 * 8, /* %l0 */
55 4 /* sizeof (%y) */
56 };
57
58 static void
59 sparc64obsd_supply_gregset (const struct regset *regset,
60 struct regcache *regcache,
61 int regnum, const void *gregs, size_t len)
62 {
63 const char *regs = gregs;
64
65 sparc64_supply_gregset (&sparc64obsd_core_gregset, regcache, regnum, regs);
66 sparc64_supply_fpregset (regcache, regnum, regs + 288);
67 }
68 \f
69
70 /* Signal trampolines. */
71
72 /* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page
73 in virtual memory. The randomness makes it somewhat tricky to
74 detect it, but fortunately we can rely on the fact that the start
75 of the sigtramp routine is page-aligned. We recognize the
76 trampoline by looking for the code that invokes the sigreturn
77 system call. The offset where we can find that code varies from
78 release to release.
79
80 By the way, the mapping mentioned above is read-only, so you cannot
81 place a breakpoint in the signal trampoline. */
82
83 /* Default page size. */
84 static const int sparc64obsd_page_size = 8192;
85
86 /* Offset for sigreturn(2). */
87 static const int sparc64obsd_sigreturn_offset[] = {
88 0xf0, /* OpenBSD 3.8 */
89 0xec, /* OpenBSD 3.6 */
90 0xe8, /* OpenBSD 3.2 */
91 -1
92 };
93
94 static int
95 sparc64obsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
96 {
97 CORE_ADDR start_pc = (pc & ~(sparc64obsd_page_size - 1));
98 unsigned long insn;
99 const int *offset;
100
101 if (name)
102 return 0;
103
104 for (offset = sparc64obsd_sigreturn_offset; *offset != -1; offset++)
105 {
106 /* Check for "restore %g0, SYS_sigreturn, %g1". */
107 insn = sparc_fetch_instruction (start_pc + *offset);
108 if (insn != 0x83e82067)
109 continue;
110
111 /* Check for "t ST_SYSCALL". */
112 insn = sparc_fetch_instruction (start_pc + *offset + 8);
113 if (insn != 0x91d02000)
114 continue;
115
116 return 1;
117 }
118
119 return 0;
120 }
121
122 static struct sparc_frame_cache *
123 sparc64obsd_frame_cache (struct frame_info *next_frame, void **this_cache)
124 {
125 struct sparc_frame_cache *cache;
126 CORE_ADDR addr;
127
128 if (*this_cache)
129 return *this_cache;
130
131 cache = sparc_frame_cache (next_frame, this_cache);
132 gdb_assert (cache == *this_cache);
133
134 /* If we couldn't find the frame's function, we're probably dealing
135 with an on-stack signal trampoline. */
136 if (cache->pc == 0)
137 {
138 cache->pc = frame_pc_unwind (next_frame);
139 cache->pc &= ~(sparc64obsd_page_size - 1);
140
141 /* Since we couldn't find the frame's function, the cache was
142 initialized under the assumption that we're frameless. */
143 cache->frameless_p = 0;
144 addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
145 if (addr & 1)
146 addr += BIAS;
147 cache->base = addr;
148 }
149
150 /* We find the appropriate instance of `struct sigcontext' at a
151 fixed offset in the signal frame. */
152 addr = cache->base + 128 + 16;
153 cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, next_frame);
154
155 return cache;
156 }
157
158 static void
159 sparc64obsd_frame_this_id (struct frame_info *next_frame, void **this_cache,
160 struct frame_id *this_id)
161 {
162 struct sparc_frame_cache *cache =
163 sparc64obsd_frame_cache (next_frame, this_cache);
164
165 (*this_id) = frame_id_build (cache->base, cache->pc);
166 }
167
168 static void
169 sparc64obsd_frame_prev_register (struct frame_info *next_frame,
170 void **this_cache,
171 int regnum, int *optimizedp,
172 enum lval_type *lvalp, CORE_ADDR *addrp,
173 int *realnump, gdb_byte *valuep)
174 {
175 struct sparc_frame_cache *cache =
176 sparc64obsd_frame_cache (next_frame, this_cache);
177
178 trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum,
179 optimizedp, lvalp, addrp, realnump, valuep);
180 }
181
182 static const struct frame_unwind sparc64obsd_frame_unwind =
183 {
184 SIGTRAMP_FRAME,
185 sparc64obsd_frame_this_id,
186 sparc64obsd_frame_prev_register
187 };
188
189 static const struct frame_unwind *
190 sparc64obsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
191 {
192 CORE_ADDR pc = frame_pc_unwind (next_frame);
193 char *name;
194
195 find_pc_partial_function (pc, &name, NULL, NULL);
196 if (sparc64obsd_pc_in_sigtramp (pc, name))
197 return &sparc64obsd_frame_unwind;
198
199 return NULL;
200 }
201 \f
202
203 static void
204 sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
205 {
206 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
207
208 tdep->gregset = regset_alloc (gdbarch, sparc64obsd_supply_gregset, NULL);
209 tdep->sizeof_gregset = 832;
210
211 frame_unwind_append_sniffer (gdbarch, sparc64obsd_sigtramp_frame_sniffer);
212
213 sparc64_init_abi (info, gdbarch);
214
215 /* OpenBSD/sparc64 has SVR4-style shared libraries. */
216 set_solib_svr4_fetch_link_map_offsets
217 (gdbarch, svr4_lp64_fetch_link_map_offsets);
218 set_gdbarch_skip_solib_resolver (gdbarch, obsd_skip_solib_resolver);
219 }
220 \f
221
222 /* Provide a prototype to silence -Wmissing-prototypes. */
223 void _initialize_sparc64obsd_tdep (void);
224
225 void
226 _initialize_sparc64obsd_tdep (void)
227 {
228 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
229 GDB_OSABI_OPENBSD_ELF, sparc64obsd_init_abi);
230 }