* rs6000-tdep: Include "features/rs6000/powerpc-vsx32.c".
[deliverable/binutils-gdb.git] / gdb / ppc-linux-nat.c
1 /* PPC GNU/Linux native support.
2
3 Copyright (C) 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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
10 the Free Software Foundation; either version 3 of the License, or
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
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "defs.h"
22 #include "gdb_string.h"
23 #include "frame.h"
24 #include "inferior.h"
25 #include "gdbcore.h"
26 #include "regcache.h"
27 #include "gdb_assert.h"
28 #include "target.h"
29 #include "linux-nat.h"
30
31 #include <stdint.h>
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <signal.h>
35 #include <sys/user.h>
36 #include <sys/ioctl.h>
37 #include "gdb_wait.h"
38 #include <fcntl.h>
39 #include <sys/procfs.h>
40 #include <sys/ptrace.h>
41
42 /* Prototypes for supply_gregset etc. */
43 #include "gregset.h"
44 #include "ppc-tdep.h"
45 #include "ppc-linux-tdep.h"
46
47 /* Required when using the AUXV. */
48 #include "elf/common.h"
49 #include "auxv.h"
50
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
58
59 #ifndef PPC_FEATURE_BOOKE
60 #define PPC_FEATURE_BOOKE 0x00008000
61 #endif
62
63 /* Glibc's headers don't define PTRACE_GETVRREGS so we cannot use a
64 configure time check. Some older glibc's (for instance 2.2.1)
65 don't have a specific powerpc version of ptrace.h, and fall back on
66 a generic one. In such cases, sys/ptrace.h defines
67 PTRACE_GETFPXREGS and PTRACE_SETFPXREGS to the same numbers that
68 ppc kernel's asm/ptrace.h defines PTRACE_GETVRREGS and
69 PTRACE_SETVRREGS to be. This also makes a configury check pretty
70 much useless. */
71
72 /* These definitions should really come from the glibc header files,
73 but Glibc doesn't know about the vrregs yet. */
74 #ifndef PTRACE_GETVRREGS
75 #define PTRACE_GETVRREGS 18
76 #define PTRACE_SETVRREGS 19
77 #endif
78
79 /* PTRACE requests for POWER7 VSX registers. */
80 #ifndef PTRACE_GETVSXREGS
81 #define PTRACE_GETVSXREGS 27
82 #define PTRACE_SETVSXREGS 28
83 #endif
84
85 /* Similarly for the ptrace requests for getting / setting the SPE
86 registers (ev0 -- ev31, acc, and spefscr). See the description of
87 gdb_evrregset_t for details. */
88 #ifndef PTRACE_GETEVRREGS
89 #define PTRACE_GETEVRREGS 20
90 #define PTRACE_SETEVRREGS 21
91 #endif
92
93 /* Similarly for the hardware watchpoint support. */
94 #ifndef PTRACE_GET_DEBUGREG
95 #define PTRACE_GET_DEBUGREG 25
96 #endif
97 #ifndef PTRACE_SET_DEBUGREG
98 #define PTRACE_SET_DEBUGREG 26
99 #endif
100 #ifndef PTRACE_GETSIGINFO
101 #define PTRACE_GETSIGINFO 0x4202
102 #endif
103
104 /* This oddity is because the Linux kernel defines elf_vrregset_t as
105 an array of 33 16 bytes long elements. I.e. it leaves out vrsave.
106 However the PTRACE_GETVRREGS and PTRACE_SETVRREGS requests return
107 the vrsave as an extra 4 bytes at the end. I opted for creating a
108 flat array of chars, so that it is easier to manipulate for gdb.
109
110 There are 32 vector registers 16 bytes longs, plus a VSCR register
111 which is only 4 bytes long, but is fetched as a 16 bytes
112 quantity. Up to here we have the elf_vrregset_t structure.
113 Appended to this there is space for the VRSAVE register: 4 bytes.
114 Even though this vrsave register is not included in the regset
115 typedef, it is handled by the ptrace requests.
116
117 Note that GNU/Linux doesn't support little endian PPC hardware,
118 therefore the offset at which the real value of the VSCR register
119 is located will be always 12 bytes.
120
121 The layout is like this (where x is the actual value of the vscr reg): */
122
123 /* *INDENT-OFF* */
124 /*
125 |.|.|.|.|.....|.|.|.|.||.|.|.|x||.|
126 <-------> <-------><-------><->
127 VR0 VR31 VSCR VRSAVE
128 */
129 /* *INDENT-ON* */
130
131 #define SIZEOF_VRREGS 33*16+4
132
133 typedef char gdb_vrregset_t[SIZEOF_VRREGS];
134
135 /* This is the layout of the POWER7 VSX registers and the way they overlap
136 with the existing FPR and VMX registers.
137
138 VSR doubleword 0 VSR doubleword 1
139 ----------------------------------------------------------------
140 VSR[0] | FPR[0] | |
141 ----------------------------------------------------------------
142 VSR[1] | FPR[1] | |
143 ----------------------------------------------------------------
144 | ... | |
145 | ... | |
146 ----------------------------------------------------------------
147 VSR[30] | FPR[30] | |
148 ----------------------------------------------------------------
149 VSR[31] | FPR[31] | |
150 ----------------------------------------------------------------
151 VSR[32] | VR[0] |
152 ----------------------------------------------------------------
153 VSR[33] | VR[1] |
154 ----------------------------------------------------------------
155 | ... |
156 | ... |
157 ----------------------------------------------------------------
158 VSR[62] | VR[30] |
159 ----------------------------------------------------------------
160 VSR[63] | VR[31] |
161 ----------------------------------------------------------------
162
163 VSX has 64 128bit registers. The first 32 registers overlap with
164 the FP registers (doubleword 0) and hence extend them with additional
165 64 bits (doubleword 1). The other 32 regs overlap with the VMX
166 registers. */
167 #define SIZEOF_VSXREGS 32*8
168
169 typedef char gdb_vsxregset_t[SIZEOF_VSXREGS];
170
171 /* On PPC processors that support the the Signal Processing Extension
172 (SPE) APU, the general-purpose registers are 64 bits long.
173 However, the ordinary Linux kernel PTRACE_PEEKUSER / PTRACE_POKEUSER
174 ptrace calls only access the lower half of each register, to allow
175 them to behave the same way they do on non-SPE systems. There's a
176 separate pair of calls, PTRACE_GETEVRREGS / PTRACE_SETEVRREGS, that
177 read and write the top halves of all the general-purpose registers
178 at once, along with some SPE-specific registers.
179
180 GDB itself continues to claim the general-purpose registers are 32
181 bits long. It has unnamed raw registers that hold the upper halves
182 of the gprs, and the the full 64-bit SIMD views of the registers,
183 'ev0' -- 'ev31', are pseudo-registers that splice the top and
184 bottom halves together.
185
186 This is the structure filled in by PTRACE_GETEVRREGS and written to
187 the inferior's registers by PTRACE_SETEVRREGS. */
188 struct gdb_evrregset_t
189 {
190 unsigned long evr[32];
191 unsigned long long acc;
192 unsigned long spefscr;
193 };
194
195 /* Non-zero if our kernel may support the PTRACE_GETVSXREGS and
196 PTRACE_SETVSXREGS requests, for reading and writing the VSX
197 POWER7 registers 0 through 31. Zero if we've tried one of them and
198 gotten an error. Note that VSX registers 32 through 63 overlap
199 with VR registers 0 through 31. */
200 int have_ptrace_getsetvsxregs = 1;
201
202 /* Non-zero if our kernel may support the PTRACE_GETVRREGS and
203 PTRACE_SETVRREGS requests, for reading and writing the Altivec
204 registers. Zero if we've tried one of them and gotten an
205 error. */
206 int have_ptrace_getvrregs = 1;
207
208 /* Non-zero if our kernel may support the PTRACE_GETEVRREGS and
209 PTRACE_SETEVRREGS requests, for reading and writing the SPE
210 registers. Zero if we've tried one of them and gotten an
211 error. */
212 int have_ptrace_getsetevrregs = 1;
213
214 /* *INDENT-OFF* */
215 /* registers layout, as presented by the ptrace interface:
216 PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
217 PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15,
218 PT_R16, PT_R17, PT_R18, PT_R19, PT_R20, PT_R21, PT_R22, PT_R23,
219 PT_R24, PT_R25, PT_R26, PT_R27, PT_R28, PT_R29, PT_R30, PT_R31,
220 PT_FPR0, PT_FPR0 + 2, PT_FPR0 + 4, PT_FPR0 + 6, PT_FPR0 + 8, PT_FPR0 + 10, PT_FPR0 + 12, PT_FPR0 + 14,
221 PT_FPR0 + 16, PT_FPR0 + 18, PT_FPR0 + 20, PT_FPR0 + 22, PT_FPR0 + 24, PT_FPR0 + 26, PT_FPR0 + 28, PT_FPR0 + 30,
222 PT_FPR0 + 32, PT_FPR0 + 34, PT_FPR0 + 36, PT_FPR0 + 38, PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46,
223 PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54, PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62,
224 PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */
225 /* *INDENT_ON * */
226
227 static int
228 ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
229 {
230 int u_addr = -1;
231 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
232 /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace
233 interface, and not the wordsize of the program's ABI. */
234 int wordsize = sizeof (long);
235
236 /* General purpose registers occupy 1 slot each in the buffer */
237 if (regno >= tdep->ppc_gp0_regnum
238 && regno < tdep->ppc_gp0_regnum + ppc_num_gprs)
239 u_addr = ((regno - tdep->ppc_gp0_regnum + PT_R0) * wordsize);
240
241 /* Floating point regs: eight bytes each in both 32- and 64-bit
242 ptrace interfaces. Thus, two slots each in 32-bit interface, one
243 slot each in 64-bit interface. */
244 if (tdep->ppc_fp0_regnum >= 0
245 && regno >= tdep->ppc_fp0_regnum
246 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
247 u_addr = (PT_FPR0 * wordsize) + ((regno - tdep->ppc_fp0_regnum) * 8);
248
249 /* UISA special purpose registers: 1 slot each */
250 if (regno == gdbarch_pc_regnum (gdbarch))
251 u_addr = PT_NIP * wordsize;
252 if (regno == tdep->ppc_lr_regnum)
253 u_addr = PT_LNK * wordsize;
254 if (regno == tdep->ppc_cr_regnum)
255 u_addr = PT_CCR * wordsize;
256 if (regno == tdep->ppc_xer_regnum)
257 u_addr = PT_XER * wordsize;
258 if (regno == tdep->ppc_ctr_regnum)
259 u_addr = PT_CTR * wordsize;
260 #ifdef PT_MQ
261 if (regno == tdep->ppc_mq_regnum)
262 u_addr = PT_MQ * wordsize;
263 #endif
264 if (regno == tdep->ppc_ps_regnum)
265 u_addr = PT_MSR * wordsize;
266 if (regno == PPC_ORIG_R3_REGNUM)
267 u_addr = PT_ORIG_R3 * wordsize;
268 if (regno == PPC_TRAP_REGNUM)
269 u_addr = PT_TRAP * wordsize;
270 if (tdep->ppc_fpscr_regnum >= 0
271 && regno == tdep->ppc_fpscr_regnum)
272 {
273 /* NOTE: cagney/2005-02-08: On some 64-bit GNU/Linux systems the
274 kernel headers incorrectly contained the 32-bit definition of
275 PT_FPSCR. For the 32-bit definition, floating-point
276 registers occupy two 32-bit "slots", and the FPSCR lives in
277 the secondhalf of such a slot-pair (hence +1). For 64-bit,
278 the FPSCR instead occupies the full 64-bit 2-word-slot and
279 hence no adjustment is necessary. Hack around this. */
280 if (wordsize == 8 && PT_FPSCR == (48 + 32 + 1))
281 u_addr = (48 + 32) * wordsize;
282 else
283 u_addr = PT_FPSCR * wordsize;
284 }
285 return u_addr;
286 }
287
288 /* The Linux kernel ptrace interface for POWER7 VSX registers uses the
289 registers set mechanism, as opposed to the interface for all the
290 other registers, that stores/fetches each register individually. */
291 static void
292 fetch_vsx_register (struct regcache *regcache, int tid, int regno)
293 {
294 int ret;
295 gdb_vsxregset_t regs;
296 struct gdbarch *gdbarch = get_regcache_arch (regcache);
297 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
298 int vsxregsize = register_size (gdbarch, tdep->ppc_vsr0_upper_regnum);
299
300 ret = ptrace (PTRACE_GETVSXREGS, tid, 0, &regs);
301 if (ret < 0)
302 {
303 if (errno == EIO)
304 {
305 have_ptrace_getsetvsxregs = 0;
306 return;
307 }
308 perror_with_name (_("Unable to fetch VSX register"));
309 }
310
311 regcache_raw_supply (regcache, regno,
312 regs + (regno - tdep->ppc_vsr0_upper_regnum)
313 * vsxregsize);
314 }
315
316 /* The Linux kernel ptrace interface for AltiVec registers uses the
317 registers set mechanism, as opposed to the interface for all the
318 other registers, that stores/fetches each register individually. */
319 static void
320 fetch_altivec_register (struct regcache *regcache, int tid, int regno)
321 {
322 int ret;
323 int offset = 0;
324 gdb_vrregset_t regs;
325 struct gdbarch *gdbarch = get_regcache_arch (regcache);
326 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
327 int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum);
328
329 ret = ptrace (PTRACE_GETVRREGS, tid, 0, &regs);
330 if (ret < 0)
331 {
332 if (errno == EIO)
333 {
334 have_ptrace_getvrregs = 0;
335 return;
336 }
337 perror_with_name (_("Unable to fetch AltiVec register"));
338 }
339
340 /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes
341 long on the hardware. We deal only with the lower 4 bytes of the
342 vector. VRSAVE is at the end of the array in a 4 bytes slot, so
343 there is no need to define an offset for it. */
344 if (regno == (tdep->ppc_vrsave_regnum - 1))
345 offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum);
346
347 regcache_raw_supply (regcache, regno,
348 regs + (regno - tdep->ppc_vr0_regnum) * vrregsize + offset);
349 }
350
351 /* Fetch the top 32 bits of TID's general-purpose registers and the
352 SPE-specific registers, and place the results in EVRREGSET. If we
353 don't support PTRACE_GETEVRREGS, then just fill EVRREGSET with
354 zeros.
355
356 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
357 PTRACE_SETEVRREGS requests are supported is isolated here, and in
358 set_spe_registers. */
359 static void
360 get_spe_registers (int tid, struct gdb_evrregset_t *evrregset)
361 {
362 if (have_ptrace_getsetevrregs)
363 {
364 if (ptrace (PTRACE_GETEVRREGS, tid, 0, evrregset) >= 0)
365 return;
366 else
367 {
368 /* EIO means that the PTRACE_GETEVRREGS request isn't supported;
369 we just return zeros. */
370 if (errno == EIO)
371 have_ptrace_getsetevrregs = 0;
372 else
373 /* Anything else needs to be reported. */
374 perror_with_name (_("Unable to fetch SPE registers"));
375 }
376 }
377
378 memset (evrregset, 0, sizeof (*evrregset));
379 }
380
381 /* Supply values from TID for SPE-specific raw registers: the upper
382 halves of the GPRs, the accumulator, and the spefscr. REGNO must
383 be the number of an upper half register, acc, spefscr, or -1 to
384 supply the values of all registers. */
385 static void
386 fetch_spe_register (struct regcache *regcache, int tid, int regno)
387 {
388 struct gdbarch *gdbarch = get_regcache_arch (regcache);
389 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
390 struct gdb_evrregset_t evrregs;
391
392 gdb_assert (sizeof (evrregs.evr[0])
393 == register_size (gdbarch, tdep->ppc_ev0_upper_regnum));
394 gdb_assert (sizeof (evrregs.acc)
395 == register_size (gdbarch, tdep->ppc_acc_regnum));
396 gdb_assert (sizeof (evrregs.spefscr)
397 == register_size (gdbarch, tdep->ppc_spefscr_regnum));
398
399 get_spe_registers (tid, &evrregs);
400
401 if (regno == -1)
402 {
403 int i;
404
405 for (i = 0; i < ppc_num_gprs; i++)
406 regcache_raw_supply (regcache, tdep->ppc_ev0_upper_regnum + i,
407 &evrregs.evr[i]);
408 }
409 else if (tdep->ppc_ev0_upper_regnum <= regno
410 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
411 regcache_raw_supply (regcache, regno,
412 &evrregs.evr[regno - tdep->ppc_ev0_upper_regnum]);
413
414 if (regno == -1
415 || regno == tdep->ppc_acc_regnum)
416 regcache_raw_supply (regcache, tdep->ppc_acc_regnum, &evrregs.acc);
417
418 if (regno == -1
419 || regno == tdep->ppc_spefscr_regnum)
420 regcache_raw_supply (regcache, tdep->ppc_spefscr_regnum,
421 &evrregs.spefscr);
422 }
423
424 static void
425 fetch_register (struct regcache *regcache, int tid, int regno)
426 {
427 struct gdbarch *gdbarch = get_regcache_arch (regcache);
428 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
429 /* This isn't really an address. But ptrace thinks of it as one. */
430 CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno);
431 int bytes_transferred;
432 unsigned int offset; /* Offset of registers within the u area. */
433 char buf[MAX_REGISTER_SIZE];
434
435 if (altivec_register_p (gdbarch, regno))
436 {
437 /* If this is the first time through, or if it is not the first
438 time through, and we have comfirmed that there is kernel
439 support for such a ptrace request, then go and fetch the
440 register. */
441 if (have_ptrace_getvrregs)
442 {
443 fetch_altivec_register (regcache, tid, regno);
444 return;
445 }
446 /* If we have discovered that there is no ptrace support for
447 AltiVec registers, fall through and return zeroes, because
448 regaddr will be -1 in this case. */
449 }
450 if (vsx_register_p (gdbarch, regno))
451 {
452 if (have_ptrace_getsetvsxregs)
453 {
454 fetch_vsx_register (regcache, tid, regno);
455 return;
456 }
457 }
458 else if (spe_register_p (gdbarch, regno))
459 {
460 fetch_spe_register (regcache, tid, regno);
461 return;
462 }
463
464 if (regaddr == -1)
465 {
466 memset (buf, '\0', register_size (gdbarch, regno)); /* Supply zeroes */
467 regcache_raw_supply (regcache, regno, buf);
468 return;
469 }
470
471 /* Read the raw register using sizeof(long) sized chunks. On a
472 32-bit platform, 64-bit floating-point registers will require two
473 transfers. */
474 for (bytes_transferred = 0;
475 bytes_transferred < register_size (gdbarch, regno);
476 bytes_transferred += sizeof (long))
477 {
478 errno = 0;
479 *(long *) &buf[bytes_transferred]
480 = ptrace (PTRACE_PEEKUSER, tid, (PTRACE_TYPE_ARG3) regaddr, 0);
481 regaddr += sizeof (long);
482 if (errno != 0)
483 {
484 char message[128];
485 sprintf (message, "reading register %s (#%d)",
486 gdbarch_register_name (gdbarch, regno), regno);
487 perror_with_name (message);
488 }
489 }
490
491 /* Now supply the register. Keep in mind that the regcache's idea
492 of the register's size may not be a multiple of sizeof
493 (long). */
494 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
495 {
496 /* Little-endian values are always found at the left end of the
497 bytes transferred. */
498 regcache_raw_supply (regcache, regno, buf);
499 }
500 else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
501 {
502 /* Big-endian values are found at the right end of the bytes
503 transferred. */
504 size_t padding = (bytes_transferred - register_size (gdbarch, regno));
505 regcache_raw_supply (regcache, regno, buf + padding);
506 }
507 else
508 internal_error (__FILE__, __LINE__,
509 _("fetch_register: unexpected byte order: %d"),
510 gdbarch_byte_order (gdbarch));
511 }
512
513 static void
514 supply_vsxregset (struct regcache *regcache, gdb_vsxregset_t *vsxregsetp)
515 {
516 int i;
517 struct gdbarch *gdbarch = get_regcache_arch (regcache);
518 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
519 int vsxregsize = register_size (gdbarch, tdep->ppc_vsr0_upper_regnum);
520
521 for (i = 0; i < ppc_num_vshrs; i++)
522 {
523 regcache_raw_supply (regcache, tdep->ppc_vsr0_upper_regnum + i,
524 *vsxregsetp + i * vsxregsize);
525 }
526 }
527
528 static void
529 supply_vrregset (struct regcache *regcache, gdb_vrregset_t *vrregsetp)
530 {
531 int i;
532 struct gdbarch *gdbarch = get_regcache_arch (regcache);
533 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
534 int num_of_vrregs = tdep->ppc_vrsave_regnum - tdep->ppc_vr0_regnum + 1;
535 int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum);
536 int offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum);
537
538 for (i = 0; i < num_of_vrregs; i++)
539 {
540 /* The last 2 registers of this set are only 32 bit long, not
541 128. However an offset is necessary only for VSCR because it
542 occupies a whole vector, while VRSAVE occupies a full 4 bytes
543 slot. */
544 if (i == (num_of_vrregs - 2))
545 regcache_raw_supply (regcache, tdep->ppc_vr0_regnum + i,
546 *vrregsetp + i * vrregsize + offset);
547 else
548 regcache_raw_supply (regcache, tdep->ppc_vr0_regnum + i,
549 *vrregsetp + i * vrregsize);
550 }
551 }
552
553 static void
554 fetch_vsx_registers (struct regcache *regcache, int tid)
555 {
556 int ret;
557 gdb_vsxregset_t regs;
558
559 ret = ptrace (PTRACE_GETVSXREGS, tid, 0, &regs);
560 if (ret < 0)
561 {
562 if (errno == EIO)
563 {
564 have_ptrace_getsetvsxregs = 0;
565 return;
566 }
567 perror_with_name (_("Unable to fetch VSX registers"));
568 }
569 supply_vsxregset (regcache, &regs);
570 }
571
572 static void
573 fetch_altivec_registers (struct regcache *regcache, int tid)
574 {
575 int ret;
576 gdb_vrregset_t regs;
577
578 ret = ptrace (PTRACE_GETVRREGS, tid, 0, &regs);
579 if (ret < 0)
580 {
581 if (errno == EIO)
582 {
583 have_ptrace_getvrregs = 0;
584 return;
585 }
586 perror_with_name (_("Unable to fetch AltiVec registers"));
587 }
588 supply_vrregset (regcache, &regs);
589 }
590
591 static void
592 fetch_ppc_registers (struct regcache *regcache, int tid)
593 {
594 int i;
595 struct gdbarch *gdbarch = get_regcache_arch (regcache);
596 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
597
598 for (i = 0; i < ppc_num_gprs; i++)
599 fetch_register (regcache, tid, tdep->ppc_gp0_regnum + i);
600 if (tdep->ppc_fp0_regnum >= 0)
601 for (i = 0; i < ppc_num_fprs; i++)
602 fetch_register (regcache, tid, tdep->ppc_fp0_regnum + i);
603 fetch_register (regcache, tid, gdbarch_pc_regnum (gdbarch));
604 if (tdep->ppc_ps_regnum != -1)
605 fetch_register (regcache, tid, tdep->ppc_ps_regnum);
606 if (tdep->ppc_cr_regnum != -1)
607 fetch_register (regcache, tid, tdep->ppc_cr_regnum);
608 if (tdep->ppc_lr_regnum != -1)
609 fetch_register (regcache, tid, tdep->ppc_lr_regnum);
610 if (tdep->ppc_ctr_regnum != -1)
611 fetch_register (regcache, tid, tdep->ppc_ctr_regnum);
612 if (tdep->ppc_xer_regnum != -1)
613 fetch_register (regcache, tid, tdep->ppc_xer_regnum);
614 if (tdep->ppc_mq_regnum != -1)
615 fetch_register (regcache, tid, tdep->ppc_mq_regnum);
616 if (ppc_linux_trap_reg_p (gdbarch))
617 {
618 fetch_register (regcache, tid, PPC_ORIG_R3_REGNUM);
619 fetch_register (regcache, tid, PPC_TRAP_REGNUM);
620 }
621 if (tdep->ppc_fpscr_regnum != -1)
622 fetch_register (regcache, tid, tdep->ppc_fpscr_regnum);
623 if (have_ptrace_getvrregs)
624 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
625 fetch_altivec_registers (regcache, tid);
626 if (have_ptrace_getsetvsxregs)
627 if (tdep->ppc_vsr0_upper_regnum != -1)
628 fetch_vsx_registers (regcache, tid);
629 if (tdep->ppc_ev0_upper_regnum >= 0)
630 fetch_spe_register (regcache, tid, -1);
631 }
632
633 /* Fetch registers from the child process. Fetch all registers if
634 regno == -1, otherwise fetch all general registers or all floating
635 point registers depending upon the value of regno. */
636 static void
637 ppc_linux_fetch_inferior_registers (struct regcache *regcache, int regno)
638 {
639 /* Overload thread id onto process id */
640 int tid = TIDGET (inferior_ptid);
641
642 /* No thread id, just use process id */
643 if (tid == 0)
644 tid = PIDGET (inferior_ptid);
645
646 if (regno == -1)
647 fetch_ppc_registers (regcache, tid);
648 else
649 fetch_register (regcache, tid, regno);
650 }
651
652 /* Store one VSX register. */
653 static void
654 store_vsx_register (const struct regcache *regcache, int tid, int regno)
655 {
656 int ret;
657 gdb_vsxregset_t regs;
658 struct gdbarch *gdbarch = get_regcache_arch (regcache);
659 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
660 int vsxregsize = register_size (gdbarch, tdep->ppc_vsr0_upper_regnum);
661
662 ret = ptrace (PTRACE_SETVSXREGS, tid, 0, &regs);
663 if (ret < 0)
664 {
665 if (errno == EIO)
666 {
667 have_ptrace_getsetvsxregs = 0;
668 return;
669 }
670 perror_with_name (_("Unable to fetch VSX register"));
671 }
672
673 regcache_raw_collect (regcache, regno, regs +
674 (regno - tdep->ppc_vsr0_upper_regnum) * vsxregsize);
675
676 ret = ptrace (PTRACE_SETVSXREGS, tid, 0, &regs);
677 if (ret < 0)
678 perror_with_name (_("Unable to store VSX register"));
679 }
680
681 /* Store one register. */
682 static void
683 store_altivec_register (const struct regcache *regcache, int tid, int regno)
684 {
685 int ret;
686 int offset = 0;
687 gdb_vrregset_t regs;
688 struct gdbarch *gdbarch = get_regcache_arch (regcache);
689 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
690 int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum);
691
692 ret = ptrace (PTRACE_GETVRREGS, tid, 0, &regs);
693 if (ret < 0)
694 {
695 if (errno == EIO)
696 {
697 have_ptrace_getvrregs = 0;
698 return;
699 }
700 perror_with_name (_("Unable to fetch AltiVec register"));
701 }
702
703 /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes
704 long on the hardware. */
705 if (regno == (tdep->ppc_vrsave_regnum - 1))
706 offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum);
707
708 regcache_raw_collect (regcache, regno,
709 regs + (regno - tdep->ppc_vr0_regnum) * vrregsize + offset);
710
711 ret = ptrace (PTRACE_SETVRREGS, tid, 0, &regs);
712 if (ret < 0)
713 perror_with_name (_("Unable to store AltiVec register"));
714 }
715
716 /* Assuming TID referrs to an SPE process, set the top halves of TID's
717 general-purpose registers and its SPE-specific registers to the
718 values in EVRREGSET. If we don't support PTRACE_SETEVRREGS, do
719 nothing.
720
721 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
722 PTRACE_SETEVRREGS requests are supported is isolated here, and in
723 get_spe_registers. */
724 static void
725 set_spe_registers (int tid, struct gdb_evrregset_t *evrregset)
726 {
727 if (have_ptrace_getsetevrregs)
728 {
729 if (ptrace (PTRACE_SETEVRREGS, tid, 0, evrregset) >= 0)
730 return;
731 else
732 {
733 /* EIO means that the PTRACE_SETEVRREGS request isn't
734 supported; we fail silently, and don't try the call
735 again. */
736 if (errno == EIO)
737 have_ptrace_getsetevrregs = 0;
738 else
739 /* Anything else needs to be reported. */
740 perror_with_name (_("Unable to set SPE registers"));
741 }
742 }
743 }
744
745 /* Write GDB's value for the SPE-specific raw register REGNO to TID.
746 If REGNO is -1, write the values of all the SPE-specific
747 registers. */
748 static void
749 store_spe_register (const struct regcache *regcache, int tid, int regno)
750 {
751 struct gdbarch *gdbarch = get_regcache_arch (regcache);
752 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
753 struct gdb_evrregset_t evrregs;
754
755 gdb_assert (sizeof (evrregs.evr[0])
756 == register_size (gdbarch, tdep->ppc_ev0_upper_regnum));
757 gdb_assert (sizeof (evrregs.acc)
758 == register_size (gdbarch, tdep->ppc_acc_regnum));
759 gdb_assert (sizeof (evrregs.spefscr)
760 == register_size (gdbarch, tdep->ppc_spefscr_regnum));
761
762 if (regno == -1)
763 /* Since we're going to write out every register, the code below
764 should store to every field of evrregs; if that doesn't happen,
765 make it obvious by initializing it with suspicious values. */
766 memset (&evrregs, 42, sizeof (evrregs));
767 else
768 /* We can only read and write the entire EVR register set at a
769 time, so to write just a single register, we do a
770 read-modify-write maneuver. */
771 get_spe_registers (tid, &evrregs);
772
773 if (regno == -1)
774 {
775 int i;
776
777 for (i = 0; i < ppc_num_gprs; i++)
778 regcache_raw_collect (regcache,
779 tdep->ppc_ev0_upper_regnum + i,
780 &evrregs.evr[i]);
781 }
782 else if (tdep->ppc_ev0_upper_regnum <= regno
783 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
784 regcache_raw_collect (regcache, regno,
785 &evrregs.evr[regno - tdep->ppc_ev0_upper_regnum]);
786
787 if (regno == -1
788 || regno == tdep->ppc_acc_regnum)
789 regcache_raw_collect (regcache,
790 tdep->ppc_acc_regnum,
791 &evrregs.acc);
792
793 if (regno == -1
794 || regno == tdep->ppc_spefscr_regnum)
795 regcache_raw_collect (regcache,
796 tdep->ppc_spefscr_regnum,
797 &evrregs.spefscr);
798
799 /* Write back the modified register set. */
800 set_spe_registers (tid, &evrregs);
801 }
802
803 static void
804 store_register (const struct regcache *regcache, int tid, int regno)
805 {
806 struct gdbarch *gdbarch = get_regcache_arch (regcache);
807 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
808 /* This isn't really an address. But ptrace thinks of it as one. */
809 CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno);
810 int i;
811 size_t bytes_to_transfer;
812 char buf[MAX_REGISTER_SIZE];
813
814 if (altivec_register_p (gdbarch, regno))
815 {
816 store_altivec_register (regcache, tid, regno);
817 return;
818 }
819 if (vsx_register_p (gdbarch, regno))
820 {
821 store_vsx_register (regcache, tid, regno);
822 return;
823 }
824 else if (spe_register_p (gdbarch, regno))
825 {
826 store_spe_register (regcache, tid, regno);
827 return;
828 }
829
830 if (regaddr == -1)
831 return;
832
833 /* First collect the register. Keep in mind that the regcache's
834 idea of the register's size may not be a multiple of sizeof
835 (long). */
836 memset (buf, 0, sizeof buf);
837 bytes_to_transfer = align_up (register_size (gdbarch, regno), sizeof (long));
838 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
839 {
840 /* Little-endian values always sit at the left end of the buffer. */
841 regcache_raw_collect (regcache, regno, buf);
842 }
843 else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
844 {
845 /* Big-endian values sit at the right end of the buffer. */
846 size_t padding = (bytes_to_transfer - register_size (gdbarch, regno));
847 regcache_raw_collect (regcache, regno, buf + padding);
848 }
849
850 for (i = 0; i < bytes_to_transfer; i += sizeof (long))
851 {
852 errno = 0;
853 ptrace (PTRACE_POKEUSER, tid, (PTRACE_TYPE_ARG3) regaddr,
854 *(long *) &buf[i]);
855 regaddr += sizeof (long);
856
857 if (errno == EIO
858 && (regno == tdep->ppc_fpscr_regnum
859 || regno == PPC_ORIG_R3_REGNUM
860 || regno == PPC_TRAP_REGNUM))
861 {
862 /* Some older kernel versions don't allow fpscr, orig_r3
863 or trap to be written. */
864 continue;
865 }
866
867 if (errno != 0)
868 {
869 char message[128];
870 sprintf (message, "writing register %s (#%d)",
871 gdbarch_register_name (gdbarch, regno), regno);
872 perror_with_name (message);
873 }
874 }
875 }
876
877 static void
878 fill_vsxregset (const struct regcache *regcache, gdb_vsxregset_t *vsxregsetp)
879 {
880 int i;
881 struct gdbarch *gdbarch = get_regcache_arch (regcache);
882 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
883 int vsxregsize = register_size (gdbarch, tdep->ppc_vsr0_upper_regnum);
884
885 for (i = 0; i < ppc_num_vshrs; i++)
886 regcache_raw_collect (regcache, tdep->ppc_vsr0_upper_regnum + i,
887 *vsxregsetp + i * vsxregsize);
888 }
889
890 static void
891 fill_vrregset (const struct regcache *regcache, gdb_vrregset_t *vrregsetp)
892 {
893 int i;
894 struct gdbarch *gdbarch = get_regcache_arch (regcache);
895 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
896 int num_of_vrregs = tdep->ppc_vrsave_regnum - tdep->ppc_vr0_regnum + 1;
897 int vrregsize = register_size (gdbarch, tdep->ppc_vr0_regnum);
898 int offset = vrregsize - register_size (gdbarch, tdep->ppc_vrsave_regnum);
899
900 for (i = 0; i < num_of_vrregs; i++)
901 {
902 /* The last 2 registers of this set are only 32 bit long, not
903 128, but only VSCR is fetched as a 16 bytes quantity. */
904 if (i == (num_of_vrregs - 2))
905 regcache_raw_collect (regcache, tdep->ppc_vr0_regnum + i,
906 *vrregsetp + i * vrregsize + offset);
907 else
908 regcache_raw_collect (regcache, tdep->ppc_vr0_regnum + i,
909 *vrregsetp + i * vrregsize);
910 }
911 }
912
913 static void
914 store_vsx_registers (const struct regcache *regcache, int tid)
915 {
916 int ret;
917 gdb_vsxregset_t regs;
918
919 ret = ptrace (PTRACE_GETVSXREGS, tid, 0, &regs);
920 if (ret < 0)
921 {
922 if (errno == EIO)
923 {
924 have_ptrace_getsetvsxregs = 0;
925 return;
926 }
927 perror_with_name (_("Couldn't get VSX registers"));
928 }
929
930 fill_vsxregset (regcache, &regs);
931
932 if (ptrace (PTRACE_SETVSXREGS, tid, 0, &regs) < 0)
933 perror_with_name (_("Couldn't write VSX registers"));
934 }
935
936 static void
937 store_altivec_registers (const struct regcache *regcache, int tid)
938 {
939 int ret;
940 gdb_vrregset_t regs;
941
942 ret = ptrace (PTRACE_GETVRREGS, tid, 0, &regs);
943 if (ret < 0)
944 {
945 if (errno == EIO)
946 {
947 have_ptrace_getvrregs = 0;
948 return;
949 }
950 perror_with_name (_("Couldn't get AltiVec registers"));
951 }
952
953 fill_vrregset (regcache, &regs);
954
955 if (ptrace (PTRACE_SETVRREGS, tid, 0, &regs) < 0)
956 perror_with_name (_("Couldn't write AltiVec registers"));
957 }
958
959 static void
960 store_ppc_registers (const struct regcache *regcache, int tid)
961 {
962 int i;
963 struct gdbarch *gdbarch = get_regcache_arch (regcache);
964 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
965
966 for (i = 0; i < ppc_num_gprs; i++)
967 store_register (regcache, tid, tdep->ppc_gp0_regnum + i);
968 if (tdep->ppc_fp0_regnum >= 0)
969 for (i = 0; i < ppc_num_fprs; i++)
970 store_register (regcache, tid, tdep->ppc_fp0_regnum + i);
971 store_register (regcache, tid, gdbarch_pc_regnum (gdbarch));
972 if (tdep->ppc_ps_regnum != -1)
973 store_register (regcache, tid, tdep->ppc_ps_regnum);
974 if (tdep->ppc_cr_regnum != -1)
975 store_register (regcache, tid, tdep->ppc_cr_regnum);
976 if (tdep->ppc_lr_regnum != -1)
977 store_register (regcache, tid, tdep->ppc_lr_regnum);
978 if (tdep->ppc_ctr_regnum != -1)
979 store_register (regcache, tid, tdep->ppc_ctr_regnum);
980 if (tdep->ppc_xer_regnum != -1)
981 store_register (regcache, tid, tdep->ppc_xer_regnum);
982 if (tdep->ppc_mq_regnum != -1)
983 store_register (regcache, tid, tdep->ppc_mq_regnum);
984 if (tdep->ppc_fpscr_regnum != -1)
985 store_register (regcache, tid, tdep->ppc_fpscr_regnum);
986 if (ppc_linux_trap_reg_p (gdbarch))
987 {
988 store_register (regcache, tid, PPC_ORIG_R3_REGNUM);
989 store_register (regcache, tid, PPC_TRAP_REGNUM);
990 }
991 if (have_ptrace_getvrregs)
992 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
993 store_altivec_registers (regcache, tid);
994 if (have_ptrace_getsetvsxregs)
995 if (tdep->ppc_vsr0_upper_regnum != -1)
996 store_vsx_registers (regcache, tid);
997 if (tdep->ppc_ev0_upper_regnum >= 0)
998 store_spe_register (regcache, tid, -1);
999 }
1000
1001 static int
1002 ppc_linux_check_watch_resources (int type, int cnt, int ot)
1003 {
1004 int tid;
1005 ptid_t ptid = inferior_ptid;
1006
1007 /* DABR (data address breakpoint register) is optional for PPC variants.
1008 Some variants have one DABR, others have none. So CNT can't be larger
1009 than 1. */
1010 if (cnt > 1)
1011 return 0;
1012
1013 /* We need to know whether ptrace supports PTRACE_SET_DEBUGREG and whether
1014 the target has DABR. If either answer is no, the ptrace call will
1015 return -1. Fail in that case. */
1016 tid = TIDGET (ptid);
1017 if (tid == 0)
1018 tid = PIDGET (ptid);
1019
1020 if (ptrace (PTRACE_SET_DEBUGREG, tid, 0, 0) == -1)
1021 return 0;
1022 return 1;
1023 }
1024
1025 /* Fetch the AT_HWCAP entry from the aux vector. */
1026 unsigned long ppc_linux_get_hwcap (void)
1027 {
1028 CORE_ADDR field;
1029
1030 if (target_auxv_search (&current_target, AT_HWCAP, &field))
1031 return (unsigned long) field;
1032
1033 return 0;
1034 }
1035
1036 static int
1037 ppc_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
1038 {
1039 /* Handle sub-8-byte quantities. */
1040 if (len <= 0)
1041 return 0;
1042
1043 /* addr+len must fall in the 8 byte watchable region for DABR-based
1044 processors. DAC-based processors, like the PowerPC 440, will use
1045 addresses aligned to 4-bytes due to the way the read/write flags are
1046 passed at the moment. */
1047 if (((ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
1048 && (addr + len) > (addr & ~3) + 4)
1049 || (addr + len) > (addr & ~7) + 8)
1050 return 0;
1051
1052 return 1;
1053 }
1054
1055 /* The cached DABR value, to install in new threads. */
1056 static long saved_dabr_value;
1057
1058 /* Set a watchpoint of type TYPE at address ADDR. */
1059 static int
1060 ppc_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw)
1061 {
1062 struct lwp_info *lp;
1063 ptid_t ptid;
1064 long dabr_value;
1065 long read_mode, write_mode;
1066
1067 if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
1068 {
1069 /* PowerPC 440 requires only the read/write flags to be passed
1070 to the kernel. */
1071 read_mode = 1;
1072 write_mode = 2;
1073 }
1074 else
1075 {
1076 /* PowerPC 970 and other DABR-based processors are required to pass
1077 the Breakpoint Translation bit together with the flags. */
1078 read_mode = 5;
1079 write_mode = 6;
1080 }
1081
1082 dabr_value = addr & ~(read_mode | write_mode);
1083 switch (rw)
1084 {
1085 case hw_read:
1086 /* Set read and translate bits. */
1087 dabr_value |= read_mode;
1088 break;
1089 case hw_write:
1090 /* Set write and translate bits. */
1091 dabr_value |= write_mode;
1092 break;
1093 case hw_access:
1094 /* Set read, write and translate bits. */
1095 dabr_value |= read_mode | write_mode;
1096 break;
1097 }
1098
1099 saved_dabr_value = dabr_value;
1100
1101 ALL_LWPS (lp, ptid)
1102 if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0, saved_dabr_value) < 0)
1103 return -1;
1104
1105 return 0;
1106 }
1107
1108 static int
1109 ppc_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw)
1110 {
1111 struct lwp_info *lp;
1112 ptid_t ptid;
1113 long dabr_value = 0;
1114
1115 saved_dabr_value = 0;
1116 ALL_LWPS (lp, ptid)
1117 if (ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0, saved_dabr_value) < 0)
1118 return -1;
1119 return 0;
1120 }
1121
1122 static void
1123 ppc_linux_new_thread (ptid_t ptid)
1124 {
1125 ptrace (PTRACE_SET_DEBUGREG, TIDGET (ptid), 0, saved_dabr_value);
1126 }
1127
1128 static int
1129 ppc_linux_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
1130 {
1131 struct siginfo *siginfo_p;
1132
1133 siginfo_p = linux_nat_get_siginfo (inferior_ptid);
1134
1135 if (siginfo_p->si_signo != SIGTRAP
1136 || (siginfo_p->si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
1137 return 0;
1138
1139 *addr_p = (CORE_ADDR) (uintptr_t) siginfo_p->si_addr;
1140 return 1;
1141 }
1142
1143 static int
1144 ppc_linux_stopped_by_watchpoint (void)
1145 {
1146 CORE_ADDR addr;
1147 return ppc_linux_stopped_data_address (&current_target, &addr);
1148 }
1149
1150 static int
1151 ppc_linux_watchpoint_addr_within_range (struct target_ops *target,
1152 CORE_ADDR addr,
1153 CORE_ADDR start, int length)
1154 {
1155 int mask;
1156
1157 if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE)
1158 mask = 3;
1159 else
1160 mask = 7;
1161
1162 addr &= ~mask;
1163
1164 /* Check whether [start, start+length-1] intersects [addr, addr+mask]. */
1165 return start <= addr + mask && start + length - 1 >= addr;
1166 }
1167
1168 static void
1169 ppc_linux_store_inferior_registers (struct regcache *regcache, int regno)
1170 {
1171 /* Overload thread id onto process id */
1172 int tid = TIDGET (inferior_ptid);
1173
1174 /* No thread id, just use process id */
1175 if (tid == 0)
1176 tid = PIDGET (inferior_ptid);
1177
1178 if (regno >= 0)
1179 store_register (regcache, tid, regno);
1180 else
1181 store_ppc_registers (regcache, tid);
1182 }
1183
1184 /* Functions for transferring registers between a gregset_t or fpregset_t
1185 (see sys/ucontext.h) and gdb's regcache. The word size is that used
1186 by the ptrace interface, not the current program's ABI. eg. If a
1187 powerpc64-linux gdb is being used to debug a powerpc32-linux app, we
1188 read or write 64-bit gregsets. This is to suit the host libthread_db. */
1189
1190 void
1191 supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
1192 {
1193 const struct regset *regset = ppc_linux_gregset (sizeof (long));
1194
1195 ppc_supply_gregset (regset, regcache, -1, gregsetp, sizeof (*gregsetp));
1196 }
1197
1198 void
1199 fill_gregset (const struct regcache *regcache,
1200 gdb_gregset_t *gregsetp, int regno)
1201 {
1202 const struct regset *regset = ppc_linux_gregset (sizeof (long));
1203
1204 if (regno == -1)
1205 memset (gregsetp, 0, sizeof (*gregsetp));
1206 ppc_collect_gregset (regset, regcache, regno, gregsetp, sizeof (*gregsetp));
1207 }
1208
1209 void
1210 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t * fpregsetp)
1211 {
1212 const struct regset *regset = ppc_linux_fpregset ();
1213
1214 ppc_supply_fpregset (regset, regcache, -1,
1215 fpregsetp, sizeof (*fpregsetp));
1216 }
1217
1218 void
1219 fill_fpregset (const struct regcache *regcache,
1220 gdb_fpregset_t *fpregsetp, int regno)
1221 {
1222 const struct regset *regset = ppc_linux_fpregset ();
1223
1224 ppc_collect_fpregset (regset, regcache, regno,
1225 fpregsetp, sizeof (*fpregsetp));
1226 }
1227
1228 static const struct target_desc *
1229 ppc_linux_read_description (struct target_ops *ops)
1230 {
1231 int altivec = 0;
1232 int vsx = 0;
1233
1234 int tid = TIDGET (inferior_ptid);
1235 if (tid == 0)
1236 tid = PIDGET (inferior_ptid);
1237
1238 if (have_ptrace_getsetevrregs)
1239 {
1240 struct gdb_evrregset_t evrregset;
1241
1242 if (ptrace (PTRACE_GETEVRREGS, tid, 0, &evrregset) >= 0)
1243 return tdesc_powerpc_e500l;
1244
1245 /* EIO means that the PTRACE_GETEVRREGS request isn't supported.
1246 Anything else needs to be reported. */
1247 else if (errno != EIO)
1248 perror_with_name (_("Unable to fetch SPE registers"));
1249 }
1250
1251 if (have_ptrace_getsetvsxregs)
1252 {
1253 gdb_vsxregset_t vsxregset;
1254
1255 if (ptrace (PTRACE_GETVSXREGS, tid, 0, &vsxregset) >= 0)
1256 vsx = 1;
1257
1258 /* EIO means that the PTRACE_GETVSXREGS request isn't supported.
1259 Anything else needs to be reported. */
1260 else if (errno != EIO)
1261 perror_with_name (_("Unable to fetch VSX registers"));
1262 }
1263
1264 if (have_ptrace_getvrregs)
1265 {
1266 gdb_vrregset_t vrregset;
1267
1268 if (ptrace (PTRACE_GETVRREGS, tid, 0, &vrregset) >= 0)
1269 altivec = 1;
1270
1271 /* EIO means that the PTRACE_GETVRREGS request isn't supported.
1272 Anything else needs to be reported. */
1273 else if (errno != EIO)
1274 perror_with_name (_("Unable to fetch AltiVec registers"));
1275 }
1276
1277 /* Check for 64-bit inferior process. This is the case when the host is
1278 64-bit, and in addition the top bit of the MSR register is set. */
1279 #ifdef __powerpc64__
1280 {
1281 long msr;
1282 errno = 0;
1283 msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0);
1284 if (errno == 0 && msr < 0)
1285 {
1286 if (vsx)
1287 return tdesc_powerpc_vsx64l;
1288 else if (altivec)
1289 return tdesc_powerpc_altivec64l;
1290
1291 return tdesc_powerpc_64l;
1292 }
1293 }
1294 #endif
1295
1296 if (vsx)
1297 return tdesc_powerpc_vsx32l;
1298 else if (altivec)
1299 return tdesc_powerpc_altivec32l;
1300
1301 return tdesc_powerpc_32l;
1302 }
1303
1304 void _initialize_ppc_linux_nat (void);
1305
1306 void
1307 _initialize_ppc_linux_nat (void)
1308 {
1309 struct target_ops *t;
1310
1311 /* Fill in the generic GNU/Linux methods. */
1312 t = linux_target ();
1313
1314 /* Add our register access methods. */
1315 t->to_fetch_registers = ppc_linux_fetch_inferior_registers;
1316 t->to_store_registers = ppc_linux_store_inferior_registers;
1317
1318 /* Add our watchpoint methods. */
1319 t->to_can_use_hw_breakpoint = ppc_linux_check_watch_resources;
1320 t->to_region_ok_for_hw_watchpoint = ppc_linux_region_ok_for_hw_watchpoint;
1321 t->to_insert_watchpoint = ppc_linux_insert_watchpoint;
1322 t->to_remove_watchpoint = ppc_linux_remove_watchpoint;
1323 t->to_stopped_by_watchpoint = ppc_linux_stopped_by_watchpoint;
1324 t->to_stopped_data_address = ppc_linux_stopped_data_address;
1325 t->to_watchpoint_addr_within_range = ppc_linux_watchpoint_addr_within_range;
1326
1327 t->to_read_description = ppc_linux_read_description;
1328
1329 /* Register the target. */
1330 linux_nat_add_target (t);
1331 linux_nat_set_new_thread (t, ppc_linux_new_thread);
1332 }
This page took 0.07184 seconds and 4 git commands to generate.