GDB (xrefs)

/tmp/gdb-8.1/gdb/hppa-nbsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for NetBSD/hppa.
2
3 Copyright (C) 2008-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
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
33 static int
34 hppanbsd_gregset_supplies_p (int regnum)
35 {
36 return ((regnum >= HPPA_R0_REGNUM && regnum <= HPPA_R31_REGNUM) ||
37 (regnum >= HPPA_SAR_REGNUM && regnum <= HPPA_PCSQ_TAIL_REGNUM) ||
38 regnum == HPPA_IPSW_REGNUM ||
39 (regnum >= HPPA_SR4_REGNUM && regnum <= HPPA_SR4_REGNUM + 5));
40 }
41
42 static int
43 hppanbsd_fpregset_supplies_p (int regnum)
44 {
45 return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
46 }
47
48 /* Supply the general-purpose registers stored in GREGS to REGCACHE. */
49
50 static void
51 hppanbsd_supply_gregset (struct regcache *regcache, const void *gregs)
52 {
53 const char *regs = gregs;
54 const int *r = gregs;
55 int regnum;
56
57 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
58 regcache_raw_supply (regcache, regnum, regs + regnum * 4);
59
60 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
61 regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
62 regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
63 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
64 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
65 regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
66 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
67 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
68 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
69 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
70 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
71 }
72
73 /* Supply the floating-point registers stored in FPREGS to REGCACHE. */
74
75 static void
76 hppanbsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
77 {
78 const char *regs = fpregs;
79 int regnum;
80
81 for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
82 regnum += 2, regs += 8)
83 {
84 regcache_raw_supply (regcache, regnum, regs);
85 regcache_raw_supply (regcache, regnum + 1, regs + 4);
86 }
87 }
88
89 /* Collect the general-purpose registers from REGCACHE and store them
90 in GREGS. */
91
92 static void
93 hppanbsd_collect_gregset (const struct regcache *regcache,
94 void *gregs, int regnum)
95 {
96 char *regs = gregs;
97 int *r = gregs;
98 int i;
99
100 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
101 {
102 if (regnum == -1 || regnum == i)
103 regcache_raw_collect (regcache, i, regs + i * 4);
104 }
105
106 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
107 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
108 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
109 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
110 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
111 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
112
113 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
114 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
115 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
116 regcache_raw_collect (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
117 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
118 regcache_raw_collect (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
119 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
120 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
121 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
122 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
123 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
124 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
125 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
126 regcache_raw_collect (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
127 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 1)
128 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
129 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 2)
130 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
131 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 3)
132 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
133 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 4)
134 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
135 }
136
137 /* Collect the floating-point registers from REGCACHE and store them
138 in FPREGS. */
139
140 static void
141 hppanbsd_collect_fpregset (struct regcache *regcache,
142 void *fpregs, int regnum)
143 {
144 char *regs = fpregs;
145 int i;
146
147 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
148 {
149 if (regnum == -1 || regnum == i || regnum == i + 1)
150 {
151 regcache_raw_collect (regcache, i, regs);
152 regcache_raw_collect (regcache, i + 1, regs + 4);
153 }
154 }
155 }
156
157
158 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
159 for all registers (including the floating-point registers). */
160
161 static void
162 hppanbsd_fetch_registers (struct target_ops *ops,
163 struct regcache *regcache, int regnum)
164
165 {
166 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
167
168 if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
169 {
170 struct reg regs;
171
172 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
173 perror_with_name (_("Couldn't get registers"));
174
175 hppanbsd_supply_gregset (regcache, &regs);
176 }
177
178 if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
179 {
180 struct fpreg fpregs;
181
182 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
183 perror_with_name (_("Couldn't get floating point status"));
184
185 hppanbsd_supply_fpregset (regcache, &fpregs);
186 }
187 }
188
189 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
190 this for all registers (including the floating-point registers). */
191
192 static void
193 hppanbsd_store_registers (struct target_ops *ops,
194 struct regcache *regcache, int regnum)
195 {
196 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
197
198 if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
199 {
200 struct reg regs;
201
202 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
203 perror_with_name (_("Couldn't get registers"));
204
205 hppanbsd_collect_gregset (regcache, &regs, regnum);
206
207 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
208 perror_with_name (_("Couldn't write registers"));
209 }
210
211 if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
212 {
213 struct fpreg fpregs;
214
215 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
216 perror_with_name (_("Couldn't get floating point status"));
217
218 hppanbsd_collect_fpregset (regcache, &fpregs, regnum);
219
220 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
221 perror_with_name (_("Couldn't write floating point status"));
222 }
223 }
224
225 void
226 _initialize_hppanbsd_nat (void)
227 {
228 struct target_ops *t;
229
230 /* Add some extra features to the ptrace target. */
231 t = inf_ptrace_target ();
232
233 t->to_fetch_registers = hppanbsd_fetch_registers;
234 t->to_store_registers = hppanbsd_store_registers;
235
236 t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
237
238 add_target (t);
239 }
add_target
void add_target(struct target_ops *t)
Definition: target.c:395
_initialize_hppanbsd_nat
void _initialize_hppanbsd_nat(void)
Definition: hppa-nbsd-nat.c:226
nbsd_pid_to_exec_file
char * nbsd_pid_to_exec_file(struct target_ops *self, int pid)
Definition: nbsd-nat.c:28
hppa-tdep.h
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
hppanbsd_collect_fpregset
static void hppanbsd_collect_fpregset(struct regcache *regcache, void *fpregs, int regnum)
Definition: hppa-nbsd-nat.c:141
hppanbsd_gregset_supplies_p
static int hppanbsd_gregset_supplies_p(int regnum)
Definition: hppa-nbsd-nat.c:34
regcache_get_ptid
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
HPPA_PCOQ_TAIL_REGNUM
Definition: hppa-tdep.h:46
HPPA_PCOQ_HEAD_REGNUM
Definition: hppa-tdep.h:44
hppanbsd_fetch_registers
static void hppanbsd_fetch_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: hppa-nbsd-nat.c:162
_
#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
regcache.h
HPPA_IPSW_REGNUM
Definition: hppa-tdep.h:43
HPPA_FP0_REGNUM
Definition: hppa-tdep.h:70
inferior.h
hppanbsd_store_registers
static void hppanbsd_store_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: hppa-nbsd-nat.c:193
regnum
int regnum
Definition: aarch64-tdep.c:77
HPPA_SR4_REGNUM
Definition: hppa-tdep.h:52
HPPA_R31_REGNUM
Definition: hppa-tdep.h:41
target_ops::to_pid_to_exec_file
char *(* to_pid_to_exec_file)(struct target_ops *, int pid) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:650
nbsd-nat.h
reg
Definition: regdef.h:22
hppanbsd_supply_fpregset
static void hppanbsd_supply_fpregset(struct regcache *regcache, const void *fpregs)
Definition: hppa-nbsd-nat.c:76
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
hppanbsd_supply_gregset
static void hppanbsd_supply_gregset(struct regcache *regcache, const void *gregs)
Definition: hppa-nbsd-nat.c:51
HPPA_FP31R_REGNUM
Definition: hppa-tdep.h:73
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
regcache
Definition: regcache.h:232
hppanbsd_fpregset_supplies_p
static int hppanbsd_fpregset_supplies_p(int regnum)
Definition: hppa-nbsd-nat.c:43
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
hppanbsd_collect_gregset
static void hppanbsd_collect_gregset(const struct regcache *regcache, void *gregs, int regnum)
Definition: hppa-nbsd-nat.c:93