]>
Commit | Line | Data |
---|---|---|
9abe5450 | 1 | /* PPC GNU/Linux native support. |
2555fe1a | 2 | |
6aba47ca | 3 | Copyright (C) 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003, |
4c38e0a4 | 4 | 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
c877c8e6 KB |
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 |
c877c8e6 KB |
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/>. */ |
c877c8e6 KB |
20 | |
21 | #include "defs.h" | |
e162d11b | 22 | #include "gdb_string.h" |
c877c8e6 KB |
23 | #include "frame.h" |
24 | #include "inferior.h" | |
25 | #include "gdbcore.h" | |
4e052eda | 26 | #include "regcache.h" |
383f0f5b | 27 | #include "gdb_assert.h" |
10d6c8cd DJ |
28 | #include "target.h" |
29 | #include "linux-nat.h" | |
c877c8e6 | 30 | |
411cb3f9 | 31 | #include <stdint.h> |
c877c8e6 KB |
32 | #include <sys/types.h> |
33 | #include <sys/param.h> | |
34 | #include <signal.h> | |
35 | #include <sys/user.h> | |
36 | #include <sys/ioctl.h> | |
2555fe1a | 37 | #include "gdb_wait.h" |
c877c8e6 KB |
38 | #include <fcntl.h> |
39 | #include <sys/procfs.h> | |
45229ea4 | 40 | #include <sys/ptrace.h> |
c877c8e6 | 41 | |
c60c0f5f MS |
42 | /* Prototypes for supply_gregset etc. */ |
43 | #include "gregset.h" | |
16333c4f | 44 | #include "ppc-tdep.h" |
7284e1be UW |
45 | #include "ppc-linux-tdep.h" |
46 | ||
b7622095 LM |
47 | /* Required when using the AUXV. */ |
48 | #include "elf/common.h" | |
49 | #include "auxv.h" | |
50 | ||
7284e1be UW |
51 | /* This sometimes isn't defined. */ |
52 | #ifndef PT_ORIG_R3 | |
53 | #define PT_ORIG_R3 34 | |
54 | #endif | |
55 | #ifndef PT_TRAP | |
56 | #define PT_TRAP 40 | |
57 | #endif | |
c60c0f5f | 58 | |
69abc51c TJB |
59 | /* The PPC_FEATURE_* defines should be provided by <asm/cputable.h>. |
60 | If they aren't, we can provide them ourselves (their values are fixed | |
61 | because they are part of the kernel ABI). They are used in the AT_HWCAP | |
62 | entry of the AUXV. */ | |
f4d9bade UW |
63 | #ifndef PPC_FEATURE_CELL |
64 | #define PPC_FEATURE_CELL 0x00010000 | |
65 | #endif | |
b7622095 LM |
66 | #ifndef PPC_FEATURE_BOOKE |
67 | #define PPC_FEATURE_BOOKE 0x00008000 | |
68 | #endif | |
f04c6d38 TJB |
69 | #ifndef PPC_FEATURE_HAS_DFP |
70 | #define PPC_FEATURE_HAS_DFP 0x00000400 /* Decimal Floating Point. */ | |
69abc51c | 71 | #endif |
b7622095 | 72 | |
9abe5450 EZ |
73 | /* Glibc's headers don't define PTRACE_GETVRREGS so we cannot use a |
74 | configure time check. Some older glibc's (for instance 2.2.1) | |
75 | don't have a specific powerpc version of ptrace.h, and fall back on | |
76 | a generic one. In such cases, sys/ptrace.h defines | |
77 | PTRACE_GETFPXREGS and PTRACE_SETFPXREGS to the same numbers that | |
78 | ppc kernel's asm/ptrace.h defines PTRACE_GETVRREGS and | |
79 | PTRACE_SETVRREGS to be. This also makes a configury check pretty | |
80 | much useless. */ | |
81 | ||
82 | /* These definitions should really come from the glibc header files, | |
83 | but Glibc doesn't know about the vrregs yet. */ | |
84 | #ifndef PTRACE_GETVRREGS | |
85 | #define PTRACE_GETVRREGS 18 | |
86 | #define PTRACE_SETVRREGS 19 | |
87 | #endif | |
88 | ||
604c2f83 LM |
89 | /* PTRACE requests for POWER7 VSX registers. */ |
90 | #ifndef PTRACE_GETVSXREGS | |
91 | #define PTRACE_GETVSXREGS 27 | |
92 | #define PTRACE_SETVSXREGS 28 | |
93 | #endif | |
01904826 JB |
94 | |
95 | /* Similarly for the ptrace requests for getting / setting the SPE | |
96 | registers (ev0 -- ev31, acc, and spefscr). See the description of | |
97 | gdb_evrregset_t for details. */ | |
98 | #ifndef PTRACE_GETEVRREGS | |
99 | #define PTRACE_GETEVRREGS 20 | |
100 | #define PTRACE_SETEVRREGS 21 | |
101 | #endif | |
102 | ||
e0d24f8d WZ |
103 | /* Similarly for the hardware watchpoint support. */ |
104 | #ifndef PTRACE_GET_DEBUGREG | |
105 | #define PTRACE_GET_DEBUGREG 25 | |
106 | #endif | |
107 | #ifndef PTRACE_SET_DEBUGREG | |
108 | #define PTRACE_SET_DEBUGREG 26 | |
109 | #endif | |
110 | #ifndef PTRACE_GETSIGINFO | |
111 | #define PTRACE_GETSIGINFO 0x4202 | |
112 | #endif | |
01904826 | 113 | |
1dfe79e8 SDJ |
114 | /* Similarly for the general-purpose (gp0 -- gp31) |
115 | and floating-point registers (fp0 -- fp31). */ | |
116 | #ifndef PTRACE_GETREGS | |
117 | #define PTRACE_GETREGS 12 | |
118 | #endif | |
119 | #ifndef PTRACE_SETREGS | |
120 | #define PTRACE_SETREGS 13 | |
121 | #endif | |
122 | #ifndef PTRACE_GETFPREGS | |
123 | #define PTRACE_GETFPREGS 14 | |
124 | #endif | |
125 | #ifndef PTRACE_SETFPREGS | |
126 | #define PTRACE_SETFPREGS 15 | |
127 | #endif | |
128 | ||
9abe5450 EZ |
129 | /* This oddity is because the Linux kernel defines elf_vrregset_t as |
130 | an array of 33 16 bytes long elements. I.e. it leaves out vrsave. | |
131 | However the PTRACE_GETVRREGS and PTRACE_SETVRREGS requests return | |
132 | the vrsave as an extra 4 bytes at the end. I opted for creating a | |
133 | flat array of chars, so that it is easier to manipulate for gdb. | |
134 | ||
135 | There are 32 vector registers 16 bytes longs, plus a VSCR register | |
136 | which is only 4 bytes long, but is fetched as a 16 bytes | |
137 | quantity. Up to here we have the elf_vrregset_t structure. | |
138 | Appended to this there is space for the VRSAVE register: 4 bytes. | |
139 | Even though this vrsave register is not included in the regset | |
140 | typedef, it is handled by the ptrace requests. | |
141 | ||
142 | Note that GNU/Linux doesn't support little endian PPC hardware, | |
143 | therefore the offset at which the real value of the VSCR register | |
144 | is located will be always 12 bytes. | |
145 | ||
146 | The layout is like this (where x is the actual value of the vscr reg): */ | |
147 | ||
148 | /* *INDENT-OFF* */ | |
149 | /* | |
150 | |.|.|.|.|.....|.|.|.|.||.|.|.|x||.| | |
151 | <-------> <-------><-------><-> | |
152 | VR0 VR31 VSCR VRSAVE | |
153 | */ | |
154 | /* *INDENT-ON* */ | |
155 | ||
156 | #define SIZEOF_VRREGS 33*16+4 | |
157 | ||
158 | typedef char gdb_vrregset_t[SIZEOF_VRREGS]; | |
159 | ||
604c2f83 LM |
160 | /* This is the layout of the POWER7 VSX registers and the way they overlap |
161 | with the existing FPR and VMX registers. | |
162 | ||
163 | VSR doubleword 0 VSR doubleword 1 | |
164 | ---------------------------------------------------------------- | |
165 | VSR[0] | FPR[0] | | | |
166 | ---------------------------------------------------------------- | |
167 | VSR[1] | FPR[1] | | | |
168 | ---------------------------------------------------------------- | |
169 | | ... | | | |
170 | | ... | | | |
171 | ---------------------------------------------------------------- | |
172 | VSR[30] | FPR[30] | | | |
173 | ---------------------------------------------------------------- | |
174 | VSR[31] | FPR[31] | | | |
175 | ---------------------------------------------------------------- | |
176 | VSR[32] | VR[0] | | |
177 | ---------------------------------------------------------------- | |
178 | VSR[33] | VR[1] | | |
179 | ---------------------------------------------------------------- | |
180 | | ... | | |
181 | | ... | | |
182 | ---------------------------------------------------------------- | |
183 | VSR[62] | VR[30] | | |
184 | ---------------------------------------------------------------- | |
185 | VSR[63] | VR[31] | | |
186 | ---------------------------------------------------------------- | |
187 | ||
188 | VSX has 64 128bit registers. The first 32 registers overlap with | |
189 | the FP registers (doubleword 0) and hence extend them with additional | |
190 | 64 bits (doubleword 1). The other 32 regs overlap with the VMX | |
191 | registers. */ | |
192 | #define SIZEOF_VSXREGS 32*8 | |
193 | ||
194 | typedef char gdb_vsxregset_t[SIZEOF_VSXREGS]; | |
01904826 JB |
195 | |
196 | /* On PPC processors that support the the Signal Processing Extension | |
197 | (SPE) APU, the general-purpose registers are 64 bits long. | |
411cb3f9 PG |
198 | However, the ordinary Linux kernel PTRACE_PEEKUSER / PTRACE_POKEUSER |
199 | ptrace calls only access the lower half of each register, to allow | |
200 | them to behave the same way they do on non-SPE systems. There's a | |
201 | separate pair of calls, PTRACE_GETEVRREGS / PTRACE_SETEVRREGS, that | |
202 | read and write the top halves of all the general-purpose registers | |
203 | at once, along with some SPE-specific registers. | |
01904826 JB |
204 | |
205 | GDB itself continues to claim the general-purpose registers are 32 | |
6ced10dd JB |
206 | bits long. It has unnamed raw registers that hold the upper halves |
207 | of the gprs, and the the full 64-bit SIMD views of the registers, | |
208 | 'ev0' -- 'ev31', are pseudo-registers that splice the top and | |
209 | bottom halves together. | |
01904826 JB |
210 | |
211 | This is the structure filled in by PTRACE_GETEVRREGS and written to | |
212 | the inferior's registers by PTRACE_SETEVRREGS. */ | |
213 | struct gdb_evrregset_t | |
214 | { | |
215 | unsigned long evr[32]; | |
216 | unsigned long long acc; | |
217 | unsigned long spefscr; | |
218 | }; | |
219 | ||
604c2f83 LM |
220 | /* Non-zero if our kernel may support the PTRACE_GETVSXREGS and |
221 | PTRACE_SETVSXREGS requests, for reading and writing the VSX | |
222 | POWER7 registers 0 through 31. Zero if we've tried one of them and | |
223 | gotten an error. Note that VSX registers 32 through 63 overlap | |
224 | with VR registers 0 through 31. */ | |
225 | int have_ptrace_getsetvsxregs = 1; | |
01904826 JB |
226 | |
227 | /* Non-zero if our kernel may support the PTRACE_GETVRREGS and | |
228 | PTRACE_SETVRREGS requests, for reading and writing the Altivec | |
229 | registers. Zero if we've tried one of them and gotten an | |
230 | error. */ | |
9abe5450 EZ |
231 | int have_ptrace_getvrregs = 1; |
232 | ||
01904826 JB |
233 | /* Non-zero if our kernel may support the PTRACE_GETEVRREGS and |
234 | PTRACE_SETEVRREGS requests, for reading and writing the SPE | |
235 | registers. Zero if we've tried one of them and gotten an | |
236 | error. */ | |
237 | int have_ptrace_getsetevrregs = 1; | |
238 | ||
1dfe79e8 SDJ |
239 | /* Non-zero if our kernel may support the PTRACE_GETREGS and |
240 | PTRACE_SETREGS requests, for reading and writing the | |
241 | general-purpose registers. Zero if we've tried one of | |
242 | them and gotten an error. */ | |
243 | int have_ptrace_getsetregs = 1; | |
244 | ||
245 | /* Non-zero if our kernel may support the PTRACE_GETFPREGS and | |
246 | PTRACE_SETFPREGS requests, for reading and writing the | |
247 | floating-pointers registers. Zero if we've tried one of | |
248 | them and gotten an error. */ | |
249 | int have_ptrace_getsetfpregs = 1; | |
250 | ||
16333c4f EZ |
251 | /* *INDENT-OFF* */ |
252 | /* registers layout, as presented by the ptrace interface: | |
253 | PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7, | |
254 | PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15, | |
255 | PT_R16, PT_R17, PT_R18, PT_R19, PT_R20, PT_R21, PT_R22, PT_R23, | |
256 | PT_R24, PT_R25, PT_R26, PT_R27, PT_R28, PT_R29, PT_R30, PT_R31, | |
257 | PT_FPR0, PT_FPR0 + 2, PT_FPR0 + 4, PT_FPR0 + 6, PT_FPR0 + 8, PT_FPR0 + 10, PT_FPR0 + 12, PT_FPR0 + 14, | |
258 | PT_FPR0 + 16, PT_FPR0 + 18, PT_FPR0 + 20, PT_FPR0 + 22, PT_FPR0 + 24, PT_FPR0 + 26, PT_FPR0 + 28, PT_FPR0 + 30, | |
259 | PT_FPR0 + 32, PT_FPR0 + 34, PT_FPR0 + 36, PT_FPR0 + 38, PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46, | |
260 | PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54, PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62, | |
261 | PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */ | |
262 | /* *INDENT_ON * */ | |
c877c8e6 | 263 | |
45229ea4 | 264 | static int |
e101270f | 265 | ppc_register_u_addr (struct gdbarch *gdbarch, int regno) |
c877c8e6 | 266 | { |
16333c4f | 267 | int u_addr = -1; |
e101270f | 268 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
56d0d96a AC |
269 | /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace |
270 | interface, and not the wordsize of the program's ABI. */ | |
411cb3f9 | 271 | int wordsize = sizeof (long); |
16333c4f EZ |
272 | |
273 | /* General purpose registers occupy 1 slot each in the buffer */ | |
8bf659e8 JB |
274 | if (regno >= tdep->ppc_gp0_regnum |
275 | && regno < tdep->ppc_gp0_regnum + ppc_num_gprs) | |
26e75e5c | 276 | u_addr = ((regno - tdep->ppc_gp0_regnum + PT_R0) * wordsize); |
16333c4f | 277 | |
49ff75ad JB |
278 | /* Floating point regs: eight bytes each in both 32- and 64-bit |
279 | ptrace interfaces. Thus, two slots each in 32-bit interface, one | |
280 | slot each in 64-bit interface. */ | |
383f0f5b JB |
281 | if (tdep->ppc_fp0_regnum >= 0 |
282 | && regno >= tdep->ppc_fp0_regnum | |
366f009f JB |
283 | && regno < tdep->ppc_fp0_regnum + ppc_num_fprs) |
284 | u_addr = (PT_FPR0 * wordsize) + ((regno - tdep->ppc_fp0_regnum) * 8); | |
16333c4f EZ |
285 | |
286 | /* UISA special purpose registers: 1 slot each */ | |
e101270f | 287 | if (regno == gdbarch_pc_regnum (gdbarch)) |
49ff75ad | 288 | u_addr = PT_NIP * wordsize; |
dc5cfeb6 | 289 | if (regno == tdep->ppc_lr_regnum) |
49ff75ad | 290 | u_addr = PT_LNK * wordsize; |
dc5cfeb6 | 291 | if (regno == tdep->ppc_cr_regnum) |
49ff75ad | 292 | u_addr = PT_CCR * wordsize; |
dc5cfeb6 | 293 | if (regno == tdep->ppc_xer_regnum) |
49ff75ad | 294 | u_addr = PT_XER * wordsize; |
dc5cfeb6 | 295 | if (regno == tdep->ppc_ctr_regnum) |
49ff75ad | 296 | u_addr = PT_CTR * wordsize; |
f8c59253 | 297 | #ifdef PT_MQ |
dc5cfeb6 | 298 | if (regno == tdep->ppc_mq_regnum) |
49ff75ad | 299 | u_addr = PT_MQ * wordsize; |
f8c59253 | 300 | #endif |
dc5cfeb6 | 301 | if (regno == tdep->ppc_ps_regnum) |
49ff75ad | 302 | u_addr = PT_MSR * wordsize; |
7284e1be UW |
303 | if (regno == PPC_ORIG_R3_REGNUM) |
304 | u_addr = PT_ORIG_R3 * wordsize; | |
305 | if (regno == PPC_TRAP_REGNUM) | |
306 | u_addr = PT_TRAP * wordsize; | |
383f0f5b JB |
307 | if (tdep->ppc_fpscr_regnum >= 0 |
308 | && regno == tdep->ppc_fpscr_regnum) | |
8f135812 AC |
309 | { |
310 | /* NOTE: cagney/2005-02-08: On some 64-bit GNU/Linux systems the | |
311 | kernel headers incorrectly contained the 32-bit definition of | |
312 | PT_FPSCR. For the 32-bit definition, floating-point | |
313 | registers occupy two 32-bit "slots", and the FPSCR lives in | |
69abc51c | 314 | the second half of such a slot-pair (hence +1). For 64-bit, |
8f135812 AC |
315 | the FPSCR instead occupies the full 64-bit 2-word-slot and |
316 | hence no adjustment is necessary. Hack around this. */ | |
317 | if (wordsize == 8 && PT_FPSCR == (48 + 32 + 1)) | |
318 | u_addr = (48 + 32) * wordsize; | |
69abc51c TJB |
319 | /* If the FPSCR is 64-bit wide, we need to fetch the whole 64-bit |
320 | slot and not just its second word. The PT_FPSCR supplied when | |
321 | GDB is compiled as a 32-bit app doesn't reflect this. */ | |
322 | else if (wordsize == 4 && register_size (gdbarch, regno) == 8 | |
323 | && PT_FPSCR == (48 + 2*32 + 1)) | |
324 | u_addr = (48 + 2*32) * wordsize; | |
8f135812 AC |
325 | else |
326 | u_addr = PT_FPSCR * wordsize; | |
327 | } | |
16333c4f | 328 | return u_addr; |
c877c8e6 KB |
329 | } |
330 | ||
604c2f83 LM |
331 | /* The Linux kernel ptrace interface for POWER7 VSX registers uses the |
332 | registers set mechanism, as opposed to the interface for all the | |
333 | other registers, that stores/fetches each register individually. */ | |
334 | static void | |
335 | fetch_vsx_register (struct regcache *regcache, int tid, int regno) | |
336 | { | |
337 | int ret; | |
338 | gdb_vsxregset_t regs; | |
339 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
340 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
341 | int vsxregsize = register_size (gdbarch, tdep->ppc_vsr0_upper_regnum); | |
342 | ||
343 | ret = ptrace (PTRACE_GETVSXREGS, tid, 0, ®s); | |
344 | if (ret < 0) | |
345 | { | |
346 | if (errno == EIO) | |
347 | { | |
348 | have_ptrace_getsetvsxregs = 0; | |
349 | return; | |
350 | } | |
351 | perror_with_name (_("Unable to fetch VSX register")); | |
352 | } | |
353 | ||
354 | regcache_raw_supply (regcache, regno, | |
355 | regs + (regno - tdep->ppc_vsr0_upper_regnum) | |
356 | * vsxregsize); | |
357 | } | |
358 | ||
9abe5450 EZ |
359 | /* The Linux kernel ptrace interface for AltiVec registers uses the |
360 | registers set mechanism, as opposed to the interface for all the | |
361 | other registers, that stores/fetches each register individually. */ | |
362 | static void | |
56be3814 | 363 | fetch_altivec_register (struct regcache *regcache, int tid, int regno) |
9abe5450 EZ |
364 | { |
365 | int ret; | |
366 | int offset = 0; | |
367 | gdb_vrregset_t regs; | |
40a6adc1 MD |
368 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
369 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
370 | int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum); | |
9abe5450 EZ |
371 | |
372 | ret = ptrace (PTRACE_GETVRREGS, tid, 0, ®s); | |
373 | if (ret < 0) | |
374 | { | |
375 | if (errno == EIO) | |
376 | { | |
377 | have_ptrace_getvrregs = 0; | |
378 | return; | |
379 | } | |
e2e0b3e5 | 380 | perror_with_name (_("Unable to fetch AltiVec register")); |
9abe5450 EZ |
381 | } |
382 | ||
383 | /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes | |
384 | long on the hardware. We deal only with the lower 4 bytes of the | |
385 | vector. VRSAVE is at the end of the array in a 4 bytes slot, so | |
386 | there is no need to define an offset for it. */ | |
387 | if (regno == (tdep->ppc_vrsave_regnum - 1)) | |
40a6adc1 | 388 | offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum); |
9abe5450 | 389 | |
56be3814 | 390 | regcache_raw_supply (regcache, regno, |
23a6d369 | 391 | regs + (regno - tdep->ppc_vr0_regnum) * vrregsize + offset); |
9abe5450 EZ |
392 | } |
393 | ||
01904826 JB |
394 | /* Fetch the top 32 bits of TID's general-purpose registers and the |
395 | SPE-specific registers, and place the results in EVRREGSET. If we | |
396 | don't support PTRACE_GETEVRREGS, then just fill EVRREGSET with | |
397 | zeros. | |
398 | ||
399 | All the logic to deal with whether or not the PTRACE_GETEVRREGS and | |
400 | PTRACE_SETEVRREGS requests are supported is isolated here, and in | |
401 | set_spe_registers. */ | |
402 | static void | |
403 | get_spe_registers (int tid, struct gdb_evrregset_t *evrregset) | |
404 | { | |
405 | if (have_ptrace_getsetevrregs) | |
406 | { | |
407 | if (ptrace (PTRACE_GETEVRREGS, tid, 0, evrregset) >= 0) | |
408 | return; | |
409 | else | |
410 | { | |
411 | /* EIO means that the PTRACE_GETEVRREGS request isn't supported; | |
412 | we just return zeros. */ | |
413 | if (errno == EIO) | |
414 | have_ptrace_getsetevrregs = 0; | |
415 | else | |
416 | /* Anything else needs to be reported. */ | |
e2e0b3e5 | 417 | perror_with_name (_("Unable to fetch SPE registers")); |
01904826 JB |
418 | } |
419 | } | |
420 | ||
421 | memset (evrregset, 0, sizeof (*evrregset)); | |
422 | } | |
423 | ||
6ced10dd JB |
424 | /* Supply values from TID for SPE-specific raw registers: the upper |
425 | halves of the GPRs, the accumulator, and the spefscr. REGNO must | |
426 | be the number of an upper half register, acc, spefscr, or -1 to | |
427 | supply the values of all registers. */ | |
01904826 | 428 | static void |
56be3814 | 429 | fetch_spe_register (struct regcache *regcache, int tid, int regno) |
01904826 | 430 | { |
40a6adc1 MD |
431 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
432 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
01904826 JB |
433 | struct gdb_evrregset_t evrregs; |
434 | ||
6ced10dd | 435 | gdb_assert (sizeof (evrregs.evr[0]) |
40a6adc1 | 436 | == register_size (gdbarch, tdep->ppc_ev0_upper_regnum)); |
6ced10dd | 437 | gdb_assert (sizeof (evrregs.acc) |
40a6adc1 | 438 | == register_size (gdbarch, tdep->ppc_acc_regnum)); |
6ced10dd | 439 | gdb_assert (sizeof (evrregs.spefscr) |
40a6adc1 | 440 | == register_size (gdbarch, tdep->ppc_spefscr_regnum)); |
6ced10dd | 441 | |
01904826 JB |
442 | get_spe_registers (tid, &evrregs); |
443 | ||
6ced10dd | 444 | if (regno == -1) |
01904826 | 445 | { |
6ced10dd JB |
446 | int i; |
447 | ||
448 | for (i = 0; i < ppc_num_gprs; i++) | |
56be3814 | 449 | regcache_raw_supply (regcache, tdep->ppc_ev0_upper_regnum + i, |
6ced10dd | 450 | &evrregs.evr[i]); |
01904826 | 451 | } |
6ced10dd JB |
452 | else if (tdep->ppc_ev0_upper_regnum <= regno |
453 | && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs) | |
56be3814 | 454 | regcache_raw_supply (regcache, regno, |
6ced10dd JB |
455 | &evrregs.evr[regno - tdep->ppc_ev0_upper_regnum]); |
456 | ||
457 | if (regno == -1 | |
458 | || regno == tdep->ppc_acc_regnum) | |
56be3814 | 459 | regcache_raw_supply (regcache, tdep->ppc_acc_regnum, &evrregs.acc); |
6ced10dd JB |
460 | |
461 | if (regno == -1 | |
462 | || regno == tdep->ppc_spefscr_regnum) | |
56be3814 | 463 | regcache_raw_supply (regcache, tdep->ppc_spefscr_regnum, |
6ced10dd | 464 | &evrregs.spefscr); |
01904826 JB |
465 | } |
466 | ||
45229ea4 | 467 | static void |
56be3814 | 468 | fetch_register (struct regcache *regcache, int tid, int regno) |
45229ea4 | 469 | { |
40a6adc1 MD |
470 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
471 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
45229ea4 | 472 | /* This isn't really an address. But ptrace thinks of it as one. */ |
e101270f | 473 | CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno); |
4a19ea35 | 474 | int bytes_transferred; |
45229ea4 | 475 | unsigned int offset; /* Offset of registers within the u area. */ |
d9d9c31f | 476 | char buf[MAX_REGISTER_SIZE]; |
45229ea4 | 477 | |
be8626e0 | 478 | if (altivec_register_p (gdbarch, regno)) |
9abe5450 EZ |
479 | { |
480 | /* If this is the first time through, or if it is not the first | |
481 | time through, and we have comfirmed that there is kernel | |
482 | support for such a ptrace request, then go and fetch the | |
483 | register. */ | |
484 | if (have_ptrace_getvrregs) | |
485 | { | |
56be3814 | 486 | fetch_altivec_register (regcache, tid, regno); |
9abe5450 EZ |
487 | return; |
488 | } | |
489 | /* If we have discovered that there is no ptrace support for | |
490 | AltiVec registers, fall through and return zeroes, because | |
491 | regaddr will be -1 in this case. */ | |
492 | } | |
604c2f83 LM |
493 | if (vsx_register_p (gdbarch, regno)) |
494 | { | |
495 | if (have_ptrace_getsetvsxregs) | |
496 | { | |
497 | fetch_vsx_register (regcache, tid, regno); | |
498 | return; | |
499 | } | |
500 | } | |
be8626e0 | 501 | else if (spe_register_p (gdbarch, regno)) |
01904826 | 502 | { |
56be3814 | 503 | fetch_spe_register (regcache, tid, regno); |
01904826 JB |
504 | return; |
505 | } | |
9abe5450 | 506 | |
45229ea4 EZ |
507 | if (regaddr == -1) |
508 | { | |
40a6adc1 | 509 | memset (buf, '\0', register_size (gdbarch, regno)); /* Supply zeroes */ |
56be3814 | 510 | regcache_raw_supply (regcache, regno, buf); |
45229ea4 EZ |
511 | return; |
512 | } | |
513 | ||
411cb3f9 | 514 | /* Read the raw register using sizeof(long) sized chunks. On a |
56d0d96a AC |
515 | 32-bit platform, 64-bit floating-point registers will require two |
516 | transfers. */ | |
4a19ea35 | 517 | for (bytes_transferred = 0; |
40a6adc1 | 518 | bytes_transferred < register_size (gdbarch, regno); |
411cb3f9 | 519 | bytes_transferred += sizeof (long)) |
45229ea4 EZ |
520 | { |
521 | errno = 0; | |
411cb3f9 PG |
522 | *(long *) &buf[bytes_transferred] |
523 | = ptrace (PTRACE_PEEKUSER, tid, (PTRACE_TYPE_ARG3) regaddr, 0); | |
524 | regaddr += sizeof (long); | |
45229ea4 EZ |
525 | if (errno != 0) |
526 | { | |
bc97b3ba JB |
527 | char message[128]; |
528 | sprintf (message, "reading register %s (#%d)", | |
40a6adc1 | 529 | gdbarch_register_name (gdbarch, regno), regno); |
bc97b3ba | 530 | perror_with_name (message); |
45229ea4 EZ |
531 | } |
532 | } | |
56d0d96a | 533 | |
4a19ea35 JB |
534 | /* Now supply the register. Keep in mind that the regcache's idea |
535 | of the register's size may not be a multiple of sizeof | |
411cb3f9 | 536 | (long). */ |
40a6adc1 | 537 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) |
4a19ea35 JB |
538 | { |
539 | /* Little-endian values are always found at the left end of the | |
540 | bytes transferred. */ | |
56be3814 | 541 | regcache_raw_supply (regcache, regno, buf); |
4a19ea35 | 542 | } |
40a6adc1 | 543 | else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
4a19ea35 JB |
544 | { |
545 | /* Big-endian values are found at the right end of the bytes | |
546 | transferred. */ | |
40a6adc1 | 547 | size_t padding = (bytes_transferred - register_size (gdbarch, regno)); |
56be3814 | 548 | regcache_raw_supply (regcache, regno, buf + padding); |
4a19ea35 JB |
549 | } |
550 | else | |
a44bddec | 551 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 552 | _("fetch_register: unexpected byte order: %d"), |
40a6adc1 | 553 | gdbarch_byte_order (gdbarch)); |
45229ea4 EZ |
554 | } |
555 | ||
604c2f83 LM |
556 | static void |
557 | supply_vsxregset (struct regcache *regcache, gdb_vsxregset_t *vsxregsetp) | |
558 | { | |
559 | int i; | |
560 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
561 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
562 | int vsxregsize = register_size (gdbarch, tdep->ppc_vsr0_upper_regnum); | |
563 | ||
564 | for (i = 0; i < ppc_num_vshrs; i++) | |
565 | { | |
566 | regcache_raw_supply (regcache, tdep->ppc_vsr0_upper_regnum + i, | |
567 | *vsxregsetp + i * vsxregsize); | |
568 | } | |
569 | } | |
570 | ||
9abe5450 | 571 | static void |
56be3814 | 572 | supply_vrregset (struct regcache *regcache, gdb_vrregset_t *vrregsetp) |
9abe5450 EZ |
573 | { |
574 | int i; | |
40a6adc1 MD |
575 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
576 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
9abe5450 | 577 | int num_of_vrregs = tdep->ppc_vrsave_regnum - tdep->ppc_vr0_regnum + 1; |
40a6adc1 MD |
578 | int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum); |
579 | int offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum); | |
9abe5450 EZ |
580 | |
581 | for (i = 0; i < num_of_vrregs; i++) | |
582 | { | |
583 | /* The last 2 registers of this set are only 32 bit long, not | |
584 | 128. However an offset is necessary only for VSCR because it | |
585 | occupies a whole vector, while VRSAVE occupies a full 4 bytes | |
586 | slot. */ | |
587 | if (i == (num_of_vrregs - 2)) | |
56be3814 | 588 | regcache_raw_supply (regcache, tdep->ppc_vr0_regnum + i, |
23a6d369 | 589 | *vrregsetp + i * vrregsize + offset); |
9abe5450 | 590 | else |
56be3814 | 591 | regcache_raw_supply (regcache, tdep->ppc_vr0_regnum + i, |
23a6d369 | 592 | *vrregsetp + i * vrregsize); |
9abe5450 EZ |
593 | } |
594 | } | |
595 | ||
604c2f83 LM |
596 | static void |
597 | fetch_vsx_registers (struct regcache *regcache, int tid) | |
598 | { | |
599 | int ret; | |
600 | gdb_vsxregset_t regs; | |
601 | ||
602 | ret = ptrace (PTRACE_GETVSXREGS, tid, 0, ®s); | |
603 | if (ret < 0) | |
604 | { | |
605 | if (errno == EIO) | |
606 | { | |
607 | have_ptrace_getsetvsxregs = 0; | |
608 | return; | |
609 | } | |
610 | perror_with_name (_("Unable to fetch VSX registers")); | |
611 | } | |
612 | supply_vsxregset (regcache, ®s); | |
613 | } | |
614 | ||
9abe5450 | 615 | static void |
56be3814 | 616 | fetch_altivec_registers (struct regcache *regcache, int tid) |
9abe5450 EZ |
617 | { |
618 | int ret; | |
619 | gdb_vrregset_t regs; | |
620 | ||
621 | ret = ptrace (PTRACE_GETVRREGS, tid, 0, ®s); | |
622 | if (ret < 0) | |
623 | { | |
624 | if (errno == EIO) | |
625 | { | |
626 | have_ptrace_getvrregs = 0; | |
627 | return; | |
628 | } | |
e2e0b3e5 | 629 | perror_with_name (_("Unable to fetch AltiVec registers")); |
9abe5450 | 630 | } |
56be3814 | 631 | supply_vrregset (regcache, ®s); |
9abe5450 EZ |
632 | } |
633 | ||
1dfe79e8 SDJ |
634 | /* This function actually issues the request to ptrace, telling |
635 | it to get all general-purpose registers and put them into the | |
636 | specified regset. | |
637 | ||
638 | If the ptrace request does not exist, this function returns 0 | |
639 | and properly sets the have_ptrace_* flag. If the request fails, | |
640 | this function calls perror_with_name. Otherwise, if the request | |
641 | succeeds, then the regcache gets filled and 1 is returned. */ | |
642 | static int | |
643 | fetch_all_gp_regs (struct regcache *regcache, int tid) | |
644 | { | |
645 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
646 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
647 | gdb_gregset_t gregset; | |
648 | ||
649 | if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0) | |
650 | { | |
651 | if (errno == EIO) | |
652 | { | |
653 | have_ptrace_getsetregs = 0; | |
654 | return 0; | |
655 | } | |
656 | perror_with_name (_("Couldn't get general-purpose registers.")); | |
657 | } | |
658 | ||
659 | supply_gregset (regcache, (const gdb_gregset_t *) &gregset); | |
660 | ||
661 | return 1; | |
662 | } | |
663 | ||
664 | /* This is a wrapper for the fetch_all_gp_regs function. It is | |
665 | responsible for verifying if this target has the ptrace request | |
666 | that can be used to fetch all general-purpose registers at one | |
667 | shot. If it doesn't, then we should fetch them using the | |
668 | old-fashioned way, which is to iterate over the registers and | |
669 | request them one by one. */ | |
670 | static void | |
671 | fetch_gp_regs (struct regcache *regcache, int tid) | |
672 | { | |
673 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
674 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
675 | int i; | |
676 | ||
677 | if (have_ptrace_getsetregs) | |
678 | if (fetch_all_gp_regs (regcache, tid)) | |
679 | return; | |
680 | ||
681 | /* If we've hit this point, it doesn't really matter which | |
682 | architecture we are using. We just need to read the | |
683 | registers in the "old-fashioned way". */ | |
684 | for (i = 0; i < ppc_num_gprs; i++) | |
685 | fetch_register (regcache, tid, tdep->ppc_gp0_regnum + i); | |
686 | } | |
687 | ||
688 | /* This function actually issues the request to ptrace, telling | |
689 | it to get all floating-point registers and put them into the | |
690 | specified regset. | |
691 | ||
692 | If the ptrace request does not exist, this function returns 0 | |
693 | and properly sets the have_ptrace_* flag. If the request fails, | |
694 | this function calls perror_with_name. Otherwise, if the request | |
695 | succeeds, then the regcache gets filled and 1 is returned. */ | |
696 | static int | |
697 | fetch_all_fp_regs (struct regcache *regcache, int tid) | |
698 | { | |
699 | gdb_fpregset_t fpregs; | |
700 | ||
701 | if (ptrace (PTRACE_GETFPREGS, tid, 0, (void *) &fpregs) < 0) | |
702 | { | |
703 | if (errno == EIO) | |
704 | { | |
705 | have_ptrace_getsetfpregs = 0; | |
706 | return 0; | |
707 | } | |
708 | perror_with_name (_("Couldn't get floating-point registers.")); | |
709 | } | |
710 | ||
711 | supply_fpregset (regcache, (const gdb_fpregset_t *) &fpregs); | |
712 | ||
713 | return 1; | |
714 | } | |
715 | ||
716 | /* This is a wrapper for the fetch_all_fp_regs function. It is | |
717 | responsible for verifying if this target has the ptrace request | |
718 | that can be used to fetch all floating-point registers at one | |
719 | shot. If it doesn't, then we should fetch them using the | |
720 | old-fashioned way, which is to iterate over the registers and | |
721 | request them one by one. */ | |
722 | static void | |
723 | fetch_fp_regs (struct regcache *regcache, int tid) | |
724 | { | |
725 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
726 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
727 | int i; | |
728 | ||
729 | if (have_ptrace_getsetfpregs) | |
730 | if (fetch_all_fp_regs (regcache, tid)) | |
731 | return; | |
732 | ||
733 | /* If we've hit this point, it doesn't really matter which | |
734 | architecture we are using. We just need to read the | |
735 | registers in the "old-fashioned way". */ | |
736 | for (i = 0; i < ppc_num_fprs; i++) | |
737 | fetch_register (regcache, tid, tdep->ppc_fp0_regnum + i); | |
738 | } | |
739 | ||
45229ea4 | 740 | static void |
56be3814 | 741 | fetch_ppc_registers (struct regcache *regcache, int tid) |
45229ea4 EZ |
742 | { |
743 | int i; | |
40a6adc1 MD |
744 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
745 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
9abe5450 | 746 | |
1dfe79e8 | 747 | fetch_gp_regs (regcache, tid); |
32b99774 | 748 | if (tdep->ppc_fp0_regnum >= 0) |
1dfe79e8 | 749 | fetch_fp_regs (regcache, tid); |
40a6adc1 | 750 | fetch_register (regcache, tid, gdbarch_pc_regnum (gdbarch)); |
32b99774 | 751 | if (tdep->ppc_ps_regnum != -1) |
56be3814 | 752 | fetch_register (regcache, tid, tdep->ppc_ps_regnum); |
32b99774 | 753 | if (tdep->ppc_cr_regnum != -1) |
56be3814 | 754 | fetch_register (regcache, tid, tdep->ppc_cr_regnum); |
32b99774 | 755 | if (tdep->ppc_lr_regnum != -1) |
56be3814 | 756 | fetch_register (regcache, tid, tdep->ppc_lr_regnum); |
32b99774 | 757 | if (tdep->ppc_ctr_regnum != -1) |
56be3814 | 758 | fetch_register (regcache, tid, tdep->ppc_ctr_regnum); |
32b99774 | 759 | if (tdep->ppc_xer_regnum != -1) |
56be3814 | 760 | fetch_register (regcache, tid, tdep->ppc_xer_regnum); |
e3f36dbd | 761 | if (tdep->ppc_mq_regnum != -1) |
56be3814 | 762 | fetch_register (regcache, tid, tdep->ppc_mq_regnum); |
7284e1be UW |
763 | if (ppc_linux_trap_reg_p (gdbarch)) |
764 | { | |
765 | fetch_register (regcache, tid, PPC_ORIG_R3_REGNUM); | |
766 | fetch_register (regcache, tid, PPC_TRAP_REGNUM); | |
767 | } | |
32b99774 | 768 | if (tdep->ppc_fpscr_regnum != -1) |
56be3814 | 769 | fetch_register (regcache, tid, tdep->ppc_fpscr_regnum); |
9abe5450 EZ |
770 | if (have_ptrace_getvrregs) |
771 | if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1) | |
56be3814 | 772 | fetch_altivec_registers (regcache, tid); |
604c2f83 LM |
773 | if (have_ptrace_getsetvsxregs) |
774 | if (tdep->ppc_vsr0_upper_regnum != -1) | |
775 | fetch_vsx_registers (regcache, tid); | |
6ced10dd | 776 | if (tdep->ppc_ev0_upper_regnum >= 0) |
56be3814 | 777 | fetch_spe_register (regcache, tid, -1); |
45229ea4 EZ |
778 | } |
779 | ||
780 | /* Fetch registers from the child process. Fetch all registers if | |
781 | regno == -1, otherwise fetch all general registers or all floating | |
782 | point registers depending upon the value of regno. */ | |
10d6c8cd | 783 | static void |
28439f5e PA |
784 | ppc_linux_fetch_inferior_registers (struct target_ops *ops, |
785 | struct regcache *regcache, int regno) | |
45229ea4 | 786 | { |
9abe5450 | 787 | /* Overload thread id onto process id */ |
05f13b9c EZ |
788 | int tid = TIDGET (inferior_ptid); |
789 | ||
790 | /* No thread id, just use process id */ | |
791 | if (tid == 0) | |
792 | tid = PIDGET (inferior_ptid); | |
793 | ||
9abe5450 | 794 | if (regno == -1) |
56be3814 | 795 | fetch_ppc_registers (regcache, tid); |
45229ea4 | 796 | else |
56be3814 | 797 | fetch_register (regcache, tid, regno); |
45229ea4 EZ |
798 | } |
799 | ||
604c2f83 LM |
800 | /* Store one VSX register. */ |
801 | static void | |
802 | store_vsx_register (const struct regcache *regcache, int tid, int regno) | |
803 | { | |
804 | int ret; | |
805 | gdb_vsxregset_t regs; | |
806 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
807 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
808 | int vsxregsize = register_size (gdbarch, tdep->ppc_vsr0_upper_regnum); | |
809 | ||
810 | ret = ptrace (PTRACE_SETVSXREGS, tid, 0, ®s); | |
811 | if (ret < 0) | |
812 | { | |
813 | if (errno == EIO) | |
814 | { | |
815 | have_ptrace_getsetvsxregs = 0; | |
816 | return; | |
817 | } | |
818 | perror_with_name (_("Unable to fetch VSX register")); | |
819 | } | |
820 | ||
821 | regcache_raw_collect (regcache, regno, regs + | |
822 | (regno - tdep->ppc_vsr0_upper_regnum) * vsxregsize); | |
823 | ||
824 | ret = ptrace (PTRACE_SETVSXREGS, tid, 0, ®s); | |
825 | if (ret < 0) | |
826 | perror_with_name (_("Unable to store VSX register")); | |
827 | } | |
828 | ||
45229ea4 | 829 | /* Store one register. */ |
9abe5450 | 830 | static void |
56be3814 | 831 | store_altivec_register (const struct regcache *regcache, int tid, int regno) |
9abe5450 EZ |
832 | { |
833 | int ret; | |
834 | int offset = 0; | |
835 | gdb_vrregset_t regs; | |
40a6adc1 MD |
836 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
837 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
838 | int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum); | |
9abe5450 EZ |
839 | |
840 | ret = ptrace (PTRACE_GETVRREGS, tid, 0, ®s); | |
841 | if (ret < 0) | |
842 | { | |
843 | if (errno == EIO) | |
844 | { | |
845 | have_ptrace_getvrregs = 0; | |
846 | return; | |
847 | } | |
e2e0b3e5 | 848 | perror_with_name (_("Unable to fetch AltiVec register")); |
9abe5450 EZ |
849 | } |
850 | ||
851 | /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes | |
852 | long on the hardware. */ | |
853 | if (regno == (tdep->ppc_vrsave_regnum - 1)) | |
40a6adc1 | 854 | offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum); |
9abe5450 | 855 | |
56be3814 | 856 | regcache_raw_collect (regcache, regno, |
822c9732 | 857 | regs + (regno - tdep->ppc_vr0_regnum) * vrregsize + offset); |
9abe5450 EZ |
858 | |
859 | ret = ptrace (PTRACE_SETVRREGS, tid, 0, ®s); | |
860 | if (ret < 0) | |
e2e0b3e5 | 861 | perror_with_name (_("Unable to store AltiVec register")); |
9abe5450 EZ |
862 | } |
863 | ||
01904826 JB |
864 | /* Assuming TID referrs to an SPE process, set the top halves of TID's |
865 | general-purpose registers and its SPE-specific registers to the | |
866 | values in EVRREGSET. If we don't support PTRACE_SETEVRREGS, do | |
867 | nothing. | |
868 | ||
869 | All the logic to deal with whether or not the PTRACE_GETEVRREGS and | |
870 | PTRACE_SETEVRREGS requests are supported is isolated here, and in | |
871 | get_spe_registers. */ | |
872 | static void | |
873 | set_spe_registers (int tid, struct gdb_evrregset_t *evrregset) | |
874 | { | |
875 | if (have_ptrace_getsetevrregs) | |
876 | { | |
877 | if (ptrace (PTRACE_SETEVRREGS, tid, 0, evrregset) >= 0) | |
878 | return; | |
879 | else | |
880 | { | |
881 | /* EIO means that the PTRACE_SETEVRREGS request isn't | |
882 | supported; we fail silently, and don't try the call | |
883 | again. */ | |
884 | if (errno == EIO) | |
885 | have_ptrace_getsetevrregs = 0; | |
886 | else | |
887 | /* Anything else needs to be reported. */ | |
e2e0b3e5 | 888 | perror_with_name (_("Unable to set SPE registers")); |
01904826 JB |
889 | } |
890 | } | |
891 | } | |
892 | ||
6ced10dd JB |
893 | /* Write GDB's value for the SPE-specific raw register REGNO to TID. |
894 | If REGNO is -1, write the values of all the SPE-specific | |
895 | registers. */ | |
01904826 | 896 | static void |
56be3814 | 897 | store_spe_register (const struct regcache *regcache, int tid, int regno) |
01904826 | 898 | { |
40a6adc1 MD |
899 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
900 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
01904826 JB |
901 | struct gdb_evrregset_t evrregs; |
902 | ||
6ced10dd | 903 | gdb_assert (sizeof (evrregs.evr[0]) |
40a6adc1 | 904 | == register_size (gdbarch, tdep->ppc_ev0_upper_regnum)); |
6ced10dd | 905 | gdb_assert (sizeof (evrregs.acc) |
40a6adc1 | 906 | == register_size (gdbarch, tdep->ppc_acc_regnum)); |
6ced10dd | 907 | gdb_assert (sizeof (evrregs.spefscr) |
40a6adc1 | 908 | == register_size (gdbarch, tdep->ppc_spefscr_regnum)); |
01904826 | 909 | |
6ced10dd JB |
910 | if (regno == -1) |
911 | /* Since we're going to write out every register, the code below | |
912 | should store to every field of evrregs; if that doesn't happen, | |
913 | make it obvious by initializing it with suspicious values. */ | |
914 | memset (&evrregs, 42, sizeof (evrregs)); | |
915 | else | |
916 | /* We can only read and write the entire EVR register set at a | |
917 | time, so to write just a single register, we do a | |
918 | read-modify-write maneuver. */ | |
919 | get_spe_registers (tid, &evrregs); | |
920 | ||
921 | if (regno == -1) | |
01904826 | 922 | { |
6ced10dd JB |
923 | int i; |
924 | ||
925 | for (i = 0; i < ppc_num_gprs; i++) | |
56be3814 | 926 | regcache_raw_collect (regcache, |
6ced10dd JB |
927 | tdep->ppc_ev0_upper_regnum + i, |
928 | &evrregs.evr[i]); | |
01904826 | 929 | } |
6ced10dd JB |
930 | else if (tdep->ppc_ev0_upper_regnum <= regno |
931 | && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs) | |
56be3814 | 932 | regcache_raw_collect (regcache, regno, |
6ced10dd JB |
933 | &evrregs.evr[regno - tdep->ppc_ev0_upper_regnum]); |
934 | ||
935 | if (regno == -1 | |
936 | || regno == tdep->ppc_acc_regnum) | |
56be3814 | 937 | regcache_raw_collect (regcache, |
6ced10dd JB |
938 | tdep->ppc_acc_regnum, |
939 | &evrregs.acc); | |
940 | ||
941 | if (regno == -1 | |
942 | || regno == tdep->ppc_spefscr_regnum) | |
56be3814 | 943 | regcache_raw_collect (regcache, |
6ced10dd JB |
944 | tdep->ppc_spefscr_regnum, |
945 | &evrregs.spefscr); | |
01904826 JB |
946 | |
947 | /* Write back the modified register set. */ | |
948 | set_spe_registers (tid, &evrregs); | |
949 | } | |
950 | ||
45229ea4 | 951 | static void |
56be3814 | 952 | store_register (const struct regcache *regcache, int tid, int regno) |
45229ea4 | 953 | { |
40a6adc1 MD |
954 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
955 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
45229ea4 | 956 | /* This isn't really an address. But ptrace thinks of it as one. */ |
e101270f | 957 | CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno); |
52f0bd74 | 958 | int i; |
4a19ea35 | 959 | size_t bytes_to_transfer; |
d9d9c31f | 960 | char buf[MAX_REGISTER_SIZE]; |
45229ea4 | 961 | |
be8626e0 | 962 | if (altivec_register_p (gdbarch, regno)) |
45229ea4 | 963 | { |
56be3814 | 964 | store_altivec_register (regcache, tid, regno); |
45229ea4 EZ |
965 | return; |
966 | } | |
604c2f83 LM |
967 | if (vsx_register_p (gdbarch, regno)) |
968 | { | |
969 | store_vsx_register (regcache, tid, regno); | |
970 | return; | |
971 | } | |
be8626e0 | 972 | else if (spe_register_p (gdbarch, regno)) |
01904826 | 973 | { |
56be3814 | 974 | store_spe_register (regcache, tid, regno); |
01904826 JB |
975 | return; |
976 | } | |
45229ea4 | 977 | |
9abe5450 EZ |
978 | if (regaddr == -1) |
979 | return; | |
980 | ||
4a19ea35 JB |
981 | /* First collect the register. Keep in mind that the regcache's |
982 | idea of the register's size may not be a multiple of sizeof | |
411cb3f9 | 983 | (long). */ |
56d0d96a | 984 | memset (buf, 0, sizeof buf); |
40a6adc1 MD |
985 | bytes_to_transfer = align_up (register_size (gdbarch, regno), sizeof (long)); |
986 | if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE) | |
4a19ea35 JB |
987 | { |
988 | /* Little-endian values always sit at the left end of the buffer. */ | |
56be3814 | 989 | regcache_raw_collect (regcache, regno, buf); |
4a19ea35 | 990 | } |
40a6adc1 | 991 | else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) |
4a19ea35 JB |
992 | { |
993 | /* Big-endian values sit at the right end of the buffer. */ | |
40a6adc1 | 994 | size_t padding = (bytes_to_transfer - register_size (gdbarch, regno)); |
56be3814 | 995 | regcache_raw_collect (regcache, regno, buf + padding); |
4a19ea35 JB |
996 | } |
997 | ||
411cb3f9 | 998 | for (i = 0; i < bytes_to_transfer; i += sizeof (long)) |
45229ea4 EZ |
999 | { |
1000 | errno = 0; | |
411cb3f9 PG |
1001 | ptrace (PTRACE_POKEUSER, tid, (PTRACE_TYPE_ARG3) regaddr, |
1002 | *(long *) &buf[i]); | |
1003 | regaddr += sizeof (long); | |
e3f36dbd KB |
1004 | |
1005 | if (errno == EIO | |
7284e1be UW |
1006 | && (regno == tdep->ppc_fpscr_regnum |
1007 | || regno == PPC_ORIG_R3_REGNUM | |
1008 | || regno == PPC_TRAP_REGNUM)) | |
e3f36dbd | 1009 | { |
7284e1be UW |
1010 | /* Some older kernel versions don't allow fpscr, orig_r3 |
1011 | or trap to be written. */ | |
e3f36dbd KB |
1012 | continue; |
1013 | } | |
1014 | ||
45229ea4 EZ |
1015 | if (errno != 0) |
1016 | { | |
bc97b3ba JB |
1017 | char message[128]; |
1018 | sprintf (message, "writing register %s (#%d)", | |
40a6adc1 | 1019 | gdbarch_register_name (gdbarch, regno), regno); |
bc97b3ba | 1020 | perror_with_name (message); |
45229ea4 EZ |
1021 | } |
1022 | } | |
1023 | } | |
1024 | ||
604c2f83 LM |
1025 | static void |
1026 | fill_vsxregset (const struct regcache *regcache, gdb_vsxregset_t *vsxregsetp) | |
1027 | { | |
1028 | int i; | |
1029 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
1030 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1031 | int vsxregsize = register_size (gdbarch, tdep->ppc_vsr0_upper_regnum); | |
1032 | ||
1033 | for (i = 0; i < ppc_num_vshrs; i++) | |
1034 | regcache_raw_collect (regcache, tdep->ppc_vsr0_upper_regnum + i, | |
1035 | *vsxregsetp + i * vsxregsize); | |
1036 | } | |
1037 | ||
9abe5450 | 1038 | static void |
56be3814 | 1039 | fill_vrregset (const struct regcache *regcache, gdb_vrregset_t *vrregsetp) |
9abe5450 EZ |
1040 | { |
1041 | int i; | |
40a6adc1 MD |
1042 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1043 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
9abe5450 | 1044 | int num_of_vrregs = tdep->ppc_vrsave_regnum - tdep->ppc_vr0_regnum + 1; |
40a6adc1 MD |
1045 | int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum); |
1046 | int offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum); | |
9abe5450 EZ |
1047 | |
1048 | for (i = 0; i < num_of_vrregs; i++) | |
1049 | { | |
1050 | /* The last 2 registers of this set are only 32 bit long, not | |
1051 | 128, but only VSCR is fetched as a 16 bytes quantity. */ | |
1052 | if (i == (num_of_vrregs - 2)) | |
56be3814 | 1053 | regcache_raw_collect (regcache, tdep->ppc_vr0_regnum + i, |
822c9732 | 1054 | *vrregsetp + i * vrregsize + offset); |
9abe5450 | 1055 | else |
56be3814 | 1056 | regcache_raw_collect (regcache, tdep->ppc_vr0_regnum + i, |
822c9732 | 1057 | *vrregsetp + i * vrregsize); |
9abe5450 EZ |
1058 | } |
1059 | } | |
1060 | ||
604c2f83 LM |
1061 | static void |
1062 | store_vsx_registers (const struct regcache *regcache, int tid) | |
1063 | { | |
1064 | int ret; | |
1065 | gdb_vsxregset_t regs; | |
1066 | ||
1067 | ret = ptrace (PTRACE_GETVSXREGS, tid, 0, ®s); | |
1068 | if (ret < 0) | |
1069 | { | |
1070 | if (errno == EIO) | |
1071 | { | |
1072 | have_ptrace_getsetvsxregs = 0; | |
1073 | return; | |
1074 | } | |
1075 | perror_with_name (_("Couldn't get VSX registers")); | |
1076 | } | |
1077 | ||
1078 | fill_vsxregset (regcache, ®s); | |
1079 | ||
1080 | if (ptrace (PTRACE_SETVSXREGS, tid, 0, ®s) < 0) | |
1081 | perror_with_name (_("Couldn't write VSX registers")); | |
1082 | } | |
1083 | ||
9abe5450 | 1084 | static void |
56be3814 | 1085 | store_altivec_registers (const struct regcache *regcache, int tid) |
9abe5450 EZ |
1086 | { |
1087 | int ret; | |
1088 | gdb_vrregset_t regs; | |
1089 | ||
0897f59b | 1090 | ret = ptrace (PTRACE_GETVRREGS, tid, 0, ®s); |
9abe5450 EZ |
1091 | if (ret < 0) |
1092 | { | |
1093 | if (errno == EIO) | |
1094 | { | |
1095 | have_ptrace_getvrregs = 0; | |
1096 | return; | |
1097 | } | |
e2e0b3e5 | 1098 | perror_with_name (_("Couldn't get AltiVec registers")); |
9abe5450 EZ |
1099 | } |
1100 | ||
56be3814 | 1101 | fill_vrregset (regcache, ®s); |
9abe5450 | 1102 | |
0897f59b | 1103 | if (ptrace (PTRACE_SETVRREGS, tid, 0, ®s) < 0) |
e2e0b3e5 | 1104 | perror_with_name (_("Couldn't write AltiVec registers")); |
9abe5450 EZ |
1105 | } |
1106 | ||
1dfe79e8 SDJ |
1107 | /* This function actually issues the request to ptrace, telling |
1108 | it to store all general-purpose registers present in the specified | |
1109 | regset. | |
1110 | ||
1111 | If the ptrace request does not exist, this function returns 0 | |
1112 | and properly sets the have_ptrace_* flag. If the request fails, | |
1113 | this function calls perror_with_name. Otherwise, if the request | |
1114 | succeeds, then the regcache is stored and 1 is returned. */ | |
1115 | static int | |
1116 | store_all_gp_regs (const struct regcache *regcache, int tid, int regno) | |
1117 | { | |
1118 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
1119 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1120 | gdb_gregset_t gregset; | |
1121 | ||
1122 | if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0) | |
1123 | { | |
1124 | if (errno == EIO) | |
1125 | { | |
1126 | have_ptrace_getsetregs = 0; | |
1127 | return 0; | |
1128 | } | |
1129 | perror_with_name (_("Couldn't get general-purpose registers.")); | |
1130 | } | |
1131 | ||
1132 | fill_gregset (regcache, &gregset, regno); | |
1133 | ||
1134 | if (ptrace (PTRACE_SETREGS, tid, 0, (void *) &gregset) < 0) | |
1135 | { | |
1136 | if (errno == EIO) | |
1137 | { | |
1138 | have_ptrace_getsetregs = 0; | |
1139 | return 0; | |
1140 | } | |
1141 | perror_with_name (_("Couldn't set general-purpose registers.")); | |
1142 | } | |
1143 | ||
1144 | return 1; | |
1145 | } | |
1146 | ||
1147 | /* This is a wrapper for the store_all_gp_regs function. It is | |
1148 | responsible for verifying if this target has the ptrace request | |
1149 | that can be used to store all general-purpose registers at one | |
1150 | shot. If it doesn't, then we should store them using the | |
1151 | old-fashioned way, which is to iterate over the registers and | |
1152 | store them one by one. */ | |
45229ea4 | 1153 | static void |
1dfe79e8 | 1154 | store_gp_regs (const struct regcache *regcache, int tid, int regno) |
45229ea4 | 1155 | { |
40a6adc1 MD |
1156 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1157 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1dfe79e8 SDJ |
1158 | int i; |
1159 | ||
1160 | if (have_ptrace_getsetregs) | |
1161 | if (store_all_gp_regs (regcache, tid, regno)) | |
1162 | return; | |
1163 | ||
1164 | /* If we hit this point, it doesn't really matter which | |
1165 | architecture we are using. We just need to store the | |
1166 | registers in the "old-fashioned way". */ | |
6ced10dd | 1167 | for (i = 0; i < ppc_num_gprs; i++) |
56be3814 | 1168 | store_register (regcache, tid, tdep->ppc_gp0_regnum + i); |
1dfe79e8 SDJ |
1169 | } |
1170 | ||
1171 | /* This function actually issues the request to ptrace, telling | |
1172 | it to store all floating-point registers present in the specified | |
1173 | regset. | |
1174 | ||
1175 | If the ptrace request does not exist, this function returns 0 | |
1176 | and properly sets the have_ptrace_* flag. If the request fails, | |
1177 | this function calls perror_with_name. Otherwise, if the request | |
1178 | succeeds, then the regcache is stored and 1 is returned. */ | |
1179 | static int | |
1180 | store_all_fp_regs (const struct regcache *regcache, int tid, int regno) | |
1181 | { | |
1182 | gdb_fpregset_t fpregs; | |
1183 | ||
1184 | if (ptrace (PTRACE_GETFPREGS, tid, 0, (void *) &fpregs) < 0) | |
1185 | { | |
1186 | if (errno == EIO) | |
1187 | { | |
1188 | have_ptrace_getsetfpregs = 0; | |
1189 | return 0; | |
1190 | } | |
1191 | perror_with_name (_("Couldn't get floating-point registers.")); | |
1192 | } | |
1193 | ||
1194 | fill_fpregset (regcache, &fpregs, regno); | |
1195 | ||
1196 | if (ptrace (PTRACE_SETFPREGS, tid, 0, (void *) &fpregs) < 0) | |
1197 | { | |
1198 | if (errno == EIO) | |
1199 | { | |
1200 | have_ptrace_getsetfpregs = 0; | |
1201 | return 0; | |
1202 | } | |
1203 | perror_with_name (_("Couldn't set floating-point registers.")); | |
1204 | } | |
1205 | ||
1206 | return 1; | |
1207 | } | |
1208 | ||
1209 | /* This is a wrapper for the store_all_fp_regs function. It is | |
1210 | responsible for verifying if this target has the ptrace request | |
1211 | that can be used to store all floating-point registers at one | |
1212 | shot. If it doesn't, then we should store them using the | |
1213 | old-fashioned way, which is to iterate over the registers and | |
1214 | store them one by one. */ | |
1215 | static void | |
1216 | store_fp_regs (const struct regcache *regcache, int tid, int regno) | |
1217 | { | |
1218 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
1219 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1220 | int i; | |
1221 | ||
1222 | if (have_ptrace_getsetfpregs) | |
1223 | if (store_all_fp_regs (regcache, tid, regno)) | |
1224 | return; | |
1225 | ||
1226 | /* If we hit this point, it doesn't really matter which | |
1227 | architecture we are using. We just need to store the | |
1228 | registers in the "old-fashioned way". */ | |
1229 | for (i = 0; i < ppc_num_fprs; i++) | |
1230 | store_register (regcache, tid, tdep->ppc_fp0_regnum + i); | |
1231 | } | |
1232 | ||
1233 | static void | |
1234 | store_ppc_registers (const struct regcache *regcache, int tid) | |
1235 | { | |
1236 | int i; | |
1237 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
1238 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1239 | ||
1240 | store_gp_regs (regcache, tid, -1); | |
32b99774 | 1241 | if (tdep->ppc_fp0_regnum >= 0) |
1dfe79e8 | 1242 | store_fp_regs (regcache, tid, -1); |
40a6adc1 | 1243 | store_register (regcache, tid, gdbarch_pc_regnum (gdbarch)); |
32b99774 | 1244 | if (tdep->ppc_ps_regnum != -1) |
56be3814 | 1245 | store_register (regcache, tid, tdep->ppc_ps_regnum); |
32b99774 | 1246 | if (tdep->ppc_cr_regnum != -1) |
56be3814 | 1247 | store_register (regcache, tid, tdep->ppc_cr_regnum); |
32b99774 | 1248 | if (tdep->ppc_lr_regnum != -1) |
56be3814 | 1249 | store_register (regcache, tid, tdep->ppc_lr_regnum); |
32b99774 | 1250 | if (tdep->ppc_ctr_regnum != -1) |
56be3814 | 1251 | store_register (regcache, tid, tdep->ppc_ctr_regnum); |
32b99774 | 1252 | if (tdep->ppc_xer_regnum != -1) |
56be3814 | 1253 | store_register (regcache, tid, tdep->ppc_xer_regnum); |
e3f36dbd | 1254 | if (tdep->ppc_mq_regnum != -1) |
56be3814 | 1255 | store_register (regcache, tid, tdep->ppc_mq_regnum); |
32b99774 | 1256 | if (tdep->ppc_fpscr_regnum != -1) |
56be3814 | 1257 | store_register (regcache, tid, tdep->ppc_fpscr_regnum); |
7284e1be UW |
1258 | if (ppc_linux_trap_reg_p (gdbarch)) |
1259 | { | |
1260 | store_register (regcache, tid, PPC_ORIG_R3_REGNUM); | |
1261 | store_register (regcache, tid, PPC_TRAP_REGNUM); | |
1262 | } | |
9abe5450 EZ |
1263 | if (have_ptrace_getvrregs) |
1264 | if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1) | |
56be3814 | 1265 | store_altivec_registers (regcache, tid); |
604c2f83 LM |
1266 | if (have_ptrace_getsetvsxregs) |
1267 | if (tdep->ppc_vsr0_upper_regnum != -1) | |
1268 | store_vsx_registers (regcache, tid); | |
6ced10dd | 1269 | if (tdep->ppc_ev0_upper_regnum >= 0) |
56be3814 | 1270 | store_spe_register (regcache, tid, -1); |
45229ea4 EZ |
1271 | } |
1272 | ||
e0d24f8d WZ |
1273 | static int |
1274 | ppc_linux_check_watch_resources (int type, int cnt, int ot) | |
1275 | { | |
1276 | int tid; | |
1277 | ptid_t ptid = inferior_ptid; | |
1278 | ||
1279 | /* DABR (data address breakpoint register) is optional for PPC variants. | |
1280 | Some variants have one DABR, others have none. So CNT can't be larger | |
1281 | than 1. */ | |
1282 | if (cnt > 1) | |
1283 | return 0; | |
1284 | ||
1285 | /* We need to know whether ptrace supports PTRACE_SET_DEBUGREG and whether | |
1286 | the target has DABR. If either answer is no, the ptrace call will | |
1287 | return -1. Fail in that case. */ | |
1288 | tid = TIDGET (ptid); | |
1289 | if (tid == 0) | |
1290 | tid = PIDGET (ptid); | |
1291 | ||
1292 | if (ptrace (PTRACE_SET_DEBUGREG, tid, 0, 0) == -1) | |
1293 | return 0; | |
1294 | return 1; | |
1295 | } | |
1296 | ||
b7622095 LM |
1297 | /* Fetch the AT_HWCAP entry from the aux vector. */ |
1298 | unsigned long ppc_linux_get_hwcap (void) | |
1299 | { | |
1300 | CORE_ADDR field; | |
1301 | ||
fcb09a75 | 1302 | if (target_auxv_search (¤t_target, AT_HWCAP, &field)) |
b7622095 LM |
1303 | return (unsigned long) field; |
1304 | ||
1305 | return 0; | |
1306 | } | |
1307 | ||
e0d24f8d WZ |
1308 | static int |
1309 | ppc_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) | |
1310 | { | |
1311 | /* Handle sub-8-byte quantities. */ | |
1312 | if (len <= 0) | |
1313 | return 0; | |
1314 | ||
b7622095 LM |
1315 | /* addr+len must fall in the 8 byte watchable region for DABR-based |
1316 | processors. DAC-based processors, like the PowerPC 440, will use | |
1317 | addresses aligned to 4-bytes due to the way the read/write flags are | |
1318 | passed at the moment. */ | |
1319 | if (((ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE) | |
1320 | && (addr + len) > (addr & ~3) + 4) | |
1321 | || (addr + len) > (addr & ~7) + 8) | |
e0d24f8d WZ |
1322 | return 0; |
1323 | ||
1324 | return 1; | |
1325 | } | |
1326 | ||
9f0bdab8 DJ |
1327 | /* The cached DABR value, to install in new threads. */ |
1328 | static long saved_dabr_value; | |
1329 | ||
e0d24f8d | 1330 | /* Set a watchpoint of type TYPE at address ADDR. */ |
2c387241 | 1331 | static int |
e0d24f8d WZ |
1332 | ppc_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw) |
1333 | { | |
9f0bdab8 DJ |
1334 | struct lwp_info *lp; |
1335 | ptid_t ptid; | |
e0d24f8d | 1336 | long dabr_value; |
b7622095 LM |
1337 | long read_mode, write_mode; |
1338 | ||
1339 | if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE) | |
1340 | { | |
1341 | /* PowerPC 440 requires only the read/write flags to be passed | |
1342 | to the kernel. */ | |
1343 | read_mode = 1; | |
1344 | write_mode = 2; | |
1345 | } | |
1346 | else | |
1347 | { | |
1348 | /* PowerPC 970 and other DABR-based processors are required to pass | |
1349 | the Breakpoint Translation bit together with the flags. */ | |
1350 | read_mode = 5; | |
1351 | write_mode = 6; | |
1352 | } | |
1353 | ||
1354 | dabr_value = addr & ~(read_mode | write_mode); | |
e0d24f8d WZ |
1355 | switch (rw) |
1356 | { | |
1357 | case hw_read: | |
1358 | /* Set read and translate bits. */ | |
b7622095 | 1359 | dabr_value |= read_mode; |
e0d24f8d WZ |
1360 | break; |
1361 | case hw_write: | |
1362 | /* Set write and translate bits. */ | |
b7622095 | 1363 | dabr_value |= write_mode; |
e0d24f8d WZ |
1364 | break; |
1365 | case hw_access: | |
1366 | /* Set read, write and translate bits. */ | |
b7622095 | 1367 | dabr_value |= read_mode | write_mode; |
e0d24f8d WZ |
1368 | break; |
1369 | } | |
1370 | ||
1c86e440 LM |
1371 | saved_dabr_value = dabr_value; |
1372 | ||
9f0bdab8 DJ |
1373 | ALL_LWPS (lp, ptid) |
1374 | if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0, saved_dabr_value) < 0) | |
1375 | return -1; | |
1c86e440 | 1376 | |
9f0bdab8 | 1377 | return 0; |
e0d24f8d WZ |
1378 | } |
1379 | ||
2c387241 AM |
1380 | static int |
1381 | ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw) | |
e0d24f8d | 1382 | { |
9f0bdab8 DJ |
1383 | struct lwp_info *lp; |
1384 | ptid_t ptid; | |
1385 | long dabr_value = 0; | |
1386 | ||
1387 | saved_dabr_value = 0; | |
1388 | ALL_LWPS (lp, ptid) | |
1389 | if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0, saved_dabr_value) < 0) | |
1390 | return -1; | |
1391 | return 0; | |
e0d24f8d WZ |
1392 | } |
1393 | ||
9f0bdab8 DJ |
1394 | static void |
1395 | ppc_linux_new_thread (ptid_t ptid) | |
e0d24f8d | 1396 | { |
9f0bdab8 | 1397 | ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0, saved_dabr_value); |
e0d24f8d WZ |
1398 | } |
1399 | ||
1400 | static int | |
9f0bdab8 | 1401 | ppc_linux_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p) |
e0d24f8d | 1402 | { |
9f0bdab8 | 1403 | struct siginfo *siginfo_p; |
e0d24f8d | 1404 | |
9f0bdab8 | 1405 | siginfo_p = linux_nat_get_siginfo (inferior_ptid); |
e0d24f8d | 1406 | |
9f0bdab8 DJ |
1407 | if (siginfo_p->si_signo != SIGTRAP |
1408 | || (siginfo_p->si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */) | |
e0d24f8d WZ |
1409 | return 0; |
1410 | ||
407f1a2e | 1411 | *addr_p = (CORE_ADDR) (uintptr_t) siginfo_p->si_addr; |
e0d24f8d WZ |
1412 | return 1; |
1413 | } | |
1414 | ||
9f0bdab8 DJ |
1415 | static int |
1416 | ppc_linux_stopped_by_watchpoint (void) | |
1417 | { | |
1418 | CORE_ADDR addr; | |
1419 | return ppc_linux_stopped_data_address (¤t_target, &addr); | |
1420 | } | |
1421 | ||
5009afc5 AS |
1422 | static int |
1423 | ppc_linux_watchpoint_addr_within_range (struct target_ops *target, | |
1424 | CORE_ADDR addr, | |
1425 | CORE_ADDR start, int length) | |
1426 | { | |
b7622095 LM |
1427 | int mask; |
1428 | ||
1429 | if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE) | |
1430 | mask = 3; | |
1431 | else | |
1432 | mask = 7; | |
1433 | ||
1434 | addr &= ~mask; | |
1435 | ||
1436 | /* Check whether [start, start+length-1] intersects [addr, addr+mask]. */ | |
1437 | return start <= addr + mask && start + length - 1 >= addr; | |
5009afc5 AS |
1438 | } |
1439 | ||
10d6c8cd | 1440 | static void |
28439f5e PA |
1441 | ppc_linux_store_inferior_registers (struct target_ops *ops, |
1442 | struct regcache *regcache, int regno) | |
45229ea4 | 1443 | { |
05f13b9c EZ |
1444 | /* Overload thread id onto process id */ |
1445 | int tid = TIDGET (inferior_ptid); | |
1446 | ||
1447 | /* No thread id, just use process id */ | |
1448 | if (tid == 0) | |
1449 | tid = PIDGET (inferior_ptid); | |
1450 | ||
45229ea4 | 1451 | if (regno >= 0) |
56be3814 | 1452 | store_register (regcache, tid, regno); |
45229ea4 | 1453 | else |
56be3814 | 1454 | store_ppc_registers (regcache, tid); |
45229ea4 EZ |
1455 | } |
1456 | ||
f2db237a AM |
1457 | /* Functions for transferring registers between a gregset_t or fpregset_t |
1458 | (see sys/ucontext.h) and gdb's regcache. The word size is that used | |
1459 | by the ptrace interface, not the current program's ABI. eg. If a | |
1460 | powerpc64-linux gdb is being used to debug a powerpc32-linux app, we | |
1461 | read or write 64-bit gregsets. This is to suit the host libthread_db. */ | |
1462 | ||
50c9bd31 | 1463 | void |
7f7fe91e | 1464 | supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp) |
c877c8e6 | 1465 | { |
f2db237a | 1466 | const struct regset *regset = ppc_linux_gregset (sizeof (long)); |
f9be684a | 1467 | |
f2db237a | 1468 | ppc_supply_gregset (regset, regcache, -1, gregsetp, sizeof (*gregsetp)); |
c877c8e6 KB |
1469 | } |
1470 | ||
fdb28ac4 | 1471 | void |
7f7fe91e UW |
1472 | fill_gregset (const struct regcache *regcache, |
1473 | gdb_gregset_t *gregsetp, int regno) | |
fdb28ac4 | 1474 | { |
f2db237a | 1475 | const struct regset *regset = ppc_linux_gregset (sizeof (long)); |
f9be684a | 1476 | |
f2db237a AM |
1477 | if (regno == -1) |
1478 | memset (gregsetp, 0, sizeof (*gregsetp)); | |
1479 | ppc_collect_gregset (regset, regcache, regno, gregsetp, sizeof (*gregsetp)); | |
fdb28ac4 KB |
1480 | } |
1481 | ||
50c9bd31 | 1482 | void |
7f7fe91e | 1483 | supply_fpregset (struct regcache *regcache, const gdb_fpregset_t * fpregsetp) |
c877c8e6 | 1484 | { |
f2db237a AM |
1485 | const struct regset *regset = ppc_linux_fpregset (); |
1486 | ||
1487 | ppc_supply_fpregset (regset, regcache, -1, | |
1488 | fpregsetp, sizeof (*fpregsetp)); | |
c877c8e6 | 1489 | } |
fdb28ac4 | 1490 | |
fdb28ac4 | 1491 | void |
7f7fe91e UW |
1492 | fill_fpregset (const struct regcache *regcache, |
1493 | gdb_fpregset_t *fpregsetp, int regno) | |
fdb28ac4 | 1494 | { |
f2db237a AM |
1495 | const struct regset *regset = ppc_linux_fpregset (); |
1496 | ||
1497 | ppc_collect_fpregset (regset, regcache, regno, | |
1498 | fpregsetp, sizeof (*fpregsetp)); | |
fdb28ac4 | 1499 | } |
10d6c8cd | 1500 | |
409c383c UW |
1501 | static int |
1502 | ppc_linux_target_wordsize (void) | |
1503 | { | |
1504 | int wordsize = 4; | |
1505 | ||
1506 | /* Check for 64-bit inferior process. This is the case when the host is | |
1507 | 64-bit, and in addition the top bit of the MSR register is set. */ | |
1508 | #ifdef __powerpc64__ | |
1509 | long msr; | |
1510 | ||
1511 | int tid = TIDGET (inferior_ptid); | |
1512 | if (tid == 0) | |
1513 | tid = PIDGET (inferior_ptid); | |
1514 | ||
1515 | errno = 0; | |
1516 | msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0); | |
1517 | if (errno == 0 && msr < 0) | |
1518 | wordsize = 8; | |
1519 | #endif | |
1520 | ||
1521 | return wordsize; | |
1522 | } | |
1523 | ||
1524 | static int | |
1525 | ppc_linux_auxv_parse (struct target_ops *ops, gdb_byte **readptr, | |
1526 | gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp) | |
1527 | { | |
1528 | int sizeof_auxv_field = ppc_linux_target_wordsize (); | |
e17a4113 | 1529 | enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); |
409c383c UW |
1530 | gdb_byte *ptr = *readptr; |
1531 | ||
1532 | if (endptr == ptr) | |
1533 | return 0; | |
1534 | ||
1535 | if (endptr - ptr < sizeof_auxv_field * 2) | |
1536 | return -1; | |
1537 | ||
e17a4113 | 1538 | *typep = extract_unsigned_integer (ptr, sizeof_auxv_field, byte_order); |
409c383c | 1539 | ptr += sizeof_auxv_field; |
e17a4113 | 1540 | *valp = extract_unsigned_integer (ptr, sizeof_auxv_field, byte_order); |
409c383c UW |
1541 | ptr += sizeof_auxv_field; |
1542 | ||
1543 | *readptr = ptr; | |
1544 | return 1; | |
1545 | } | |
1546 | ||
310a98e1 DJ |
1547 | static const struct target_desc * |
1548 | ppc_linux_read_description (struct target_ops *ops) | |
1549 | { | |
7284e1be | 1550 | int altivec = 0; |
604c2f83 | 1551 | int vsx = 0; |
69abc51c | 1552 | int isa205 = 0; |
f4d9bade | 1553 | int cell = 0; |
7284e1be UW |
1554 | |
1555 | int tid = TIDGET (inferior_ptid); | |
1556 | if (tid == 0) | |
1557 | tid = PIDGET (inferior_ptid); | |
1558 | ||
310a98e1 DJ |
1559 | if (have_ptrace_getsetevrregs) |
1560 | { | |
1561 | struct gdb_evrregset_t evrregset; | |
310a98e1 DJ |
1562 | |
1563 | if (ptrace (PTRACE_GETEVRREGS, tid, 0, &evrregset) >= 0) | |
7284e1be UW |
1564 | return tdesc_powerpc_e500l; |
1565 | ||
1566 | /* EIO means that the PTRACE_GETEVRREGS request isn't supported. | |
1567 | Anything else needs to be reported. */ | |
1568 | else if (errno != EIO) | |
1569 | perror_with_name (_("Unable to fetch SPE registers")); | |
1570 | } | |
1571 | ||
604c2f83 LM |
1572 | if (have_ptrace_getsetvsxregs) |
1573 | { | |
1574 | gdb_vsxregset_t vsxregset; | |
1575 | ||
1576 | if (ptrace (PTRACE_GETVSXREGS, tid, 0, &vsxregset) >= 0) | |
1577 | vsx = 1; | |
1578 | ||
1579 | /* EIO means that the PTRACE_GETVSXREGS request isn't supported. | |
1580 | Anything else needs to be reported. */ | |
1581 | else if (errno != EIO) | |
1582 | perror_with_name (_("Unable to fetch VSX registers")); | |
1583 | } | |
1584 | ||
7284e1be UW |
1585 | if (have_ptrace_getvrregs) |
1586 | { | |
1587 | gdb_vrregset_t vrregset; | |
1588 | ||
1589 | if (ptrace (PTRACE_GETVRREGS, tid, 0, &vrregset) >= 0) | |
1590 | altivec = 1; | |
1591 | ||
1592 | /* EIO means that the PTRACE_GETVRREGS request isn't supported. | |
1593 | Anything else needs to be reported. */ | |
1594 | else if (errno != EIO) | |
1595 | perror_with_name (_("Unable to fetch AltiVec registers")); | |
310a98e1 DJ |
1596 | } |
1597 | ||
f04c6d38 TJB |
1598 | /* Power ISA 2.05 (implemented by Power 6 and newer processors) increases |
1599 | the FPSCR from 32 bits to 64 bits. Even though Power 7 supports this | |
1600 | ISA version, it doesn't have PPC_FEATURE_ARCH_2_05 set, only | |
1601 | PPC_FEATURE_ARCH_2_06. Since for now the only bits used in the higher | |
1602 | half of the register are for Decimal Floating Point, we check if that | |
1603 | feature is available to decide the size of the FPSCR. */ | |
1604 | if (ppc_linux_get_hwcap () & PPC_FEATURE_HAS_DFP) | |
69abc51c TJB |
1605 | isa205 = 1; |
1606 | ||
f4d9bade UW |
1607 | if (ppc_linux_get_hwcap () & PPC_FEATURE_CELL) |
1608 | cell = 1; | |
1609 | ||
409c383c UW |
1610 | if (ppc_linux_target_wordsize () == 8) |
1611 | { | |
f4d9bade UW |
1612 | if (cell) |
1613 | return tdesc_powerpc_cell64l; | |
1614 | else if (vsx) | |
409c383c UW |
1615 | return isa205? tdesc_powerpc_isa205_vsx64l : tdesc_powerpc_vsx64l; |
1616 | else if (altivec) | |
1617 | return isa205? tdesc_powerpc_isa205_altivec64l : tdesc_powerpc_altivec64l; | |
1618 | ||
1619 | return isa205? tdesc_powerpc_isa205_64l : tdesc_powerpc_64l; | |
1620 | } | |
7284e1be | 1621 | |
f4d9bade UW |
1622 | if (cell) |
1623 | return tdesc_powerpc_cell32l; | |
1624 | else if (vsx) | |
69abc51c | 1625 | return isa205? tdesc_powerpc_isa205_vsx32l : tdesc_powerpc_vsx32l; |
604c2f83 | 1626 | else if (altivec) |
69abc51c | 1627 | return isa205? tdesc_powerpc_isa205_altivec32l : tdesc_powerpc_altivec32l; |
604c2f83 | 1628 | |
69abc51c | 1629 | return isa205? tdesc_powerpc_isa205_32l : tdesc_powerpc_32l; |
310a98e1 DJ |
1630 | } |
1631 | ||
10d6c8cd DJ |
1632 | void _initialize_ppc_linux_nat (void); |
1633 | ||
1634 | void | |
1635 | _initialize_ppc_linux_nat (void) | |
1636 | { | |
1637 | struct target_ops *t; | |
1638 | ||
1639 | /* Fill in the generic GNU/Linux methods. */ | |
1640 | t = linux_target (); | |
1641 | ||
1642 | /* Add our register access methods. */ | |
1643 | t->to_fetch_registers = ppc_linux_fetch_inferior_registers; | |
1644 | t->to_store_registers = ppc_linux_store_inferior_registers; | |
1645 | ||
e0d24f8d WZ |
1646 | /* Add our watchpoint methods. */ |
1647 | t->to_can_use_hw_breakpoint = ppc_linux_check_watch_resources; | |
1648 | t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint; | |
1649 | t->to_insert_watchpoint = ppc_linux_insert_watchpoint; | |
1650 | t->to_remove_watchpoint = ppc_linux_remove_watchpoint; | |
1651 | t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint; | |
1652 | t->to_stopped_data_address = ppc_linux_stopped_data_address; | |
5009afc5 | 1653 | t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range; |
e0d24f8d | 1654 | |
310a98e1 | 1655 | t->to_read_description = ppc_linux_read_description; |
409c383c | 1656 | t->to_auxv_parse = ppc_linux_auxv_parse; |
310a98e1 | 1657 | |
10d6c8cd | 1658 | /* Register the target. */ |
f973ed9c | 1659 | linux_nat_add_target (t); |
9f0bdab8 | 1660 | linux_nat_set_new_thread (t, ppc_linux_new_thread); |
10d6c8cd | 1661 | } |