1 /* Native-dependent code for FreeBSD/arm.
3 Copyright (C) 2017-2019 Free Software Foundation, 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 3 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, see <http://www.gnu.org/licenses/>. */
22 /* Standard C includes. */
23 #include <machine/reg.h>
24 #include <sys/ptrace.h>
25 #include <sys/types.h>
27 /* Local non-gdb includes. */
28 #include "arm-fbsd-tdep.h"
31 #include "inf-ptrace.h"
34 struct arm_fbsd_nat_target : public fbsd_nat_target
36 void fetch_registers (struct regcache *, int) override;
37 void store_registers (struct regcache *, int) override;
38 const struct target_desc *read_description () override;
41 static arm_fbsd_nat_target the_arm_fbsd_nat_target;
43 /* Determine if PT_GETREGS fetches REGNUM. */
46 getregs_supplies (struct gdbarch *gdbarch, int regnum)
48 return ((regnum >= ARM_A1_REGNUM && regnum <= ARM_PC_REGNUM)
49 || regnum == ARM_PS_REGNUM);
53 /* Determine if PT_GETVFPREGS fetches REGNUM. */
56 getvfpregs_supplies (struct gdbarch *gdbarch, int regnum)
58 return ((regnum >= ARM_D0_REGNUM && regnum <= ARM_D31_REGNUM)
59 || regnum == ARM_FPSCR_REGNUM);
63 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
67 arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
69 pid_t pid = get_ptrace_pid (regcache->ptid ());
71 struct gdbarch *gdbarch = regcache->arch ();
72 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
76 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
77 perror_with_name (_("Couldn't get registers"));
79 regcache->supply_regset (&arm_fbsd_gregset, regnum, ®s,
84 if (regnum == -1 || getvfpregs_supplies (gdbarch, regnum))
86 struct vfpreg vfpregs;
88 if (ptrace (PT_GETVFPREGS, pid, (PTRACE_TYPE_ARG3) &vfpregs, 0) == -1)
89 perror_with_name (_("Couldn't get floating point status"));
91 regcache->supply_regset (&arm_fbsd_vfpregset, regnum, &vfpregs,
97 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
98 this for all registers. */
101 arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
103 pid_t pid = get_ptrace_pid (regcache->ptid ());
105 struct gdbarch *gdbarch = regcache->arch ();
106 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
110 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
111 perror_with_name (_("Couldn't get registers"));
113 regcache->collect_regset (&arm_fbsd_gregset, regnum, ®s,
116 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
117 perror_with_name (_("Couldn't write registers"));
121 if (regnum == -1 || getvfpregs_supplies (gdbarch, regnum))
123 struct vfpreg vfpregs;
125 if (ptrace (PT_GETVFPREGS, pid, (PTRACE_TYPE_ARG3) &vfpregs, 0) == -1)
126 perror_with_name (_("Couldn't get floating point status"));
128 regcache->collect_regset (&arm_fbsd_vfpregset, regnum, &vfpregs,
131 if (ptrace (PT_SETVFPREGS, pid, (PTRACE_TYPE_ARG3) &vfpregs, 0) == -1)
132 perror_with_name (_("Couldn't write floating point status"));
137 /* Implement the to_read_description method. */
139 const struct target_desc *
140 arm_fbsd_nat_target::read_description ()
142 const struct target_desc *desc;
144 desc = arm_fbsd_read_description_auxv (this);
146 desc = this->beneath ()->read_description ();
151 _initialize_arm_fbsd_nat (void)
153 add_inf_child_target (&the_arm_fbsd_nat_target);