1 /* Target-dependent code for NetBSD/powerpc.
2
3 Copyright (C) 2002-2020 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 3 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, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "gdbtypes.h"
24 #include "osabi.h"
25 #include "regcache.h"
26 #include "regset.h"
27 #include "trad-frame.h"
28 #include "tramp-frame.h"
29
30 #include "ppc-tdep.h"
31 #include "nbsd-tdep.h"
32 #include "ppc-nbsd-tdep.h"
33 #include "ppc-tdep.h"
34 #include "solib-svr4.h"
35
36 /* Register offsets from <machine/reg.h>. */
37 struct ppc_reg_offsets ppcnbsd_reg_offsets;
38
39
40 /* Core file support. */
41
42 /* NetBSD/powerpc register sets. */
43
44 const struct regset ppcnbsd_gregset =
45 {
46 &ppcnbsd_reg_offsets,
47 ppc_supply_gregset
48 };
49
50 const struct regset ppcnbsd_fpregset =
51 {
52 &ppcnbsd_reg_offsets,
53 ppc_supply_fpregset
54 };
55
56 /* Iterate over core file register note sections. */
57
58 static void
ppcnbsd_iterate_over_regset_sections(struct gdbarch * gdbarch,iterate_over_regset_sections_cb * cb,void * cb_data,const struct regcache * regcache)59 ppcnbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
60 iterate_over_regset_sections_cb *cb,
61 void *cb_data,
62 const struct regcache *regcache)
63 {
64 cb (".reg", 148, 148, &ppcnbsd_gregset, NULL, cb_data);
65 cb (".reg2", 264, 264, &ppcnbsd_fpregset, NULL, cb_data);
66 }
67
68
69 /* NetBSD is confused. It appears that 1.5 was using the correct SVR4
70 convention but, 1.6 switched to the below broken convention. For
71 the moment use the broken convention. Ulgh! */
72
73 static enum return_value_convention
ppcnbsd_return_value(struct gdbarch * gdbarch,struct value * function,struct type * valtype,struct regcache * regcache,gdb_byte * readbuf,const gdb_byte * writebuf)74 ppcnbsd_return_value (struct gdbarch *gdbarch, struct value *function,
75 struct type *valtype, struct regcache *regcache,
76 gdb_byte *readbuf, const gdb_byte *writebuf)
77 {
78 #if 0
79 if ((valtype->code () == TYPE_CODE_STRUCT
80 || valtype->code () == TYPE_CODE_UNION)
81 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
82 && TYPE_VECTOR (valtype))
83 && !(TYPE_LENGTH (valtype) == 1
84 || TYPE_LENGTH (valtype) == 2
85 || TYPE_LENGTH (valtype) == 4
86 || TYPE_LENGTH (valtype) == 8))
87 return RETURN_VALUE_STRUCT_CONVENTION;
88 else
89 #endif
90 return ppc_sysv_abi_broken_return_value (gdbarch, function, valtype,
91 regcache, readbuf, writebuf);
92 }
93
94
95 /* Signal trampolines. */
96
97 extern const struct tramp_frame ppcnbsd2_sigtramp;
98
99 static void
ppcnbsd_sigtramp_cache_init(const struct tramp_frame * self,struct frame_info * this_frame,struct trad_frame_cache * this_cache,CORE_ADDR func)100 ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
101 struct frame_info *this_frame,
102 struct trad_frame_cache *this_cache,
103 CORE_ADDR func)
104 {
105 struct gdbarch *gdbarch = get_frame_arch (this_frame);
106 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
107 CORE_ADDR addr, base;
108 int i;
109
110 base = get_frame_register_unsigned (this_frame,
111 gdbarch_sp_regnum (gdbarch));
112 if (self == &ppcnbsd2_sigtramp)
113 addr = base + 0x10 + 2 * tdep->wordsize;
114 else
115 addr = base + 0x18 + 2 * tdep->wordsize;
116 for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize)
117 {
118 int regnum = i + tdep->ppc_gp0_regnum;
119 trad_frame_set_reg_addr (this_cache, regnum, addr);
120 }
121 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, addr);
122 addr += tdep->wordsize;
123 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, addr);
124 addr += tdep->wordsize;
125 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, addr);
126 addr += tdep->wordsize;
127 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, addr);
128 addr += tdep->wordsize;
129 trad_frame_set_reg_addr (this_cache, gdbarch_pc_regnum (gdbarch),
130 addr); /* SRR0? */
131 addr += tdep->wordsize;
132
133 /* Construct the frame ID using the function start. */
134 trad_frame_set_id (this_cache, frame_id_build (base, func));
135 }
136
137 static const struct tramp_frame ppcnbsd_sigtramp =
138 {
139 SIGTRAMP_FRAME,
140 4,
141 {
142 { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */
143 { 0x4e800021, ULONGEST_MAX }, /* blrl */
144 { 0x38610018, ULONGEST_MAX }, /* addi r3,r1,24 */
145 { 0x38000127, ULONGEST_MAX }, /* li r0,295 */
146 { 0x44000002, ULONGEST_MAX }, /* sc */
147 { 0x38000001, ULONGEST_MAX }, /* li r0,1 */
148 { 0x44000002, ULONGEST_MAX }, /* sc */
149 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
150 },
151 ppcnbsd_sigtramp_cache_init
152 };
153
154 /* NetBSD 2.0 introduced a slightly different signal trampoline. */
155
156 const struct tramp_frame ppcnbsd2_sigtramp =
157 {
158 SIGTRAMP_FRAME,
159 4,
160 {
161 { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */
162 { 0x4e800021, ULONGEST_MAX }, /* blrl */
163 { 0x38610010, ULONGEST_MAX }, /* addi r3,r1,16 */
164 { 0x38000127, ULONGEST_MAX }, /* li r0,295 */
165 { 0x44000002, ULONGEST_MAX }, /* sc */
166 { 0x38000001, ULONGEST_MAX }, /* li r0,1 */
167 { 0x44000002, ULONGEST_MAX }, /* sc */
168 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
169 },
170 ppcnbsd_sigtramp_cache_init
171 };
172
173
174 static void
ppcnbsd_init_abi(struct gdbarch_info info,struct gdbarch * gdbarch)175 ppcnbsd_init_abi (struct gdbarch_info info,
176 struct gdbarch *gdbarch)
177 {
178 nbsd_init_abi (info, gdbarch);
179
180 /* NetBSD doesn't support the 128-bit `long double' from the psABI. */
181 set_gdbarch_long_double_bit (gdbarch, 64);
182 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
183
184 /* For NetBSD, this is an on again, off again thing. Some systems
185 do use the broken struct convention, and some don't. */
186 set_gdbarch_return_value (gdbarch, ppcnbsd_return_value);
187
188 /* NetBSD uses SVR4-style shared libraries. */
189 set_solib_svr4_fetch_link_map_offsets
190 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
191
192 set_gdbarch_iterate_over_regset_sections
193 (gdbarch, ppcnbsd_iterate_over_regset_sections);
194
195 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp);
196 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp);
197 }
198
199 void _initialize_ppcnbsd_tdep ();
200 void
_initialize_ppcnbsd_tdep()201 _initialize_ppcnbsd_tdep ()
202 {
203 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD,
204 ppcnbsd_init_abi);
205 gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_NETBSD,
206 ppcnbsd_init_abi);
207
208 /* Avoid initializing the register offsets again if they were
209 already initialized 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.gpr_size = 4;
215 ppcnbsd_reg_offsets.xr_size = 4;
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;
227 ppcnbsd_reg_offsets.fpscr_size = 4;
228
229 }
230 }
231