GDB (xrefs)
Loading...
Searching...
No Matches
sh-linux-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for GNU/Linux Super-H.
2
3 Copyright (C) 2005-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 "osabi.h"
22
23#include "solib-svr4.h"
24#include "symtab.h"
25
26#include "trad-frame.h"
27#include "tramp-frame.h"
28
29#include "glibc-tdep.h"
30#include "sh-tdep.h"
31#include "linux-tdep.h"
32#include "gdbarch.h"
33
34#define REGSx16(base) \
35 {(base), 0}, \
36 {(base) + 1, 4}, \
37 {(base) + 2, 8}, \
38 {(base) + 3, 12}, \
39 {(base) + 4, 16}, \
40 {(base) + 5, 20}, \
41 {(base) + 6, 24}, \
42 {(base) + 7, 28}, \
43 {(base) + 8, 32}, \
44 {(base) + 9, 36}, \
45 {(base) + 10, 40}, \
46 {(base) + 11, 44}, \
47 {(base) + 12, 48}, \
48 {(base) + 13, 52}, \
49 {(base) + 14, 56}, \
50 {(base) + 15, 60}
51
52/* Describe the contents of the .reg section of the core file. */
53
54static const struct sh_corefile_regmap gregs_table[] =
55{
57 {PC_REGNUM, 64},
58 {PR_REGNUM, 68},
59 {SR_REGNUM, 72},
60 {GBR_REGNUM, 76},
61 {MACH_REGNUM, 80},
62 {MACL_REGNUM, 84},
63 {-1 /* Terminator. */, 0}
64};
65
66/* Describe the contents of the .reg2 section of the core file. */
67
68static const struct sh_corefile_regmap fpregs_table[] =
69{
71 /* REGSx16 xfp_regs omitted. */
72 {FPSCR_REGNUM, 128},
73 {FPUL_REGNUM, 132},
74 {-1 /* Terminator. */, 0}
75};
76
77/* SH signal handler frame support. */
78
79static void
81 struct trad_frame_cache *this_cache,
82 CORE_ADDR func, int regs_offset)
83{
84 int i;
85 struct gdbarch *gdbarch = get_frame_arch (this_frame);
86 CORE_ADDR base = get_frame_register_unsigned (this_frame,
88 CORE_ADDR regs = base + regs_offset;
89
90 for (i = 0; i < 18; i++)
91 trad_frame_set_reg_addr (this_cache, i, regs + i * 4);
92
93 trad_frame_set_reg_addr (this_cache, SR_REGNUM, regs + 18 * 4);
94 trad_frame_set_reg_addr (this_cache, GBR_REGNUM, regs + 19 * 4);
95 trad_frame_set_reg_addr (this_cache, MACH_REGNUM, regs + 20 * 4);
96 trad_frame_set_reg_addr (this_cache, MACL_REGNUM, regs + 21 * 4);
97
98 /* Restore FP state if we have an FPU. */
99 if (gdbarch_fp0_regnum (gdbarch) != -1)
100 {
101 CORE_ADDR fpregs = regs + 22 * 4;
102 for (i = FR0_REGNUM; i <= FP_LAST_REGNUM; i++)
103 trad_frame_set_reg_addr (this_cache, i, fpregs + i * 4);
104 trad_frame_set_reg_addr (this_cache, FPSCR_REGNUM, fpregs + 32 * 4);
105 trad_frame_set_reg_addr (this_cache, FPUL_REGNUM, fpregs + 33 * 4);
106 }
107
108 /* Save a frame ID. */
109 trad_frame_set_id (this_cache, frame_id_build (base, func));
110}
111
112/* Implement struct tramp_frame "init" callbacks for signal
113 trampolines on 32-bit SH. */
114
115static void
117 frame_info_ptr this_frame,
118 struct trad_frame_cache *this_cache,
119 CORE_ADDR func)
120{
121 /* SH 32-bit sigframe: sigcontext at start of sigframe,
122 registers start after a single 'oldmask' word. */
123 sh_linux_sigtramp_cache (this_frame, this_cache, func, 4);
124}
125
126static void
128 frame_info_ptr this_frame,
129 struct trad_frame_cache *this_cache,
130 CORE_ADDR func)
131{
132 /* SH 32-bit rt_sigframe: starts with a siginfo (128 bytes), then
133 we can find sigcontext embedded within a ucontext (offset 20 bytes).
134 Then registers start after a single 'oldmask' word. */
135 sh_linux_sigtramp_cache (this_frame, this_cache, func,
136 128 /* sizeof (struct siginfo) */
137 + 20 /* offsetof (struct ucontext, uc_mcontext) */
138 + 4 /* oldmask word at start of sigcontext */);
139}
140
141/* Instruction patterns. */
142#define SH_MOVW 0x9305
143#define SH_TRAP 0xc300
144#define SH_OR_R0_R0 0x200b
145
146/* SH sigreturn syscall numbers. */
147#define SH_NR_SIGRETURN 0x0077
148#define SH_NR_RT_SIGRETURN 0x00ad
149
152 2,
153 {
154 { SH_MOVW, 0xffff },
155 { SH_TRAP, 0xff00 }, /* #imm argument part filtered out. */
156 { SH_OR_R0_R0, 0xffff },
157 { SH_OR_R0_R0, 0xffff },
158 { SH_OR_R0_R0, 0xffff },
159 { SH_OR_R0_R0, 0xffff },
160 { SH_OR_R0_R0, 0xffff },
161 { SH_NR_SIGRETURN, 0xffff },
163 },
165};
166
169 2,
170 {
171 { SH_MOVW, 0xffff },
172 { SH_TRAP, 0xff00 }, /* #imm argument part filtered out. */
173 { SH_OR_R0_R0, 0xffff },
174 { SH_OR_R0_R0, 0xffff },
175 { SH_OR_R0_R0, 0xffff },
176 { SH_OR_R0_R0, 0xffff },
177 { SH_OR_R0_R0, 0xffff },
178 { SH_NR_RT_SIGRETURN, 0xffff },
180 },
182};
183
184static void
186{
187 linux_init_abi (info, gdbarch, 0);
188
189 /* GNU/Linux uses SVR4-style shared libraries. */
194
197
198 sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
199
200 /* Remember regset characteristics. The sizes should match
201 elf_gregset_t and elf_fpregset_t from Linux. */
203 tdep->sizeof_gregset = 92;
205 tdep->sizeof_fpregset = 136;
206
209}
210
212void
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
@ SIGTRAMP_FRAME
Definition frame.h:198
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype *skip_trampoline_code)
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2037
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address)
int gdbarch_fp0_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2088
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype *skip_solib_resolver)
CORE_ADDR glibc_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition glibc-tdep.c:38
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)
@ R0_REGNUM
Definition m32r-tdep.h:34
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
void(* func)(remote_target *remote, char *)
#define SH_NR_SIGRETURN
static const struct sh_corefile_regmap fpregs_table[]
#define SH_NR_RT_SIGRETURN
static void sh_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
static struct tramp_frame sh_linux_rt_sigreturn_tramp_frame
static void sh_linux_sigreturn_init(const struct tramp_frame *self, frame_info_ptr this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
static struct tramp_frame sh_linux_sigreturn_tramp_frame
static void sh_linux_rt_sigreturn_init(const struct tramp_frame *self, frame_info_ptr this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
static const struct sh_corefile_regmap gregs_table[]
#define SH_TRAP
static void sh_linux_sigtramp_cache(frame_info_ptr this_frame, struct trad_frame_cache *this_cache, CORE_ADDR func, int regs_offset)
#define REGSx16(base)
#define SH_OR_R0_R0
#define SH_MOVW
void _initialize_sh_linux_tdep()
@ FP_LAST_REGNUM
Definition sh-tdep.h:47
@ FR0_REGNUM
Definition sh-tdep.h:44
@ MACL_REGNUM
Definition sh-tdep.h:39
@ SR_REGNUM
Definition sh-tdep.h:40
@ PR_REGNUM
Definition sh-tdep.h:35
@ FPSCR_REGNUM
Definition sh-tdep.h:43
@ GBR_REGNUM
Definition sh-tdep.h:36
@ MACH_REGNUM
Definition sh-tdep.h:38
@ PC_REGNUM
Definition sh-tdep.h:34
@ FPUL_REGNUM
Definition sh-tdep.h:41
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)
int sizeof_fpregset
Definition sh-tdep.h:105
struct sh_corefile_regmap * core_fpregmap
Definition sh-tdep.h:104
struct sh_corefile_regmap * core_gregmap
Definition sh-tdep.h:99
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