GDB (xrefs)

/tmp/gdb-8.1/gdb/sparc64-fbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for FreeBSD/sparc64.
2
3 Copyright (C) 2003-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "frame-unwind.h"
23 #include "gdbcore.h"
24 #include "osabi.h"
25 #include "regcache.h"
26 #include "regset.h"
27 #include "target.h"
28 #include "trad-frame.h"
29
30 #include "sparc64-tdep.h"
31 #include "fbsd-tdep.h"
32 #include "solib-svr4.h"
33
34 /* From <machine/reg.h>. */
35 const struct sparc_gregmap sparc64fbsd_gregmap =
36 {
37 26 * 8, /* "tstate" */
38 25 * 8, /* %pc */
39 24 * 8, /* %npc */
40 28 * 8, /* %y */
41 16 * 8, /* %fprs */
42 -1,
43 1 * 8, /* %g1 */
44 -1, /* %l0 */
45 8 /* sizeof (%y) */
46 };
47
48
49 static void
50 sparc64fbsd_supply_gregset (const struct regset *regset,
51 struct regcache *regcache,
52 int regnum, const void *gregs, size_t len)
53 {
54 sparc64_supply_gregset (&sparc64fbsd_gregmap, regcache, regnum, gregs);
55 }
56
57 static void
58 sparc64fbsd_collect_gregset (const struct regset *regset,
59 const struct regcache *regcache,
60 int regnum, void *gregs, size_t len)
61 {
62 sparc64_collect_gregset (&sparc64fbsd_gregmap, regcache, regnum, gregs);
63 }
64
65 static void
66 sparc64fbsd_supply_fpregset (const struct regset *regset,
67 struct regcache *regcache,
68 int regnum, const void *fpregs, size_t len)
69 {
70 sparc64_supply_fpregset (&sparc64_bsd_fpregmap, regcache, regnum, fpregs);
71 }
72
73 static void
74 sparc64fbsd_collect_fpregset (const struct regset *regset,
75 const struct regcache *regcache,
76 int regnum, void *fpregs, size_t len)
77 {
78 sparc64_collect_fpregset (&sparc64_bsd_fpregmap, regcache, regnum, fpregs);
79 }
80
81
82 /* Signal trampolines. */
83
84 static int
85 sparc64fbsd_pc_in_sigtramp (CORE_ADDR pc, const char *name)
86 {
87 return (name && strcmp (name, "__sigtramp") == 0);
88 }
89
90 static struct sparc_frame_cache *
91 sparc64fbsd_sigtramp_frame_cache (struct frame_info *this_frame,
92 void **this_cache)
93 {
94 struct sparc_frame_cache *cache;
95 CORE_ADDR addr, mcontext_addr, sp;
96 LONGEST fprs;
97 int regnum;
98
99 if (*this_cache)
100 return (struct sparc_frame_cache *) *this_cache;
101
102 cache = sparc_frame_cache (this_frame, this_cache);
103 gdb_assert (cache == *this_cache);
104
105 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
106
107 /* The third argument is a pointer to an instance of `ucontext_t',
108 which has a member `uc_mcontext' that contains the saved
109 registers. */
110 addr = get_frame_register_unsigned (this_frame, SPARC_O2_REGNUM);
111 mcontext_addr = addr + 64;
112
113 /* The following registers travel in the `mc_local' slots of
114 `mcontext_t'. */
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;
118
119 /* The following registers travel in the `mc_in' slots of
120 `mcontext_t'. */
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;
126
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;
133
134 /* The `local' and `in' registers have been saved in the register
135 save area. */
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;
141
142 /* The floating-point registers are only saved if the FEF bit in
143 %fprs has been set. */
144
145 #define FPRS_FEF (1 << 2)
146
147 addr = cache->saved_regs[SPARC64_FPRS_REGNUM].addr;
148 fprs = get_frame_memory_unsigned (this_frame, addr, 8);
149 if (fprs & FPRS_FEF)
150 {
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;
154
155 for (regnum = SPARC64_F32_REGNUM;
156 regnum <= SPARC64_F62_REGNUM; regnum++, addr += 8)
157 cache->saved_regs[regnum].addr = addr;
158 }
159
160 return cache;
161 }
162
163 static void
164 sparc64fbsd_sigtramp_frame_this_id (struct frame_info *this_frame,
165 void **this_cache,
166 struct frame_id *this_id)
167 {
168 struct sparc_frame_cache *cache =
169 sparc64fbsd_sigtramp_frame_cache (this_frame, this_cache);
170
171 (*this_id) = frame_id_build (cache->base, cache->pc);
172 }
173
174 static struct value *
175 sparc64fbsd_sigtramp_frame_prev_register (struct frame_info *this_frame,
176 void **this_cache, int regnum)
177 {
178 struct sparc_frame_cache *cache =
179 sparc64fbsd_sigtramp_frame_cache (this_frame, this_cache);
180
181 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
182 }
183
184 static int
185 sparc64fbsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
186 struct frame_info *this_frame,
187 void **this_cache)
188 {
189 CORE_ADDR pc = get_frame_pc (this_frame);
190 const char *name;
191
192 find_pc_partial_function (pc, &name, NULL, NULL);
193 if (sparc64fbsd_pc_in_sigtramp (pc, name))
194 return 1;
195
196 return 0;
197 }
198
199 static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind =
200 {
201 SIGTRAMP_FRAME,
202 default_frame_unwind_stop_reason,
203 sparc64fbsd_sigtramp_frame_this_id,
204 sparc64fbsd_sigtramp_frame_prev_register,
205 NULL,
206 sparc64fbsd_sigtramp_frame_sniffer
207 };
208
209
210 static const struct regset sparc64fbsd_gregset =
211 {
212 NULL, sparc64fbsd_supply_gregset, sparc64fbsd_collect_gregset
213 };
214
215 static const struct regset sparc64fbsd_fpregset =
216 {
217 NULL, sparc64fbsd_supply_fpregset, sparc64fbsd_collect_fpregset
218 };
219
220 static void
221 sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
222 {
223 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
224
225 /* Generic FreeBSD support. */
226 fbsd_init_abi (info, gdbarch);
227
228 tdep->gregset = &sparc64fbsd_gregset;
229 tdep->sizeof_gregset = 256;
230
231 tdep->fpregset = &sparc64fbsd_fpregset;
232 tdep->sizeof_fpregset = 272;
233
234 frame_unwind_append_unwinder (gdbarch, &sparc64fbsd_sigtramp_frame_unwind);
235
236 sparc64_init_abi (info, gdbarch);
237
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);
242 }
243
244 void
245 _initialize_sparc64fbsd_tdep (void)
246 {
247 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
248 GDB_OSABI_FREEBSD, sparc64fbsd_init_abi);
249 }
gdbarch
Definition: gdbarch.c:127
fbsd-tdep.h
sparc64fbsd_sigtramp_frame_unwind
static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind
Definition: sparc64-fbsd-tdep.c:199
sparc64_collect_fpregset
void sparc64_collect_fpregset(const struct sparc_fpregmap *fpregmap, const struct regcache *regcache, int regnum, void *fpregs)
Definition: sparc64-tdep.c:2143
sparc64_init_abi
void sparc64_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: sparc64-tdep.c:1804
frame_id_build
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:624
FPRS_FEF
#define FPRS_FEF
get_frame_pc
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
svr4_lp64_fetch_link_map_offsets
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3214
trad_frame_get_prev_register
struct value * trad_frame_get_prev_register(struct frame_info *this_frame, struct trad_frame_saved_reg this_saved_regs[], int regnum)
Definition: trad-frame.c:142
sparc_frame_cache::pc
CORE_ADDR pc
Definition: sparc-tdep.h:171
set_gdbarch_skip_trampoline_code
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3316
gdbarch_tdep::gregset
const struct regset * gregset
Definition: sparc-tdep.h:73
sparc_frame_cache
struct sparc_frame_cache * sparc_frame_cache(struct frame_info *this_frame, void **this_cache)
Definition: sparc-tdep.c:1174
BIAS
#define BIAS
Definition: sparc-tdep.c:72
gdbarch_tdep
Definition: aarch64-tdep.h:55
SPARC_O7_REGNUM
Definition: sparc-tdep.h:116
sparc64-tdep.h
SIGTRAMP_FRAME
Definition: frame.h:255
frame_info
Definition: frame.c:85
sparc_gregmap
Definition: sparc-tdep.h:37
gdbarch_tdep::sizeof_fpregset
size_t sizeof_fpregset
Definition: i386-tdep.h:66
get_frame_memory_unsigned
ULONGEST get_frame_memory_unsigned(struct frame_info *this_frame, CORE_ADDR addr, int len)
Definition: frame.c:2671
SPARC_F31_REGNUM
Definition: sparc-tdep.h:141
defs.h
sparc64_collect_gregset
void sparc64_collect_gregset(const struct sparc_gregmap *gregmap, const struct regcache *regcache, int regnum, void *gregs)
Definition: sparc64-tdep.c:1995
sparc64_supply_gregset
void sparc64_supply_gregset(const struct sparc_gregmap *gregmap, struct regcache *regcache, int regnum, const void *gregs)
Definition: sparc64-tdep.c:1878
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
SPARC_F0_REGNUM
Definition: sparc-tdep.h:133
SPARC_O2_REGNUM
Definition: sparc-tdep.h:111
frame_unwind_append_unwinder
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:79
sparc64fbsd_gregset
static const struct regset sparc64fbsd_gregset
Definition: sparc64-fbsd-tdep.c:210
sparc64fbsd_sigtramp_frame_this_id
static void sparc64fbsd_sigtramp_frame_this_id(struct frame_info *this_frame, void **this_cache, struct frame_id *this_id)
Definition: sparc64-fbsd-tdep.c:164
sparc_frame_cache::saved_regs
struct trad_frame_saved_reg * saved_regs
Definition: sparc-tdep.h:189
SPARC_SP_REGNUM
Definition: sparc-tdep.h:115
regset
Definition: regset.h:34
SPARC_I7_REGNUM
Definition: sparc-tdep.h:132
sparc64_bsd_fpregmap
const struct sparc_fpregmap sparc64_bsd_fpregmap
Definition: sparc64-tdep.c:2180
name
const char *const name
Definition: aarch64-tdep.c:76
GDB_OSABI_FREEBSD
Definition: defs.h:518
SPARC64_PC_REGNUM
Definition: sparc64-tdep.h:53
SPARC_L0_REGNUM
Definition: sparc-tdep.h:117
sparc64fbsd_fpregset
static const struct regset sparc64fbsd_fpregset
Definition: sparc64-fbsd-tdep.c:215
trad-frame.h
find_solib_trampoline_target
CORE_ADDR find_solib_trampoline_target(struct frame_info *frame, CORE_ADDR pc)
Definition: minsyms.c:1492
solib-svr4.h
sparc64fbsd_collect_gregset
static void sparc64fbsd_collect_gregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
Definition: sparc64-fbsd-tdep.c:58
osabi.h
regcache.h
sparc_frame_cache::base
CORE_ADDR base
Definition: sparc-tdep.h:170
SPARC64_NPC_REGNUM
Definition: sparc64-tdep.h:54
sparc64_supply_fpregset
void sparc64_supply_fpregset(const struct sparc_fpregmap *fpregmap, struct regcache *regcache, int regnum, const void *fpregs)
Definition: sparc64-tdep.c:2105
frame.h
sparc64fbsd_collect_fpregset
static void sparc64fbsd_collect_fpregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *fpregs, size_t len)
Definition: sparc64-fbsd-tdep.c:74
set_solib_svr4_fetch_link_map_offsets
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3137
find_pc_partial_function
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
Definition: blockframe.c:320
sparc64fbsd_pc_in_sigtramp
static int sparc64fbsd_pc_in_sigtramp(CORE_ADDR pc, const char *name)
Definition: sparc64-fbsd-tdep.c:85
fbsd_init_abi
void fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: fbsd-tdep.c:516
frame-unwind.h
SPARC64_STATE_REGNUM
Definition: sparc64-tdep.h:55
SPARC_G1_REGNUM
Definition: sparc-tdep.h:102
regnum
int regnum
Definition: aarch64-tdep.c:77
get_frame_register_unsigned
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1308
SPARC64_FSR_REGNUM
Definition: sparc64-tdep.h:56
gdbarch_register_osabi
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:143
trad_frame_alloc_saved_regs
struct trad_frame_saved_reg * trad_frame_alloc_saved_regs(struct gdbarch *gdbarch)
Definition: trad-frame.c:47
_initialize_sparc64fbsd_tdep
void _initialize_sparc64fbsd_tdep(void)
Definition: sparc64-fbsd-tdep.c:245
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
value
Definition: value.c:169
trad_frame_saved_reg::addr
LONGEST addr
Definition: trad-frame.h:83
sparc64fbsd_init_abi
static void sparc64fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: sparc64-fbsd-tdep.c:221
SPARC64_F62_REGNUM
Definition: sparc64-tdep.h:51
gdbcore.h
sparc64fbsd_supply_fpregset
static void sparc64fbsd_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
Definition: sparc64-fbsd-tdep.c:66
SPARC64_Y_REGNUM
Definition: sparc64-tdep.h:58
sparc64fbsd_sigtramp_frame_sniffer
static int sparc64fbsd_sigtramp_frame_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **this_cache)
Definition: sparc64-fbsd-tdep.c:185
SPARC64_F32_REGNUM
Definition: sparc64-tdep.h:49
sparc64fbsd_gregmap
const struct sparc_gregmap sparc64fbsd_gregmap
Definition: sparc64-fbsd-tdep.c:35
gdbarch_tdep::sizeof_gregset
size_t sizeof_gregset
Definition: i386-tdep.h:63
target.h
sparc64fbsd_supply_gregset
static void sparc64fbsd_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
Definition: sparc64-fbsd-tdep.c:50
sparc64fbsd_sigtramp_frame_cache
static struct sparc_frame_cache * sparc64fbsd_sigtramp_frame_cache(struct frame_info *this_frame, void **this_cache)
Definition: sparc64-fbsd-tdep.c:91
frame_unwind
Definition: frame-unwind.h:144
gdbarch_tdep::fpregset
const struct regset * fpregset
Definition: i386-tdep.h:253
default_frame_unwind_stop_reason
enum unwind_stop_reason default_frame_unwind_stop_reason(struct frame_info *this_frame, void **this_cache)
Definition: frame-unwind.c:184
sparc64fbsd_sigtramp_frame_prev_register
static struct value * sparc64fbsd_sigtramp_frame_prev_register(struct frame_info *this_frame, void **this_cache, int regnum)
Definition: sparc64-fbsd-tdep.c:175
regcache
Definition: regcache.h:232
gdbarch_info
Definition: gdbarch.h:1626
SPARC64_FPRS_REGNUM
Definition: sparc64-tdep.h:57
regset.h
sparc_frame_cache
Definition: sparc-tdep.h:167
frame_id
Definition: frame.h:111
LONGEST
long long LONGEST
Definition: common-types.h:52