f0b07804bb4ee54309ce37601ea3a17cc3e50abf
[deliverable/binutils-gdb.git] / gdb / arm-fbsd-nat.c
1 /* Native-dependent code for FreeBSD/arm.
2
3 Copyright (C) 2017-2019 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21
22 /* Standard C includes. */
23 #include <machine/reg.h>
24 #include <sys/ptrace.h>
25 #include <sys/types.h>
26
27 /* Local non-gdb includes. */
28 #include "arm-fbsd-tdep.h"
29 #include "arm-tdep.h"
30 #include "fbsd-nat.h"
31 #include "inf-ptrace.h"
32 #include "target.h"
33
34 struct arm_fbsd_nat_target : public fbsd_nat_target
35 {
36 void fetch_registers (struct regcache *, int) override;
37 void store_registers (struct regcache *, int) override;
38 const struct target_desc *read_description () override;
39 };
40
41 static arm_fbsd_nat_target the_arm_fbsd_nat_target;
42
43 /* Determine if PT_GETREGS fetches REGNUM. */
44
45 static bool
46 getregs_supplies (struct gdbarch *gdbarch, int regnum)
47 {
48 return ((regnum >= ARM_A1_REGNUM && regnum <= ARM_PC_REGNUM)
49 || regnum == ARM_PS_REGNUM);
50 }
51
52 #ifdef PT_GETVFPREGS
53 /* Determine if PT_GETVFPREGS fetches REGNUM. */
54
55 static bool
56 getvfpregs_supplies (struct gdbarch *gdbarch, int regnum)
57 {
58 return ((regnum >= ARM_D0_REGNUM && regnum <= ARM_D31_REGNUM)
59 || regnum == ARM_FPSCR_REGNUM);
60 }
61 #endif
62
63 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
64 for all registers. */
65
66 void
67 arm_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
68 {
69 pid_t pid = get_ptrace_pid (regcache->ptid ());
70
71 struct gdbarch *gdbarch = regcache->arch ();
72 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
73 {
74 struct reg regs;
75
76 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
77 perror_with_name (_("Couldn't get registers"));
78
79 regcache->supply_regset (&arm_fbsd_gregset, regnum, &regs,
80 sizeof (regs));
81 }
82
83 #ifdef PT_GETVFPREGS
84 if (regnum == -1 || getvfpregs_supplies (gdbarch, regnum))
85 {
86 struct vfpreg vfpregs;
87
88 if (ptrace (PT_GETVFPREGS, pid, (PTRACE_TYPE_ARG3) &vfpregs, 0) == -1)
89 perror_with_name (_("Couldn't get floating point status"));
90
91 regcache->supply_regset (&arm_fbsd_vfpregset, regnum, &vfpregs,
92 sizeof (vfpregs));
93 }
94 #endif
95 }
96
97 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
98 this for all registers. */
99
100 void
101 arm_fbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
102 {
103 pid_t pid = get_ptrace_pid (regcache->ptid ());
104
105 struct gdbarch *gdbarch = regcache->arch ();
106 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
107 {
108 struct reg regs;
109
110 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
111 perror_with_name (_("Couldn't get registers"));
112
113 regcache->collect_regset (&arm_fbsd_gregset, regnum, &regs,
114 sizeof (regs));
115
116 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
117 perror_with_name (_("Couldn't write registers"));
118 }
119
120 #ifdef PT_GETVFPREGS
121 if (regnum == -1 || getvfpregs_supplies (gdbarch, regnum))
122 {
123 struct vfpreg vfpregs;
124
125 if (ptrace (PT_GETVFPREGS, pid, (PTRACE_TYPE_ARG3) &vfpregs, 0) == -1)
126 perror_with_name (_("Couldn't get floating point status"));
127
128 regcache->collect_regset (&arm_fbsd_vfpregset, regnum, &vfpregs,
129 sizeof (vfpregs));
130
131 if (ptrace (PT_SETVFPREGS, pid, (PTRACE_TYPE_ARG3) &vfpregs, 0) == -1)
132 perror_with_name (_("Couldn't write floating point status"));
133 }
134 #endif
135 }
136
137 /* Implement the to_read_description method. */
138
139 const struct target_desc *
140 arm_fbsd_nat_target::read_description ()
141 {
142 const struct target_desc *desc;
143
144 desc = arm_fbsd_read_description_auxv (this);
145 if (desc == NULL)
146 desc = this->beneath ()->read_description ();
147 return desc;
148 }
149
150 void
151 _initialize_arm_fbsd_nat (void)
152 {
153 add_inf_child_target (&the_arm_fbsd_nat_target);
154 }
This page took 0.03631 seconds and 4 git commands to generate.