1 /* Target-dependent code for FreeBSD/sparc64.
3 Copyright (C) 2003-2013 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 3 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, see <http://www.gnu.org/licenses/>. */
22 #include "frame-unwind.h"
28 #include "trad-frame.h"
30 #include "gdb_assert.h"
31 #include "gdb_string.h"
33 #include "sparc64-tdep.h"
34 #include "solib-svr4.h"
36 /* From <machine/reg.h>. */
37 const struct sparc_gregset sparc64fbsd_gregset
=
39 26 * 8, /* "tstate" */
52 sparc64fbsd_supply_gregset (const struct regset
*regset
,
53 struct regcache
*regcache
,
54 int regnum
, const void *gregs
, size_t len
)
56 sparc64_supply_gregset (&sparc64fbsd_gregset
, regcache
, regnum
, gregs
);
60 sparc64fbsd_collect_gregset (const struct regset
*regset
,
61 const struct regcache
*regcache
,
62 int regnum
, void *gregs
, size_t len
)
64 sparc64_collect_gregset (&sparc64fbsd_gregset
, regcache
, regnum
, gregs
);
68 sparc64fbsd_supply_fpregset (const struct regset
*regset
,
69 struct regcache
*regcache
,
70 int regnum
, const void *fpregs
, size_t len
)
72 sparc64_supply_fpregset (&sparc64_bsd_fpregset
, regcache
, regnum
, fpregs
);
76 sparc64fbsd_collect_fpregset (const struct regset
*regset
,
77 const struct regcache
*regcache
,
78 int regnum
, void *fpregs
, size_t len
)
80 sparc64_collect_fpregset (&sparc64_bsd_fpregset
, regcache
, regnum
, fpregs
);
84 /* Signal trampolines. */
87 sparc64fbsd_pc_in_sigtramp (CORE_ADDR pc
, const char *name
)
89 return (name
&& strcmp (name
, "__sigtramp") == 0);
92 static struct sparc_frame_cache
*
93 sparc64fbsd_sigtramp_frame_cache (struct frame_info
*this_frame
,
96 struct sparc_frame_cache
*cache
;
97 CORE_ADDR addr
, mcontext_addr
, sp
;
104 cache
= sparc_frame_cache (this_frame
, this_cache
);
105 gdb_assert (cache
== *this_cache
);
107 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
109 /* The third argument is a pointer to an instance of `ucontext_t',
110 which has a member `uc_mcontext' that contains the saved
112 addr
= get_frame_register_unsigned (this_frame
, SPARC_O2_REGNUM
);
113 mcontext_addr
= addr
+ 64;
115 /* The following registers travel in the `mc_local' slots of
117 addr
= mcontext_addr
+ 16 * 8;
118 cache
->saved_regs
[SPARC64_FPRS_REGNUM
].addr
= addr
+ 0 * 8;
119 cache
->saved_regs
[SPARC64_FSR_REGNUM
].addr
= addr
+ 1 * 8;
121 /* The following registers travel in the `mc_in' slots of
123 addr
= mcontext_addr
+ 24 * 8;
124 cache
->saved_regs
[SPARC64_NPC_REGNUM
].addr
= addr
+ 0 * 8;
125 cache
->saved_regs
[SPARC64_PC_REGNUM
].addr
= addr
+ 1 * 8;
126 cache
->saved_regs
[SPARC64_STATE_REGNUM
].addr
= addr
+ 2 * 8;
127 cache
->saved_regs
[SPARC64_Y_REGNUM
].addr
= addr
+ 4 * 8;
129 /* The `global' and `out' registers travel in the `mc_global' and
130 `mc_out' slots of `mcontext_t', except for %g0. Since %g0 is
131 always zero, keep the identity encoding. */
132 for (regnum
= SPARC_G1_REGNUM
, addr
= mcontext_addr
+ 8;
133 regnum
<= SPARC_O7_REGNUM
; regnum
++, addr
+= 8)
134 cache
->saved_regs
[regnum
].addr
= addr
;
136 /* The `local' and `in' registers have been saved in the register
138 addr
= cache
->saved_regs
[SPARC_SP_REGNUM
].addr
;
139 sp
= get_frame_memory_unsigned (this_frame
, addr
, 8);
140 for (regnum
= SPARC_L0_REGNUM
, addr
= sp
+ BIAS
;
141 regnum
<= SPARC_I7_REGNUM
; regnum
++, addr
+= 8)
142 cache
->saved_regs
[regnum
].addr
= addr
;
144 /* The floating-point registers are only saved if the FEF bit in
145 %fprs has been set. */
147 #define FPRS_FEF (1 << 2)
149 addr
= cache
->saved_regs
[SPARC64_FPRS_REGNUM
].addr
;
150 fprs
= get_frame_memory_unsigned (this_frame
, addr
, 8);
153 for (regnum
= SPARC_F0_REGNUM
, addr
= mcontext_addr
+ 32 * 8;
154 regnum
<= SPARC_F31_REGNUM
; regnum
++, addr
+= 4)
155 cache
->saved_regs
[regnum
].addr
= addr
;
157 for (regnum
= SPARC64_F32_REGNUM
;
158 regnum
<= SPARC64_F62_REGNUM
; regnum
++, addr
+= 8)
159 cache
->saved_regs
[regnum
].addr
= addr
;
166 sparc64fbsd_sigtramp_frame_this_id (struct frame_info
*this_frame
,
168 struct frame_id
*this_id
)
170 struct sparc_frame_cache
*cache
=
171 sparc64fbsd_sigtramp_frame_cache (this_frame
, this_cache
);
173 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
176 static struct value
*
177 sparc64fbsd_sigtramp_frame_prev_register (struct frame_info
*this_frame
,
178 void **this_cache
, int regnum
)
180 struct sparc_frame_cache
*cache
=
181 sparc64fbsd_sigtramp_frame_cache (this_frame
, this_cache
);
183 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
, regnum
);
187 sparc64fbsd_sigtramp_frame_sniffer (const struct frame_unwind
*self
,
188 struct frame_info
*this_frame
,
191 CORE_ADDR pc
= get_frame_pc (this_frame
);
194 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
195 if (sparc64fbsd_pc_in_sigtramp (pc
, name
))
201 static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind
=
204 default_frame_unwind_stop_reason
,
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
);