1 /* Target-dependent code for FreeBSD/sparc64.
3 Copyright 2003, 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"
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_supply_fpregset (const struct regset *regset,
62 struct regcache *regcache,
63 int regnum, const void *fpregs, size_t len)
65 sparc64_supply_fpregset (regcache, regnum, fpregs);
69 /* Signal trampolines. */
72 sparc64fbsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
74 return (name && strcmp (name, "__sigtramp") == 0);
77 static struct sparc_frame_cache *
78 sparc64fbsd_sigtramp_frame_cache (struct frame_info *next_frame,
81 struct sparc_frame_cache *cache;
82 CORE_ADDR addr, mcontext_addr, sp;
89 cache = sparc_frame_cache (next_frame, this_cache);
90 gdb_assert (cache == *this_cache);
92 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
94 /* The third argument is a pointer to an instance of `ucontext_t',
95 which has a member `uc_mcontext' that contains the saved
97 addr = frame_unwind_register_unsigned (next_frame, SPARC_O2_REGNUM);
98 mcontext_addr = addr + 64;
100 /* The following registers travel in the `mc_local' slots of
102 addr = mcontext_addr + 16 * 8;
103 cache->saved_regs[SPARC64_FPRS_REGNUM].addr = addr + 0 * 8;
104 cache->saved_regs[SPARC64_FSR_REGNUM].addr = addr + 1 * 8;
106 /* The following registers travel in the `mc_in' slots of
108 addr = mcontext_addr + 24 * 8;
109 cache->saved_regs[SPARC64_NPC_REGNUM].addr = addr + 0 * 8;
110 cache->saved_regs[SPARC64_PC_REGNUM].addr = addr + 1 * 8;
111 cache->saved_regs[SPARC64_STATE_REGNUM].addr = addr + 2 * 8;
112 cache->saved_regs[SPARC64_Y_REGNUM].addr = addr + 4 * 8;
114 /* The `global' and `out' registers travel in the `mc_global' and
115 `mc_out' slots of `mcontext_t', except for %g0. Since %g0 is
116 always zero, keep the identity encoding. */
117 for (regnum = SPARC_G1_REGNUM, addr = mcontext_addr + 8;
118 regnum <= SPARC_O7_REGNUM; regnum++, addr += 8)
119 cache->saved_regs[regnum].addr = addr;
121 /* The `local' and `in' registers have been saved in the register
123 addr = cache->saved_regs[SPARC_SP_REGNUM].addr;
124 sp = get_frame_memory_unsigned (next_frame, addr, 8);
125 for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
126 regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
127 cache->saved_regs[regnum].addr = addr;
129 /* The floating-point registers are only saved if the FEF bit in
130 %fprs has been set. */
132 #define FPRS_FEF (1 << 2)
134 addr = cache->saved_regs[SPARC64_FPRS_REGNUM].addr;
135 fprs = get_frame_memory_unsigned (next_frame, addr, 8);
138 for (regnum = SPARC_F0_REGNUM, addr = mcontext_addr + 32 * 8;
139 regnum <= SPARC_F31_REGNUM; regnum++, addr += 4)
140 cache->saved_regs[regnum].addr = addr;
142 for (regnum = SPARC64_F32_REGNUM;
143 regnum <= SPARC64_F62_REGNUM; regnum++, addr += 8)
144 cache->saved_regs[regnum].addr = addr;
151 sparc64fbsd_sigtramp_frame_this_id (struct frame_info *next_frame,
153 struct frame_id *this_id)
155 struct sparc_frame_cache *cache =
156 sparc64fbsd_sigtramp_frame_cache (next_frame, this_cache);
158 (*this_id) = frame_id_build (cache->base, cache->pc);
162 sparc64fbsd_sigtramp_frame_prev_register (struct frame_info *next_frame,
164 int regnum, int *optimizedp,
165 enum lval_type *lvalp,
167 int *realnump, void *valuep)
169 struct sparc_frame_cache *cache =
170 sparc64fbsd_sigtramp_frame_cache (next_frame, this_cache);
172 trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum,
173 optimizedp, lvalp, addrp, realnump, valuep);
176 static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind =
179 sparc64fbsd_sigtramp_frame_this_id,
180 sparc64fbsd_sigtramp_frame_prev_register
183 static const struct frame_unwind *
184 sparc64fbsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
186 CORE_ADDR pc = frame_pc_unwind (next_frame);
189 find_pc_partial_function (pc, &name, NULL, NULL);
190 if (sparc64fbsd_pc_in_sigtramp (pc, name))
191 return &sparc64fbsd_sigtramp_frame_unwind;
198 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
200 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
202 tdep->gregset = regset_alloc (gdbarch, sparc64fbsd_supply_gregset, NULL);
203 tdep->sizeof_gregset = 256;
205 tdep->fpregset = regset_alloc (gdbarch, sparc64fbsd_supply_fpregset, NULL);
206 tdep->sizeof_fpregset = 272;
208 frame_unwind_append_sniffer (gdbarch, sparc64fbsd_sigtramp_frame_sniffer);
210 sparc64_init_abi (info, gdbarch);
213 /* Provide a prototype to silence -Wmissing-prototypes. */
214 void _initialize_sparc64fbsd_tdep (void);
217 _initialize_sparc64fbsd_tdep (void)
219 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
220 GDB_OSABI_FREEBSD_ELF, sparc64fbsd_init_abi);