1 /* Target-dependent code for FreeBSD/sparc64.
3 Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "frame-unwind.h"
29 #include "trad-frame.h"
31 #include "gdb_assert.h"
32 #include "gdb_string.h"
34 #include "sparc64-tdep.h"
35 #include "solib-svr4.h"
37 /* From <machine/reg.h>. */
38 const struct sparc_gregset sparc64fbsd_gregset =
40 26 * 8, /* "tstate" */
53 sparc64fbsd_supply_gregset (const struct regset *regset,
54 struct regcache *regcache,
55 int regnum, const void *gregs, size_t len)
57 sparc64_supply_gregset (&sparc64fbsd_gregset, regcache, regnum, gregs);
61 sparc64fbsd_collect_gregset (const struct regset *regset,
62 const struct regcache *regcache,
63 int regnum, void *gregs, size_t len)
65 sparc64_collect_gregset (&sparc64fbsd_gregset, regcache, regnum, gregs);
69 sparc64fbsd_supply_fpregset (const struct regset *regset,
70 struct regcache *regcache,
71 int regnum, const void *fpregs, size_t len)
73 sparc64_supply_fpregset (regcache, regnum, fpregs);
77 sparc64fbsd_collect_fpregset (const struct regset *regset,
78 const struct regcache *regcache,
79 int regnum, void *fpregs, size_t len)
81 sparc64_collect_fpregset (regcache, regnum, fpregs);
85 /* Signal trampolines. */
88 sparc64fbsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
90 return (name && strcmp (name, "__sigtramp") == 0);
93 static struct sparc_frame_cache *
94 sparc64fbsd_sigtramp_frame_cache (struct frame_info *this_frame,
97 struct sparc_frame_cache *cache;
98 CORE_ADDR addr, mcontext_addr, sp;
105 cache = sparc_frame_cache (this_frame, this_cache);
106 gdb_assert (cache == *this_cache);
108 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
110 /* The third argument is a pointer to an instance of `ucontext_t',
111 which has a member `uc_mcontext' that contains the saved
113 addr = get_frame_register_unsigned (this_frame, SPARC_O2_REGNUM);
114 mcontext_addr = addr + 64;
116 /* The following registers travel in the `mc_local' slots of
118 addr = mcontext_addr + 16 * 8;
119 cache->saved_regs[SPARC64_FPRS_REGNUM].addr = addr + 0 * 8;
120 cache->saved_regs[SPARC64_FSR_REGNUM].addr = addr + 1 * 8;
122 /* The following registers travel in the `mc_in' slots of
124 addr = mcontext_addr + 24 * 8;
125 cache->saved_regs[SPARC64_NPC_REGNUM].addr = addr + 0 * 8;
126 cache->saved_regs[SPARC64_PC_REGNUM].addr = addr + 1 * 8;
127 cache->saved_regs[SPARC64_STATE_REGNUM].addr = addr + 2 * 8;
128 cache->saved_regs[SPARC64_Y_REGNUM].addr = addr + 4 * 8;
130 /* The `global' and `out' registers travel in the `mc_global' and
131 `mc_out' slots of `mcontext_t', except for %g0. Since %g0 is
132 always zero, keep the identity encoding. */
133 for (regnum = SPARC_G1_REGNUM, addr = mcontext_addr + 8;
134 regnum <= SPARC_O7_REGNUM; regnum++, addr += 8)
135 cache->saved_regs[regnum].addr = addr;
137 /* The `local' and `in' registers have been saved in the register
139 addr = cache->saved_regs[SPARC_SP_REGNUM].addr;
140 sp = get_frame_memory_unsigned (this_frame, addr, 8);
141 for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
142 regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
143 cache->saved_regs[regnum].addr = addr;
145 /* The floating-point registers are only saved if the FEF bit in
146 %fprs has been set. */
148 #define FPRS_FEF (1 << 2)
150 addr = cache->saved_regs[SPARC64_FPRS_REGNUM].addr;
151 fprs = get_frame_memory_unsigned (this_frame, addr, 8);
154 for (regnum = SPARC_F0_REGNUM, addr = mcontext_addr + 32 * 8;
155 regnum <= SPARC_F31_REGNUM; regnum++, addr += 4)
156 cache->saved_regs[regnum].addr = addr;
158 for (regnum = SPARC64_F32_REGNUM;
159 regnum <= SPARC64_F62_REGNUM; regnum++, addr += 8)
160 cache->saved_regs[regnum].addr = addr;
167 sparc64fbsd_sigtramp_frame_this_id (struct frame_info *this_frame,
169 struct frame_id *this_id)
171 struct sparc_frame_cache *cache =
172 sparc64fbsd_sigtramp_frame_cache (this_frame, this_cache);
174 (*this_id) = frame_id_build (cache->base, cache->pc);
177 static struct value *
178 sparc64fbsd_sigtramp_frame_prev_register (struct frame_info *this_frame,
179 void **this_cache, int regnum)
181 struct sparc_frame_cache *cache =
182 sparc64fbsd_sigtramp_frame_cache (this_frame, this_cache);
184 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
188 sparc64fbsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
189 struct frame_info *this_frame,
192 CORE_ADDR pc = get_frame_pc (this_frame);
195 find_pc_partial_function (pc, &name, NULL, NULL);
196 if (sparc64fbsd_pc_in_sigtramp (pc, name))
202 static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind =
205 sparc64fbsd_sigtramp_frame_this_id,
206 sparc64fbsd_sigtramp_frame_prev_register,
208 sparc64fbsd_sigtramp_frame_sniffer
213 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
215 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
217 tdep->gregset = regset_alloc (gdbarch, sparc64fbsd_supply_gregset,
218 sparc64fbsd_collect_gregset);
219 tdep->sizeof_gregset = 256;
221 tdep->fpregset = regset_alloc (gdbarch, sparc64fbsd_supply_fpregset,
222 sparc64fbsd_collect_fpregset);
223 tdep->sizeof_fpregset = 272;
225 frame_unwind_append_unwinder (gdbarch, &sparc64fbsd_sigtramp_frame_unwind);
227 sparc64_init_abi (info, gdbarch);
229 /* FreeBSD/sparc64 has SVR4-style shared libraries. */
230 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
231 set_solib_svr4_fetch_link_map_offsets
232 (gdbarch, svr4_lp64_fetch_link_map_offsets);
235 /* Provide a prototype to silence -Wmissing-prototypes. */
236 void _initialize_sparc64fbsd_tdep (void);
239 _initialize_sparc64fbsd_tdep (void)
241 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
242 GDB_OSABI_FREEBSD_ELF, sparc64fbsd_init_abi);