1 /* Native-dependent code for NetBSD/hppa.
3 Copyright (C) 2008-2024 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 3 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, see <http://www.gnu.org/licenses/>. */
23 #include <sys/types.h>
24 #include <sys/ptrace.h>
25 #include <machine/reg.h>
27 #include "hppa-tdep.h"
28 #include "inf-ptrace.h"
30 #include "netbsd-nat.h"
32 class hppa_nbsd_nat_target final
: public nbsd_nat_target
34 void fetch_registers (struct regcache
*, int) override
;
35 void store_registers (struct regcache
*, int) override
;
38 static hppa_nbsd_nat_target the_hppa_nbsd_nat_target
;
41 hppanbsd_gregset_supplies_p (int regnum
)
43 return ((regnum
>= HPPA_R0_REGNUM
&& regnum
<= HPPA_R31_REGNUM
) ||
44 (regnum
>= HPPA_SAR_REGNUM
&& regnum
<= HPPA_PCSQ_TAIL_REGNUM
) ||
45 regnum
== HPPA_IPSW_REGNUM
||
46 (regnum
>= HPPA_SR4_REGNUM
&& regnum
<= HPPA_SR4_REGNUM
+ 5));
50 hppanbsd_fpregset_supplies_p (int regnum
)
52 return (regnum
>= HPPA_FP0_REGNUM
&& regnum
<= HPPA_FP31R_REGNUM
);
55 /* Supply the general-purpose registers stored in GREGS to REGCACHE. */
58 hppanbsd_supply_gregset (struct regcache
*regcache
, const void *gregs
)
60 const char *regs
= gregs
;
64 for (regnum
= HPPA_R1_REGNUM
; regnum
<= HPPA_R31_REGNUM
; regnum
++)
65 regcache
->raw_supply (regnum
, regs
+ regnum
* 4);
67 regcache
->raw_supply (HPPA_SAR_REGNUM
, regs
+ 32 * 4);
68 regcache
->raw_supply (HPPA_PCSQ_HEAD_REGNUM
, regs
+ 33 * 4);
69 regcache
->raw_supply (HPPA_PCSQ_TAIL_REGNUM
, regs
+ 34 * 4);
70 regcache
->raw_supply (HPPA_PCOQ_HEAD_REGNUM
, regs
+ 35 * 4);
71 regcache
->raw_supply (HPPA_PCOQ_TAIL_REGNUM
, regs
+ 36 * 4);
72 regcache
->raw_supply (HPPA_IPSW_REGNUM
, regs
);
73 regcache
->raw_supply (HPPA_SR4_REGNUM
, regs
+ 41 * 4);
74 regcache
->raw_supply (HPPA_SR4_REGNUM
+ 1, regs
+ 37 * 4);
75 regcache
->raw_supply (HPPA_SR4_REGNUM
+ 2, regs
+ 38 * 4);
76 regcache
->raw_supply (HPPA_SR4_REGNUM
+ 3, regs
+ 39 * 4);
77 regcache
->raw_supply (HPPA_SR4_REGNUM
+ 4, regs
+ 40 * 4);
80 /* Supply the floating-point registers stored in FPREGS to REGCACHE. */
83 hppanbsd_supply_fpregset (struct regcache
*regcache
, const void *fpregs
)
85 const char *regs
= fpregs
;
88 for (regnum
= HPPA_FP0_REGNUM
; regnum
<= HPPA_FP31R_REGNUM
;
89 regnum
+= 2, regs
+= 8)
91 regcache
->raw_supply (regnum
, regs
);
92 regcache
->raw_supply (regnum
+ 1, regs
+ 4);
96 /* Collect the general-purpose registers from REGCACHE and store them
100 hppanbsd_collect_gregset (const struct regcache
*regcache
,
101 void *gregs
, int regnum
)
107 for (i
= HPPA_R1_REGNUM
; i
<= HPPA_R31_REGNUM
; i
++)
109 if (regnum
== -1 || regnum
== i
)
110 regcache
->raw_collect (i
, regs
+ i
* 4);
113 if (regnum
== -1 || regnum
== HPPA_IPSW_REGNUM
)
114 regcache
->raw_collect (HPPA_IPSW_REGNUM
, regs
);
115 if (regnum
== -1 || regnum
== HPPA_PCOQ_HEAD_REGNUM
)
116 regcache
->raw_collect (HPPA_PCOQ_HEAD_REGNUM
, regs
+ 35 * 4);
117 if (regnum
== -1 || regnum
== HPPA_PCOQ_TAIL_REGNUM
)
118 regcache
->raw_collect (HPPA_PCOQ_TAIL_REGNUM
, regs
+ 36 * 4);
120 if (regnum
== -1 || regnum
== HPPA_SAR_REGNUM
)
121 regcache
->raw_collect (HPPA_SAR_REGNUM
, regs
+ 32 * 4);
122 if (regnum
== -1 || regnum
== HPPA_PCSQ_HEAD_REGNUM
)
123 regcache
->raw_collect (HPPA_PCSQ_HEAD_REGNUM
, regs
+ 33 * 4);
124 if (regnum
== -1 || regnum
== HPPA_PCSQ_TAIL_REGNUM
)
125 regcache
->raw_collect (HPPA_PCSQ_TAIL_REGNUM
, regs
+ 34 * 4);
126 if (regnum
== -1 || regnum
== HPPA_PCOQ_HEAD_REGNUM
)
127 regcache
->raw_collect (HPPA_PCOQ_HEAD_REGNUM
, regs
+ 35 * 4);
128 if (regnum
== -1 || regnum
== HPPA_PCOQ_TAIL_REGNUM
)
129 regcache
->raw_collect (HPPA_PCOQ_TAIL_REGNUM
, regs
+ 36 * 4);
130 if (regnum
== -1 || regnum
== HPPA_IPSW_REGNUM
)
131 regcache
->raw_collect (HPPA_IPSW_REGNUM
, regs
);
132 if (regnum
== -1 || regnum
== HPPA_SR4_REGNUM
)
133 regcache
->raw_collect (HPPA_SR4_REGNUM
, regs
+ 41 * 4);
134 if (regnum
== -1 || regnum
== HPPA_SR4_REGNUM
+ 1)
135 regcache
->raw_collect (HPPA_SR4_REGNUM
+ 1, regs
+ 37 * 4);
136 if (regnum
== -1 || regnum
== HPPA_SR4_REGNUM
+ 2)
137 regcache
->raw_collect (HPPA_SR4_REGNUM
+ 2, regs
+ 38 * 4);
138 if (regnum
== -1 || regnum
== HPPA_SR4_REGNUM
+ 3)
139 regcache
->raw_collect (HPPA_SR4_REGNUM
+ 3, regs
+ 39 * 4);
140 if (regnum
== -1 || regnum
== HPPA_SR4_REGNUM
+ 4)
141 regcache
->raw_collect (HPPA_SR4_REGNUM
+ 4, regs
+ 40 * 4);
144 /* Collect the floating-point registers from REGCACHE and store them
148 hppanbsd_collect_fpregset (struct regcache
*regcache
,
149 void *fpregs
, int regnum
)
154 for (i
= HPPA_FP0_REGNUM
; i
<= HPPA_FP31R_REGNUM
; i
+= 2, regs
+= 8)
156 if (regnum
== -1 || regnum
== i
|| regnum
== i
+ 1)
158 regcache
->raw_collect (i
, regs
);
159 regcache
->raw_collect (i
+ 1, regs
+ 4);
165 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
166 for all registers (including the floating-point registers). */
169 hppa_nbsd_nat_target::fetch_registers (struct regcache
*regcache
, int regnum
)
172 pid_t pid
= regcache
->ptid ().pid ();
173 int lwp
= regcache
->ptid ().lwp ();
175 if (regnum
== -1 || hppanbsd_gregset_supplies_p (regnum
))
179 if (ptrace (PT_GETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, lwp
) == -1)
180 perror_with_name (_("Couldn't get registers"));
182 hppanbsd_supply_gregset (regcache
, ®s
);
185 if (regnum
== -1 || hppanbsd_fpregset_supplies_p (regnum
))
189 if (ptrace (PT_GETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, lwp
) == -1)
190 perror_with_name (_("Couldn't get floating point status"));
192 hppanbsd_supply_fpregset (regcache
, &fpregs
);
196 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
197 this for all registers (including the floating-point registers). */
200 hppa_nbsd_nat_target::store_registers (struct regcache
*regcache
, int regnum
)
202 pid_t pid
= regcache
->ptid ().pid ();
203 int lwp
= regcache
->ptid ().lwp ();
205 if (regnum
== -1 || hppanbsd_gregset_supplies_p (regnum
))
209 if (ptrace (PT_GETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, lwp
) == -1)
210 perror_with_name (_("Couldn't get registers"));
212 hppanbsd_collect_gregset (regcache
, ®s
, regnum
);
214 if (ptrace (PT_SETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, lwp
) == -1)
215 perror_with_name (_("Couldn't write registers"));
218 if (regnum
== -1 || hppanbsd_fpregset_supplies_p (regnum
))
222 if (ptrace (PT_GETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, lwp
) == -1)
223 perror_with_name (_("Couldn't get floating point status"));
225 hppanbsd_collect_fpregset (regcache
, &fpregs
, regnum
);
227 if (ptrace (PT_SETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, lwp
) == -1)
228 perror_with_name (_("Couldn't write floating point status"));
232 void _initialize_hppanbsd_nat ();
234 _initialize_hppanbsd_nat ()
236 add_inf_child_target (&the_hppa_nbsd_nat_target
);