1 /* Target-dependent code for PowerPC systems running FreeBSD.
3 Copyright 2002, 2003, 2004 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 2 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, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
33 #include "ppcfbsd-tdep.h"
34 #include "trad-frame.h"
35 #include "gdb_assert.h"
36 #include "solib-svr4.h"
38 #define REG_FIXREG_OFFSET(x) ((x) * 4)
39 #define REG_LR_OFFSET (32 * 4)
40 #define REG_CR_OFFSET (33 * 4)
41 #define REG_XER_OFFSET (34 * 4)
42 #define REG_CTR_OFFSET (35 * 4)
43 #define REG_PC_OFFSET (36 * 4)
44 #define SIZEOF_STRUCT_REG (37 * 4)
46 #define FPREG_FPR_OFFSET(x) ((x) * 8)
47 #define FPREG_FPSCR_OFFSET (32 * 8)
48 #define SIZEOF_STRUCT_FPREG (33 * 8)
51 ppcfbsd_supply_reg (char *regs, int regno)
53 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
56 for (i = tdep->ppc_gp0_regnum; i <= tdep->ppc_gplast_regnum; i++)
58 if (regno == i || regno == -1)
59 regcache_raw_supply (current_regcache, i, regs +
60 REG_FIXREG_OFFSET (i - tdep->ppc_gp0_regnum));
63 if (regno == tdep->ppc_lr_regnum || regno == -1)
64 regcache_raw_supply (current_regcache, tdep->ppc_lr_regnum,
65 regs + REG_LR_OFFSET);
67 if (regno == tdep->ppc_cr_regnum || regno == -1)
68 regcache_raw_supply (current_regcache, tdep->ppc_cr_regnum,
69 regs + REG_CR_OFFSET);
71 if (regno == tdep->ppc_xer_regnum || regno == -1)
72 regcache_raw_supply (current_regcache, tdep->ppc_xer_regnum,
73 regs + REG_XER_OFFSET);
75 if (regno == tdep->ppc_ctr_regnum || regno == -1)
76 regcache_raw_supply (current_regcache, tdep->ppc_ctr_regnum,
77 regs + REG_CTR_OFFSET);
79 if (regno == PC_REGNUM || regno == -1)
80 regcache_raw_supply (current_regcache, PC_REGNUM,
81 regs + REG_PC_OFFSET);
85 ppcfbsd_fill_reg (char *regs, int regno)
87 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
90 for (i = tdep->ppc_gp0_regnum; i <= tdep->ppc_gplast_regnum; i++)
92 if (regno == i || regno == -1)
93 regcache_raw_collect (current_regcache, i, regs +
94 REG_FIXREG_OFFSET (i - tdep->ppc_gp0_regnum));
97 if (regno == tdep->ppc_lr_regnum || regno == -1)
98 regcache_raw_collect (current_regcache, tdep->ppc_lr_regnum,
99 regs + REG_LR_OFFSET);
101 if (regno == tdep->ppc_cr_regnum || regno == -1)
102 regcache_raw_collect (current_regcache, tdep->ppc_cr_regnum,
103 regs + REG_CR_OFFSET);
105 if (regno == tdep->ppc_xer_regnum || regno == -1)
106 regcache_raw_collect (current_regcache, tdep->ppc_xer_regnum,
107 regs + REG_XER_OFFSET);
109 if (regno == tdep->ppc_ctr_regnum || regno == -1)
110 regcache_raw_collect (current_regcache, tdep->ppc_ctr_regnum,
111 regs + REG_CTR_OFFSET);
113 if (regno == PC_REGNUM || regno == -1)
114 regcache_raw_collect (current_regcache, PC_REGNUM, regs + REG_PC_OFFSET);
118 ppcfbsd_supply_fpreg (char *fpregs, int regno)
120 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
123 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
124 point registers. Traditionally, GDB's register set has still
125 listed the floating point registers for such machines, so this
126 code is harmless. However, the new E500 port actually omits the
127 floating point registers entirely from the register set --- they
128 don't even have register numbers assigned to them.
130 It's not clear to me how best to update this code, so this assert
131 will alert the first person to encounter the NetBSD/E500
132 combination to the problem. */
133 gdb_assert (ppc_floating_point_unit_p (current_gdbarch));
135 for (i = FP0_REGNUM; i <= FPLAST_REGNUM; i++)
137 if (regno == i || regno == -1)
138 regcache_raw_supply (current_regcache, i, fpregs +
139 FPREG_FPR_OFFSET (i - FP0_REGNUM));
142 if (regno == tdep->ppc_fpscr_regnum || regno == -1)
143 regcache_raw_supply (current_regcache, tdep->ppc_fpscr_regnum,
144 fpregs + FPREG_FPSCR_OFFSET);
148 ppcfbsd_fill_fpreg (char *fpregs, int regno)
150 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
153 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
154 point registers. Traditionally, GDB's register set has still
155 listed the floating point registers for such machines, so this
156 code is harmless. However, the new E500 port actually omits the
157 floating point registers entirely from the register set --- they
158 don't even have register numbers assigned to them.
160 It's not clear to me how best to update this code, so this assert
161 will alert the first person to encounter the NetBSD/E500
162 combination to the problem. */
163 gdb_assert (ppc_floating_point_unit_p (current_gdbarch));
165 for (i = FP0_REGNUM; i <= FPLAST_REGNUM; i++)
167 if (regno == i || regno == -1)
168 regcache_raw_collect (current_regcache, i, fpregs +
169 FPREG_FPR_OFFSET (i - FP0_REGNUM));
172 if (regno == tdep->ppc_fpscr_regnum || regno == -1)
173 regcache_raw_collect (current_regcache, tdep->ppc_fpscr_regnum,
174 fpregs + FPREG_FPSCR_OFFSET);
178 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
183 /* We get everything from one section. */
187 regs = core_reg_sect;
188 fpregs = core_reg_sect + SIZEOF_STRUCT_REG;
190 /* Integer registers. */
191 ppcfbsd_supply_reg (regs, -1);
193 /* Floating point registers. */
194 ppcfbsd_supply_fpreg (fpregs, -1);
198 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size, int which,
203 case 0: /* Integer registers. */
204 if (core_reg_size != SIZEOF_STRUCT_REG)
205 warning (_("Wrong size register set in core file."));
207 ppcfbsd_supply_reg (core_reg_sect, -1);
210 case 2: /* Floating point registers. */
211 if (core_reg_size != SIZEOF_STRUCT_FPREG)
212 warning (_("Wrong size FP register set in core file."));
214 ppcfbsd_supply_fpreg (core_reg_sect, -1);
218 /* Don't know what kind of register request this is; just ignore it. */
223 static struct core_fns ppcfbsd_core_fns =
225 bfd_target_unknown_flavour, /* core_flavour */
226 default_check_format, /* check_format */
227 default_core_sniffer, /* core_sniffer */
228 fetch_core_registers, /* core_read_registers */
232 static struct core_fns ppcfbsd_elfcore_fns =
234 bfd_target_elf_flavour, /* core_flavour */
235 default_check_format, /* check_format */
236 default_core_sniffer, /* core_sniffer */
237 fetch_elfcore_registers, /* core_read_registers */
242 ppcfbsd_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
244 return (pc >= 0x7fffef00U) ? 1 : 0;
247 /* NetBSD is confused. It appears that 1.5 was using the correct SVr4
248 convention but, 1.6 switched to the below broken convention. For
249 the moment use the broken convention. Ulgh!. */
251 static enum return_value_convention
252 ppcfbsd_return_value (struct gdbarch *gdbarch, struct type *valtype,
253 struct regcache *regcache, void *readbuf,
254 const void *writebuf)
256 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
257 || TYPE_CODE (valtype) == TYPE_CODE_UNION)
258 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8))
259 && !(TYPE_LENGTH (valtype) == 1
260 || TYPE_LENGTH (valtype) == 2
261 || TYPE_LENGTH (valtype) == 4
262 || TYPE_LENGTH (valtype) == 8))
263 return RETURN_VALUE_STRUCT_CONVENTION;
265 return ppc_sysv_abi_broken_return_value (gdbarch, valtype, regcache,
270 ppcfbsd_init_abi (struct gdbarch_info info,
271 struct gdbarch *gdbarch)
273 set_gdbarch_pc_in_sigtramp (gdbarch, ppcfbsd_pc_in_sigtramp);
274 /* For NetBSD, this is an on again, off again thing. Some systems
275 do use the broken struct convention, and some don't. */
276 set_gdbarch_return_value (gdbarch, ppcfbsd_return_value);
277 set_solib_svr4_fetch_link_map_offsets (gdbarch,
278 svr4_ilp32_fetch_link_map_offsets);
282 _initialize_ppcfbsd_tdep (void)
284 gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_FREEBSD_ELF,
286 gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_FREEBSD_ELF,
289 add_core_fns (&ppcfbsd_core_fns);
290 add_core_fns (&ppcfbsd_elfcore_fns);