GDB (xrefs)
Loading...
Searching...
No Matches
hppa-netbsd-nat.c
Go to the documentation of this file.
1/* Native-dependent code for NetBSD/hppa.
2
3 Copyright (C) 2008-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
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 "netbsd-nat.h"
32
34{
35 void fetch_registers (struct regcache *, int) override;
36 void store_registers (struct regcache *, int) override;
37};
38
40
41static int
49
50static int
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
66 regcache->raw_supply (regnum, regs + regnum * 4);
67
68 regcache->raw_supply (HPPA_SAR_REGNUM, regs + 32 * 4);
74 regcache->raw_supply (HPPA_SR4_REGNUM, regs + 41 * 4);
75 regcache->raw_supply (HPPA_SR4_REGNUM + 1, regs + 37 * 4);
76 regcache->raw_supply (HPPA_SR4_REGNUM + 2, regs + 38 * 4);
77 regcache->raw_supply (HPPA_SR4_REGNUM + 3, regs + 39 * 4);
78 regcache->raw_supply (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
90 regnum += 2, regs += 8)
91 {
92 regcache->raw_supply (regnum, regs);
93 regcache->raw_supply (regnum + 1, regs + 4);
94 }
95}
96
97/* Collect the general-purpose registers from REGCACHE and store them
98 in GREGS. */
99
100static void
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 (i, regs + i * 4);
112 }
113
114 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
116 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
118 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
120
121 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
122 regcache->raw_collect (HPPA_SAR_REGNUM, regs + 32 * 4);
123 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
125 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
127 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
129 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
131 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
133 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
134 regcache->raw_collect (HPPA_SR4_REGNUM, regs + 41 * 4);
135 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 1)
136 regcache->raw_collect (HPPA_SR4_REGNUM + 1, regs + 37 * 4);
137 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 2)
138 regcache->raw_collect (HPPA_SR4_REGNUM + 2, regs + 38 * 4);
139 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 3)
140 regcache->raw_collect (HPPA_SR4_REGNUM + 3, regs + 39 * 4);
141 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 4)
142 regcache->raw_collect (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
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 (i, regs);
160 regcache->raw_collect (i + 1, regs + 4);
161 }
162 }
163}
164
165
166/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
167 for all registers (including the floating-point registers). */
168
169void
171
172{
173 pid_t pid = regcache->ptid ().pid ();
174 int lwp = regcache->ptid ().lwp ();
175
177 {
178 struct reg regs;
179
180 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, lwp) == -1)
181 perror_with_name (_("Couldn't get registers"));
182
184 }
185
187 {
188 struct fpreg fpregs;
189
190 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
191 perror_with_name (_("Couldn't get floating point status"));
192
194 }
195}
196
197/* Store register REGNUM back into the inferior. If REGNUM is -1, do
198 this for all registers (including the floating-point registers). */
199
200void
202{
203 pid_t pid = regcache->ptid ().pid ();
204 int lwp = regcache->ptid ().lwp ();
205
207 {
208 struct reg regs;
209
210 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, lwp) == -1)
211 perror_with_name (_("Couldn't get registers"));
212
214
215 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, lwp) == -1)
216 perror_with_name (_("Couldn't write registers"));
217 }
218
220 {
221 struct fpreg fpregs;
222
223 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
224 perror_with_name (_("Couldn't get floating point status"));
225
227
228 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, lwp) == -1)
229 perror_with_name (_("Couldn't write floating point status"));
230 }
231}
232
234void
int regnum
void fetch_registers(struct regcache *, int) override
void store_registers(struct regcache *, int) override
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 hppanbsd_collect_fpregset(struct regcache *regcache, void *fpregs, int regnum)
static void hppanbsd_supply_fpregset(struct regcache *regcache, const void *fpregs)
static int hppanbsd_gregset_supplies_p(int regnum)
static hppa_nbsd_nat_target the_hppa_nbsd_nat_target
static void hppanbsd_supply_gregset(struct regcache *regcache, const void *gregs)
void _initialize_hppanbsd_nat()
static int hppanbsd_fpregset_supplies_p(int regnum)
static void hppanbsd_collect_gregset(const struct regcache *regcache, void *gregs, int regnum)
@ 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_SAR_REGNUM
Definition hppa-tdep.h:44
@ HPPA_IPSW_REGNUM
Definition hppa-tdep.h:45
@ HPPA_FP31R_REGNUM
Definition hppa-tdep.h:75
@ HPPA_PCOQ_HEAD_REGNUM
Definition hppa-tdep.h:46
@ HPPA_PCSQ_TAIL_REGNUM
Definition hppa-tdep.h:49
@ HPPA_PCOQ_TAIL_REGNUM
Definition hppa-tdep.h:48
@ HPPA_FP0_REGNUM
Definition hppa-tdep.h:72
@ HPPA_SR4_REGNUM
Definition hppa-tdep.h:54
@ 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