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, 2010 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_CELL
64 #define PPC_FEATURE_CELL 0x00010000
66 #ifndef PPC_FEATURE_BOOKE
67 #define PPC_FEATURE_BOOKE 0x00008000
69 #ifndef PPC_FEATURE_HAS_DFP
70 #define PPC_FEATURE_HAS_DFP 0x00000400 /* Decimal Floating Point. */
73 /* Glibc's headers don't define PTRACE_GETVRREGS so we cannot use a
74 configure time check. Some older glibc's (for instance 2.2.1)
75 don't have a specific powerpc version of ptrace.h, and fall back on
76 a generic one. In such cases, sys/ptrace.h defines
77 PTRACE_GETFPXREGS and PTRACE_SETFPXREGS to the same numbers that
78 ppc kernel's asm/ptrace.h defines PTRACE_GETVRREGS and
79 PTRACE_SETVRREGS to be. This also makes a configury check pretty
82 /* These definitions should really come from the glibc header files,
83 but Glibc doesn't know about the vrregs yet. */
84 #ifndef PTRACE_GETVRREGS
85 #define PTRACE_GETVRREGS 18
86 #define PTRACE_SETVRREGS 19
89 /* PTRACE requests for POWER7 VSX registers. */
90 #ifndef PTRACE_GETVSXREGS
91 #define PTRACE_GETVSXREGS 27
92 #define PTRACE_SETVSXREGS 28
95 /* Similarly for the ptrace requests for getting / setting the SPE
96 registers (ev0 -- ev31, acc, and spefscr). See the description of
97 gdb_evrregset_t for details. */
98 #ifndef PTRACE_GETEVRREGS
99 #define PTRACE_GETEVRREGS 20
100 #define PTRACE_SETEVRREGS 21
103 /* Similarly for the hardware watchpoint support. */
104 #ifndef PTRACE_GET_DEBUGREG
105 #define PTRACE_GET_DEBUGREG 25
107 #ifndef PTRACE_SET_DEBUGREG
108 #define PTRACE_SET_DEBUGREG 26
110 #ifndef PTRACE_GETSIGINFO
111 #define PTRACE_GETSIGINFO 0x4202
114 /* Similarly for the general-purpose (gp0 -- gp31)
115 and floating-point registers (fp0 -- fp31). */
116 #ifndef PTRACE_GETREGS
117 #define PTRACE_GETREGS 12
119 #ifndef PTRACE_SETREGS
120 #define PTRACE_SETREGS 13
122 #ifndef PTRACE_GETFPREGS
123 #define PTRACE_GETFPREGS 14
125 #ifndef PTRACE_SETFPREGS
126 #define PTRACE_SETFPREGS 15
129 /* This oddity is because the Linux kernel defines elf_vrregset_t as
130 an array of 33 16 bytes long elements. I.e. it leaves out vrsave.
131 However the PTRACE_GETVRREGS and PTRACE_SETVRREGS requests return
132 the vrsave as an extra 4 bytes at the end. I opted for creating a
133 flat array of chars, so that it is easier to manipulate for gdb.
135 There are 32 vector registers 16 bytes longs, plus a VSCR register
136 which is only 4 bytes long, but is fetched as a 16 bytes
137 quantity. Up to here we have the elf_vrregset_t structure.
138 Appended to this there is space for the VRSAVE register: 4 bytes.
139 Even though this vrsave register is not included in the regset
140 typedef, it is handled by the ptrace requests.
142 Note that GNU/Linux doesn't support little endian PPC hardware,
143 therefore the offset at which the real value of the VSCR register
144 is located will be always 12 bytes.
146 The layout is like this (where x is the actual value of the vscr reg): */
150 |.|.|.|.|.....|.|.|.|.||.|.|.|x||.|
151 <-------> <-------><-------><->
156 #define SIZEOF_VRREGS 33*16+4
158 typedef char gdb_vrregset_t
[SIZEOF_VRREGS
];
160 /* This is the layout of the POWER7 VSX registers and the way they overlap
161 with the existing FPR and VMX registers.
163 VSR doubleword 0 VSR doubleword 1
164 ----------------------------------------------------------------
166 ----------------------------------------------------------------
168 ----------------------------------------------------------------
171 ----------------------------------------------------------------
172 VSR[30] | FPR[30] | |
173 ----------------------------------------------------------------
174 VSR[31] | FPR[31] | |
175 ----------------------------------------------------------------
177 ----------------------------------------------------------------
179 ----------------------------------------------------------------
182 ----------------------------------------------------------------
184 ----------------------------------------------------------------
186 ----------------------------------------------------------------
188 VSX has 64 128bit registers. The first 32 registers overlap with
189 the FP registers (doubleword 0) and hence extend them with additional
190 64 bits (doubleword 1). The other 32 regs overlap with the VMX
192 #define SIZEOF_VSXREGS 32*8
194 typedef char gdb_vsxregset_t
[SIZEOF_VSXREGS
];
196 /* On PPC processors that support the the Signal Processing Extension
197 (SPE) APU, the general-purpose registers are 64 bits long.
198 However, the ordinary Linux kernel PTRACE_PEEKUSER / PTRACE_POKEUSER
199 ptrace calls only access the lower half of each register, to allow
200 them to behave the same way they do on non-SPE systems. There's a
201 separate pair of calls, PTRACE_GETEVRREGS / PTRACE_SETEVRREGS, that
202 read and write the top halves of all the general-purpose registers
203 at once, along with some SPE-specific registers.
205 GDB itself continues to claim the general-purpose registers are 32
206 bits long. It has unnamed raw registers that hold the upper halves
207 of the gprs, and the the full 64-bit SIMD views of the registers,
208 'ev0' -- 'ev31', are pseudo-registers that splice the top and
209 bottom halves together.
211 This is the structure filled in by PTRACE_GETEVRREGS and written to
212 the inferior's registers by PTRACE_SETEVRREGS. */
213 struct gdb_evrregset_t
215 unsigned long evr
[32];
216 unsigned long long acc
;
217 unsigned long spefscr
;
220 /* Non-zero if our kernel may support the PTRACE_GETVSXREGS and
221 PTRACE_SETVSXREGS requests, for reading and writing the VSX
222 POWER7 registers 0 through 31. Zero if we've tried one of them and
223 gotten an error. Note that VSX registers 32 through 63 overlap
224 with VR registers 0 through 31. */
225 int have_ptrace_getsetvsxregs
= 1;
227 /* Non-zero if our kernel may support the PTRACE_GETVRREGS and
228 PTRACE_SETVRREGS requests, for reading and writing the Altivec
229 registers. Zero if we've tried one of them and gotten an
231 int have_ptrace_getvrregs
= 1;
233 /* Non-zero if our kernel may support the PTRACE_GETEVRREGS and
234 PTRACE_SETEVRREGS requests, for reading and writing the SPE
235 registers. Zero if we've tried one of them and gotten an
237 int have_ptrace_getsetevrregs
= 1;
239 /* Non-zero if our kernel may support the PTRACE_GETREGS and
240 PTRACE_SETREGS requests, for reading and writing the
241 general-purpose registers. Zero if we've tried one of
242 them and gotten an error. */
243 int have_ptrace_getsetregs
= 1;
245 /* Non-zero if our kernel may support the PTRACE_GETFPREGS and
246 PTRACE_SETFPREGS requests, for reading and writing the
247 floating-pointers registers. Zero if we've tried one of
248 them and gotten an error. */
249 int have_ptrace_getsetfpregs
= 1;
252 /* registers layout, as presented by the ptrace interface:
253 PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
254 PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15,
255 PT_R16, PT_R17, PT_R18, PT_R19, PT_R20, PT_R21, PT_R22, PT_R23,
256 PT_R24, PT_R25, PT_R26, PT_R27, PT_R28, PT_R29, PT_R30, PT_R31,
257 PT_FPR0, PT_FPR0 + 2, PT_FPR0 + 4, PT_FPR0 + 6, PT_FPR0 + 8, PT_FPR0 + 10, PT_FPR0 + 12, PT_FPR0 + 14,
258 PT_FPR0 + 16, PT_FPR0 + 18, PT_FPR0 + 20, PT_FPR0 + 22, PT_FPR0 + 24, PT_FPR0 + 26, PT_FPR0 + 28, PT_FPR0 + 30,
259 PT_FPR0 + 32, PT_FPR0 + 34, PT_FPR0 + 36, PT_FPR0 + 38, PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46,
260 PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54, PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62,
261 PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */
265 ppc_register_u_addr (struct gdbarch
*gdbarch
, int regno
)
268 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
269 /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace
270 interface, and not the wordsize of the program's ABI. */
271 int wordsize
= sizeof (long);
273 /* General purpose registers occupy 1 slot each in the buffer */
274 if (regno
>= tdep
->ppc_gp0_regnum
275 && regno
< tdep
->ppc_gp0_regnum
+ ppc_num_gprs
)
276 u_addr
= ((regno
- tdep
->ppc_gp0_regnum
+ PT_R0
) * wordsize
);
278 /* Floating point regs: eight bytes each in both 32- and 64-bit
279 ptrace interfaces. Thus, two slots each in 32-bit interface, one
280 slot each in 64-bit interface. */
281 if (tdep
->ppc_fp0_regnum
>= 0
282 && regno
>= tdep
->ppc_fp0_regnum
283 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
284 u_addr
= (PT_FPR0
* wordsize
) + ((regno
- tdep
->ppc_fp0_regnum
) * 8);
286 /* UISA special purpose registers: 1 slot each */
287 if (regno
== gdbarch_pc_regnum (gdbarch
))
288 u_addr
= PT_NIP
* wordsize
;
289 if (regno
== tdep
->ppc_lr_regnum
)
290 u_addr
= PT_LNK
* wordsize
;
291 if (regno
== tdep
->ppc_cr_regnum
)
292 u_addr
= PT_CCR
* wordsize
;
293 if (regno
== tdep
->ppc_xer_regnum
)
294 u_addr
= PT_XER
* wordsize
;
295 if (regno
== tdep
->ppc_ctr_regnum
)
296 u_addr
= PT_CTR
* wordsize
;
298 if (regno
== tdep
->ppc_mq_regnum
)
299 u_addr
= PT_MQ
* wordsize
;
301 if (regno
== tdep
->ppc_ps_regnum
)
302 u_addr
= PT_MSR
* wordsize
;
303 if (regno
== PPC_ORIG_R3_REGNUM
)
304 u_addr
= PT_ORIG_R3
* wordsize
;
305 if (regno
== PPC_TRAP_REGNUM
)
306 u_addr
= PT_TRAP
* wordsize
;
307 if (tdep
->ppc_fpscr_regnum
>= 0
308 && regno
== tdep
->ppc_fpscr_regnum
)
310 /* NOTE: cagney/2005-02-08: On some 64-bit GNU/Linux systems the
311 kernel headers incorrectly contained the 32-bit definition of
312 PT_FPSCR. For the 32-bit definition, floating-point
313 registers occupy two 32-bit "slots", and the FPSCR lives in
314 the second half of such a slot-pair (hence +1). For 64-bit,
315 the FPSCR instead occupies the full 64-bit 2-word-slot and
316 hence no adjustment is necessary. Hack around this. */
317 if (wordsize
== 8 && PT_FPSCR
== (48 + 32 + 1))
318 u_addr
= (48 + 32) * wordsize
;
319 /* If the FPSCR is 64-bit wide, we need to fetch the whole 64-bit
320 slot and not just its second word. The PT_FPSCR supplied when
321 GDB is compiled as a 32-bit app doesn't reflect this. */
322 else if (wordsize
== 4 && register_size (gdbarch
, regno
) == 8
323 && PT_FPSCR
== (48 + 2*32 + 1))
324 u_addr
= (48 + 2*32) * wordsize
;
326 u_addr
= PT_FPSCR
* wordsize
;
331 /* The Linux kernel ptrace interface for POWER7 VSX registers uses the
332 registers set mechanism, as opposed to the interface for all the
333 other registers, that stores/fetches each register individually. */
335 fetch_vsx_register (struct regcache
*regcache
, int tid
, int regno
)
338 gdb_vsxregset_t regs
;
339 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
340 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
341 int vsxregsize
= register_size (gdbarch
, tdep
->ppc_vsr0_upper_regnum
);
343 ret
= ptrace (PTRACE_GETVSXREGS
, tid
, 0, ®s
);
348 have_ptrace_getsetvsxregs
= 0;
351 perror_with_name (_("Unable to fetch VSX register"));
354 regcache_raw_supply (regcache
, regno
,
355 regs
+ (regno
- tdep
->ppc_vsr0_upper_regnum
)
359 /* The Linux kernel ptrace interface for AltiVec registers uses the
360 registers set mechanism, as opposed to the interface for all the
361 other registers, that stores/fetches each register individually. */
363 fetch_altivec_register (struct regcache
*regcache
, int tid
, int regno
)
368 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
369 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
370 int vrregsize
= register_size (gdbarch
, tdep
->ppc_vr0_regnum
);
372 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
377 have_ptrace_getvrregs
= 0;
380 perror_with_name (_("Unable to fetch AltiVec register"));
383 /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes
384 long on the hardware. We deal only with the lower 4 bytes of the
385 vector. VRSAVE is at the end of the array in a 4 bytes slot, so
386 there is no need to define an offset for it. */
387 if (regno
== (tdep
->ppc_vrsave_regnum
- 1))
388 offset
= vrregsize
- register_size (gdbarch
, tdep
->ppc_vrsave_regnum
);
390 regcache_raw_supply (regcache
, regno
,
391 regs
+ (regno
- tdep
->ppc_vr0_regnum
) * vrregsize
+ offset
);
394 /* Fetch the top 32 bits of TID's general-purpose registers and the
395 SPE-specific registers, and place the results in EVRREGSET. If we
396 don't support PTRACE_GETEVRREGS, then just fill EVRREGSET with
399 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
400 PTRACE_SETEVRREGS requests are supported is isolated here, and in
401 set_spe_registers. */
403 get_spe_registers (int tid
, struct gdb_evrregset_t
*evrregset
)
405 if (have_ptrace_getsetevrregs
)
407 if (ptrace (PTRACE_GETEVRREGS
, tid
, 0, evrregset
) >= 0)
411 /* EIO means that the PTRACE_GETEVRREGS request isn't supported;
412 we just return zeros. */
414 have_ptrace_getsetevrregs
= 0;
416 /* Anything else needs to be reported. */
417 perror_with_name (_("Unable to fetch SPE registers"));
421 memset (evrregset
, 0, sizeof (*evrregset
));
424 /* Supply values from TID for SPE-specific raw registers: the upper
425 halves of the GPRs, the accumulator, and the spefscr. REGNO must
426 be the number of an upper half register, acc, spefscr, or -1 to
427 supply the values of all registers. */
429 fetch_spe_register (struct regcache
*regcache
, int tid
, int regno
)
431 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
432 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
433 struct gdb_evrregset_t evrregs
;
435 gdb_assert (sizeof (evrregs
.evr
[0])
436 == register_size (gdbarch
, tdep
->ppc_ev0_upper_regnum
));
437 gdb_assert (sizeof (evrregs
.acc
)
438 == register_size (gdbarch
, tdep
->ppc_acc_regnum
));
439 gdb_assert (sizeof (evrregs
.spefscr
)
440 == register_size (gdbarch
, tdep
->ppc_spefscr_regnum
));
442 get_spe_registers (tid
, &evrregs
);
448 for (i
= 0; i
< ppc_num_gprs
; i
++)
449 regcache_raw_supply (regcache
, tdep
->ppc_ev0_upper_regnum
+ i
,
452 else if (tdep
->ppc_ev0_upper_regnum
<= regno
453 && regno
< tdep
->ppc_ev0_upper_regnum
+ ppc_num_gprs
)
454 regcache_raw_supply (regcache
, regno
,
455 &evrregs
.evr
[regno
- tdep
->ppc_ev0_upper_regnum
]);
458 || regno
== tdep
->ppc_acc_regnum
)
459 regcache_raw_supply (regcache
, tdep
->ppc_acc_regnum
, &evrregs
.acc
);
462 || regno
== tdep
->ppc_spefscr_regnum
)
463 regcache_raw_supply (regcache
, tdep
->ppc_spefscr_regnum
,
468 fetch_register (struct regcache
*regcache
, int tid
, int regno
)
470 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
471 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
472 /* This isn't really an address. But ptrace thinks of it as one. */
473 CORE_ADDR regaddr
= ppc_register_u_addr (gdbarch
, regno
);
474 int bytes_transferred
;
475 unsigned int offset
; /* Offset of registers within the u area. */
476 char buf
[MAX_REGISTER_SIZE
];
478 if (altivec_register_p (gdbarch
, regno
))
480 /* If this is the first time through, or if it is not the first
481 time through, and we have comfirmed that there is kernel
482 support for such a ptrace request, then go and fetch the
484 if (have_ptrace_getvrregs
)
486 fetch_altivec_register (regcache
, tid
, regno
);
489 /* If we have discovered that there is no ptrace support for
490 AltiVec registers, fall through and return zeroes, because
491 regaddr will be -1 in this case. */
493 if (vsx_register_p (gdbarch
, regno
))
495 if (have_ptrace_getsetvsxregs
)
497 fetch_vsx_register (regcache
, tid
, regno
);
501 else if (spe_register_p (gdbarch
, regno
))
503 fetch_spe_register (regcache
, tid
, regno
);
509 memset (buf
, '\0', register_size (gdbarch
, regno
)); /* Supply zeroes */
510 regcache_raw_supply (regcache
, regno
, buf
);
514 /* Read the raw register using sizeof(long) sized chunks. On a
515 32-bit platform, 64-bit floating-point registers will require two
517 for (bytes_transferred
= 0;
518 bytes_transferred
< register_size (gdbarch
, regno
);
519 bytes_transferred
+= sizeof (long))
522 *(long *) &buf
[bytes_transferred
]
523 = ptrace (PTRACE_PEEKUSER
, tid
, (PTRACE_TYPE_ARG3
) regaddr
, 0);
524 regaddr
+= sizeof (long);
528 sprintf (message
, "reading register %s (#%d)",
529 gdbarch_register_name (gdbarch
, regno
), regno
);
530 perror_with_name (message
);
534 /* Now supply the register. Keep in mind that the regcache's idea
535 of the register's size may not be a multiple of sizeof
537 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
539 /* Little-endian values are always found at the left end of the
540 bytes transferred. */
541 regcache_raw_supply (regcache
, regno
, buf
);
543 else if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
545 /* Big-endian values are found at the right end of the bytes
547 size_t padding
= (bytes_transferred
- register_size (gdbarch
, regno
));
548 regcache_raw_supply (regcache
, regno
, buf
+ padding
);
551 internal_error (__FILE__
, __LINE__
,
552 _("fetch_register: unexpected byte order: %d"),
553 gdbarch_byte_order (gdbarch
));
557 supply_vsxregset (struct regcache
*regcache
, gdb_vsxregset_t
*vsxregsetp
)
560 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
561 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
562 int vsxregsize
= register_size (gdbarch
, tdep
->ppc_vsr0_upper_regnum
);
564 for (i
= 0; i
< ppc_num_vshrs
; i
++)
566 regcache_raw_supply (regcache
, tdep
->ppc_vsr0_upper_regnum
+ i
,
567 *vsxregsetp
+ i
* vsxregsize
);
572 supply_vrregset (struct regcache
*regcache
, gdb_vrregset_t
*vrregsetp
)
575 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
576 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
577 int num_of_vrregs
= tdep
->ppc_vrsave_regnum
- tdep
->ppc_vr0_regnum
+ 1;
578 int vrregsize
= register_size (gdbarch
, tdep
->ppc_vr0_regnum
);
579 int offset
= vrregsize
- register_size (gdbarch
, tdep
->ppc_vrsave_regnum
);
581 for (i
= 0; i
< num_of_vrregs
; i
++)
583 /* The last 2 registers of this set are only 32 bit long, not
584 128. However an offset is necessary only for VSCR because it
585 occupies a whole vector, while VRSAVE occupies a full 4 bytes
587 if (i
== (num_of_vrregs
- 2))
588 regcache_raw_supply (regcache
, tdep
->ppc_vr0_regnum
+ i
,
589 *vrregsetp
+ i
* vrregsize
+ offset
);
591 regcache_raw_supply (regcache
, tdep
->ppc_vr0_regnum
+ i
,
592 *vrregsetp
+ i
* vrregsize
);
597 fetch_vsx_registers (struct regcache
*regcache
, int tid
)
600 gdb_vsxregset_t regs
;
602 ret
= ptrace (PTRACE_GETVSXREGS
, tid
, 0, ®s
);
607 have_ptrace_getsetvsxregs
= 0;
610 perror_with_name (_("Unable to fetch VSX registers"));
612 supply_vsxregset (regcache
, ®s
);
616 fetch_altivec_registers (struct regcache
*regcache
, int tid
)
621 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
626 have_ptrace_getvrregs
= 0;
629 perror_with_name (_("Unable to fetch AltiVec registers"));
631 supply_vrregset (regcache
, ®s
);
634 /* This function actually issues the request to ptrace, telling
635 it to get all general-purpose registers and put them into the
638 If the ptrace request does not exist, this function returns 0
639 and properly sets the have_ptrace_* flag. If the request fails,
640 this function calls perror_with_name. Otherwise, if the request
641 succeeds, then the regcache gets filled and 1 is returned. */
643 fetch_all_gp_regs (struct regcache
*regcache
, int tid
)
645 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
646 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
647 gdb_gregset_t gregset
;
649 if (ptrace (PTRACE_GETREGS
, tid
, 0, (void *) &gregset
) < 0)
653 have_ptrace_getsetregs
= 0;
656 perror_with_name (_("Couldn't get general-purpose registers."));
659 supply_gregset (regcache
, (const gdb_gregset_t
*) &gregset
);
664 /* This is a wrapper for the fetch_all_gp_regs function. It is
665 responsible for verifying if this target has the ptrace request
666 that can be used to fetch all general-purpose registers at one
667 shot. If it doesn't, then we should fetch them using the
668 old-fashioned way, which is to iterate over the registers and
669 request them one by one. */
671 fetch_gp_regs (struct regcache
*regcache
, int tid
)
673 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
674 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
677 if (have_ptrace_getsetregs
)
678 if (fetch_all_gp_regs (regcache
, tid
))
681 /* If we've hit this point, it doesn't really matter which
682 architecture we are using. We just need to read the
683 registers in the "old-fashioned way". */
684 for (i
= 0; i
< ppc_num_gprs
; i
++)
685 fetch_register (regcache
, tid
, tdep
->ppc_gp0_regnum
+ i
);
688 /* This function actually issues the request to ptrace, telling
689 it to get all floating-point registers and put them into the
692 If the ptrace request does not exist, this function returns 0
693 and properly sets the have_ptrace_* flag. If the request fails,
694 this function calls perror_with_name. Otherwise, if the request
695 succeeds, then the regcache gets filled and 1 is returned. */
697 fetch_all_fp_regs (struct regcache
*regcache
, int tid
)
699 gdb_fpregset_t fpregs
;
701 if (ptrace (PTRACE_GETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
705 have_ptrace_getsetfpregs
= 0;
708 perror_with_name (_("Couldn't get floating-point registers."));
711 supply_fpregset (regcache
, (const gdb_fpregset_t
*) &fpregs
);
716 /* This is a wrapper for the fetch_all_fp_regs function. It is
717 responsible for verifying if this target has the ptrace request
718 that can be used to fetch all floating-point registers at one
719 shot. If it doesn't, then we should fetch them using the
720 old-fashioned way, which is to iterate over the registers and
721 request them one by one. */
723 fetch_fp_regs (struct regcache
*regcache
, int tid
)
725 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
726 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
729 if (have_ptrace_getsetfpregs
)
730 if (fetch_all_fp_regs (regcache
, tid
))
733 /* If we've hit this point, it doesn't really matter which
734 architecture we are using. We just need to read the
735 registers in the "old-fashioned way". */
736 for (i
= 0; i
< ppc_num_fprs
; i
++)
737 fetch_register (regcache
, tid
, tdep
->ppc_fp0_regnum
+ i
);
741 fetch_ppc_registers (struct regcache
*regcache
, int tid
)
744 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
745 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
747 fetch_gp_regs (regcache
, tid
);
748 if (tdep
->ppc_fp0_regnum
>= 0)
749 fetch_fp_regs (regcache
, tid
);
750 fetch_register (regcache
, tid
, gdbarch_pc_regnum (gdbarch
));
751 if (tdep
->ppc_ps_regnum
!= -1)
752 fetch_register (regcache
, tid
, tdep
->ppc_ps_regnum
);
753 if (tdep
->ppc_cr_regnum
!= -1)
754 fetch_register (regcache
, tid
, tdep
->ppc_cr_regnum
);
755 if (tdep
->ppc_lr_regnum
!= -1)
756 fetch_register (regcache
, tid
, tdep
->ppc_lr_regnum
);
757 if (tdep
->ppc_ctr_regnum
!= -1)
758 fetch_register (regcache
, tid
, tdep
->ppc_ctr_regnum
);
759 if (tdep
->ppc_xer_regnum
!= -1)
760 fetch_register (regcache
, tid
, tdep
->ppc_xer_regnum
);
761 if (tdep
->ppc_mq_regnum
!= -1)
762 fetch_register (regcache
, tid
, tdep
->ppc_mq_regnum
);
763 if (ppc_linux_trap_reg_p (gdbarch
))
765 fetch_register (regcache
, tid
, PPC_ORIG_R3_REGNUM
);
766 fetch_register (regcache
, tid
, PPC_TRAP_REGNUM
);
768 if (tdep
->ppc_fpscr_regnum
!= -1)
769 fetch_register (regcache
, tid
, tdep
->ppc_fpscr_regnum
);
770 if (have_ptrace_getvrregs
)
771 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
772 fetch_altivec_registers (regcache
, tid
);
773 if (have_ptrace_getsetvsxregs
)
774 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
775 fetch_vsx_registers (regcache
, tid
);
776 if (tdep
->ppc_ev0_upper_regnum
>= 0)
777 fetch_spe_register (regcache
, tid
, -1);
780 /* Fetch registers from the child process. Fetch all registers if
781 regno == -1, otherwise fetch all general registers or all floating
782 point registers depending upon the value of regno. */
784 ppc_linux_fetch_inferior_registers (struct target_ops
*ops
,
785 struct regcache
*regcache
, int regno
)
787 /* Overload thread id onto process id */
788 int tid
= TIDGET (inferior_ptid
);
790 /* No thread id, just use process id */
792 tid
= PIDGET (inferior_ptid
);
795 fetch_ppc_registers (regcache
, tid
);
797 fetch_register (regcache
, tid
, regno
);
800 /* Store one VSX register. */
802 store_vsx_register (const struct regcache
*regcache
, int tid
, int regno
)
805 gdb_vsxregset_t regs
;
806 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
807 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
808 int vsxregsize
= register_size (gdbarch
, tdep
->ppc_vsr0_upper_regnum
);
810 ret
= ptrace (PTRACE_SETVSXREGS
, tid
, 0, ®s
);
815 have_ptrace_getsetvsxregs
= 0;
818 perror_with_name (_("Unable to fetch VSX register"));
821 regcache_raw_collect (regcache
, regno
, regs
+
822 (regno
- tdep
->ppc_vsr0_upper_regnum
) * vsxregsize
);
824 ret
= ptrace (PTRACE_SETVSXREGS
, tid
, 0, ®s
);
826 perror_with_name (_("Unable to store VSX register"));
829 /* Store one register. */
831 store_altivec_register (const struct regcache
*regcache
, int tid
, int regno
)
836 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
837 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
838 int vrregsize
= register_size (gdbarch
, tdep
->ppc_vr0_regnum
);
840 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
845 have_ptrace_getvrregs
= 0;
848 perror_with_name (_("Unable to fetch AltiVec register"));
851 /* VSCR is fetched as a 16 bytes quantity, but it is really 4 bytes
852 long on the hardware. */
853 if (regno
== (tdep
->ppc_vrsave_regnum
- 1))
854 offset
= vrregsize
- register_size (gdbarch
, tdep
->ppc_vrsave_regnum
);
856 regcache_raw_collect (regcache
, regno
,
857 regs
+ (regno
- tdep
->ppc_vr0_regnum
) * vrregsize
+ offset
);
859 ret
= ptrace (PTRACE_SETVRREGS
, tid
, 0, ®s
);
861 perror_with_name (_("Unable to store AltiVec register"));
864 /* Assuming TID referrs to an SPE process, set the top halves of TID's
865 general-purpose registers and its SPE-specific registers to the
866 values in EVRREGSET. If we don't support PTRACE_SETEVRREGS, do
869 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
870 PTRACE_SETEVRREGS requests are supported is isolated here, and in
871 get_spe_registers. */
873 set_spe_registers (int tid
, struct gdb_evrregset_t
*evrregset
)
875 if (have_ptrace_getsetevrregs
)
877 if (ptrace (PTRACE_SETEVRREGS
, tid
, 0, evrregset
) >= 0)
881 /* EIO means that the PTRACE_SETEVRREGS request isn't
882 supported; we fail silently, and don't try the call
885 have_ptrace_getsetevrregs
= 0;
887 /* Anything else needs to be reported. */
888 perror_with_name (_("Unable to set SPE registers"));
893 /* Write GDB's value for the SPE-specific raw register REGNO to TID.
894 If REGNO is -1, write the values of all the SPE-specific
897 store_spe_register (const struct regcache
*regcache
, int tid
, int regno
)
899 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
900 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
901 struct gdb_evrregset_t evrregs
;
903 gdb_assert (sizeof (evrregs
.evr
[0])
904 == register_size (gdbarch
, tdep
->ppc_ev0_upper_regnum
));
905 gdb_assert (sizeof (evrregs
.acc
)
906 == register_size (gdbarch
, tdep
->ppc_acc_regnum
));
907 gdb_assert (sizeof (evrregs
.spefscr
)
908 == register_size (gdbarch
, tdep
->ppc_spefscr_regnum
));
911 /* Since we're going to write out every register, the code below
912 should store to every field of evrregs; if that doesn't happen,
913 make it obvious by initializing it with suspicious values. */
914 memset (&evrregs
, 42, sizeof (evrregs
));
916 /* We can only read and write the entire EVR register set at a
917 time, so to write just a single register, we do a
918 read-modify-write maneuver. */
919 get_spe_registers (tid
, &evrregs
);
925 for (i
= 0; i
< ppc_num_gprs
; i
++)
926 regcache_raw_collect (regcache
,
927 tdep
->ppc_ev0_upper_regnum
+ i
,
930 else if (tdep
->ppc_ev0_upper_regnum
<= regno
931 && regno
< tdep
->ppc_ev0_upper_regnum
+ ppc_num_gprs
)
932 regcache_raw_collect (regcache
, regno
,
933 &evrregs
.evr
[regno
- tdep
->ppc_ev0_upper_regnum
]);
936 || regno
== tdep
->ppc_acc_regnum
)
937 regcache_raw_collect (regcache
,
938 tdep
->ppc_acc_regnum
,
942 || regno
== tdep
->ppc_spefscr_regnum
)
943 regcache_raw_collect (regcache
,
944 tdep
->ppc_spefscr_regnum
,
947 /* Write back the modified register set. */
948 set_spe_registers (tid
, &evrregs
);
952 store_register (const struct regcache
*regcache
, int tid
, int regno
)
954 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
955 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
956 /* This isn't really an address. But ptrace thinks of it as one. */
957 CORE_ADDR regaddr
= ppc_register_u_addr (gdbarch
, regno
);
959 size_t bytes_to_transfer
;
960 char buf
[MAX_REGISTER_SIZE
];
962 if (altivec_register_p (gdbarch
, regno
))
964 store_altivec_register (regcache
, tid
, regno
);
967 if (vsx_register_p (gdbarch
, regno
))
969 store_vsx_register (regcache
, tid
, regno
);
972 else if (spe_register_p (gdbarch
, regno
))
974 store_spe_register (regcache
, tid
, regno
);
981 /* First collect the register. Keep in mind that the regcache's
982 idea of the register's size may not be a multiple of sizeof
984 memset (buf
, 0, sizeof buf
);
985 bytes_to_transfer
= align_up (register_size (gdbarch
, regno
), sizeof (long));
986 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_LITTLE
)
988 /* Little-endian values always sit at the left end of the buffer. */
989 regcache_raw_collect (regcache
, regno
, buf
);
991 else if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
993 /* Big-endian values sit at the right end of the buffer. */
994 size_t padding
= (bytes_to_transfer
- register_size (gdbarch
, regno
));
995 regcache_raw_collect (regcache
, regno
, buf
+ padding
);
998 for (i
= 0; i
< bytes_to_transfer
; i
+= sizeof (long))
1001 ptrace (PTRACE_POKEUSER
, tid
, (PTRACE_TYPE_ARG3
) regaddr
,
1003 regaddr
+= sizeof (long);
1006 && (regno
== tdep
->ppc_fpscr_regnum
1007 || regno
== PPC_ORIG_R3_REGNUM
1008 || regno
== PPC_TRAP_REGNUM
))
1010 /* Some older kernel versions don't allow fpscr, orig_r3
1011 or trap to be written. */
1018 sprintf (message
, "writing register %s (#%d)",
1019 gdbarch_register_name (gdbarch
, regno
), regno
);
1020 perror_with_name (message
);
1026 fill_vsxregset (const struct regcache
*regcache
, gdb_vsxregset_t
*vsxregsetp
)
1029 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1030 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1031 int vsxregsize
= register_size (gdbarch
, tdep
->ppc_vsr0_upper_regnum
);
1033 for (i
= 0; i
< ppc_num_vshrs
; i
++)
1034 regcache_raw_collect (regcache
, tdep
->ppc_vsr0_upper_regnum
+ i
,
1035 *vsxregsetp
+ i
* vsxregsize
);
1039 fill_vrregset (const struct regcache
*regcache
, gdb_vrregset_t
*vrregsetp
)
1042 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1043 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1044 int num_of_vrregs
= tdep
->ppc_vrsave_regnum
- tdep
->ppc_vr0_regnum
+ 1;
1045 int vrregsize
= register_size (gdbarch
, tdep
->ppc_vr0_regnum
);
1046 int offset
= vrregsize
- register_size (gdbarch
, tdep
->ppc_vrsave_regnum
);
1048 for (i
= 0; i
< num_of_vrregs
; i
++)
1050 /* The last 2 registers of this set are only 32 bit long, not
1051 128, but only VSCR is fetched as a 16 bytes quantity. */
1052 if (i
== (num_of_vrregs
- 2))
1053 regcache_raw_collect (regcache
, tdep
->ppc_vr0_regnum
+ i
,
1054 *vrregsetp
+ i
* vrregsize
+ offset
);
1056 regcache_raw_collect (regcache
, tdep
->ppc_vr0_regnum
+ i
,
1057 *vrregsetp
+ i
* vrregsize
);
1062 store_vsx_registers (const struct regcache
*regcache
, int tid
)
1065 gdb_vsxregset_t regs
;
1067 ret
= ptrace (PTRACE_GETVSXREGS
, tid
, 0, ®s
);
1072 have_ptrace_getsetvsxregs
= 0;
1075 perror_with_name (_("Couldn't get VSX registers"));
1078 fill_vsxregset (regcache
, ®s
);
1080 if (ptrace (PTRACE_SETVSXREGS
, tid
, 0, ®s
) < 0)
1081 perror_with_name (_("Couldn't write VSX registers"));
1085 store_altivec_registers (const struct regcache
*regcache
, int tid
)
1088 gdb_vrregset_t regs
;
1090 ret
= ptrace (PTRACE_GETVRREGS
, tid
, 0, ®s
);
1095 have_ptrace_getvrregs
= 0;
1098 perror_with_name (_("Couldn't get AltiVec registers"));
1101 fill_vrregset (regcache
, ®s
);
1103 if (ptrace (PTRACE_SETVRREGS
, tid
, 0, ®s
) < 0)
1104 perror_with_name (_("Couldn't write AltiVec registers"));
1107 /* This function actually issues the request to ptrace, telling
1108 it to store all general-purpose registers present in the specified
1111 If the ptrace request does not exist, this function returns 0
1112 and properly sets the have_ptrace_* flag. If the request fails,
1113 this function calls perror_with_name. Otherwise, if the request
1114 succeeds, then the regcache is stored and 1 is returned. */
1116 store_all_gp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1118 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1119 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1120 gdb_gregset_t gregset
;
1122 if (ptrace (PTRACE_GETREGS
, tid
, 0, (void *) &gregset
) < 0)
1126 have_ptrace_getsetregs
= 0;
1129 perror_with_name (_("Couldn't get general-purpose registers."));
1132 fill_gregset (regcache
, &gregset
, regno
);
1134 if (ptrace (PTRACE_SETREGS
, tid
, 0, (void *) &gregset
) < 0)
1138 have_ptrace_getsetregs
= 0;
1141 perror_with_name (_("Couldn't set general-purpose registers."));
1147 /* This is a wrapper for the store_all_gp_regs function. It is
1148 responsible for verifying if this target has the ptrace request
1149 that can be used to store all general-purpose registers at one
1150 shot. If it doesn't, then we should store them using the
1151 old-fashioned way, which is to iterate over the registers and
1152 store them one by one. */
1154 store_gp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1156 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1157 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1160 if (have_ptrace_getsetregs
)
1161 if (store_all_gp_regs (regcache
, tid
, regno
))
1164 /* If we hit this point, it doesn't really matter which
1165 architecture we are using. We just need to store the
1166 registers in the "old-fashioned way". */
1167 for (i
= 0; i
< ppc_num_gprs
; i
++)
1168 store_register (regcache
, tid
, tdep
->ppc_gp0_regnum
+ i
);
1171 /* This function actually issues the request to ptrace, telling
1172 it to store all floating-point registers present in the specified
1175 If the ptrace request does not exist, this function returns 0
1176 and properly sets the have_ptrace_* flag. If the request fails,
1177 this function calls perror_with_name. Otherwise, if the request
1178 succeeds, then the regcache is stored and 1 is returned. */
1180 store_all_fp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1182 gdb_fpregset_t fpregs
;
1184 if (ptrace (PTRACE_GETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
1188 have_ptrace_getsetfpregs
= 0;
1191 perror_with_name (_("Couldn't get floating-point registers."));
1194 fill_fpregset (regcache
, &fpregs
, regno
);
1196 if (ptrace (PTRACE_SETFPREGS
, tid
, 0, (void *) &fpregs
) < 0)
1200 have_ptrace_getsetfpregs
= 0;
1203 perror_with_name (_("Couldn't set floating-point registers."));
1209 /* This is a wrapper for the store_all_fp_regs function. It is
1210 responsible for verifying if this target has the ptrace request
1211 that can be used to store all floating-point registers at one
1212 shot. If it doesn't, then we should store them using the
1213 old-fashioned way, which is to iterate over the registers and
1214 store them one by one. */
1216 store_fp_regs (const struct regcache
*regcache
, int tid
, int regno
)
1218 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1219 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1222 if (have_ptrace_getsetfpregs
)
1223 if (store_all_fp_regs (regcache
, tid
, regno
))
1226 /* If we hit this point, it doesn't really matter which
1227 architecture we are using. We just need to store the
1228 registers in the "old-fashioned way". */
1229 for (i
= 0; i
< ppc_num_fprs
; i
++)
1230 store_register (regcache
, tid
, tdep
->ppc_fp0_regnum
+ i
);
1234 store_ppc_registers (const struct regcache
*regcache
, int tid
)
1237 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1238 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1240 store_gp_regs (regcache
, tid
, -1);
1241 if (tdep
->ppc_fp0_regnum
>= 0)
1242 store_fp_regs (regcache
, tid
, -1);
1243 store_register (regcache
, tid
, gdbarch_pc_regnum (gdbarch
));
1244 if (tdep
->ppc_ps_regnum
!= -1)
1245 store_register (regcache
, tid
, tdep
->ppc_ps_regnum
);
1246 if (tdep
->ppc_cr_regnum
!= -1)
1247 store_register (regcache
, tid
, tdep
->ppc_cr_regnum
);
1248 if (tdep
->ppc_lr_regnum
!= -1)
1249 store_register (regcache
, tid
, tdep
->ppc_lr_regnum
);
1250 if (tdep
->ppc_ctr_regnum
!= -1)
1251 store_register (regcache
, tid
, tdep
->ppc_ctr_regnum
);
1252 if (tdep
->ppc_xer_regnum
!= -1)
1253 store_register (regcache
, tid
, tdep
->ppc_xer_regnum
);
1254 if (tdep
->ppc_mq_regnum
!= -1)
1255 store_register (regcache
, tid
, tdep
->ppc_mq_regnum
);
1256 if (tdep
->ppc_fpscr_regnum
!= -1)
1257 store_register (regcache
, tid
, tdep
->ppc_fpscr_regnum
);
1258 if (ppc_linux_trap_reg_p (gdbarch
))
1260 store_register (regcache
, tid
, PPC_ORIG_R3_REGNUM
);
1261 store_register (regcache
, tid
, PPC_TRAP_REGNUM
);
1263 if (have_ptrace_getvrregs
)
1264 if (tdep
->ppc_vr0_regnum
!= -1 && tdep
->ppc_vrsave_regnum
!= -1)
1265 store_altivec_registers (regcache
, tid
);
1266 if (have_ptrace_getsetvsxregs
)
1267 if (tdep
->ppc_vsr0_upper_regnum
!= -1)
1268 store_vsx_registers (regcache
, tid
);
1269 if (tdep
->ppc_ev0_upper_regnum
>= 0)
1270 store_spe_register (regcache
, tid
, -1);
1274 ppc_linux_check_watch_resources (int type
, int cnt
, int ot
)
1277 ptid_t ptid
= inferior_ptid
;
1279 /* DABR (data address breakpoint register) is optional for PPC variants.
1280 Some variants have one DABR, others have none. So CNT can't be larger
1285 /* We need to know whether ptrace supports PTRACE_SET_DEBUGREG and whether
1286 the target has DABR. If either answer is no, the ptrace call will
1287 return -1. Fail in that case. */
1288 tid
= TIDGET (ptid
);
1290 tid
= PIDGET (ptid
);
1292 if (ptrace (PTRACE_SET_DEBUGREG
, tid
, 0, 0) == -1)
1297 /* Fetch the AT_HWCAP entry from the aux vector. */
1298 unsigned long ppc_linux_get_hwcap (void)
1302 if (target_auxv_search (¤t_target
, AT_HWCAP
, &field
))
1303 return (unsigned long) field
;
1309 ppc_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr
, int len
)
1311 /* Handle sub-8-byte quantities. */
1315 /* addr+len must fall in the 8 byte watchable region for DABR-based
1316 processors. DAC-based processors, like the PowerPC 440, will use
1317 addresses aligned to 4-bytes due to the way the read/write flags are
1318 passed at the moment. */
1319 if (((ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE
)
1320 && (addr
+ len
) > (addr
& ~3) + 4)
1321 || (addr
+ len
) > (addr
& ~7) + 8)
1327 /* The cached DABR value, to install in new threads. */
1328 static long saved_dabr_value
;
1330 /* Set a watchpoint of type TYPE at address ADDR. */
1332 ppc_linux_insert_watchpoint (CORE_ADDR addr
, int len
, int rw
)
1334 struct lwp_info
*lp
;
1337 long read_mode
, write_mode
;
1339 if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE
)
1341 /* PowerPC 440 requires only the read/write flags to be passed
1348 /* PowerPC 970 and other DABR-based processors are required to pass
1349 the Breakpoint Translation bit together with the flags. */
1354 dabr_value
= addr
& ~(read_mode
| write_mode
);
1358 /* Set read and translate bits. */
1359 dabr_value
|= read_mode
;
1362 /* Set write and translate bits. */
1363 dabr_value
|= write_mode
;
1366 /* Set read, write and translate bits. */
1367 dabr_value
|= read_mode
| write_mode
;
1371 saved_dabr_value
= dabr_value
;
1374 if (ptrace (PTRACE_SET_DEBUGREG
, TIDGET (ptid
), 0, saved_dabr_value
) < 0)
1381 ppc_linux_remove_watchpoint (CORE_ADDR addr
, int len
, int rw
)
1383 struct lwp_info
*lp
;
1385 long dabr_value
= 0;
1387 saved_dabr_value
= 0;
1389 if (ptrace (PTRACE_SET_DEBUGREG
, TIDGET (ptid
), 0, saved_dabr_value
) < 0)
1395 ppc_linux_new_thread (ptid_t ptid
)
1397 ptrace (PTRACE_SET_DEBUGREG
, TIDGET (ptid
), 0, saved_dabr_value
);
1401 ppc_linux_stopped_data_address (struct target_ops
*target
, CORE_ADDR
*addr_p
)
1403 struct siginfo
*siginfo_p
;
1405 siginfo_p
= linux_nat_get_siginfo (inferior_ptid
);
1407 if (siginfo_p
->si_signo
!= SIGTRAP
1408 || (siginfo_p
->si_code
& 0xffff) != 0x0004 /* TRAP_HWBKPT */)
1411 *addr_p
= (CORE_ADDR
) (uintptr_t) siginfo_p
->si_addr
;
1416 ppc_linux_stopped_by_watchpoint (void)
1419 return ppc_linux_stopped_data_address (¤t_target
, &addr
);
1423 ppc_linux_watchpoint_addr_within_range (struct target_ops
*target
,
1425 CORE_ADDR start
, int length
)
1429 if (ppc_linux_get_hwcap () & PPC_FEATURE_BOOKE
)
1436 /* Check whether [start, start+length-1] intersects [addr, addr+mask]. */
1437 return start
<= addr
+ mask
&& start
+ length
- 1 >= addr
;
1441 ppc_linux_store_inferior_registers (struct target_ops
*ops
,
1442 struct regcache
*regcache
, int regno
)
1444 /* Overload thread id onto process id */
1445 int tid
= TIDGET (inferior_ptid
);
1447 /* No thread id, just use process id */
1449 tid
= PIDGET (inferior_ptid
);
1452 store_register (regcache
, tid
, regno
);
1454 store_ppc_registers (regcache
, tid
);
1457 /* Functions for transferring registers between a gregset_t or fpregset_t
1458 (see sys/ucontext.h) and gdb's regcache. The word size is that used
1459 by the ptrace interface, not the current program's ABI. eg. If a
1460 powerpc64-linux gdb is being used to debug a powerpc32-linux app, we
1461 read or write 64-bit gregsets. This is to suit the host libthread_db. */
1464 supply_gregset (struct regcache
*regcache
, const gdb_gregset_t
*gregsetp
)
1466 const struct regset
*regset
= ppc_linux_gregset (sizeof (long));
1468 ppc_supply_gregset (regset
, regcache
, -1, gregsetp
, sizeof (*gregsetp
));
1472 fill_gregset (const struct regcache
*regcache
,
1473 gdb_gregset_t
*gregsetp
, int regno
)
1475 const struct regset
*regset
= ppc_linux_gregset (sizeof (long));
1478 memset (gregsetp
, 0, sizeof (*gregsetp
));
1479 ppc_collect_gregset (regset
, regcache
, regno
, gregsetp
, sizeof (*gregsetp
));
1483 supply_fpregset (struct regcache
*regcache
, const gdb_fpregset_t
* fpregsetp
)
1485 const struct regset
*regset
= ppc_linux_fpregset ();
1487 ppc_supply_fpregset (regset
, regcache
, -1,
1488 fpregsetp
, sizeof (*fpregsetp
));
1492 fill_fpregset (const struct regcache
*regcache
,
1493 gdb_fpregset_t
*fpregsetp
, int regno
)
1495 const struct regset
*regset
= ppc_linux_fpregset ();
1497 ppc_collect_fpregset (regset
, regcache
, regno
,
1498 fpregsetp
, sizeof (*fpregsetp
));
1502 ppc_linux_target_wordsize (void)
1506 /* Check for 64-bit inferior process. This is the case when the host is
1507 64-bit, and in addition the top bit of the MSR register is set. */
1508 #ifdef __powerpc64__
1511 int tid
= TIDGET (inferior_ptid
);
1513 tid
= PIDGET (inferior_ptid
);
1516 msr
= (long) ptrace (PTRACE_PEEKUSER
, tid
, PT_MSR
* 8, 0);
1517 if (errno
== 0 && msr
< 0)
1525 ppc_linux_auxv_parse (struct target_ops
*ops
, gdb_byte
**readptr
,
1526 gdb_byte
*endptr
, CORE_ADDR
*typep
, CORE_ADDR
*valp
)
1528 int sizeof_auxv_field
= ppc_linux_target_wordsize ();
1529 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch
);
1530 gdb_byte
*ptr
= *readptr
;
1535 if (endptr
- ptr
< sizeof_auxv_field
* 2)
1538 *typep
= extract_unsigned_integer (ptr
, sizeof_auxv_field
, byte_order
);
1539 ptr
+= sizeof_auxv_field
;
1540 *valp
= extract_unsigned_integer (ptr
, sizeof_auxv_field
, byte_order
);
1541 ptr
+= sizeof_auxv_field
;
1547 static const struct target_desc
*
1548 ppc_linux_read_description (struct target_ops
*ops
)
1555 int tid
= TIDGET (inferior_ptid
);
1557 tid
= PIDGET (inferior_ptid
);
1559 if (have_ptrace_getsetevrregs
)
1561 struct gdb_evrregset_t evrregset
;
1563 if (ptrace (PTRACE_GETEVRREGS
, tid
, 0, &evrregset
) >= 0)
1564 return tdesc_powerpc_e500l
;
1566 /* EIO means that the PTRACE_GETEVRREGS request isn't supported.
1567 Anything else needs to be reported. */
1568 else if (errno
!= EIO
)
1569 perror_with_name (_("Unable to fetch SPE registers"));
1572 if (have_ptrace_getsetvsxregs
)
1574 gdb_vsxregset_t vsxregset
;
1576 if (ptrace (PTRACE_GETVSXREGS
, tid
, 0, &vsxregset
) >= 0)
1579 /* EIO means that the PTRACE_GETVSXREGS request isn't supported.
1580 Anything else needs to be reported. */
1581 else if (errno
!= EIO
)
1582 perror_with_name (_("Unable to fetch VSX registers"));
1585 if (have_ptrace_getvrregs
)
1587 gdb_vrregset_t vrregset
;
1589 if (ptrace (PTRACE_GETVRREGS
, tid
, 0, &vrregset
) >= 0)
1592 /* EIO means that the PTRACE_GETVRREGS request isn't supported.
1593 Anything else needs to be reported. */
1594 else if (errno
!= EIO
)
1595 perror_with_name (_("Unable to fetch AltiVec registers"));
1598 /* Power ISA 2.05 (implemented by Power 6 and newer processors) increases
1599 the FPSCR from 32 bits to 64 bits. Even though Power 7 supports this
1600 ISA version, it doesn't have PPC_FEATURE_ARCH_2_05 set, only
1601 PPC_FEATURE_ARCH_2_06. Since for now the only bits used in the higher
1602 half of the register are for Decimal Floating Point, we check if that
1603 feature is available to decide the size of the FPSCR. */
1604 if (ppc_linux_get_hwcap () & PPC_FEATURE_HAS_DFP
)
1607 if (ppc_linux_get_hwcap () & PPC_FEATURE_CELL
)
1610 if (ppc_linux_target_wordsize () == 8)
1613 return tdesc_powerpc_cell64l
;
1615 return isa205
? tdesc_powerpc_isa205_vsx64l
: tdesc_powerpc_vsx64l
;
1617 return isa205
? tdesc_powerpc_isa205_altivec64l
: tdesc_powerpc_altivec64l
;
1619 return isa205
? tdesc_powerpc_isa205_64l
: tdesc_powerpc_64l
;
1623 return tdesc_powerpc_cell32l
;
1625 return isa205
? tdesc_powerpc_isa205_vsx32l
: tdesc_powerpc_vsx32l
;
1627 return isa205
? tdesc_powerpc_isa205_altivec32l
: tdesc_powerpc_altivec32l
;
1629 return isa205
? tdesc_powerpc_isa205_32l
: tdesc_powerpc_32l
;
1632 void _initialize_ppc_linux_nat (void);
1635 _initialize_ppc_linux_nat (void)
1637 struct target_ops
*t
;
1639 /* Fill in the generic GNU/Linux methods. */
1640 t
= linux_target ();
1642 /* Add our register access methods. */
1643 t
->to_fetch_registers
= ppc_linux_fetch_inferior_registers
;
1644 t
->to_store_registers
= ppc_linux_store_inferior_registers
;
1646 /* Add our watchpoint methods. */
1647 t
->to_can_use_hw_breakpoint
= ppc_linux_check_watch_resources
;
1648 t
->to_region_ok_for_hw_watchpoint
= ppc_linux_region_ok_for_hw_watchpoint
;
1649 t
->to_insert_watchpoint
= ppc_linux_insert_watchpoint
;
1650 t
->to_remove_watchpoint
= ppc_linux_remove_watchpoint
;
1651 t
->to_stopped_by_watchpoint
= ppc_linux_stopped_by_watchpoint
;
1652 t
->to_stopped_data_address
= ppc_linux_stopped_data_address
;
1653 t
->to_watchpoint_addr_within_range
= ppc_linux_watchpoint_addr_within_range
;
1655 t
->to_read_description
= ppc_linux_read_description
;
1656 t
->to_auxv_parse
= ppc_linux_auxv_parse
;
1658 /* Register the target. */
1659 linux_nat_add_target (t
);
1660 linux_nat_set_new_thread (t
, ppc_linux_new_thread
);