]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/hppa-obsd-nat.c
update copyright year range in GDB files
[thirdparty/binutils-gdb.git] / gdb / hppa-obsd-nat.c
CommitLineData
2dcb2b1a 1/* Native-dependent code for OpenBSD/hppa.
0e56aeaf 2
61baf725 3 Copyright (C) 2004-2017 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 31
2dcb2b1a
MK
32#include "obsd-nat.h"
33
0e56aeaf 34static int
2dcb2b1a 35hppaobsd_gregset_supplies_p (int regnum)
0e56aeaf 36{
cbb6aada 37 return (regnum >= HPPA_R0_REGNUM && regnum <= HPPA_CR27_REGNUM);
0e56aeaf
MK
38}
39
20776c7d 40static int
2dcb2b1a 41hppaobsd_fpregset_supplies_p (int regnum)
20776c7d
MK
42{
43 return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
44}
45
0e56aeaf
MK
46/* Supply the general-purpose registers stored in GREGS to REGCACHE. */
47
48static void
2dcb2b1a 49hppaobsd_supply_gregset (struct regcache *regcache, const void *gregs)
0e56aeaf 50{
cbb6aada 51 gdb_byte zero[4] = { 0 };
0e56aeaf
MK
52 const char *regs = gregs;
53 int regnum;
54
cbb6aada 55 regcache_raw_supply (regcache, HPPA_R0_REGNUM, &zero);
0e56aeaf
MK
56 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
57 regcache_raw_supply (regcache, regnum, regs + regnum * 4);
58
cbb6aada
MK
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 }
0e56aeaf
MK
84}
85
20776c7d
MK
86/* Supply the floating-point registers stored in FPREGS to REGCACHE. */
87
88static void
2dcb2b1a 89hppaobsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
20776c7d
MK
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
0e56aeaf
MK
102/* Collect the general-purpose registers from REGCACHE and store them
103 in GREGS. */
104
105static void
2dcb2b1a 106hppaobsd_collect_gregset (const struct regcache *regcache,
0e56aeaf
MK
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
cbb6aada
MK
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 }
0e56aeaf 162}
20776c7d
MK
163
164/* Collect the floating-point registers from REGCACHE and store them
165 in FPREGS. */
166
167static void
2dcb2b1a
MK
168hppaobsd_collect_fpregset (struct regcache *regcache,
169 void *fpregs, int regnum)
20776c7d
MK
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}
0e56aeaf
MK
183\f
184
185/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
186 for all registers (including the floating-point registers). */
187
57cd0b54 188static void
2dcb2b1a
MK
189hppaobsd_fetch_registers (struct target_ops *ops,
190 struct regcache *regcache, int regnum)
0e56aeaf 191{
2dcb2b1a 192 if (regnum == -1 || hppaobsd_gregset_supplies_p (regnum))
0e56aeaf
MK
193 {
194 struct reg regs;
195
dfd4cc63 196 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 197 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 198 perror_with_name (_("Couldn't get registers"));
0e56aeaf 199
2dcb2b1a 200 hppaobsd_supply_gregset (regcache, &regs);
0e56aeaf 201 }
20776c7d 202
2dcb2b1a 203 if (regnum == -1 || hppaobsd_fpregset_supplies_p (regnum))
20776c7d
MK
204 {
205 struct fpreg fpregs;
206
dfd4cc63 207 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
20776c7d
MK
208 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
209 perror_with_name (_("Couldn't get floating point status"));
210
2dcb2b1a 211 hppaobsd_supply_fpregset (regcache, &fpregs);
20776c7d 212 }
0e56aeaf
MK
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
57cd0b54 218static void
2dcb2b1a
MK
219hppaobsd_store_registers (struct target_ops *ops,
220 struct regcache *regcache, int regnum)
0e56aeaf 221{
2dcb2b1a 222 if (regnum == -1 || hppaobsd_gregset_supplies_p (regnum))
0e56aeaf
MK
223 {
224 struct reg regs;
225
dfd4cc63 226 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 227 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 228 perror_with_name (_("Couldn't get registers"));
0e56aeaf 229
2dcb2b1a 230 hppaobsd_collect_gregset (regcache, &regs, regnum);
0e56aeaf 231
dfd4cc63 232 if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
9f8e0089 233 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 234 perror_with_name (_("Couldn't write registers"));
0e56aeaf 235 }
20776c7d 236
2dcb2b1a 237 if (regnum == -1 || hppaobsd_fpregset_supplies_p (regnum))
20776c7d
MK
238 {
239 struct fpreg fpregs;
240
dfd4cc63 241 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
20776c7d
MK
242 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
243 perror_with_name (_("Couldn't get floating point status"));
244
2dcb2b1a 245 hppaobsd_collect_fpregset (regcache, &fpregs, regnum);
20776c7d 246
dfd4cc63 247 if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
20776c7d
MK
248 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
249 perror_with_name (_("Couldn't write floating point status"));
250 }
0e56aeaf 251}
57cd0b54
MK
252
253/* Provide a prototype to silence -Wmissing-prototypes. */
2dcb2b1a 254void _initialize_hppaobsd_nat (void);
57cd0b54
MK
255
256void
2dcb2b1a 257_initialize_hppaobsd_nat (void)
57cd0b54
MK
258{
259 struct target_ops *t;
260
57cd0b54 261 t = inf_ptrace_target ();
2dcb2b1a
MK
262 t->to_fetch_registers = hppaobsd_fetch_registers;
263 t->to_store_registers = hppaobsd_store_registers;
264 obsd_add_target (t);
57cd0b54 265}