]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/hppanbsd-nat.c
* corelow.c (get_core_registers): Adjust.
[thirdparty/binutils-gdb.git] / gdb / hppanbsd-nat.c
CommitLineData
af5ca30d
NH
1/* Native-dependent code for NetBSD/hppa.
2
0fb0cc75 3 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
af5ca30d
NH
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 2 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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22#include "defs.h"
23#include "inferior.h"
24#include "regcache.h"
25
26#include <sys/types.h>
27#include <sys/ptrace.h>
28#include <machine/reg.h>
29
30#include "hppa-tdep.h"
31#include "inf-ptrace.h"
32
33#include "nbsd-nat.h"
34
35static int
36hppanbsd_gregset_supplies_p (int regnum)
37{
38 return ((regnum >= HPPA_R0_REGNUM && regnum <= HPPA_R31_REGNUM) ||
39 (regnum >= HPPA_SAR_REGNUM && regnum <= HPPA_PCSQ_TAIL_REGNUM) ||
40 regnum == HPPA_IPSW_REGNUM ||
41 (regnum >= HPPA_SR4_REGNUM && regnum <= HPPA_SR4_REGNUM + 5));
42}
43
44static int
45hppanbsd_fpregset_supplies_p (int regnum)
46{
47 return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
48}
49
50/* Supply the general-purpose registers stored in GREGS to REGCACHE. */
51
52static void
53hppanbsd_supply_gregset (struct regcache *regcache, const void *gregs)
54{
55 const char *regs = gregs;
56 const int *r = gregs;
57 int regnum;
58
59 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
60 regcache_raw_supply (regcache, regnum, regs + regnum * 4);
61
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_IPSW_REGNUM, regs);
68 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
69 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
70 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
71 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
72 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
73}
74
75/* Supply the floating-point registers stored in FPREGS to REGCACHE. */
76
77static void
78hppanbsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
79{
80 const char *regs = fpregs;
81 int regnum;
82
83 for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
84 regnum += 2, regs += 8)
85 {
86 regcache_raw_supply (regcache, regnum, regs);
87 regcache_raw_supply (regcache, regnum + 1, regs + 4);
88 }
89}
90
91/* Collect the general-purpose registers from REGCACHE and store them
92 in GREGS. */
93
94static void
95hppanbsd_collect_gregset (const struct regcache *regcache,
96 void *gregs, int regnum)
97{
98 char *regs = gregs;
99 int *r = gregs;
100 int i;
101
102 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
103 {
104 if (regnum == -1 || regnum == i)
105 regcache_raw_collect (regcache, i, regs + i * 4);
106 }
107
108 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
109 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
110 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
111 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
112 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
113 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
114
115 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
116 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
117 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
118 regcache_raw_collect (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
119 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
120 regcache_raw_collect (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
121 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
122 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
123 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
124 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
125 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
126 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
127 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
128 regcache_raw_collect (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
129 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 1)
130 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
131 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 2)
132 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
133 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 3)
134 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
135 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 4)
136 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
137}
138
139/* Collect the floating-point registers from REGCACHE and store them
140 in FPREGS. */
141
142static void
143hppanbsd_collect_fpregset (struct regcache *regcache,
144 void *fpregs, int regnum)
145{
146 char *regs = fpregs;
147 int i;
148
149 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
150 {
151 if (regnum == -1 || regnum == i || regnum == i + 1)
152 {
153 regcache_raw_collect (regcache, i, regs);
154 regcache_raw_collect (regcache, i + 1, regs + 4);
155 }
156 }
157}
158\f
159
160/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
161 for all registers (including the floating-point registers). */
162
163static void
28439f5e
PA
164hppanbsd_fetch_registers (struct target_ops *ops,
165 struct regcache *regcache, int regnum)
af5ca30d
NH
166
167{
168 if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
169 {
170 struct reg regs;
171
172 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
173 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
174 perror_with_name (_("Couldn't get registers"));
175
176 hppanbsd_supply_gregset (regcache, &regs);
177 }
178
179 if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
180 {
181 struct fpreg fpregs;
182
183 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
184 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
185 perror_with_name (_("Couldn't get floating point status"));
186
187 hppanbsd_supply_fpregset (regcache, &fpregs);
188 }
189}
190
191/* Store register REGNUM back into the inferior. If REGNUM is -1, do
192 this for all registers (including the floating-point registers). */
193
194static void
28439f5e
PA
195hppanbsd_store_registers (struct target_ops *ops,
196 struct regcache *regcache, int regnum)
af5ca30d
NH
197{
198 if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
199 {
200 struct reg regs;
201
202 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
203 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
204 perror_with_name (_("Couldn't get registers"));
205
206 hppanbsd_collect_gregset (regcache, &regs, regnum);
207
208 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
209 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
210 perror_with_name (_("Couldn't write registers"));
211 }
212
213 if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
214 {
215 struct fpreg fpregs;
216
217 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
218 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
219 perror_with_name (_("Couldn't get floating point status"));
220
221 hppanbsd_collect_fpregset (regcache, &fpregs, regnum);
222
223 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
224 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
225 perror_with_name (_("Couldn't write floating point status"));
226 }
227}
228
229
230/* Provide a prototype to silence -Wmissing-prototypes. */
231void _initialize_hppanbsd_nat (void);
232
233void
234_initialize_hppanbsd_nat (void)
235{
236 struct target_ops *t;
237
238 /* Add some extra features to the ptrace target. */
239 t = inf_ptrace_target ();
240
241 t->to_fetch_registers = hppanbsd_fetch_registers;
242 t->to_store_registers = hppanbsd_store_registers;
243
244 t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
245
246 add_target (t);
247}