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