*** 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 Free Software Foundation, Inc.
4
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
11 the Free Software Foundation; either version 2 of the License, or
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
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
23
24 #include "defs.h"
25 #include "gdbtypes.h"
26 #include "osabi.h"
27 #include "regcache.h"
28 #include "regset.h"
29 #include "trad-frame.h"
30 #include "tramp-frame.h"
31
32 #include "gdb_assert.h"
33 #include "gdb_string.h"
34
35 #include "ppc-tdep.h"
36 #include "ppcnbsd-tdep.h"
37 #include "solib-svr4.h"
38
39 /* Register offsets from <machine/reg.h>. */
40 struct ppc_reg_offsets ppcnbsd_reg_offsets;
41 \f
42
43 /* Core file support. */
44
45 /* NetBSD/powerpc register set. */
46
47 struct regset ppcnbsd_gregset =
48 {
49 &ppcnbsd_reg_offsets,
50 ppc_supply_gregset
51 };
52
53 struct regset ppcnbsd_fpregset =
54 {
55 &ppcnbsd_reg_offsets,
56 ppc_supply_fpregset
57 };
58
59 /* Return the appropriate register set for the core section identified
60 by SECT_NAME and SECT_SIZE. */
61
62 static const struct regset *
63 ppcnbsd_regset_from_core_section (struct gdbarch *gdbarch,
64 const char *sect_name, size_t sect_size)
65 {
66 if (strcmp (sect_name, ".reg") == 0 && sect_size >= 148)
67 return &ppcnbsd_gregset;
68
69 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= 264)
70 return &ppcnbsd_fpregset;
71
72 return NULL;
73 }
74 \f
75
76 /* NetBSD is confused. It appears that 1.5 was using the correct SVR4
77 convention but, 1.6 switched to the below broken convention. For
78 the moment use the broken convention. Ulgh!. */
79
80 static enum return_value_convention
81 ppcnbsd_return_value (struct gdbarch *gdbarch, struct type *valtype,
82 struct regcache *regcache, gdb_byte *readbuf,
83 const gdb_byte *writebuf)
84 {
85 #if 0
86 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
87 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
88 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
89 && TYPE_VECTOR (valtype))
90 && !(TYPE_LENGTH (valtype) == 1
91 || TYPE_LENGTH (valtype) == 2
92 || TYPE_LENGTH (valtype) == 4
93 || TYPE_LENGTH (valtype) == 8))
94 return RETURN_VALUE_STRUCT_CONVENTION;
95 else
96 #endif
97 return ppc_sysv_abi_broken_return_value (gdbarch, valtype, regcache,
98 readbuf, writebuf);
99 }
100 \f
101
102 /* Signal trampolines. */
103
104 static const struct tramp_frame ppcnbsd2_sigtramp;
105
106 static void
107 ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
108 struct frame_info *next_frame,
109 struct trad_frame_cache *this_cache,
110 CORE_ADDR func)
111 {
112 struct gdbarch *gdbarch = get_frame_arch (next_frame);
113 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
114 CORE_ADDR addr, base;
115 int i;
116
117 base = frame_unwind_register_unsigned (next_frame, SP_REGNUM);
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)
123 {
124 int regnum = i + tdep->ppc_gp0_regnum;
125 trad_frame_set_reg_addr (this_cache, regnum, addr);
126 }
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;
135 trad_frame_set_reg_addr (this_cache, PC_REGNUM, addr); /* SRR0? */
136 addr += tdep->wordsize;
137
138 /* Construct the frame ID using the function start. */
139 trad_frame_set_id (this_cache, frame_id_build (base, func));
140 }
141
142 static 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. */
160
161 static const struct tramp_frame ppcnbsd2_sigtramp =
162 {
163 SIGTRAMP_FRAME,
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 */
173 { TRAMP_SENTINEL_INSN, -1 }
174 },
175 ppcnbsd_sigtramp_cache_init
176 };
177 \f
178
179 static void
180 ppcnbsd_init_abi (struct gdbarch_info info,
181 struct gdbarch *gdbarch)
182 {
183 /* For NetBSD, this is an on again, off again thing. Some systems
184 do use the broken struct convention, and some don't. */
185 set_gdbarch_return_value (gdbarch, ppcnbsd_return_value);
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
194 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp);
195 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp);
196 }
197 \f
198
199 /* Provide a prototype to silence -Wmissing-prototypes. */
200 void _initialize_ppcnbsd_tdep (void);
201
202 void
203 _initialize_ppcnbsd_tdep (void)
204 {
205 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD_ELF,
206 ppcnbsd_init_abi);
207
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;
214 ppcnbsd_reg_offsets.lr_offset = 128;
215 ppcnbsd_reg_offsets.cr_offset = 132;
216 ppcnbsd_reg_offsets.xer_offset = 136;
217 ppcnbsd_reg_offsets.ctr_offset = 140;
218 ppcnbsd_reg_offsets.pc_offset = 144;
219 ppcnbsd_reg_offsets.ps_offset = -1;
220 ppcnbsd_reg_offsets.mq_offset = -1;
221
222 /* Floating-point registers. */
223 ppcnbsd_reg_offsets.f0_offset = 0;
224 ppcnbsd_reg_offsets.fpscr_offset = 256;
225
226 /* AltiVec registers. */
227 ppcnbsd_reg_offsets.vr0_offset = 0;
228 ppcnbsd_reg_offsets.vrsave_offset = 512;
229 ppcnbsd_reg_offsets.vscr_offset = 524;
230 }
231 }
This page took 0.033956 seconds and 4 git commands to generate.