1 /* Target-dependent code for PowerPC systems running NetBSD.
2 Copyright 2002 Free Software Foundation, Inc.
3 Contributed by Wasabi Systems, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "breakpoint.h"
30 #include "ppcnbsd-tdep.h"
31 #include "nbsd-tdep.h"
33 #include "solib-svr4.h"
35 #define REG_FIXREG_OFFSET(x) ((x) * 4)
36 #define REG_LR_OFFSET (32 * 4)
37 #define REG_CR_OFFSET (33 * 4)
38 #define REG_XER_OFFSET (34 * 4)
39 #define REG_CTR_OFFSET (35 * 4)
40 #define REG_PC_OFFSET (36 * 4)
41 #define SIZEOF_STRUCT_REG (37 * 4)
43 #define FPREG_FPR_OFFSET(x) ((x) * 8)
44 #define FPREG_FPSCR_OFFSET (32 * 8)
45 #define SIZEOF_STRUCT_FPREG (33 * 8)
48 ppcnbsd_supply_reg (char *regs
, int regno
)
50 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
53 for (i
= 0; i
<= 31; i
++)
55 if (regno
== i
|| regno
== -1)
56 supply_register (i
, regs
+ REG_FIXREG_OFFSET (i
));
59 if (regno
== tdep
->ppc_lr_regnum
|| regno
== -1)
60 supply_register (tdep
->ppc_lr_regnum
, regs
+ REG_LR_OFFSET
);
62 if (regno
== tdep
->ppc_cr_regnum
|| regno
== -1)
63 supply_register (tdep
->ppc_cr_regnum
, regs
+ REG_CR_OFFSET
);
65 if (regno
== tdep
->ppc_xer_regnum
|| regno
== -1)
66 supply_register (tdep
->ppc_xer_regnum
, regs
+ REG_XER_OFFSET
);
68 if (regno
== tdep
->ppc_ctr_regnum
|| regno
== -1)
69 supply_register (tdep
->ppc_ctr_regnum
, regs
+ REG_CTR_OFFSET
);
71 if (regno
== PC_REGNUM
|| regno
== -1)
72 supply_register (PC_REGNUM
, regs
+ REG_PC_OFFSET
);
76 ppcnbsd_fill_reg (char *regs
, int regno
)
78 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
81 for (i
= 0; i
<= 31; i
++)
83 if (regno
== i
|| regno
== -1)
84 regcache_collect (i
, regs
+ REG_FIXREG_OFFSET (i
));
87 if (regno
== tdep
->ppc_lr_regnum
|| regno
== -1)
88 regcache_collect (tdep
->ppc_lr_regnum
, regs
+ REG_LR_OFFSET
);
90 if (regno
== tdep
->ppc_cr_regnum
|| regno
== -1)
91 regcache_collect (tdep
->ppc_cr_regnum
, regs
+ REG_CR_OFFSET
);
93 if (regno
== tdep
->ppc_xer_regnum
|| regno
== -1)
94 regcache_collect (tdep
->ppc_xer_regnum
, regs
+ REG_XER_OFFSET
);
96 if (regno
== tdep
->ppc_ctr_regnum
|| regno
== -1)
97 regcache_collect (tdep
->ppc_ctr_regnum
, regs
+ REG_CTR_OFFSET
);
99 if (regno
== PC_REGNUM
|| regno
== -1)
100 regcache_collect (PC_REGNUM
, regs
+ REG_PC_OFFSET
);
104 ppcnbsd_supply_fpreg (char *fpregs
, int regno
)
106 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
109 for (i
= FP0_REGNUM
; i
<= FP0_REGNUM
+ 31; i
++)
111 if (regno
== i
|| regno
== -1)
112 supply_register (i
, fpregs
+ FPREG_FPR_OFFSET (i
- FP0_REGNUM
));
115 if (regno
== tdep
->ppc_fpscr_regnum
|| regno
== -1)
116 supply_register (tdep
->ppc_fpscr_regnum
, fpregs
+ FPREG_FPSCR_OFFSET
);
120 ppcnbsd_fill_fpreg (char *fpregs
, int regno
)
122 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
125 for (i
= FP0_REGNUM
; i
<= FP0_REGNUM
+ 31; i
++)
127 if (regno
== i
|| regno
== -1)
128 regcache_collect (i
, fpregs
+ FPREG_FPR_OFFSET (i
- FP0_REGNUM
));
131 if (regno
== tdep
->ppc_fpscr_regnum
|| regno
== -1)
132 regcache_collect (tdep
->ppc_fpscr_regnum
, fpregs
+ FPREG_FPSCR_OFFSET
);
136 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
, int which
,
141 /* We get everything from one section. */
145 regs
= core_reg_sect
;
146 fpregs
= core_reg_sect
+ SIZEOF_STRUCT_REG
;
148 /* Integer registers. */
149 ppcnbsd_supply_reg (regs
, -1);
151 /* Floating point registers. */
152 ppcnbsd_supply_fpreg (fpregs
, -1);
156 fetch_elfcore_registers (char *core_reg_sect
, unsigned core_reg_size
, int which
,
161 case 0: /* Integer registers. */
162 if (core_reg_size
!= SIZEOF_STRUCT_REG
)
163 warning ("Wrong size register set in core file.");
165 ppcnbsd_supply_reg (core_reg_sect
, -1);
168 case 2: /* Floating point registers. */
169 if (core_reg_size
!= SIZEOF_STRUCT_FPREG
)
170 warning ("Wrong size FP register set in core file.");
172 ppcnbsd_supply_fpreg (core_reg_sect
, -1);
176 /* Don't know what kind of register request this is; just ignore it. */
181 static struct core_fns ppcnbsd_core_fns
=
183 bfd_target_unknown_flavour
, /* core_flavour */
184 default_check_format
, /* check_format */
185 default_core_sniffer
, /* core_sniffer */
186 fetch_core_registers
, /* core_read_registers */
190 static struct core_fns ppcnbsd_elfcore_fns
=
192 bfd_target_elf_flavour
, /* core_flavour */
193 default_check_format
, /* check_format */
194 default_core_sniffer
, /* core_sniffer */
195 fetch_elfcore_registers
, /* core_read_registers */
200 ppcnbsd_init_abi (struct gdbarch_info info
,
201 struct gdbarch
*gdbarch
)
204 set_gdbarch_frame_chain_valid (gdbarch
, generic_func_frame_chain_valid
);
206 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
207 nbsd_ilp32_solib_svr4_fetch_link_map_offsets
);
211 _initialize_ppcnbsd_tdep (void)
213 gdbarch_register_osabi (bfd_arch_powerpc
, GDB_OSABI_NETBSD_ELF
,
216 add_core_fns (&ppcnbsd_core_fns
);
217 add_core_fns (&ppcnbsd_elfcore_fns
);