1 /* Target-dependent code for OpenBSD/sparc64.
3 Copyright 2004 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
24 #include "frame-unwind.h"
28 #include "solib-svr4.h"
29 #include "trad-frame.h"
31 #include "gdb_assert.h"
33 #include "sparc64-tdep.h"
34 #include "nbsd-tdep.h"
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). */
43 /* From <machine/reg.h>. */
44 const struct sparc_gregset sparc64obsd_core_gregset =
58 sparc64obsd_supply_gregset (const struct regset *regset,
59 struct regcache *regcache,
60 int regnum, const void *gregs, size_t len)
62 const char *regs = gregs;
64 sparc64_supply_gregset (regset->descr, regcache, regnum, regs);
65 sparc64_supply_fpregset (regcache, regnum, regs + 288);
69 /* Signal trampolines. */
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.
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. */
79 static const int sparc64obsd_page_size = 8192;
82 sparc64obsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
84 CORE_ADDR start_pc = (pc & ~(sparc64obsd_page_size - 1));
90 /* Check for "restore %g0, SYS_sigreturn, %g1". */
91 insn = sparc_fetch_instruction (start_pc + 0xe8);
92 if (insn != 0x83e82067)
95 /* Check for "t ST_SYSCALL". */
96 insn = sparc_fetch_instruction (start_pc + 0xf0);
97 if (insn != 0x91d02000)
103 static struct sparc_frame_cache *
104 sparc64obsd_frame_cache (struct frame_info *next_frame, void **this_cache)
106 struct sparc_frame_cache *cache;
112 cache = sparc_frame_cache (next_frame, this_cache);
113 gdb_assert (cache == *this_cache);
115 /* If we couldn't find the frame's function, we're probably dealing
116 with an on-stack signal trampoline. */
119 cache->pc = frame_pc_unwind (next_frame);
120 cache->pc &= ~(sparc64obsd_page_size - 1);
122 /* Since we couldn't find the frame's function, the cache was
123 initialized under the assumption that we're frameless. */
124 cache->frameless_p = 0;
125 addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
129 /* We find the appropriate instance of `struct sigcontext' at a
130 fixed offset in the signal frame. */
131 addr = cache->base + BIAS + 128 + 16;
132 cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, next_frame);
138 sparc64obsd_frame_this_id (struct frame_info *next_frame, void **this_cache,
139 struct frame_id *this_id)
141 struct sparc_frame_cache *cache =
142 sparc64obsd_frame_cache (next_frame, this_cache);
144 (*this_id) = frame_id_build (cache->base, cache->pc);
148 sparc64obsd_frame_prev_register (struct frame_info *next_frame,
150 int regnum, int *optimizedp,
151 enum lval_type *lvalp, CORE_ADDR *addrp,
152 int *realnump, void *valuep)
154 struct sparc_frame_cache *cache =
155 sparc64obsd_frame_cache (next_frame, this_cache);
157 trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
158 optimizedp, lvalp, addrp, realnump, valuep);
161 static const struct frame_unwind sparc64obsd_frame_unwind =
164 sparc64obsd_frame_this_id,
165 sparc64obsd_frame_prev_register
168 static const struct frame_unwind *
169 sparc64obsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
171 CORE_ADDR pc = frame_pc_unwind (next_frame);
174 find_pc_partial_function (pc, &name, NULL, NULL);
175 if (sparc64obsd_pc_in_sigtramp (pc, name))
176 return &sparc64obsd_frame_unwind;
183 sparc64obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
185 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
187 tdep->gregset = XMALLOC (struct regset);
188 tdep->gregset->descr = &sparc64obsd_core_gregset;
189 tdep->gregset->supply_regset = sparc64obsd_supply_gregset;
190 tdep->sizeof_gregset = 832;
192 set_gdbarch_pc_in_sigtramp (gdbarch, sparc64obsd_pc_in_sigtramp);
193 frame_unwind_append_sniffer (gdbarch, sparc64obsd_sigtramp_frame_sniffer);
195 sparc64_init_abi (info, gdbarch);
197 set_solib_svr4_fetch_link_map_offsets
198 (gdbarch, nbsd_lp64_solib_svr4_fetch_link_map_offsets);
202 /* Provide a prototype to silence -Wmissing-prototypes. */
203 void _initialize_sparc64obsd_tdep (void);
206 _initialize_sparc64obsd_tdep (void)
208 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
209 GDB_OSABI_OPENBSD_ELF, sparc64obsd_init_abi);