No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / hppanbsd-nat.c
blobceb18cb0d5bd749879f56057904e87d28601dcee
1 /* Native-dependent code for NetBSD/hppa.
3 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
22 #include "defs.h"
23 #include "inferior.h"
24 #include "target.h"
25 #include "regcache.h"
27 #include <sys/types.h>
28 #include <sys/ptrace.h>
29 #include <machine/reg.h>
31 #include "hppa-tdep.h"
32 #include "inf-ptrace.h"
34 #include "nbsd-nat.h"
37 static int
38 hppanbsd_gregset_supplies_p (int regnum)
40 return ((regnum >= HPPA_R0_REGNUM && regnum <= HPPA_R31_REGNUM) ||
41 (regnum >= HPPA_SAR_REGNUM && regnum <= HPPA_PCSQ_TAIL_REGNUM) ||
42 regnum == HPPA_IPSW_REGNUM ||
43 (regnum >= HPPA_SR4_REGNUM && regnum <= HPPA_SR4_REGNUM + 5));
46 static int
47 hppanbsd_fpregset_supplies_p (int regnum)
49 return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM);
52 /* Supply the general-purpose registers stored in GREGS to REGCACHE. */
54 static void
55 hppanbsd_supply_gregset (struct regcache *regcache, const void *gregs)
57 const char *regs = gregs;
58 const int *r = gregs;
59 int regnum;
61 for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++)
62 regcache_raw_supply (regcache, regnum, regs + regnum * 4);
64 regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
65 regcache_raw_supply (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
66 regcache_raw_supply (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
67 regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
68 regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
69 regcache_raw_supply (regcache, HPPA_IPSW_REGNUM, regs);
70 regcache_raw_supply (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
71 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
72 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
73 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
74 regcache_raw_supply (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
77 /* Supply the floating-point registers stored in FPREGS to REGCACHE. */
79 static void
80 hppanbsd_supply_fpregset (struct regcache *regcache, const void *fpregs)
82 const char *regs = fpregs;
83 int regnum;
85 for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM;
86 regnum += 2, regs += 8)
88 regcache_raw_supply (regcache, regnum, regs);
89 regcache_raw_supply (regcache, regnum + 1, regs + 4);
93 /* Collect the general-purpose registers from REGCACHE and store them
94 in GREGS. */
96 static void
97 hppanbsd_collect_gregset (const struct regcache *regcache,
98 void *gregs, int regnum)
100 char *regs = gregs;
101 int *r = gregs;
102 int i;
104 for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++)
106 if (regnum == -1 || regnum == i)
107 regcache_raw_collect (regcache, i, regs + i * 4);
110 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
111 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
112 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
113 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
114 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
115 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
117 if (regnum == -1 || regnum == HPPA_SAR_REGNUM)
118 regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs + 32 * 4);
119 if (regnum == -1 || regnum == HPPA_PCSQ_HEAD_REGNUM)
120 regcache_raw_collect (regcache, HPPA_PCSQ_HEAD_REGNUM, regs + 33 * 4);
121 if (regnum == -1 || regnum == HPPA_PCSQ_TAIL_REGNUM)
122 regcache_raw_collect (regcache, HPPA_PCSQ_TAIL_REGNUM, regs + 34 * 4);
123 if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM)
124 regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 35 * 4);
125 if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM)
126 regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 36 * 4);
127 if (regnum == -1 || regnum == HPPA_IPSW_REGNUM)
128 regcache_raw_collect (regcache, HPPA_IPSW_REGNUM, regs);
129 if (regnum == -1 || regnum == HPPA_SR4_REGNUM)
130 regcache_raw_collect (regcache, HPPA_SR4_REGNUM, regs + 41 * 4);
131 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 1)
132 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 1, regs + 37 * 4);
133 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 2)
134 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 2, regs + 38 * 4);
135 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 3)
136 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 3, regs + 39 * 4);
137 if (regnum == -1 || regnum == HPPA_SR4_REGNUM + 4)
138 regcache_raw_collect (regcache, HPPA_SR4_REGNUM + 4, regs + 40 * 4);
141 /* Collect the floating-point registers from REGCACHE and store them
142 in FPREGS. */
144 static void
145 hppanbsd_collect_fpregset (struct regcache *regcache,
146 void *fpregs, int regnum)
148 char *regs = fpregs;
149 int i;
151 for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8)
153 if (regnum == -1 || regnum == i || regnum == i + 1)
155 regcache_raw_collect (regcache, i, regs);
156 regcache_raw_collect (regcache, i + 1, regs + 4);
162 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
163 for all registers (including the floating-point registers). */
165 static void
166 hppanbsd_fetch_registers (int regnum)
168 struct regcache *regcache = current_regcache;
170 if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
172 struct reg regs;
174 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
175 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
176 perror_with_name (_("Couldn't get registers"));
178 hppanbsd_supply_gregset (regcache, &regs);
181 if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
183 struct fpreg fpregs;
185 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
186 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
187 perror_with_name (_("Couldn't get floating point status"));
189 hppanbsd_supply_fpregset (current_regcache, &fpregs);
193 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
194 this for all registers (including the floating-point registers). */
196 static void
197 hppanbsd_store_registers (int regnum)
199 if (regnum == -1 || hppanbsd_gregset_supplies_p (regnum))
201 struct reg regs;
203 if (ptrace (PT_GETREGS, PIDGET (inferior_ptid),
204 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
205 perror_with_name (_("Couldn't get registers"));
207 hppanbsd_collect_gregset (current_regcache, &regs, regnum);
209 if (ptrace (PT_SETREGS, PIDGET (inferior_ptid),
210 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
211 perror_with_name (_("Couldn't write registers"));
214 if (regnum == -1 || hppanbsd_fpregset_supplies_p (regnum))
216 struct fpreg fpregs;
218 if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid),
219 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
220 perror_with_name (_("Couldn't get floating point status"));
222 hppanbsd_collect_fpregset (current_regcache, &fpregs, regnum);
224 if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid),
225 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
226 perror_with_name (_("Couldn't write floating point status"));
231 /* Provide a prototype to silence -Wmissing-prototypes. */
232 void _initialize_hppanbsd_nat (void);
234 void
235 _initialize_hppanbsd_nat (void)
237 struct target_ops *t;
239 /* Add some extra features to the ptrace target. */
240 t = inf_ptrace_target ();
242 t->to_fetch_registers = hppanbsd_fetch_registers;
243 t->to_store_registers = hppanbsd_store_registers;
245 t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
247 add_target (t);