Update mn10300 dwarf register map
[deliverable/binutils-gdb.git] / gdb / sparc64obsd-tdep.c
CommitLineData
1e067c66
MK
1/* Target-dependent code for OpenBSD/sparc64.
2
ecd75fc8 3 Copyright (C) 2004-2014 Free Software Foundation, Inc.
1e067c66
MK
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
1e067c66
MK
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1e067c66
MK
19
20#include "defs.h"
21#include "frame.h"
22#include "frame-unwind.h"
585e38ed 23#include "gdbcore.h"
1e067c66 24#include "osabi.h"
585e38ed 25#include "regcache.h"
1e067c66
MK
26#include "regset.h"
27#include "symtab.h"
3510d1f2 28#include "objfiles.h"
1e067c66
MK
29#include "trad-frame.h"
30
31#include "gdb_assert.h"
32
4807909c 33#include "obsd-tdep.h"
1e067c66 34#include "sparc64-tdep.h"
585e38ed
MK
35#include "solib-svr4.h"
36#include "bsd-uthread.h"
1e067c66
MK
37
38/* OpenBSD uses the traditional NetBSD core file format, even for
39 ports that use ELF. The core files don't use multiple register
40 sets. Instead, the general-purpose and floating-point registers
41 are lumped together in a single section. Unlike on NetBSD, OpenBSD
42 uses a different layout for its general-purpose registers than the
43 layout used for ptrace(2). */
44
45/* From <machine/reg.h>. */
46const struct sparc_gregset sparc64obsd_core_gregset =
47{
48 0 * 8, /* "tstate" */
49 1 * 8, /* %pc */
50 2 * 8, /* %npc */
51 3 * 8, /* %y */
52 -1, /* %fprs */
53 -1,
54 7 * 8, /* %g1 */
55 22 * 8, /* %l0 */
56 4 /* sizeof (%y) */
57};
58
59static void
60sparc64obsd_supply_gregset (const struct regset *regset,
61 struct regcache *regcache,
62 int regnum, const void *gregs, size_t len)
63{
64 const char *regs = gregs;
65
9ea75c57 66 sparc64_supply_gregset (&sparc64obsd_core_gregset, regcache, regnum, regs);
db75c717 67 sparc64_supply_fpregset (&sparc64_bsd_fpregset, regcache, regnum, regs + 288);
1e067c66
MK
68}
69\f
70
71/* Signal trampolines. */
72
47b4f830
MK
73/* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page
74 in virtual memory. The randomness makes it somewhat tricky to
75 detect it, but fortunately we can rely on the fact that the start
76 of the sigtramp routine is page-aligned. We recognize the
77 trampoline by looking for the code that invokes the sigreturn
78 system call. The offset where we can find that code varies from
79 release to release.
80
81 By the way, the mapping mentioned above is read-only, so you cannot
82 place a breakpoint in the signal trampoline. */
83
84/* Default page size. */
1e067c66 85static const int sparc64obsd_page_size = 8192;
47b4f830
MK
86
87/* Offset for sigreturn(2). */
88static const int sparc64obsd_sigreturn_offset[] = {
89 0xf0, /* OpenBSD 3.8 */
90 0xec, /* OpenBSD 3.6 */
91 0xe8, /* OpenBSD 3.2 */
92 -1
93};
1e067c66
MK
94
95static int
2c02bd72 96sparc64obsd_pc_in_sigtramp (CORE_ADDR pc, const char *name)
1e067c66
MK
97{
98 CORE_ADDR start_pc = (pc & ~(sparc64obsd_page_size - 1));
99 unsigned long insn;
dc856692 100 const int *offset;
1e067c66
MK
101
102 if (name)
103 return 0;
104
dc856692 105 for (offset = sparc64obsd_sigreturn_offset; *offset != -1; offset++)
24f033e8 106 {
dc856692
MK
107 /* Check for "restore %g0, SYS_sigreturn, %g1". */
108 insn = sparc_fetch_instruction (start_pc + *offset);
109 if (insn != 0x83e82067)
110 continue;
1e067c66 111
dc856692
MK
112 /* Check for "t ST_SYSCALL". */
113 insn = sparc_fetch_instruction (start_pc + *offset + 8);
114 if (insn != 0x91d02000)
115 continue;
116
117 return 1;
5a5effe1 118 }
1e067c66 119
dc856692 120 return 0;
1e067c66
MK
121}
122
123static struct sparc_frame_cache *
94afd7a6 124sparc64obsd_frame_cache (struct frame_info *this_frame, void **this_cache)
1e067c66
MK
125{
126 struct sparc_frame_cache *cache;
127 CORE_ADDR addr;
128
129 if (*this_cache)
130 return *this_cache;
131
94afd7a6 132 cache = sparc_frame_cache (this_frame, this_cache);
1e067c66
MK
133 gdb_assert (cache == *this_cache);
134
135 /* If we couldn't find the frame's function, we're probably dealing
136 with an on-stack signal trampoline. */
137 if (cache->pc == 0)
138 {
94afd7a6 139 cache->pc = get_frame_pc (this_frame);
1e067c66
MK
140 cache->pc &= ~(sparc64obsd_page_size - 1);
141
142 /* Since we couldn't find the frame's function, the cache was
143 initialized under the assumption that we're frameless. */
369c397b 144 sparc_record_save_insn (cache);
94afd7a6 145 addr = get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
5b2d44a0
MK
146 if (addr & 1)
147 addr += BIAS;
1e067c66
MK
148 cache->base = addr;
149 }
150
151 /* We find the appropriate instance of `struct sigcontext' at a
152 fixed offset in the signal frame. */
5b2d44a0 153 addr = cache->base + 128 + 16;
94afd7a6 154 cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, this_frame);
1e067c66
MK
155
156 return cache;
157}
158
159static void
94afd7a6 160sparc64obsd_frame_this_id (struct frame_info *this_frame, void **this_cache,
1e067c66
MK
161 struct frame_id *this_id)
162{
163 struct sparc_frame_cache *cache =
94afd7a6 164 sparc64obsd_frame_cache (this_frame, this_cache);
1e067c66
MK
165
166 (*this_id) = frame_id_build (cache->base, cache->pc);
167}
168
94afd7a6
UW
169static struct value *
170sparc64obsd_frame_prev_register (struct frame_info *this_frame,
171 void **this_cache, int regnum)
1e067c66
MK
172{
173 struct sparc_frame_cache *cache =
94afd7a6 174 sparc64obsd_frame_cache (this_frame, this_cache);
1e067c66 175
94afd7a6 176 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
1e067c66
MK
177}
178
94afd7a6
UW
179static int
180sparc64obsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
181 struct frame_info *this_frame,
182 void **this_cache)
1e067c66 183{
94afd7a6 184 CORE_ADDR pc = get_frame_pc (this_frame);
2c02bd72 185 const char *name;
1e067c66
MK
186
187 find_pc_partial_function (pc, &name, NULL, NULL);
188 if (sparc64obsd_pc_in_sigtramp (pc, name))
94afd7a6 189 return 1;
1e067c66 190
94afd7a6 191 return 0;
1e067c66 192}
94afd7a6
UW
193
194static const struct frame_unwind sparc64obsd_frame_unwind =
195{
196 SIGTRAMP_FRAME,
8fbca658 197 default_frame_unwind_stop_reason,
94afd7a6
UW
198 sparc64obsd_frame_this_id,
199 sparc64obsd_frame_prev_register,
200 NULL,
201 sparc64obsd_sigtramp_frame_sniffer
202};
1e067c66 203\f
6df5070e
MK
204/* Kernel debugging support. */
205
206static struct sparc_frame_cache *
94afd7a6 207sparc64obsd_trapframe_cache (struct frame_info *this_frame, void **this_cache)
6df5070e
MK
208{
209 struct sparc_frame_cache *cache;
210 CORE_ADDR sp, trapframe_addr;
211 int regnum;
212
213 if (*this_cache)
214 return *this_cache;
215
94afd7a6 216 cache = sparc_frame_cache (this_frame, this_cache);
6df5070e
MK
217 gdb_assert (cache == *this_cache);
218
94afd7a6 219 sp = get_frame_register_unsigned (this_frame, SPARC_SP_REGNUM);
6df5070e
MK
220 trapframe_addr = sp + BIAS + 176;
221
94afd7a6 222 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
6df5070e
MK
223
224 cache->saved_regs[SPARC64_STATE_REGNUM].addr = trapframe_addr;
225 cache->saved_regs[SPARC64_PC_REGNUM].addr = trapframe_addr + 8;
226 cache->saved_regs[SPARC64_NPC_REGNUM].addr = trapframe_addr + 16;
227
228 for (regnum = SPARC_G0_REGNUM; regnum <= SPARC_I7_REGNUM; regnum++)
229 cache->saved_regs[regnum].addr =
230 trapframe_addr + 48 + (regnum - SPARC_G0_REGNUM) * 8;
231
232 return cache;
233}
234
235static void
94afd7a6 236sparc64obsd_trapframe_this_id (struct frame_info *this_frame,
6df5070e
MK
237 void **this_cache, struct frame_id *this_id)
238{
239 struct sparc_frame_cache *cache =
94afd7a6 240 sparc64obsd_trapframe_cache (this_frame, this_cache);
6df5070e
MK
241
242 (*this_id) = frame_id_build (cache->base, cache->pc);
243}
244
94afd7a6
UW
245static struct value *
246sparc64obsd_trapframe_prev_register (struct frame_info *this_frame,
247 void **this_cache, int regnum)
6df5070e
MK
248{
249 struct sparc_frame_cache *cache =
94afd7a6 250 sparc64obsd_trapframe_cache (this_frame, this_cache);
6df5070e 251
94afd7a6 252 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
6df5070e
MK
253}
254
94afd7a6
UW
255static int
256sparc64obsd_trapframe_sniffer (const struct frame_unwind *self,
257 struct frame_info *this_frame,
258 void **this_cache)
6df5070e 259{
93d42b30 260 CORE_ADDR pc;
6df5070e 261 ULONGEST pstate;
2c02bd72 262 const char *name;
6df5070e
MK
263
264 /* Check whether we are in privileged mode, and bail out if we're not. */
94afd7a6 265 pstate = get_frame_register_unsigned (this_frame, SPARC64_PSTATE_REGNUM);
6df5070e 266 if ((pstate & SPARC64_PSTATE_PRIV) == 0)
94afd7a6 267 return 0;
6df5070e 268
94afd7a6 269 pc = get_frame_address_in_block (this_frame);
93d42b30 270 find_pc_partial_function (pc, &name, NULL, NULL);
6df5070e 271 if (name && strcmp (name, "Lslowtrap_reenter") == 0)
94afd7a6 272 return 1;
6df5070e 273
94afd7a6 274 return 0;
6df5070e 275}
94afd7a6
UW
276
277static const struct frame_unwind sparc64obsd_trapframe_unwind =
278{
279 NORMAL_FRAME,
8fbca658 280 default_frame_unwind_stop_reason,
94afd7a6
UW
281 sparc64obsd_trapframe_this_id,
282 sparc64obsd_trapframe_prev_register,
283 NULL,
284 sparc64obsd_trapframe_sniffer
285};
6df5070e 286\f
1e067c66 287
585e38ed
MK
288/* Threads support. */
289
290/* Offset wthin the thread structure where we can find %fp and %i7. */
291#define SPARC64OBSD_UTHREAD_FP_OFFSET 232
292#define SPARC64OBSD_UTHREAD_PC_OFFSET 240
293
294static void
295sparc64obsd_supply_uthread (struct regcache *regcache,
296 int regnum, CORE_ADDR addr)
297{
e17a4113
UW
298 struct gdbarch *gdbarch = get_regcache_arch (regcache);
299 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
585e38ed
MK
300 CORE_ADDR fp, fp_addr = addr + SPARC64OBSD_UTHREAD_FP_OFFSET;
301 gdb_byte buf[8];
302
303 gdb_assert (regnum >= -1);
304
e17a4113 305 fp = read_memory_unsigned_integer (fp_addr, 8, byte_order);
585e38ed
MK
306 if (regnum == SPARC_SP_REGNUM || regnum == -1)
307 {
e17a4113 308 store_unsigned_integer (buf, 8, byte_order, fp);
585e38ed
MK
309 regcache_raw_supply (regcache, SPARC_SP_REGNUM, buf);
310
311 if (regnum == SPARC_SP_REGNUM)
312 return;
313 }
314
315 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM
316 || regnum == -1)
317 {
318 CORE_ADDR i7, i7_addr = addr + SPARC64OBSD_UTHREAD_PC_OFFSET;
319
e17a4113 320 i7 = read_memory_unsigned_integer (i7_addr, 8, byte_order);
585e38ed
MK
321 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
322 {
e17a4113 323 store_unsigned_integer (buf, 8, byte_order, i7 + 8);
585e38ed
MK
324 regcache_raw_supply (regcache, SPARC64_PC_REGNUM, buf);
325 }
326 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
327 {
e17a4113 328 store_unsigned_integer (buf, 8, byte_order, i7 + 12);
585e38ed
MK
329 regcache_raw_supply (regcache, SPARC64_NPC_REGNUM, buf);
330 }
331
332 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
333 return;
334 }
335
336 sparc_supply_rwindow (regcache, fp, regnum);
337}
338
339static void
340sparc64obsd_collect_uthread(const struct regcache *regcache,
341 int regnum, CORE_ADDR addr)
342{
e17a4113
UW
343 struct gdbarch *gdbarch = get_regcache_arch (regcache);
344 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
585e38ed
MK
345 CORE_ADDR sp;
346 gdb_byte buf[8];
347
348 gdb_assert (regnum >= -1);
349
350 if (regnum == SPARC_SP_REGNUM || regnum == -1)
351 {
352 CORE_ADDR fp_addr = addr + SPARC64OBSD_UTHREAD_FP_OFFSET;
353
354 regcache_raw_collect (regcache, SPARC_SP_REGNUM, buf);
355 write_memory (fp_addr,buf, 8);
356 }
357
358 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
359 {
360 CORE_ADDR i7, i7_addr = addr + SPARC64OBSD_UTHREAD_PC_OFFSET;
361
362 regcache_raw_collect (regcache, SPARC64_PC_REGNUM, buf);
e17a4113
UW
363 i7 = extract_unsigned_integer (buf, 8, byte_order) - 8;
364 write_memory_unsigned_integer (i7_addr, 8, byte_order, i7);
585e38ed
MK
365
366 if (regnum == SPARC64_PC_REGNUM)
367 return;
368 }
369
370 regcache_raw_collect (regcache, SPARC_SP_REGNUM, buf);
e17a4113 371 sp = extract_unsigned_integer (buf, 8, byte_order);
585e38ed
MK
372 sparc_collect_rwindow (regcache, sp, regnum);
373}
374\f
375
1e067c66
MK
376static void
377sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
378{
379 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
380
9ea75c57 381 tdep->gregset = regset_alloc (gdbarch, sparc64obsd_supply_gregset, NULL);
1e067c66
MK
382 tdep->sizeof_gregset = 832;
383
c893be75
MK
384 /* Make sure we can single-step "new" syscalls. */
385 tdep->step_trap = sparcnbsd_step_trap;
386
94afd7a6
UW
387 frame_unwind_append_unwinder (gdbarch, &sparc64obsd_frame_unwind);
388 frame_unwind_append_unwinder (gdbarch, &sparc64obsd_trapframe_unwind);
1e067c66
MK
389
390 sparc64_init_abi (info, gdbarch);
391
5b2d44a0 392 /* OpenBSD/sparc64 has SVR4-style shared libraries. */
1e067c66 393 set_solib_svr4_fetch_link_map_offsets
3510d1f2 394 (gdbarch, svr4_lp64_fetch_link_map_offsets);
4807909c 395 set_gdbarch_skip_solib_resolver (gdbarch, obsd_skip_solib_resolver);
585e38ed
MK
396
397 /* OpenBSD provides a user-level threads implementation. */
398 bsd_uthread_set_supply_uthread (gdbarch, sparc64obsd_supply_uthread);
399 bsd_uthread_set_collect_uthread (gdbarch, sparc64obsd_collect_uthread);
1e067c66 400}
1e067c66 401\f
5b2d44a0 402
1e067c66
MK
403/* Provide a prototype to silence -Wmissing-prototypes. */
404void _initialize_sparc64obsd_tdep (void);
405
406void
407_initialize_sparc64obsd_tdep (void)
408{
409 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
410 GDB_OSABI_OPENBSD_ELF, sparc64obsd_init_abi);
411}
This page took 1.085956 seconds and 4 git commands to generate.