1 /* Target-dependent code for FreeBSD/sparc64.
3 Copyright (C) 2003-2015 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 "sparc64-tdep.h"
31 #include "fbsd-tdep.h"
32 #include "solib-svr4.h"
34 /* From <machine/reg.h>. */
35 const struct sparc_gregmap sparc64fbsd_gregmap
=
37 26 * 8, /* "tstate" */
50 sparc64fbsd_supply_gregset (const struct regset
*regset
,
51 struct regcache
*regcache
,
52 int regnum
, const void *gregs
, size_t len
)
54 sparc64_supply_gregset (&sparc64fbsd_gregmap
, regcache
, regnum
, gregs
);
58 sparc64fbsd_collect_gregset (const struct regset
*regset
,
59 const struct regcache
*regcache
,
60 int regnum
, void *gregs
, size_t len
)
62 sparc64_collect_gregset (&sparc64fbsd_gregmap
, regcache
, regnum
, gregs
);
66 sparc64fbsd_supply_fpregset (const struct regset
*regset
,
67 struct regcache
*regcache
,
68 int regnum
, const void *fpregs
, size_t len
)
70 sparc64_supply_fpregset (&sparc64_bsd_fpregmap
, regcache
, regnum
, fpregs
);
74 sparc64fbsd_collect_fpregset (const struct regset
*regset
,
75 const struct regcache
*regcache
,
76 int regnum
, void *fpregs
, size_t len
)
78 sparc64_collect_fpregset (&sparc64_bsd_fpregmap
, regcache
, regnum
, fpregs
);
82 /* Signal trampolines. */
85 sparc64fbsd_pc_in_sigtramp (CORE_ADDR pc
, const char *name
)
87 return (name
&& strcmp (name
, "__sigtramp") == 0);
90 static struct sparc_frame_cache
*
91 sparc64fbsd_sigtramp_frame_cache (struct frame_info
*this_frame
,
94 struct sparc_frame_cache
*cache
;
95 CORE_ADDR addr
, mcontext_addr
, sp
;
102 cache
= sparc_frame_cache (this_frame
, this_cache
);
103 gdb_assert (cache
== *this_cache
);
105 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
107 /* The third argument is a pointer to an instance of `ucontext_t',
108 which has a member `uc_mcontext' that contains the saved
110 addr
= get_frame_register_unsigned (this_frame
, SPARC_O2_REGNUM
);
111 mcontext_addr
= addr
+ 64;
113 /* The following registers travel in the `mc_local' slots of
115 addr
= mcontext_addr
+ 16 * 8;
116 cache
->saved_regs
[SPARC64_FPRS_REGNUM
].addr
= addr
+ 0 * 8;
117 cache
->saved_regs
[SPARC64_FSR_REGNUM
].addr
= addr
+ 1 * 8;
119 /* The following registers travel in the `mc_in' slots of
121 addr
= mcontext_addr
+ 24 * 8;
122 cache
->saved_regs
[SPARC64_NPC_REGNUM
].addr
= addr
+ 0 * 8;
123 cache
->saved_regs
[SPARC64_PC_REGNUM
].addr
= addr
+ 1 * 8;
124 cache
->saved_regs
[SPARC64_STATE_REGNUM
].addr
= addr
+ 2 * 8;
125 cache
->saved_regs
[SPARC64_Y_REGNUM
].addr
= addr
+ 4 * 8;
127 /* The `global' and `out' registers travel in the `mc_global' and
128 `mc_out' slots of `mcontext_t', except for %g0. Since %g0 is
129 always zero, keep the identity encoding. */
130 for (regnum
= SPARC_G1_REGNUM
, addr
= mcontext_addr
+ 8;
131 regnum
<= SPARC_O7_REGNUM
; regnum
++, addr
+= 8)
132 cache
->saved_regs
[regnum
].addr
= addr
;
134 /* The `local' and `in' registers have been saved in the register
136 addr
= cache
->saved_regs
[SPARC_SP_REGNUM
].addr
;
137 sp
= get_frame_memory_unsigned (this_frame
, addr
, 8);
138 for (regnum
= SPARC_L0_REGNUM
, addr
= sp
+ BIAS
;
139 regnum
<= SPARC_I7_REGNUM
; regnum
++, addr
+= 8)
140 cache
->saved_regs
[regnum
].addr
= addr
;
142 /* The floating-point registers are only saved if the FEF bit in
143 %fprs has been set. */
145 #define FPRS_FEF (1 << 2)
147 addr
= cache
->saved_regs
[SPARC64_FPRS_REGNUM
].addr
;
148 fprs
= get_frame_memory_unsigned (this_frame
, addr
, 8);
151 for (regnum
= SPARC_F0_REGNUM
, addr
= mcontext_addr
+ 32 * 8;
152 regnum
<= SPARC_F31_REGNUM
; regnum
++, addr
+= 4)
153 cache
->saved_regs
[regnum
].addr
= addr
;
155 for (regnum
= SPARC64_F32_REGNUM
;
156 regnum
<= SPARC64_F62_REGNUM
; regnum
++, addr
+= 8)
157 cache
->saved_regs
[regnum
].addr
= addr
;
164 sparc64fbsd_sigtramp_frame_this_id (struct frame_info
*this_frame
,
166 struct frame_id
*this_id
)
168 struct sparc_frame_cache
*cache
=
169 sparc64fbsd_sigtramp_frame_cache (this_frame
, this_cache
);
171 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
174 static struct value
*
175 sparc64fbsd_sigtramp_frame_prev_register (struct frame_info
*this_frame
,
176 void **this_cache
, int regnum
)
178 struct sparc_frame_cache
*cache
=
179 sparc64fbsd_sigtramp_frame_cache (this_frame
, this_cache
);
181 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
, regnum
);
185 sparc64fbsd_sigtramp_frame_sniffer (const struct frame_unwind
*self
,
186 struct frame_info
*this_frame
,
189 CORE_ADDR pc
= get_frame_pc (this_frame
);
192 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
193 if (sparc64fbsd_pc_in_sigtramp (pc
, name
))
199 static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind
=
202 default_frame_unwind_stop_reason
,
203 sparc64fbsd_sigtramp_frame_this_id
,
204 sparc64fbsd_sigtramp_frame_prev_register
,
206 sparc64fbsd_sigtramp_frame_sniffer
210 static const struct regset sparc64fbsd_gregset
=
212 NULL
, sparc64fbsd_supply_gregset
, sparc64fbsd_collect_gregset
215 static const struct regset sparc64fbsd_fpregset
=
217 NULL
, sparc64fbsd_supply_fpregset
, sparc64fbsd_collect_fpregset
221 sparc64fbsd_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
223 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
225 /* Generic FreeBSD support. */
226 fbsd_init_abi (info
, gdbarch
);
228 tdep
->gregset
= &sparc64fbsd_gregset
;
229 tdep
->sizeof_gregset
= 256;
231 tdep
->fpregset
= &sparc64fbsd_fpregset
;
232 tdep
->sizeof_fpregset
= 272;
234 frame_unwind_append_unwinder (gdbarch
, &sparc64fbsd_sigtramp_frame_unwind
);
236 sparc64_init_abi (info
, gdbarch
);
238 /* FreeBSD/sparc64 has SVR4-style shared libraries. */
239 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
240 set_solib_svr4_fetch_link_map_offsets
241 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
244 /* Provide a prototype to silence -Wmissing-prototypes. */
245 void _initialize_sparc64fbsd_tdep (void);
248 _initialize_sparc64fbsd_tdep (void)
250 gdbarch_register_osabi (bfd_arch_sparc
, bfd_mach_sparc_v9
,
251 GDB_OSABI_FREEBSD_ELF
, sparc64fbsd_init_abi
);