1 /* PPC GNU/Linux native support.
3 Copyright (C) 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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/>. */
22 #include "gdb_string.h"
27 #include "gdb_assert.h"
29 #include "linux-nat.h"
32 #include <sys/types.h>
33 #include <sys/param.h>
36 #include <sys/ioctl.h>
39 #include <sys/procfs.h>
40 #include <sys/ptrace.h>
42 /* Prototypes for supply_gregset etc. */
45 #include "ppc-linux-tdep.h"
47 /* Required when using the AUXV. */
48 #include "elf/common.h"
51 /* This sometimes isn't defined. */
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
63 #ifndef PPC_FEATURE_BOOKE
64 #define PPC_FEATURE_BOOKE 0x00008000
66 #ifndef PPC_FEATURE_HAS_DFP
67 #define PPC_FEATURE_HAS_DFP 0x00000400 /* Decimal Floating Point. */
70 /* Glibc's headers don't define PTRACE_GETVRREGS so we cannot use a
71 configure time check. Some older glibc's (for instance 2.2.1)
72 don't have a specific powerpc version of ptrace.h, and fall back on
73 a generic one. In such cases, sys/ptrace.h defines
74 PTRACE_GETFPXREGS and PTRACE_SETFPXREGS to the same numbers that
75 ppc kernel's asm/ptrace.h defines PTRACE_GETVRREGS and
76 PTRACE_SETVRREGS to be. This also makes a configury check pretty
79 /* These definitions should really come from the glibc header files,
80 but Glibc doesn't know about the vrregs yet. */
81 #ifndef PTRACE_GETVRREGS
82 #define PTRACE_GETVRREGS 18
83 #define PTRACE_SETVRREGS 19
86 /* PTRACE requests for POWER7 VSX registers. */
87 #ifndef PTRACE_GETVSXREGS
88 #define PTRACE_GETVSXREGS 27
89 #define PTRACE_SETVSXREGS 28
92 /* Similarly for the ptrace requests for getting / setting the SPE
93 registers (ev0 -- ev31, acc, and spefscr). See the description of
94 gdb_evrregset_t for details. */
95 #ifndef PTRACE_GETEVRREGS
96 #define PTRACE_GETEVRREGS 20
97 #define PTRACE_SETEVRREGS 21
100 /* Similarly for the hardware watchpoint support. */
101 #ifndef PTRACE_GET_DEBUGREG
102 #define PTRACE_GET_DEBUGREG 25
104 #ifndef PTRACE_SET_DEBUGREG
105 #define PTRACE_SET_DEBUGREG 26
107 #ifndef PTRACE_GETSIGINFO
108 #define PTRACE_GETSIGINFO 0x4202
111 /* Similarly for the general-purpose (gp0 -- gp31)
112 and floating-point registers (fp0 -- fp31). */
113 #ifndef PTRACE_GETREGS
114 #define PTRACE_GETREGS 12
116 #ifndef PTRACE_SETREGS
117 #define PTRACE_SETREGS 13
119 #ifndef PTRACE_GETFPREGS
120 #define PTRACE_GETFPREGS 14
122 #ifndef PTRACE_SETFPREGS
123 #define PTRACE_SETFPREGS 15
126 /* This oddity is because the Linux kernel defines elf_vrregset_t as
127 an array of 33 16 bytes long elements. I.e. it leaves out vrsave.
128 However the PTRACE_GETVRREGS and PTRACE_SETVRREGS requests return
129 the vrsave as an extra 4 bytes at the end. I opted for creating a
130 flat array of chars, so that it is easier to manipulate for gdb.
132 There are 32 vector registers 16 bytes longs, plus a VSCR register
133 which is only 4 bytes long, but is fetched as a 16 bytes
134 quantity. Up to here we have the elf_vrregset_t structure.
135 Appended to this there is space for the VRSAVE register: 4 bytes.
136 Even though this vrsave register is not included in the regset
137 typedef, it is handled by the ptrace requests.
139 Note that GNU/Linux doesn't support little endian PPC hardware,
140 therefore the offset at which the real value of the VSCR register
141 is located will be always 12 bytes.
143 The layout is like this (where x is the actual value of the vscr reg): */
147 |.|.|.|.|.....|.|.|.|.||.|.|.|x||.|
148 <-------> <-------><-------><->
153 #define SIZEOF_VRREGS 33*16+4
155 typedef char gdb_vrregset_t
[SIZEOF_VRREGS
];
157 /* This is the layout of the POWER7 VSX registers and the way they overlap
158 with the existing FPR and VMX registers.
160 VSR doubleword 0 VSR doubleword 1
161 ----------------------------------------------------------------
163 ----------------------------------------------------------------
165 ----------------------------------------------------------------
168 ----------------------------------------------------------------
169 VSR[30] | FPR[30] | |
170 ----------------------------------------------------------------
171 VSR[31] | FPR[31] | |
172 ----------------------------------------------------------------
174 ----------------------------------------------------------------
176 ----------------------------------------------------------------
179 ----------------------------------------------------------------
181 ----------------------------------------------------------------
183 ----------------------------------------------------------------
185 VSX has 64 128bit registers. The first 32 registers overlap with
186 the FP registers (doubleword 0) and hence extend them with additional
187 64 bits (doubleword 1). The other 32 regs overlap with the VMX
189 #define SIZEOF_VSXREGS 32*8
191 typedef char gdb_vsxregset_t
[SIZEOF_VSXREGS
];
193 /* On PPC processors that support the the Signal Processing Extension
194 (SPE) APU, the general-purpose registers are 64 bits long.
195 However, the ordinary Linux kernel PTRACE_PEEKUSER / PTRACE_POKEUSER
196 ptrace calls only access the lower half of each register, to allow
197 them to behave the same way they do on non-SPE systems. There's a
198 separate pair of calls, PTRACE_GETEVRREGS / PTRACE_SETEVRREGS, that
199 read and write the top halves of all the general-purpose registers
200 at once, along with some SPE-specific registers.
202 GDB itself continues to claim the general-purpose registers are 32
203 bits long. It has unnamed raw registers that hold the upper halves
204 of the gprs, and the the full 64-bit SIMD views of the registers,
205 'ev0' -- 'ev31', are pseudo-registers that splice the top and
206 bottom halves together.
208 This is the structure filled in by PTRACE_GETEVRREGS and written to
209 the inferior's registers by PTRACE_SETEVRREGS. */
210 struct gdb_evrregset_t
212 unsigned long evr
[32];
213 unsigned long long acc
;
214 unsigned long spefscr
;
217 /* Non-zero if our kernel may support the PTRACE_GETVSXREGS and
218 PTRACE_SETVSXREGS requests, for reading and writing the VSX
219 POWER7 registers 0 through 31. Zero if we've tried one of them and
220 gotten an error. Note that VSX registers 32 through 63 overlap
221 with VR registers 0 through 31. */
222 int have_ptrace_getsetvsxregs
= 1;
224 /* Non-zero if our kernel may support the PTRACE_GETVRREGS and
225 PTRACE_SETVRREGS requests, for reading and writing the Altivec
226 registers. Zero if we've tried one of them and gotten an
228 int have_ptrace_getvrregs
= 1;
230 /* Non-zero if our kernel may support the PTRACE_GETEVRREGS and
231 PTRACE_SETEVRREGS requests, for reading and writing the SPE
232 registers. Zero if we've tried one of them and gotten an
234 int have_ptrace_getsetevrregs
= 1;
236 /* Non-zero if our kernel may support the PTRACE_GETREGS and
237 PTRACE_SETREGS requests, for reading and writing the
238 general-purpose registers. Zero if we've tried one of
239 them and gotten an error. */
240 int have_ptrace_getsetregs
= 1;
242 /* Non-zero if our kernel may support the PTRACE_GETFPREGS and
243 PTRACE_SETFPREGS requests, for reading and writing the
244 floating-pointers registers. Zero if we've tried one of
245 them and gotten an error. */
246 int have_ptrace_getsetfpregs
= 1;
249 /* registers layout, as presented by the ptrace interface:
250 PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
251 PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15,
252 PT_R16, PT_R17, PT_R18, PT_R19, PT_R20, PT_R21, PT_R22, PT_R23,
253 PT_R24, PT_R25, PT_R26, PT_R27, PT_R28, PT_R29, PT_R30, PT_R31,
254 PT_FPR0, PT_FPR0 + 2, PT_FPR0 + 4, PT_FPR0 + 6, PT_FPR0 + 8, PT_FPR0 + 10, PT_FPR0 + 12, PT_FPR0 + 14,
255 PT_FPR0 + 16, PT_FPR0 + 18, PT_FPR0 + 20, PT_FPR0 + 22, PT_FPR0 + 24, PT_FPR0 + 26, PT_FPR0 + 28, PT_FPR0 + 30,
256 PT_FPR0 + 32, PT_FPR0 + 34, PT_FPR0 + 36, PT_FPR0 + 38, PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46,
257 PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54, PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62,
258 PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */
262 ppc_register_u_addr (struct gdbarch
*gdbarch
, int regno
)
265 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
266 /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace
267 interface, and not the wordsize of the program's ABI. */
268 int wordsize
= sizeof (long);
270 /* General purpose registers occupy 1 slot each in the buffer */
271 if (regno
>= tdep
->ppc_gp0_regnum
272 && regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
)
273 u_addr
= ((regno
- tdep
->ppc_gp0_regnum
+ PT_R0
) * wordsize
);
275 /* Floating point regs: eight bytes each in both 32- and 64-bit
276 ptrace interfaces. Thus, two slots each in 32-bit interface, one
277 slot each in 64-bit interface. */
278 if (tdep
->ppc_fp0_regnum
>= 0
279 && regno
>= tdep
->ppc_fp0_regnum
280 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
281 u_addr
= (PT_FPR0
* wordsize
) + ((regno
- tdep
->ppc_fp0_regnum
) * 8);
283 /* UISA special purpose registers: 1 slot each */
284 if (regno
== gdbarch_pc_regnum (gdbarch
))
285 u_addr
= PT_NIP
* wordsize
;
286 if (regno
== tdep
->ppc_lr_regnum
)
287 u_addr
= PT_LNK
* wordsize
;
288 if (regno
== tdep
->ppc_cr_regnum
)
289 u_addr
= PT_CCR
* wordsize
;
290 if (regno
== tdep
->ppc_xer_regnum
)
291 u_addr
= PT_XER
* wordsize
;
292 if (regno
== tdep
->ppc_ctr_regnum
)
293 u_addr
= PT_CTR
* wordsize
;
295 if (regno
== tdep
->ppc_mq_regnum
)
296 u_addr
= PT_MQ
* wordsize
;
298 if (regno
== tdep
->ppc_ps_regnum
)
299 u_addr
= PT_MSR
* wordsize
;
300 if (regno
== PPC_ORIG_R3_REGNUM
)
301 u_addr
= PT_ORIG_R3
* wordsize
;
302 if (regno
== PPC_TRAP_REGNUM
)
303 u_addr
= PT_TRAP
* wordsize
;
304 if (tdep
->ppc_fpscr_regnum
>= 0
305 && regno
== tdep
->ppc_fpscr_regnum
)
307 /* NOTE: cagney/2005-02-08: On some 64-bit GNU/Linux systems the
308 kernel headers incorrectly contained the 32-bit definition of
309 PT_FPSCR. For the 32-bit definition, floating-point
310 registers occupy two 32-bit "slots", and the FPSCR lives in
311 the second half of such a slot-pair (hence +1). For 64-bit,
312 the FPSCR instead occupies the full 64-bit 2-word-slot and
313 hence no adjustment is necessary. Hack around this. */
314 if (wordsize
== 8 && PT_FPSCR
== (48 + 32 + 1))
315 u_addr
= (48 + 32) * wordsize
;
316 /* If the FPSCR is 64-bit wide, we need to fetch the whole 64-bit
317 slot and not just its second word. The PT_FPSCR supplied when
318 GDB is compiled as a 32-bit app doesn't reflect this. */
319 else if (wordsize
== 4 && register_size (gdbarch
, regno
) == 8
320 && PT_FPSCR
== (48 + 2*32 + 1))
321 u_addr
= (48 + 2*32) * wordsize
;
323 u_addr
= PT_FPSCR
* wordsize
;
328 /* The Linux kernel ptrace interface for POWER7 VSX registers uses the
329 registers set mechanism, as opposed to the interface for all the
330 other registers, that stores/fetches each register individually. */
332 fetch_vsx_register (struct regcache
*regcache
, int tid
, int regno
)
335 gdb_vsxregset_t regs
;
336 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
337 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
338 int vsxregsize
= register_size (gdbarch
, tdep
->ppc_vsr0_upper_regnum
);
340 ret
= ptrace (PTRACE_GETVSXREGS
, tid
, 0, ®s
);
345 have_ptrace_getsetvsxregs
= 0;
348 perror_with_name (_("Unable to fetch VSX register"));
351 regcache_raw_supply (regcache
, regno
,
352 regs
+ (regno
- tdep
->ppc_vsr0_upper_regnum
)
356 /* The Linux kernel ptrace interface for AltiVec registers uses the
357 registers set mechanism, as opposed to the interface for all the
358 other registers, that stores/fetches each register individually. */
360 fetch_altivec_register (struct regcache
*regcache
, int tid
, int regno
)
365 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
366 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
367 int vrregsize
= register_size (gdbarch
, tdep
->ppc_vr0_regnum
);
369 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
374 have_ptrace_getvrregs
= 0;
377 perror_with_name (_("Unable to fetch AltiVec register"));
380 /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes
381 long on the hardware. We deal only with the lower 4 bytes of the
382 vector. VRSAVE is at the end of the array in a 4 bytes slot, so
383 there is no need to define an offset for it. */
384 if (regno
== (tdep
->ppc_vrsave_regnum
- 1))
385 offset
= vrregsize
- register_size (gdbarch
, tdep
->ppc_vrsave_regnum
);
387 regcache_raw_supply (regcache
, regno
,
388 regs
+ (regno
- tdep
->ppc_vr0_regnum
) * vrregsize
+ offset
);
391 /* Fetch the top 32 bits of TID's general-purpose registers and the
392 SPE-specific registers, and place the results in EVRREGSET. If we
393 don't support PTRACE_GETEVRREGS, then just fill EVRREGSET with
396 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
397 PTRACE_SETEVRREGS requests are supported is isolated here, and in
398 set_spe_registers. */
400 get_spe_registers (int tid
, struct gdb_evrregset_t
*evrregset
)
402 if (have_ptrace_getsetevrregs
)
404 if (ptrace (PTRACE_GETEVRREGS
, tid
, 0, evrregset
) >= 0)
408 /* EIO means that the PTRACE_GETEVRREGS request isn't supported;
409 we just return zeros. */
411 have_ptrace_getsetevrregs
= 0;
413 /* Anything else needs to be reported. */
414 perror_with_name (_("Unable to fetch SPE registers"));
418 memset (evrregset
, 0, sizeof (*evrregset
));
421 /* Supply values from TID for SPE-specific raw registers: the upper
422 halves of the GPRs, the accumulator, and the spefscr. REGNO must
423 be the number of an upper half register, acc, spefscr, or -1 to
424 supply the values of all registers. */
426 fetch_spe_register (struct regcache
*regcache
, int tid
, int regno
)
428 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
429 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
430 struct gdb_evrregset_t evrregs
;
432 gdb_assert (sizeof (evrregs
.evr
[0])
433 == register_size (gdbarch
, tdep
->ppc_ev0_upper_regnum
));
434 gdb_assert (sizeof (evrregs
.acc
)
435 == register_size (gdbarch
, tdep
->ppc_acc_regnum
));
436 gdb_assert (sizeof (evrregs
.spefscr
)
437 == register_size (gdbarch
, tdep
->ppc_spefscr_regnum
));
439 get_spe_registers (tid
, &evrregs
);
445 for (i
= 0; i
< ppc_num_gprs
; i
++)
446 regcache_raw_supply (regcache
, tdep
->ppc_ev0_upper_regnum
+ i
,
449 else if (tdep
->ppc_ev0_upper_regnum
<= regno
450 && regno
< tdep
->ppc_ev0_upper_regnum
+ ppc_num_gprs
)
451 regcache_raw_supply (regcache
, regno
,
452 &evrregs
.evr
[regno
- tdep
->ppc_ev0_upper_regnum
]);
455 || regno
== tdep
->ppc_acc_regnum
)
456 regcache_raw_supply (regcache
, tdep
->ppc_acc_regnum
, &evrregs
.acc
);
459 || regno
== tdep
->ppc_spefscr_regnum
)
460 regcache_raw_supply (regcache
, tdep
->ppc_spefscr_regnum
,
465 fetch_register (struct regcache
*regcache
, int tid
, int regno
)
467 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
468 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
469 /* This isn't really an address. But ptrace thinks of it as one. */
470 CORE_ADDR regaddr
= ppc_register_u_addr (gdbarch
, regno
);
471 int bytes_transferred
;
472 unsigned int offset
; /* Offset of registers within the u area. */
473 char buf
[MAX_REGISTER_SIZE
];
475 if (altivec_register_p (gdbarch
, regno
))
477 /* If this is the first time through, or if it is not the first
478 time through, and we have comfirmed that there is kernel
479 support for such a ptrace request, then go and fetch the
481 if (have_ptrace_getvrregs
)
483 fetch_altivec_register (regcache
, tid
, regno
);
486 /* If we have discovered that there is no ptrace support for
487 AltiVec registers, fall through and return zeroes, because
488 regaddr will be -1 in this case. */
490 if (vsx_register_p (gdbarch
, regno
))
492 if (have_ptrace_getsetvsxregs
)
494 fetch_vsx_register (regcache
, tid
, regno
);
498 else if (spe_register_p (gdbarch
, regno
))
500 fetch_spe_register (regcache
, tid
, regno
);
506 memset (buf
, '\0', register_size (gdbarch
, regno
)); /* Supply zeroes */
507 regcache_raw_supply (regcache
, regno
, buf
);
511 /* Read the raw register using sizeof(long) sized chunks. On a
512 32-bit platform, 64-bit floating-point registers will require two
514 for (bytes_transferred
= 0;
515 bytes_transferred
< register_size (gdbarch
, regno
);
516 bytes_transferred
+= sizeof (long))
519 *(long *) &buf
[bytes_transferred
]
520 = ptrace (PTRACE_PEEKUSER
, tid
, (PTRACE_TYPE_ARG3
) regaddr
, 0);
521 regaddr
+= sizeof (long);
525 sprintf (message
, "reading register %s (#%d)",
526 gdbarch_register_name (gdbarch
, regno
), regno
);
527 perror_with_name (message
);
531 /* Now supply the register. Keep in mind that the regcache's idea
532 of the register's size may not be a multiple of sizeof
534 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
536 /* Little-endian values are always found at the left end of the
537 bytes transferred. */
538 regcache_raw_supply (regcache
, regno
, buf
);
540 else if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
542 /* Big-endian values are found at the right end of the bytes
544 size_t padding
= (bytes_transferred
- register_size (gdbarch
, regno
));
545 regcache_raw_supply (regcache
, regno
, buf
+ padding
);
548 internal_error (__FILE__
, __LINE__
,
549 _("fetch_register: unexpected byte order: %d"),
550 gdbarch_byte_order (gdbarch
));
554 supply_vsxregset (struct regcache
*regcache
, gdb_vsxregset_t
*vsxregsetp
)
557 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
558 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
559 int vsxregsize
= register_size (gdbarch
, tdep
->ppc_vsr0_upper_regnum
);
561 for (i
= 0; i
< ppc_num_vshrs
; i
++)
563 regcache_raw_supply (regcache
, tdep
->ppc_vsr0_upper_regnum
+ i
,
564 *vsxregsetp
+ i
* vsxregsize
);
569 supply_vrregset (struct regcache
*regcache
, gdb_vrregset_t
*vrregsetp
)
572 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
573 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
574 int num_of_vrregs
= tdep
->ppc_vrsave_regnum
- tdep
->ppc_vr0_regnum
+ 1;
575 int vrregsize
= register_size (gdbarch
, tdep
->ppc_vr0_regnum
);
576 int offset
= vrregsize
- register_size (gdbarch
, tdep
->ppc_vrsave_regnum
);
578 for (i
= 0; i
< num_of_vrregs
; i
++)
580 /* The last 2 registers of this set are only 32 bit long, not
581 128. However an offset is necessary only for VSCR because it
582 occupies a whole vector, while VRSAVE occupies a full 4 bytes
584 if (i
== (num_of_vrregs
- 2))
585 regcache_raw_supply (regcache
, tdep
->ppc_vr0_regnum
+ i
,
586 *vrregsetp
+ i
* vrregsize
+ offset
);
588 regcache_raw_supply (regcache
, tdep
->ppc_vr0_regnum
+ i
,
589 *vrregsetp
+ i
* vrregsize
);
594 fetch_vsx_registers (struct regcache
*regcache
, int tid
)
597 gdb_vsxregset_t regs
;
599 ret
= ptrace (PTRACE_GETVSXREGS
, tid
, 0, ®s
);
604 have_ptrace_getsetvsxregs
= 0;
607 perror_with_name (_("Unable to fetch VSX registers"));
609 supply_vsxregset (regcache
, ®s
);
613 fetch_altivec_registers (struct regcache
*regcache
, int tid
)
618 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
623 have_ptrace_getvrregs
= 0;
626 perror_with_name (_("Unable to fetch AltiVec registers"));
628 supply_vrregset (regcache
, ®s
);
631 /* This function actually issues the request to ptrace, telling
632 it to get all general-purpose registers and put them into the
635 If the ptrace request does not exist, this function returns 0
636 and properly sets the have_ptrace_* flag. If the request fails,
637 this function calls perror_with_name. Otherwise, if the request
638 succeeds, then the regcache gets filled and 1 is returned. */
640 fetch_all_gp_regs (struct regcache
*regcache
, int tid
)
642 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
643 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
644 gdb_gregset_t gregset
;
646 if (ptrace (PTRACE_GETREGS
, tid
, 0, (void *) &gregset
) < 0)
650 have_ptrace_getsetregs
= 0;
653 perror_with_name (_("Couldn't get general-purpose registers."));
656 supply_gregset (regcache
, (const gdb_gregset_t
*) &gregset
);
661 /* This is a wrapper for the fetch_all_gp_regs function. It is
662 responsible for verifying if this target has the ptrace request
663 that can be used to fetch all general-purpose registers at one
664 shot. If it doesn't, then we should fetch them using the
665 old-fashioned way, which is to iterate over the registers and
666 request them one by one. */
668 fetch_gp_regs (struct regcache
*regcache
, int tid
)
670 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
671 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
674 if (have_ptrace_getsetregs
)
675 if (fetch_all_gp_regs (regcache
, tid
))
678 /* If we've hit this point, it doesn't really matter which
679 architecture we are using. We just need to read the
680 registers in the "old-fashioned way". */
681 for (i
= 0; i
< ppc_num_gprs
; i
++)
682 fetch_register (regcache
, tid
, tdep
->ppc_gp0_regnum
+ i
);
685 /* This function actually issues the request to ptrace, telling
686 it to get all floating-point registers and put them into the
689 If the ptrace request does not exist, this function returns 0
690 and properly sets the have_ptrace_* flag. If the request fails,
691 this function calls perror_with_name. Otherwise, if the request
692 succeeds, then the regcache gets filled and 1 is returned. */
694 fetch_all_fp_regs (struct regcache
*regcache
, int tid
)
696 gdb_fpregset_t fpregs
;
698 if (ptrace (PTRACE_GETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
702 have_ptrace_getsetfpregs
= 0;
705 perror_with_name (_("Couldn't get floating-point registers."));
708 supply_fpregset (regcache
, (const gdb_fpregset_t
*) &fpregs
);
713 /* This is a wrapper for the fetch_all_fp_regs function. It is
714 responsible for verifying if this target has the ptrace request
715 that can be used to fetch all floating-point registers at one
716 shot. If it doesn't, then we should fetch them using the
717 old-fashioned way, which is to iterate over the registers and
718 request them one by one. */
720 fetch_fp_regs (struct regcache
*regcache
, int tid
)
722 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
723 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
726 if (have_ptrace_getsetfpregs
)
727 if (fetch_all_fp_regs (regcache
, tid
))
730 /* If we've hit this point, it doesn't really matter which
731 architecture we are using. We just need to read the
732 registers in the "old-fashioned way". */
733 for (i
= 0; i
< ppc_num_fprs
; i
++)
734 fetch_register (regcache
, tid
, tdep
->ppc_fp0_regnum
+ i
);
738 fetch_ppc_registers (struct regcache
*regcache
, int tid
)
741 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
742 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
744 fetch_gp_regs (regcache
, tid
);
745 if (tdep
->ppc_fp0_regnum
>= 0)
746 fetch_fp_regs (regcache
, tid
);
747 fetch_register (regcache
, tid
, gdbarch_pc_regnum (gdbarch
));
748 if (tdep
->ppc_ps_regnum
!= -1)
749 fetch_register (regcache
, tid
, tdep
->ppc_ps_regnum
);
750 if (tdep
->ppc_cr_regnum
!= -1)
751 fetch_register (regcache
, tid
, tdep
->ppc_cr_regnum
);
752 if (tdep
->ppc_lr_regnum
!= -1)
753 fetch_register (regcache
, tid
, tdep
->ppc_lr_regnum
);
754 if (tdep
->ppc_ctr_regnum
!= -1)
755 fetch_register (regcache
, tid
, tdep
->ppc_ctr_regnum
);
756 if (tdep
->ppc_xer_regnum
!= -1)
757 fetch_register (regcache
, tid
, tdep
->ppc_xer_regnum
);
758 if (tdep
->ppc_mq_regnum
!= -1)
759 fetch_register (regcache
, tid
, tdep
->ppc_mq_regnum
);
760 if (ppc_linux_trap_reg_p (gdbarch
))
762 fetch_register (regcache
, tid
, PPC_ORIG_R3_REGNUM
);
763 fetch_register (regcache
, tid
, PPC_TRAP_REGNUM
);
765 if (tdep
->ppc_fpscr_regnum
!= -1)
766 fetch_register (regcache
, tid
, tdep
->ppc_fpscr_regnum
);
767 if (have_ptrace_getvrregs
)
768 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
769 fetch_altivec_registers (regcache
, tid
);
770 if (have_ptrace_getsetvsxregs
)
771 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
772 fetch_vsx_registers (regcache
, tid
);
773 if (tdep
->ppc_ev0_upper_regnum
>= 0)
774 fetch_spe_register (regcache
, tid
, -1);
777 /* Fetch registers from the child process. Fetch all registers if
778 regno == -1, otherwise fetch all general registers or all floating
779 point registers depending upon the value of regno. */
781 ppc_linux_fetch_inferior_registers (struct target_ops
*ops
,
782 struct regcache
*regcache
, int regno
)
784 /* Overload thread id onto process id */
785 int tid
= TIDGET (inferior_ptid
);
787 /* No thread id, just use process id */
789 tid
= PIDGET (inferior_ptid
);
792 fetch_ppc_registers (regcache
, tid
);
794 fetch_register (regcache
, tid
, regno
);
797 /* Store one VSX register. */
799 store_vsx_register (const struct regcache
*regcache
, int tid
, int regno
)
802 gdb_vsxregset_t regs
;
803 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
804 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
805 int vsxregsize
= register_size (gdbarch
, tdep
->ppc_vsr0_upper_regnum
);
807 ret
= ptrace (PTRACE_SETVSXREGS
, tid
, 0, ®s
);
812 have_ptrace_getsetvsxregs
= 0;
815 perror_with_name (_("Unable to fetch VSX register"));
818 regcache_raw_collect (regcache
, regno
, regs
+
819 (regno
- tdep
->ppc_vsr0_upper_regnum
) * vsxregsize
);
821 ret
= ptrace (PTRACE_SETVSXREGS
, tid
, 0, ®s
);
823 perror_with_name (_("Unable to store VSX register"));
826 /* Store one register. */
828 store_altivec_register (const struct regcache
*regcache
, int tid
, int regno
)
833 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
834 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
835 int vrregsize
= register_size (gdbarch
, tdep
->ppc_vr0_regnum
);
837 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
842 have_ptrace_getvrregs
= 0;
845 perror_with_name (_("Unable to fetch AltiVec register"));
848 /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes
849 long on the hardware. */
850 if (regno
== (tdep
->ppc_vrsave_regnum
- 1))
851 offset
= vrregsize
- register_size (gdbarch
, tdep
->ppc_vrsave_regnum
);
853 regcache_raw_collect (regcache
, regno
,
854 regs
+ (regno
- tdep
->ppc_vr0_regnum
) * vrregsize
+ offset
);
856 ret
= ptrace (PTRACE_SETVRREGS
, tid
, 0, ®s
);
858 perror_with_name (_("Unable to store AltiVec register"));
861 /* Assuming TID referrs to an SPE process, set the top halves of TID's
862 general-purpose registers and its SPE-specific registers to the
863 values in EVRREGSET. If we don't support PTRACE_SETEVRREGS, do
866 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
867 PTRACE_SETEVRREGS requests are supported is isolated here, and in
868 get_spe_registers. */
870 set_spe_registers (int tid
, struct gdb_evrregset_t
*evrregset
)
872 if (have_ptrace_getsetevrregs
)
874 if (ptrace (PTRACE_SETEVRREGS
, tid
, 0, evrregset
) >= 0)
878 /* EIO means that the PTRACE_SETEVRREGS request isn't
879 supported; we fail silently, and don't try the call
882 have_ptrace_getsetevrregs
= 0;
884 /* Anything else needs to be reported. */
885 perror_with_name (_("Unable to set SPE registers"));
890 /* Write GDB's value for the SPE-specific raw register REGNO to TID.
891 If REGNO is -1, write the values of all the SPE-specific
894 store_spe_register (const struct regcache
*regcache
, int tid
, int regno
)
896 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
897 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
898 struct gdb_evrregset_t evrregs
;
900 gdb_assert (sizeof (evrregs
.evr
[0])
901 == register_size (gdbarch
, tdep
->ppc_ev0_upper_regnum
));
902 gdb_assert (sizeof (evrregs
.acc
)
903 == register_size (gdbarch
, tdep
->ppc_acc_regnum
));
904 gdb_assert (sizeof (evrregs
.spefscr
)
905 == register_size (gdbarch
, tdep
->ppc_spefscr_regnum
));
908 /* Since we're going to write out every register, the code below
909 should store to every field of evrregs; if that doesn't happen,
910 make it obvious by initializing it with suspicious values. */
911 memset (&evrregs
, 42, sizeof (evrregs
));
913 /* We can only read and write the entire EVR register set at a
914 time, so to write just a single register, we do a
915 read-modify-write maneuver. */
916 get_spe_registers (tid
, &evrregs
);
922 for (i
= 0; i
< ppc_num_gprs
; i
++)
923 regcache_raw_collect (regcache
,
924 tdep
->ppc_ev0_upper_regnum
+ i
,
927 else if (tdep
->ppc_ev0_upper_regnum
<= regno
928 && regno
< tdep
->ppc_ev0_upper_regnum
+ ppc_num_gprs
)
929 regcache_raw_collect (regcache
, regno
,
930 &evrregs
.evr
[regno
- tdep
->ppc_ev0_upper_regnum
]);
933 || regno
== tdep
->ppc_acc_regnum
)
934 regcache_raw_collect (regcache
,
935 tdep
->ppc_acc_regnum
,
939 || regno
== tdep
->ppc_spefscr_regnum
)
940 regcache_raw_collect (regcache
,
941 tdep
->ppc_spefscr_regnum
,
944 /* Write back the modified register set. */
945 set_spe_registers (tid
, &evrregs
);
949 store_register (const struct regcache
*regcache
, int tid
, int regno
)
951 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
952 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
953 /* This isn't really an address. But ptrace thinks of it as one. */
954 CORE_ADDR regaddr
= ppc_register_u_addr (gdbarch
, regno
);
956 size_t bytes_to_transfer
;
957 char buf
[MAX_REGISTER_SIZE
];
959 if (altivec_register_p (gdbarch
, regno
))
961 store_altivec_register (regcache
, tid
, regno
);
964 if (vsx_register_p (gdbarch
, regno
))
966 store_vsx_register (regcache
, tid
, regno
);
969 else if (spe_register_p (gdbarch
, regno
))
971 store_spe_register (regcache
, tid
, regno
);
978 /* First collect the register. Keep in mind that the regcache's
979 idea of the register's size may not be a multiple of sizeof
981 memset (buf
, 0, sizeof buf
);
982 bytes_to_transfer
= align_up (register_size (gdbarch
, regno
), sizeof (long));
983 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
985 /* Little-endian values always sit at the left end of the buffer. */
986 regcache_raw_collect (regcache
, regno
, buf
);
988 else if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
990 /* Big-endian values sit at the right end of the buffer. */
991 size_t padding
= (bytes_to_transfer
- register_size (gdbarch
, regno
));
992 regcache_raw_collect (regcache
, regno
, buf
+ padding
);
995 for (i
= 0; i
< bytes_to_transfer
; i
+= sizeof (long))
998 ptrace (PTRACE_POKEUSER
, tid
, (PTRACE_TYPE_ARG3
) regaddr
,
1000 regaddr
+= sizeof (long);
1003 && (regno
== tdep
->ppc_fpscr_regnum
1004 || regno
== PPC_ORIG_R3_REGNUM
1005 || regno
== PPC_TRAP_REGNUM
))
1007 /* Some older kernel versions don't allow fpscr, orig_r3
1008 or trap to be written. */
1015 sprintf (message
, "writing register %s (#%d)",
1016 gdbarch_register_name (gdbarch
, regno
), regno
);
1017 perror_with_name (message
);
1023 fill_vsxregset (const struct regcache
*regcache
, gdb_vsxregset_t
*vsxregsetp
)
1026 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1027 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1028 int vsxregsize
= register_size (gdbarch
, tdep
->ppc_vsr0_upper_regnum
);
1030 for (i
= 0; i
< ppc_num_vshrs
; i
++)
1031 regcache_raw_collect (regcache
, tdep
->ppc_vsr0_upper_regnum
+ i
,
1032 *vsxregsetp
+ i
* vsxregsize
);
1036 fill_vrregset (const struct regcache
*regcache
, gdb_vrregset_t
*vrregsetp
)
1039 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1040 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1041 int num_of_vrregs
= tdep
->ppc_vrsave_regnum
- tdep
->ppc_vr0_regnum
+ 1;
1042 int vrregsize
= register_size (gdbarch
, tdep
->ppc_vr0_regnum
);
1043 int offset
= vrregsize
- register_size (gdbarch
, tdep
->ppc_vrsave_regnum
);
1045 for (i
= 0; i
< num_of_vrregs
; i
++)
1047 /* The last 2 registers of this set are only 32 bit long, not
1048 128, but only VSCR is fetched as a 16 bytes quantity. */
1049 if (i
== (num_of_vrregs
- 2))
1050 regcache_raw_collect (regcache
, tdep
->ppc_vr0_regnum
+ i
,
1051 *vrregsetp
+ i
* vrregsize
+ offset
);
1053 regcache_raw_collect (regcache
, tdep
->ppc_vr0_regnum
+ i
,
1054 *vrregsetp
+ i
* vrregsize
);
1059 store_vsx_registers (const struct regcache
*regcache
, int tid
)
1062 gdb_vsxregset_t regs
;
1064 ret
= ptrace (PTRACE_GETVSXREGS
, tid
, 0, ®s
);
1069 have_ptrace_getsetvsxregs
= 0;
1072 perror_with_name (_("Couldn't get VSX registers"));
1075 fill_vsxregset (regcache
, ®s
);
1077 if (ptrace (PTRACE_SETVSXREGS
, tid
, 0, ®s
) < 0)
1078 perror_with_name (_("Couldn't write VSX registers"));
1082 store_altivec_registers (const struct regcache
*regcache
, int tid
)
1085 gdb_vrregset_t regs
;
1087 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
1092 have_ptrace_getvrregs
= 0;
1095 perror_with_name (_("Couldn't get AltiVec registers"));
1098 fill_vrregset (regcache
, ®s
);
1100 if (ptrace (PTRACE_SETVRREGS
, tid
, 0, ®s
) < 0)
1101 perror_with_name (_("Couldn't write AltiVec registers"));
1104 /* This function actually issues the request to ptrace, telling
1105 it to store all general-purpose registers present in the specified
1108 If the ptrace request does not exist, this function returns 0
1109 and properly sets the have_ptrace_* flag. If the request fails,
1110 this function calls perror_with_name. Otherwise, if the request
1111 succeeds, then the regcache is stored and 1 is returned. */
1113 store_all_gp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1115 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1116 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1117 gdb_gregset_t gregset
;
1119 if (ptrace (PTRACE_GETREGS
, tid
, 0, (void *) &gregset
) < 0)
1123 have_ptrace_getsetregs
= 0;
1126 perror_with_name (_("Couldn't get general-purpose registers."));
1129 fill_gregset (regcache
, &gregset
, regno
);
1131 if (ptrace (PTRACE_SETREGS
, tid
, 0, (void *) &gregset
) < 0)
1135 have_ptrace_getsetregs
= 0;
1138 perror_with_name (_("Couldn't set general-purpose registers."));
1144 /* This is a wrapper for the store_all_gp_regs function. It is
1145 responsible for verifying if this target has the ptrace request
1146 that can be used to store all general-purpose registers at one
1147 shot. If it doesn't, then we should store them using the
1148 old-fashioned way, which is to iterate over the registers and
1149 store them one by one. */
1151 store_gp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1153 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1154 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1157 if (have_ptrace_getsetregs
)
1158 if (store_all_gp_regs (regcache
, tid
, regno
))
1161 /* If we hit this point, it doesn't really matter which
1162 architecture we are using. We just need to store the
1163 registers in the "old-fashioned way". */
1164 for (i
= 0; i
< ppc_num_gprs
; i
++)
1165 store_register (regcache
, tid
, tdep
->ppc_gp0_regnum
+ i
);
1168 /* This function actually issues the request to ptrace, telling
1169 it to store all floating-point registers present in the specified
1172 If the ptrace request does not exist, this function returns 0
1173 and properly sets the have_ptrace_* flag. If the request fails,
1174 this function calls perror_with_name. Otherwise, if the request
1175 succeeds, then the regcache is stored and 1 is returned. */
1177 store_all_fp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1179 gdb_fpregset_t fpregs
;
1181 if (ptrace (PTRACE_GETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
1185 have_ptrace_getsetfpregs
= 0;
1188 perror_with_name (_("Couldn't get floating-point registers."));
1191 fill_fpregset (regcache
, &fpregs
, regno
);
1193 if (ptrace (PTRACE_SETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
1197 have_ptrace_getsetfpregs
= 0;
1200 perror_with_name (_("Couldn't set floating-point registers."));
1206 /* This is a wrapper for the store_all_fp_regs function. It is
1207 responsible for verifying if this target has the ptrace request
1208 that can be used to store all floating-point registers at one
1209 shot. If it doesn't, then we should store them using the
1210 old-fashioned way, which is to iterate over the registers and
1211 store them one by one. */
1213 store_fp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1215 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1216 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1219 if (have_ptrace_getsetfpregs
)
1220 if (store_all_fp_regs (regcache
, tid
, regno
))
1223 /* If we hit this point, it doesn't really matter which
1224 architecture we are using. We just need to store the
1225 registers in the "old-fashioned way". */
1226 for (i
= 0; i
< ppc_num_fprs
; i
++)
1227 store_register (regcache
, tid
, tdep
->ppc_fp0_regnum
+ i
);
1231 store_ppc_registers (const struct regcache
*regcache
, int tid
)
1234 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1235 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1237 store_gp_regs (regcache
, tid
, -1);
1238 if (tdep
->ppc_fp0_regnum
>= 0)
1239 store_fp_regs (regcache
, tid
, -1);
1240 store_register (regcache
, tid
, gdbarch_pc_regnum (gdbarch
));
1241 if (tdep
->ppc_ps_regnum
!= -1)
1242 store_register (regcache
, tid
, tdep
->ppc_ps_regnum
);
1243 if (tdep
->ppc_cr_regnum
!= -1)
1244 store_register (regcache
, tid
, tdep
->ppc_cr_regnum
);
1245 if (tdep
->ppc_lr_regnum
!= -1)
1246 store_register (regcache
, tid
, tdep
->ppc_lr_regnum
);
1247 if (tdep
->ppc_ctr_regnum
!= -1)
1248 store_register (regcache
, tid
, tdep
->ppc_ctr_regnum
);
1249 if (tdep
->ppc_xer_regnum
!= -1)
1250 store_register (regcache
, tid
, tdep
->ppc_xer_regnum
);
1251 if (tdep
->ppc_mq_regnum
!= -1)
1252 store_register (regcache
, tid
, tdep
->ppc_mq_regnum
);
1253 if (tdep
->ppc_fpscr_regnum
!= -1)
1254 store_register (regcache
, tid
, tdep
->ppc_fpscr_regnum
);
1255 if (ppc_linux_trap_reg_p (gdbarch
))
1257 store_register (regcache
, tid
, PPC_ORIG_R3_REGNUM
);
1258 store_register (regcache
, tid
, PPC_TRAP_REGNUM
);
1260 if (have_ptrace_getvrregs
)
1261 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
1262 store_altivec_registers (regcache
, tid
);
1263 if (have_ptrace_getsetvsxregs
)
1264 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
1265 store_vsx_registers (regcache
, tid
);
1266 if (tdep
->ppc_ev0_upper_regnum
>= 0)
1267 store_spe_register (regcache
, tid
, -1);
1271 ppc_linux_check_watch_resources (int type
, int cnt
, int ot
)
1274 ptid_t ptid
= inferior_ptid
;
1276 /* DABR (data address breakpoint register) is optional for PPC variants.
1277 Some variants have one DABR, others have none. So CNT can't be larger
1282 /* We need to know whether ptrace supports PTRACE_SET_DEBUGREG and whether
1283 the target has DABR. If either answer is no, the ptrace call will
1284 return -1. Fail in that case. */
1285 tid
= TIDGET (ptid
);
1287 tid
= PIDGET (ptid
);
1289 if (ptrace (PTRACE_SET_DEBUGREG
, tid
, 0, 0) == -1)
1294 /* Fetch the AT_HWCAP entry from the aux vector. */
1295 unsigned long ppc_linux_get_hwcap (void)
1299 if (target_auxv_search (¤t_target
, AT_HWCAP
, &field
))
1300 return (unsigned long) field
;
1306 ppc_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
1308 /* Handle sub-8-byte quantities. */
1312 /* addr+len must fall in the 8 byte watchable region for DABR-based
1313 processors. DAC-based processors, like the PowerPC 440, will use
1314 addresses aligned to 4-bytes due to the way the read/write flags are
1315 passed at the moment. */
1316 if (((ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE
)
1317 && (addr
+ len
) > (addr
& ~3) + 4)
1318 || (addr
+ len
) > (addr
& ~7) + 8)
1324 /* The cached DABR value, to install in new threads. */
1325 static long saved_dabr_value
;
1327 /* Set a watchpoint of type TYPE at address ADDR. */
1329 ppc_linux_insert_watchpoint (CORE_ADDR addr
, int len
, int rw
)
1331 struct lwp_info
*lp
;
1334 long read_mode
, write_mode
;
1336 if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE
)
1338 /* PowerPC 440 requires only the read/write flags to be passed
1345 /* PowerPC 970 and other DABR-based processors are required to pass
1346 the Breakpoint Translation bit together with the flags. */
1351 dabr_value
= addr
& ~(read_mode
| write_mode
);
1355 /* Set read and translate bits. */
1356 dabr_value
|= read_mode
;
1359 /* Set write and translate bits. */
1360 dabr_value
|= write_mode
;
1363 /* Set read, write and translate bits. */
1364 dabr_value
|= read_mode
| write_mode
;
1368 saved_dabr_value
= dabr_value
;
1371 if (ptrace (PTRACE_SET_DEBUGREG
, TIDGET (ptid
), 0, saved_dabr_value
) < 0)
1378 ppc_linux_remove_watchpoint (CORE_ADDR addr
, int len
, int rw
)
1380 struct lwp_info
*lp
;
1382 long dabr_value
= 0;
1384 saved_dabr_value
= 0;
1386 if (ptrace (PTRACE_SET_DEBUGREG
, TIDGET (ptid
), 0, saved_dabr_value
) < 0)
1392 ppc_linux_new_thread (ptid_t ptid
)
1394 ptrace (PTRACE_SET_DEBUGREG
, TIDGET (ptid
), 0, saved_dabr_value
);
1398 ppc_linux_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
1400 struct siginfo
*siginfo_p
;
1402 siginfo_p
= linux_nat_get_siginfo (inferior_ptid
);
1404 if (siginfo_p
->si_signo
!= SIGTRAP
1405 || (siginfo_p
->si_code
& 0xffff) != 0x0004 /* TRAP_HWBKPT */)
1408 *addr_p
= (CORE_ADDR
) (uintptr_t) siginfo_p
->si_addr
;
1413 ppc_linux_stopped_by_watchpoint (void)
1416 return ppc_linux_stopped_data_address (¤t_target
, &addr
);
1420 ppc_linux_watchpoint_addr_within_range (struct target_ops
*target
,
1422 CORE_ADDR start
, int length
)
1426 if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE
)
1433 /* Check whether [start, start+length-1] intersects [addr, addr+mask]. */
1434 return start
<= addr
+ mask
&& start
+ length
- 1 >= addr
;
1438 ppc_linux_store_inferior_registers (struct target_ops
*ops
,
1439 struct regcache
*regcache
, int regno
)
1441 /* Overload thread id onto process id */
1442 int tid
= TIDGET (inferior_ptid
);
1444 /* No thread id, just use process id */
1446 tid
= PIDGET (inferior_ptid
);
1449 store_register (regcache
, tid
, regno
);
1451 store_ppc_registers (regcache
, tid
);
1454 /* Functions for transferring registers between a gregset_t or fpregset_t
1455 (see sys/ucontext.h) and gdb's regcache. The word size is that used
1456 by the ptrace interface, not the current program's ABI. eg. If a
1457 powerpc64-linux gdb is being used to debug a powerpc32-linux app, we
1458 read or write 64-bit gregsets. This is to suit the host libthread_db. */
1461 supply_gregset (struct regcache
*regcache
, const gdb_gregset_t
*gregsetp
)
1463 const struct regset
*regset
= ppc_linux_gregset (sizeof (long));
1465 ppc_supply_gregset (regset
, regcache
, -1, gregsetp
, sizeof (*gregsetp
));
1469 fill_gregset (const struct regcache
*regcache
,
1470 gdb_gregset_t
*gregsetp
, int regno
)
1472 const struct regset
*regset
= ppc_linux_gregset (sizeof (long));
1475 memset (gregsetp
, 0, sizeof (*gregsetp
));
1476 ppc_collect_gregset (regset
, regcache
, regno
, gregsetp
, sizeof (*gregsetp
));
1480 supply_fpregset (struct regcache
*regcache
, const gdb_fpregset_t
* fpregsetp
)
1482 const struct regset
*regset
= ppc_linux_fpregset ();
1484 ppc_supply_fpregset (regset
, regcache
, -1,
1485 fpregsetp
, sizeof (*fpregsetp
));
1489 fill_fpregset (const struct regcache
*regcache
,
1490 gdb_fpregset_t
*fpregsetp
, int regno
)
1492 const struct regset
*regset
= ppc_linux_fpregset ();
1494 ppc_collect_fpregset (regset
, regcache
, regno
,
1495 fpregsetp
, sizeof (*fpregsetp
));
1499 ppc_linux_target_wordsize (void)
1503 /* Check for 64-bit inferior process. This is the case when the host is
1504 64-bit, and in addition the top bit of the MSR register is set. */
1505 #ifdef __powerpc64__
1508 int tid
= TIDGET (inferior_ptid
);
1510 tid
= PIDGET (inferior_ptid
);
1513 msr
= (long) ptrace (PTRACE_PEEKUSER
, tid
, PT_MSR
* 8, 0);
1514 if (errno
== 0 && msr
< 0)
1522 ppc_linux_auxv_parse (struct target_ops
*ops
, gdb_byte
**readptr
,
1523 gdb_byte
*endptr
, CORE_ADDR
*typep
, CORE_ADDR
*valp
)
1525 int sizeof_auxv_field
= ppc_linux_target_wordsize ();
1526 gdb_byte
*ptr
= *readptr
;
1531 if (endptr
- ptr
< sizeof_auxv_field
* 2)
1534 *typep
= extract_unsigned_integer (ptr
, sizeof_auxv_field
);
1535 ptr
+= sizeof_auxv_field
;
1536 *valp
= extract_unsigned_integer (ptr
, sizeof_auxv_field
);
1537 ptr
+= sizeof_auxv_field
;
1543 static const struct target_desc
*
1544 ppc_linux_read_description (struct target_ops
*ops
)
1550 int tid
= TIDGET (inferior_ptid
);
1552 tid
= PIDGET (inferior_ptid
);
1554 if (have_ptrace_getsetevrregs
)
1556 struct gdb_evrregset_t evrregset
;
1558 if (ptrace (PTRACE_GETEVRREGS
, tid
, 0, &evrregset
) >= 0)
1559 return tdesc_powerpc_e500l
;
1561 /* EIO means that the PTRACE_GETEVRREGS request isn't supported.
1562 Anything else needs to be reported. */
1563 else if (errno
!= EIO
)
1564 perror_with_name (_("Unable to fetch SPE registers"));
1567 if (have_ptrace_getsetvsxregs
)
1569 gdb_vsxregset_t vsxregset
;
1571 if (ptrace (PTRACE_GETVSXREGS
, tid
, 0, &vsxregset
) >= 0)
1574 /* EIO means that the PTRACE_GETVSXREGS request isn't supported.
1575 Anything else needs to be reported. */
1576 else if (errno
!= EIO
)
1577 perror_with_name (_("Unable to fetch VSX registers"));
1580 if (have_ptrace_getvrregs
)
1582 gdb_vrregset_t vrregset
;
1584 if (ptrace (PTRACE_GETVRREGS
, tid
, 0, &vrregset
) >= 0)
1587 /* EIO means that the PTRACE_GETVRREGS request isn't supported.
1588 Anything else needs to be reported. */
1589 else if (errno
!= EIO
)
1590 perror_with_name (_("Unable to fetch AltiVec registers"));
1593 /* Power ISA 2.05 (implemented by Power 6 and newer processors) increases
1594 the FPSCR from 32 bits to 64 bits. Even though Power 7 supports this
1595 ISA version, it doesn't have PPC_FEATURE_ARCH_2_05 set, only
1596 PPC_FEATURE_ARCH_2_06. Since for now the only bits used in the higher
1597 half of the register are for Decimal Floating Point, we check if that
1598 feature is available to decide the size of the FPSCR. */
1599 if (ppc_linux_get_hwcap () & PPC_FEATURE_HAS_DFP
)
1602 if (ppc_linux_target_wordsize () == 8)
1605 return isa205
? tdesc_powerpc_isa205_vsx64l
: tdesc_powerpc_vsx64l
;
1607 return isa205
? tdesc_powerpc_isa205_altivec64l
: tdesc_powerpc_altivec64l
;
1609 return isa205
? tdesc_powerpc_isa205_64l
: tdesc_powerpc_64l
;
1613 return isa205
? tdesc_powerpc_isa205_vsx32l
: tdesc_powerpc_vsx32l
;
1615 return isa205
? tdesc_powerpc_isa205_altivec32l
: tdesc_powerpc_altivec32l
;
1617 return isa205
? tdesc_powerpc_isa205_32l
: tdesc_powerpc_32l
;
1620 void _initialize_ppc_linux_nat (void);
1623 _initialize_ppc_linux_nat (void)
1625 struct target_ops
*t
;
1627 /* Fill in the generic GNU/Linux methods. */
1628 t
= linux_target ();
1630 /* Add our register access methods. */
1631 t
->to_fetch_registers
= ppc_linux_fetch_inferior_registers
;
1632 t
->to_store_registers
= ppc_linux_store_inferior_registers
;
1634 /* Add our watchpoint methods. */
1635 t
->to_can_use_hw_breakpoint
= ppc_linux_check_watch_resources
;
1636 t
->to_region_ok_for_hw_watchpoint
= ppc_linux_region_ok_for_hw_watchpoint
;
1637 t
->to_insert_watchpoint
= ppc_linux_insert_watchpoint
;
1638 t
->to_remove_watchpoint
= ppc_linux_remove_watchpoint
;
1639 t
->to_stopped_by_watchpoint
= ppc_linux_stopped_by_watchpoint
;
1640 t
->to_stopped_data_address
= ppc_linux_stopped_data_address
;
1641 t
->to_watchpoint_addr_within_range
= ppc_linux_watchpoint_addr_within_range
;
1643 t
->to_read_description
= ppc_linux_read_description
;
1644 t
->to_auxv_parse
= ppc_linux_auxv_parse
;
1646 /* Register the target. */
1647 linux_nat_add_target (t
);
1648 linux_nat_set_new_thread (t
, ppc_linux_new_thread
);