Commit | Line | Data |
---|---|---|
0e56aeaf MK |
1 | /* Native-dependent code for HP PA-RISC BSD's. |
2 | ||
0b302171 | 3 | Copyright (C) 2004-2005, 2007-2012 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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
0e56aeaf MK |
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 | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0e56aeaf MK |
19 | |
20 | #include "defs.h" | |
21 | #include "inferior.h" | |
22 | #include "regcache.h" | |
57cd0b54 | 23 | #include "target.h" |
0e56aeaf MK |
24 | |
25 | #include <sys/types.h> | |
26 | #include <sys/ptrace.h> | |
27 | #include <machine/reg.h> | |
28 | ||
29 | #include "hppa-tdep.h" | |
57cd0b54 | 30 | #include "inf-ptrace.h" |
0e56aeaf MK |
31 | |
32 | static int | |
33 | hppabsd_gregset_supplies_p (int regnum) | |
34 | { | |
35 | return (regnum >= HPPA_R0_REGNUM && regnum <= HPPA_PCOQ_TAIL_REGNUM); | |
36 | } | |
37 | ||
20776c7d MK |
38 | static int |
39 | hppabsd_fpregset_supplies_p (int regnum) | |
40 | { | |
41 | return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM); | |
42 | } | |
43 | ||
0e56aeaf MK |
44 | /* Supply the general-purpose registers stored in GREGS to REGCACHE. */ |
45 | ||
46 | static void | |
47 | hppabsd_supply_gregset (struct regcache *regcache, const void *gregs) | |
48 | { | |
49 | const char *regs = gregs; | |
50 | int regnum; | |
51 | ||
52 | for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++) | |
53 | regcache_raw_supply (regcache, regnum, regs + regnum * 4); | |
54 | ||
55 | regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs); | |
56 | regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4); | |
57 | regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4); | |
58 | } | |
59 | ||
20776c7d MK |
60 | /* Supply the floating-point registers stored in FPREGS to REGCACHE. */ |
61 | ||
62 | static void | |
63 | hppabsd_supply_fpregset (struct regcache *regcache, const void *fpregs) | |
64 | { | |
65 | const char *regs = fpregs; | |
66 | int regnum; | |
67 | ||
68 | for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM; | |
69 | regnum += 2, regs += 8) | |
70 | { | |
71 | regcache_raw_supply (regcache, regnum, regs); | |
72 | regcache_raw_supply (regcache, regnum + 1, regs + 4); | |
73 | } | |
74 | } | |
75 | ||
0e56aeaf MK |
76 | /* Collect the general-purpose registers from REGCACHE and store them |
77 | in GREGS. */ | |
78 | ||
79 | static void | |
80 | hppabsd_collect_gregset (const struct regcache *regcache, | |
81 | void *gregs, int regnum) | |
82 | { | |
83 | char *regs = gregs; | |
84 | int i; | |
85 | ||
86 | for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++) | |
87 | { | |
88 | if (regnum == -1 || regnum == i) | |
89 | regcache_raw_collect (regcache, i, regs + i * 4); | |
90 | } | |
91 | ||
92 | if (regnum == -1 || regnum == HPPA_SAR_REGNUM) | |
93 | regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs); | |
94 | if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM) | |
95 | regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4); | |
96 | if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM) | |
97 | regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4); | |
98 | } | |
20776c7d MK |
99 | |
100 | /* Collect the floating-point registers from REGCACHE and store them | |
101 | in FPREGS. */ | |
102 | ||
103 | static void | |
104 | hppabsd_collect_fpregset (struct regcache *regcache, | |
105 | void *fpregs, int regnum) | |
106 | { | |
107 | char *regs = fpregs; | |
108 | int i; | |
109 | ||
110 | for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8) | |
111 | { | |
112 | if (regnum == -1 || regnum == i || regnum == i + 1) | |
113 | { | |
114 | regcache_raw_collect (regcache, i, regs); | |
115 | regcache_raw_collect (regcache, i + 1, regs + 4); | |
116 | } | |
117 | } | |
118 | } | |
0e56aeaf MK |
119 | \f |
120 | ||
121 | /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this | |
122 | for all registers (including the floating-point registers). */ | |
123 | ||
57cd0b54 | 124 | static void |
28439f5e PA |
125 | hppabsd_fetch_registers (struct target_ops *ops, |
126 | struct regcache *regcache, int regnum) | |
0e56aeaf | 127 | { |
0e56aeaf MK |
128 | if (regnum == -1 || hppabsd_gregset_supplies_p (regnum)) |
129 | { | |
130 | struct reg regs; | |
131 | ||
132 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 133 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 134 | perror_with_name (_("Couldn't get registers")); |
0e56aeaf MK |
135 | |
136 | hppabsd_supply_gregset (regcache, ®s); | |
137 | } | |
20776c7d MK |
138 | |
139 | if (regnum == -1 || hppabsd_fpregset_supplies_p (regnum)) | |
140 | { | |
141 | struct fpreg fpregs; | |
142 | ||
143 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
144 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | |
145 | perror_with_name (_("Couldn't get floating point status")); | |
146 | ||
56be3814 | 147 | hppabsd_supply_fpregset (regcache, &fpregs); |
20776c7d | 148 | } |
0e56aeaf MK |
149 | } |
150 | ||
151 | /* Store register REGNUM back into the inferior. If REGNUM is -1, do | |
152 | this for all registers (including the floating-point registers). */ | |
153 | ||
57cd0b54 | 154 | static void |
28439f5e PA |
155 | hppabsd_store_registers (struct target_ops *ops, |
156 | 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) ®s, 0) == -1) |
e2e0b3e5 | 164 | perror_with_name (_("Couldn't get registers")); |
0e56aeaf | 165 | |
56be3814 | 166 | hppabsd_collect_gregset (regcache, ®s, regnum); |
0e56aeaf MK |
167 | |
168 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 169 | (PTRACE_TYPE_ARG3) ®s, 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. */ | |
190 | void _initialize_hppabsd_nat (void); | |
191 | ||
192 | void | |
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 | } |