* aarch64-linux-nat.c: Replace PIDGET with ptid_get_pid.
[deliverable/binutils-gdb.git] / gdb / hppabsd-nat.c
CommitLineData
0e56aeaf
MK
1/* Native-dependent code for HP PA-RISC BSD's.
2
28e7fd62 3 Copyright (C) 2004-2013 Free Software Foundation, Inc.
0e56aeaf
MK
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
0e56aeaf
MK
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0e56aeaf
MK
19
20#include "defs.h"
21#include "inferior.h"
22#include "regcache.h"
57cd0b54 23#include "target.h"
0e56aeaf
MK
24
25#include <sys/types.h>
26#include <sys/ptrace.h>
27#include <machine/reg.h>
28
29#include "hppa-tdep.h"
57cd0b54 30#include "inf-ptrace.h"
0e56aeaf
MK
31
32static int
33hppabsd_gregset_supplies_p (int regnum)
34{
cbb6aada 35 return (regnum >= HPPA_R0_REGNUM && regnum <= HPPA_CR27_REGNUM);
0e56aeaf
MK
36}
37
20776c7d
MK
38static int
39hppabsd_fpregset_supplies_p (int regnum)
40{
41 return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
42}
43
0e56aeaf
MK
44/* Supply the general-purpose registers stored in GREGS to REGCACHE. */
45
46static void
47hppabsd_supply_gregset (struct regcache *regcache, const void *gregs)
48{
cbb6aada 49 gdb_byte zero[4] = { 0 };
0e56aeaf
MK
50 const char *regs = gregs;
51 int regnum;
52
cbb6aada 53 regcache_raw_supply (regcache, HPPA_R0_REGNUM, &zero);
0e56aeaf
MK
54 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
55 regcache_raw_supply (regcache, regnum, regs + regnum * 4);
56
cbb6aada
MK
57 if (sizeof(struct reg) >= 46 * 4)
58 {
59 regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
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_SR0_REGNUM, regs + 37 * 4);
66 regcache_raw_supply (regcache, HPPA_SR1_REGNUM, regs + 38 * 4);
67 regcache_raw_supply (regcache, HPPA_SR2_REGNUM, regs + 39 * 4);
68 regcache_raw_supply (regcache, HPPA_SR3_REGNUM, regs + 40 * 4);
69 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
70 regcache_raw_supply (regcache, HPPA_SR5_REGNUM, regs + 42 * 4);
71 regcache_raw_supply (regcache, HPPA_SR6_REGNUM, regs + 43 * 4);
72 regcache_raw_supply (regcache, HPPA_SR7_REGNUM, regs + 44 * 4);
73 regcache_raw_supply (regcache, HPPA_CR26_REGNUM, regs + 45 * 4);
74 regcache_raw_supply (regcache, HPPA_CR27_REGNUM, regs + 46 * 4);
75 }
76 else
77 {
78 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs);
79 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
80 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
81 }
0e56aeaf
MK
82}
83
20776c7d
MK
84/* Supply the floating-point registers stored in FPREGS to REGCACHE. */
85
86static void
87hppabsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
88{
89 const char *regs = fpregs;
90 int regnum;
91
92 for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
93 regnum += 2, regs += 8)
94 {
95 regcache_raw_supply (regcache, regnum, regs);
96 regcache_raw_supply (regcache, regnum + 1, regs + 4);
97 }
98}
99
0e56aeaf
MK
100/* Collect the general-purpose registers from REGCACHE and store them
101 in GREGS. */
102
103static void
104hppabsd_collect_gregset (const struct regcache *regcache,
105 void *gregs, int regnum)
106{
107 char *regs = gregs;
108 int i;
109
110 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
111 {
112 if (regnum == -1 || regnum == i)
113 regcache_raw_collect (regcache, i, regs + i * 4);
114 }
115
cbb6aada
MK
116 if (sizeof(struct reg) >= 46 * 4)
117 {
118 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
119 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
120 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
121 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
122 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
123 regcache_raw_collect (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
124 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
125 regcache_raw_collect (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
126 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
127 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
128 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
129 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
130 if (regnum == -1 || regnum == HPPA_SR0_REGNUM)
131 regcache_raw_collect (regcache, HPPA_SR0_REGNUM, regs + 37 * 4);
132 if (regnum == -1 || regnum == HPPA_SR1_REGNUM)
133 regcache_raw_collect (regcache, HPPA_SR1_REGNUM, regs + 38 * 4);
134 if (regnum == -1 || regnum == HPPA_SR2_REGNUM)
135 regcache_raw_collect (regcache, HPPA_SR2_REGNUM, regs + 39 * 4);
136 if (regnum == -1 || regnum == HPPA_SR3_REGNUM)
137 regcache_raw_collect (regcache, HPPA_SR3_REGNUM, regs + 40 * 4);
138 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
139 regcache_raw_collect (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
140 if (regnum == -1 || regnum == HPPA_SR5_REGNUM)
141 regcache_raw_collect (regcache, HPPA_SR5_REGNUM, regs + 42 * 4);
142 if (regnum == -1 || regnum == HPPA_SR6_REGNUM)
143 regcache_raw_collect (regcache, HPPA_SR6_REGNUM, regs + 43 * 4);
144 if (regnum == -1 || regnum == HPPA_SR7_REGNUM)
145 regcache_raw_collect (regcache, HPPA_SR7_REGNUM, regs + 44 * 4);
146 if (regnum == -1 || regnum == HPPA_CR26_REGNUM)
147 regcache_raw_collect (regcache, HPPA_CR26_REGNUM, regs + 45 * 4);
148 if (regnum == -1 || regnum == HPPA_CR27_REGNUM)
149 regcache_raw_collect (regcache, HPPA_CR27_REGNUM, regs + 46 * 4);
150 }
151 else
152 {
153 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
154 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs);
155 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
156 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
157 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
158 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
159 }
0e56aeaf 160}
20776c7d
MK
161
162/* Collect the floating-point registers from REGCACHE and store them
163 in FPREGS. */
164
165static void
166hppabsd_collect_fpregset (struct regcache *regcache,
167 void *fpregs, int regnum)
168{
169 char *regs = fpregs;
170 int i;
171
172 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
173 {
174 if (regnum == -1 || regnum == i || regnum == i + 1)
175 {
176 regcache_raw_collect (regcache, i, regs);
177 regcache_raw_collect (regcache, i + 1, regs + 4);
178 }
179 }
180}
0e56aeaf
MK
181\f
182
183/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
184 for all registers (including the floating-point registers). */
185
57cd0b54 186static void
28439f5e
PA
187hppabsd_fetch_registers (struct target_ops *ops,
188 struct regcache *regcache, int regnum)
0e56aeaf 189{
0e56aeaf
MK
190 if (regnum == -1 || hppabsd_gregset_supplies_p (regnum))
191 {
192 struct reg regs;
193
dfd4cc63 194 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 195 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 196 perror_with_name (_("Couldn't get registers"));
0e56aeaf
MK
197
198 hppabsd_supply_gregset (regcache, &regs);
199 }
20776c7d
MK
200
201 if (regnum == -1 || hppabsd_fpregset_supplies_p (regnum))
202 {
203 struct fpreg fpregs;
204
dfd4cc63 205 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
20776c7d
MK
206 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
207 perror_with_name (_("Couldn't get floating point status"));
208
56be3814 209 hppabsd_supply_fpregset (regcache, &fpregs);
20776c7d 210 }
0e56aeaf
MK
211}
212
213/* Store register REGNUM back into the inferior. If REGNUM is -1, do
214 this for all registers (including the floating-point registers). */
215
57cd0b54 216static void
28439f5e
PA
217hppabsd_store_registers (struct target_ops *ops,
218 struct regcache *regcache, int regnum)
0e56aeaf
MK
219{
220 if (regnum == -1 || hppabsd_gregset_supplies_p (regnum))
221 {
222 struct reg regs;
223
dfd4cc63 224 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 225 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 226 perror_with_name (_("Couldn't get registers"));
0e56aeaf 227
56be3814 228 hppabsd_collect_gregset (regcache, &regs, regnum);
0e56aeaf 229
dfd4cc63 230 if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 231 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 232 perror_with_name (_("Couldn't write registers"));
0e56aeaf 233 }
20776c7d
MK
234
235 if (regnum == -1 || hppabsd_fpregset_supplies_p (regnum))
236 {
237 struct fpreg fpregs;
238
dfd4cc63 239 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
20776c7d
MK
240 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
241 perror_with_name (_("Couldn't get floating point status"));
242
56be3814 243 hppabsd_collect_fpregset (regcache, &fpregs, regnum);
20776c7d 244
dfd4cc63 245 if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
20776c7d
MK
246 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
247 perror_with_name (_("Couldn't write floating point status"));
248 }
0e56aeaf 249}
57cd0b54
MK
250
251/* Provide a prototype to silence -Wmissing-prototypes. */
252void _initialize_hppabsd_nat (void);
253
254void
255_initialize_hppabsd_nat (void)
256{
257 struct target_ops *t;
258
259 /* Add in local overrides. */
260 t = inf_ptrace_target ();
261 t->to_fetch_registers = hppabsd_fetch_registers;
262 t->to_store_registers = hppabsd_store_registers;
263 add_target (t);
264}
This page took 0.77539 seconds and 4 git commands to generate.