GDB (xrefs)

/tmp/gdb-8.1/gdb/hppa-obsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for OpenBSD/hppa.
2
3 Copyright (C) 2004-2018 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 #include "inferior.h"
22 #include "regcache.h"
23 #include "target.h"
24
25 #include <sys/types.h>
26 #include <sys/ptrace.h>
27 #include <machine/reg.h>
28
29 #include "hppa-tdep.h"
30 #include "inf-ptrace.h"
31
32 #include "obsd-nat.h"
33
34 static int
35 hppaobsd_gregset_supplies_p (int regnum)
36 {
37 return (regnum >= HPPA_R0_REGNUM && regnum <= HPPA_CR27_REGNUM);
38 }
39
40 static int
41 hppaobsd_fpregset_supplies_p (int regnum)
42 {
43 return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
44 }
45
46 /* Supply the general-purpose registers stored in GREGS to REGCACHE. */
47
48 static void
49 hppaobsd_supply_gregset (struct regcache *regcache, const void *gregs)
50 {
51 gdb_byte zero[4] = { 0 };
52 const char *regs = gregs;
53 int regnum;
54
55 regcache_raw_supply (regcache, HPPA_R0_REGNUM, &zero);
56 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
57 regcache_raw_supply (regcache, regnum, regs + regnum * 4);
58
59 if (sizeof(struct reg) >= 46 * 4)
60 {
61 regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
62 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
63 regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
64 regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
65 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
66 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
67 regcache_raw_supply (regcache, HPPA_SR0_REGNUM, regs + 37 * 4);
68 regcache_raw_supply (regcache, HPPA_SR1_REGNUM, regs + 38 * 4);
69 regcache_raw_supply (regcache, HPPA_SR2_REGNUM, regs + 39 * 4);
70 regcache_raw_supply (regcache, HPPA_SR3_REGNUM, regs + 40 * 4);
71 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
72 regcache_raw_supply (regcache, HPPA_SR5_REGNUM, regs + 42 * 4);
73 regcache_raw_supply (regcache, HPPA_SR6_REGNUM, regs + 43 * 4);
74 regcache_raw_supply (regcache, HPPA_SR7_REGNUM, regs + 44 * 4);
75 regcache_raw_supply (regcache, HPPA_CR26_REGNUM, regs + 45 * 4);
76 regcache_raw_supply (regcache, HPPA_CR27_REGNUM, regs + 46 * 4);
77 }
78 else
79 {
80 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs);
81 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
82 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
83 }
84 }
85
86 /* Supply the floating-point registers stored in FPREGS to REGCACHE. */
87
88 static void
89 hppaobsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
90 {
91 const char *regs = fpregs;
92 int regnum;
93
94 for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
95 regnum += 2, regs += 8)
96 {
97 regcache_raw_supply (regcache, regnum, regs);
98 regcache_raw_supply (regcache, regnum + 1, regs + 4);
99 }
100 }
101
102 /* Collect the general-purpose registers from REGCACHE and store them
103 in GREGS. */
104
105 static void
106 hppaobsd_collect_gregset (const struct regcache *regcache,
107 void *gregs, int regnum)
108 {
109 char *regs = gregs;
110 int i;
111
112 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
113 {
114 if (regnum == -1 || regnum == i)
115 regcache_raw_collect (regcache, i, regs + i * 4);
116 }
117
118 if (sizeof(struct reg) >= 46 * 4)
119 {
120 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
121 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
122 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
123 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
124 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
125 regcache_raw_collect (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
126 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
127 regcache_raw_collect (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
128 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
129 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
130 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
131 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
132 if (regnum == -1 || regnum == HPPA_SR0_REGNUM)
133 regcache_raw_collect (regcache, HPPA_SR0_REGNUM, regs + 37 * 4);
134 if (regnum == -1 || regnum == HPPA_SR1_REGNUM)
135 regcache_raw_collect (regcache, HPPA_SR1_REGNUM, regs + 38 * 4);
136 if (regnum == -1 || regnum == HPPA_SR2_REGNUM)
137 regcache_raw_collect (regcache, HPPA_SR2_REGNUM, regs + 39 * 4);
138 if (regnum == -1 || regnum == HPPA_SR3_REGNUM)
139 regcache_raw_collect (regcache, HPPA_SR3_REGNUM, regs + 40 * 4);
140 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
141 regcache_raw_collect (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
142 if (regnum == -1 || regnum == HPPA_SR5_REGNUM)
143 regcache_raw_collect (regcache, HPPA_SR5_REGNUM, regs + 42 * 4);
144 if (regnum == -1 || regnum == HPPA_SR6_REGNUM)
145 regcache_raw_collect (regcache, HPPA_SR6_REGNUM, regs + 43 * 4);
146 if (regnum == -1 || regnum == HPPA_SR7_REGNUM)
147 regcache_raw_collect (regcache, HPPA_SR7_REGNUM, regs + 44 * 4);
148 if (regnum == -1 || regnum == HPPA_CR26_REGNUM)
149 regcache_raw_collect (regcache, HPPA_CR26_REGNUM, regs + 45 * 4);
150 if (regnum == -1 || regnum == HPPA_CR27_REGNUM)
151 regcache_raw_collect (regcache, HPPA_CR27_REGNUM, regs + 46 * 4);
152 }
153 else
154 {
155 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
156 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs);
157 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
158 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
159 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
160 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
161 }
162 }
163
164 /* Collect the floating-point registers from REGCACHE and store them
165 in FPREGS. */
166
167 static void
168 hppaobsd_collect_fpregset (struct regcache *regcache,
169 void *fpregs, int regnum)
170 {
171 char *regs = fpregs;
172 int i;
173
174 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
175 {
176 if (regnum == -1 || regnum == i || regnum == i + 1)
177 {
178 regcache_raw_collect (regcache, i, regs);
179 regcache_raw_collect (regcache, i + 1, regs + 4);
180 }
181 }
182 }
183
184
185 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
186 for all registers (including the floating-point registers). */
187
188 static void
189 hppaobsd_fetch_registers (struct target_ops *ops,
190 struct regcache *regcache, int regnum)
191 {
192 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
193
194 if (regnum == -1 || hppaobsd_gregset_supplies_p (regnum))
195 {
196 struct reg regs;
197
198 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
199 perror_with_name (_("Couldn't get registers"));
200
201 hppaobsd_supply_gregset (regcache, &regs);
202 }
203
204 if (regnum == -1 || hppaobsd_fpregset_supplies_p (regnum))
205 {
206 struct fpreg fpregs;
207
208 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
209 perror_with_name (_("Couldn't get floating point status"));
210
211 hppaobsd_supply_fpregset (regcache, &fpregs);
212 }
213 }
214
215 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
216 this for all registers (including the floating-point registers). */
217
218 static void
219 hppaobsd_store_registers (struct target_ops *ops,
220 struct regcache *regcache, int regnum)
221 {
222 if (regnum == -1 || hppaobsd_gregset_supplies_p (regnum))
223 {
224 struct reg regs;
225
226 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
227 perror_with_name (_("Couldn't get registers"));
228
229 hppaobsd_collect_gregset (regcache, &regs, regnum);
230
231 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
232 perror_with_name (_("Couldn't write registers"));
233 }
234
235 if (regnum == -1 || hppaobsd_fpregset_supplies_p (regnum))
236 {
237 struct fpreg fpregs;
238
239 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
240 perror_with_name (_("Couldn't get floating point status"));
241
242 hppaobsd_collect_fpregset (regcache, &fpregs, regnum);
243
244 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
245 perror_with_name (_("Couldn't write floating point status"));
246 }
247 }
248
249 void
250 _initialize_hppaobsd_nat (void)
251 {
252 struct target_ops *t;
253
254 t = inf_ptrace_target ();
255 t->to_fetch_registers = hppaobsd_fetch_registers;
256 t->to_store_registers = hppaobsd_store_registers;
257 obsd_add_target (t);
258 }
hppaobsd_supply_fpregset
static void hppaobsd_supply_fpregset(struct regcache *regcache, const void *fpregs)
Definition: hppa-obsd-nat.c:89
hppaobsd_gregset_supplies_p
static int hppaobsd_gregset_supplies_p(int regnum)
Definition: hppa-obsd-nat.c:35
HPPA_SR2_REGNUM
Definition: hppa-tdep.h:55
HPPA_SR5_REGNUM
Definition: hppa-tdep.h:57
hppa-tdep.h
obsd_add_target
void obsd_add_target(struct target_ops *t)
Definition: obsd-nat.c:181
ptid_get_pid
int ptid_get_pid(const ptid_t &ptid)
Definition: ptid.c:47
pid
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition: gnu-nat.c:1824
HPPA_SR1_REGNUM
Definition: hppa-tdep.h:54
regcache_get_ptid
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
HPPA_SR0_REGNUM
Definition: hppa-tdep.h:53
HPPA_PCOQ_TAIL_REGNUM
Definition: hppa-tdep.h:46
obsd-nat.h
HPPA_PCOQ_HEAD_REGNUM
Definition: hppa-tdep.h:44
_
#define _(String)
Definition: gdb_locale.h:35
inf_ptrace_target
struct target_ops * inf_ptrace_target(void)
Definition: inf-ptrace.c:676
HPPA_R0_REGNUM
Definition: hppa-tdep.h:31
defs.h
HPPA_R1_REGNUM
Definition: hppa-tdep.h:33
ptrace
PTRACE_TYPE_RET ptrace()
HPPA_SAR_REGNUM
Definition: hppa-tdep.h:42
inf-ptrace.h
target_ops
Definition: target.h:412
HPPA_PCSQ_HEAD_REGNUM
Definition: hppa-tdep.h:45
HPPA_CR26_REGNUM
Definition: hppa-tdep.h:67
regcache.h
HPPA_IPSW_REGNUM
Definition: hppa-tdep.h:43
HPPA_FP0_REGNUM
Definition: hppa-tdep.h:70
HPPA_SR3_REGNUM
Definition: hppa-tdep.h:56
inferior.h
hppaobsd_collect_fpregset
static void hppaobsd_collect_fpregset(struct regcache *regcache, void *fpregs, int regnum)
Definition: hppa-obsd-nat.c:168
HPPA_SR7_REGNUM
Definition: hppa-tdep.h:59
hppaobsd_store_registers
static void hppaobsd_store_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: hppa-obsd-nat.c:219
hppaobsd_fetch_registers
static void hppaobsd_fetch_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: hppa-obsd-nat.c:189
regnum
int regnum
Definition: aarch64-tdep.c:77
_initialize_hppaobsd_nat
void _initialize_hppaobsd_nat(void)
Definition: hppa-obsd-nat.c:250
HPPA_SR4_REGNUM
Definition: hppa-tdep.h:52
HPPA_R31_REGNUM
Definition: hppa-tdep.h:41
hppaobsd_collect_gregset
static void hppaobsd_collect_gregset(const struct regcache *regcache, void *gregs, int regnum)
Definition: hppa-obsd-nat.c:106
reg
Definition: regdef.h:22
HPPA_CR27_REGNUM
Definition: hppa-tdep.h:68
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
target_ops::to_fetch_registers
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:457
perror_with_name
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
hppaobsd_fpregset_supplies_p
static int hppaobsd_fpregset_supplies_p(int regnum)
Definition: hppa-obsd-nat.c:41
target.h
HPPA_FP31R_REGNUM
Definition: hppa-tdep.h:73
hppaobsd_supply_gregset
static void hppaobsd_supply_gregset(struct regcache *regcache, const void *gregs)
Definition: hppa-obsd-nat.c:49
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
regcache
Definition: regcache.h:232
regcache_raw_collect
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1085
HPPA_PCSQ_TAIL_REGNUM
Definition: hppa-tdep.h:47
PTRACE_TYPE_ARG3
#define PTRACE_TYPE_ARG3
Definition: config.h:642
target_ops::to_store_registers
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:459
HPPA_SR6_REGNUM
Definition: hppa-tdep.h:58