1 /* Native-dependent code for PowerPC's running NetBSD, for GDB.
2 Copyright 2002, 2004 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. */
22 #include <sys/types.h>
23 #include <sys/ptrace.h>
24 #include <machine/reg.h>
25 #include <machine/frame.h>
26 #include <machine/pcb.h>
30 #include "gdb_assert.h"
36 #include "ppcnbsd-tdep.h"
38 #include "inf-ptrace.h"
40 /* Returns true if PT_GETREGS fetches this register. */
42 getregs_supplies (int regno)
44 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
46 return ((regno >= tdep->ppc_gp0_regnum
47 && regno < tdep->ppc_gp0_regnum + ppc_num_gprs)
48 || regno == tdep->ppc_lr_regnum
49 || regno == tdep->ppc_cr_regnum
50 || regno == tdep->ppc_xer_regnum
51 || regno == tdep->ppc_ctr_regnum
52 || regno == PC_REGNUM);
55 /* Like above, but for PT_GETFPREGS. */
57 getfpregs_supplies (int regno)
59 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
61 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
62 point registers. Traditionally, GDB's register set has still
63 listed the floating point registers for such machines, so this
64 code is harmless. However, the new E500 port actually omits the
65 floating point registers entirely from the register set --- they
66 don't even have register numbers assigned to them.
68 It's not clear to me how best to update this code, so this assert
69 will alert the first person to encounter the NetBSD/E500
70 combination to the problem. */
71 gdb_assert (ppc_floating_point_unit_p (current_gdbarch));
73 return ((regno >= tdep->ppc_fp0_regnum
74 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
75 || regno == tdep->ppc_fpscr_regnum);
79 ppcnbsd_fetch_inferior_registers (int regno)
81 if (regno == -1 || getregs_supplies (regno))
85 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
86 (PTRACE_TYPE_ARG3) ®s, 0) == -1)
87 perror_with_name (_("Couldn't get registers"));
89 ppcnbsd_supply_reg ((char *) ®s, regno);
94 if (regno == -1 || getfpregs_supplies (regno))
98 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
99 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
100 perror_with_name (_("Couldn't get FP registers"));
102 ppcnbsd_supply_fpreg ((char *) &fpregs, regno);
109 ppcnbsd_store_inferior_registers (int regno)
111 if (regno == -1 || getregs_supplies (regno))
115 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
116 (PTRACE_TYPE_ARG3) ®s, 0) == -1)
117 perror_with_name (_("Couldn't get registers"));
119 ppcnbsd_fill_reg ((char *) ®s, regno);
121 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
122 (PTRACE_TYPE_ARG3) ®s, 0) == -1)
123 perror_with_name (_("Couldn't write registers"));
129 if (regno == -1 || getfpregs_supplies (regno))
133 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
134 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
135 perror_with_name (_("Couldn't get FP registers"));
137 ppcnbsd_fill_fpreg ((char *) &fpregs, regno);
139 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
140 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
141 perror_with_name (_("Couldn't set FP registers"));
146 ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
148 struct switchframe sf;
150 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
153 /* The stack pointer shouldn't be zero. */
154 if (pcb->pcb_sp == 0)
157 read_memory (pcb->pcb_sp, (char *) &sf, sizeof sf);
158 regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr);
159 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2);
160 for (i = 0 ; i < 19 ; i++)
161 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 13 + i,
164 read_memory(sf.sp, (char *)&cf, sizeof(cf));
165 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30);
166 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31);
167 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 1, &cf.sp);
169 read_memory(cf.sp, (char *)&cf, sizeof(cf));
170 regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr);
171 regcache_raw_supply (regcache, PC_REGNUM, &cf.lr);
176 /* Provide a prototype to silence -Wmissing-prototypes. */
177 void _initialize_ppcnbsd_nat (void);
180 _initialize_ppcnbsd_nat (void)
182 struct target_ops *t;
183 /* Support debugging kernel virtual memory images. */
184 bsd_kvm_add_target (ppcnbsd_supply_pcb);
185 /* Add in local overrides. */
186 t = inf_ptrace_target ();
187 t->to_fetch_registers = ppcnbsd_fetch_inferior_registers;
188 t->to_store_registers = ppcnbsd_store_inferior_registers;