*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / ppcnbsd-tdep.c
1 /* Target-dependent code for NetBSD/powerpc.
2
3 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
5
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
12 the Free Software Foundation; either version 2 of the License, or
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
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
24
25 #include "defs.h"
26 #include "gdbtypes.h"
27 #include "osabi.h"
28 #include "regcache.h"
29 #include "regset.h"
30 #include "trad-frame.h"
31 #include "tramp-frame.h"
32
33 #include "gdb_assert.h"
34 #include "gdb_string.h"
35
36 #include "ppc-tdep.h"
37 #include "ppcnbsd-tdep.h"
38 #include "solib-svr4.h"
39
40 /* Register offsets from <machine/reg.h>. */
41 struct ppc_reg_offsets ppcnbsd_reg_offsets;
42 \f
43
44 /* Core file support. */
45
46 /* NetBSD/powerpc register sets. */
47
48 struct regset ppcnbsd_gregset =
49 {
50 &ppcnbsd_reg_offsets,
51 ppc_supply_gregset
52 };
53
54 struct regset ppcnbsd_fpregset =
55 {
56 &ppcnbsd_reg_offsets,
57 ppc_supply_fpregset
58 };
59
60 /* Return the appropriate register set for the core section identified
61 by SECT_NAME and SECT_SIZE. */
62
63 static const struct regset *
64 ppcnbsd_regset_from_core_section (struct gdbarch *gdbarch,
65 const char *sect_name, size_t sect_size)
66 {
67 if (strcmp (sect_name, ".reg") == 0 && sect_size >= 148)
68 return &ppcnbsd_gregset;
69
70 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 264)
71 return &ppcnbsd_fpregset;
72
73 return NULL;
74 }
75 \f
76
77 /* NetBSD is confused. It appears that 1.5 was using the correct SVR4
78 convention but, 1.6 switched to the below broken convention. For
79 the moment use the broken convention. Ulgh!. */
80
81 static enum return_value_convention
82 ppcnbsd_return_value (struct gdbarch *gdbarch, struct type *valtype,
83 struct regcache *regcache, gdb_byte *readbuf,
84 const gdb_byte *writebuf)
85 {
86 #if 0
87 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
88 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
89 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
90 && TYPE_VECTOR (valtype))
91 && !(TYPE_LENGTH (valtype) == 1
92 || TYPE_LENGTH (valtype) == 2
93 || TYPE_LENGTH (valtype) == 4
94 || TYPE_LENGTH (valtype) == 8))
95 return RETURN_VALUE_STRUCT_CONVENTION;
96 else
97 #endif
98 return ppc_sysv_abi_broken_return_value (gdbarch, valtype, regcache,
99 readbuf, writebuf);
100 }
101 \f
102
103 /* Signal trampolines. */
104
105 static const struct tramp_frame ppcnbsd2_sigtramp;
106
107 static void
108 ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
109 struct frame_info *next_frame,
110 struct trad_frame_cache *this_cache,
111 CORE_ADDR func)
112 {
113 struct gdbarch *gdbarch = get_frame_arch (next_frame);
114 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
115 CORE_ADDR addr, base;
116 int i;
117
118 base = frame_unwind_register_unsigned (next_frame,
119 gdbarch_sp_regnum (current_gdbarch));
120 if (self == &ppcnbsd2_sigtramp)
121 addr = base + 0x10 + 2 * tdep->wordsize;
122 else
123 addr = base + 0x18 + 2 * tdep->wordsize;
124 for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize)
125 {
126 int regnum = i + tdep->ppc_gp0_regnum;
127 trad_frame_set_reg_addr (this_cache, regnum, addr);
128 }
129 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, addr);
130 addr += tdep->wordsize;
131 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, addr);
132 addr += tdep->wordsize;
133 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, addr);
134 addr += tdep->wordsize;
135 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, addr);
136 addr += tdep->wordsize;
137 trad_frame_set_reg_addr (this_cache,
138 gdbarch_pc_regnum (current_gdbarch),
139 addr); /* SRR0? */
140 addr += tdep->wordsize;
141
142 /* Construct the frame ID using the function start. */
143 trad_frame_set_id (this_cache, frame_id_build (base, func));
144 }
145
146 static const struct tramp_frame ppcnbsd_sigtramp =
147 {
148 SIGTRAMP_FRAME,
149 4,
150 {
151 { 0x3821fff0, -1 }, /* add r1,r1,-16 */
152 { 0x4e800021, -1 }, /* blrl */
153 { 0x38610018, -1 }, /* addi r3,r1,24 */
154 { 0x38000127, -1 }, /* li r0,295 */
155 { 0x44000002, -1 }, /* sc */
156 { 0x38000001, -1 }, /* li r0,1 */
157 { 0x44000002, -1 }, /* sc */
158 { TRAMP_SENTINEL_INSN, -1 }
159 },
160 ppcnbsd_sigtramp_cache_init
161 };
162
163 /* NetBSD 2.0 introduced a slightly different signal trampoline. */
164
165 static const struct tramp_frame ppcnbsd2_sigtramp =
166 {
167 SIGTRAMP_FRAME,
168 4,
169 {
170 { 0x3821fff0, -1 }, /* add r1,r1,-16 */
171 { 0x4e800021, -1 }, /* blrl */
172 { 0x38610010, -1 }, /* addi r3,r1,16 */
173 { 0x38000127, -1 }, /* li r0,295 */
174 { 0x44000002, -1 }, /* sc */
175 { 0x38000001, -1 }, /* li r0,1 */
176 { 0x44000002, -1 }, /* sc */
177 { TRAMP_SENTINEL_INSN, -1 }
178 },
179 ppcnbsd_sigtramp_cache_init
180 };
181 \f
182
183 static void
184 ppcnbsd_init_abi (struct gdbarch_info info,
185 struct gdbarch *gdbarch)
186 {
187 /* For NetBSD, this is an on again, off again thing. Some systems
188 do use the broken struct convention, and some don't. */
189 set_gdbarch_return_value (gdbarch, ppcnbsd_return_value);
190
191 /* NetBSD uses SVR4-style shared libraries. */
192 set_solib_svr4_fetch_link_map_offsets
193 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
194
195 set_gdbarch_regset_from_core_section
196 (gdbarch, ppcnbsd_regset_from_core_section);
197
198 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp);
199 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp);
200 }
201 \f
202
203 /* Provide a prototype to silence -Wmissing-prototypes. */
204 void _initialize_ppcnbsd_tdep (void);
205
206 void
207 _initialize_ppcnbsd_tdep (void)
208 {
209 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD_ELF,
210 ppcnbsd_init_abi);
211
212 /* Avoid initializing the register offsets again if they were
213 already initailized by ppcnbsd-nat.c. */
214 if (ppcnbsd_reg_offsets.pc_offset == 0)
215 {
216 /* General-purpose registers. */
217 ppcnbsd_reg_offsets.r0_offset = 0;
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;
229
230 /* AltiVec registers. */
231 ppcnbsd_reg_offsets.vr0_offset = 0;
232 ppcnbsd_reg_offsets.vrsave_offset = 512;
233 ppcnbsd_reg_offsets.vscr_offset = 524;
234 }
235 }
This page took 0.033046 seconds and 4 git commands to generate.