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 /* Returns true if PT_GETREGS fetches this register. */
40 getregs_supplies (int regno)
42 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
44 return ((regno >= tdep->ppc_gp0_regnum
45 && regno < tdep->ppc_gp0_regnum + ppc_num_gprs)
46 || regno == tdep->ppc_lr_regnum
47 || regno == tdep->ppc_cr_regnum
48 || regno == tdep->ppc_xer_regnum
49 || regno == tdep->ppc_ctr_regnum
50 || regno == PC_REGNUM);
53 /* Like above, but for PT_GETFPREGS. */
55 getfpregs_supplies (int regno)
57 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
59 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
60 point registers. Traditionally, GDB's register set has still
61 listed the floating point registers for such machines, so this
62 code is harmless. However, the new E500 port actually omits the
63 floating point registers entirely from the register set --- they
64 don't even have register numbers assigned to them.
66 It's not clear to me how best to update this code, so this assert
67 will alert the first person to encounter the NetBSD/E500
68 combination to the problem. */
69 gdb_assert (ppc_floating_point_unit_p (current_gdbarch));
71 return ((regno >= tdep->ppc_fp0_regnum
72 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
73 || regno == tdep->ppc_fpscr_regnum);
77 fetch_inferior_registers (int regno)
79 if (regno == -1 || getregs_supplies (regno))
83 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
84 (PTRACE_ARG3_TYPE) ®s, 0) == -1)
85 perror_with_name ("Couldn't get registers");
87 ppcnbsd_supply_reg ((char *) ®s, regno);
92 if (regno == -1 || getfpregs_supplies (regno))
96 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
97 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
98 perror_with_name ("Couldn't get FP registers");
100 ppcnbsd_supply_fpreg ((char *) &fpregs, regno);
107 store_inferior_registers (int regno)
109 if (regno == -1 || getregs_supplies (regno))
113 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
114 (PTRACE_ARG3_TYPE) ®s, 0) == -1)
115 perror_with_name ("Couldn't get registers");
117 ppcnbsd_fill_reg ((char *) ®s, regno);
119 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
120 (PTRACE_ARG3_TYPE) ®s, 0) == -1)
121 perror_with_name ("Couldn't write registers");
127 if (regno == -1 || getfpregs_supplies (regno))
131 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
132 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
133 perror_with_name ("Couldn't get FP registers");
135 ppcnbsd_fill_fpreg ((char *) &fpregs, regno);
137 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
138 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
139 perror_with_name ("Couldn't set FP registers");
144 ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
146 struct switchframe sf;
148 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
151 /* The stack pointer shouldn't be zero. */
152 if (pcb->pcb_sp == 0)
155 read_memory (pcb->pcb_sp, (char *) &sf, sizeof sf);
156 regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr);
157 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2);
158 for (i = 0 ; i < 19 ; i++)
159 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 13 + i,
162 read_memory(sf.sp, (char *)&cf, sizeof(cf));
163 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30);
164 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31);
165 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 1, &cf.sp);
167 read_memory(cf.sp, (char *)&cf, sizeof(cf));
168 regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr);
169 regcache_raw_supply (regcache, PC_REGNUM, &cf.lr);
174 /* Provide a prototype to silence -Wmissing-prototypes. */
175 void _initialize_ppcnbsd_nat (void);
178 _initialize_ppcnbsd_nat (void)
180 /* Support debugging kernel virtual memory images. */
181 bsd_kvm_add_target (ppcnbsd_supply_pcb);