Re: nios2: Remove binutils support for Nios II target
[binutils-gdb.git] / gdb / sh-linux-tdep.c
blobaffbf550a505a742bdac590541e50bfbc5cdbc99
1 /* Target-dependent code for GNU/Linux Super-H.
3 Copyright (C) 2005-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "osabi.h"
22 #include "solib-svr4.h"
23 #include "symtab.h"
25 #include "trad-frame.h"
26 #include "tramp-frame.h"
28 #include "glibc-tdep.h"
29 #include "sh-tdep.h"
30 #include "linux-tdep.h"
31 #include "gdbarch.h"
33 #define REGSx16(base) \
34 {(base), 0}, \
35 {(base) + 1, 4}, \
36 {(base) + 2, 8}, \
37 {(base) + 3, 12}, \
38 {(base) + 4, 16}, \
39 {(base) + 5, 20}, \
40 {(base) + 6, 24}, \
41 {(base) + 7, 28}, \
42 {(base) + 8, 32}, \
43 {(base) + 9, 36}, \
44 {(base) + 10, 40}, \
45 {(base) + 11, 44}, \
46 {(base) + 12, 48}, \
47 {(base) + 13, 52}, \
48 {(base) + 14, 56}, \
49 {(base) + 15, 60}
51 /* Describe the contents of the .reg section of the core file. */
53 static const struct sh_corefile_regmap gregs_table[] =
55 REGSx16 (R0_REGNUM),
56 {PC_REGNUM, 64},
57 {PR_REGNUM, 68},
58 {SR_REGNUM, 72},
59 {GBR_REGNUM, 76},
60 {MACH_REGNUM, 80},
61 {MACL_REGNUM, 84},
62 {-1 /* Terminator. */, 0}
65 /* Describe the contents of the .reg2 section of the core file. */
67 static const struct sh_corefile_regmap fpregs_table[] =
69 REGSx16 (FR0_REGNUM),
70 /* REGSx16 xfp_regs omitted. */
71 {FPSCR_REGNUM, 128},
72 {FPUL_REGNUM, 132},
73 {-1 /* Terminator. */, 0}
76 /* SH signal handler frame support. */
78 static void
79 sh_linux_sigtramp_cache (const frame_info_ptr &this_frame,
80 struct trad_frame_cache *this_cache,
81 CORE_ADDR func, int regs_offset)
83 int i;
84 struct gdbarch *gdbarch = get_frame_arch (this_frame);
85 CORE_ADDR base = get_frame_register_unsigned (this_frame,
86 gdbarch_sp_regnum (gdbarch));
87 CORE_ADDR regs = base + regs_offset;
89 for (i = 0; i < 18; i++)
90 trad_frame_set_reg_addr (this_cache, i, regs + i * 4);
92 trad_frame_set_reg_addr (this_cache, SR_REGNUM, regs + 18 * 4);
93 trad_frame_set_reg_addr (this_cache, GBR_REGNUM, regs + 19 * 4);
94 trad_frame_set_reg_addr (this_cache, MACH_REGNUM, regs + 20 * 4);
95 trad_frame_set_reg_addr (this_cache, MACL_REGNUM, regs + 21 * 4);
97 /* Restore FP state if we have an FPU. */
98 if (gdbarch_fp0_regnum (gdbarch) != -1)
100 CORE_ADDR fpregs = regs + 22 * 4;
101 for (i = FR0_REGNUM; i <= FP_LAST_REGNUM; i++)
102 trad_frame_set_reg_addr (this_cache, i, fpregs + i * 4);
103 trad_frame_set_reg_addr (this_cache, FPSCR_REGNUM, fpregs + 32 * 4);
104 trad_frame_set_reg_addr (this_cache, FPUL_REGNUM, fpregs + 33 * 4);
107 /* Save a frame ID. */
108 trad_frame_set_id (this_cache, frame_id_build (base, func));
111 /* Implement struct tramp_frame "init" callbacks for signal
112 trampolines on 32-bit SH. */
114 static void
115 sh_linux_sigreturn_init (const struct tramp_frame *self,
116 const frame_info_ptr &this_frame,
117 struct trad_frame_cache *this_cache,
118 CORE_ADDR func)
120 /* SH 32-bit sigframe: sigcontext at start of sigframe,
121 registers start after a single 'oldmask' word. */
122 sh_linux_sigtramp_cache (this_frame, this_cache, func, 4);
125 static void
126 sh_linux_rt_sigreturn_init (const struct tramp_frame *self,
127 const frame_info_ptr &this_frame,
128 struct trad_frame_cache *this_cache,
129 CORE_ADDR func)
131 /* SH 32-bit rt_sigframe: starts with a siginfo (128 bytes), then
132 we can find sigcontext embedded within a ucontext (offset 20 bytes).
133 Then registers start after a single 'oldmask' word. */
134 sh_linux_sigtramp_cache (this_frame, this_cache, func,
135 128 /* sizeof (struct siginfo) */
136 + 20 /* offsetof (struct ucontext, uc_mcontext) */
137 + 4 /* oldmask word at start of sigcontext */);
140 /* Instruction patterns. */
141 #define SH_MOVW 0x9305
142 #define SH_TRAP 0xc300
143 #define SH_OR_R0_R0 0x200b
145 /* SH sigreturn syscall numbers. */
146 #define SH_NR_SIGRETURN 0x0077
147 #define SH_NR_RT_SIGRETURN 0x00ad
149 static struct tramp_frame sh_linux_sigreturn_tramp_frame = {
150 SIGTRAMP_FRAME,
153 { SH_MOVW, 0xffff },
154 { SH_TRAP, 0xff00 }, /* #imm argument part filtered out. */
155 { SH_OR_R0_R0, 0xffff },
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_NR_SIGRETURN, 0xffff },
161 { TRAMP_SENTINEL_INSN }
163 sh_linux_sigreturn_init
166 static struct tramp_frame sh_linux_rt_sigreturn_tramp_frame = {
167 SIGTRAMP_FRAME,
170 { SH_MOVW, 0xffff },
171 { SH_TRAP, 0xff00 }, /* #imm argument part filtered out. */
172 { SH_OR_R0_R0, 0xffff },
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_NR_RT_SIGRETURN, 0xffff },
178 { TRAMP_SENTINEL_INSN }
180 sh_linux_rt_sigreturn_init
183 static void
184 sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
186 linux_init_abi (info, gdbarch, 0);
188 /* GNU/Linux uses SVR4-style shared libraries. */
189 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
190 set_solib_svr4_fetch_link_map_offsets
191 (gdbarch, linux_ilp32_fetch_link_map_offsets);
192 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
194 set_gdbarch_fetch_tls_load_module_address (gdbarch,
195 svr4_fetch_objfile_link_map);
197 sh_gdbarch_tdep *tdep = gdbarch_tdep<sh_gdbarch_tdep> (gdbarch);
199 /* Remember regset characteristics. The sizes should match
200 elf_gregset_t and elf_fpregset_t from Linux. */
201 tdep->core_gregmap = (struct sh_corefile_regmap *) gregs_table;
202 tdep->sizeof_gregset = 92;
203 tdep->core_fpregmap = (struct sh_corefile_regmap *) fpregs_table;
204 tdep->sizeof_fpregset = 136;
206 tramp_frame_prepend_unwinder (gdbarch, &sh_linux_sigreturn_tramp_frame);
207 tramp_frame_prepend_unwinder (gdbarch, &sh_linux_rt_sigreturn_tramp_frame);
210 void _initialize_sh_linux_tdep ();
211 void
212 _initialize_sh_linux_tdep ()
214 gdbarch_register_osabi (bfd_arch_sh, 0, GDB_OSABI_LINUX, sh_linux_init_abi);