GDB (xrefs)

/tmp/gdb-8.1/gdb/sparc64-nbsd-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for NetBSD/sparc64.
2
3 Copyright (C) 2002-2018 Free Software Foundation, Inc.
4 Based on code contributed by Wasabi Systems, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "defs.h"
22 #include "frame.h"
23 #include "frame-unwind.h"
24 #include "gdbcore.h"
25 #include "osabi.h"
26 #include "regcache.h"
27 #include "regset.h"
28 #include "symtab.h"
29 #include "objfiles.h"
30 #include "solib-svr4.h"
31 #include "trad-frame.h"
32
33 #include "sparc64-tdep.h"
34 #include "nbsd-tdep.h"
35
36 /* From <machine/reg.h>. */
37 const struct sparc_gregmap sparc64nbsd_gregmap =
38 {
39 0 * 8, /* "tstate" */
40 1 * 8, /* %pc */
41 2 * 8, /* %npc */
42 3 * 8, /* %y */
43 -1, /* %fprs */
44 -1,
45 5 * 8, /* %g1 */
46 -1, /* %l0 */
47 4 /* sizeof (%y) */
48 };
49
50
51 static void
52 sparc64nbsd_supply_gregset (const struct regset *regset,
53 struct regcache *regcache,
54 int regnum, const void *gregs, size_t len)
55 {
56 sparc64_supply_gregset (&sparc64nbsd_gregmap, regcache, regnum, gregs);
57 }
58
59 static void
60 sparc64nbsd_supply_fpregset (const struct regset *regset,
61 struct regcache *regcache,
62 int regnum, const void *fpregs, size_t len)
63 {
64 sparc64_supply_fpregset (&sparc64_bsd_fpregmap, regcache, regnum, fpregs);
65 }
66
67
68 /* Signal trampolines. */
69
70 /* The following variables describe the location of an on-stack signal
71 trampoline. The current values correspond to the memory layout for
72 NetBSD 1.3 and up. These shouldn't be necessary for NetBSD 2.0 and
73 up, since NetBSD uses signal trampolines provided by libc now. */
74
75 static const CORE_ADDR sparc64nbsd_sigtramp_start = 0xffffffffffffdee4ULL;
76 static const CORE_ADDR sparc64nbsd_sigtramp_end = 0xffffffffffffe000ULL;
77
78 static int
79 sparc64nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *name)
80 {
81 if (pc >= sparc64nbsd_sigtramp_start && pc < sparc64nbsd_sigtramp_end)
82 return 1;
83
84 return nbsd_pc_in_sigtramp (pc, name);
85 }
86
87 struct trad_frame_saved_reg *
88 sparc64nbsd_sigcontext_saved_regs (CORE_ADDR sigcontext_addr,
89 struct frame_info *this_frame)
90 {
91 struct gdbarch *gdbarch = get_frame_arch (this_frame);
92 struct trad_frame_saved_reg *saved_regs;
93 CORE_ADDR addr, sp;
94 int regnum, delta;
95
96 saved_regs = trad_frame_alloc_saved_regs (this_frame);
97
98 /* The registers are saved in bits and pieces scattered all over the
99 place. The code below records their location on the assumption
100 that the part of the signal trampoline that saves the state has
101 been executed. */
102
103 saved_regs[SPARC_SP_REGNUM].addr = sigcontext_addr + 8;
104 saved_regs[SPARC64_PC_REGNUM].addr = sigcontext_addr + 16;
105 saved_regs[SPARC64_NPC_REGNUM].addr = sigcontext_addr + 24;
106 saved_regs[SPARC64_STATE_REGNUM].addr = sigcontext_addr + 32;
107 saved_regs[SPARC_G1_REGNUM].addr = sigcontext_addr + 40;
108 saved_regs[SPARC_O0_REGNUM].addr = sigcontext_addr + 48;
109
110 /* The remaining `global' registers and %y are saved in the `local'
111 registers. */
112 delta = SPARC_L0_REGNUM - SPARC_G0_REGNUM;
113 for (regnum = SPARC_G2_REGNUM; regnum <= SPARC_G7_REGNUM; regnum++)
114 saved_regs[regnum].realreg = regnum + delta;
115 saved_regs[SPARC64_Y_REGNUM].realreg = SPARC_L1_REGNUM;
116
117 /* The remaining `out' registers can be found in the current frame's
118 `in' registers. */
119 delta = SPARC_I0_REGNUM - SPARC_O0_REGNUM;
120 for (regnum = SPARC_O1_REGNUM; regnum <= SPARC_O5_REGNUM; regnum++)
121 saved_regs[regnum].realreg = regnum + delta;
122 saved_regs[SPARC_O7_REGNUM].realreg = SPARC_I7_REGNUM;
123
124 /* The `local' and `in' registers have been saved in the register
125 save area. */
126 addr = saved_regs[SPARC_SP_REGNUM].addr;
127 sp = get_frame_memory_unsigned (this_frame, addr, 8);
128 for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
129 regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
130 saved_regs[regnum].addr = addr;
131
132 /* Handle StackGhost. */
133 {
134 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
135
136 if (wcookie != 0)
137 {
138 ULONGEST i7;
139
140 addr = saved_regs[SPARC_I7_REGNUM].addr;
141 i7 = get_frame_memory_unsigned (this_frame, addr, 8);
142 trad_frame_set_value (saved_regs, SPARC_I7_REGNUM, i7 ^ wcookie);
143 }
144 }
145
146 /* TODO: Handle the floating-point registers. */
147
148 return saved_regs;
149 }
150
151 static struct sparc_frame_cache *
152 sparc64nbsd_sigcontext_frame_cache (struct frame_info *this_frame,
153 void **this_cache)
154 {
155 struct sparc_frame_cache *cache;
156 CORE_ADDR addr;
157
158 if (*this_cache)
159 return (struct sparc_frame_cache *) *this_cache;
160
161 cache = sparc_frame_cache (this_frame, this_cache);
162 gdb_assert (cache == *this_cache);
163
164 /* If we couldn't find the frame's function, we're probably dealing
165 with an on-stack signal trampoline. */
166 if (cache->pc == 0)
167 {
168 cache->pc = sparc64nbsd_sigtramp_start;
169
170 /* Since we couldn't find the frame's function, the cache was
171 initialized under the assumption that we're frameless. */
172 sparc_record_save_insn (cache);
173 addr = get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
174 if (addr & 1)
175 addr += BIAS;
176 cache->base = addr;
177 }
178
179 /* We find the appropriate instance of `struct sigcontext' at a
180 fixed offset in the signal frame. */
181 addr = cache->base + 128 + 8;
182 cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, this_frame);
183
184 return cache;
185 }
186
187 static void
188 sparc64nbsd_sigcontext_frame_this_id (struct frame_info *this_frame,
189 void **this_cache,
190 struct frame_id *this_id)
191 {
192 struct sparc_frame_cache *cache =
193 sparc64nbsd_sigcontext_frame_cache (this_frame, this_cache);
194
195 (*this_id) = frame_id_build (cache->base, cache->pc);
196 }
197
198 static struct value *
199 sparc64nbsd_sigcontext_frame_prev_register (struct frame_info *this_frame,
200 void **this_cache, int regnum)
201 {
202 struct sparc_frame_cache *cache =
203 sparc64nbsd_sigcontext_frame_cache (this_frame, this_cache);
204
205 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
206 }
207
208 static int
209 sparc64nbsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
210 struct frame_info *this_frame,
211 void **this_cache)
212 {
213 CORE_ADDR pc = get_frame_pc (this_frame);
214 const char *name;
215
216 find_pc_partial_function (pc, &name, NULL, NULL);
217 if (sparc64nbsd_pc_in_sigtramp (pc, name))
218 {
219 if (name == NULL || !startswith (name, "__sigtramp_sigcontext"))
220 return 1;
221 }
222
223 return 0;
224 }
225
226 static const struct frame_unwind sparc64nbsd_sigcontext_frame_unwind =
227 {
228 SIGTRAMP_FRAME,
229 default_frame_unwind_stop_reason,
230 sparc64nbsd_sigcontext_frame_this_id,
231 sparc64nbsd_sigcontext_frame_prev_register,
232 NULL,
233 sparc64nbsd_sigtramp_frame_sniffer
234 };
235
236
237 static const struct regset sparc64nbsd_gregset =
238 {
239 NULL, sparc64nbsd_supply_gregset, NULL
240 };
241
242 static const struct regset sparc64nbsd_fpregset =
243 {
244 NULL, sparc64nbsd_supply_fpregset, NULL
245 };
246
247 static void
248 sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
249 {
250 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
251
252 tdep->gregset = &sparc64nbsd_gregset;
253 tdep->sizeof_gregset = 160;
254
255 tdep->fpregset = &sparc64nbsd_fpregset;
256 tdep->sizeof_fpregset = 272;
257
258 /* Make sure we can single-step "new" syscalls. */
259 tdep->step_trap = sparcnbsd_step_trap;
260
261 frame_unwind_append_unwinder (gdbarch, &sparc64nbsd_sigcontext_frame_unwind);
262
263 sparc64_init_abi (info, gdbarch);
264
265 /* NetBSD/sparc64 has SVR4-style shared libraries. */
266 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
267 set_solib_svr4_fetch_link_map_offsets
268 (gdbarch, svr4_lp64_fetch_link_map_offsets);
269 }
270
271 void
272 _initialize_sparc64nbsd_tdep (void)
273 {
274 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
275 GDB_OSABI_NETBSD, sparc64nbsd_init_abi);
276 }
gdbarch
Definition: gdbarch.c:127
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
get_frame_pc
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
sparc64nbsd_supply_gregset
static void sparc64nbsd_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
Definition: sparc64-nbsd-tdep.c:52
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
sparc64nbsd_fpregset
static const struct regset sparc64nbsd_fpregset
Definition: sparc64-nbsd-tdep.c:242
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
SPARC_L1_REGNUM
Definition: sparc-tdep.h:118
sparc_record_save_insn
void sparc_record_save_insn(struct sparc_frame_cache *cache)
Definition: sparc-tdep.c:942
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
trad_frame_set_value
void trad_frame_set_value(struct trad_frame_saved_reg this_saved_regs[], int regnum, LONGEST val)
Definition: trad-frame.c:99
sparc64nbsd_sigcontext_frame_this_id
static void sparc64nbsd_sigcontext_frame_this_id(struct frame_info *this_frame, void **this_cache, struct frame_id *this_id)
Definition: sparc64-nbsd-tdep.c:188
gdbarch_tdep::gregset
const struct regset * gregset
Definition: sparc-tdep.h:73
nbsd_pc_in_sigtramp
int nbsd_pc_in_sigtramp(CORE_ADDR pc, const char *func_name)
Definition: nbsd-tdep.c:42
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_I0_REGNUM
Definition: sparc-tdep.h:125
sparc_gregmap
Definition: sparc-tdep.h:37
gdbarch_tdep::step_trap
CORE_ADDR(* step_trap)(struct frame_info *frame, unsigned long insn)
Definition: sparc-tdep.h:86
sparc64nbsd_pc_in_sigtramp
static int sparc64nbsd_pc_in_sigtramp(CORE_ADDR pc, const char *name)
Definition: sparc64-nbsd-tdep.c:79
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
defs.h
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_G0_REGNUM
Definition: sparc-tdep.h:101
frame_unwind_append_unwinder
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:79
sparc64nbsd_sigcontext_saved_regs
struct trad_frame_saved_reg * sparc64nbsd_sigcontext_saved_regs(CORE_ADDR sigcontext_addr, struct frame_info *this_frame)
Definition: sparc64-nbsd-tdep.c:88
sparc_frame_cache::saved_regs
struct trad_frame_saved_reg * saved_regs
Definition: sparc-tdep.h:189
objfiles.h
sparc_fetch_wcookie
ULONGEST sparc_fetch_wcookie(struct gdbarch *gdbarch)
Definition: sparc-tdep.c:189
SPARC_SP_REGNUM
Definition: sparc-tdep.h:115
regset
Definition: regset.h:34
SPARC_I7_REGNUM
Definition: sparc-tdep.h:132
symtab.h
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
sparc64nbsd_sigtramp_frame_sniffer
static int sparc64nbsd_sigtramp_frame_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **this_cache)
Definition: sparc64-nbsd-tdep.c:209
SPARC64_PC_REGNUM
Definition: sparc64-tdep.h:53
SPARC_L0_REGNUM
Definition: sparc-tdep.h:117
SPARC_O5_REGNUM
Definition: sparc-tdep.h:114
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
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
sparc64nbsd_init_abi
static void sparc64nbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: sparc64-nbsd-tdep.c:248
frame.h
sparc64nbsd_sigcontext_frame_prev_register
static struct value * sparc64nbsd_sigcontext_frame_prev_register(struct frame_info *this_frame, void **this_cache, int regnum)
Definition: sparc64-nbsd-tdep.c:199
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
frame-unwind.h
SPARC64_STATE_REGNUM
Definition: sparc64-tdep.h:55
sparc64nbsd_gregmap
const struct sparc_gregmap sparc64nbsd_gregmap
Definition: sparc64-nbsd-tdep.c:37
startswith
static int startswith(const char *string, const char *pattern)
Definition: common-utils.h:107
SPARC_G1_REGNUM
Definition: sparc-tdep.h:102
sparcnbsd_step_trap
CORE_ADDR sparcnbsd_step_trap(struct frame_info *frame, unsigned long insn)
Definition: sparc-nbsd-tdep.c:265
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
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
nbsd-tdep.h
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
SPARC_O1_REGNUM
Definition: sparc-tdep.h:110
SPARC_O0_REGNUM
Definition: sparc-tdep.h:109
gdbcore.h
SPARC_G2_REGNUM
Definition: sparc-tdep.h:103
GDB_OSABI_NETBSD
Definition: defs.h:519
SPARC64_Y_REGNUM
Definition: sparc64-tdep.h:58
gdbarch_tdep::sizeof_gregset
size_t sizeof_gregset
Definition: i386-tdep.h:63
frame_unwind
Definition: frame-unwind.h:144
sparc64nbsd_sigtramp_end
static const CORE_ADDR sparc64nbsd_sigtramp_end
Definition: sparc64-nbsd-tdep.c:76
gdbarch_tdep::fpregset
const struct regset * fpregset
Definition: i386-tdep.h:253
sparc64nbsd_gregset
static const struct regset sparc64nbsd_gregset
Definition: sparc64-nbsd-tdep.c:237
ULONGEST
unsigned long long ULONGEST
Definition: common-types.h:53
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
regcache
Definition: regcache.h:232
gdbarch_info
Definition: gdbarch.h:1626
sparc64nbsd_sigcontext_frame_unwind
static const struct frame_unwind sparc64nbsd_sigcontext_frame_unwind
Definition: sparc64-nbsd-tdep.c:226
SPARC_FP_REGNUM
Definition: sparc-tdep.h:131
regset.h
sparc64nbsd_sigtramp_start
static const CORE_ADDR sparc64nbsd_sigtramp_start
Definition: sparc64-nbsd-tdep.c:75
sparc64nbsd_supply_fpregset
static void sparc64nbsd_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
Definition: sparc64-nbsd-tdep.c:60
sparc_frame_cache
Definition: sparc-tdep.h:167
sparc64nbsd_sigcontext_frame_cache
static struct sparc_frame_cache * sparc64nbsd_sigcontext_frame_cache(struct frame_info *this_frame, void **this_cache)
Definition: sparc64-nbsd-tdep.c:152
trad_frame_saved_reg
Definition: trad-frame.h:81
trad_frame_saved_reg::realreg
int realreg
Definition: trad-frame.h:84
_initialize_sparc64nbsd_tdep
void _initialize_sparc64nbsd_tdep(void)
Definition: sparc64-nbsd-tdep.c:272
frame_id
Definition: frame.h:111
get_frame_arch
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
SPARC_G7_REGNUM
Definition: sparc-tdep.h:108