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"
36 #include "solib-svr4.h"
38 /* From <machine/reg.h>. */
39 const struct sparc_gregset sparc64fbsd_gregset
=
41 26 * 8, /* "tstate" */
54 sparc64fbsd_supply_gregset (const struct regset
*regset
,
55 struct regcache
*regcache
,
56 int regnum
, const void *gregs
, size_t len
)
58 sparc64_supply_gregset (&sparc64fbsd_gregset
, regcache
, regnum
, gregs
);
62 sparc64fbsd_collect_gregset (const struct regset
*regset
,
63 const struct regcache
*regcache
,
64 int regnum
, void *gregs
, size_t len
)
66 sparc64_collect_gregset (&sparc64fbsd_gregset
, regcache
, regnum
, gregs
);
70 sparc64fbsd_supply_fpregset (const struct regset
*regset
,
71 struct regcache
*regcache
,
72 int regnum
, const void *fpregs
, size_t len
)
74 sparc64_supply_fpregset (regcache
, regnum
, fpregs
);
78 sparc64fbsd_collect_fpregset (const struct regset
*regset
,
79 const struct regcache
*regcache
,
80 int regnum
, void *fpregs
, size_t len
)
82 sparc64_collect_fpregset (regcache
, regnum
, fpregs
);
86 /* Signal trampolines. */
89 sparc64fbsd_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
91 return (name
&& strcmp (name
, "__sigtramp") == 0);
94 static struct sparc_frame_cache
*
95 sparc64fbsd_sigtramp_frame_cache (struct frame_info
*next_frame
,
98 struct sparc_frame_cache
*cache
;
99 CORE_ADDR addr
, mcontext_addr
, sp
;
106 cache
= sparc_frame_cache (next_frame
, this_cache
);
107 gdb_assert (cache
== *this_cache
);
109 cache
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
111 /* The third argument is a pointer to an instance of `ucontext_t',
112 which has a member `uc_mcontext' that contains the saved
114 addr
= frame_unwind_register_unsigned (next_frame
, SPARC_O2_REGNUM
);
115 mcontext_addr
= addr
+ 64;
117 /* The following registers travel in the `mc_local' slots of
119 addr
= mcontext_addr
+ 16 * 8;
120 cache
->saved_regs
[SPARC64_FPRS_REGNUM
].addr
= addr
+ 0 * 8;
121 cache
->saved_regs
[SPARC64_FSR_REGNUM
].addr
= addr
+ 1 * 8;
123 /* The following registers travel in the `mc_in' slots of
125 addr
= mcontext_addr
+ 24 * 8;
126 cache
->saved_regs
[SPARC64_NPC_REGNUM
].addr
= addr
+ 0 * 8;
127 cache
->saved_regs
[SPARC64_PC_REGNUM
].addr
= addr
+ 1 * 8;
128 cache
->saved_regs
[SPARC64_STATE_REGNUM
].addr
= addr
+ 2 * 8;
129 cache
->saved_regs
[SPARC64_Y_REGNUM
].addr
= addr
+ 4 * 8;
131 /* The `global' and `out' registers travel in the `mc_global' and
132 `mc_out' slots of `mcontext_t', except for %g0. Since %g0 is
133 always zero, keep the identity encoding. */
134 for (regnum
= SPARC_G1_REGNUM
, addr
= mcontext_addr
+ 8;
135 regnum
<= SPARC_O7_REGNUM
; regnum
++, addr
+= 8)
136 cache
->saved_regs
[regnum
].addr
= addr
;
138 /* The `local' and `in' registers have been saved in the register
140 addr
= cache
->saved_regs
[SPARC_SP_REGNUM
].addr
;
141 sp
= get_frame_memory_unsigned (next_frame
, addr
, 8);
142 for (regnum
= SPARC_L0_REGNUM
, addr
= sp
+ BIAS
;
143 regnum
<= SPARC_I7_REGNUM
; regnum
++, addr
+= 8)
144 cache
->saved_regs
[regnum
].addr
= addr
;
146 /* The floating-point registers are only saved if the FEF bit in
147 %fprs has been set. */
149 #define FPRS_FEF (1 << 2)
151 addr
= cache
->saved_regs
[SPARC64_FPRS_REGNUM
].addr
;
152 fprs
= get_frame_memory_unsigned (next_frame
, addr
, 8);
155 for (regnum
= SPARC_F0_REGNUM
, addr
= mcontext_addr
+ 32 * 8;
156 regnum
<= SPARC_F31_REGNUM
; regnum
++, addr
+= 4)
157 cache
->saved_regs
[regnum
].addr
= addr
;
159 for (regnum
= SPARC64_F32_REGNUM
;
160 regnum
<= SPARC64_F62_REGNUM
; regnum
++, addr
+= 8)
161 cache
->saved_regs
[regnum
].addr
= addr
;
168 sparc64fbsd_sigtramp_frame_this_id (struct frame_info
*next_frame
,
170 struct frame_id
*this_id
)
172 struct sparc_frame_cache
*cache
=
173 sparc64fbsd_sigtramp_frame_cache (next_frame
, this_cache
);
175 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
179 sparc64fbsd_sigtramp_frame_prev_register (struct frame_info
*next_frame
,
181 int regnum
, int *optimizedp
,
182 enum lval_type
*lvalp
,
184 int *realnump
, void *valuep
)
186 struct sparc_frame_cache
*cache
=
187 sparc64fbsd_sigtramp_frame_cache (next_frame
, this_cache
);
189 trad_frame_get_prev_register (next_frame
, cache
->saved_regs
, regnum
,
190 optimizedp
, lvalp
, addrp
, realnump
, valuep
);
193 static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind
=
196 sparc64fbsd_sigtramp_frame_this_id
,
197 sparc64fbsd_sigtramp_frame_prev_register
200 static const struct frame_unwind
*
201 sparc64fbsd_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
203 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
206 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
207 if (sparc64fbsd_pc_in_sigtramp (pc
, name
))
208 return &sparc64fbsd_sigtramp_frame_unwind
;
215 sparc64fbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
217 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
219 tdep
->gregset
= regset_alloc (gdbarch
, sparc64fbsd_supply_gregset
,
220 sparc64fbsd_collect_gregset
);
221 tdep
->sizeof_gregset
= 256;
223 tdep
->fpregset
= regset_alloc (gdbarch
, sparc64fbsd_supply_fpregset
,
224 sparc64fbsd_collect_fpregset
);
225 tdep
->sizeof_fpregset
= 272;
227 frame_unwind_append_sniffer (gdbarch
, sparc64fbsd_sigtramp_frame_sniffer
);
229 sparc64_init_abi (info
, gdbarch
);
231 /* FreeBSD/sparc64 has SVR4-style shared libraries. */
232 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
233 set_solib_svr4_fetch_link_map_offsets
234 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
237 /* Provide a prototype to silence -Wmissing-prototypes. */
238 void _initialize_sparc64fbsd_tdep (void);
241 _initialize_sparc64fbsd_tdep (void)
243 gdbarch_register_osabi (bfd_arch_sparc
, bfd_mach_sparc_v9
,
244 GDB_OSABI_FREEBSD_ELF
, sparc64fbsd_init_abi
);