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