This commit was generated by cvs2svn to track changes on a CVS vendor
[platform/upstream/binutils.git] / gdb / ppcnbsd-tdep.c
1 /* Target-dependent code for PowerPC systems running NetBSD.
2    Copyright 2002 Free Software Foundation, Inc.
3    Contributed by Wasabi Systems, Inc.
4
5    This file is part of GDB.
6
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.
11
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.
16
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.  */
21
22 #include "defs.h"
23 #include "gdbcore.h"
24 #include "regcache.h"
25 #include "target.h"
26 #include "breakpoint.h"
27 #include "value.h"
28
29 #include "ppc-tdep.h"
30 #include "ppcnbsd-tdep.h"
31 #include "nbsd-tdep.h"
32
33 #include "solib-svr4.h"
34
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)
42
43 #define FPREG_FPR_OFFSET(x)     ((x) * 8)
44 #define FPREG_FPSCR_OFFSET      (32 * 8)
45 #define SIZEOF_STRUCT_FPREG     (33 * 8)
46
47 void
48 ppcnbsd_supply_reg (char *regs, int regno)
49 {
50   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
51   int i;
52
53   for (i = 0; i <= 31; i++)
54     {
55       if (regno == i || regno == -1)
56         supply_register (i, regs + REG_FIXREG_OFFSET (i));
57     }
58
59   if (regno == tdep->ppc_lr_regnum || regno == -1)
60     supply_register (tdep->ppc_lr_regnum, regs + REG_LR_OFFSET);
61
62   if (regno == tdep->ppc_cr_regnum || regno == -1)
63     supply_register (tdep->ppc_cr_regnum, regs + REG_CR_OFFSET);
64
65   if (regno == tdep->ppc_xer_regnum || regno == -1)
66     supply_register (tdep->ppc_xer_regnum, regs + REG_XER_OFFSET);
67
68   if (regno == tdep->ppc_ctr_regnum || regno == -1)
69     supply_register (tdep->ppc_ctr_regnum, regs + REG_CTR_OFFSET);
70
71   if (regno == PC_REGNUM || regno == -1)
72     supply_register (PC_REGNUM, regs + REG_PC_OFFSET);
73 }
74
75 void
76 ppcnbsd_fill_reg (char *regs, int regno)
77 {
78   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
79   int i;
80
81   for (i = 0; i <= 31; i++)
82     {
83       if (regno == i || regno == -1)
84         regcache_collect (i, regs + REG_FIXREG_OFFSET (i));
85     }
86
87   if (regno == tdep->ppc_lr_regnum || regno == -1)
88     regcache_collect (tdep->ppc_lr_regnum, regs + REG_LR_OFFSET);
89
90   if (regno == tdep->ppc_cr_regnum || regno == -1)
91     regcache_collect (tdep->ppc_cr_regnum, regs + REG_CR_OFFSET);
92
93   if (regno == tdep->ppc_xer_regnum || regno == -1)
94     regcache_collect (tdep->ppc_xer_regnum, regs + REG_XER_OFFSET);
95
96   if (regno == tdep->ppc_ctr_regnum || regno == -1)
97     regcache_collect (tdep->ppc_ctr_regnum, regs + REG_CTR_OFFSET);
98
99   if (regno == PC_REGNUM || regno == -1)
100     regcache_collect (PC_REGNUM, regs + REG_PC_OFFSET);
101 }
102
103 void
104 ppcnbsd_supply_fpreg (char *fpregs, int regno)
105 {
106   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
107   int i;
108
109   for (i = FP0_REGNUM; i <= FP0_REGNUM + 31; i++)
110     {
111       if (regno == i || regno == -1)
112         supply_register (i, fpregs + FPREG_FPR_OFFSET (i - FP0_REGNUM));
113     }
114
115   if (regno == tdep->ppc_fpscr_regnum || regno == -1)
116     supply_register (tdep->ppc_fpscr_regnum, fpregs + FPREG_FPSCR_OFFSET);
117 }
118
119 void
120 ppcnbsd_fill_fpreg (char *fpregs, int regno)
121 {
122   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
123   int i;
124
125   for (i = FP0_REGNUM; i <= FP0_REGNUM + 31; i++)
126     {
127       if (regno == i || regno == -1)
128         regcache_collect (i, fpregs + FPREG_FPR_OFFSET (i - FP0_REGNUM));
129     }
130
131   if (regno == tdep->ppc_fpscr_regnum || regno == -1)
132     regcache_collect (tdep->ppc_fpscr_regnum, fpregs + FPREG_FPSCR_OFFSET);
133 }
134
135 static void
136 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
137                       CORE_ADDR ignore)
138 {
139   char *regs, *fpregs;
140
141   /* We get everything from one section.  */
142   if (which != 0)
143     return;
144
145   regs = core_reg_sect;
146   fpregs = core_reg_sect + SIZEOF_STRUCT_REG;
147
148   /* Integer registers.  */
149   ppcnbsd_supply_reg (regs, -1);
150
151   /* Floating point registers.  */
152   ppcnbsd_supply_fpreg (fpregs, -1);
153 }
154
155 static void
156 fetch_elfcore_registers (char *core_reg_sect, unsigned core_reg_size, int which,
157                          CORE_ADDR ignore)
158 {
159   switch (which)
160     {
161     case 0:  /* Integer registers.  */
162       if (core_reg_size != SIZEOF_STRUCT_REG)
163         warning ("Wrong size register set in core file.");
164       else
165         ppcnbsd_supply_reg (core_reg_sect, -1);
166       break;
167
168     case 2:  /* Floating point registers.  */
169       if (core_reg_size != SIZEOF_STRUCT_FPREG)
170         warning ("Wrong size FP register set in core file.");
171       else
172         ppcnbsd_supply_fpreg (core_reg_sect, -1);
173       break;
174
175     default:
176       /* Don't know what kind of register request this is; just ignore it.  */
177       break;
178     }
179 }
180
181 static struct core_fns ppcnbsd_core_fns =
182 {
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 */
187   NULL                                  /* next */
188 };
189
190 static struct core_fns ppcnbsd_elfcore_fns =
191 {
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 */
196   NULL                                  /* next */
197 };
198
199 static void
200 ppcnbsd_init_abi (struct gdbarch_info info,
201                   struct gdbarch *gdbarch)
202 {
203   /* Stop at main.  */
204   set_gdbarch_frame_chain_valid (gdbarch, generic_func_frame_chain_valid);
205
206   set_solib_svr4_fetch_link_map_offsets (gdbarch,
207                                 nbsd_ilp32_solib_svr4_fetch_link_map_offsets);
208 }
209
210 void
211 _initialize_ppcnbsd_tdep (void)
212 {
213   gdbarch_register_osabi (bfd_arch_powerpc, GDB_OSABI_NETBSD_ELF,
214                           ppcnbsd_init_abi);
215
216   add_core_fns (&ppcnbsd_core_fns);
217   add_core_fns (&ppcnbsd_elfcore_fns);
218 }