remove duplicated word
[deliverable/binutils-gdb.git] / gdb / sparc64obsd-tdep.c
CommitLineData
1e067c66
MK
1/* Target-dependent code for OpenBSD/sparc64.
2
3 Copyright 2004 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 "frame.h"
24#include "frame-unwind.h"
25#include "osabi.h"
26#include "regset.h"
27#include "symtab.h"
28#include "solib-svr4.h"
29#include "trad-frame.h"
30
31#include "gdb_assert.h"
32
33#include "sparc64-tdep.h"
34#include "nbsd-tdep.h"
35
36/* OpenBSD uses the traditional NetBSD core file format, even for
37 ports that use ELF. The core files don't use multiple register
38 sets. Instead, the general-purpose and floating-point registers
39 are lumped together in a single section. Unlike on NetBSD, OpenBSD
40 uses a different layout for its general-purpose registers than the
41 layout used for ptrace(2). */
42
43/* From <machine/reg.h>. */
44const struct sparc_gregset sparc64obsd_core_gregset =
45{
46 0 * 8, /* "tstate" */
47 1 * 8, /* %pc */
48 2 * 8, /* %npc */
49 3 * 8, /* %y */
50 -1, /* %fprs */
51 -1,
52 7 * 8, /* %g1 */
53 22 * 8, /* %l0 */
54 4 /* sizeof (%y) */
55};
56
57static void
58sparc64obsd_supply_gregset (const struct regset *regset,
59 struct regcache *regcache,
60 int regnum, const void *gregs, size_t len)
61{
62 const char *regs = gregs;
63
9ea75c57 64 sparc64_supply_gregset (&sparc64obsd_core_gregset, regcache, regnum, regs);
1e067c66
MK
65 sparc64_supply_fpregset (regcache, regnum, regs + 288);
66}
67\f
68
69/* Signal trampolines. */
70
71/* The OpenBSD kernel maps the signal trampoline at some random
72 location in user space, which means that the traditional BSD way of
73 detecting it won't work.
74
75 The signal trampoline will be mapped at an address that is page
76 aligned. We recognize the signal trampoline by the looking for the
77 sigreturn system call. */
78
79static const int sparc64obsd_page_size = 8192;
80
81static int
82sparc64obsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
83{
84 CORE_ADDR start_pc = (pc & ~(sparc64obsd_page_size - 1));
85 unsigned long insn;
24f033e8 86 int offset = 0;
1e067c66
MK
87
88 if (name)
89 return 0;
90
24f033e8 91 retry:
1e067c66 92 /* Check for "restore %g0, SYS_sigreturn, %g1". */
24f033e8 93 insn = sparc_fetch_instruction (start_pc + offset + 0xec);
1e067c66 94 if (insn != 0x83e82067)
24f033e8
MK
95 {
96 if (offset == 0)
97 {
98 /* In OpenBSD 3.5 and earlier releases, the code
99 implementing the sigreturn system call was at a different
100 offset within the signal trampoline. Try again. */
101 offset = -4;
102 goto retry;
103 }
104
105 return 0;
106 }
1e067c66
MK
107
108 /* Check for "t ST_SYSCALL". */
24f033e8 109 insn = sparc_fetch_instruction (start_pc + offset + 0xf4);
1e067c66
MK
110 if (insn != 0x91d02000)
111 return 0;
112
113 return 1;
114}
115
116static struct sparc_frame_cache *
117sparc64obsd_frame_cache (struct frame_info *next_frame, void **this_cache)
118{
119 struct sparc_frame_cache *cache;
120 CORE_ADDR addr;
121
122 if (*this_cache)
123 return *this_cache;
124
125 cache = sparc_frame_cache (next_frame, this_cache);
126 gdb_assert (cache == *this_cache);
127
128 /* If we couldn't find the frame's function, we're probably dealing
129 with an on-stack signal trampoline. */
130 if (cache->pc == 0)
131 {
132 cache->pc = frame_pc_unwind (next_frame);
133 cache->pc &= ~(sparc64obsd_page_size - 1);
134
135 /* Since we couldn't find the frame's function, the cache was
136 initialized under the assumption that we're frameless. */
137 cache->frameless_p = 0;
138 addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
139 cache->base = addr;
140 }
141
142 /* We find the appropriate instance of `struct sigcontext' at a
143 fixed offset in the signal frame. */
144 addr = cache->base + BIAS + 128 + 16;
145 cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, next_frame);
146
147 return cache;
148}
149
150static void
151sparc64obsd_frame_this_id (struct frame_info *next_frame, void **this_cache,
152 struct frame_id *this_id)
153{
154 struct sparc_frame_cache *cache =
155 sparc64obsd_frame_cache (next_frame, this_cache);
156
157 (*this_id) = frame_id_build (cache->base, cache->pc);
158}
159
160static void
161sparc64obsd_frame_prev_register (struct frame_info *next_frame,
162 void **this_cache,
163 int regnum, int *optimizedp,
164 enum lval_type *lvalp, CORE_ADDR *addrp,
165 int *realnump, void *valuep)
166{
167 struct sparc_frame_cache *cache =
168 sparc64obsd_frame_cache (next_frame, this_cache);
169
170 trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
171 optimizedp, lvalp, addrp, realnump, valuep);
172}
173
174static const struct frame_unwind sparc64obsd_frame_unwind =
175{
176 SIGTRAMP_FRAME,
177 sparc64obsd_frame_this_id,
178 sparc64obsd_frame_prev_register
179};
180
181static const struct frame_unwind *
182sparc64obsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
183{
184 CORE_ADDR pc = frame_pc_unwind (next_frame);
185 char *name;
186
187 find_pc_partial_function (pc, &name, NULL, NULL);
188 if (sparc64obsd_pc_in_sigtramp (pc, name))
189 return &sparc64obsd_frame_unwind;
190
191 return NULL;
192}
193\f
194
195static void
196sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
197{
198 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
199
9ea75c57 200 tdep->gregset = regset_alloc (gdbarch, sparc64obsd_supply_gregset, NULL);
1e067c66
MK
201 tdep->sizeof_gregset = 832;
202
1e067c66
MK
203 frame_unwind_append_sniffer (gdbarch, sparc64obsd_sigtramp_frame_sniffer);
204
205 sparc64_init_abi (info, gdbarch);
206
207 set_solib_svr4_fetch_link_map_offsets
208 (gdbarch, nbsd_lp64_solib_svr4_fetch_link_map_offsets);
209}
210
211\f
212/* Provide a prototype to silence -Wmissing-prototypes. */
213void _initialize_sparc64obsd_tdep (void);
214
215void
216_initialize_sparc64obsd_tdep (void)
217{
218 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
219 GDB_OSABI_OPENBSD_ELF, sparc64obsd_init_abi);
220}
This page took 0.086626 seconds and 4 git commands to generate.