Remove regcache_cooked_write_part
[deliverable/binutils-gdb.git] / gdb / hppa-nbsd-nat.c
CommitLineData
af5ca30d
NH
1/* Native-dependent code for NetBSD/hppa.
2
e2882c85 3 Copyright (C) 2008-2018 Free Software Foundation, Inc.
af5ca30d
NH
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
5b1ba0e5 9 the Free Software Foundation; either version 3 of the License, or
af5ca30d
NH
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
5b1ba0e5 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
af5ca30d
NH
19
20#include "defs.h"
21#include "inferior.h"
22#include "regcache.h"
23
24#include <sys/types.h>
25#include <sys/ptrace.h>
26#include <machine/reg.h>
27
28#include "hppa-tdep.h"
29#include "inf-ptrace.h"
30
31#include "nbsd-nat.h"
32
f6ac5f3d
PA
33class hppa_nbsd_nat_target final : public nbsd_nat_target
34{
35 void fetch_registers (struct regcache *, int) override;
36 void store_registers (struct regcache *, int) override;
37};
38
39static hppa_nbsd_nat_target the_hppa_nbsd_nat_target;
40
af5ca30d
NH
41static int
42hppanbsd_gregset_supplies_p (int regnum)
43{
44 return ((regnum >= HPPA_R0_REGNUM && regnum <= HPPA_R31_REGNUM) ||
45 (regnum >= HPPA_SAR_REGNUM && regnum <= HPPA_PCSQ_TAIL_REGNUM) ||
46 regnum == HPPA_IPSW_REGNUM ||
47 (regnum >= HPPA_SR4_REGNUM && regnum <= HPPA_SR4_REGNUM + 5));
48}
49
50static int
51hppanbsd_fpregset_supplies_p (int regnum)
52{
53 return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
54}
55
56/* Supply the general-purpose registers stored in GREGS to REGCACHE. */
57
58static void
59hppanbsd_supply_gregset (struct regcache *regcache, const void *gregs)
60{
61 const char *regs = gregs;
62 const int *r = gregs;
63 int regnum;
64
65 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
66 regcache_raw_supply (regcache, regnum, regs + regnum * 4);
67
68 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
69 regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
70 regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
71 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
72 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
73 regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
74 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
75 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
76 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
77 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
78 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
79}
80
81/* Supply the floating-point registers stored in FPREGS to REGCACHE. */
82
83static void
84hppanbsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
85{
86 const char *regs = fpregs;
87 int regnum;
88
89 for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
90 regnum += 2, regs += 8)
91 {
92 regcache_raw_supply (regcache, regnum, regs);
93 regcache_raw_supply (regcache, regnum + 1, regs + 4);
94 }
95}
96
97/* Collect the general-purpose registers from REGCACHE and store them
98 in GREGS. */
99
100static void
101hppanbsd_collect_gregset (const struct regcache *regcache,
102 void *gregs, int regnum)
103{
104 char *regs = gregs;
105 int *r = gregs;
106 int i;
107
108 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
109 {
110 if (regnum == -1 || regnum == i)
111 regcache_raw_collect (regcache, i, regs + i * 4);
112 }
113
114 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
115 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
116 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
117 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
118 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
119 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
120
121 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
122 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
123 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
124 regcache_raw_collect (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
125 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
126 regcache_raw_collect (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
127 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
128 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
129 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
130 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
131 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
132 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
133 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
134 regcache_raw_collect (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
135 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 1)
136 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
137 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 2)
138 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
139 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 3)
140 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
141 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 4)
142 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
143}
144
145/* Collect the floating-point registers from REGCACHE and store them
146 in FPREGS. */
147
148static void
149hppanbsd_collect_fpregset (struct regcache *regcache,
150 void *fpregs, int regnum)
151{
152 char *regs = fpregs;
153 int i;
154
155 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
156 {
157 if (regnum == -1 || regnum == i || regnum == i + 1)
158 {
159 regcache_raw_collect (regcache, i, regs);
160 regcache_raw_collect (regcache, i + 1, regs + 4);
161 }
162 }
163}
164\f
165
166/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
167 for all registers (including the floating-point registers). */
168
f6ac5f3d
PA
169void
170hppa_nbsd_nat_target::fetch_registers (struct regcache *regcache, int regnum)
af5ca30d
NH
171
172{
222312d3 173 pid_t pid = ptid_get_pid (regcache->ptid ());
10799020 174
af5ca30d
NH
175 if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
176 {
177 struct reg regs;
178
10799020 179 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
af5ca30d
NH
180 perror_with_name (_("Couldn't get registers"));
181
182 hppanbsd_supply_gregset (regcache, &regs);
183 }
184
185 if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
186 {
187 struct fpreg fpregs;
188
10799020 189 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
af5ca30d
NH
190 perror_with_name (_("Couldn't get floating point status"));
191
192 hppanbsd_supply_fpregset (regcache, &fpregs);
193 }
194}
195
196/* Store register REGNUM back into the inferior. If REGNUM is -1, do
197 this for all registers (including the floating-point registers). */
198
f6ac5f3d
PA
199void
200hppa_nbsd_nat_target::store_registers (struct regcache *regcache, int regnum)
af5ca30d 201{
222312d3 202 pid_t pid = ptid_get_pid (regcache->ptid ());
10799020 203
af5ca30d
NH
204 if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
205 {
206 struct reg regs;
207
10799020 208 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
af5ca30d
NH
209 perror_with_name (_("Couldn't get registers"));
210
211 hppanbsd_collect_gregset (regcache, &regs, regnum);
212
10799020 213 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
af5ca30d
NH
214 perror_with_name (_("Couldn't write registers"));
215 }
216
217 if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
218 {
219 struct fpreg fpregs;
220
10799020 221 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
af5ca30d
NH
222 perror_with_name (_("Couldn't get floating point status"));
223
224 hppanbsd_collect_fpregset (regcache, &fpregs, regnum);
225
10799020 226 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
af5ca30d
NH
227 perror_with_name (_("Couldn't write floating point status"));
228 }
229}
230
af5ca30d
NH
231void
232_initialize_hppanbsd_nat (void)
233{
d9f719f1 234 add_inf_child_target (&the_hppa_nbsd_nat_target);
af5ca30d 235}
This page took 0.854003 seconds and 4 git commands to generate.