No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / ppcnbsd-nat.c
blob52dc1226b0459e7fe997b57f3d5c3e51208f9208
1 /* Native-dependent code for NetBSD/powerpc.
3 Copyright (C) 2002, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
24 #include <sys/types.h>
25 #include <sys/ptrace.h>
26 #include <machine/reg.h>
27 #include <machine/frame.h>
28 #include <machine/pcb.h>
30 #include "defs.h"
31 #include "gdbcore.h"
32 #include "inferior.h"
33 #include "regcache.h"
35 #include "gdb_assert.h"
37 #include "nbsd-nat.h"
38 #include "ppc-tdep.h"
39 #include "ppcnbsd-tdep.h"
40 #include "bsd-kvm.h"
41 #include "inf-ptrace.h"
43 /* Returns true if PT_GETREGS fetches this register. */
45 static int
46 getregs_supplies (int regnum)
48 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
50 return ((regnum >= tdep->ppc_gp0_regnum
51 && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
52 || regnum == tdep->ppc_lr_regnum
53 || regnum == tdep->ppc_cr_regnum
54 || regnum == tdep->ppc_xer_regnum
55 || regnum == tdep->ppc_ctr_regnum
56 || regnum == PC_REGNUM);
59 /* Like above, but for PT_GETFPREGS. */
61 static int
62 getfpregs_supplies (int regnum)
64 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
66 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
67 point registers. Traditionally, GDB's register set has still
68 listed the floating point registers for such machines, so this
69 code is harmless. However, the new E500 port actually omits the
70 floating point registers entirely from the register set --- they
71 don't even have register numbers assigned to them.
73 It's not clear to me how best to update this code, so this assert
74 will alert the first person to encounter the NetBSD/E500
75 combination to the problem. */
76 gdb_assert (ppc_floating_point_unit_p (current_gdbarch));
78 return ((regnum >= tdep->ppc_fp0_regnum
79 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs)
80 || regnum == tdep->ppc_fpscr_regnum);
83 static void
84 ppcnbsd_fetch_inferior_registers (int regnum)
86 if (regnum == -1 || getregs_supplies (regnum))
88 struct reg regs;
90 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
91 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
92 perror_with_name (_("Couldn't get registers"));
94 ppc_supply_gregset (&ppcnbsd_gregset, current_regcache,
95 regnum, &regs, sizeof regs);
98 if (regnum == -1 || getfpregs_supplies (regnum))
100 struct fpreg fpregs;
102 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
103 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
104 perror_with_name (_("Couldn't get FP registers"));
106 ppc_supply_fpregset (&ppcnbsd_fpregset, current_regcache,
107 regnum, &fpregs, sizeof fpregs);
111 static void
112 ppcnbsd_store_inferior_registers (int regnum)
114 if (regnum == -1 || getregs_supplies (regnum))
116 struct reg regs;
118 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
119 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
120 perror_with_name (_("Couldn't get registers"));
122 ppc_collect_gregset (&ppcnbsd_gregset, current_regcache,
123 regnum, &regs, sizeof regs);
125 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
126 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
127 perror_with_name (_("Couldn't write registers"));
130 if (regnum == -1 || getfpregs_supplies (regnum))
132 struct fpreg fpregs;
134 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
135 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
136 perror_with_name (_("Couldn't get FP registers"));
138 ppc_collect_fpregset (&ppcnbsd_fpregset, current_regcache,
139 regnum, &fpregs, sizeof fpregs);
141 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
142 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
143 perror_with_name (_("Couldn't set FP registers"));
147 static int
148 ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
150 struct switchframe sf;
151 struct callframe cf;
152 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
153 int i;
155 /* The stack pointer shouldn't be zero. */
156 if (pcb->pcb_sp == 0)
157 return 0;
159 read_memory (pcb->pcb_sp, (gdb_byte *)&sf, sizeof sf);
160 regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr);
161 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2);
162 for (i = 0 ; i < 19 ; i++)
163 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 13 + i,
164 &sf.fixreg[i]);
166 read_memory(sf.sp, (gdb_byte *)&cf, sizeof(cf));
167 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30);
168 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31);
169 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 1, &cf.sp);
171 read_memory(cf.sp, (gdb_byte *)&cf, sizeof(cf));
172 regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr);
173 regcache_raw_supply (regcache, PC_REGNUM, &cf.lr);
175 return 1;
178 /* Provide a prototype to silence -Wmissing-prototypes. */
179 void _initialize_ppcnbsd_nat (void);
181 void
182 _initialize_ppcnbsd_nat (void)
184 struct target_ops *t;
186 /* Support debugging kernel virtual memory images. */
187 bsd_kvm_add_target (ppcnbsd_supply_pcb);
189 /* Add in local overrides. */
190 t = inf_ptrace_target ();
191 t->to_fetch_registers = ppcnbsd_fetch_inferior_registers;
192 t->to_store_registers = ppcnbsd_store_inferior_registers;
193 t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
194 add_target (t);