GDB (xrefs)
Loading...
Searching...
No Matches
sparc-netbsd-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for NetBSD/sparc.
2
3 Copyright (C) 2002-2023 Free Software Foundation, Inc.
4 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 "gdbtypes.h"
26#include "osabi.h"
27#include "regcache.h"
28#include "regset.h"
29#include "solib-svr4.h"
30#include "symtab.h"
31#include "trad-frame.h"
32#include "gdbarch.h"
33
34#include "sparc-tdep.h"
35#include "netbsd-tdep.h"
36
37/* Macros to extract fields from SPARC instructions. */
38#define X_RS1(i) (((i) >> 14) & 0x1f)
39#define X_RS2(i) ((i) & 0x1f)
40#define X_I(i) (((i) >> 13) & 1)
41
43{
44 0 * 4, /* %psr */
45 1 * 4, /* %pc */
46 2 * 4, /* %npc */
47 3 * 4, /* %y */
48 -1, /* %wim */
49 -1, /* %tbr */
50 5 * 4, /* %g1 */
51 -1 /* %l0 */
52};
53
54static void
56 struct regcache *regcache,
57 int regnum, const void *gregs, size_t len)
58{
60
61 /* Traditional NetBSD core files don't use multiple register sets.
62 Instead, the general-purpose and floating-point registers are
63 lumped together in a single section. */
64 if (len >= 212)
66 (const char *) gregs + 80);
67}
68
69static void
71 struct regcache *regcache,
72 int regnum, const void *fpregs, size_t len)
73{
75}
76
77
78/* Signal trampolines. */
79
80/* The following variables describe the location of an on-stack signal
81 trampoline. The current values correspond to the memory layout for
82 NetBSD 1.3 and up. These shouldn't be necessary for NetBSD 2.0 and
83 up, since NetBSD uses signal trampolines provided by libc now. */
84
85static const CORE_ADDR sparc32nbsd_sigtramp_start = 0xeffffef0;
86static const CORE_ADDR sparc32nbsd_sigtramp_end = 0xeffffff0;
87
88static int
89sparc32nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *name)
90{
92 return 1;
93
94 return nbsd_pc_in_sigtramp (pc, name);
95}
96
99{
100 struct gdbarch *gdbarch = get_frame_arch (this_frame);
101 trad_frame_saved_reg *saved_regs;
102 CORE_ADDR addr, sigcontext_addr;
103 int regnum, delta;
104 ULONGEST psr;
105
106 saved_regs = trad_frame_alloc_saved_regs (this_frame);
107
108 /* We find the appropriate instance of `struct sigcontext' at a
109 fixed offset in the signal frame. */
110 addr = get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
111 sigcontext_addr = addr + 64 + 16;
112
113 /* The registers are saved in bits and pieces scattered all over the
114 place. The code below records their location on the assumption
115 that the part of the signal trampoline that saves the state has
116 been executed. */
117
118 saved_regs[SPARC_SP_REGNUM].set_addr (sigcontext_addr + 8);
119 saved_regs[SPARC32_PC_REGNUM].set_addr (sigcontext_addr + 12);
120 saved_regs[SPARC32_NPC_REGNUM].set_addr (sigcontext_addr + 16);
121 saved_regs[SPARC32_PSR_REGNUM].set_addr (sigcontext_addr + 20);
122 saved_regs[SPARC_G1_REGNUM].set_addr (sigcontext_addr + 24);
123 saved_regs[SPARC_O0_REGNUM].set_addr (sigcontext_addr + 28);
124
125 /* The remaining `global' registers and %y are saved in the `local'
126 registers. */
129 saved_regs[regnum].set_realreg (regnum + delta);
131
132 /* The remaining `out' registers can be found in the current frame's
133 `in' registers. */
136 saved_regs[regnum].set_realreg (regnum + delta);
138
139 /* The `local' and `in' registers have been saved in the register
140 save area. */
141 addr = saved_regs[SPARC_SP_REGNUM].addr ();
142 addr = get_frame_memory_unsigned (this_frame, addr, 4);
143 for (regnum = SPARC_L0_REGNUM;
144 regnum <= SPARC_I7_REGNUM; regnum++, addr += 4)
145 saved_regs[regnum].set_addr (addr);
146
147 /* Handle StackGhost. */
148 {
149 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
150
151 if (wcookie != 0)
152 {
153 ULONGEST i7;
154
155 addr = saved_regs[SPARC_I7_REGNUM].addr ();
156 i7 = get_frame_memory_unsigned (this_frame, addr, 4);
157 saved_regs[SPARC_I7_REGNUM].set_value (i7 ^ wcookie);
158 }
159 }
160
161 /* The floating-point registers are only saved if the EF bit in %prs
162 has been set. */
163
164#define PSR_EF 0x00001000
165
166 addr = saved_regs[SPARC32_PSR_REGNUM].addr ();
167 psr = get_frame_memory_unsigned (this_frame, addr, 4);
168 if (psr & PSR_EF)
169 {
170 CORE_ADDR sp;
171
173 saved_regs[SPARC32_FSR_REGNUM].set_addr (sp + 96);
174 for (regnum = SPARC_F0_REGNUM, addr = sp + 96 + 8;
175 regnum <= SPARC_F31_REGNUM; regnum++, addr += 4)
176 saved_regs[regnum].set_addr (addr);
177 }
178
179 return saved_regs;
180}
181
182static struct sparc_frame_cache *
184 void **this_cache)
185{
186 struct sparc_frame_cache *cache;
187 CORE_ADDR addr;
188
189 if (*this_cache)
190 return (struct sparc_frame_cache *) *this_cache;
191
192 cache = sparc_frame_cache (this_frame, this_cache);
193 gdb_assert (cache == *this_cache);
194
195 /* If we couldn't find the frame's function, we're probably dealing
196 with an on-stack signal trampoline. */
197 if (cache->pc == 0)
198 {
200
201 /* Since we couldn't find the frame's function, the cache was
202 initialized under the assumption that we're frameless. */
204 addr = get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
205 cache->base = addr;
206 }
207
208 cache->saved_regs = sparc32nbsd_sigcontext_saved_regs (this_frame);
209
210 return cache;
211}
212
213static void
215 void **this_cache,
216 struct frame_id *this_id)
217{
218 struct sparc_frame_cache *cache =
219 sparc32nbsd_sigcontext_frame_cache (this_frame, this_cache);
220
221 (*this_id) = frame_id_build (cache->base, cache->pc);
222}
223
224static struct value *
226 void **this_cache, int regnum)
227{
228 struct sparc_frame_cache *cache =
229 sparc32nbsd_sigcontext_frame_cache (this_frame, this_cache);
230
231 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
232}
233
234static int
236 frame_info_ptr this_frame,
237 void **this_cache)
238{
239 CORE_ADDR pc = get_frame_pc (this_frame);
240 const char *name;
241
242 find_pc_partial_function (pc, &name, NULL, NULL);
244 {
245 if (name == NULL || !startswith (name, "__sigtramp_sigcontext"))
246 return 1;
247 }
248
249 return 0;
250}
251
262
263/* Return the address of a system call's alternative return
264 address. */
265
266CORE_ADDR
267sparcnbsd_step_trap (frame_info_ptr frame, unsigned long insn)
268{
269 if ((X_I (insn) == 0 && X_RS1 (insn) == 0 && X_RS2 (insn) == 0)
270 || (X_I (insn) == 1 && X_RS1 (insn) == 0 && (insn & 0x7f) == 0))
271 {
272 /* "New" system call. */
273 ULONGEST number = get_frame_register_unsigned (frame, SPARC_G1_REGNUM);
274
275 if (number & 0x400)
277 if (number & 0x800)
279 }
280
281 return 0;
282}
283
284
285static const struct regset sparc32nbsd_gregset =
286 {
288 };
289
290static const struct regset sparc32nbsd_fpregset =
291 {
293 };
294
295void
297{
298 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
299
300 nbsd_init_abi (info, gdbarch);
301
302 /* NetBSD doesn't support the 128-bit `long double' from the psABI. */
305
307 tdep->sizeof_gregset = 20 * 4;
308
310 tdep->sizeof_fpregset = 33 * 4;
311
312 /* Make sure we can single-step "new" syscalls. */
314
316
319}
320
322void
int regnum
const char *const name
bool find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block)
Definition blockframe.c:373
enum unwind_stop_reason default_frame_unwind_stop_reason(frame_info_ptr this_frame, void **this_cache)
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition frame.c:1399
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition frame.c:736
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
ULONGEST get_frame_memory_unsigned(frame_info_ptr this_frame, CORE_ADDR addr, int len)
Definition frame.c:3007
@ SIGTRAMP_FRAME
Definition frame.h:198
void set_gdbarch_long_double_format(struct gdbarch *gdbarch, const struct floatformat **long_double_format)
Definition gdbarch.c:1663
void set_gdbarch_long_double_bit(struct gdbarch *gdbarch, int long_double_bit)
Definition gdbarch.c:1646
const struct floatformat * floatformats_ieee_double[BFD_ENDIAN_UNKNOWN]
Definition gdbtypes.c:89
int nbsd_pc_in_sigtramp(CORE_ADDR pc, const char *func_name)
Definition netbsd-tdep.c:48
void nbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
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:146
@ GDB_OSABI_NETBSD
Definition osabi.h:34
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
trad_frame_saved_reg * sparc32nbsd_sigcontext_saved_regs(frame_info_ptr this_frame)
CORE_ADDR sparcnbsd_step_trap(frame_info_ptr frame, unsigned long insn)
static int sparc32nbsd_sigcontext_frame_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache)
static void sparc32nbsd_sigcontext_frame_this_id(frame_info_ptr this_frame, void **this_cache, struct frame_id *this_id)
#define PSR_EF
static const struct regset sparc32nbsd_fpregset
#define X_RS2(i)
static struct sparc_frame_cache * sparc32nbsd_sigcontext_frame_cache(frame_info_ptr this_frame, void **this_cache)
static const struct regset sparc32nbsd_gregset
void sparc32nbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
static const CORE_ADDR sparc32nbsd_sigtramp_end
#define X_I(i)
void _initialize_sparcnbsd_tdep()
static const CORE_ADDR sparc32nbsd_sigtramp_start
static int sparc32nbsd_pc_in_sigtramp(CORE_ADDR pc, const char *name)
static const struct frame_unwind sparc32nbsd_sigcontext_frame_unwind
static struct value * sparc32nbsd_sigcontext_frame_prev_register(frame_info_ptr this_frame, void **this_cache, int regnum)
static void sparc32nbsd_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
#define X_RS1(i)
static void sparc32nbsd_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
const struct sparc_gregmap sparc32nbsd_gregmap
struct sparc_frame_cache * sparc_frame_cache(frame_info_ptr this_frame, void **this_cache)
void sparc_record_save_insn(struct sparc_frame_cache *cache)
Definition sparc-tdep.c:960
ULONGEST sparc_fetch_wcookie(struct gdbarch *gdbarch)
Definition sparc-tdep.c:185
void sparc32_supply_gregset(const struct sparc_gregmap *gregmap, struct regcache *regcache, int regnum, const void *gregs)
const struct sparc_fpregmap sparc32_bsd_fpregmap
void sparc32_supply_fpregset(const struct sparc_fpregmap *fpregmap, struct regcache *regcache, int regnum, const void *fpregs)
@ SPARC32_NPC_REGNUM
Definition sparc-tdep.h:156
@ SPARC32_FSR_REGNUM
Definition sparc-tdep.h:157
@ SPARC32_PSR_REGNUM
Definition sparc-tdep.h:152
@ SPARC32_PC_REGNUM
Definition sparc-tdep.h:155
@ SPARC32_Y_REGNUM
Definition sparc-tdep.h:150
@ SPARC_FP_REGNUM
Definition sparc-tdep.h:134
@ SPARC_O0_REGNUM
Definition sparc-tdep.h:112
@ SPARC_G0_REGNUM
Definition sparc-tdep.h:104
@ SPARC_G1_REGNUM
Definition sparc-tdep.h:105
@ SPARC_L0_REGNUM
Definition sparc-tdep.h:120
@ SPARC_I0_REGNUM
Definition sparc-tdep.h:128
@ SPARC_L1_REGNUM
Definition sparc-tdep.h:121
@ SPARC_G7_REGNUM
Definition sparc-tdep.h:111
@ SPARC_G2_REGNUM
Definition sparc-tdep.h:106
@ SPARC_F0_REGNUM
Definition sparc-tdep.h:136
@ SPARC_I7_REGNUM
Definition sparc-tdep.h:135
@ SPARC_O5_REGNUM
Definition sparc-tdep.h:117
@ SPARC_F31_REGNUM
Definition sparc-tdep.h:144
@ SPARC_O1_REGNUM
Definition sparc-tdep.h:113
@ SPARC_O7_REGNUM
Definition sparc-tdep.h:119
@ SPARC_SP_REGNUM
Definition sparc-tdep.h:118
struct trad_frame_saved_reg * saved_regs
Definition sparc-tdep.h:192
CORE_ADDR(* step_trap)(frame_info_ptr frame, unsigned long insn)
Definition sparc-tdep.h:88
const struct regset * fpregset
Definition sparc-tdep.h:77
const struct regset * gregset
Definition sparc-tdep.h:75
void set_realreg(int realreg)
Definition trad-frame.h:95
void set_addr(LONGEST addr)
Definition trad-frame.h:102
void set_value(LONGEST val)
Definition trad-frame.h:88
Definition value.h:130
trad_frame_saved_reg * trad_frame_alloc_saved_regs(struct gdbarch *gdbarch)
Definition trad-frame.c:62
struct value * trad_frame_get_prev_register(frame_info_ptr this_frame, trad_frame_saved_reg this_saved_regs[], int regnum)
Definition trad-frame.c:187