]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - contrib/gdb/gdb/ppcfbsd-tdep.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / contrib / gdb / gdb / ppcfbsd-tdep.c
1 /* Target-dependent code for PowerPC systems running FreeBSD.
2
3    Copyright 2002, 2003, 2004 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., 59 Temple Place - Suite 330,
22    Boston, MA 02111-1307, USA.  */
23
24 #include "defs.h"
25 #include "gdbcore.h"
26 #include "regcache.h"
27 #include "target.h"
28 #include "breakpoint.h"
29 #include "value.h"
30 #include "osabi.h"
31
32 #include "ppc-tdep.h"
33 #include "ppcfbsd-tdep.h"
34 #include "trad-frame.h"
35 #include "gdb_assert.h"
36 #include "solib-svr4.h"
37
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)
45
46 #define FPREG_FPR_OFFSET(x)     ((x) * 8)
47 #define FPREG_FPSCR_OFFSET      (32 * 8)
48 #define SIZEOF_STRUCT_FPREG     (33 * 8)
49
50 void
51 ppcfbsd_supply_reg (char *regs, int regno)
52 {
53   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
54   int i;
55
56   for (i = tdep->ppc_gp0_regnum; i <= tdep->ppc_gplast_regnum; i++)
57     {
58       if (regno == i || regno == -1)
59         regcache_raw_supply (current_regcache, i, regs +
60                              REG_FIXREG_OFFSET (i - tdep->ppc_gp0_regnum));
61     }
62
63   if (regno == tdep->ppc_lr_regnum || regno == -1)
64     regcache_raw_supply (current_regcache, tdep->ppc_lr_regnum,
65                          regs + REG_LR_OFFSET);
66
67   if (regno == tdep->ppc_cr_regnum || regno == -1)
68     regcache_raw_supply (current_regcache, tdep->ppc_cr_regnum,
69                          regs + REG_CR_OFFSET);
70
71   if (regno == tdep->ppc_xer_regnum || regno == -1)
72     regcache_raw_supply (current_regcache, tdep->ppc_xer_regnum,
73                          regs + REG_XER_OFFSET);
74
75   if (regno == tdep->ppc_ctr_regnum || regno == -1)
76     regcache_raw_supply (current_regcache, tdep->ppc_ctr_regnum,
77                          regs + REG_CTR_OFFSET);
78
79   if (regno == PC_REGNUM || regno == -1)
80     regcache_raw_supply (current_regcache, PC_REGNUM,
81                          regs + REG_PC_OFFSET);
82 }
83
84 void
85 ppcfbsd_fill_reg (char *regs, int regno)
86 {
87   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
88   int i;
89
90   for (i = tdep->ppc_gp0_regnum; i <= tdep->ppc_gplast_regnum; i++)
91     {
92       if (regno == i || regno == -1)
93         regcache_raw_collect (current_regcache, i, regs +
94                               REG_FIXREG_OFFSET (i - tdep->ppc_gp0_regnum));
95     }
96
97   if (regno == tdep->ppc_lr_regnum || regno == -1)
98     regcache_raw_collect (current_regcache, tdep->ppc_lr_regnum,
99                           regs + REG_LR_OFFSET);
100
101   if (regno == tdep->ppc_cr_regnum || regno == -1)
102     regcache_raw_collect (current_regcache, tdep->ppc_cr_regnum,
103                           regs + REG_CR_OFFSET);
104
105   if (regno == tdep->ppc_xer_regnum || regno == -1)
106     regcache_raw_collect (current_regcache, tdep->ppc_xer_regnum,
107                           regs + REG_XER_OFFSET);
108
109   if (regno == tdep->ppc_ctr_regnum || regno == -1)
110     regcache_raw_collect (current_regcache, tdep->ppc_ctr_regnum,
111                           regs + REG_CTR_OFFSET);
112
113   if (regno == PC_REGNUM || regno == -1)
114     regcache_raw_collect (current_regcache, PC_REGNUM, regs + REG_PC_OFFSET);
115 }
116
117 void
118 ppcfbsd_supply_fpreg (char *fpregs, int regno)
119 {
120   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
121   int i;
122
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.
129
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));
134
135   for (i = FP0_REGNUM; i <= FPLAST_REGNUM; i++)
136     {
137       if (regno == i || regno == -1)
138         regcache_raw_supply (current_regcache, i, fpregs +
139                              FPREG_FPR_OFFSET (i - FP0_REGNUM));
140     }
141
142   if (regno == tdep->ppc_fpscr_regnum || regno == -1)
143     regcache_raw_supply (current_regcache, tdep->ppc_fpscr_regnum,
144                          fpregs + FPREG_FPSCR_OFFSET);
145 }
146
147 void
148 ppcfbsd_fill_fpreg (char *fpregs, int regno)
149 {
150   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
151   int i;
152
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.
159
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));
164
165   for (i = FP0_REGNUM; i <= FPLAST_REGNUM; i++)
166     {
167       if (regno == i || regno == -1)
168         regcache_raw_collect (current_regcache, i, fpregs +
169                               FPREG_FPR_OFFSET (i - FP0_REGNUM));
170     }
171
172   if (regno == tdep->ppc_fpscr_regnum || regno == -1)
173     regcache_raw_collect (current_regcache, tdep->ppc_fpscr_regnum,
174                           fpregs + FPREG_FPSCR_OFFSET);
175 }
176
177 static void
178 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
179                       CORE_ADDR ignore)
180 {
181   char *regs, *fpregs;
182
183   /* We get everything from one section.  */
184   if (which != 0)
185     return;
186
187   regs = core_reg_sect;
188   fpregs = core_reg_sect + SIZEOF_STRUCT_REG;
189
190   /* Integer registers.  */
191   ppcfbsd_supply_reg (regs, -1);
192
193   /* Floating point registers.  */
194   ppcfbsd_supply_fpreg (fpregs, -1);
195 }
196
197 static void
198 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size, int which,
199                          CORE_ADDR ignore)
200 {
201   switch (which)
202     {
203     case 0:  /* Integer registers.  */
204       if (core_reg_size != SIZEOF_STRUCT_REG)
205         warning (_("Wrong size register set in core file."));
206       else
207         ppcfbsd_supply_reg (core_reg_sect, -1);
208       break;
209
210     case 2:  /* Floating point registers.  */
211       if (core_reg_size != SIZEOF_STRUCT_FPREG)
212         warning (_("Wrong size FP register set in core file."));
213       else
214         ppcfbsd_supply_fpreg (core_reg_sect, -1);
215       break;
216
217     default:
218       /* Don't know what kind of register request this is; just ignore it.  */
219       break;
220     }
221 }
222
223 static struct core_fns ppcfbsd_core_fns =
224 {
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 */
229   NULL                                  /* next */
230 };
231
232 static struct core_fns ppcfbsd_elfcore_fns =
233 {
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 */
238   NULL                                  /* next */
239 };
240
241 static int
242 ppcfbsd_pc_in_sigtramp (CORE_ADDR pc, char *func_name)
243 {
244   return (pc >= 0x7fffef00U) ? 1 : 0;
245 }
246
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!.  */
250
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)
255 {
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; 
264   else 
265     return ppc_sysv_abi_broken_return_value (gdbarch, valtype, regcache,
266                                              readbuf, writebuf); 
267 }
268
269 static void
270 ppcfbsd_init_abi (struct gdbarch_info info,
271                   struct gdbarch *gdbarch)
272 {
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);
279 }
280
281 void
282 _initialize_ppcfbsd_tdep (void)
283 {
284   gdbarch_register_osabi (bfd_arch_rs6000, 0, GDB_OSABI_FREEBSD_ELF,
285                           ppcfbsd_init_abi);
286   gdbarch_register_osabi (bfd_arch_powerpc, 0, GDB_OSABI_FREEBSD_ELF,
287                           ppcfbsd_init_abi);
288
289   add_core_fns (&ppcfbsd_core_fns);
290   add_core_fns (&ppcfbsd_elfcore_fns);
291 }