*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / hppabsd-nat.c
CommitLineData
0e56aeaf
MK
1/* Native-dependent code for HP PA-RISC BSD's.
2
6aba47ca 3 Copyright (C) 2004, 2005, 2007 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
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
197e01b6
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
0e56aeaf
MK
21
22#include "defs.h"
23#include "inferior.h"
24#include "regcache.h"
57cd0b54 25#include "target.h"
0e56aeaf
MK
26
27#include <sys/types.h>
28#include <sys/ptrace.h>
29#include <machine/reg.h>
30
31#include "hppa-tdep.h"
57cd0b54 32#include "inf-ptrace.h"
0e56aeaf
MK
33
34static int
35hppabsd_gregset_supplies_p (int regnum)
36{
37 return (regnum >= HPPA_R0_REGNUM && regnum <= HPPA_PCOQ_TAIL_REGNUM);
38}
39
20776c7d
MK
40static int
41hppabsd_fpregset_supplies_p (int regnum)
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
49hppabsd_supply_gregset (struct regcache *regcache, const void *gregs)
50{
51 const char *regs = gregs;
52 int regnum;
53
54 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
55 regcache_raw_supply (regcache, regnum, regs + regnum * 4);
56
57 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs);
58 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
59 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
60}
61
20776c7d
MK
62/* Supply the floating-point registers stored in FPREGS to REGCACHE. */
63
64static void
65hppabsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
66{
67 const char *regs = fpregs;
68 int regnum;
69
70 for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
71 regnum += 2, regs += 8)
72 {
73 regcache_raw_supply (regcache, regnum, regs);
74 regcache_raw_supply (regcache, regnum + 1, regs + 4);
75 }
76}
77
0e56aeaf
MK
78/* Collect the general-purpose registers from REGCACHE and store them
79 in GREGS. */
80
81static void
82hppabsd_collect_gregset (const struct regcache *regcache,
83 void *gregs, int regnum)
84{
85 char *regs = gregs;
86 int i;
87
88 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
89 {
90 if (regnum == -1 || regnum == i)
91 regcache_raw_collect (regcache, i, regs + i * 4);
92 }
93
94 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
95 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs);
96 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
97 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4);
98 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
99 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4);
100}
20776c7d
MK
101
102/* Collect the floating-point registers from REGCACHE and store them
103 in FPREGS. */
104
105static void
106hppabsd_collect_fpregset (struct regcache *regcache,
107 void *fpregs, int regnum)
108{
109 char *regs = fpregs;
110 int i;
111
112 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
113 {
114 if (regnum == -1 || regnum == i || regnum == i + 1)
115 {
116 regcache_raw_collect (regcache, i, regs);
117 regcache_raw_collect (regcache, i + 1, regs + 4);
118 }
119 }
120}
0e56aeaf
MK
121\f
122
123/* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
124 for all registers (including the floating-point registers). */
125
57cd0b54 126static void
56be3814 127hppabsd_fetch_registers (struct regcache *regcache, int regnum)
0e56aeaf 128{
0e56aeaf
MK
129 if (regnum == -1 || hppabsd_gregset_supplies_p (regnum))
130 {
131 struct reg regs;
132
133 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
9f8e0089 134 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 135 perror_with_name (_("Couldn't get registers"));
0e56aeaf
MK
136
137 hppabsd_supply_gregset (regcache, &regs);
138 }
20776c7d
MK
139
140 if (regnum == -1 || hppabsd_fpregset_supplies_p (regnum))
141 {
142 struct fpreg fpregs;
143
144 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
145 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
146 perror_with_name (_("Couldn't get floating point status"));
147
56be3814 148 hppabsd_supply_fpregset (regcache, &fpregs);
20776c7d 149 }
0e56aeaf
MK
150}
151
152/* Store register REGNUM back into the inferior. If REGNUM is -1, do
153 this for all registers (including the floating-point registers). */
154
57cd0b54 155static void
56be3814 156hppabsd_store_registers (struct regcache *regcache, int regnum)
0e56aeaf
MK
157{
158 if (regnum == -1 || hppabsd_gregset_supplies_p (regnum))
159 {
160 struct reg regs;
161
162 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
9f8e0089 163 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 164 perror_with_name (_("Couldn't get registers"));
0e56aeaf 165
56be3814 166 hppabsd_collect_gregset (regcache, &regs, regnum);
0e56aeaf
MK
167
168 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
9f8e0089 169 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 170 perror_with_name (_("Couldn't write registers"));
0e56aeaf 171 }
20776c7d
MK
172
173 if (regnum == -1 || hppabsd_fpregset_supplies_p (regnum))
174 {
175 struct fpreg fpregs;
176
177 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
178 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
179 perror_with_name (_("Couldn't get floating point status"));
180
56be3814 181 hppabsd_collect_fpregset (regcache, &fpregs, regnum);
20776c7d
MK
182
183 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
184 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
185 perror_with_name (_("Couldn't write floating point status"));
186 }
0e56aeaf 187}
57cd0b54
MK
188
189/* Provide a prototype to silence -Wmissing-prototypes. */
190void _initialize_hppabsd_nat (void);
191
192void
193_initialize_hppabsd_nat (void)
194{
195 struct target_ops *t;
196
197 /* Add in local overrides. */
198 t = inf_ptrace_target ();
199 t->to_fetch_registers = hppabsd_fetch_registers;
200 t->to_store_registers = hppabsd_store_registers;
201 add_target (t);
202}
This page took 0.211425 seconds and 4 git commands to generate.