Update comments to TERNOP_SLICE
[deliverable/binutils-gdb.git] / gdb / ppcfbsd-tdep.c
1 /* Target-dependent code for PowerPC systems running FreeBSD.
2
3 Copyright (C) 2013-2014 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 "arch-utils.h"
22 #include "frame.h"
23 #include "gdbcore.h"
24 #include "frame-unwind.h"
25 #include "gdbtypes.h"
26 #include "osabi.h"
27 #include "regcache.h"
28 #include "regset.h"
29 #include "symtab.h"
30 #include "target.h"
31 #include "trad-frame.h"
32
33 #include "gdb_assert.h"
34 #include <string.h>
35
36 #include "ppc-tdep.h"
37 #include "ppc64-tdep.h"
38 #include "ppcfbsd-tdep.h"
39 #include "solib-svr4.h"
40
41
42 /* 32-bit regset descriptions. */
43
44 static const struct ppc_reg_offsets ppc32_fbsd_reg_offsets =
45 {
46 /* General-purpose registers. */
47 /* .r0_offset = */ 0,
48 /* .gpr_size = */ 4,
49 /* .xr_size = */ 4,
50 /* .pc_offset = */ 144,
51 /* .ps_offset = */ -1,
52 /* .cr_offset = */ 132,
53 /* .lr_offset = */ 128,
54 /* .ctr_offset = */ 140,
55 /* .xer_offset = */ 136,
56 /* .mq_offset = */ -1,
57
58 /* Floating-point registers. */
59 /* .f0_offset = */ 0,
60 /* .fpscr_offset = */ 256,
61 /* .fpscr_size = */ 8,
62 #ifdef NOTYET
63 /* AltiVec registers. */
64 /* .vr0_offset = */ 0,
65 /* .vscr_offset = */ 512 + 12,
66 /* .vrsave_offset = */ 512
67 #endif
68 };
69
70 /* 64-bit regset descriptions. */
71
72 static const struct ppc_reg_offsets ppc64_fbsd_reg_offsets =
73 {
74 /* General-purpose registers. */
75 /* .r0_offset = */ 0,
76 /* .gpr_size = */ 8,
77 /* .xr_size = */ 8,
78 /* .pc_offset = */ 288,
79 /* .ps_offset = */ -1,
80 /* .cr_offset = */ 264,
81 /* .lr_offset = */ 256,
82 /* .ctr_offset = */ 280,
83 /* .xer_offset = */ 272,
84 /* .mq_offset = */ -1,
85
86 /* Floating-point registers. */
87 /* .f0_offset = */ 0,
88 /* .fpscr_offset = */ 256,
89 /* .fpscr_size = */ 8,
90 #ifdef NOYET
91 /* AltiVec registers. */
92 /* .vr0_offset = */ 0,
93 /* .vscr_offset = */ 512 + 12,
94 /* .vrsave_offset = */ 528
95 #endif
96 };
97
98 /* 32-bit general-purpose register set. */
99
100 static const struct regset ppc32_fbsd_gregset = {
101 &ppc32_fbsd_reg_offsets,
102 ppc_supply_gregset,
103 ppc_collect_gregset
104 };
105
106 /* 64-bit general-purpose register set. */
107
108 static const struct regset ppc64_fbsd_gregset = {
109 &ppc64_fbsd_reg_offsets,
110 ppc_supply_gregset,
111 ppc_collect_gregset
112 };
113
114 /* 32-/64-bit floating-point register set. */
115
116 static const struct regset ppc32_fbsd_fpregset = {
117 &ppc32_fbsd_reg_offsets,
118 ppc_supply_fpregset,
119 ppc_collect_fpregset
120 };
121
122 const struct regset *
123 ppc_fbsd_gregset (int wordsize)
124 {
125 return wordsize == 8 ? &ppc64_fbsd_gregset : &ppc32_fbsd_gregset;
126 }
127
128 const struct regset *
129 ppc_fbsd_fpregset (void)
130 {
131 return &ppc32_fbsd_fpregset;
132 }
133
134 /* Return the appropriate register set for the core section identified
135 by SECT_NAME and SECT_SIZE. */
136
137 static const struct regset *
138 ppcfbsd_regset_from_core_section (struct gdbarch *gdbarch,
139 const char *sect_name, size_t sect_size)
140 {
141 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
142 if (strcmp (sect_name, ".reg") == 0 && sect_size >= 148)
143 {
144 if (tdep->wordsize == 4)
145 return &ppc32_fbsd_gregset;
146 else
147 return &ppc64_fbsd_gregset;
148 }
149 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 264)
150 return &ppc32_fbsd_fpregset;
151 return NULL;
152 }
153
154 /* Default page size. */
155
156 static const int ppcfbsd_page_size = 4096;
157
158 /* Offset for sigreturn(2). */
159
160 static const int ppcfbsd_sigreturn_offset[] = {
161 0xc, /* FreeBSD 32-bit */
162 -1
163 };
164
165 /* Signal trampolines. */
166
167 static int
168 ppcfbsd_sigtramp_frame_sniffer (const struct frame_unwind *self,
169 struct frame_info *this_frame,
170 void **this_cache)
171 {
172 struct gdbarch *gdbarch = get_frame_arch (this_frame);
173 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
174 CORE_ADDR pc = get_frame_pc (this_frame);
175 CORE_ADDR start_pc = (pc & ~(ppcfbsd_page_size - 1));
176 const int *offset;
177 const char *name;
178
179 /* A stack trampoline is detected if no name is associated
180 to the current pc and if it points inside a trampoline
181 sequence. */
182
183 find_pc_partial_function (pc, &name, NULL, NULL);
184
185 /* If we have a name, we have no trampoline, return. */
186 if (name)
187 return 0;
188
189 for (offset = ppcfbsd_sigreturn_offset; *offset != -1; offset++)
190 {
191 gdb_byte buf[2 * PPC_INSN_SIZE];
192 unsigned long insn;
193
194 if (!safe_frame_unwind_memory (this_frame, start_pc + *offset,
195 buf, sizeof buf))
196 continue;
197
198 /* Check for "li r0,SYS_sigreturn". */
199 insn = extract_unsigned_integer (buf, PPC_INSN_SIZE, byte_order);
200 if (insn != 0x380001a1)
201 continue;
202
203 /* Check for "sc". */
204 insn = extract_unsigned_integer (buf + PPC_INSN_SIZE,
205 PPC_INSN_SIZE, byte_order);
206 if (insn != 0x44000002)
207 continue;
208
209 return 1;
210 }
211
212 return 0;
213 }
214
215 static struct trad_frame_cache *
216 ppcfbsd_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
217 {
218 struct gdbarch *gdbarch = get_frame_arch (this_frame);
219 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
220 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
221 struct trad_frame_cache *cache;
222 CORE_ADDR addr, base, func;
223 gdb_byte buf[PPC_INSN_SIZE];
224 int i;
225
226 if (*this_cache)
227 return *this_cache;
228
229 cache = trad_frame_cache_zalloc (this_frame);
230 *this_cache = cache;
231
232 func = get_frame_pc (this_frame);
233 func &= ~(ppcfbsd_page_size - 1);
234 if (!safe_frame_unwind_memory (this_frame, func, buf, sizeof buf))
235 return cache;
236
237 base = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch));
238 addr = base + 0x10 + 2 * tdep->wordsize;
239 for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize)
240 {
241 int regnum = i + tdep->ppc_gp0_regnum;
242 trad_frame_set_reg_addr (cache, regnum, addr);
243 }
244 trad_frame_set_reg_addr (cache, tdep->ppc_lr_regnum, addr);
245 addr += tdep->wordsize;
246 trad_frame_set_reg_addr (cache, tdep->ppc_cr_regnum, addr);
247 addr += tdep->wordsize;
248 trad_frame_set_reg_addr (cache, tdep->ppc_xer_regnum, addr);
249 addr += tdep->wordsize;
250 trad_frame_set_reg_addr (cache, tdep->ppc_ctr_regnum, addr);
251 addr += tdep->wordsize;
252 trad_frame_set_reg_addr (cache, gdbarch_pc_regnum (gdbarch), addr);
253 /* SRR0? */
254 addr += tdep->wordsize;
255
256 /* Construct the frame ID using the function start. */
257 trad_frame_set_id (cache, frame_id_build (base, func));
258
259 return cache;
260 }
261
262 static void
263 ppcfbsd_sigtramp_frame_this_id (struct frame_info *this_frame,
264 void **this_cache, struct frame_id *this_id)
265 {
266 struct trad_frame_cache *cache =
267 ppcfbsd_sigtramp_frame_cache (this_frame, this_cache);
268
269 trad_frame_get_id (cache, this_id);
270 }
271
272 static struct value *
273 ppcfbsd_sigtramp_frame_prev_register (struct frame_info *this_frame,
274 void **this_cache, int regnum)
275 {
276 struct trad_frame_cache *cache =
277 ppcfbsd_sigtramp_frame_cache (this_frame, this_cache);
278
279 return trad_frame_get_register (cache, this_frame, regnum);
280 }
281
282 static const struct frame_unwind ppcfbsd_sigtramp_frame_unwind = {
283 SIGTRAMP_FRAME,
284 default_frame_unwind_stop_reason,
285 ppcfbsd_sigtramp_frame_this_id,
286 ppcfbsd_sigtramp_frame_prev_register,
287 NULL,
288 ppcfbsd_sigtramp_frame_sniffer
289 };
290
291 static enum return_value_convention
292 ppcfbsd_return_value (struct gdbarch *gdbarch, struct value *function,
293 struct type *valtype, struct regcache *regcache,
294 gdb_byte *readbuf, const gdb_byte *writebuf)
295 {
296 return ppc_sysv_abi_broken_return_value (gdbarch, function, valtype,
297 regcache, readbuf, writebuf);
298 }
299
300
301 static void
302 ppcfbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
303 {
304 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
305
306 /* FreeBSD doesn't support the 128-bit `long double' from the psABI. */
307 set_gdbarch_long_double_bit (gdbarch, 64);
308 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
309
310 if (tdep->wordsize == 4)
311 {
312 set_gdbarch_return_value (gdbarch, ppcfbsd_return_value);
313
314 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
315 set_solib_svr4_fetch_link_map_offsets (gdbarch,
316 svr4_ilp32_fetch_link_map_offsets);
317
318 frame_unwind_append_unwinder (gdbarch, &ppcfbsd_sigtramp_frame_unwind);
319 set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
320 }
321
322 if (tdep->wordsize == 8)
323 {
324 set_gdbarch_convert_from_func_ptr_addr
325 (gdbarch, ppc64_convert_from_func_ptr_addr);
326 set_gdbarch_elf_make_msymbol_special (gdbarch,
327 ppc64_elf_make_msymbol_special);
328
329 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
330 set_solib_svr4_fetch_link_map_offsets (gdbarch,
331 svr4_lp64_fetch_link_map_offsets);
332 set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
333 }
334
335 set_gdbarch_regset_from_core_section
336 (gdbarch, ppcfbsd_regset_from_core_section);
337
338 set_gdbarch_fetch_tls_load_module_address (gdbarch,
339 svr4_fetch_objfile_link_map);
340 }
341
342 /* Provide a prototype to silence -Wmissing-prototypes. */
343
344 void _initialize_ppcfbsd_tdep (void);
345
346 void
347 _initialize_ppcfbsd_tdep (void)
348 {
349 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_FREEBSD_ELF,
350 ppcfbsd_init_abi);
351 gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64,
352 GDB_OSABI_FREEBSD_ELF,
353 ppcfbsd_init_abi);
354 gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_FREEBSD_ELF,
355 ppcfbsd_init_abi);
356 }
This page took 0.036916 seconds and 4 git commands to generate.