* remote-sim.c (init_gdbsim_ops): Remove
[deliverable/binutils-gdb.git] / gdb / sparcobsd-tdep.c
CommitLineData
566626fa
MK
1/* Target-dependent code for OpenBSD/sparc.
2
9b254dd1 3 Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
566626fa
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
566626fa
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/>. */
566626fa
MK
19
20#include "defs.h"
21#include "floatformat.h"
22#include "frame.h"
23#include "frame-unwind.h"
92c2d36a 24#include "gdbcore.h"
566626fa 25#include "osabi.h"
92c2d36a 26#include "regcache.h"
566626fa
MK
27#include "symtab.h"
28#include "trad-frame.h"
29
30#include "gdb_assert.h"
31
dfe1ff2e 32#include "obsd-tdep.h"
566626fa 33#include "sparc-tdep.h"
92c2d36a
MK
34#include "solib-svr4.h"
35#include "bsd-uthread.h"
566626fa
MK
36
37/* Signal trampolines. */
38
39/* The OpenBSD kernel maps the signal trampoline at some random
40 location in user space, which means that the traditional BSD way of
41 detecting it won't work.
42
43 The signal trampoline will be mapped at an address that is page
37e28b92 44 aligned. We recognize the signal trampoline by looking for the
566626fa
MK
45 sigreturn system call. */
46
47static const int sparc32obsd_page_size = 4096;
48
49static int
50sparc32obsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
51{
52 CORE_ADDR start_pc = (pc & ~(sparc32obsd_page_size - 1));
53 unsigned long insn;
54
55 if (name)
56 return 0;
57
58 /* Check for "restore %g0, SYS_sigreturn, %g1". */
59 insn = sparc_fetch_instruction (start_pc + 0xec);
60 if (insn != 0x83e82067)
61 return 0;
62
63 /* Check for "t ST_SYSCALL". */
64 insn = sparc_fetch_instruction (start_pc + 0xf4);
65 if (insn != 0x91d02000)
66 return 0;
67
68 return 1;
69}
70
71static struct sparc_frame_cache *
7ea566be
MK
72sparc32obsd_sigtramp_frame_cache (struct frame_info *this_frame,
73 void **this_cache)
566626fa
MK
74{
75 struct sparc_frame_cache *cache;
76 CORE_ADDR addr;
77
78 if (*this_cache)
79 return *this_cache;
80
7ea566be 81 cache = sparc_frame_cache (this_frame, this_cache);
566626fa
MK
82 gdb_assert (cache == *this_cache);
83
84 /* If we couldn't find the frame's function, we're probably dealing
85 with an on-stack signal trampoline. */
86 if (cache->pc == 0)
87 {
7ea566be 88 cache->pc = get_frame_pc (this_frame);
566626fa
MK
89 cache->pc &= ~(sparc32obsd_page_size - 1);
90
91 /* Since we couldn't find the frame's function, the cache was
92 initialized under the assumption that we're frameless. */
93 cache->frameless_p = 0;
7ea566be 94 addr = get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
566626fa
MK
95 cache->base = addr;
96 }
97
7ea566be 98 cache->saved_regs = sparc32nbsd_sigcontext_saved_regs (this_frame);
566626fa
MK
99
100 return cache;
101}
102
103static void
7ea566be
MK
104sparc32obsd_sigtramp_frame_this_id (struct frame_info *this_frame,
105 void **this_cache,
106 struct frame_id *this_id)
566626fa
MK
107{
108 struct sparc_frame_cache *cache =
7ea566be 109 sparc32obsd_sigtramp_frame_cache (this_frame, this_cache);
566626fa
MK
110
111 (*this_id) = frame_id_build (cache->base, cache->pc);
112}
113
7ea566be
MK
114static struct value *
115sparc32obsd_sigtramp_frame_prev_register (struct frame_info *this_frame,
116 void **this_cache, int regnum)
566626fa
MK
117{
118 struct sparc_frame_cache *cache =
7ea566be 119 sparc32obsd_sigtramp_frame_cache (this_frame, this_cache);
566626fa 120
7ea566be 121 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
566626fa
MK
122}
123
7ea566be
MK
124static int
125sparc32obsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
126 struct frame_info *this_frame,
127 void **this_cache)
566626fa 128{
7ea566be 129 CORE_ADDR pc = get_frame_pc (this_frame);
566626fa
MK
130 char *name;
131
132 find_pc_partial_function (pc, &name, NULL, NULL);
133 if (sparc32obsd_pc_in_sigtramp (pc, name))
7ea566be 134 return 1;
566626fa 135
7ea566be 136 return 0;
566626fa 137}
7ea566be
MK
138static const struct frame_unwind sparc32obsd_sigtramp_frame_unwind =
139{
140 SIGTRAMP_FRAME,
141 sparc32obsd_sigtramp_frame_this_id,
142 sparc32obsd_sigtramp_frame_prev_register,
143 NULL,
144 sparc32obsd_sigtramp_frame_sniffer
145};
146
566626fa
MK
147\f
148
92c2d36a
MK
149/* Offset wthin the thread structure where we can find %fp and %i7. */
150#define SPARC32OBSD_UTHREAD_FP_OFFSET 128
151#define SPARC32OBSD_UTHREAD_PC_OFFSET 132
152
153static void
154sparc32obsd_supply_uthread (struct regcache *regcache,
155 int regnum, CORE_ADDR addr)
156{
157 CORE_ADDR fp, fp_addr = addr + SPARC32OBSD_UTHREAD_FP_OFFSET;
158 gdb_byte buf[4];
159
160 gdb_assert (regnum >= -1);
161
162 fp = read_memory_unsigned_integer (fp_addr, 4);
163 if (regnum == SPARC_SP_REGNUM || regnum == -1)
164 {
165 store_unsigned_integer (buf, 4, fp);
166 regcache_raw_supply (regcache, SPARC_SP_REGNUM, buf);
167
168 if (regnum == SPARC_SP_REGNUM)
169 return;
170 }
171
172 if (regnum == SPARC32_PC_REGNUM || regnum == SPARC32_NPC_REGNUM
173 || regnum == -1)
174 {
175 CORE_ADDR i7, i7_addr = addr + SPARC32OBSD_UTHREAD_PC_OFFSET;
176
177 i7 = read_memory_unsigned_integer (i7_addr, 4);
178 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
179 {
180 store_unsigned_integer (buf, 4, i7 + 8);
181 regcache_raw_supply (regcache, SPARC32_PC_REGNUM, buf);
182 }
183 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
184 {
185 store_unsigned_integer (buf, 4, i7 + 12);
186 regcache_raw_supply (regcache, SPARC32_NPC_REGNUM, buf);
187 }
188
189 if (regnum == SPARC32_PC_REGNUM || regnum == SPARC32_NPC_REGNUM)
190 return;
191 }
192
193 sparc_supply_rwindow (regcache, fp, regnum);
194}
195
196static void
197sparc32obsd_collect_uthread(const struct regcache *regcache,
198 int regnum, CORE_ADDR addr)
199{
200 CORE_ADDR sp;
201 gdb_byte buf[4];
202
203 gdb_assert (regnum >= -1);
204
205 if (regnum == SPARC_SP_REGNUM || regnum == -1)
206 {
207 CORE_ADDR fp_addr = addr + SPARC32OBSD_UTHREAD_FP_OFFSET;
208
209 regcache_raw_collect (regcache, SPARC_SP_REGNUM, buf);
210 write_memory (fp_addr,buf, 4);
211 }
212
213 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
214 {
215 CORE_ADDR i7, i7_addr = addr + SPARC32OBSD_UTHREAD_PC_OFFSET;
216
217 regcache_raw_collect (regcache, SPARC32_PC_REGNUM, buf);
218 i7 = extract_unsigned_integer (buf, 4) - 8;
219 write_memory_unsigned_integer (i7_addr, 4, i7);
220
221 if (regnum == SPARC32_PC_REGNUM)
222 return;
223 }
224
225 regcache_raw_collect (regcache, SPARC_SP_REGNUM, buf);
226 sp = extract_unsigned_integer (buf, 4);
227 sparc_collect_rwindow (regcache, sp, regnum);
228}
229\f
230
566626fa
MK
231static void
232sparc32obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
233{
234 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
235
19671c2b
MK
236 /* OpenBSD/sparc is very similar to NetBSD/sparc ELF. */
237 sparc32nbsd_elf_init_abi (info, gdbarch);
566626fa 238
dfe1ff2e
MK
239 set_gdbarch_skip_solib_resolver (gdbarch, obsd_skip_solib_resolver);
240
7ea566be 241 frame_unwind_append_unwinder (gdbarch, &sparc32obsd_sigtramp_frame_unwind);
92c2d36a
MK
242
243 /* OpenBSD provides a user-level threads implementation. */
244 bsd_uthread_set_supply_uthread (gdbarch, sparc32obsd_supply_uthread);
245 bsd_uthread_set_collect_uthread (gdbarch, sparc32obsd_collect_uthread);
566626fa
MK
246}
247
248\f
249/* Provide a prototype to silence -Wmissing-prototypes. */
250void _initialize_sparc32obsd_tdep (void);
251
252void
253_initialize_sparc32obsd_tdep (void)
254{
255 gdbarch_register_osabi (bfd_arch_sparc, 0, GDB_OSABI_OPENBSD_ELF,
256 sparc32obsd_init_abi);
257}
This page took 0.48833 seconds and 4 git commands to generate.