GDB (xrefs)
Loading...
Searching...
No Matches
sparc-linux-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for GNU/Linux SPARC.
2
3 Copyright (C) 2003-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 "dwarf2/frame.h"
22#include "frame.h"
23#include "frame-unwind.h"
24#include "gdbtypes.h"
25#include "regset.h"
26#include "gdbarch.h"
27#include "gdbcore.h"
28#include "osabi.h"
29#include "regcache.h"
30#include "solib-svr4.h"
31#include "symtab.h"
32#include "trad-frame.h"
33#include "tramp-frame.h"
34#include "xml-syscall.h"
35#include "linux-tdep.h"
36
37/* The syscall's XML filename for sparc 32-bit. */
38#define XML_SYSCALL_FILENAME_SPARC32 "syscalls/sparc-linux.xml"
39
40#include "sparc-tdep.h"
41
42/* Signal trampoline support. */
43
44static void sparc32_linux_sigframe_init (const struct tramp_frame *self,
45 frame_info_ptr this_frame,
46 struct trad_frame_cache *this_cache,
47 CORE_ADDR func);
48
49/* GNU/Linux has two flavors of signals. Normal signal handlers, and
50 "realtime" (RT) signals. The RT signals can provide additional
51 information to the signal handler if the SA_SIGINFO flag is set
52 when establishing a signal handler using `sigaction'. It is not
53 unlikely that future versions of GNU/Linux will support SA_SIGINFO
54 for normal signals too. */
55
56/* When the sparc Linux kernel calls a signal handler and the
57 SA_RESTORER flag isn't set, the return address points to a bit of
58 code on the stack. This code checks whether the PC appears to be
59 within this bit of code.
60
61 The instruction sequence for normal signals is encoded below.
62 Checking for the code sequence should be somewhat reliable, because
63 the effect is to call the system call sigreturn. This is unlikely
64 to occur anywhere other than a signal trampoline. */
65
67{
69 4,
70 {
71 { 0x821020d8, ULONGEST_MAX }, /* mov __NR_sigreturn, %g1 */
72 { 0x91d02010, ULONGEST_MAX }, /* ta 0x10 */
73 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
74 },
76};
77
78/* The instruction sequence for RT signals is slightly different. The
79 effect is to call the system call rt_sigreturn. */
80
82{
84 4,
85 {
86 { 0x82102065, ULONGEST_MAX }, /* mov __NR_rt_sigreturn, %g1 */
87 { 0x91d02010, ULONGEST_MAX }, /* ta 0x10 */
88 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
89 },
91};
92
93/* This enum represents the signals' numbers on the SPARC
94 architecture. It just contains the signal definitions which are
95 different from the generic implementation.
96
97 It is derived from the file <arch/sparc/include/uapi/asm/signal.h>,
98 from the Linux kernel tree. */
99
100enum
101 {
116 };
117
118static void
120 frame_info_ptr this_frame,
121 struct trad_frame_cache *this_cache,
122 CORE_ADDR func)
123{
124 CORE_ADDR base, addr, sp_addr;
125 int regnum;
126
127 base = get_frame_register_unsigned (this_frame, SPARC_O1_REGNUM);
128 if (self == &sparc32_linux_rt_sigframe)
129 base += 128;
130
131 /* Offsets from <bits/sigcontext.h>. */
132
133 trad_frame_set_reg_addr (this_cache, SPARC32_PSR_REGNUM, base + 0);
134 trad_frame_set_reg_addr (this_cache, SPARC32_PC_REGNUM, base + 4);
135 trad_frame_set_reg_addr (this_cache, SPARC32_NPC_REGNUM, base + 8);
136 trad_frame_set_reg_addr (this_cache, SPARC32_Y_REGNUM, base + 12);
137
138 /* Since %g0 is always zero, keep the identity encoding. */
139 addr = base + 20;
140 sp_addr = base + 16 + ((SPARC_SP_REGNUM - SPARC_G0_REGNUM) * 4);
142 {
143 trad_frame_set_reg_addr (this_cache, regnum, addr);
144 addr += 4;
145 }
146
147 base = get_frame_register_unsigned (this_frame, SPARC_SP_REGNUM);
148 addr = get_frame_memory_unsigned (this_frame, sp_addr, 4);
149
151 {
152 trad_frame_set_reg_addr (this_cache, regnum, addr);
153 addr += 4;
154 }
155 trad_frame_set_id (this_cache, frame_id_build (base, func));
156}
157
158/* Return the address of a system call's alternative return
159 address. */
160
161static CORE_ADDR
163{
164 if (insn == 0x91d02010)
165 {
166 ULONGEST sc_num = get_frame_register_unsigned (frame, SPARC_G1_REGNUM);
167
168 /* __NR_rt_sigreturn is 101 and __NR_sigreturn is 216. */
169 if (sc_num == 101 || sc_num == 216)
170 {
171 struct gdbarch *gdbarch = get_frame_arch (frame);
172 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
173
174 ULONGEST sp, pc_offset;
175
177
178 /* The kernel puts the sigreturn registers on the stack,
179 and this is where the signal unwinding state is take from
180 when returning from a signal.
181
182 For __NR_sigreturn, this register area sits 96 bytes from
183 the base of the stack. The saved PC sits 4 bytes into the
184 sigreturn register save area.
185
186 For __NR_rt_sigreturn a siginfo_t, which is 128 bytes, sits
187 right before the sigreturn register save area. */
188
189 pc_offset = 96 + 4;
190 if (sc_num == 101)
191 pc_offset += 128;
192
193 return read_memory_unsigned_integer (sp + pc_offset, 4, byte_order);
194 }
195 }
196
197 return 0;
198}
199
200
202{
203 32 * 4, /* %psr */
204 33 * 4, /* %pc */
205 34 * 4, /* %npc */
206 35 * 4, /* %y */
207 -1, /* %wim */
208 -1, /* %tbr */
209 1 * 4, /* %g1 */
210 16 * 4, /* %l0 */
211 4, /* y size */
212};
213
214
215static void
217 struct regcache *regcache,
218 int regnum, const void *gregs, size_t len)
219{
221 regcache, regnum, gregs);
222}
223
224static void
226 const struct regcache *regcache,
227 int regnum, void *gregs, size_t len)
228{
230 regcache, regnum, gregs);
231}
232
233static void
235 struct regcache *regcache,
236 int regnum, const void *fpregs, size_t len)
237{
239}
240
241static void
243 const struct regcache *regcache,
244 int regnum, void *fpregs, size_t len)
245{
247}
248
249/* Set the program counter for process PTID to PC. */
250
251#define PSR_SYSCALL 0x00004000
252
253static void
255{
256 gdbarch *arch = regcache->arch ();
257 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (arch);
258 ULONGEST psr;
259
262
263 /* Clear the "in syscall" bit to prevent the kernel from
264 messing with the PCs we just installed, if we happen to be
265 within an interrupted system call that the kernel wants to
266 restart.
267
268 Note that after we return from the dummy call, the PSR et al.
269 registers will be automatically restored, and the kernel
270 continues to restart the system call at this point. */
272 psr &= ~PSR_SYSCALL;
274}
275
276static LONGEST
278 thread_info *thread)
279{
280 struct regcache *regcache = get_thread_regcache (thread);
281 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
282 /* The content of a register. */
283 gdb_byte buf[4];
284 /* The result. */
285 LONGEST ret;
286
287 /* Getting the system call number from the register.
288 When dealing with the sparc architecture, this information
289 is stored at the %g1 register. */
291
292 ret = extract_signed_integer (buf, 4, byte_order);
293
294 return ret;
295}
296
297/* Implementation of `gdbarch_gdb_signal_from_target', as defined in
298 gdbarch.h. */
299
300static enum gdb_signal
302 int signal)
303{
304 switch (signal)
305 {
307 return GDB_SIGNAL_EMT;
308
310 return GDB_SIGNAL_BUS;
311
313 return GDB_SIGNAL_SYS;
314
316 return GDB_SIGNAL_URG;
317
319 return GDB_SIGNAL_STOP;
320
322 return GDB_SIGNAL_TSTP;
323
325 return GDB_SIGNAL_CONT;
326
328 return GDB_SIGNAL_CHLD;
329
330 /* No way to differentiate between SIGIO and SIGPOLL.
331 Therefore, we just handle the first one. */
333 return GDB_SIGNAL_IO;
334
335 /* No way to differentiate between SIGLOST and SIGPWR.
336 Therefore, we just handle the first one. */
338 return GDB_SIGNAL_LOST;
339
341 return GDB_SIGNAL_USR1;
342
344 return GDB_SIGNAL_USR2;
345 }
346
347 return linux_gdb_signal_from_target (gdbarch, signal);
348}
349
350/* Implementation of `gdbarch_gdb_signal_to_target', as defined in
351 gdbarch.h. */
352
353static int
355 enum gdb_signal signal)
356{
357 switch (signal)
358 {
359 case GDB_SIGNAL_EMT:
360 return SPARC_LINUX_SIGEMT;
361
362 case GDB_SIGNAL_BUS:
363 return SPARC_LINUX_SIGBUS;
364
365 case GDB_SIGNAL_SYS:
366 return SPARC_LINUX_SIGSYS;
367
368 case GDB_SIGNAL_URG:
369 return SPARC_LINUX_SIGURG;
370
371 case GDB_SIGNAL_STOP:
372 return SPARC_LINUX_SIGSTOP;
373
374 case GDB_SIGNAL_TSTP:
375 return SPARC_LINUX_SIGTSTP;
376
377 case GDB_SIGNAL_CONT:
378 return SPARC_LINUX_SIGCONT;
379
380 case GDB_SIGNAL_CHLD:
381 return SPARC_LINUX_SIGCHLD;
382
383 case GDB_SIGNAL_IO:
384 return SPARC_LINUX_SIGIO;
385
386 case GDB_SIGNAL_POLL:
387 return SPARC_LINUX_SIGPOLL;
388
389 case GDB_SIGNAL_LOST:
390 return SPARC_LINUX_SIGLOST;
391
392 case GDB_SIGNAL_PWR:
393 return SPARC_LINUX_SIGPWR;
394
395 case GDB_SIGNAL_USR1:
396 return SPARC_LINUX_SIGUSR1;
397
398 case GDB_SIGNAL_USR2:
399 return SPARC_LINUX_SIGUSR2;
400 }
401
402 return linux_gdb_signal_to_target (gdbarch, signal);
403}
404
405
406
413
420
421static void
423{
424 sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
425
426 linux_init_abi (info, gdbarch, 0);
427
429 tdep->sizeof_gregset = 152;
430
432 tdep->sizeof_fpregset = 396;
433
436
437 /* GNU/Linux has SVR4-style shared libraries... */
441
442 /* ...which means that we need some special handling when doing
443 prologue analysis. */
444 tdep->plt_entry_size = 12;
445
446 /* Enable TLS support. */
449
450 /* Make sure we can single-step over signal return system calls. */
452
453 /* Hook in the DWARF CFI frame unwinder. */
455
457
458 /* Functions for 'catch syscall'. */
462
467}
468
470void
int regnum
enum register_status cooked_read(int regnum, gdb_byte *buf)
Definition regcache.c:698
gdbarch * arch() const
Definition regcache.c:231
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition corefile.c:306
static LONGEST extract_signed_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:465
void dwarf2_append_unwinders(struct gdbarch *gdbarch)
Definition frame.c:1369
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition frame.c:1399
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
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
void set_gdbarch_write_pc(struct gdbarch *gdbarch, gdbarch_write_pc_ftype *write_pc)
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype *skip_trampoline_code)
void set_gdbarch_get_syscall_number(struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype *get_syscall_number)
void set_gdbarch_gdb_signal_from_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_from_target_ftype *gdb_signal_from_target)
void set_gdbarch_gdb_signal_to_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_to_target_ftype *gdb_signal_to_target)
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address)
int linux_gdb_signal_to_target(struct gdbarch *gdbarch, enum gdb_signal signal)
enum gdb_signal linux_gdb_signal_from_target(struct gdbarch *gdbarch, int signal)
link_map_offsets * linux_ilp32_fetch_link_map_offsets()
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, int num_disp_step_buffers)
CORE_ADDR find_solib_trampoline_target(frame_info_ptr frame, CORE_ADDR pc)
Definition minsyms.c:1554
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_LINUX
Definition osabi.h:32
enum register_status regcache_cooked_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
Definition regcache.c:796
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
Definition regcache.c:400
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition regcache.c:825
void(* func)(remote_target *remote, char *)
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
static void sparc32_linux_supply_core_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
static void sparc32_linux_collect_core_gregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
static void sparc32_linux_sigframe_init(const struct tramp_frame *self, frame_info_ptr this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
#define XML_SYSCALL_FILENAME_SPARC32
void _initialize_sparc_linux_tdep()
@ SPARC_LINUX_SIGBUS
@ SPARC_LINUX_SIGTSTP
@ SPARC_LINUX_SIGLOST
@ SPARC_LINUX_SIGCONT
@ SPARC_LINUX_SIGURG
@ SPARC_LINUX_SIGPOLL
@ SPARC_LINUX_SIGSYS
@ SPARC_LINUX_SIGPWR
@ SPARC_LINUX_SIGCHLD
@ SPARC_LINUX_SIGUSR2
@ SPARC_LINUX_SIGEMT
@ SPARC_LINUX_SIGSTOP
@ SPARC_LINUX_SIGIO
@ SPARC_LINUX_SIGUSR1
static const struct tramp_frame sparc32_linux_rt_sigframe
static void sparc_linux_write_pc(struct regcache *regcache, CORE_ADDR pc)
static void sparc32_linux_collect_core_fpregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *fpregs, size_t len)
static int sparc32_linux_gdb_signal_to_target(struct gdbarch *gdbarch, enum gdb_signal signal)
const struct sparc_gregmap sparc32_linux_core_gregmap
static const struct regset sparc32_linux_gregset
static enum gdb_signal sparc32_linux_gdb_signal_from_target(struct gdbarch *gdbarch, int signal)
static LONGEST sparc32_linux_get_syscall_number(struct gdbarch *gdbarch, thread_info *thread)
static const struct regset sparc32_linux_fpregset
static const struct tramp_frame sparc32_linux_sigframe
static void sparc32_linux_supply_core_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
static CORE_ADDR sparc32_linux_step_trap(frame_info_ptr frame, unsigned long insn)
static void sparc32_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
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)
void sparc32_collect_fpregset(const struct sparc_fpregmap *fpregmap, const struct regcache *regcache, int regnum, void *fpregs)
void sparc32_collect_gregset(const struct sparc_gregmap *gregmap, const struct regcache *regcache, int regnum, void *gregs)
@ SPARC32_NPC_REGNUM
Definition sparc-tdep.h:156
@ 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_G0_REGNUM
Definition sparc-tdep.h:104
@ SPARC_G1_REGNUM
Definition sparc-tdep.h:105
@ SPARC_L0_REGNUM
Definition sparc-tdep.h:120
@ SPARC_I7_REGNUM
Definition sparc-tdep.h:135
@ SPARC_O1_REGNUM
Definition sparc-tdep.h:113
@ SPARC_O7_REGNUM
Definition sparc-tdep.h:119
@ SPARC_SP_REGNUM
Definition sparc-tdep.h:118
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
struct tramp_frame::@191 insn[48]
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition trad-frame.c:110
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition trad-frame.c:220
void tramp_frame_prepend_unwinder(struct gdbarch *gdbarch, const struct tramp_frame *tramp_frame)
#define TRAMP_SENTINEL_INSN
Definition tramp-frame.h:44
void set_xml_syscall_file_name(struct gdbarch *gdbarch, const char *name)
Definition xml-syscall.c:50