GDB (xrefs)
Loading...
Searching...
No Matches
hppa-obsd-nat.c
Go to the documentation of this file.
1/* Native-dependent code for OpenBSD/hppa.
2
3 Copyright (C) 2004-2023 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
35{
36 void fetch_registers (struct regcache *, int) override;
37 void store_registers (struct regcache *, int) override;
38};
39
41
42static int
47
48static int
53
54/* Supply the general-purpose registers stored in GREGS to REGCACHE. */
55
56static void
57hppaobsd_supply_gregset (struct regcache *regcache, const void *gregs)
58{
59 gdb_byte zero[4] = { 0 };
60 const char *regs = gregs;
61 int regnum;
62
65 regcache->raw_supply (regnum, regs + regnum * 4);
66
67 if (sizeof(struct reg) >= 46 * 4)
68 {
70 regcache->raw_supply (HPPA_SAR_REGNUM, regs + 32 * 4);
75 regcache->raw_supply (HPPA_SR0_REGNUM, regs + 37 * 4);
76 regcache->raw_supply (HPPA_SR1_REGNUM, regs + 38 * 4);
77 regcache->raw_supply (HPPA_SR2_REGNUM, regs + 39 * 4);
78 regcache->raw_supply (HPPA_SR3_REGNUM, regs + 40 * 4);
79 regcache->raw_supply (HPPA_SR4_REGNUM, regs + 41 * 4);
80 regcache->raw_supply (HPPA_SR5_REGNUM, regs + 42 * 4);
81 regcache->raw_supply (HPPA_SR6_REGNUM, regs + 43 * 4);
82 regcache->raw_supply (HPPA_SR7_REGNUM, regs + 44 * 4);
83 regcache->raw_supply (HPPA_CR26_REGNUM, regs + 45 * 4);
84 regcache->raw_supply (HPPA_CR27_REGNUM, regs + 46 * 4);
85 }
86 else
87 {
91 }
92}
93
94/* Supply the floating-point registers stored in FPREGS to REGCACHE. */
95
96static void
97hppaobsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
98{
99 const char *regs = fpregs;
100 int regnum;
101
103 regnum += 2, regs += 8)
104 {
105 regcache->raw_supply (regnum, regs);
106 regcache->raw_supply (regnum + 1, regs + 4);
107 }
108}
109
110/* Collect the general-purpose registers from REGCACHE and store them
111 in GREGS. */
112
113static void
115 void *gregs, int regnum)
116{
117 char *regs = gregs;
118 int i;
119
120 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
121 {
122 if (regnum == -1 || regnum == i)
123 regcache->raw_collect (i, regs + i * 4);
124 }
125
126 if (sizeof(struct reg) >= 46 * 4)
127 {
128 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
130 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
131 regcache->raw_collect (HPPA_SAR_REGNUM, regs + 32 * 4);
132 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
134 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
136 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
138 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
140 if (regnum == -1 || regnum == HPPA_SR0_REGNUM)
141 regcache->raw_collect (HPPA_SR0_REGNUM, regs + 37 * 4);
142 if (regnum == -1 || regnum == HPPA_SR1_REGNUM)
143 regcache->raw_collect (HPPA_SR1_REGNUM, regs + 38 * 4);
144 if (regnum == -1 || regnum == HPPA_SR2_REGNUM)
145 regcache->raw_collect (HPPA_SR2_REGNUM, regs + 39 * 4);
146 if (regnum == -1 || regnum == HPPA_SR3_REGNUM)
147 regcache->raw_collect (HPPA_SR3_REGNUM, regs + 40 * 4);
148 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
149 regcache->raw_collect (HPPA_SR4_REGNUM, regs + 41 * 4);
150 if (regnum == -1 || regnum == HPPA_SR5_REGNUM)
151 regcache->raw_collect (HPPA_SR5_REGNUM, regs + 42 * 4);
152 if (regnum == -1 || regnum == HPPA_SR6_REGNUM)
153 regcache->raw_collect (HPPA_SR6_REGNUM, regs + 43 * 4);
154 if (regnum == -1 || regnum == HPPA_SR7_REGNUM)
155 regcache->raw_collect (HPPA_SR7_REGNUM, regs + 44 * 4);
156 if (regnum == -1 || regnum == HPPA_CR26_REGNUM)
157 regcache->raw_collect (HPPA_CR26_REGNUM, regs + 45 * 4);
158 if (regnum == -1 || regnum == HPPA_CR27_REGNUM)
159 regcache->raw_collect (HPPA_CR27_REGNUM, regs + 46 * 4);
160 }
161 else
162 {
163 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
165 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
167 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
169 }
170}
171
172/* Collect the floating-point registers from REGCACHE and store them
173 in FPREGS. */
174
175static void
177 void *fpregs, int regnum)
178{
179 char *regs = fpregs;
180 int i;
181
182 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
183 {
184 if (regnum == -1 || regnum == i || regnum == i + 1)
185 {
186 regcache->raw_collect (i, regs);
187 regcache->raw_collect (i + 1, regs + 4);
188 }
189 }
190}
191
192
193/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
194 for all registers (including the floating-point registers). */
195
196void
198{
199 pid_t pid = regcache->ptid ().pid ();
200
202 {
203 struct reg regs;
204
205 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
206 perror_with_name (_("Couldn't get registers"));
207
209 }
210
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
219 }
220}
221
222/* Store register REGNUM back into the inferior. If REGNUM is -1, do
223 this for all registers (including the floating-point registers). */
224
225void
227{
229 {
230 struct reg regs;
231
232 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
233 perror_with_name (_("Couldn't get registers"));
234
236
237 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
238 perror_with_name (_("Couldn't write registers"));
239 }
240
242 {
243 struct fpreg fpregs;
244
245 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
246 perror_with_name (_("Couldn't get floating point status"));
247
249
250 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
251 perror_with_name (_("Couldn't write floating point status"));
252 }
253}
254
256void
int regnum
void raw_collect(int regnum, void *buf) const override
Definition regcache.c:1127
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
ptid_t ptid() const
Definition regcache.h:408
#define ptrace(request, pid, addr, data)
Definition gdb_ptrace.h:141
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:1791
static void hppaobsd_collect_gregset(const struct regcache *regcache, void *gregs, int regnum)
static void hppaobsd_supply_gregset(struct regcache *regcache, const void *gregs)
static int hppaobsd_gregset_supplies_p(int regnum)
void _initialize_hppaobsd_nat()
static int hppaobsd_fpregset_supplies_p(int regnum)
static void hppaobsd_collect_fpregset(struct regcache *regcache, void *fpregs, int regnum)
static void hppaobsd_supply_fpregset(struct regcache *regcache, const void *fpregs)
static hppa_obsd_nat_target the_hppa_obsd_nat_target
@ HPPA_R31_REGNUM
Definition hppa-tdep.h:43
@ HPPA_R1_REGNUM
Definition hppa-tdep.h:35
@ HPPA_PCSQ_HEAD_REGNUM
Definition hppa-tdep.h:47
@ HPPA_SR2_REGNUM
Definition hppa-tdep.h:57
@ HPPA_SAR_REGNUM
Definition hppa-tdep.h:44
@ HPPA_IPSW_REGNUM
Definition hppa-tdep.h:45
@ HPPA_SR5_REGNUM
Definition hppa-tdep.h:59
@ HPPA_SR1_REGNUM
Definition hppa-tdep.h:56
@ HPPA_FP31R_REGNUM
Definition hppa-tdep.h:75
@ HPPA_CR26_REGNUM
Definition hppa-tdep.h:69
@ HPPA_SR7_REGNUM
Definition hppa-tdep.h:61
@ HPPA_PCOQ_HEAD_REGNUM
Definition hppa-tdep.h:46
@ HPPA_SR6_REGNUM
Definition hppa-tdep.h:60
@ HPPA_PCSQ_TAIL_REGNUM
Definition hppa-tdep.h:49
@ HPPA_PCOQ_TAIL_REGNUM
Definition hppa-tdep.h:48
@ HPPA_CR27_REGNUM
Definition hppa-tdep.h:70
@ HPPA_FP0_REGNUM
Definition hppa-tdep.h:72
@ HPPA_SR0_REGNUM
Definition hppa-tdep.h:55
@ HPPA_SR4_REGNUM
Definition hppa-tdep.h:54
@ HPPA_SR3_REGNUM
Definition hppa-tdep.h:58
@ HPPA_R0_REGNUM
Definition hppa-tdep.h:33
void add_inf_child_target(inf_child_target *target)
Definition inf-child.c:418
#define PTRACE_TYPE_ARG3
void store_registers(struct regcache *, int) override
void fetch_registers(struct regcache *, int) override