1 /* Native-dependent code for OpenBSD/hppa.
3 Copyright (C) 2004-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/>. */
24 #include <sys/types.h>
25 #include <sys/ptrace.h>
26 #include <machine/reg.h>
28 #include "hppa-tdep.h"
29 #include "inf-ptrace.h"
33 struct hppa_obsd_nat_target final
: public obsd_nat_target
35 void fetch_registers (struct regcache
*, int) override
;
36 void store_registers (struct regcache
*, int) override
;
39 static hppa_obsd_nat_target the_hppa_obsd_nat_target
;
42 hppaobsd_gregset_supplies_p (int regnum
)
44 return (regnum
>= HPPA_R0_REGNUM
&& regnum
<= HPPA_CR27_REGNUM
);
48 hppaobsd_fpregset_supplies_p (int regnum
)
50 return (regnum
>= HPPA_FP0_REGNUM
&& regnum
<= HPPA_FP31R_REGNUM
);
53 /* Supply the general-purpose registers stored in GREGS to REGCACHE. */
56 hppaobsd_supply_gregset (struct regcache
*regcache
, const void *gregs
)
58 gdb_byte zero
[4] = { 0 };
59 const char *regs
= gregs
;
62 regcache
->raw_supply (HPPA_R0_REGNUM
, &zero
);
63 for (regnum
= HPPA_R1_REGNUM
; regnum
<= HPPA_R31_REGNUM
; regnum
++)
64 regcache
->raw_supply (regnum
, regs
+ regnum
* 4);
66 if (sizeof(struct reg
) >= 46 * 4)
68 regcache
->raw_supply (HPPA_IPSW_REGNUM
, regs
);
69 regcache
->raw_supply (HPPA_SAR_REGNUM
, regs
+ 32 * 4);
70 regcache
->raw_supply (HPPA_PCSQ_HEAD_REGNUM
, regs
+ 33 * 4);
71 regcache
->raw_supply (HPPA_PCSQ_TAIL_REGNUM
, regs
+ 34 * 4);
72 regcache
->raw_supply (HPPA_PCOQ_HEAD_REGNUM
, regs
+ 35 * 4);
73 regcache
->raw_supply (HPPA_PCOQ_TAIL_REGNUM
, regs
+ 36 * 4);
74 regcache
->raw_supply (HPPA_SR0_REGNUM
, regs
+ 37 * 4);
75 regcache
->raw_supply (HPPA_SR1_REGNUM
, regs
+ 38 * 4);
76 regcache
->raw_supply (HPPA_SR2_REGNUM
, regs
+ 39 * 4);
77 regcache
->raw_supply (HPPA_SR3_REGNUM
, regs
+ 40 * 4);
78 regcache
->raw_supply (HPPA_SR4_REGNUM
, regs
+ 41 * 4);
79 regcache
->raw_supply (HPPA_SR5_REGNUM
, regs
+ 42 * 4);
80 regcache
->raw_supply (HPPA_SR6_REGNUM
, regs
+ 43 * 4);
81 regcache
->raw_supply (HPPA_SR7_REGNUM
, regs
+ 44 * 4);
82 regcache
->raw_supply (HPPA_CR26_REGNUM
, regs
+ 45 * 4);
83 regcache
->raw_supply (HPPA_CR27_REGNUM
, regs
+ 46 * 4);
87 regcache
->raw_supply (HPPA_SAR_REGNUM
, regs
);
88 regcache
->raw_supply (HPPA_PCOQ_HEAD_REGNUM
, regs
+ 32 * 4);
89 regcache
->raw_supply (HPPA_PCOQ_TAIL_REGNUM
, regs
+ 33 * 4);
93 /* Supply the floating-point registers stored in FPREGS to REGCACHE. */
96 hppaobsd_supply_fpregset (struct regcache
*regcache
, const void *fpregs
)
98 const char *regs
= fpregs
;
101 for (regnum
= HPPA_FP0_REGNUM
; regnum
<= HPPA_FP31R_REGNUM
;
102 regnum
+= 2, regs
+= 8)
104 regcache
->raw_supply (regnum
, regs
);
105 regcache
->raw_supply (regnum
+ 1, regs
+ 4);
109 /* Collect the general-purpose registers from REGCACHE and store them
113 hppaobsd_collect_gregset (const struct regcache
*regcache
,
114 void *gregs
, int regnum
)
119 for (i
= HPPA_R1_REGNUM
; i
<= HPPA_R31_REGNUM
; i
++)
121 if (regnum
== -1 || regnum
== i
)
122 regcache
->raw_collect (i
, regs
+ i
* 4);
125 if (sizeof(struct reg
) >= 46 * 4)
127 if (regnum
== -1 || regnum
== HPPA_IPSW_REGNUM
)
128 regcache
->raw_collect (HPPA_IPSW_REGNUM
, regs
);
129 if (regnum
== -1 || regnum
== HPPA_SAR_REGNUM
)
130 regcache
->raw_collect (HPPA_SAR_REGNUM
, regs
+ 32 * 4);
131 if (regnum
== -1 || regnum
== HPPA_PCSQ_HEAD_REGNUM
)
132 regcache
->raw_collect (HPPA_PCSQ_HEAD_REGNUM
, regs
+ 33 * 4);
133 if (regnum
== -1 || regnum
== HPPA_PCSQ_TAIL_REGNUM
)
134 regcache
->raw_collect (HPPA_PCSQ_TAIL_REGNUM
, regs
+ 34 * 4);
135 if (regnum
== -1 || regnum
== HPPA_PCOQ_HEAD_REGNUM
)
136 regcache
->raw_collect (HPPA_PCOQ_HEAD_REGNUM
, regs
+ 35 * 4);
137 if (regnum
== -1 || regnum
== HPPA_PCOQ_TAIL_REGNUM
)
138 regcache
->raw_collect (HPPA_PCOQ_TAIL_REGNUM
, regs
+ 36 * 4);
139 if (regnum
== -1 || regnum
== HPPA_SR0_REGNUM
)
140 regcache
->raw_collect (HPPA_SR0_REGNUM
, regs
+ 37 * 4);
141 if (regnum
== -1 || regnum
== HPPA_SR1_REGNUM
)
142 regcache
->raw_collect (HPPA_SR1_REGNUM
, regs
+ 38 * 4);
143 if (regnum
== -1 || regnum
== HPPA_SR2_REGNUM
)
144 regcache
->raw_collect (HPPA_SR2_REGNUM
, regs
+ 39 * 4);
145 if (regnum
== -1 || regnum
== HPPA_SR3_REGNUM
)
146 regcache
->raw_collect (HPPA_SR3_REGNUM
, regs
+ 40 * 4);
147 if (regnum
== -1 || regnum
== HPPA_SR4_REGNUM
)
148 regcache
->raw_collect (HPPA_SR4_REGNUM
, regs
+ 41 * 4);
149 if (regnum
== -1 || regnum
== HPPA_SR5_REGNUM
)
150 regcache
->raw_collect (HPPA_SR5_REGNUM
, regs
+ 42 * 4);
151 if (regnum
== -1 || regnum
== HPPA_SR6_REGNUM
)
152 regcache
->raw_collect (HPPA_SR6_REGNUM
, regs
+ 43 * 4);
153 if (regnum
== -1 || regnum
== HPPA_SR7_REGNUM
)
154 regcache
->raw_collect (HPPA_SR7_REGNUM
, regs
+ 44 * 4);
155 if (regnum
== -1 || regnum
== HPPA_CR26_REGNUM
)
156 regcache
->raw_collect (HPPA_CR26_REGNUM
, regs
+ 45 * 4);
157 if (regnum
== -1 || regnum
== HPPA_CR27_REGNUM
)
158 regcache
->raw_collect (HPPA_CR27_REGNUM
, regs
+ 46 * 4);
162 if (regnum
== -1 || regnum
== HPPA_SAR_REGNUM
)
163 regcache
->raw_collect (HPPA_SAR_REGNUM
, regs
);
164 if (regnum
== -1 || regnum
== HPPA_PCOQ_HEAD_REGNUM
)
165 regcache
->raw_collect (HPPA_PCOQ_HEAD_REGNUM
, regs
+ 32 * 4);
166 if (regnum
== -1 || regnum
== HPPA_PCOQ_TAIL_REGNUM
)
167 regcache
->raw_collect (HPPA_PCOQ_TAIL_REGNUM
, regs
+ 33 * 4);
171 /* Collect the floating-point registers from REGCACHE and store them
175 hppaobsd_collect_fpregset (struct regcache
*regcache
,
176 void *fpregs
, int regnum
)
181 for (i
= HPPA_FP0_REGNUM
; i
<= HPPA_FP31R_REGNUM
; i
+= 2, regs
+= 8)
183 if (regnum
== -1 || regnum
== i
|| regnum
== i
+ 1)
185 regcache
->raw_collect (i
, regs
);
186 regcache
->raw_collect (i
+ 1, regs
+ 4);
192 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
193 for all registers (including the floating-point registers). */
196 hppa_obsd_nat_target::fetch_registers (struct regcache
*regcache
, int regnum
)
198 pid_t pid
= regcache
->ptid ().pid ();
200 if (regnum
== -1 || hppaobsd_gregset_supplies_p (regnum
))
204 if (ptrace (PT_GETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
205 perror_with_name (_("Couldn't get registers"));
207 hppaobsd_supply_gregset (regcache
, ®s
);
210 if (regnum
== -1 || hppaobsd_fpregset_supplies_p (regnum
))
214 if (ptrace (PT_GETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
215 perror_with_name (_("Couldn't get floating point status"));
217 hppaobsd_supply_fpregset (regcache
, &fpregs
);
221 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
222 this for all registers (including the floating-point registers). */
225 hppa_obsd_nat_target::store_registers (struct regcache
*regcache
, int regnum
)
227 if (regnum
== -1 || hppaobsd_gregset_supplies_p (regnum
))
231 if (ptrace (PT_GETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
232 perror_with_name (_("Couldn't get registers"));
234 hppaobsd_collect_gregset (regcache
, ®s
, regnum
);
236 if (ptrace (PT_SETREGS
, pid
, (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
237 perror_with_name (_("Couldn't write registers"));
240 if (regnum
== -1 || hppaobsd_fpregset_supplies_p (regnum
))
244 if (ptrace (PT_GETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
245 perror_with_name (_("Couldn't get floating point status"));
247 hppaobsd_collect_fpregset (regcache
, &fpregs
, regnum
);
249 if (ptrace (PT_SETFPREGS
, pid
, (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
250 perror_with_name (_("Couldn't write floating point status"));
254 void _initialize_hppaobsd_nat ();
256 _initialize_hppaobsd_nat ()
258 add_inf_child_target (&the_hppa_obsd_nat_target
);