Commit | Line | Data |
---|---|---|
0e56aeaf MK |
1 | /* Native-dependent code for HP PA-RISC BSD's. |
2 | ||
4c38e0a4 JB |
3 | Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010 |
4 | Free Software Foundation, Inc. | |
0e56aeaf MK |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
0e56aeaf MK |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0e56aeaf MK |
20 | |
21 | #include "defs.h" | |
22 | #include "inferior.h" | |
23 | #include "regcache.h" | |
57cd0b54 | 24 | #include "target.h" |
0e56aeaf MK |
25 | |
26 | #include <sys/types.h> | |
27 | #include <sys/ptrace.h> | |
28 | #include <machine/reg.h> | |
29 | ||
30 | #include "hppa-tdep.h" | |
57cd0b54 | 31 | #include "inf-ptrace.h" |
0e56aeaf MK |
32 | |
33 | static int | |
34 | hppabsd_gregset_supplies_p (int regnum) | |
35 | { | |
36 | return (regnum >= HPPA_R0_REGNUM && regnum <= HPPA_PCOQ_TAIL_REGNUM); | |
37 | } | |
38 | ||
20776c7d MK |
39 | static int |
40 | hppabsd_fpregset_supplies_p (int regnum) | |
41 | { | |
42 | return (regnum >= HPPA_FP0_REGNUM && regnum <= HPPA_FP31R_REGNUM); | |
43 | } | |
44 | ||
0e56aeaf MK |
45 | /* Supply the general-purpose registers stored in GREGS to REGCACHE. */ |
46 | ||
47 | static void | |
48 | hppabsd_supply_gregset (struct regcache *regcache, const void *gregs) | |
49 | { | |
50 | const char *regs = gregs; | |
51 | int regnum; | |
52 | ||
53 | for (regnum = HPPA_R1_REGNUM; regnum <= HPPA_R31_REGNUM; regnum++) | |
54 | regcache_raw_supply (regcache, regnum, regs + regnum * 4); | |
55 | ||
56 | regcache_raw_supply (regcache, HPPA_SAR_REGNUM, regs); | |
57 | regcache_raw_supply (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4); | |
58 | regcache_raw_supply (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4); | |
59 | } | |
60 | ||
20776c7d MK |
61 | /* Supply the floating-point registers stored in FPREGS to REGCACHE. */ |
62 | ||
63 | static void | |
64 | hppabsd_supply_fpregset (struct regcache *regcache, const void *fpregs) | |
65 | { | |
66 | const char *regs = fpregs; | |
67 | int regnum; | |
68 | ||
69 | for (regnum = HPPA_FP0_REGNUM; regnum <= HPPA_FP31R_REGNUM; | |
70 | regnum += 2, regs += 8) | |
71 | { | |
72 | regcache_raw_supply (regcache, regnum, regs); | |
73 | regcache_raw_supply (regcache, regnum + 1, regs + 4); | |
74 | } | |
75 | } | |
76 | ||
0e56aeaf MK |
77 | /* Collect the general-purpose registers from REGCACHE and store them |
78 | in GREGS. */ | |
79 | ||
80 | static void | |
81 | hppabsd_collect_gregset (const struct regcache *regcache, | |
82 | void *gregs, int regnum) | |
83 | { | |
84 | char *regs = gregs; | |
85 | int i; | |
86 | ||
87 | for (i = HPPA_R1_REGNUM; i <= HPPA_R31_REGNUM; i++) | |
88 | { | |
89 | if (regnum == -1 || regnum == i) | |
90 | regcache_raw_collect (regcache, i, regs + i * 4); | |
91 | } | |
92 | ||
93 | if (regnum == -1 || regnum == HPPA_SAR_REGNUM) | |
94 | regcache_raw_collect (regcache, HPPA_SAR_REGNUM, regs); | |
95 | if (regnum == -1 || regnum == HPPA_PCOQ_HEAD_REGNUM) | |
96 | regcache_raw_collect (regcache, HPPA_PCOQ_HEAD_REGNUM, regs + 32 * 4); | |
97 | if (regnum == -1 || regnum == HPPA_PCOQ_TAIL_REGNUM) | |
98 | regcache_raw_collect (regcache, HPPA_PCOQ_TAIL_REGNUM, regs + 33 * 4); | |
99 | } | |
20776c7d MK |
100 | |
101 | /* Collect the floating-point registers from REGCACHE and store them | |
102 | in FPREGS. */ | |
103 | ||
104 | static void | |
105 | hppabsd_collect_fpregset (struct regcache *regcache, | |
106 | void *fpregs, int regnum) | |
107 | { | |
108 | char *regs = fpregs; | |
109 | int i; | |
110 | ||
111 | for (i = HPPA_FP0_REGNUM; i <= HPPA_FP31R_REGNUM; i += 2, regs += 8) | |
112 | { | |
113 | if (regnum == -1 || regnum == i || regnum == i + 1) | |
114 | { | |
115 | regcache_raw_collect (regcache, i, regs); | |
116 | regcache_raw_collect (regcache, i + 1, regs + 4); | |
117 | } | |
118 | } | |
119 | } | |
0e56aeaf MK |
120 | \f |
121 | ||
122 | /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this | |
123 | for all registers (including the floating-point registers). */ | |
124 | ||
57cd0b54 | 125 | static void |
28439f5e PA |
126 | hppabsd_fetch_registers (struct target_ops *ops, |
127 | 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) ®s, 0) == -1) |
e2e0b3e5 | 135 | perror_with_name (_("Couldn't get registers")); |
0e56aeaf MK |
136 | |
137 | hppabsd_supply_gregset (regcache, ®s); | |
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 | 155 | static void |
28439f5e PA |
156 | hppabsd_store_registers (struct target_ops *ops, |
157 | struct regcache *regcache, int regnum) | |
0e56aeaf MK |
158 | { |
159 | if (regnum == -1 || hppabsd_gregset_supplies_p (regnum)) | |
160 | { | |
161 | struct reg regs; | |
162 | ||
163 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 164 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 165 | perror_with_name (_("Couldn't get registers")); |
0e56aeaf | 166 | |
56be3814 | 167 | hppabsd_collect_gregset (regcache, ®s, regnum); |
0e56aeaf MK |
168 | |
169 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 170 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 171 | perror_with_name (_("Couldn't write registers")); |
0e56aeaf | 172 | } |
20776c7d MK |
173 | |
174 | if (regnum == -1 || hppabsd_fpregset_supplies_p (regnum)) | |
175 | { | |
176 | struct fpreg fpregs; | |
177 | ||
178 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
179 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | |
180 | perror_with_name (_("Couldn't get floating point status")); | |
181 | ||
56be3814 | 182 | hppabsd_collect_fpregset (regcache, &fpregs, regnum); |
20776c7d MK |
183 | |
184 | if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), | |
185 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | |
186 | perror_with_name (_("Couldn't write floating point status")); | |
187 | } | |
0e56aeaf | 188 | } |
57cd0b54 MK |
189 | |
190 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
191 | void _initialize_hppabsd_nat (void); | |
192 | ||
193 | void | |
194 | _initialize_hppabsd_nat (void) | |
195 | { | |
196 | struct target_ops *t; | |
197 | ||
198 | /* Add in local overrides. */ | |
199 | t = inf_ptrace_target (); | |
200 | t->to_fetch_registers = hppabsd_fetch_registers; | |
201 | t->to_store_registers = hppabsd_store_registers; | |
202 | add_target (t); | |
203 | } |