Introduce ref_ptr::new_reference
[deliverable/binutils-gdb.git] / gdb / sh-linux-tdep.c
1 /* Target-dependent code for GNU/Linux Super-H.
2
3 Copyright (C) 2005-2018 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
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}
50
51 /* Describe the contents of the .reg section of the core file. */
52
53 static const struct sh_corefile_regmap gregs_table[] =
54 {
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}
63 };
64
65 /* Describe the contents of the .reg2 section of the core file. */
66
67 static const struct sh_corefile_regmap fpregs_table[] =
68 {
69 REGSx16 (FR0_REGNUM),
70 /* REGSx16 xfp_regs omitted. */
71 {FPSCR_REGNUM, 128},
72 {FPUL_REGNUM, 132},
73 {-1 /* Terminator. */, 0}
74 };
75
76 /* SH signal handler frame support. */
77
78 static void
79 sh_linux_sigtramp_cache (struct frame_info *this_frame,
80 struct trad_frame_cache *this_cache,
81 CORE_ADDR func, int regs_offset)
82 {
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;
88
89 for (i = 0; i < 18; i++)
90 trad_frame_set_reg_addr (this_cache, i, regs + i * 4);
91
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);
96
97 /* Restore FP state if we have an FPU. */
98 if (gdbarch_fp0_regnum (gdbarch) != -1)
99 {
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);
105 }
106
107 /* Save a frame ID. */
108 trad_frame_set_id (this_cache, frame_id_build (base, func));
109 }
110
111 /* Implement struct tramp_frame "init" callbacks for signal
112 trampolines on 32-bit SH. */
113
114 static void
115 sh_linux_sigreturn_init (const struct tramp_frame *self,
116 struct frame_info *this_frame,
117 struct trad_frame_cache *this_cache,
118 CORE_ADDR func)
119 {
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);
123 }
124
125 static void
126 sh_linux_rt_sigreturn_init (const struct tramp_frame *self,
127 struct frame_info *this_frame,
128 struct trad_frame_cache *this_cache,
129 CORE_ADDR func)
130 {
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 */);
138 }
139
140 /* Instruction patterns. */
141 #define SH_MOVW 0x9305
142 #define SH_TRAP 0xc300
143 #define SH_OR_R0_R0 0x200b
144
145 /* SH sigreturn syscall numbers. */
146 #define SH_NR_SIGRETURN 0x0077
147 #define SH_NR_RT_SIGRETURN 0x00ad
148
149 static struct tramp_frame sh_linux_sigreturn_tramp_frame = {
150 SIGTRAMP_FRAME,
151 2,
152 {
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 }
162 },
163 sh_linux_sigreturn_init
164 };
165
166 static struct tramp_frame sh_linux_rt_sigreturn_tramp_frame = {
167 SIGTRAMP_FRAME,
168 2,
169 {
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 }
179 },
180 sh_linux_rt_sigreturn_init
181 };
182
183 static void
184 sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
185 {
186 linux_init_abi (info, gdbarch);
187
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, svr4_ilp32_fetch_link_map_offsets);
192 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
193
194 set_gdbarch_fetch_tls_load_module_address (gdbarch,
195 svr4_fetch_objfile_link_map);
196
197 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
198
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;
205
206 tramp_frame_prepend_unwinder (gdbarch, &sh_linux_sigreturn_tramp_frame);
207 tramp_frame_prepend_unwinder (gdbarch, &sh_linux_rt_sigreturn_tramp_frame);
208 }
209
210 void
211 _initialize_sh_linux_tdep (void)
212 {
213 gdbarch_register_osabi (bfd_arch_sh, 0, GDB_OSABI_LINUX, sh_linux_init_abi);
214 }
This page took 0.034583 seconds and 4 git commands to generate.