PR binutils/13558
[deliverable/binutils-gdb.git] / gdb / ppcnbsd-tdep.c
CommitLineData
def18405 1/* Target-dependent code for NetBSD/powerpc.
476be15e 2
0b302171 3 Copyright (C) 2002-2012 Free Software Foundation, Inc.
476be15e 4
485721b1
JT
5 Contributed by Wasabi Systems, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
485721b1
JT
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
485721b1
JT
21
22#include "defs.h"
def18405 23#include "gdbtypes.h"
4be87837 24#include "osabi.h"
def18405
MK
25#include "regcache.h"
26#include "regset.h"
27#include "trad-frame.h"
28#include "tramp-frame.h"
29
30#include "gdb_assert.h"
31#include "gdb_string.h"
485721b1
JT
32
33#include "ppc-tdep.h"
34#include "ppcnbsd-tdep.h"
485721b1
JT
35#include "solib-svr4.h"
36
def18405
MK
37/* Register offsets from <machine/reg.h>. */
38struct ppc_reg_offsets ppcnbsd_reg_offsets;
39\f
485721b1 40
def18405 41/* Core file support. */
485721b1 42
1e17aef8 43/* NetBSD/powerpc register sets. */
485721b1 44
def18405 45struct regset ppcnbsd_gregset =
485721b1 46{
def18405
MK
47 &ppcnbsd_reg_offsets,
48 ppc_supply_gregset
49};
485721b1 50
def18405 51struct regset ppcnbsd_fpregset =
485721b1 52{
def18405
MK
53 &ppcnbsd_reg_offsets,
54 ppc_supply_fpregset
55};
485721b1 56
def18405
MK
57/* Return the appropriate register set for the core section identified
58 by SECT_NAME and SECT_SIZE. */
485721b1 59
def18405
MK
60static const struct regset *
61ppcnbsd_regset_from_core_section (struct gdbarch *gdbarch,
62 const char *sect_name, size_t sect_size)
485721b1 63{
def18405
MK
64 if (strcmp (sect_name, ".reg") == 0 && sect_size >= 148)
65 return &ppcnbsd_gregset;
485721b1 66
def18405
MK
67 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 264)
68 return &ppcnbsd_fpregset;
485721b1 69
def18405 70 return NULL;
485721b1 71}
def18405 72\f
485721b1 73
def18405 74/* NetBSD is confused. It appears that 1.5 was using the correct SVR4
957e27ac 75 convention but, 1.6 switched to the below broken convention. For
0df8b418 76 the moment use the broken convention. Ulgh! */
957e27ac 77
05580c65 78static enum return_value_convention
c055b101
CV
79ppcnbsd_return_value (struct gdbarch *gdbarch, struct type *func_type,
80 struct type *valtype, struct regcache *regcache,
81 gdb_byte *readbuf, const gdb_byte *writebuf)
05580c65 82{
def18405 83#if 0
05580c65
AC
84 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
85 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
86 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
87 && TYPE_VECTOR (valtype))
88 && !(TYPE_LENGTH (valtype) == 1
89 || TYPE_LENGTH (valtype) == 2
90 || TYPE_LENGTH (valtype) == 4
91 || TYPE_LENGTH (valtype) == 8))
92 return RETURN_VALUE_STRUCT_CONVENTION;
93 else
def18405 94#endif
c055b101
CV
95 return ppc_sysv_abi_broken_return_value (gdbarch, func_type, valtype,
96 regcache, readbuf, writebuf);
957e27ac 97}
def18405
MK
98\f
99
100/* Signal trampolines. */
101
102static const struct tramp_frame ppcnbsd2_sigtramp;
957e27ac 103
476be15e
AC
104static void
105ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
5366653e 106 struct frame_info *this_frame,
476be15e
AC
107 struct trad_frame_cache *this_cache,
108 CORE_ADDR func)
109{
5366653e 110 struct gdbarch *gdbarch = get_frame_arch (this_frame);
476be15e 111 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
def18405
MK
112 CORE_ADDR addr, base;
113 int i;
476be15e 114
5366653e
DJ
115 base = get_frame_register_unsigned (this_frame,
116 gdbarch_sp_regnum (gdbarch));
def18405
MK
117 if (self == &ppcnbsd2_sigtramp)
118 addr = base + 0x10 + 2 * tdep->wordsize;
119 else
120 addr = base + 0x18 + 2 * tdep->wordsize;
121 for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize)
476be15e
AC
122 {
123 int regnum = i + tdep->ppc_gp0_regnum;
def18405 124 trad_frame_set_reg_addr (this_cache, regnum, addr);
476be15e 125 }
def18405
MK
126 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, addr);
127 addr += tdep->wordsize;
128 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, addr);
129 addr += tdep->wordsize;
130 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, addr);
131 addr += tdep->wordsize;
132 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, addr);
133 addr += tdep->wordsize;
40a6adc1 134 trad_frame_set_reg_addr (this_cache, gdbarch_pc_regnum (gdbarch),
0df8b418 135 addr); /* SRR0? */
def18405 136 addr += tdep->wordsize;
476be15e
AC
137
138 /* Construct the frame ID using the function start. */
139 trad_frame_set_id (this_cache, frame_id_build (base, func));
140}
141
def18405
MK
142static const struct tramp_frame ppcnbsd_sigtramp =
143{
144 SIGTRAMP_FRAME,
145 4,
146 {
147 { 0x3821fff0, -1 }, /* add r1,r1,-16 */
148 { 0x4e800021, -1 }, /* blrl */
149 { 0x38610018, -1 }, /* addi r3,r1,24 */
150 { 0x38000127, -1 }, /* li r0,295 */
151 { 0x44000002, -1 }, /* sc */
152 { 0x38000001, -1 }, /* li r0,1 */
153 { 0x44000002, -1 }, /* sc */
154 { TRAMP_SENTINEL_INSN, -1 }
155 },
156 ppcnbsd_sigtramp_cache_init
157};
158
159/* NetBSD 2.0 introduced a slightly different signal trampoline. */
476be15e 160
def18405
MK
161static const struct tramp_frame ppcnbsd2_sigtramp =
162{
2cd8546d 163 SIGTRAMP_FRAME,
def18405
MK
164 4,
165 {
166 { 0x3821fff0, -1 }, /* add r1,r1,-16 */
167 { 0x4e800021, -1 }, /* blrl */
168 { 0x38610010, -1 }, /* addi r3,r1,16 */
169 { 0x38000127, -1 }, /* li r0,295 */
170 { 0x44000002, -1 }, /* sc */
171 { 0x38000001, -1 }, /* li r0,1 */
172 { 0x44000002, -1 }, /* sc */
2cd8546d 173 { TRAMP_SENTINEL_INSN, -1 }
476be15e
AC
174 },
175 ppcnbsd_sigtramp_cache_init
176};
def18405 177\f
476be15e 178
485721b1
JT
179static void
180ppcnbsd_init_abi (struct gdbarch_info info,
181 struct gdbarch *gdbarch)
182{
e754ae69
AC
183 /* For NetBSD, this is an on again, off again thing. Some systems
184 do use the broken struct convention, and some don't. */
05580c65 185 set_gdbarch_return_value (gdbarch, ppcnbsd_return_value);
def18405
MK
186
187 /* NetBSD uses SVR4-style shared libraries. */
188 set_solib_svr4_fetch_link_map_offsets
189 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
190
191 set_gdbarch_regset_from_core_section
192 (gdbarch, ppcnbsd_regset_from_core_section);
193
476be15e 194 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp);
def18405 195 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp);
485721b1 196}
def18405
MK
197\f
198
199/* Provide a prototype to silence -Wmissing-prototypes. */
200void _initialize_ppcnbsd_tdep (void);
485721b1
JT
201
202void
203_initialize_ppcnbsd_tdep (void)
204{
05816f70 205 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD_ELF,
485721b1
JT
206 ppcnbsd_init_abi);
207
def18405
MK
208 /* Avoid initializing the register offsets again if they were
209 already initailized by ppcnbsd-nat.c. */
210 if (ppcnbsd_reg_offsets.pc_offset == 0)
211 {
212 /* General-purpose registers. */
213 ppcnbsd_reg_offsets.r0_offset = 0;
f2db237a
AM
214 ppcnbsd_reg_offsets.gpr_size = 4;
215 ppcnbsd_reg_offsets.xr_size = 4;
def18405
MK
216 ppcnbsd_reg_offsets.lr_offset = 128;
217 ppcnbsd_reg_offsets.cr_offset = 132;
218 ppcnbsd_reg_offsets.xer_offset = 136;
219 ppcnbsd_reg_offsets.ctr_offset = 140;
220 ppcnbsd_reg_offsets.pc_offset = 144;
221 ppcnbsd_reg_offsets.ps_offset = -1;
222 ppcnbsd_reg_offsets.mq_offset = -1;
223
224 /* Floating-point registers. */
225 ppcnbsd_reg_offsets.f0_offset = 0;
226 ppcnbsd_reg_offsets.fpscr_offset = 256;
f2db237a 227 ppcnbsd_reg_offsets.fpscr_size = 4;
def18405
MK
228
229 /* AltiVec registers. */
230 ppcnbsd_reg_offsets.vr0_offset = 0;
231 ppcnbsd_reg_offsets.vrsave_offset = 512;
232 ppcnbsd_reg_offsets.vscr_offset = 524;
233 }
485721b1 234}
This page took 1.251693 seconds and 4 git commands to generate.