1 /* Target-dependent code for FreeBSD/sparc64.
3 Copyright 2003, 2004, 2005 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"
30 #include "trad-frame.h"
32 #include "gdb_assert.h"
33 #include "gdb_string.h"
35 #include "sparc64-tdep.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 *next_frame,
97 struct sparc_frame_cache *cache;
98 CORE_ADDR addr, mcontext_addr, sp;
105 cache = sparc_frame_cache (next_frame, this_cache);
106 gdb_assert (cache == *this_cache);
108 cache->saved_regs = trad_frame_alloc_saved_regs (next_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 = frame_unwind_register_unsigned (next_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 (next_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 (next_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 *next_frame,
169 struct frame_id *this_id)
171 struct sparc_frame_cache *cache =
172 sparc64fbsd_sigtramp_frame_cache (next_frame, this_cache);
174 (*this_id) = frame_id_build (cache->base, cache->pc);
178 sparc64fbsd_sigtramp_frame_prev_register (struct frame_info *next_frame,
180 int regnum, int *optimizedp,
181 enum lval_type *lvalp,
183 int *realnump, void *valuep)
185 struct sparc_frame_cache *cache =
186 sparc64fbsd_sigtramp_frame_cache (next_frame, this_cache);
188 trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum,
189 optimizedp, lvalp, addrp, realnump, valuep);
192 static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind =
195 sparc64fbsd_sigtramp_frame_this_id,
196 sparc64fbsd_sigtramp_frame_prev_register
199 static const struct frame_unwind *
200 sparc64fbsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
202 CORE_ADDR pc = frame_pc_unwind (next_frame);
205 find_pc_partial_function (pc, &name, NULL, NULL);
206 if (sparc64fbsd_pc_in_sigtramp (pc, name))
207 return &sparc64fbsd_sigtramp_frame_unwind;
214 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
216 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
218 tdep->gregset = regset_alloc (gdbarch, sparc64fbsd_supply_gregset,
219 sparc64fbsd_collect_gregset);
220 tdep->sizeof_gregset = 256;
222 tdep->fpregset = regset_alloc (gdbarch, sparc64fbsd_supply_fpregset,
223 sparc64fbsd_collect_fpregset);
224 tdep->sizeof_fpregset = 272;
226 frame_unwind_append_sniffer (gdbarch, sparc64fbsd_sigtramp_frame_sniffer);
228 sparc64_init_abi (info, gdbarch);
231 /* Provide a prototype to silence -Wmissing-prototypes. */
232 void _initialize_sparc64fbsd_tdep (void);
235 _initialize_sparc64fbsd_tdep (void)
237 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
238 GDB_OSABI_FREEBSD_ELF, sparc64fbsd_init_abi);