GDB (xrefs)
Loading...
Searching...
No Matches
sparc64-obsd-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for OpenBSD/sparc64.
2
3 Copyright (C) 2004-2023 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 "symtab.h"
28#include "objfiles.h"
29#include "trad-frame.h"
30#include "inferior.h"
31
32#include "obsd-tdep.h"
33#include "sparc64-tdep.h"
34#include "solib-svr4.h"
35#include "bsd-uthread.h"
36
37/* Older OpenBSD versions used the traditional NetBSD core file
38 format, even for ports that use ELF. These core files don't use
39 multiple register sets. Instead, the general-purpose and
40 floating-point registers are lumped together in a single section.
41 Unlike on NetBSD, OpenBSD uses a different layout for its
42 general-purpose registers than the layout used for ptrace(2).
43
44 Newer OpenBSD versions use ELF core files. Here the register sets
45 match the ptrace(2) layout. */
46
47/* From <machine/reg.h>. */
49{
50 0 * 8, /* "tstate" */
51 1 * 8, /* %pc */
52 2 * 8, /* %npc */
53 3 * 8, /* %y */
54 -1, /* %fprs */
55 -1,
56 5 * 8, /* %g1 */
57 20 * 8, /* %l0 */
58 4 /* sizeof (%y) */
59};
60
62{
63 0 * 8, /* "tstate" */
64 1 * 8, /* %pc */
65 2 * 8, /* %npc */
66 3 * 8, /* %y */
67 -1, /* %fprs */
68 -1,
69 7 * 8, /* %g1 */
70 22 * 8, /* %l0 */
71 4 /* sizeof (%y) */
72};
73
74static void
76 struct regcache *regcache,
77 int regnum, const void *gregs, size_t len)
78{
79 const void *fpregs = (char *)gregs + 288;
80
81 if (len < 832)
82 {
84 return;
85 }
86
89}
90
91static void
93 struct regcache *regcache,
94 int regnum, const void *fpregs, size_t len)
95{
97}
98
99
100/* Signal trampolines. */
101
102/* Since OpenBSD 3.2, the sigtramp routine is mapped at a random page
103 in virtual memory. The randomness makes it somewhat tricky to
104 detect it, but fortunately we can rely on the fact that the start
105 of the sigtramp routine is page-aligned. We recognize the
106 trampoline by looking for the code that invokes the sigreturn
107 system call. The offset where we can find that code varies from
108 release to release.
109
110 By the way, the mapping mentioned above is read-only, so you cannot
111 place a breakpoint in the signal trampoline. */
112
113/* Default page size. */
114static const int sparc64obsd_page_size = 8192;
115
116/* Offset for sigreturn(2). */
117static const int sparc64obsd_sigreturn_offset[] = {
118 0xf0, /* OpenBSD 3.8 */
119 0xec, /* OpenBSD 3.6 */
120 0xe8, /* OpenBSD 3.2 */
121 -1
122};
123
124static int
125sparc64obsd_pc_in_sigtramp (CORE_ADDR pc, const char *name)
126{
127 CORE_ADDR start_pc = (pc & ~(sparc64obsd_page_size - 1));
128 unsigned long insn;
129 const int *offset;
130
131 if (name)
132 return 0;
133
134 for (offset = sparc64obsd_sigreturn_offset; *offset != -1; offset++)
135 {
136 /* Check for "restore %g0, SYS_sigreturn, %g1". */
137 insn = sparc_fetch_instruction (start_pc + *offset);
138 if (insn != 0x83e82067)
139 continue;
140
141 /* Check for "t ST_SYSCALL". */
142 insn = sparc_fetch_instruction (start_pc + *offset + 8);
143 if (insn != 0x91d02000)
144 continue;
145
146 return 1;
147 }
148
149 return 0;
150}
151
152static struct sparc_frame_cache *
153sparc64obsd_frame_cache (frame_info_ptr this_frame, 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 = get_frame_pc (this_frame);
169 cache->pc &= ~(sparc64obsd_page_size - 1);
170
171 /* Since we couldn't find the frame's function, the cache was
172 initialized under the assumption that we're frameless. */
174 addr = get_frame_register_unsigned (this_frame, SPARC_FP_REGNUM);
175 if (addr & 1)
176 addr += BIAS;
177 cache->base = addr;
178 }
179
180 /* We find the appropriate instance of `struct sigcontext' at a
181 fixed offset in the signal frame. */
182 addr = cache->base + 128 + 16;
183 cache->saved_regs = sparc64nbsd_sigcontext_saved_regs (addr, this_frame);
184
185 return cache;
186}
187
188static void
189sparc64obsd_frame_this_id (frame_info_ptr this_frame, void **this_cache,
190 struct frame_id *this_id)
191{
192 struct sparc_frame_cache *cache =
193 sparc64obsd_frame_cache (this_frame, this_cache);
194
195 (*this_id) = frame_id_build (cache->base, cache->pc);
196}
197
198static struct value *
200 void **this_cache, int regnum)
201{
202 struct sparc_frame_cache *cache =
203 sparc64obsd_frame_cache (this_frame, this_cache);
204
205 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
206}
207
208static int
210 frame_info_ptr 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);
218 return 1;
219
220 return 0;
221}
222
233
234/* Kernel debugging support. */
235
236static struct sparc_frame_cache *
237sparc64obsd_trapframe_cache (frame_info_ptr this_frame, void **this_cache)
238{
239 struct sparc_frame_cache *cache;
240 CORE_ADDR sp, trapframe_addr;
241 int regnum;
242
243 if (*this_cache)
244 return (struct sparc_frame_cache *) *this_cache;
245
246 cache = sparc_frame_cache (this_frame, this_cache);
247 gdb_assert (cache == *this_cache);
248
250 trapframe_addr = sp + BIAS + 176;
251
252 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
253
254 cache->saved_regs[SPARC64_STATE_REGNUM].set_addr (trapframe_addr);
255 cache->saved_regs[SPARC64_PC_REGNUM].set_addr (trapframe_addr + 8);
256 cache->saved_regs[SPARC64_NPC_REGNUM].set_addr (trapframe_addr + 16);
257
259 cache->saved_regs[regnum].set_addr (trapframe_addr + 48
260 + (regnum - SPARC_G0_REGNUM) * 8);
261
262 return cache;
263}
264
265static void
267 void **this_cache, struct frame_id *this_id)
268{
269 struct sparc_frame_cache *cache =
270 sparc64obsd_trapframe_cache (this_frame, this_cache);
271
272 (*this_id) = frame_id_build (cache->base, cache->pc);
273}
274
275static struct value *
277 void **this_cache, int regnum)
278{
279 struct sparc_frame_cache *cache =
280 sparc64obsd_trapframe_cache (this_frame, this_cache);
281
282 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
283}
284
285static int
287 frame_info_ptr this_frame,
288 void **this_cache)
289{
290 CORE_ADDR pc;
291 ULONGEST pstate;
292 const char *name;
293
294 /* Check whether we are in privileged mode, and bail out if we're not. */
296 if ((pstate & SPARC64_PSTATE_PRIV) == 0)
297 return 0;
298
299 pc = get_frame_address_in_block (this_frame);
300 find_pc_partial_function (pc, &name, NULL, NULL);
301 if (name && strcmp (name, "Lslowtrap_reenter") == 0)
302 return 1;
303
304 return 0;
305}
306
317
318
319/* Threads support. */
320
321/* Offset wthin the thread structure where we can find %fp and %i7. */
322#define SPARC64OBSD_UTHREAD_FP_OFFSET 232
323#define SPARC64OBSD_UTHREAD_PC_OFFSET 240
324
325static void
327 int regnum, CORE_ADDR addr)
328{
329 struct gdbarch *gdbarch = regcache->arch ();
330 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
331 CORE_ADDR fp, fp_addr = addr + SPARC64OBSD_UTHREAD_FP_OFFSET;
332 gdb_byte buf[8];
333
334 /* This function calls functions that depend on the global current thread. */
335 gdb_assert (regcache->ptid () == inferior_ptid);
336
337 gdb_assert (regnum >= -1);
338
339 fp = read_memory_unsigned_integer (fp_addr, 8, byte_order);
340 if (regnum == SPARC_SP_REGNUM || regnum == -1)
341 {
342 store_unsigned_integer (buf, 8, byte_order, fp);
344
345 if (regnum == SPARC_SP_REGNUM)
346 return;
347 }
348
350 || regnum == -1)
351 {
352 CORE_ADDR i7, i7_addr = addr + SPARC64OBSD_UTHREAD_PC_OFFSET;
353
354 i7 = read_memory_unsigned_integer (i7_addr, 8, byte_order);
355 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
356 {
357 store_unsigned_integer (buf, 8, byte_order, i7 + 8);
359 }
360 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
361 {
362 store_unsigned_integer (buf, 8, byte_order, i7 + 12);
364 }
365
367 return;
368 }
369
371}
372
373static void
375 int regnum, CORE_ADDR addr)
376{
377 struct gdbarch *gdbarch = regcache->arch ();
378 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
379 CORE_ADDR sp;
380 gdb_byte buf[8];
381
382 /* This function calls functions that depend on the global current thread. */
383 gdb_assert (regcache->ptid () == inferior_ptid);
384
385 gdb_assert (regnum >= -1);
386
387 if (regnum == SPARC_SP_REGNUM || regnum == -1)
388 {
389 CORE_ADDR fp_addr = addr + SPARC64OBSD_UTHREAD_FP_OFFSET;
390
392 write_memory (fp_addr,buf, 8);
393 }
394
395 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
396 {
397 CORE_ADDR i7, i7_addr = addr + SPARC64OBSD_UTHREAD_PC_OFFSET;
398
400 i7 = extract_unsigned_integer (buf, 8, byte_order) - 8;
401 write_memory_unsigned_integer (i7_addr, 8, byte_order, i7);
402
404 return;
405 }
406
408 sp = extract_unsigned_integer (buf, 8, byte_order);
410}
411
412
413static const struct regset sparc64obsd_gregset =
414 {
416 };
417
418static const struct regset sparc64obsd_fpregset =
419 {
421 };
422
423static void
425{
426 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
427
429 tdep->sizeof_gregset = 288;
431 tdep->sizeof_fpregset = 272;
432
433 /* Make sure we can single-step "new" syscalls. */
435
438
440 obsd_init_abi (info, gdbarch);
441
442 /* OpenBSD/sparc64 has SVR4-style shared libraries. */
446
447 /* OpenBSD provides a user-level threads implementation. */
450}
451
453void
455{
456 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
458}
int regnum
const char *const name
static struct parser_state * pstate
Definition ada-exp.c:101
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
void bsd_uthread_set_collect_uthread(struct gdbarch *gdbarch, void(*collect_uthread)(const struct regcache *, int, CORE_ADDR))
void bsd_uthread_set_supply_uthread(struct gdbarch *gdbarch, void(*supply_uthread)(struct regcache *, int, CORE_ADDR))
Definition bsd-uthread.c:98
gdbarch * arch() const
Definition regcache.c:231
void raw_collect(int regnum, void *buf) const override
Definition regcache.c:1127
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
ptid_t ptid() const
Definition regcache.h:408
void write_memory(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
Definition corefile.c:347
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition corefile.c:306
void write_memory_unsigned_integer(CORE_ADDR addr, int len, enum bfd_endian byte_order, ULONGEST value)
Definition corefile.c:380
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition defs.h:515
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
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
CORE_ADDR get_frame_address_in_block(frame_info_ptr this_frame)
Definition frame.c:2742
@ SIGTRAMP_FRAME
Definition frame.h:198
@ NORMAL_FRAME
Definition frame.h:187
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype *skip_solib_resolver)
ptid_t inferior_ptid
Definition infcmd.c:74
void obsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition obsd-tdep.c:294
CORE_ADDR obsd_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition obsd-tdep.c:29
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_OPENBSD
Definition osabi.h:35
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
struct link_map_offsets * svr4_lp64_fetch_link_map_offsets(void)
CORE_ADDR sparcnbsd_step_trap(frame_info_ptr frame, unsigned long insn)
void sparc_supply_rwindow(struct regcache *regcache, CORE_ADDR sp, int regnum)
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
void sparc_collect_rwindow(const struct regcache *regcache, CORE_ADDR sp, int regnum)
unsigned long sparc_fetch_instruction(CORE_ADDR pc)
Definition sparc-tdep.c:94
#define BIAS
Definition sparc-tdep.c:68
@ SPARC_FP_REGNUM
Definition sparc-tdep.h:134
@ SPARC_G0_REGNUM
Definition sparc-tdep.h:104
@ SPARC_I7_REGNUM
Definition sparc-tdep.h:135
@ SPARC_SP_REGNUM
Definition sparc-tdep.h:118
trad_frame_saved_reg * sparc64nbsd_sigcontext_saved_regs(CORE_ADDR sigcontext_addr, frame_info_ptr this_frame)
static const int sparc64obsd_page_size
static int sparc64obsd_pc_in_sigtramp(CORE_ADDR pc, const char *name)
void _initialize_sparc64obsd_tdep()
static void sparc64obsd_supply_uthread(struct regcache *regcache, int regnum, CORE_ADDR addr)
static const struct frame_unwind sparc64obsd_trapframe_unwind
static const struct regset sparc64obsd_fpregset
static struct value * sparc64obsd_trapframe_prev_register(frame_info_ptr this_frame, void **this_cache, int regnum)
const struct sparc_gregmap sparc64obsd_gregmap
static const struct regset sparc64obsd_gregset
static int sparc64obsd_trapframe_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache)
#define SPARC64OBSD_UTHREAD_FP_OFFSET
static void sparc64obsd_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
static int sparc64obsd_sigtramp_frame_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache)
#define SPARC64OBSD_UTHREAD_PC_OFFSET
static struct value * sparc64obsd_frame_prev_register(frame_info_ptr this_frame, void **this_cache, int regnum)
static const struct frame_unwind sparc64obsd_frame_unwind
static struct sparc_frame_cache * sparc64obsd_frame_cache(frame_info_ptr this_frame, void **this_cache)
static void sparc64obsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
const struct sparc_gregmap sparc64obsd_core_gregmap
static void sparc64obsd_frame_this_id(frame_info_ptr this_frame, void **this_cache, struct frame_id *this_id)
static void sparc64obsd_trapframe_this_id(frame_info_ptr this_frame, void **this_cache, struct frame_id *this_id)
static struct sparc_frame_cache * sparc64obsd_trapframe_cache(frame_info_ptr this_frame, void **this_cache)
static void sparc64obsd_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
static const int sparc64obsd_sigreturn_offset[]
static void sparc64obsd_collect_uthread(const struct regcache *regcache, int regnum, CORE_ADDR addr)
void sparc64_supply_gregset(const struct sparc_gregmap *gregmap, struct regcache *regcache, int regnum, const void *gregs)
void sparc64_supply_fpregset(const struct sparc_fpregmap *fpregmap, struct regcache *regcache, int regnum, const void *fpregs)
void sparc64_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
const struct sparc_fpregmap sparc64_bsd_fpregmap
#define SPARC64_PSTATE_PRIV
@ SPARC64_PSTATE_REGNUM
@ SPARC64_PC_REGNUM
@ SPARC64_NPC_REGNUM
@ SPARC64_STATE_REGNUM
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_addr(LONGEST addr)
Definition trad-frame.h:102
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