1 /* Native-dependent code for NetBSD/powerpc.
3 Copyright (C) 2002-2016 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 3 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, see <http://www.gnu.org/licenses/>. */
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>
35 #include "ppc-nbsd-tdep.h"
37 #include "inf-ptrace.h"
39 /* Returns true if PT_GETREGS fetches this register. */
42 getregs_supplies (struct gdbarch *gdbarch, int regnum)
44 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
46 return ((regnum >= tdep->ppc_gp0_regnum
47 && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
48 || regnum == tdep->ppc_lr_regnum
49 || regnum == tdep->ppc_cr_regnum
50 || regnum == tdep->ppc_xer_regnum
51 || regnum == tdep->ppc_ctr_regnum
52 || regnum == gdbarch_pc_regnum (gdbarch));
55 /* Like above, but for PT_GETFPREGS. */
58 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
60 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
62 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
63 point registers. Traditionally, GDB's register set has still
64 listed the floating point registers for such machines, so this
65 code is harmless. However, the new E500 port actually omits the
66 floating point registers entirely from the register set --- they
67 don't even have register numbers assigned to them.
69 It's not clear to me how best to update this code, so this assert
70 will alert the first person to encounter the NetBSD/E500
71 combination to the problem. */
72 gdb_assert (ppc_floating_point_unit_p (gdbarch));
74 return ((regnum >= tdep->ppc_fp0_regnum
75 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs)
76 || regnum == tdep->ppc_fpscr_regnum);
80 ppcnbsd_fetch_inferior_registers (struct target_ops *ops,
81 struct regcache *regcache, int regnum)
83 struct gdbarch *gdbarch = get_regcache_arch (regcache);
85 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
89 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
90 (PTRACE_TYPE_ARG3) ®s, 0) == -1)
91 perror_with_name (_("Couldn't get registers"));
93 ppc_supply_gregset (&ppcnbsd_gregset, regcache,
94 regnum, ®s, sizeof regs);
97 if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
101 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
102 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
103 perror_with_name (_("Couldn't get FP registers"));
105 ppc_supply_fpregset (&ppcnbsd_fpregset, regcache,
106 regnum, &fpregs, sizeof fpregs);
111 ppcnbsd_store_inferior_registers (struct target_ops *ops,
112 struct regcache *regcache, int regnum)
114 struct gdbarch *gdbarch = get_regcache_arch (regcache);
116 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
120 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
121 (PTRACE_TYPE_ARG3) ®s, 0) == -1)
122 perror_with_name (_("Couldn't get registers"));
124 ppc_collect_gregset (&ppcnbsd_gregset, regcache,
125 regnum, ®s, sizeof regs);
127 if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
128 (PTRACE_TYPE_ARG3) ®s, 0) == -1)
129 perror_with_name (_("Couldn't write registers"));
132 if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
136 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
137 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
138 perror_with_name (_("Couldn't get FP registers"));
140 ppc_collect_fpregset (&ppcnbsd_fpregset, regcache,
141 regnum, &fpregs, sizeof fpregs);
143 if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
144 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
145 perror_with_name (_("Couldn't set FP registers"));
150 ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
152 struct switchframe sf;
154 struct gdbarch *gdbarch = get_regcache_arch (regcache);
155 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
158 /* The stack pointer shouldn't be zero. */
159 if (pcb->pcb_sp == 0)
162 read_memory (pcb->pcb_sp, (gdb_byte *)&sf, sizeof sf);
163 regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr);
164 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2);
165 for (i = 0 ; i < 19 ; i++)
166 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 13 + i,
169 read_memory(sf.sp, (gdb_byte *)&cf, sizeof(cf));
170 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30);
171 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31);
172 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 1, &cf.sp);
174 read_memory(cf.sp, (gdb_byte *)&cf, sizeof(cf));
175 regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr);
176 regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch), &cf.lr);
181 /* Provide a prototype to silence -Wmissing-prototypes. */
182 void _initialize_ppcnbsd_nat (void);
185 _initialize_ppcnbsd_nat (void)
187 struct target_ops *t;
189 /* Support debugging kernel virtual memory images. */
190 bsd_kvm_add_target (ppcnbsd_supply_pcb);
192 /* Add in local overrides. */
193 t = inf_ptrace_target ();
194 t->to_fetch_registers = ppcnbsd_fetch_inferior_registers;
195 t->to_store_registers = ppcnbsd_store_inferior_registers;