1 /* Native-dependent code for NetBSD/powerpc.
3 Copyright (C) 2002-2020 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/>. */
22 /* We define this to get types like register_t. */
26 #include <sys/types.h>
27 #include <sys/ptrace.h>
28 #include <machine/reg.h>
29 #include <machine/frame.h>
30 #include <machine/pcb.h>
37 #include "ppc-nbsd-tdep.h"
39 #include "inf-ptrace.h"
41 struct ppc_nbsd_nat_target final
: public inf_ptrace_target
43 void fetch_registers (struct regcache
*, int) override
;
44 void store_registers (struct regcache
*, int) override
;
47 static ppc_nbsd_nat_target the_ppc_nbsd_nat_target
;
49 /* Returns true if PT_GETREGS fetches this register. */
52 getregs_supplies (struct gdbarch
*gdbarch
, int regnum
)
54 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
56 return ((regnum
>= tdep
->ppc_gp0_regnum
57 && regnum
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
)
58 || regnum
== tdep
->ppc_lr_regnum
59 || regnum
== tdep
->ppc_cr_regnum
60 || regnum
== tdep
->ppc_xer_regnum
61 || regnum
== tdep
->ppc_ctr_regnum
62 || regnum
== gdbarch_pc_regnum (gdbarch
));
65 /* Like above, but for PT_GETFPREGS. */
68 getfpregs_supplies (struct gdbarch
*gdbarch
, int regnum
)
70 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
72 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
73 point registers. Traditionally, GDB's register set has still
74 listed the floating point registers for such machines, so this
75 code is harmless. However, the new E500 port actually omits the
76 floating point registers entirely from the register set --- they
77 don't even have register numbers assigned to them.
79 It's not clear to me how best to update this code, so this assert
80 will alert the first person to encounter the NetBSD/E500
81 combination to the problem. */
82 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
84 return ((regnum
>= tdep
->ppc_fp0_regnum
85 && regnum
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
86 || regnum
== tdep
->ppc_fpscr_regnum
);
90 ppc_nbsd_nat_target::fetch_registers (struct regcache
*regcache
, int regnum
)
92 struct gdbarch
*gdbarch
= regcache
->arch ();
93 pid_t pid
= regcache
->ptid ().pid ();
95 if (regnum
== -1 || getregs_supplies (gdbarch
, regnum
))
99 if (ptrace (PT_GETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
100 perror_with_name (_("Couldn't get registers"));
102 ppc_supply_gregset (&ppcnbsd_gregset
, regcache
,
103 regnum
, ®s
, sizeof regs
);
106 if (regnum
== -1 || getfpregs_supplies (gdbarch
, regnum
))
110 if (ptrace (PT_GETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
111 perror_with_name (_("Couldn't get FP registers"));
113 ppc_supply_fpregset (&ppcnbsd_fpregset
, regcache
,
114 regnum
, &fpregs
, sizeof fpregs
);
119 ppc_nbsd_nat_target::store_registers (struct regcache
*regcache
, int regnum
)
121 struct gdbarch
*gdbarch
= regcache
->arch ();
122 pid_t pid
= regcache
->ptid ().pid ();
124 if (regnum
== -1 || getregs_supplies (gdbarch
, regnum
))
128 if (ptrace (PT_GETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
129 perror_with_name (_("Couldn't get registers"));
131 ppc_collect_gregset (&ppcnbsd_gregset
, regcache
,
132 regnum
, ®s
, sizeof regs
);
134 if (ptrace (PT_SETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
135 perror_with_name (_("Couldn't write registers"));
138 if (regnum
== -1 || getfpregs_supplies (gdbarch
, regnum
))
142 if (ptrace (PT_GETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
143 perror_with_name (_("Couldn't get FP registers"));
145 ppc_collect_fpregset (&ppcnbsd_fpregset
, regcache
,
146 regnum
, &fpregs
, sizeof fpregs
);
148 if (ptrace (PT_SETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
149 perror_with_name (_("Couldn't set FP registers"));
154 ppcnbsd_supply_pcb (struct regcache
*regcache
, struct pcb
*pcb
)
156 struct switchframe sf
;
158 struct gdbarch
*gdbarch
= regcache
->arch ();
159 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
162 /* The stack pointer shouldn't be zero. */
163 if (pcb
->pcb_sp
== 0)
166 read_memory (pcb
->pcb_sp
, (gdb_byte
*)&sf
, sizeof sf
);
167 regcache
->raw_supply (tdep
->ppc_cr_regnum
, &sf
.cr
);
168 regcache
->raw_supply (tdep
->ppc_gp0_regnum
+ 2, &sf
.fixreg2
);
169 for (i
= 0 ; i
< 19 ; i
++)
170 regcache
->raw_supply (tdep
->ppc_gp0_regnum
+ 13 + i
, &sf
.fixreg
[i
]);
172 read_memory(sf
.sp
, (gdb_byte
*)&cf
, sizeof(cf
));
173 regcache
->raw_supply (tdep
->ppc_gp0_regnum
+ 30, &cf
.r30
);
174 regcache
->raw_supply (tdep
->ppc_gp0_regnum
+ 31, &cf
.r31
);
175 regcache
->raw_supply (tdep
->ppc_gp0_regnum
+ 1, &cf
.sp
);
177 read_memory(cf
.sp
, (gdb_byte
*)&cf
, sizeof(cf
));
178 regcache
->raw_supply (tdep
->ppc_lr_regnum
, &cf
.lr
);
179 regcache
->raw_supply (gdbarch_pc_regnum (gdbarch
), &cf
.lr
);
184 void _initialize_ppcnbsd_nat ();
186 _initialize_ppcnbsd_nat ()
188 /* Support debugging kernel virtual memory images. */
189 bsd_kvm_add_target (ppcnbsd_supply_pcb
);
191 add_inf_child_target (&the_ppc_nbsd_nat_target
);