Add translations for various sub-directories
[binutils-gdb.git] / gdb / ppc-netbsd-tdep.c
blobb412030ab9ee2c99b32ea7ee600eaf3f6e1cda44
1 /* Target-dependent code for NetBSD/powerpc.
3 Copyright (C) 2002-2024 Free Software Foundation, Inc.
5 Contributed by Wasabi Systems, Inc.
7 This file is part of GDB.
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.
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.
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/>. */
22 #include "gdbtypes.h"
23 #include "osabi.h"
24 #include "regcache.h"
25 #include "regset.h"
26 #include "trad-frame.h"
27 #include "tramp-frame.h"
29 #include "ppc-tdep.h"
30 #include "netbsd-tdep.h"
31 #include "solib-svr4.h"
33 /* Register offsets from <machine/reg.h>. */
34 static ppc_reg_offsets ppcnbsd_reg_offsets;
37 /* Core file support. */
39 /* NetBSD/powerpc register sets. */
41 const struct regset ppcnbsd_gregset =
43 &ppcnbsd_reg_offsets,
44 ppc_supply_gregset
47 const struct regset ppcnbsd_fpregset =
49 &ppcnbsd_reg_offsets,
50 ppc_supply_fpregset
53 /* Iterate over core file register note sections. */
55 static void
56 ppcnbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
57 iterate_over_regset_sections_cb *cb,
58 void *cb_data,
59 const struct regcache *regcache)
61 cb (".reg", 148, 148, &ppcnbsd_gregset, NULL, cb_data);
62 cb (".reg2", 264, 264, &ppcnbsd_fpregset, NULL, cb_data);
66 /* NetBSD is confused. It appears that 1.5 was using the correct SVR4
67 convention but, 1.6 switched to the below broken convention. For
68 the moment use the broken convention. Ulgh! */
70 static enum return_value_convention
71 ppcnbsd_return_value (struct gdbarch *gdbarch, struct value *function,
72 struct type *valtype, struct regcache *regcache,
73 gdb_byte *readbuf, const gdb_byte *writebuf)
75 #if 0
76 if ((valtype->code () == TYPE_CODE_STRUCT
77 || valtype->code () == TYPE_CODE_UNION)
78 && !((valtype->length () == 16 || valtype->length () == 8)
79 && valtype->is_vector ())
80 && !(valtype->length () == 1
81 || valtype->length () == 2
82 || valtype->length () == 4
83 || valtype->length () == 8))
84 return RETURN_VALUE_STRUCT_CONVENTION;
85 else
86 #endif
87 return ppc_sysv_abi_broken_return_value (gdbarch, function, valtype,
88 regcache, readbuf, writebuf);
92 /* Signal trampolines. */
94 extern const struct tramp_frame ppcnbsd2_sigtramp;
96 static void
97 ppcnbsd_sigtramp_cache_init (const struct tramp_frame *self,
98 const frame_info_ptr &this_frame,
99 struct trad_frame_cache *this_cache,
100 CORE_ADDR func)
102 struct gdbarch *gdbarch = get_frame_arch (this_frame);
103 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
104 CORE_ADDR addr, base;
105 int i;
107 base = get_frame_register_unsigned (this_frame,
108 gdbarch_sp_regnum (gdbarch));
109 if (self == &ppcnbsd2_sigtramp)
110 addr = base + 0x10 + 2 * tdep->wordsize;
111 else
112 addr = base + 0x18 + 2 * tdep->wordsize;
113 for (i = 0; i < ppc_num_gprs; i++, addr += tdep->wordsize)
115 int regnum = i + tdep->ppc_gp0_regnum;
116 trad_frame_set_reg_addr (this_cache, regnum, addr);
118 trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum, addr);
119 addr += tdep->wordsize;
120 trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum, addr);
121 addr += tdep->wordsize;
122 trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum, addr);
123 addr += tdep->wordsize;
124 trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum, addr);
125 addr += tdep->wordsize;
126 trad_frame_set_reg_addr (this_cache, gdbarch_pc_regnum (gdbarch),
127 addr); /* SRR0? */
128 addr += tdep->wordsize;
130 /* Construct the frame ID using the function start. */
131 trad_frame_set_id (this_cache, frame_id_build (base, func));
134 static const struct tramp_frame ppcnbsd_sigtramp =
136 SIGTRAMP_FRAME,
139 { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */
140 { 0x4e800021, ULONGEST_MAX }, /* blrl */
141 { 0x38610018, ULONGEST_MAX }, /* addi r3,r1,24 */
142 { 0x38000127, ULONGEST_MAX }, /* li r0,295 */
143 { 0x44000002, ULONGEST_MAX }, /* sc */
144 { 0x38000001, ULONGEST_MAX }, /* li r0,1 */
145 { 0x44000002, ULONGEST_MAX }, /* sc */
146 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
148 ppcnbsd_sigtramp_cache_init
151 /* NetBSD 2.0 introduced a slightly different signal trampoline. */
153 const struct tramp_frame ppcnbsd2_sigtramp =
155 SIGTRAMP_FRAME,
158 { 0x3821fff0, ULONGEST_MAX }, /* add r1,r1,-16 */
159 { 0x4e800021, ULONGEST_MAX }, /* blrl */
160 { 0x38610010, ULONGEST_MAX }, /* addi r3,r1,16 */
161 { 0x38000127, ULONGEST_MAX }, /* li r0,295 */
162 { 0x44000002, ULONGEST_MAX }, /* sc */
163 { 0x38000001, ULONGEST_MAX }, /* li r0,1 */
164 { 0x44000002, ULONGEST_MAX }, /* sc */
165 { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
167 ppcnbsd_sigtramp_cache_init
171 static void
172 ppcnbsd_init_abi (struct gdbarch_info info,
173 struct gdbarch *gdbarch)
175 nbsd_init_abi (info, gdbarch);
177 /* For NetBSD, this is an on again, off again thing. Some systems
178 do use the broken struct convention, and some don't. */
179 set_gdbarch_return_value (gdbarch, ppcnbsd_return_value);
181 /* NetBSD uses SVR4-style shared libraries. */
182 set_solib_svr4_fetch_link_map_offsets
183 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
185 set_gdbarch_iterate_over_regset_sections
186 (gdbarch, ppcnbsd_iterate_over_regset_sections);
188 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd_sigtramp);
189 tramp_frame_prepend_unwinder (gdbarch, &ppcnbsd2_sigtramp);
192 void _initialize_ppcnbsd_tdep ();
193 void
194 _initialize_ppcnbsd_tdep ()
196 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_NETBSD,
197 ppcnbsd_init_abi);
199 /* Avoid initializing the register offsets again if they were
200 already initialized by ppc-netbsd-nat.c. */
201 if (ppcnbsd_reg_offsets.pc_offset == 0)
203 /* General-purpose registers. */
204 ppcnbsd_reg_offsets.r0_offset = 0;
205 ppcnbsd_reg_offsets.gpr_size = 4;
206 ppcnbsd_reg_offsets.xr_size = 4;
207 ppcnbsd_reg_offsets.lr_offset = 128;
208 ppcnbsd_reg_offsets.cr_offset = 132;
209 ppcnbsd_reg_offsets.xer_offset = 136;
210 ppcnbsd_reg_offsets.ctr_offset = 140;
211 ppcnbsd_reg_offsets.pc_offset = 144;
212 ppcnbsd_reg_offsets.ps_offset = -1;
213 ppcnbsd_reg_offsets.mq_offset = -1;
215 /* Floating-point registers. */
216 ppcnbsd_reg_offsets.f0_offset = 0;
217 ppcnbsd_reg_offsets.fpscr_offset = 256;
218 ppcnbsd_reg_offsets.fpscr_size = 4;