]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/ppc-linux-nat.c
gdb, gdbserver, gdbsupport: remove includes of early headers
[thirdparty/binutils-gdb.git] / gdb / ppc-linux-nat.c
CommitLineData
9abe5450 1/* PPC GNU/Linux native support.
2555fe1a 2
1d506c26 3 Copyright (C) 1988-2024 Free Software Foundation, Inc.
c877c8e6
KB
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c877c8e6
KB
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c877c8e6 19
c877c8e6
KB
20#include "frame.h"
21#include "inferior.h"
6ffbb7ab 22#include "gdbthread.h"
c877c8e6 23#include "gdbcore.h"
4e052eda 24#include "regcache.h"
1d75a658 25#include "regset.h"
10d6c8cd
DJ
26#include "target.h"
27#include "linux-nat.h"
c877c8e6 28#include <sys/types.h>
c877c8e6
KB
29#include <signal.h>
30#include <sys/user.h>
31#include <sys/ioctl.h>
7ca18ed6 32#include <sys/uio.h>
268a13a5 33#include "gdbsupport/gdb_wait.h"
c877c8e6
KB
34#include <fcntl.h>
35#include <sys/procfs.h>
5826e159 36#include "nat/gdb_ptrace.h"
64f57f3d 37#include "nat/linux-ptrace.h"
bcc0c096 38#include "inf-ptrace.h"
227c0bf4
PFC
39#include <algorithm>
40#include <unordered_map>
41#include <list>
c877c8e6 42
0df8b418 43/* Prototypes for supply_gregset etc. */
c60c0f5f 44#include "gregset.h"
16333c4f 45#include "ppc-tdep.h"
7284e1be
UW
46#include "ppc-linux-tdep.h"
47
b7622095
LM
48/* Required when using the AUXV. */
49#include "elf/common.h"
50#include "auxv.h"
51
bd64614e
PFC
52#include "arch/ppc-linux-common.h"
53#include "arch/ppc-linux-tdesc.h"
514c5338 54#include "nat/ppc-linux.h"
53c973f2 55#include "linux-tdep.h"
413403fc 56#include "expop.h"
01904826 57
6ffbb7ab 58/* Similarly for the hardware watchpoint support. These requests are used
926bf92d 59 when the PowerPC HWDEBUG ptrace interface is not available. */
e0d24f8d
WZ
60#ifndef PTRACE_GET_DEBUGREG
61#define PTRACE_GET_DEBUGREG 25
62#endif
63#ifndef PTRACE_SET_DEBUGREG
64#define PTRACE_SET_DEBUGREG 26
65#endif
66#ifndef PTRACE_GETSIGINFO
67#define PTRACE_GETSIGINFO 0x4202
68#endif
01904826 69
926bf92d
UW
70/* These requests are used when the PowerPC HWDEBUG ptrace interface is
71 available. It exposes the debug facilities of PowerPC processors, as well
72 as additional features of BookE processors, such as ranged breakpoints and
73 watchpoints and hardware-accelerated condition evaluation. */
6ffbb7ab
TJB
74#ifndef PPC_PTRACE_GETHWDBGINFO
75
926bf92d
UW
76/* Not having PPC_PTRACE_GETHWDBGINFO defined means that the PowerPC HWDEBUG
77 ptrace interface is not present in ptrace.h, so we'll have to pretty much
78 include it all here so that the code at least compiles on older systems. */
6ffbb7ab
TJB
79#define PPC_PTRACE_GETHWDBGINFO 0x89
80#define PPC_PTRACE_SETHWDEBUG 0x88
81#define PPC_PTRACE_DELHWDEBUG 0x87
82
83struct ppc_debug_info
84{
dda83cd7
SM
85 uint32_t version; /* Only version 1 exists to date. */
86 uint32_t num_instruction_bps;
87 uint32_t num_data_bps;
88 uint32_t num_condition_regs;
89 uint32_t data_bp_alignment;
90 uint32_t sizeof_condition; /* size of the DVC register. */
91 uint64_t features;
6ffbb7ab
TJB
92};
93
94/* Features will have bits indicating whether there is support for: */
95#define PPC_DEBUG_FEATURE_INSN_BP_RANGE 0x1
96#define PPC_DEBUG_FEATURE_INSN_BP_MASK 0x2
97#define PPC_DEBUG_FEATURE_DATA_BP_RANGE 0x4
98#define PPC_DEBUG_FEATURE_DATA_BP_MASK 0x8
99
100struct ppc_hw_breakpoint
101{
dda83cd7
SM
102 uint32_t version; /* currently, version must be 1 */
103 uint32_t trigger_type; /* only some combinations allowed */
104 uint32_t addr_mode; /* address match mode */
105 uint32_t condition_mode; /* break/watchpoint condition flags */
106 uint64_t addr; /* break/watchpoint address */
107 uint64_t addr2; /* range end or mask */
108 uint64_t condition_value; /* contents of the DVC register */
6ffbb7ab
TJB
109};
110
111/* Trigger type. */
112#define PPC_BREAKPOINT_TRIGGER_EXECUTE 0x1
113#define PPC_BREAKPOINT_TRIGGER_READ 0x2
114#define PPC_BREAKPOINT_TRIGGER_WRITE 0x4
115#define PPC_BREAKPOINT_TRIGGER_RW 0x6
116
117/* Address mode. */
118#define PPC_BREAKPOINT_MODE_EXACT 0x0
119#define PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE 0x1
120#define PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE 0x2
121#define PPC_BREAKPOINT_MODE_MASK 0x3
122
123/* Condition mode. */
124#define PPC_BREAKPOINT_CONDITION_NONE 0x0
125#define PPC_BREAKPOINT_CONDITION_AND 0x1
126#define PPC_BREAKPOINT_CONDITION_EXACT 0x1
127#define PPC_BREAKPOINT_CONDITION_OR 0x2
128#define PPC_BREAKPOINT_CONDITION_AND_OR 0x3
129#define PPC_BREAKPOINT_CONDITION_BE_ALL 0x00ff0000
130#define PPC_BREAKPOINT_CONDITION_BE_SHIFT 16
131#define PPC_BREAKPOINT_CONDITION_BE(n) \
dda83cd7 132 (1<<((n)+PPC_BREAKPOINT_CONDITION_BE_SHIFT))
6ffbb7ab
TJB
133#endif /* PPC_PTRACE_GETHWDBGINFO */
134
e23b9d6e
UW
135/* Feature defined on Linux kernel v3.9: DAWR interface, that enables wider
136 watchpoint (up to 512 bytes). */
137#ifndef PPC_DEBUG_FEATURE_DATA_BP_DAWR
138#define PPC_DEBUG_FEATURE_DATA_BP_DAWR 0x10
139#endif /* PPC_DEBUG_FEATURE_DATA_BP_DAWR */
6ffbb7ab 140
539d71e8
RA
141/* Feature defined on Linux kernel v5.1: Second watchpoint support. */
142#ifndef PPC_DEBUG_FEATURE_DATA_BP_ARCH_31
143#define PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 0x20
144#endif /* PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 */
145
227c0bf4
PFC
146/* The version of the PowerPC HWDEBUG kernel interface that we will use, if
147 available. */
148#define PPC_DEBUG_CURRENT_VERSION 1
149
1dfe79e8
SDJ
150/* Similarly for the general-purpose (gp0 -- gp31)
151 and floating-point registers (fp0 -- fp31). */
152#ifndef PTRACE_GETREGS
153#define PTRACE_GETREGS 12
154#endif
155#ifndef PTRACE_SETREGS
156#define PTRACE_SETREGS 13
157#endif
158#ifndef PTRACE_GETFPREGS
159#define PTRACE_GETFPREGS 14
160#endif
161#ifndef PTRACE_SETFPREGS
162#define PTRACE_SETFPREGS 15
163#endif
164
9abe5450
EZ
165/* This oddity is because the Linux kernel defines elf_vrregset_t as
166 an array of 33 16 bytes long elements. I.e. it leaves out vrsave.
167 However the PTRACE_GETVRREGS and PTRACE_SETVRREGS requests return
168 the vrsave as an extra 4 bytes at the end. I opted for creating a
169 flat array of chars, so that it is easier to manipulate for gdb.
170
171 There are 32 vector registers 16 bytes longs, plus a VSCR register
172 which is only 4 bytes long, but is fetched as a 16 bytes
0df8b418 173 quantity. Up to here we have the elf_vrregset_t structure.
9abe5450
EZ
174 Appended to this there is space for the VRSAVE register: 4 bytes.
175 Even though this vrsave register is not included in the regset
176 typedef, it is handled by the ptrace requests.
177
9abe5450
EZ
178 The layout is like this (where x is the actual value of the vscr reg): */
179
9abe5450 180/*
1d75a658 181Big-Endian:
9abe5450
EZ
182 |.|.|.|.|.....|.|.|.|.||.|.|.|x||.|
183 <-------> <-------><-------><->
184 VR0 VR31 VSCR VRSAVE
1d75a658
PFC
185Little-Endian:
186 |.|.|.|.|.....|.|.|.|.||X|.|.|.||.|
187 <-------> <-------><-------><->
188 VR0 VR31 VSCR VRSAVE
9abe5450 189*/
9abe5450 190
d078308a 191typedef char gdb_vrregset_t[PPC_LINUX_SIZEOF_VRREGSET];
9abe5450 192
604c2f83
LM
193/* This is the layout of the POWER7 VSX registers and the way they overlap
194 with the existing FPR and VMX registers.
195
dda83cd7
SM
196 VSR doubleword 0 VSR doubleword 1
197 ----------------------------------------------------------------
604c2f83 198 VSR[0] | FPR[0] | |
dda83cd7 199 ----------------------------------------------------------------
604c2f83 200 VSR[1] | FPR[1] | |
dda83cd7
SM
201 ----------------------------------------------------------------
202 | ... | |
203 | ... | |
204 ----------------------------------------------------------------
604c2f83 205 VSR[30] | FPR[30] | |
dda83cd7 206 ----------------------------------------------------------------
604c2f83 207 VSR[31] | FPR[31] | |
dda83cd7 208 ----------------------------------------------------------------
604c2f83 209 VSR[32] | VR[0] |
dda83cd7 210 ----------------------------------------------------------------
604c2f83 211 VSR[33] | VR[1] |
dda83cd7
SM
212 ----------------------------------------------------------------
213 | ... |
214 | ... |
215 ----------------------------------------------------------------
604c2f83 216 VSR[62] | VR[30] |
dda83cd7 217 ----------------------------------------------------------------
604c2f83 218 VSR[63] | VR[31] |
dda83cd7 219 ----------------------------------------------------------------
604c2f83
LM
220
221 VSX has 64 128bit registers. The first 32 registers overlap with
222 the FP registers (doubleword 0) and hence extend them with additional
223 64 bits (doubleword 1). The other 32 regs overlap with the VMX
224 registers. */
d078308a 225typedef char gdb_vsxregset_t[PPC_LINUX_SIZEOF_VSXREGSET];
01904826 226
b021a221 227/* On PPC processors that support the Signal Processing Extension
01904826 228 (SPE) APU, the general-purpose registers are 64 bits long.
411cb3f9
PG
229 However, the ordinary Linux kernel PTRACE_PEEKUSER / PTRACE_POKEUSER
230 ptrace calls only access the lower half of each register, to allow
231 them to behave the same way they do on non-SPE systems. There's a
232 separate pair of calls, PTRACE_GETEVRREGS / PTRACE_SETEVRREGS, that
233 read and write the top halves of all the general-purpose registers
234 at once, along with some SPE-specific registers.
01904826
JB
235
236 GDB itself continues to claim the general-purpose registers are 32
6ced10dd 237 bits long. It has unnamed raw registers that hold the upper halves
b021a221 238 of the gprs, and the full 64-bit SIMD views of the registers,
6ced10dd
JB
239 'ev0' -- 'ev31', are pseudo-registers that splice the top and
240 bottom halves together.
01904826
JB
241
242 This is the structure filled in by PTRACE_GETEVRREGS and written to
243 the inferior's registers by PTRACE_SETEVRREGS. */
244struct gdb_evrregset_t
245{
246 unsigned long evr[32];
247 unsigned long long acc;
248 unsigned long spefscr;
249};
250
604c2f83
LM
251/* Non-zero if our kernel may support the PTRACE_GETVSXREGS and
252 PTRACE_SETVSXREGS requests, for reading and writing the VSX
253 POWER7 registers 0 through 31. Zero if we've tried one of them and
254 gotten an error. Note that VSX registers 32 through 63 overlap
255 with VR registers 0 through 31. */
256int have_ptrace_getsetvsxregs = 1;
01904826
JB
257
258/* Non-zero if our kernel may support the PTRACE_GETVRREGS and
259 PTRACE_SETVRREGS requests, for reading and writing the Altivec
260 registers. Zero if we've tried one of them and gotten an
261 error. */
9abe5450
EZ
262int have_ptrace_getvrregs = 1;
263
01904826
JB
264/* Non-zero if our kernel may support the PTRACE_GETEVRREGS and
265 PTRACE_SETEVRREGS requests, for reading and writing the SPE
266 registers. Zero if we've tried one of them and gotten an
267 error. */
268int have_ptrace_getsetevrregs = 1;
269
1dfe79e8
SDJ
270/* Non-zero if our kernel may support the PTRACE_GETREGS and
271 PTRACE_SETREGS requests, for reading and writing the
272 general-purpose registers. Zero if we've tried one of
273 them and gotten an error. */
274int have_ptrace_getsetregs = 1;
275
276/* Non-zero if our kernel may support the PTRACE_GETFPREGS and
277 PTRACE_SETFPREGS requests, for reading and writing the
278 floating-pointers registers. Zero if we've tried one of
279 them and gotten an error. */
280int have_ptrace_getsetfpregs = 1;
281
227c0bf4
PFC
282/* Private arch info associated with each thread lwp_info object, used
283 for debug register handling. */
284
285struct arch_lwp_info
286{
287 /* When true, indicates that the debug registers installed in the
288 thread no longer correspond to the watchpoints and breakpoints
289 requested by GDB. */
290 bool debug_regs_stale;
291
292 /* We need a back-reference to the PTID of the thread so that we can
293 cleanup the debug register state of the thread in
294 low_delete_thread. */
295 ptid_t lwp_ptid;
296};
297
298/* Class used to detect which set of ptrace requests that
299 ppc_linux_nat_target will use to install and remove hardware
300 breakpoints and watchpoints.
301
302 The interface is only detected once, testing the ptrace calls. The
303 result can indicate that no interface is available.
304
305 The Linux kernel provides two different sets of ptrace requests to
306 handle hardware watchpoints and breakpoints for Power:
307
308 - PPC_PTRACE_GETHWDBGINFO, PPC_PTRACE_SETHWDEBUG, and
309 PPC_PTRACE_DELHWDEBUG.
310
311 Or
312
313 - PTRACE_SET_DEBUGREG and PTRACE_GET_DEBUGREG
314
315 The first set is the more flexible one and allows setting watchpoints
316 with a variable watched region length and, for BookE processors,
317 multiple types of debug registers (e.g. hardware breakpoints and
318 hardware-assisted conditions for watchpoints). The second one only
319 allows setting one debug register, a watchpoint, so we only use it if
320 the first one is not available. */
321
322class ppc_linux_dreg_interface
323{
324public:
325
326 ppc_linux_dreg_interface ()
327 : m_interface (), m_hwdebug_info ()
328 {
329 };
330
331 DISABLE_COPY_AND_ASSIGN (ppc_linux_dreg_interface);
332
333 /* One and only one of these three functions returns true, indicating
334 whether the corresponding interface is the one we detected. The
3bfdcabb 335 interface must already have been detected as a precondition. */
227c0bf4
PFC
336
337 bool hwdebug_p ()
338 {
339 gdb_assert (detected_p ());
340 return *m_interface == HWDEBUG;
341 }
342
343 bool debugreg_p ()
344 {
345 gdb_assert (detected_p ());
346 return *m_interface == DEBUGREG;
347 }
348
349 bool unavailable_p ()
350 {
351 gdb_assert (detected_p ());
352 return *m_interface == UNAVAILABLE;
353 }
354
355 /* Returns the debug register capabilities of the target. Should only
356 be called if the interface is HWDEBUG. */
357 const struct ppc_debug_info &hwdebug_info ()
358 {
359 gdb_assert (hwdebug_p ());
360
361 return m_hwdebug_info;
362 }
363
364 /* Returns true if the interface has already been detected. This is
365 useful for cases when we know there is no work to be done if the
366 interface hasn't been detected yet. */
367 bool detected_p ()
368 {
369 return m_interface.has_value ();
370 }
371
372 /* Detect the available interface, if any, if it hasn't been detected
373 before, using PTID for the necessary ptrace calls. */
374
375 void detect (const ptid_t &ptid)
376 {
377 if (m_interface.has_value ())
378 return;
379
380 gdb_assert (ptid.lwp_p ());
381
382 bool no_features = false;
383
384 if (ptrace (PPC_PTRACE_GETHWDBGINFO, ptid.lwp (), 0, &m_hwdebug_info)
6e562fa3 385 >= 0)
227c0bf4
PFC
386 {
387 /* If there are no advertised features, we don't use the
388 HWDEBUG interface and try the DEBUGREG interface instead.
389 It shouldn't be necessary to do this, however, when the
390 kernel is configured without CONFIG_HW_BREAKPOINTS (selected
391 by CONFIG_PERF_EVENTS), there is a bug that causes
392 watchpoints installed with the HWDEBUG interface not to
393 trigger. When this is the case, features will be zero,
394 which we use as an indicator to fall back to the DEBUGREG
395 interface. */
396 if (m_hwdebug_info.features != 0)
397 {
398 m_interface.emplace (HWDEBUG);
399 return;
400 }
401 else
402 no_features = true;
403 }
404
405 /* EIO indicates that the request is invalid, so we try DEBUGREG
406 next. Technically, it can also indicate other failures, but we
407 can't differentiate those.
408
409 Other errors could happen for various reasons. We could get an
410 ESRCH if the traced thread was killed by a signal. Trying to
411 detect the interface with another thread in the future would be
412 complicated, as callers would have to handle an "unknown
413 interface" case. It's also unclear if raising an exception
414 here would be safe.
415
416 Other errors, such as ENODEV, could be more permanent and cause
417 a failure for any thread.
418
419 For simplicity, with all errors other than EIO, we set the
420 interface to UNAVAILABLE and don't try DEBUGREG. If DEBUGREG
421 fails too, we'll also set the interface to UNAVAILABLE. It's
422 unlikely that trying the DEBUGREG interface with this same thread
423 would work, for errors other than EIO. This means that these
424 errors will cause hardware watchpoints and breakpoints to become
425 unavailable throughout a GDB session. */
426
427 if (no_features || errno == EIO)
428 {
429 unsigned long wp;
430
6e562fa3 431 if (ptrace (PTRACE_GET_DEBUGREG, ptid.lwp (), 0, &wp) >= 0)
227c0bf4
PFC
432 {
433 m_interface.emplace (DEBUGREG);
434 return;
435 }
436 }
437
438 if (errno != EIO)
439 warning (_("Error when detecting the debug register interface. "
440 "Debug registers will be unavailable."));
441
442 m_interface.emplace (UNAVAILABLE);
443 return;
444 }
445
446private:
447
448 /* HWDEBUG represents the set of calls PPC_PTRACE_GETHWDBGINFO,
449 PPC_PTRACE_SETHWDEBUG and PPC_PTRACE_DELHWDEBUG.
450
451 DEBUGREG represents the set of calls PTRACE_SET_DEBUGREG and
452 PTRACE_GET_DEBUGREG.
453
454 UNAVAILABLE can indicate that the kernel doesn't support any of the
455 two sets of requests or that there was an error when we tried to
33b5899f 456 detect which interface is available. */
227c0bf4
PFC
457
458 enum debug_reg_interface
459 {
460 UNAVAILABLE,
461 HWDEBUG,
462 DEBUGREG
463 };
464
465 /* The interface option. Initialized if has_value () returns true. */
6b09f134 466 std::optional<enum debug_reg_interface> m_interface;
227c0bf4
PFC
467
468 /* The info returned by the kernel with PPC_PTRACE_GETHWDBGINFO. Only
469 valid if we determined that the interface is HWDEBUG. */
470 struct ppc_debug_info m_hwdebug_info;
471};
472
473/* Per-process information. This includes the hardware watchpoints and
474 breakpoints that GDB requested to this target. */
475
476struct ppc_linux_process_info
477{
478 /* The list of hardware watchpoints and breakpoints that GDB requested
479 for this process.
480
481 Only used when the interface is HWDEBUG. */
482 std::list<struct ppc_hw_breakpoint> requested_hw_bps;
483
484 /* The watchpoint value that GDB requested for this process.
485
486 Only used when the interface is DEBUGREG. */
6b09f134 487 std::optional<long> requested_wp_val;
227c0bf4
PFC
488};
489
f6ac5f3d
PA
490struct ppc_linux_nat_target final : public linux_nat_target
491{
492 /* Add our register access methods. */
493 void fetch_registers (struct regcache *, int) override;
494 void store_registers (struct regcache *, int) override;
495
496 /* Add our breakpoint/watchpoint methods. */
497 int can_use_hw_breakpoint (enum bptype, int, int) override;
498
499 int insert_hw_breakpoint (struct gdbarch *, struct bp_target_info *)
500 override;
501
502 int remove_hw_breakpoint (struct gdbarch *, struct bp_target_info *)
503 override;
504
505 int region_ok_for_hw_watchpoint (CORE_ADDR, int) override;
506
507 int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
508 struct expression *) override;
509
510 int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type,
511 struct expression *) override;
512
513 int insert_mask_watchpoint (CORE_ADDR, CORE_ADDR, enum target_hw_bp_type)
514 override;
515
516 int remove_mask_watchpoint (CORE_ADDR, CORE_ADDR, enum target_hw_bp_type)
517 override;
518
57810aa7 519 bool watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int) override;
f6ac5f3d 520
57810aa7 521 bool can_accel_watchpoint_condition (CORE_ADDR, int, int, struct expression *)
f6ac5f3d
PA
522 override;
523
524 int masked_watch_num_registers (CORE_ADDR, CORE_ADDR) override;
525
526 int ranged_break_num_registers () override;
527
528 const struct target_desc *read_description () override;
529
3fe639b8
SM
530 int auxv_parse (const gdb_byte **readptr,
531 const gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
f6ac5f3d 532 override;
135340af
PA
533
534 /* Override linux_nat_target low methods. */
227c0bf4
PFC
535 bool low_stopped_by_watchpoint () override;
536
537 bool low_stopped_data_address (CORE_ADDR *) override;
538
135340af 539 void low_new_thread (struct lwp_info *lp) override;
227c0bf4
PFC
540
541 void low_delete_thread (arch_lwp_info *) override;
542
543 void low_new_fork (struct lwp_info *, pid_t) override;
544
545 void low_new_clone (struct lwp_info *, pid_t) override;
546
547 void low_forget_process (pid_t pid) override;
548
549 void low_prepare_to_resume (struct lwp_info *) override;
550
551private:
552
553 void copy_thread_dreg_state (const ptid_t &parent_ptid,
554 const ptid_t &child_ptid);
555
556 void mark_thread_stale (struct lwp_info *lp);
557
558 void mark_debug_registers_changed (pid_t pid);
559
560 void register_hw_breakpoint (pid_t pid,
561 const struct ppc_hw_breakpoint &bp);
562
563 void clear_hw_breakpoint (pid_t pid,
564 const struct ppc_hw_breakpoint &a);
565
566 void register_wp (pid_t pid, long wp_value);
567
568 void clear_wp (pid_t pid);
569
570 bool can_use_watchpoint_cond_accel (void);
571
572 void calculate_dvc (CORE_ADDR addr, int len,
573 CORE_ADDR data_value,
574 uint32_t *condition_mode,
575 uint64_t *condition_value);
576
577 int check_condition (CORE_ADDR watch_addr,
578 struct expression *cond,
579 CORE_ADDR *data_value, int *len);
580
581 int num_memory_accesses (const std::vector<value_ref_ptr> &chain);
582
583 int get_trigger_type (enum target_hw_bp_type type);
584
585 void create_watchpoint_request (struct ppc_hw_breakpoint *p,
586 CORE_ADDR addr,
587 int len,
588 enum target_hw_bp_type type,
589 struct expression *cond,
590 int insert);
591
592 bool hwdebug_point_cmp (const struct ppc_hw_breakpoint &a,
593 const struct ppc_hw_breakpoint &b);
594
595 void init_arch_lwp_info (struct lwp_info *lp);
596
597 arch_lwp_info *get_arch_lwp_info (struct lwp_info *lp);
598
599 /* The ptrace interface we'll use to install hardware watchpoints and
600 breakpoints (debug registers). */
601 ppc_linux_dreg_interface m_dreg_interface;
602
603 /* A map from pids to structs containing info specific to each
604 process. */
605 std::unordered_map<pid_t, ppc_linux_process_info> m_process_info;
606
607 /* Callable object to hash ptids by their lwp number. */
608 struct ptid_hash
609 {
610 std::size_t operator() (const ptid_t &ptid) const
611 {
612 return std::hash<long>{} (ptid.lwp ());
613 }
614 };
615
616 /* A map from ptid_t objects to a list of pairs of slots and hardware
617 breakpoint objects. This keeps track of which hardware breakpoints
618 and watchpoints were last installed in each slot of each thread.
619
620 Only used when the interface is HWDEBUG. */
621 std::unordered_map <ptid_t,
622 std::list<std::pair<long, ppc_hw_breakpoint>>,
623 ptid_hash> m_installed_hw_bps;
f6ac5f3d
PA
624};
625
626static ppc_linux_nat_target the_ppc_linux_nat_target;
627
16333c4f
EZ
628/* registers layout, as presented by the ptrace interface:
629PT_R0, PT_R1, PT_R2, PT_R3, PT_R4, PT_R5, PT_R6, PT_R7,
630PT_R8, PT_R9, PT_R10, PT_R11, PT_R12, PT_R13, PT_R14, PT_R15,
631PT_R16, PT_R17, PT_R18, PT_R19, PT_R20, PT_R21, PT_R22, PT_R23,
632PT_R24, PT_R25, PT_R26, PT_R27, PT_R28, PT_R29, PT_R30, PT_R31,
0df8b418
MS
633PT_FPR0, PT_FPR0 + 2, PT_FPR0 + 4, PT_FPR0 + 6,
634PT_FPR0 + 8, PT_FPR0 + 10, PT_FPR0 + 12, PT_FPR0 + 14,
635PT_FPR0 + 16, PT_FPR0 + 18, PT_FPR0 + 20, PT_FPR0 + 22,
636PT_FPR0 + 24, PT_FPR0 + 26, PT_FPR0 + 28, PT_FPR0 + 30,
637PT_FPR0 + 32, PT_FPR0 + 34, PT_FPR0 + 36, PT_FPR0 + 38,
638PT_FPR0 + 40, PT_FPR0 + 42, PT_FPR0 + 44, PT_FPR0 + 46,
639PT_FPR0 + 48, PT_FPR0 + 50, PT_FPR0 + 52, PT_FPR0 + 54,
640PT_FPR0 + 56, PT_FPR0 + 58, PT_FPR0 + 60, PT_FPR0 + 62,
16333c4f 641PT_NIP, PT_MSR, PT_CCR, PT_LNK, PT_CTR, PT_XER, PT_MQ */
c877c8e6 642
45229ea4 643static int
e101270f 644ppc_register_u_addr (struct gdbarch *gdbarch, int regno)
c877c8e6 645{
16333c4f 646 int u_addr = -1;
08106042 647 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
56d0d96a
AC
648 /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace
649 interface, and not the wordsize of the program's ABI. */
411cb3f9 650 int wordsize = sizeof (long);
16333c4f 651
0df8b418 652 /* General purpose registers occupy 1 slot each in the buffer. */
8bf659e8
JB
653 if (regno >= tdep->ppc_gp0_regnum
654 && regno < tdep->ppc_gp0_regnum + ppc_num_gprs)
26e75e5c 655 u_addr = ((regno - tdep->ppc_gp0_regnum + PT_R0) * wordsize);
16333c4f 656
49ff75ad
JB
657 /* Floating point regs: eight bytes each in both 32- and 64-bit
658 ptrace interfaces. Thus, two slots each in 32-bit interface, one
659 slot each in 64-bit interface. */
383f0f5b
JB
660 if (tdep->ppc_fp0_regnum >= 0
661 && regno >= tdep->ppc_fp0_regnum
366f009f
JB
662 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
663 u_addr = (PT_FPR0 * wordsize) + ((regno - tdep->ppc_fp0_regnum) * 8);
16333c4f 664
0df8b418 665 /* UISA special purpose registers: 1 slot each. */
e101270f 666 if (regno == gdbarch_pc_regnum (gdbarch))
49ff75ad 667 u_addr = PT_NIP * wordsize;
dc5cfeb6 668 if (regno == tdep->ppc_lr_regnum)
49ff75ad 669 u_addr = PT_LNK * wordsize;
dc5cfeb6 670 if (regno == tdep->ppc_cr_regnum)
49ff75ad 671 u_addr = PT_CCR * wordsize;
dc5cfeb6 672 if (regno == tdep->ppc_xer_regnum)
49ff75ad 673 u_addr = PT_XER * wordsize;
dc5cfeb6 674 if (regno == tdep->ppc_ctr_regnum)
49ff75ad 675 u_addr = PT_CTR * wordsize;
f8c59253 676#ifdef PT_MQ
dc5cfeb6 677 if (regno == tdep->ppc_mq_regnum)
49ff75ad 678 u_addr = PT_MQ * wordsize;
f8c59253 679#endif
dc5cfeb6 680 if (regno == tdep->ppc_ps_regnum)
49ff75ad 681 u_addr = PT_MSR * wordsize;
7284e1be
UW
682 if (regno == PPC_ORIG_R3_REGNUM)
683 u_addr = PT_ORIG_R3 * wordsize;
684 if (regno == PPC_TRAP_REGNUM)
685 u_addr = PT_TRAP * wordsize;
383f0f5b
JB
686 if (tdep->ppc_fpscr_regnum >= 0
687 && regno == tdep->ppc_fpscr_regnum)
8f135812
AC
688 {
689 /* NOTE: cagney/2005-02-08: On some 64-bit GNU/Linux systems the
690 kernel headers incorrectly contained the 32-bit definition of
691 PT_FPSCR. For the 32-bit definition, floating-point
692 registers occupy two 32-bit "slots", and the FPSCR lives in
69abc51c 693 the second half of such a slot-pair (hence +1). For 64-bit,
8f135812
AC
694 the FPSCR instead occupies the full 64-bit 2-word-slot and
695 hence no adjustment is necessary. Hack around this. */
696 if (wordsize == 8 && PT_FPSCR == (48 + 32 + 1))
697 u_addr = (48 + 32) * wordsize;
69abc51c
TJB
698 /* If the FPSCR is 64-bit wide, we need to fetch the whole 64-bit
699 slot and not just its second word. The PT_FPSCR supplied when
700 GDB is compiled as a 32-bit app doesn't reflect this. */
701 else if (wordsize == 4 && register_size (gdbarch, regno) == 8
702 && PT_FPSCR == (48 + 2*32 + 1))
703 u_addr = (48 + 2*32) * wordsize;
8f135812
AC
704 else
705 u_addr = PT_FPSCR * wordsize;
706 }
16333c4f 707 return u_addr;
c877c8e6
KB
708}
709
604c2f83
LM
710/* The Linux kernel ptrace interface for POWER7 VSX registers uses the
711 registers set mechanism, as opposed to the interface for all the
712 other registers, that stores/fetches each register individually. */
713static void
2c3305f6 714fetch_vsx_registers (struct regcache *regcache, int tid, int regno)
604c2f83
LM
715{
716 int ret;
717 gdb_vsxregset_t regs;
2c3305f6 718 const struct regset *vsxregset = ppc_linux_vsxregset ();
604c2f83
LM
719
720 ret = ptrace (PTRACE_GETVSXREGS, tid, 0, &regs);
721 if (ret < 0)
722 {
723 if (errno == EIO)
724 {
725 have_ptrace_getsetvsxregs = 0;
726 return;
727 }
2c3305f6 728 perror_with_name (_("Unable to fetch VSX registers"));
604c2f83
LM
729 }
730
2c3305f6
PFC
731 vsxregset->supply_regset (vsxregset, regcache, regno, &regs,
732 PPC_LINUX_SIZEOF_VSXREGSET);
604c2f83
LM
733}
734
9abe5450
EZ
735/* The Linux kernel ptrace interface for AltiVec registers uses the
736 registers set mechanism, as opposed to the interface for all the
737 other registers, that stores/fetches each register individually. */
738static void
1d75a658
PFC
739fetch_altivec_registers (struct regcache *regcache, int tid,
740 int regno)
9abe5450
EZ
741{
742 int ret;
9abe5450 743 gdb_vrregset_t regs;
ac7936df 744 struct gdbarch *gdbarch = regcache->arch ();
1d75a658 745 const struct regset *vrregset = ppc_linux_vrregset (gdbarch);
9abe5450
EZ
746
747 ret = ptrace (PTRACE_GETVRREGS, tid, 0, &regs);
748 if (ret < 0)
749 {
750 if (errno == EIO)
dda83cd7
SM
751 {
752 have_ptrace_getvrregs = 0;
753 return;
754 }
1d75a658 755 perror_with_name (_("Unable to fetch AltiVec registers"));
9abe5450 756 }
1d75a658
PFC
757
758 vrregset->supply_regset (vrregset, regcache, regno, &regs,
759 PPC_LINUX_SIZEOF_VRREGSET);
9abe5450
EZ
760}
761
01904826
JB
762/* Fetch the top 32 bits of TID's general-purpose registers and the
763 SPE-specific registers, and place the results in EVRREGSET. If we
764 don't support PTRACE_GETEVRREGS, then just fill EVRREGSET with
765 zeros.
766
767 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
768 PTRACE_SETEVRREGS requests are supported is isolated here, and in
769 set_spe_registers. */
770static void
771get_spe_registers (int tid, struct gdb_evrregset_t *evrregset)
772{
773 if (have_ptrace_getsetevrregs)
774 {
775 if (ptrace (PTRACE_GETEVRREGS, tid, 0, evrregset) >= 0)
dda83cd7 776 return;
01904826 777 else
dda83cd7
SM
778 {
779 /* EIO means that the PTRACE_GETEVRREGS request isn't supported;
780 we just return zeros. */
781 if (errno == EIO)
782 have_ptrace_getsetevrregs = 0;
783 else
784 /* Anything else needs to be reported. */
785 perror_with_name (_("Unable to fetch SPE registers"));
786 }
01904826
JB
787 }
788
789 memset (evrregset, 0, sizeof (*evrregset));
790}
791
6ced10dd
JB
792/* Supply values from TID for SPE-specific raw registers: the upper
793 halves of the GPRs, the accumulator, and the spefscr. REGNO must
794 be the number of an upper half register, acc, spefscr, or -1 to
795 supply the values of all registers. */
01904826 796static void
56be3814 797fetch_spe_register (struct regcache *regcache, int tid, int regno)
01904826 798{
ac7936df 799 struct gdbarch *gdbarch = regcache->arch ();
08106042 800 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
01904826
JB
801 struct gdb_evrregset_t evrregs;
802
6ced10dd 803 gdb_assert (sizeof (evrregs.evr[0])
dda83cd7 804 == register_size (gdbarch, tdep->ppc_ev0_upper_regnum));
6ced10dd 805 gdb_assert (sizeof (evrregs.acc)
dda83cd7 806 == register_size (gdbarch, tdep->ppc_acc_regnum));
6ced10dd 807 gdb_assert (sizeof (evrregs.spefscr)
dda83cd7 808 == register_size (gdbarch, tdep->ppc_spefscr_regnum));
6ced10dd 809
01904826
JB
810 get_spe_registers (tid, &evrregs);
811
6ced10dd 812 if (regno == -1)
01904826 813 {
6ced10dd
JB
814 int i;
815
816 for (i = 0; i < ppc_num_gprs; i++)
dda83cd7 817 regcache->raw_supply (tdep->ppc_ev0_upper_regnum + i, &evrregs.evr[i]);
01904826 818 }
6ced10dd 819 else if (tdep->ppc_ev0_upper_regnum <= regno
dda83cd7 820 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
73e1c03f
SM
821 regcache->raw_supply (regno,
822 &evrregs.evr[regno - tdep->ppc_ev0_upper_regnum]);
6ced10dd
JB
823
824 if (regno == -1
825 || regno == tdep->ppc_acc_regnum)
73e1c03f 826 regcache->raw_supply (tdep->ppc_acc_regnum, &evrregs.acc);
6ced10dd
JB
827
828 if (regno == -1
829 || regno == tdep->ppc_spefscr_regnum)
73e1c03f 830 regcache->raw_supply (tdep->ppc_spefscr_regnum, &evrregs.spefscr);
01904826
JB
831}
832
7ca18ed6
EBM
833/* Use ptrace to fetch all registers from the register set with note
834 type REGSET_ID, size REGSIZE, and layout described by REGSET, from
835 process/thread TID and supply their values to REGCACHE. If ptrace
836 returns ENODATA to indicate the regset is unavailable, mark the
837 registers as unavailable in REGCACHE. */
838
839static void
840fetch_regset (struct regcache *regcache, int tid,
841 int regset_id, int regsetsize, const struct regset *regset)
842{
843 void *buf = alloca (regsetsize);
844 struct iovec iov;
845
846 iov.iov_base = buf;
847 iov.iov_len = regsetsize;
848
849 if (ptrace (PTRACE_GETREGSET, tid, regset_id, &iov) < 0)
850 {
851 if (errno == ENODATA)
852 regset->supply_regset (regset, regcache, -1, NULL, regsetsize);
853 else
854 perror_with_name (_("Couldn't get register set"));
855 }
856 else
857 regset->supply_regset (regset, regcache, -1, buf, regsetsize);
858}
859
860/* Use ptrace to store register REGNUM of the regset with note type
861 REGSET_ID, size REGSETSIZE, and layout described by REGSET, from
862 REGCACHE back to process/thread TID. If REGNUM is -1 all registers
863 in the set are collected and stored. */
864
865static void
866store_regset (const struct regcache *regcache, int tid, int regnum,
867 int regset_id, int regsetsize, const struct regset *regset)
868{
869 void *buf = alloca (regsetsize);
870 struct iovec iov;
871
872 iov.iov_base = buf;
873 iov.iov_len = regsetsize;
874
875 /* Make sure that the buffer that will be stored has up to date values
876 for the registers that won't be collected. */
877 if (ptrace (PTRACE_GETREGSET, tid, regset_id, &iov) < 0)
878 perror_with_name (_("Couldn't get register set"));
879
880 regset->collect_regset (regset, regcache, regnum, buf, regsetsize);
881
882 if (ptrace (PTRACE_SETREGSET, tid, regset_id, &iov) < 0)
883 perror_with_name (_("Couldn't set register set"));
884}
885
886/* Check whether the kernel provides a register set with number
887 REGSET_ID of size REGSETSIZE for process/thread TID. */
888
889static bool
890check_regset (int tid, int regset_id, int regsetsize)
891{
892 void *buf = alloca (regsetsize);
893 struct iovec iov;
894
895 iov.iov_base = buf;
896 iov.iov_len = regsetsize;
897
898 if (ptrace (PTRACE_GETREGSET, tid, regset_id, &iov) >= 0
899 || errno == ENODATA)
900 return true;
901 else
902 return false;
903}
904
45229ea4 905static void
56be3814 906fetch_register (struct regcache *regcache, int tid, int regno)
45229ea4 907{
ac7936df 908 struct gdbarch *gdbarch = regcache->arch ();
08106042 909 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
45229ea4 910 /* This isn't really an address. But ptrace thinks of it as one. */
e101270f 911 CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno);
4a19ea35 912 int bytes_transferred;
0f068fb5 913 gdb_byte buf[PPC_MAX_REGISTER_SIZE];
45229ea4 914
be8626e0 915 if (altivec_register_p (gdbarch, regno))
9abe5450
EZ
916 {
917 /* If this is the first time through, or if it is not the first
dda83cd7
SM
918 time through, and we have confirmed that there is kernel
919 support for such a ptrace request, then go and fetch the
920 register. */
9abe5450
EZ
921 if (have_ptrace_getvrregs)
922 {
dda83cd7
SM
923 fetch_altivec_registers (regcache, tid, regno);
924 return;
9abe5450
EZ
925 }
926 /* If we have discovered that there is no ptrace support for
dda83cd7
SM
927 AltiVec registers, fall through and return zeroes, because
928 regaddr will be -1 in this case. */
9abe5450 929 }
3d907528 930 else if (vsx_register_p (gdbarch, regno))
604c2f83
LM
931 {
932 if (have_ptrace_getsetvsxregs)
933 {
2c3305f6 934 fetch_vsx_registers (regcache, tid, regno);
604c2f83
LM
935 return;
936 }
937 }
be8626e0 938 else if (spe_register_p (gdbarch, regno))
01904826 939 {
56be3814 940 fetch_spe_register (regcache, tid, regno);
01904826
JB
941 return;
942 }
7ca18ed6
EBM
943 else if (regno == PPC_DSCR_REGNUM)
944 {
945 gdb_assert (tdep->ppc_dscr_regnum != -1);
946
947 fetch_regset (regcache, tid, NT_PPC_DSCR,
948 PPC_LINUX_SIZEOF_DSCRREGSET,
949 &ppc32_linux_dscrregset);
950 return;
951 }
952 else if (regno == PPC_PPR_REGNUM)
953 {
954 gdb_assert (tdep->ppc_ppr_regnum != -1);
955
956 fetch_regset (regcache, tid, NT_PPC_PPR,
957 PPC_LINUX_SIZEOF_PPRREGSET,
958 &ppc32_linux_pprregset);
959 return;
960 }
f2cf6173
EBM
961 else if (regno == PPC_TAR_REGNUM)
962 {
963 gdb_assert (tdep->ppc_tar_regnum != -1);
964
965 fetch_regset (regcache, tid, NT_PPC_TAR,
966 PPC_LINUX_SIZEOF_TARREGSET,
967 &ppc32_linux_tarregset);
968 return;
969 }
232bfb86
EBM
970 else if (PPC_IS_EBB_REGNUM (regno))
971 {
972 gdb_assert (tdep->have_ebb);
973
974 fetch_regset (regcache, tid, NT_PPC_EBB,
975 PPC_LINUX_SIZEOF_EBBREGSET,
976 &ppc32_linux_ebbregset);
977 return;
978 }
979 else if (PPC_IS_PMU_REGNUM (regno))
980 {
981 gdb_assert (tdep->ppc_mmcr0_regnum != -1);
982
983 fetch_regset (regcache, tid, NT_PPC_PMU,
984 PPC_LINUX_SIZEOF_PMUREGSET,
985 &ppc32_linux_pmuregset);
986 return;
987 }
8d619c01
EBM
988 else if (PPC_IS_TMSPR_REGNUM (regno))
989 {
990 gdb_assert (tdep->have_htm_spr);
991
992 fetch_regset (regcache, tid, NT_PPC_TM_SPR,
993 PPC_LINUX_SIZEOF_TM_SPRREGSET,
994 &ppc32_linux_tm_sprregset);
995 return;
996 }
997 else if (PPC_IS_CKPTGP_REGNUM (regno))
998 {
999 gdb_assert (tdep->have_htm_core);
1000
1001 const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
1002 fetch_regset (regcache, tid, NT_PPC_TM_CGPR,
1003 (tdep->wordsize == 4?
1004 PPC32_LINUX_SIZEOF_CGPRREGSET
1005 : PPC64_LINUX_SIZEOF_CGPRREGSET),
1006 cgprregset);
1007 return;
1008 }
1009 else if (PPC_IS_CKPTFP_REGNUM (regno))
1010 {
1011 gdb_assert (tdep->have_htm_fpu);
1012
1013 fetch_regset (regcache, tid, NT_PPC_TM_CFPR,
1014 PPC_LINUX_SIZEOF_CFPRREGSET,
1015 &ppc32_linux_cfprregset);
1016 return;
1017 }
1018 else if (PPC_IS_CKPTVMX_REGNUM (regno))
1019 {
1020 gdb_assert (tdep->have_htm_altivec);
1021
1022 const struct regset *cvmxregset = ppc_linux_cvmxregset (gdbarch);
1023 fetch_regset (regcache, tid, NT_PPC_TM_CVMX,
1024 PPC_LINUX_SIZEOF_CVMXREGSET,
1025 cvmxregset);
1026 return;
1027 }
1028 else if (PPC_IS_CKPTVSX_REGNUM (regno))
1029 {
1030 gdb_assert (tdep->have_htm_vsx);
1031
1032 fetch_regset (regcache, tid, NT_PPC_TM_CVSX,
1033 PPC_LINUX_SIZEOF_CVSXREGSET,
1034 &ppc32_linux_cvsxregset);
1035 return;
1036 }
1037 else if (regno == PPC_CPPR_REGNUM)
1038 {
1039 gdb_assert (tdep->ppc_cppr_regnum != -1);
1040
1041 fetch_regset (regcache, tid, NT_PPC_TM_CPPR,
1042 PPC_LINUX_SIZEOF_CPPRREGSET,
1043 &ppc32_linux_cpprregset);
1044 return;
1045 }
1046 else if (regno == PPC_CDSCR_REGNUM)
1047 {
1048 gdb_assert (tdep->ppc_cdscr_regnum != -1);
1049
1050 fetch_regset (regcache, tid, NT_PPC_TM_CDSCR,
1051 PPC_LINUX_SIZEOF_CDSCRREGSET,
1052 &ppc32_linux_cdscrregset);
1053 return;
1054 }
1055 else if (regno == PPC_CTAR_REGNUM)
1056 {
1057 gdb_assert (tdep->ppc_ctar_regnum != -1);
1058
1059 fetch_regset (regcache, tid, NT_PPC_TM_CTAR,
1060 PPC_LINUX_SIZEOF_CTARREGSET,
1061 &ppc32_linux_ctarregset);
1062 return;
1063 }
9abe5450 1064
45229ea4
EZ
1065 if (regaddr == -1)
1066 {
40a6adc1 1067 memset (buf, '\0', register_size (gdbarch, regno)); /* Supply zeroes */
73e1c03f 1068 regcache->raw_supply (regno, buf);
45229ea4
EZ
1069 return;
1070 }
1071
411cb3f9 1072 /* Read the raw register using sizeof(long) sized chunks. On a
56d0d96a
AC
1073 32-bit platform, 64-bit floating-point registers will require two
1074 transfers. */
4a19ea35 1075 for (bytes_transferred = 0;
40a6adc1 1076 bytes_transferred < register_size (gdbarch, regno);
411cb3f9 1077 bytes_transferred += sizeof (long))
45229ea4 1078 {
11fde611
JK
1079 long l;
1080
45229ea4 1081 errno = 0;
11fde611 1082 l = ptrace (PTRACE_PEEKUSER, tid, (PTRACE_TYPE_ARG3) regaddr, 0);
411cb3f9 1083 regaddr += sizeof (long);
45229ea4
EZ
1084 if (errno != 0)
1085 {
dda83cd7 1086 char message[128];
8c042590
PM
1087 xsnprintf (message, sizeof (message), "reading register %s (#%d)",
1088 gdbarch_register_name (gdbarch, regno), regno);
bc97b3ba 1089 perror_with_name (message);
45229ea4 1090 }
11fde611 1091 memcpy (&buf[bytes_transferred], &l, sizeof (l));
45229ea4 1092 }
56d0d96a 1093
4a19ea35
JB
1094 /* Now supply the register. Keep in mind that the regcache's idea
1095 of the register's size may not be a multiple of sizeof
411cb3f9 1096 (long). */
40a6adc1 1097 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
4a19ea35
JB
1098 {
1099 /* Little-endian values are always found at the left end of the
dda83cd7 1100 bytes transferred. */
73e1c03f 1101 regcache->raw_supply (regno, buf);
4a19ea35 1102 }
40a6adc1 1103 else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4a19ea35
JB
1104 {
1105 /* Big-endian values are found at the right end of the bytes
dda83cd7 1106 transferred. */
40a6adc1 1107 size_t padding = (bytes_transferred - register_size (gdbarch, regno));
73e1c03f 1108 regcache->raw_supply (regno, buf + padding);
4a19ea35
JB
1109 }
1110 else
f34652de 1111 internal_error (_("fetch_register: unexpected byte order: %d"),
dda83cd7 1112 gdbarch_byte_order (gdbarch));
45229ea4
EZ
1113}
1114
1dfe79e8
SDJ
1115/* This function actually issues the request to ptrace, telling
1116 it to get all general-purpose registers and put them into the
1117 specified regset.
1118
1119 If the ptrace request does not exist, this function returns 0
1120 and properly sets the have_ptrace_* flag. If the request fails,
1121 this function calls perror_with_name. Otherwise, if the request
1122 succeeds, then the regcache gets filled and 1 is returned. */
1123static int
1124fetch_all_gp_regs (struct regcache *regcache, int tid)
1125{
1dfe79e8
SDJ
1126 gdb_gregset_t gregset;
1127
1128 if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0)
1129 {
1130 if (errno == EIO)
dda83cd7
SM
1131 {
1132 have_ptrace_getsetregs = 0;
1133 return 0;
1134 }
deb70aa0 1135 perror_with_name (_("Couldn't get general-purpose registers"));
1dfe79e8
SDJ
1136 }
1137
1138 supply_gregset (regcache, (const gdb_gregset_t *) &gregset);
1139
1140 return 1;
1141}
1142
1143/* This is a wrapper for the fetch_all_gp_regs function. It is
1144 responsible for verifying if this target has the ptrace request
1145 that can be used to fetch all general-purpose registers at one
1146 shot. If it doesn't, then we should fetch them using the
1147 old-fashioned way, which is to iterate over the registers and
1148 request them one by one. */
1149static void
1150fetch_gp_regs (struct regcache *regcache, int tid)
1151{
ac7936df 1152 struct gdbarch *gdbarch = regcache->arch ();
08106042 1153 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1dfe79e8
SDJ
1154 int i;
1155
1156 if (have_ptrace_getsetregs)
1157 if (fetch_all_gp_regs (regcache, tid))
1158 return;
1159
1160 /* If we've hit this point, it doesn't really matter which
1161 architecture we are using. We just need to read the
1162 registers in the "old-fashioned way". */
1163 for (i = 0; i < ppc_num_gprs; i++)
1164 fetch_register (regcache, tid, tdep->ppc_gp0_regnum + i);
1165}
1166
1167/* This function actually issues the request to ptrace, telling
1168 it to get all floating-point registers and put them into the
1169 specified regset.
1170
1171 If the ptrace request does not exist, this function returns 0
1172 and properly sets the have_ptrace_* flag. If the request fails,
1173 this function calls perror_with_name. Otherwise, if the request
1174 succeeds, then the regcache gets filled and 1 is returned. */
1175static int
1176fetch_all_fp_regs (struct regcache *regcache, int tid)
1177{
1178 gdb_fpregset_t fpregs;
1179
1180 if (ptrace (PTRACE_GETFPREGS, tid, 0, (void *) &fpregs) < 0)
1181 {
1182 if (errno == EIO)
dda83cd7
SM
1183 {
1184 have_ptrace_getsetfpregs = 0;
1185 return 0;
1186 }
deb70aa0 1187 perror_with_name (_("Couldn't get floating-point registers"));
1dfe79e8
SDJ
1188 }
1189
1190 supply_fpregset (regcache, (const gdb_fpregset_t *) &fpregs);
1191
1192 return 1;
1193}
1194
1195/* This is a wrapper for the fetch_all_fp_regs function. It is
1196 responsible for verifying if this target has the ptrace request
1197 that can be used to fetch all floating-point registers at one
1198 shot. If it doesn't, then we should fetch them using the
1199 old-fashioned way, which is to iterate over the registers and
1200 request them one by one. */
1201static void
1202fetch_fp_regs (struct regcache *regcache, int tid)
1203{
ac7936df 1204 struct gdbarch *gdbarch = regcache->arch ();
08106042 1205 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1dfe79e8
SDJ
1206 int i;
1207
1208 if (have_ptrace_getsetfpregs)
1209 if (fetch_all_fp_regs (regcache, tid))
1210 return;
1211
1212 /* If we've hit this point, it doesn't really matter which
1213 architecture we are using. We just need to read the
1214 registers in the "old-fashioned way". */
1215 for (i = 0; i < ppc_num_fprs; i++)
1216 fetch_register (regcache, tid, tdep->ppc_fp0_regnum + i);
1217}
1218
45229ea4 1219static void
56be3814 1220fetch_ppc_registers (struct regcache *regcache, int tid)
45229ea4 1221{
ac7936df 1222 struct gdbarch *gdbarch = regcache->arch ();
08106042 1223 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
9abe5450 1224
1dfe79e8 1225 fetch_gp_regs (regcache, tid);
32b99774 1226 if (tdep->ppc_fp0_regnum >= 0)
1dfe79e8 1227 fetch_fp_regs (regcache, tid);
40a6adc1 1228 fetch_register (regcache, tid, gdbarch_pc_regnum (gdbarch));
32b99774 1229 if (tdep->ppc_ps_regnum != -1)
56be3814 1230 fetch_register (regcache, tid, tdep->ppc_ps_regnum);
32b99774 1231 if (tdep->ppc_cr_regnum != -1)
56be3814 1232 fetch_register (regcache, tid, tdep->ppc_cr_regnum);
32b99774 1233 if (tdep->ppc_lr_regnum != -1)
56be3814 1234 fetch_register (regcache, tid, tdep->ppc_lr_regnum);
32b99774 1235 if (tdep->ppc_ctr_regnum != -1)
56be3814 1236 fetch_register (regcache, tid, tdep->ppc_ctr_regnum);
32b99774 1237 if (tdep->ppc_xer_regnum != -1)
56be3814 1238 fetch_register (regcache, tid, tdep->ppc_xer_regnum);
e3f36dbd 1239 if (tdep->ppc_mq_regnum != -1)
56be3814 1240 fetch_register (regcache, tid, tdep->ppc_mq_regnum);
7284e1be
UW
1241 if (ppc_linux_trap_reg_p (gdbarch))
1242 {
1243 fetch_register (regcache, tid, PPC_ORIG_R3_REGNUM);
1244 fetch_register (regcache, tid, PPC_TRAP_REGNUM);
1245 }
32b99774 1246 if (tdep->ppc_fpscr_regnum != -1)
56be3814 1247 fetch_register (regcache, tid, tdep->ppc_fpscr_regnum);
9abe5450
EZ
1248 if (have_ptrace_getvrregs)
1249 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
1d75a658 1250 fetch_altivec_registers (regcache, tid, -1);
604c2f83
LM
1251 if (have_ptrace_getsetvsxregs)
1252 if (tdep->ppc_vsr0_upper_regnum != -1)
2c3305f6 1253 fetch_vsx_registers (regcache, tid, -1);
6ced10dd 1254 if (tdep->ppc_ev0_upper_regnum >= 0)
56be3814 1255 fetch_spe_register (regcache, tid, -1);
7ca18ed6
EBM
1256 if (tdep->ppc_ppr_regnum != -1)
1257 fetch_regset (regcache, tid, NT_PPC_PPR,
1258 PPC_LINUX_SIZEOF_PPRREGSET,
1259 &ppc32_linux_pprregset);
1260 if (tdep->ppc_dscr_regnum != -1)
1261 fetch_regset (regcache, tid, NT_PPC_DSCR,
1262 PPC_LINUX_SIZEOF_DSCRREGSET,
1263 &ppc32_linux_dscrregset);
f2cf6173
EBM
1264 if (tdep->ppc_tar_regnum != -1)
1265 fetch_regset (regcache, tid, NT_PPC_TAR,
1266 PPC_LINUX_SIZEOF_TARREGSET,
1267 &ppc32_linux_tarregset);
232bfb86
EBM
1268 if (tdep->have_ebb)
1269 fetch_regset (regcache, tid, NT_PPC_EBB,
1270 PPC_LINUX_SIZEOF_EBBREGSET,
1271 &ppc32_linux_ebbregset);
1272 if (tdep->ppc_mmcr0_regnum != -1)
1273 fetch_regset (regcache, tid, NT_PPC_PMU,
1274 PPC_LINUX_SIZEOF_PMUREGSET,
1275 &ppc32_linux_pmuregset);
8d619c01
EBM
1276 if (tdep->have_htm_spr)
1277 fetch_regset (regcache, tid, NT_PPC_TM_SPR,
1278 PPC_LINUX_SIZEOF_TM_SPRREGSET,
1279 &ppc32_linux_tm_sprregset);
1280 if (tdep->have_htm_core)
1281 {
1282 const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
1283 fetch_regset (regcache, tid, NT_PPC_TM_CGPR,
1284 (tdep->wordsize == 4?
1285 PPC32_LINUX_SIZEOF_CGPRREGSET
1286 : PPC64_LINUX_SIZEOF_CGPRREGSET),
1287 cgprregset);
1288 }
1289 if (tdep->have_htm_fpu)
1290 fetch_regset (regcache, tid, NT_PPC_TM_CFPR,
1291 PPC_LINUX_SIZEOF_CFPRREGSET,
1292 &ppc32_linux_cfprregset);
1293 if (tdep->have_htm_altivec)
1294 {
1295 const struct regset *cvmxregset = ppc_linux_cvmxregset (gdbarch);
1296 fetch_regset (regcache, tid, NT_PPC_TM_CVMX,
1297 PPC_LINUX_SIZEOF_CVMXREGSET,
1298 cvmxregset);
1299 }
1300 if (tdep->have_htm_vsx)
1301 fetch_regset (regcache, tid, NT_PPC_TM_CVSX,
1302 PPC_LINUX_SIZEOF_CVSXREGSET,
1303 &ppc32_linux_cvsxregset);
1304 if (tdep->ppc_cppr_regnum != -1)
1305 fetch_regset (regcache, tid, NT_PPC_TM_CPPR,
1306 PPC_LINUX_SIZEOF_CPPRREGSET,
1307 &ppc32_linux_cpprregset);
1308 if (tdep->ppc_cdscr_regnum != -1)
1309 fetch_regset (regcache, tid, NT_PPC_TM_CDSCR,
1310 PPC_LINUX_SIZEOF_CDSCRREGSET,
1311 &ppc32_linux_cdscrregset);
1312 if (tdep->ppc_ctar_regnum != -1)
1313 fetch_regset (regcache, tid, NT_PPC_TM_CTAR,
1314 PPC_LINUX_SIZEOF_CTARREGSET,
1315 &ppc32_linux_ctarregset);
45229ea4
EZ
1316}
1317
1318/* Fetch registers from the child process. Fetch all registers if
1319 regno == -1, otherwise fetch all general registers or all floating
1320 point registers depending upon the value of regno. */
f6ac5f3d
PA
1321void
1322ppc_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
45229ea4 1323{
222312d3 1324 pid_t tid = get_ptrace_pid (regcache->ptid ());
05f13b9c 1325
9abe5450 1326 if (regno == -1)
56be3814 1327 fetch_ppc_registers (regcache, tid);
45229ea4 1328 else
56be3814 1329 fetch_register (regcache, tid, regno);
45229ea4
EZ
1330}
1331
604c2f83 1332static void
2c3305f6 1333store_vsx_registers (const struct regcache *regcache, int tid, int regno)
604c2f83
LM
1334{
1335 int ret;
1336 gdb_vsxregset_t regs;
2c3305f6 1337 const struct regset *vsxregset = ppc_linux_vsxregset ();
604c2f83 1338
9fe70b4f 1339 ret = ptrace (PTRACE_GETVSXREGS, tid, 0, &regs);
604c2f83
LM
1340 if (ret < 0)
1341 {
1342 if (errno == EIO)
1343 {
1344 have_ptrace_getsetvsxregs = 0;
1345 return;
1346 }
2c3305f6 1347 perror_with_name (_("Unable to fetch VSX registers"));
604c2f83
LM
1348 }
1349
2c3305f6
PFC
1350 vsxregset->collect_regset (vsxregset, regcache, regno, &regs,
1351 PPC_LINUX_SIZEOF_VSXREGSET);
604c2f83
LM
1352
1353 ret = ptrace (PTRACE_SETVSXREGS, tid, 0, &regs);
1354 if (ret < 0)
2c3305f6 1355 perror_with_name (_("Unable to store VSX registers"));
604c2f83
LM
1356}
1357
9abe5450 1358static void
1d75a658
PFC
1359store_altivec_registers (const struct regcache *regcache, int tid,
1360 int regno)
9abe5450
EZ
1361{
1362 int ret;
9abe5450 1363 gdb_vrregset_t regs;
ac7936df 1364 struct gdbarch *gdbarch = regcache->arch ();
1d75a658 1365 const struct regset *vrregset = ppc_linux_vrregset (gdbarch);
9abe5450
EZ
1366
1367 ret = ptrace (PTRACE_GETVRREGS, tid, 0, &regs);
1368 if (ret < 0)
1369 {
1370 if (errno == EIO)
dda83cd7
SM
1371 {
1372 have_ptrace_getvrregs = 0;
1373 return;
1374 }
1d75a658 1375 perror_with_name (_("Unable to fetch AltiVec registers"));
9abe5450
EZ
1376 }
1377
1d75a658
PFC
1378 vrregset->collect_regset (vrregset, regcache, regno, &regs,
1379 PPC_LINUX_SIZEOF_VRREGSET);
9abe5450
EZ
1380
1381 ret = ptrace (PTRACE_SETVRREGS, tid, 0, &regs);
1382 if (ret < 0)
1d75a658 1383 perror_with_name (_("Unable to store AltiVec registers"));
9abe5450
EZ
1384}
1385
85102364 1386/* Assuming TID refers to an SPE process, set the top halves of TID's
01904826
JB
1387 general-purpose registers and its SPE-specific registers to the
1388 values in EVRREGSET. If we don't support PTRACE_SETEVRREGS, do
1389 nothing.
1390
1391 All the logic to deal with whether or not the PTRACE_GETEVRREGS and
1392 PTRACE_SETEVRREGS requests are supported is isolated here, and in
1393 get_spe_registers. */
1394static void
1395set_spe_registers (int tid, struct gdb_evrregset_t *evrregset)
1396{
1397 if (have_ptrace_getsetevrregs)
1398 {
1399 if (ptrace (PTRACE_SETEVRREGS, tid, 0, evrregset) >= 0)
dda83cd7 1400 return;
01904826 1401 else
dda83cd7
SM
1402 {
1403 /* EIO means that the PTRACE_SETEVRREGS request isn't
1404 supported; we fail silently, and don't try the call
1405 again. */
1406 if (errno == EIO)
1407 have_ptrace_getsetevrregs = 0;
1408 else
1409 /* Anything else needs to be reported. */
1410 perror_with_name (_("Unable to set SPE registers"));
1411 }
01904826
JB
1412 }
1413}
1414
6ced10dd
JB
1415/* Write GDB's value for the SPE-specific raw register REGNO to TID.
1416 If REGNO is -1, write the values of all the SPE-specific
1417 registers. */
01904826 1418static void
56be3814 1419store_spe_register (const struct regcache *regcache, int tid, int regno)
01904826 1420{
ac7936df 1421 struct gdbarch *gdbarch = regcache->arch ();
08106042 1422 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
01904826
JB
1423 struct gdb_evrregset_t evrregs;
1424
6ced10dd 1425 gdb_assert (sizeof (evrregs.evr[0])
dda83cd7 1426 == register_size (gdbarch, tdep->ppc_ev0_upper_regnum));
6ced10dd 1427 gdb_assert (sizeof (evrregs.acc)
dda83cd7 1428 == register_size (gdbarch, tdep->ppc_acc_regnum));
6ced10dd 1429 gdb_assert (sizeof (evrregs.spefscr)
dda83cd7 1430 == register_size (gdbarch, tdep->ppc_spefscr_regnum));
01904826 1431
6ced10dd
JB
1432 if (regno == -1)
1433 /* Since we're going to write out every register, the code below
1434 should store to every field of evrregs; if that doesn't happen,
1435 make it obvious by initializing it with suspicious values. */
1436 memset (&evrregs, 42, sizeof (evrregs));
1437 else
1438 /* We can only read and write the entire EVR register set at a
1439 time, so to write just a single register, we do a
1440 read-modify-write maneuver. */
1441 get_spe_registers (tid, &evrregs);
1442
1443 if (regno == -1)
01904826 1444 {
6ced10dd
JB
1445 int i;
1446
1447 for (i = 0; i < ppc_num_gprs; i++)
34a79281
SM
1448 regcache->raw_collect (tdep->ppc_ev0_upper_regnum + i,
1449 &evrregs.evr[i]);
01904826 1450 }
6ced10dd 1451 else if (tdep->ppc_ev0_upper_regnum <= regno
dda83cd7 1452 && regno < tdep->ppc_ev0_upper_regnum + ppc_num_gprs)
34a79281
SM
1453 regcache->raw_collect (regno,
1454 &evrregs.evr[regno - tdep->ppc_ev0_upper_regnum]);
6ced10dd
JB
1455
1456 if (regno == -1
1457 || regno == tdep->ppc_acc_regnum)
34a79281
SM
1458 regcache->raw_collect (tdep->ppc_acc_regnum,
1459 &evrregs.acc);
6ced10dd
JB
1460
1461 if (regno == -1
1462 || regno == tdep->ppc_spefscr_regnum)
34a79281
SM
1463 regcache->raw_collect (tdep->ppc_spefscr_regnum,
1464 &evrregs.spefscr);
01904826
JB
1465
1466 /* Write back the modified register set. */
1467 set_spe_registers (tid, &evrregs);
1468}
1469
45229ea4 1470static void
56be3814 1471store_register (const struct regcache *regcache, int tid, int regno)
45229ea4 1472{
ac7936df 1473 struct gdbarch *gdbarch = regcache->arch ();
08106042 1474 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
45229ea4 1475 /* This isn't really an address. But ptrace thinks of it as one. */
e101270f 1476 CORE_ADDR regaddr = ppc_register_u_addr (gdbarch, regno);
52f0bd74 1477 int i;
4a19ea35 1478 size_t bytes_to_transfer;
0f068fb5 1479 gdb_byte buf[PPC_MAX_REGISTER_SIZE];
45229ea4 1480
be8626e0 1481 if (altivec_register_p (gdbarch, regno))
45229ea4 1482 {
1d75a658 1483 store_altivec_registers (regcache, tid, regno);
45229ea4
EZ
1484 return;
1485 }
3d907528 1486 else if (vsx_register_p (gdbarch, regno))
604c2f83 1487 {
2c3305f6 1488 store_vsx_registers (regcache, tid, regno);
604c2f83
LM
1489 return;
1490 }
be8626e0 1491 else if (spe_register_p (gdbarch, regno))
01904826 1492 {
56be3814 1493 store_spe_register (regcache, tid, regno);
01904826
JB
1494 return;
1495 }
7ca18ed6
EBM
1496 else if (regno == PPC_DSCR_REGNUM)
1497 {
1498 gdb_assert (tdep->ppc_dscr_regnum != -1);
1499
1500 store_regset (regcache, tid, regno, NT_PPC_DSCR,
1501 PPC_LINUX_SIZEOF_DSCRREGSET,
1502 &ppc32_linux_dscrregset);
1503 return;
1504 }
1505 else if (regno == PPC_PPR_REGNUM)
1506 {
1507 gdb_assert (tdep->ppc_ppr_regnum != -1);
1508
1509 store_regset (regcache, tid, regno, NT_PPC_PPR,
1510 PPC_LINUX_SIZEOF_PPRREGSET,
1511 &ppc32_linux_pprregset);
1512 return;
1513 }
f2cf6173
EBM
1514 else if (regno == PPC_TAR_REGNUM)
1515 {
1516 gdb_assert (tdep->ppc_tar_regnum != -1);
1517
1518 store_regset (regcache, tid, regno, NT_PPC_TAR,
1519 PPC_LINUX_SIZEOF_TARREGSET,
1520 &ppc32_linux_tarregset);
1521 return;
1522 }
232bfb86
EBM
1523 else if (PPC_IS_EBB_REGNUM (regno))
1524 {
1525 gdb_assert (tdep->have_ebb);
1526
1527 store_regset (regcache, tid, regno, NT_PPC_EBB,
1528 PPC_LINUX_SIZEOF_EBBREGSET,
1529 &ppc32_linux_ebbregset);
1530 return;
1531 }
1532 else if (PPC_IS_PMU_REGNUM (regno))
1533 {
1534 gdb_assert (tdep->ppc_mmcr0_regnum != -1);
1535
1536 store_regset (regcache, tid, regno, NT_PPC_PMU,
1537 PPC_LINUX_SIZEOF_PMUREGSET,
1538 &ppc32_linux_pmuregset);
1539 return;
1540 }
8d619c01
EBM
1541 else if (PPC_IS_TMSPR_REGNUM (regno))
1542 {
1543 gdb_assert (tdep->have_htm_spr);
1544
1545 store_regset (regcache, tid, regno, NT_PPC_TM_SPR,
1546 PPC_LINUX_SIZEOF_TM_SPRREGSET,
1547 &ppc32_linux_tm_sprregset);
1548 return;
1549 }
1550 else if (PPC_IS_CKPTGP_REGNUM (regno))
1551 {
1552 gdb_assert (tdep->have_htm_core);
1553
1554 const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
1555 store_regset (regcache, tid, regno, NT_PPC_TM_CGPR,
1556 (tdep->wordsize == 4?
1557 PPC32_LINUX_SIZEOF_CGPRREGSET
1558 : PPC64_LINUX_SIZEOF_CGPRREGSET),
1559 cgprregset);
1560 return;
1561 }
1562 else if (PPC_IS_CKPTFP_REGNUM (regno))
1563 {
1564 gdb_assert (tdep->have_htm_fpu);
1565
1566 store_regset (regcache, tid, regno, NT_PPC_TM_CFPR,
1567 PPC_LINUX_SIZEOF_CFPRREGSET,
1568 &ppc32_linux_cfprregset);
1569 return;
1570 }
1571 else if (PPC_IS_CKPTVMX_REGNUM (regno))
1572 {
1573 gdb_assert (tdep->have_htm_altivec);
1574
1575 const struct regset *cvmxregset = ppc_linux_cvmxregset (gdbarch);
1576 store_regset (regcache, tid, regno, NT_PPC_TM_CVMX,
1577 PPC_LINUX_SIZEOF_CVMXREGSET,
1578 cvmxregset);
1579 return;
1580 }
1581 else if (PPC_IS_CKPTVSX_REGNUM (regno))
1582 {
1583 gdb_assert (tdep->have_htm_vsx);
1584
1585 store_regset (regcache, tid, regno, NT_PPC_TM_CVSX,
1586 PPC_LINUX_SIZEOF_CVSXREGSET,
1587 &ppc32_linux_cvsxregset);
1588 return;
1589 }
1590 else if (regno == PPC_CPPR_REGNUM)
1591 {
1592 gdb_assert (tdep->ppc_cppr_regnum != -1);
1593
1594 store_regset (regcache, tid, regno, NT_PPC_TM_CPPR,
1595 PPC_LINUX_SIZEOF_CPPRREGSET,
1596 &ppc32_linux_cpprregset);
1597 return;
1598 }
1599 else if (regno == PPC_CDSCR_REGNUM)
1600 {
1601 gdb_assert (tdep->ppc_cdscr_regnum != -1);
1602
1603 store_regset (regcache, tid, regno, NT_PPC_TM_CDSCR,
1604 PPC_LINUX_SIZEOF_CDSCRREGSET,
1605 &ppc32_linux_cdscrregset);
1606 return;
1607 }
1608 else if (regno == PPC_CTAR_REGNUM)
1609 {
1610 gdb_assert (tdep->ppc_ctar_regnum != -1);
1611
1612 store_regset (regcache, tid, regno, NT_PPC_TM_CTAR,
1613 PPC_LINUX_SIZEOF_CTARREGSET,
1614 &ppc32_linux_ctarregset);
1615 return;
1616 }
45229ea4 1617
9abe5450
EZ
1618 if (regaddr == -1)
1619 return;
1620
4a19ea35
JB
1621 /* First collect the register. Keep in mind that the regcache's
1622 idea of the register's size may not be a multiple of sizeof
411cb3f9 1623 (long). */
56d0d96a 1624 memset (buf, 0, sizeof buf);
40a6adc1
MD
1625 bytes_to_transfer = align_up (register_size (gdbarch, regno), sizeof (long));
1626 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
4a19ea35
JB
1627 {
1628 /* Little-endian values always sit at the left end of the buffer. */
34a79281 1629 regcache->raw_collect (regno, buf);
4a19ea35 1630 }
40a6adc1 1631 else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
4a19ea35
JB
1632 {
1633 /* Big-endian values sit at the right end of the buffer. */
40a6adc1 1634 size_t padding = (bytes_to_transfer - register_size (gdbarch, regno));
34a79281 1635 regcache->raw_collect (regno, buf + padding);
4a19ea35
JB
1636 }
1637
411cb3f9 1638 for (i = 0; i < bytes_to_transfer; i += sizeof (long))
45229ea4 1639 {
11fde611
JK
1640 long l;
1641
1642 memcpy (&l, &buf[i], sizeof (l));
45229ea4 1643 errno = 0;
11fde611 1644 ptrace (PTRACE_POKEUSER, tid, (PTRACE_TYPE_ARG3) regaddr, l);
411cb3f9 1645 regaddr += sizeof (long);
e3f36dbd
KB
1646
1647 if (errno == EIO
dda83cd7 1648 && (regno == tdep->ppc_fpscr_regnum
7284e1be
UW
1649 || regno == PPC_ORIG_R3_REGNUM
1650 || regno == PPC_TRAP_REGNUM))
e3f36dbd 1651 {
7284e1be
UW
1652 /* Some older kernel versions don't allow fpscr, orig_r3
1653 or trap to be written. */
e3f36dbd
KB
1654 continue;
1655 }
1656
45229ea4
EZ
1657 if (errno != 0)
1658 {
dda83cd7 1659 char message[128];
8c042590
PM
1660 xsnprintf (message, sizeof (message), "writing register %s (#%d)",
1661 gdbarch_register_name (gdbarch, regno), regno);
bc97b3ba 1662 perror_with_name (message);
45229ea4
EZ
1663 }
1664 }
1665}
1666
1dfe79e8
SDJ
1667/* This function actually issues the request to ptrace, telling
1668 it to store all general-purpose registers present in the specified
1669 regset.
1670
1671 If the ptrace request does not exist, this function returns 0
1672 and properly sets the have_ptrace_* flag. If the request fails,
1673 this function calls perror_with_name. Otherwise, if the request
1674 succeeds, then the regcache is stored and 1 is returned. */
1675static int
1676store_all_gp_regs (const struct regcache *regcache, int tid, int regno)
1677{
1dfe79e8
SDJ
1678 gdb_gregset_t gregset;
1679
1680 if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0)
1681 {
1682 if (errno == EIO)
dda83cd7
SM
1683 {
1684 have_ptrace_getsetregs = 0;
1685 return 0;
1686 }
deb70aa0 1687 perror_with_name (_("Couldn't get general-purpose registers"));
1dfe79e8
SDJ
1688 }
1689
1690 fill_gregset (regcache, &gregset, regno);
1691
1692 if (ptrace (PTRACE_SETREGS, tid, 0, (void *) &gregset) < 0)
1693 {
1694 if (errno == EIO)
dda83cd7
SM
1695 {
1696 have_ptrace_getsetregs = 0;
1697 return 0;
1698 }
deb70aa0 1699 perror_with_name (_("Couldn't set general-purpose registers"));
1dfe79e8
SDJ
1700 }
1701
1702 return 1;
1703}
1704
1705/* This is a wrapper for the store_all_gp_regs function. It is
1706 responsible for verifying if this target has the ptrace request
1707 that can be used to store all general-purpose registers at one
1708 shot. If it doesn't, then we should store them using the
1709 old-fashioned way, which is to iterate over the registers and
1710 store them one by one. */
45229ea4 1711static void
1dfe79e8 1712store_gp_regs (const struct regcache *regcache, int tid, int regno)
45229ea4 1713{
ac7936df 1714 struct gdbarch *gdbarch = regcache->arch ();
08106042 1715 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1dfe79e8
SDJ
1716 int i;
1717
1718 if (have_ptrace_getsetregs)
1719 if (store_all_gp_regs (regcache, tid, regno))
1720 return;
1721
1722 /* If we hit this point, it doesn't really matter which
1723 architecture we are using. We just need to store the
1724 registers in the "old-fashioned way". */
6ced10dd 1725 for (i = 0; i < ppc_num_gprs; i++)
56be3814 1726 store_register (regcache, tid, tdep->ppc_gp0_regnum + i);
1dfe79e8
SDJ
1727}
1728
1729/* This function actually issues the request to ptrace, telling
1730 it to store all floating-point registers present in the specified
1731 regset.
1732
1733 If the ptrace request does not exist, this function returns 0
1734 and properly sets the have_ptrace_* flag. If the request fails,
1735 this function calls perror_with_name. Otherwise, if the request
1736 succeeds, then the regcache is stored and 1 is returned. */
1737static int
1738store_all_fp_regs (const struct regcache *regcache, int tid, int regno)
1739{
1740 gdb_fpregset_t fpregs;
1741
1742 if (ptrace (PTRACE_GETFPREGS, tid, 0, (void *) &fpregs) < 0)
1743 {
1744 if (errno == EIO)
dda83cd7
SM
1745 {
1746 have_ptrace_getsetfpregs = 0;
1747 return 0;
1748 }
deb70aa0 1749 perror_with_name (_("Couldn't get floating-point registers"));
1dfe79e8
SDJ
1750 }
1751
1752 fill_fpregset (regcache, &fpregs, regno);
1753
1754 if (ptrace (PTRACE_SETFPREGS, tid, 0, (void *) &fpregs) < 0)
1755 {
1756 if (errno == EIO)
dda83cd7
SM
1757 {
1758 have_ptrace_getsetfpregs = 0;
1759 return 0;
1760 }
deb70aa0 1761 perror_with_name (_("Couldn't set floating-point registers"));
1dfe79e8
SDJ
1762 }
1763
1764 return 1;
1765}
1766
1767/* This is a wrapper for the store_all_fp_regs function. It is
1768 responsible for verifying if this target has the ptrace request
1769 that can be used to store all floating-point registers at one
1770 shot. If it doesn't, then we should store them using the
1771 old-fashioned way, which is to iterate over the registers and
1772 store them one by one. */
1773static void
1774store_fp_regs (const struct regcache *regcache, int tid, int regno)
1775{
ac7936df 1776 struct gdbarch *gdbarch = regcache->arch ();
08106042 1777 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1dfe79e8
SDJ
1778 int i;
1779
1780 if (have_ptrace_getsetfpregs)
1781 if (store_all_fp_regs (regcache, tid, regno))
1782 return;
1783
1784 /* If we hit this point, it doesn't really matter which
1785 architecture we are using. We just need to store the
1786 registers in the "old-fashioned way". */
1787 for (i = 0; i < ppc_num_fprs; i++)
1788 store_register (regcache, tid, tdep->ppc_fp0_regnum + i);
1789}
1790
1791static void
1792store_ppc_registers (const struct regcache *regcache, int tid)
1793{
ac7936df 1794 struct gdbarch *gdbarch = regcache->arch ();
08106042 1795 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
1dfe79e8
SDJ
1796
1797 store_gp_regs (regcache, tid, -1);
32b99774 1798 if (tdep->ppc_fp0_regnum >= 0)
1dfe79e8 1799 store_fp_regs (regcache, tid, -1);
40a6adc1 1800 store_register (regcache, tid, gdbarch_pc_regnum (gdbarch));
32b99774 1801 if (tdep->ppc_ps_regnum != -1)
56be3814 1802 store_register (regcache, tid, tdep->ppc_ps_regnum);
32b99774 1803 if (tdep->ppc_cr_regnum != -1)
56be3814 1804 store_register (regcache, tid, tdep->ppc_cr_regnum);
32b99774 1805 if (tdep->ppc_lr_regnum != -1)
56be3814 1806 store_register (regcache, tid, tdep->ppc_lr_regnum);
32b99774 1807 if (tdep->ppc_ctr_regnum != -1)
56be3814 1808 store_register (regcache, tid, tdep->ppc_ctr_regnum);
32b99774 1809 if (tdep->ppc_xer_regnum != -1)
56be3814 1810 store_register (regcache, tid, tdep->ppc_xer_regnum);
e3f36dbd 1811 if (tdep->ppc_mq_regnum != -1)
56be3814 1812 store_register (regcache, tid, tdep->ppc_mq_regnum);
32b99774 1813 if (tdep->ppc_fpscr_regnum != -1)
56be3814 1814 store_register (regcache, tid, tdep->ppc_fpscr_regnum);
7284e1be
UW
1815 if (ppc_linux_trap_reg_p (gdbarch))
1816 {
1817 store_register (regcache, tid, PPC_ORIG_R3_REGNUM);
1818 store_register (regcache, tid, PPC_TRAP_REGNUM);
1819 }
9abe5450
EZ
1820 if (have_ptrace_getvrregs)
1821 if (tdep->ppc_vr0_regnum != -1 && tdep->ppc_vrsave_regnum != -1)
1d75a658 1822 store_altivec_registers (regcache, tid, -1);
604c2f83
LM
1823 if (have_ptrace_getsetvsxregs)
1824 if (tdep->ppc_vsr0_upper_regnum != -1)
2c3305f6 1825 store_vsx_registers (regcache, tid, -1);
6ced10dd 1826 if (tdep->ppc_ev0_upper_regnum >= 0)
56be3814 1827 store_spe_register (regcache, tid, -1);
7ca18ed6
EBM
1828 if (tdep->ppc_ppr_regnum != -1)
1829 store_regset (regcache, tid, -1, NT_PPC_PPR,
1830 PPC_LINUX_SIZEOF_PPRREGSET,
1831 &ppc32_linux_pprregset);
1832 if (tdep->ppc_dscr_regnum != -1)
1833 store_regset (regcache, tid, -1, NT_PPC_DSCR,
1834 PPC_LINUX_SIZEOF_DSCRREGSET,
1835 &ppc32_linux_dscrregset);
f2cf6173
EBM
1836 if (tdep->ppc_tar_regnum != -1)
1837 store_regset (regcache, tid, -1, NT_PPC_TAR,
1838 PPC_LINUX_SIZEOF_TARREGSET,
1839 &ppc32_linux_tarregset);
232bfb86
EBM
1840
1841 if (tdep->ppc_mmcr0_regnum != -1)
1842 store_regset (regcache, tid, -1, NT_PPC_PMU,
1843 PPC_LINUX_SIZEOF_PMUREGSET,
1844 &ppc32_linux_pmuregset);
1845
8d619c01
EBM
1846 if (tdep->have_htm_spr)
1847 store_regset (regcache, tid, -1, NT_PPC_TM_SPR,
1848 PPC_LINUX_SIZEOF_TM_SPRREGSET,
1849 &ppc32_linux_tm_sprregset);
1850
1851 /* Because the EBB and checkpointed HTM registers can be
1852 unavailable, attempts to store them here would cause this
1853 function to fail most of the time, so we ignore them. */
45229ea4
EZ
1854}
1855
4db10d8f
PFC
1856void
1857ppc_linux_nat_target::store_registers (struct regcache *regcache, int regno)
1858{
1859 pid_t tid = get_ptrace_pid (regcache->ptid ());
1860
1861 if (regno >= 0)
1862 store_register (regcache, tid, regno);
1863 else
1864 store_ppc_registers (regcache, tid);
1865}
1866
1867/* Functions for transferring registers between a gregset_t or fpregset_t
1868 (see sys/ucontext.h) and gdb's regcache. The word size is that used
1869 by the ptrace interface, not the current program's ABI. Eg. if a
1870 powerpc64-linux gdb is being used to debug a powerpc32-linux app, we
1871 read or write 64-bit gregsets. This is to suit the host libthread_db. */
1872
1873void
1874supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
1875{
1876 const struct regset *regset = ppc_linux_gregset (sizeof (long));
1877
1878 ppc_supply_gregset (regset, regcache, -1, gregsetp, sizeof (*gregsetp));
1879}
1880
1881void
1882fill_gregset (const struct regcache *regcache,
1883 gdb_gregset_t *gregsetp, int regno)
1884{
1885 const struct regset *regset = ppc_linux_gregset (sizeof (long));
1886
1887 if (regno == -1)
1888 memset (gregsetp, 0, sizeof (*gregsetp));
1889 ppc_collect_gregset (regset, regcache, regno, gregsetp, sizeof (*gregsetp));
1890}
1891
1892void
1893supply_fpregset (struct regcache *regcache, const gdb_fpregset_t * fpregsetp)
1894{
1895 const struct regset *regset = ppc_linux_fpregset ();
1896
1897 ppc_supply_fpregset (regset, regcache, -1,
1898 fpregsetp, sizeof (*fpregsetp));
1899}
1900
1901void
1902fill_fpregset (const struct regcache *regcache,
1903 gdb_fpregset_t *fpregsetp, int regno)
1904{
1905 const struct regset *regset = ppc_linux_fpregset ();
1906
1907 ppc_collect_fpregset (regset, regcache, regno,
1908 fpregsetp, sizeof (*fpregsetp));
1909}
1910
1911int
3fe639b8
SM
1912ppc_linux_nat_target::auxv_parse (const gdb_byte **readptr,
1913 const gdb_byte *endptr, CORE_ADDR *typep,
4db10d8f
PFC
1914 CORE_ADDR *valp)
1915{
14414227
TV
1916 gdb_assert (inferior_ptid != null_ptid);
1917
4db10d8f
PFC
1918 int tid = inferior_ptid.lwp ();
1919 if (tid == 0)
1920 tid = inferior_ptid.pid ();
1921
1922 int sizeof_auxv_field = ppc_linux_target_wordsize (tid);
1923
99d9c3b9 1924 bfd_endian byte_order = gdbarch_byte_order (current_inferior ()->arch ());
3fe639b8 1925 const gdb_byte *ptr = *readptr;
4db10d8f
PFC
1926
1927 if (endptr == ptr)
1928 return 0;
1929
1930 if (endptr - ptr < sizeof_auxv_field * 2)
1931 return -1;
1932
1933 *typep = extract_unsigned_integer (ptr, sizeof_auxv_field, byte_order);
1934 ptr += sizeof_auxv_field;
1935 *valp = extract_unsigned_integer (ptr, sizeof_auxv_field, byte_order);
1936 ptr += sizeof_auxv_field;
1937
1938 *readptr = ptr;
1939 return 1;
1940}
1941
1942const struct target_desc *
1943ppc_linux_nat_target::read_description ()
1944{
a4a688ff
JB
1945 if (inferior_ptid == null_ptid)
1946 return this->beneath ()->read_description ();
1947
fbf3c4b9 1948 int tid = inferior_ptid.pid ();
4db10d8f
PFC
1949
1950 if (have_ptrace_getsetevrregs)
1951 {
1952 struct gdb_evrregset_t evrregset;
1953
1954 if (ptrace (PTRACE_GETEVRREGS, tid, 0, &evrregset) >= 0)
dda83cd7 1955 return tdesc_powerpc_e500l;
4db10d8f
PFC
1956
1957 /* EIO means that the PTRACE_GETEVRREGS request isn't supported.
1958 Anything else needs to be reported. */
1959 else if (errno != EIO)
1960 perror_with_name (_("Unable to fetch SPE registers"));
1961 }
1962
1963 struct ppc_linux_features features = ppc_linux_no_features;
1964
1965 features.wordsize = ppc_linux_target_wordsize (tid);
1966
82d23ca8
SM
1967 CORE_ADDR hwcap = linux_get_hwcap ();
1968 CORE_ADDR hwcap2 = linux_get_hwcap2 ();
4db10d8f
PFC
1969
1970 if (have_ptrace_getsetvsxregs
1971 && (hwcap & PPC_FEATURE_HAS_VSX))
1972 {
1973 gdb_vsxregset_t vsxregset;
1974
1975 if (ptrace (PTRACE_GETVSXREGS, tid, 0, &vsxregset) >= 0)
1976 features.vsx = true;
1977
1978 /* EIO means that the PTRACE_GETVSXREGS request isn't supported.
1979 Anything else needs to be reported. */
1980 else if (errno != EIO)
1981 perror_with_name (_("Unable to fetch VSX registers"));
1982 }
1983
1984 if (have_ptrace_getvrregs
1985 && (hwcap & PPC_FEATURE_HAS_ALTIVEC))
1986 {
1987 gdb_vrregset_t vrregset;
1988
1989 if (ptrace (PTRACE_GETVRREGS, tid, 0, &vrregset) >= 0)
dda83cd7 1990 features.altivec = true;
4db10d8f
PFC
1991
1992 /* EIO means that the PTRACE_GETVRREGS request isn't supported.
1993 Anything else needs to be reported. */
1994 else if (errno != EIO)
1995 perror_with_name (_("Unable to fetch AltiVec registers"));
1996 }
1997
1998 features.isa205 = ppc_linux_has_isa205 (hwcap);
1999
2000 if ((hwcap2 & PPC_FEATURE2_DSCR)
2001 && check_regset (tid, NT_PPC_PPR, PPC_LINUX_SIZEOF_PPRREGSET)
2002 && check_regset (tid, NT_PPC_DSCR, PPC_LINUX_SIZEOF_DSCRREGSET))
2003 {
2004 features.ppr_dscr = true;
2005 if ((hwcap2 & PPC_FEATURE2_ARCH_2_07)
2006 && (hwcap2 & PPC_FEATURE2_TAR)
2007 && (hwcap2 & PPC_FEATURE2_EBB)
2008 && check_regset (tid, NT_PPC_TAR, PPC_LINUX_SIZEOF_TARREGSET)
2009 && check_regset (tid, NT_PPC_EBB, PPC_LINUX_SIZEOF_EBBREGSET)
2010 && check_regset (tid, NT_PPC_PMU, PPC_LINUX_SIZEOF_PMUREGSET))
2011 {
2012 features.isa207 = true;
2013 if ((hwcap2 & PPC_FEATURE2_HTM)
2014 && check_regset (tid, NT_PPC_TM_SPR,
2015 PPC_LINUX_SIZEOF_TM_SPRREGSET))
2016 features.htm = true;
2017 }
2018 }
2019
2020 return ppc_linux_match_description (features);
2021}
2022
227c0bf4
PFC
2023/* Routines for installing hardware watchpoints and breakpoints. When
2024 GDB requests a hardware watchpoint or breakpoint to be installed, we
2025 register the request for the pid of inferior_ptid in a map with one
2026 entry per process. We then issue a stop request to all the threads of
2027 this process, and mark a per-thread flag indicating that their debug
2028 registers should be updated. Right before they are next resumed, we
2029 remove all previously installed debug registers and install all the
2030 ones GDB requested. We then update a map with one entry per thread
2031 that keeps track of what debug registers were last installed in each
2032 thread.
2033
2034 We use this second map to remove installed registers before installing
2035 the ones requested by GDB, and to copy the debug register state after
2036 a thread clones or forks, since depending on the kernel configuration,
2037 debug registers can be inherited. */
2038
2039/* Check if we support and have enough resources to install a hardware
2040 watchpoint or breakpoint. See the description in target.h. */
e0d24f8d 2041
f6ac5f3d 2042int
227c0bf4
PFC
2043ppc_linux_nat_target::can_use_hw_breakpoint (enum bptype type, int cnt,
2044 int ot)
b7622095 2045{
6ffbb7ab 2046 int total_hw_wp, total_hw_bp;
b7622095 2047
227c0bf4
PFC
2048 m_dreg_interface.detect (inferior_ptid);
2049
2050 if (m_dreg_interface.unavailable_p ())
2051 return 0;
2052
2053 if (m_dreg_interface.hwdebug_p ())
6ffbb7ab 2054 {
926bf92d
UW
2055 /* When PowerPC HWDEBUG ptrace interface is available, the number of
2056 available hardware watchpoints and breakpoints is stored at the
2057 hwdebug_info struct. */
227c0bf4
PFC
2058 total_hw_bp = m_dreg_interface.hwdebug_info ().num_instruction_bps;
2059 total_hw_wp = m_dreg_interface.hwdebug_info ().num_data_bps;
6ffbb7ab
TJB
2060 }
2061 else
2062 {
227c0bf4
PFC
2063 gdb_assert (m_dreg_interface.debugreg_p ());
2064
2065 /* With the DEBUGREG ptrace interface, we should consider having 1
2066 hardware watchpoint and no hardware breakpoints. */
6ffbb7ab
TJB
2067 total_hw_bp = 0;
2068 total_hw_wp = 1;
2069 }
b7622095 2070
6ffbb7ab
TJB
2071 if (type == bp_hardware_watchpoint || type == bp_read_watchpoint
2072 || type == bp_access_watchpoint || type == bp_watchpoint)
2073 {
227c0bf4
PFC
2074 if (total_hw_wp == 0)
2075 return 0;
2076 else if (cnt + ot > total_hw_wp)
6ffbb7ab 2077 return -1;
227c0bf4
PFC
2078 else
2079 return 1;
6ffbb7ab
TJB
2080 }
2081 else if (type == bp_hardware_breakpoint)
2082 {
572f6555 2083 if (total_hw_bp == 0)
6ffbb7ab 2084 return 0;
227c0bf4
PFC
2085 else if (cnt > total_hw_bp)
2086 return -1;
2087 else
2088 return 1;
6ffbb7ab
TJB
2089 }
2090
227c0bf4 2091 return 0;
b7622095
LM
2092}
2093
227c0bf4
PFC
2094/* Returns 1 if we can watch LEN bytes at address ADDR, 0 otherwise. */
2095
f6ac5f3d
PA
2096int
2097ppc_linux_nat_target::region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
e0d24f8d
WZ
2098{
2099 /* Handle sub-8-byte quantities. */
2100 if (len <= 0)
2101 return 0;
2102
227c0bf4
PFC
2103 m_dreg_interface.detect (inferior_ptid);
2104
2105 if (m_dreg_interface.unavailable_p ())
2106 return 0;
2107
926bf92d
UW
2108 /* The PowerPC HWDEBUG ptrace interface tells if there are alignment
2109 restrictions for watchpoints in the processors. In that case, we use that
2110 information to determine the hardcoded watchable region for
2111 watchpoints. */
227c0bf4 2112 if (m_dreg_interface.hwdebug_p ())
6ffbb7ab 2113 {
227c0bf4
PFC
2114 const struct ppc_debug_info &hwdebug_info = (m_dreg_interface
2115 .hwdebug_info ());
539d71e8
RA
2116 int region_size = hwdebug_info.data_bp_alignment;
2117 int region_align = region_size;
227c0bf4 2118
4feebbdd
EBM
2119 /* Embedded DAC-based processors, like the PowerPC 440 have ranged
2120 watchpoints and can watch any access within an arbitrary memory
2121 region. This is useful to watch arrays and structs, for instance. It
dda83cd7 2122 takes two hardware watchpoints though. */
e09342b5 2123 if (len > 1
926bf92d 2124 && hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_RANGE
82d23ca8 2125 && (linux_get_hwcap () & PPC_FEATURE_BOOKE))
e09342b5 2126 return 2;
e23b9d6e
UW
2127 /* Check if the processor provides DAWR interface. */
2128 if (hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_DAWR)
539d71e8
RA
2129 {
2130 /* DAWR interface allows to watch up to 512 byte wide ranges. */
2131 region_size = 512;
2132 /* DAWR interface allows to watch up to 512 byte wide ranges which
f4afd6cb 2133 can't cross a 512 byte boundary on machines that don't have a
539d71e8
RA
2134 second DAWR (P9 or less). */
2135 if (!(hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_ARCH_31))
2136 region_align = 512;
2137 }
4feebbdd 2138 /* Server processors provide one hardware watchpoint and addr+len should
dda83cd7 2139 fall in the watchable region provided by the ptrace interface. */
539d71e8
RA
2140 if (region_align
2141 && (addr + len > (addr & ~(region_align - 1)) + region_size))
0cf6dd15 2142 return 0;
6ffbb7ab 2143 }
b7622095 2144 /* addr+len must fall in the 8 byte watchable region for DABR-based
926bf92d
UW
2145 processors (i.e., server processors). Without the new PowerPC HWDEBUG
2146 ptrace interface, DAC-based processors (i.e., embedded processors) will
2147 use addresses aligned to 4-bytes due to the way the read/write flags are
6ffbb7ab 2148 passed in the old ptrace interface. */
227c0bf4 2149 else
6ffbb7ab 2150 {
227c0bf4 2151 gdb_assert (m_dreg_interface.debugreg_p ());
6ffbb7ab 2152
82d23ca8 2153 if (((linux_get_hwcap () & PPC_FEATURE_BOOKE)
227c0bf4
PFC
2154 && (addr + len) > (addr & ~3) + 4)
2155 || (addr + len) > (addr & ~7) + 8)
2156 return 0;
5da01df5 2157 }
6ffbb7ab 2158
227c0bf4 2159 return 1;
6ffbb7ab
TJB
2160}
2161
227c0bf4
PFC
2162/* This function compares two ppc_hw_breakpoint structs
2163 field-by-field. */
6ffbb7ab 2164
227c0bf4
PFC
2165bool
2166ppc_linux_nat_target::hwdebug_point_cmp (const struct ppc_hw_breakpoint &a,
2167 const struct ppc_hw_breakpoint &b)
2168{
2169 return (a.trigger_type == b.trigger_type
2170 && a.addr_mode == b.addr_mode
2171 && a.condition_mode == b.condition_mode
2172 && a.addr == b.addr
2173 && a.addr2 == b.addr2
2174 && a.condition_value == b.condition_value);
6ffbb7ab 2175}
9f0bdab8 2176
f1310107
TJB
2177/* Return the number of registers needed for a ranged breakpoint. */
2178
f6ac5f3d
PA
2179int
2180ppc_linux_nat_target::ranged_break_num_registers ()
f1310107 2181{
227c0bf4
PFC
2182 m_dreg_interface.detect (inferior_ptid);
2183
2184 return ((m_dreg_interface.hwdebug_p ()
2185 && (m_dreg_interface.hwdebug_info ().features
2186 & PPC_DEBUG_FEATURE_INSN_BP_RANGE))?
f1310107
TJB
2187 2 : -1);
2188}
2189
227c0bf4
PFC
2190/* Register the hardware breakpoint described by BP_TGT, to be inserted
2191 when the threads of inferior_ptid are resumed. Returns 0 for success,
2192 or -1 if the HWDEBUG interface that we need for hardware breakpoints
2193 is not available. */
f1310107 2194
f6ac5f3d
PA
2195int
2196ppc_linux_nat_target::insert_hw_breakpoint (struct gdbarch *gdbarch,
2197 struct bp_target_info *bp_tgt)
e0d24f8d 2198{
6ffbb7ab
TJB
2199 struct ppc_hw_breakpoint p;
2200
227c0bf4
PFC
2201 m_dreg_interface.detect (inferior_ptid);
2202
2203 if (!m_dreg_interface.hwdebug_p ())
6ffbb7ab
TJB
2204 return -1;
2205
ad422571
TJB
2206 p.version = PPC_DEBUG_CURRENT_VERSION;
2207 p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
ad422571 2208 p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
0d5ed153 2209 p.addr = (uint64_t) (bp_tgt->placed_address = bp_tgt->reqstd_address);
6ffbb7ab
TJB
2210 p.condition_value = 0;
2211
f1310107
TJB
2212 if (bp_tgt->length)
2213 {
2214 p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
2215
2216 /* The breakpoint will trigger if the address of the instruction is
2217 within the defined range, as follows: p.addr <= address < p.addr2. */
2218 p.addr2 = (uint64_t) bp_tgt->placed_address + bp_tgt->length;
2219 }
2220 else
2221 {
2222 p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
2223 p.addr2 = 0;
2224 }
2225
227c0bf4 2226 register_hw_breakpoint (inferior_ptid.pid (), p);
6ffbb7ab
TJB
2227
2228 return 0;
2229}
2230
227c0bf4
PFC
2231/* Clear a registration for the hardware breakpoint given by type BP_TGT.
2232 It will be removed from the threads of inferior_ptid when they are
2233 next resumed. Returns 0 for success, or -1 if the HWDEBUG interface
2234 that we need for hardware breakpoints is not available. */
2235
f6ac5f3d
PA
2236int
2237ppc_linux_nat_target::remove_hw_breakpoint (struct gdbarch *gdbarch,
2238 struct bp_target_info *bp_tgt)
6ffbb7ab 2239{
6ffbb7ab 2240 struct ppc_hw_breakpoint p;
b7622095 2241
227c0bf4
PFC
2242 m_dreg_interface.detect (inferior_ptid);
2243
2244 if (!m_dreg_interface.hwdebug_p ())
6ffbb7ab
TJB
2245 return -1;
2246
ad422571
TJB
2247 p.version = PPC_DEBUG_CURRENT_VERSION;
2248 p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
ad422571
TJB
2249 p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
2250 p.addr = (uint64_t) bp_tgt->placed_address;
6ffbb7ab
TJB
2251 p.condition_value = 0;
2252
f1310107
TJB
2253 if (bp_tgt->length)
2254 {
2255 p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
2256
2257 /* The breakpoint will trigger if the address of the instruction is within
2258 the defined range, as follows: p.addr <= address < p.addr2. */
2259 p.addr2 = (uint64_t) bp_tgt->placed_address + bp_tgt->length;
2260 }
2261 else
2262 {
2263 p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
2264 p.addr2 = 0;
2265 }
2266
227c0bf4 2267 clear_hw_breakpoint (inferior_ptid.pid (), p);
6ffbb7ab
TJB
2268
2269 return 0;
2270}
2271
227c0bf4
PFC
2272/* Return the trigger value to set in a ppc_hw_breakpoint object for a
2273 given hardware watchpoint TYPE. We assume type is not hw_execute. */
2274
2275int
2276ppc_linux_nat_target::get_trigger_type (enum target_hw_bp_type type)
6ffbb7ab
TJB
2277{
2278 int t;
2279
e76460db 2280 if (type == hw_read)
6ffbb7ab 2281 t = PPC_BREAKPOINT_TRIGGER_READ;
e76460db 2282 else if (type == hw_write)
6ffbb7ab 2283 t = PPC_BREAKPOINT_TRIGGER_WRITE;
b7622095 2284 else
6ffbb7ab
TJB
2285 t = PPC_BREAKPOINT_TRIGGER_READ | PPC_BREAKPOINT_TRIGGER_WRITE;
2286
2287 return t;
2288}
2289
227c0bf4
PFC
2290/* Register a new masked watchpoint at ADDR using the mask MASK, to be
2291 inserted when the threads of inferior_ptid are resumed. RW may be
2292 hw_read for a read watchpoint, hw_write for a write watchpoint or
2293 hw_access for an access watchpoint. */
9c06b0b4 2294
f6ac5f3d
PA
2295int
2296ppc_linux_nat_target::insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
2297 target_hw_bp_type rw)
9c06b0b4 2298{
9c06b0b4
TJB
2299 struct ppc_hw_breakpoint p;
2300
227c0bf4 2301 gdb_assert (m_dreg_interface.hwdebug_p ());
9c06b0b4
TJB
2302
2303 p.version = PPC_DEBUG_CURRENT_VERSION;
2304 p.trigger_type = get_trigger_type (rw);
2305 p.addr_mode = PPC_BREAKPOINT_MODE_MASK;
2306 p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
2307 p.addr = addr;
2308 p.addr2 = mask;
2309 p.condition_value = 0;
2310
227c0bf4 2311 register_hw_breakpoint (inferior_ptid.pid (), p);
9c06b0b4
TJB
2312
2313 return 0;
2314}
2315
227c0bf4
PFC
2316/* Clear a registration for a masked watchpoint at ADDR with the mask
2317 MASK. It will be removed from the threads of inferior_ptid when they
2318 are next resumed. RW may be hw_read for a read watchpoint, hw_write
2319 for a write watchpoint or hw_access for an access watchpoint. */
9c06b0b4 2320
f6ac5f3d
PA
2321int
2322ppc_linux_nat_target::remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask,
2323 target_hw_bp_type rw)
9c06b0b4 2324{
9c06b0b4
TJB
2325 struct ppc_hw_breakpoint p;
2326
227c0bf4 2327 gdb_assert (m_dreg_interface.hwdebug_p ());
9c06b0b4
TJB
2328
2329 p.version = PPC_DEBUG_CURRENT_VERSION;
2330 p.trigger_type = get_trigger_type (rw);
2331 p.addr_mode = PPC_BREAKPOINT_MODE_MASK;
2332 p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
2333 p.addr = addr;
2334 p.addr2 = mask;
2335 p.condition_value = 0;
2336
227c0bf4 2337 clear_hw_breakpoint (inferior_ptid.pid (), p);
9c06b0b4
TJB
2338
2339 return 0;
2340}
2341
227c0bf4
PFC
2342/* Check whether we have at least one free DVC register for the threads
2343 of the pid of inferior_ptid. */
2344
2345bool
2346ppc_linux_nat_target::can_use_watchpoint_cond_accel (void)
0cf6dd15 2347{
227c0bf4 2348 m_dreg_interface.detect (inferior_ptid);
0cf6dd15 2349
227c0bf4
PFC
2350 if (!m_dreg_interface.hwdebug_p ())
2351 return false;
0cf6dd15 2352
227c0bf4 2353 int cnt = m_dreg_interface.hwdebug_info ().num_condition_regs;
0cf6dd15 2354
227c0bf4
PFC
2355 if (cnt == 0)
2356 return false;
0cf6dd15 2357
227c0bf4 2358 auto process_it = m_process_info.find (inferior_ptid.pid ());
0cf6dd15 2359
4a4fd10d
TY
2360 /* No breakpoints, watchpoints, tracepoints, or catchpoints have been
2361 requested for this process, we have at least one free DVC register. */
227c0bf4
PFC
2362 if (process_it == m_process_info.end ())
2363 return true;
2364
2365 for (const ppc_hw_breakpoint &bp : process_it->second.requested_hw_bps)
2366 if (bp.condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
2367 cnt--;
2368
2369 if (cnt <= 0)
2370 return false;
2371
2372 return true;
0cf6dd15
TJB
2373}
2374
2375/* Calculate the enable bits and the contents of the Data Value Compare
2376 debug register present in BookE processors.
2377
2378 ADDR is the address to be watched, LEN is the length of watched data
2379 and DATA_VALUE is the value which will trigger the watchpoint.
2380 On exit, CONDITION_MODE will hold the enable bits for the DVC, and
2381 CONDITION_VALUE will hold the value which should be put in the
2382 DVC register. */
227c0bf4
PFC
2383
2384void
2385ppc_linux_nat_target::calculate_dvc (CORE_ADDR addr, int len,
2386 CORE_ADDR data_value,
2387 uint32_t *condition_mode,
2388 uint64_t *condition_value)
0cf6dd15 2389{
227c0bf4
PFC
2390 const struct ppc_debug_info &hwdebug_info = (m_dreg_interface.
2391 hwdebug_info ());
2392
0cf6dd15
TJB
2393 int i, num_byte_enable, align_offset, num_bytes_off_dvc,
2394 rightmost_enabled_byte;
2395 CORE_ADDR addr_end_data, addr_end_dvc;
2396
2397 /* The DVC register compares bytes within fixed-length windows which
2398 are word-aligned, with length equal to that of the DVC register.
2399 We need to calculate where our watch region is relative to that
2400 window and enable comparison of the bytes which fall within it. */
2401
926bf92d 2402 align_offset = addr % hwdebug_info.sizeof_condition;
0cf6dd15
TJB
2403 addr_end_data = addr + len;
2404 addr_end_dvc = (addr - align_offset
926bf92d 2405 + hwdebug_info.sizeof_condition);
0cf6dd15
TJB
2406 num_bytes_off_dvc = (addr_end_data > addr_end_dvc)?
2407 addr_end_data - addr_end_dvc : 0;
2408 num_byte_enable = len - num_bytes_off_dvc;
2409 /* Here, bytes are numbered from right to left. */
2410 rightmost_enabled_byte = (addr_end_data < addr_end_dvc)?
2411 addr_end_dvc - addr_end_data : 0;
2412
2413 *condition_mode = PPC_BREAKPOINT_CONDITION_AND;
2414 for (i = 0; i < num_byte_enable; i++)
0df8b418
MS
2415 *condition_mode
2416 |= PPC_BREAKPOINT_CONDITION_BE (i + rightmost_enabled_byte);
0cf6dd15
TJB
2417
2418 /* Now we need to match the position within the DVC of the comparison
2419 value with where the watch region is relative to the window
2420 (i.e., the ALIGN_OFFSET). */
2421
2422 *condition_value = ((uint64_t) data_value >> num_bytes_off_dvc * 8
2423 << rightmost_enabled_byte * 8);
2424}
2425
2426/* Return the number of memory locations that need to be accessed to
2427 evaluate the expression which generated the given value chain.
2428 Returns -1 if there's any register access involved, or if there are
2429 other kinds of values which are not acceptable in a condition
2430 expression (e.g., lval_computed or lval_internalvar). */
227c0bf4
PFC
2431
2432int
2433ppc_linux_nat_target::num_memory_accesses (const std::vector<value_ref_ptr>
2434 &chain)
0cf6dd15
TJB
2435{
2436 int found_memory_cnt = 0;
0cf6dd15
TJB
2437
2438 /* The idea here is that evaluating an expression generates a series
2439 of values, one holding the value of every subexpression. (The
2440 expression a*b+c has five subexpressions: a, b, a*b, c, and
2441 a*b+c.) GDB's values hold almost enough information to establish
2442 the criteria given above --- they identify memory lvalues,
2443 register lvalues, computed values, etcetera. So we can evaluate
2444 the expression, and then scan the chain of values that leaves
2445 behind to determine the memory locations involved in the evaluation
2446 of an expression.
2447
2448 However, I don't think that the values returned by inferior
2449 function calls are special in any way. So this function may not
2450 notice that an expression contains an inferior function call.
2451 FIXME. */
2452
a6535de1 2453 for (const value_ref_ptr &iter : chain)
0cf6dd15 2454 {
a6535de1
TT
2455 struct value *v = iter.get ();
2456
0cf6dd15 2457 /* Constants and values from the history are fine. */
b2227e67 2458 if (v->lval () == not_lval || !v->deprecated_modifiable ())
0cf6dd15 2459 continue;
736355f2 2460 else if (v->lval () == lval_memory)
0cf6dd15
TJB
2461 {
2462 /* A lazy memory lvalue is one that GDB never needed to fetch;
2463 we either just used its address (e.g., `a' in `a.b') or
2464 we never needed it at all (e.g., `a' in `a,b'). */
3ee3b270 2465 if (!v->lazy ())
0cf6dd15
TJB
2466 found_memory_cnt++;
2467 }
0df8b418 2468 /* Other kinds of values are not fine. */
0cf6dd15
TJB
2469 else
2470 return -1;
2471 }
2472
2473 return found_memory_cnt;
2474}
2475
2476/* Verifies whether the expression COND can be implemented using the
2477 DVC (Data Value Compare) register in BookE processors. The expression
2478 must test the watch value for equality with a constant expression.
2479 If the function returns 1, DATA_VALUE will contain the constant against
e7db58ea
TJB
2480 which the watch value should be compared and LEN will contain the size
2481 of the constant. */
227c0bf4
PFC
2482
2483int
2484ppc_linux_nat_target::check_condition (CORE_ADDR watch_addr,
2485 struct expression *cond,
2486 CORE_ADDR *data_value, int *len)
0cf6dd15 2487{
1eaebe02 2488 int num_accesses_left, num_accesses_right;
a6535de1
TT
2489 struct value *left_val, *right_val;
2490 std::vector<value_ref_ptr> left_chain, right_chain;
0cf6dd15 2491
1eaebe02
TT
2492 expr::equal_operation *eqop
2493 = dynamic_cast<expr::equal_operation *> (cond->op.get ());
2494 if (eqop == nullptr)
0cf6dd15 2495 return 0;
1eaebe02
TT
2496 expr::operation *lhs = eqop->get_lhs ();
2497 expr::operation *rhs = eqop->get_rhs ();
0cf6dd15 2498
1eaebe02 2499 fetch_subexp_value (cond, lhs, &left_val, NULL, &left_chain, false);
0cf6dd15
TJB
2500 num_accesses_left = num_memory_accesses (left_chain);
2501
2502 if (left_val == NULL || num_accesses_left < 0)
a6535de1 2503 return 0;
0cf6dd15 2504
1eaebe02 2505 fetch_subexp_value (cond, rhs, &right_val, NULL, &right_chain, false);
0cf6dd15
TJB
2506 num_accesses_right = num_memory_accesses (right_chain);
2507
2508 if (right_val == NULL || num_accesses_right < 0)
a6535de1 2509 return 0;
0cf6dd15
TJB
2510
2511 if (num_accesses_left == 1 && num_accesses_right == 0
736355f2 2512 && left_val->lval () == lval_memory
9feb2d07 2513 && left_val->address () == watch_addr)
e7db58ea
TJB
2514 {
2515 *data_value = value_as_long (right_val);
2516
2517 /* DATA_VALUE is the constant in RIGHT_VAL, but actually has
2518 the same type as the memory region referenced by LEFT_VAL. */
d0c97917 2519 *len = check_typedef (left_val->type ())->length ();
e7db58ea 2520 }
0cf6dd15 2521 else if (num_accesses_left == 0 && num_accesses_right == 1
736355f2 2522 && right_val->lval () == lval_memory
9feb2d07 2523 && right_val->address () == watch_addr)
e7db58ea
TJB
2524 {
2525 *data_value = value_as_long (left_val);
2526
2527 /* DATA_VALUE is the constant in LEFT_VAL, but actually has
2528 the same type as the memory region referenced by RIGHT_VAL. */
d0c97917 2529 *len = check_typedef (right_val->type ())->length ();
e7db58ea 2530 }
0cf6dd15 2531 else
a6535de1 2532 return 0;
0cf6dd15
TJB
2533
2534 return 1;
2535}
2536
227c0bf4
PFC
2537/* Return true if the target is capable of using hardware to evaluate the
2538 condition expression, thus only triggering the watchpoint when it is
0cf6dd15 2539 true. */
227c0bf4 2540
57810aa7 2541bool
227c0bf4
PFC
2542ppc_linux_nat_target::can_accel_watchpoint_condition (CORE_ADDR addr,
2543 int len, int rw,
f6ac5f3d 2544 struct expression *cond)
0cf6dd15
TJB
2545{
2546 CORE_ADDR data_value;
2547
227c0bf4
PFC
2548 m_dreg_interface.detect (inferior_ptid);
2549
2550 return (m_dreg_interface.hwdebug_p ()
2551 && (m_dreg_interface.hwdebug_info ().num_condition_regs > 0)
e7db58ea 2552 && check_condition (addr, cond, &data_value, &len));
0cf6dd15
TJB
2553}
2554
e09342b5
TJB
2555/* Set up P with the parameters necessary to request a watchpoint covering
2556 LEN bytes starting at ADDR and if possible with condition expression COND
2557 evaluated by hardware. INSERT tells if we are creating a request for
2558 inserting or removing the watchpoint. */
2559
227c0bf4
PFC
2560void
2561ppc_linux_nat_target::create_watchpoint_request (struct ppc_hw_breakpoint *p,
2562 CORE_ADDR addr, int len,
2563 enum target_hw_bp_type type,
2564 struct expression *cond,
2565 int insert)
e09342b5 2566{
227c0bf4
PFC
2567 const struct ppc_debug_info &hwdebug_info = (m_dreg_interface
2568 .hwdebug_info ());
2569
f16c4e8b 2570 if (len == 1
926bf92d 2571 || !(hwdebug_info.features & PPC_DEBUG_FEATURE_DATA_BP_RANGE))
e09342b5
TJB
2572 {
2573 int use_condition;
2574 CORE_ADDR data_value;
2575
2576 use_condition = (insert? can_use_watchpoint_cond_accel ()
926bf92d 2577 : hwdebug_info.num_condition_regs > 0);
e7db58ea
TJB
2578 if (cond && use_condition && check_condition (addr, cond,
2579 &data_value, &len))
e09342b5
TJB
2580 calculate_dvc (addr, len, data_value, &p->condition_mode,
2581 &p->condition_value);
2582 else
2583 {
2584 p->condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
2585 p->condition_value = 0;
2586 }
2587
2588 p->addr_mode = PPC_BREAKPOINT_MODE_EXACT;
2589 p->addr2 = 0;
2590 }
2591 else
2592 {
2593 p->addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
2594 p->condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
2595 p->condition_value = 0;
2596
2597 /* The watchpoint will trigger if the address of the memory access is
2598 within the defined range, as follows: p->addr <= address < p->addr2.
2599
2600 Note that the above sentence just documents how ptrace interprets
2601 its arguments; the watchpoint is set to watch the range defined by
2602 the user _inclusively_, as specified by the user interface. */
2603 p->addr2 = (uint64_t) addr + len;
2604 }
2605
2606 p->version = PPC_DEBUG_CURRENT_VERSION;
e76460db 2607 p->trigger_type = get_trigger_type (type);
e09342b5
TJB
2608 p->addr = (uint64_t) addr;
2609}
2610
227c0bf4
PFC
2611/* Register a watchpoint, to be inserted when the threads of the group of
2612 inferior_ptid are next resumed. Returns 0 on success, and -1 if there
2613 is no ptrace interface available to install the watchpoint. */
2614
f6ac5f3d
PA
2615int
2616ppc_linux_nat_target::insert_watchpoint (CORE_ADDR addr, int len,
2617 enum target_hw_bp_type type,
2618 struct expression *cond)
6ffbb7ab 2619{
227c0bf4
PFC
2620 m_dreg_interface.detect (inferior_ptid);
2621
2622 if (m_dreg_interface.unavailable_p ())
2623 return -1;
6ffbb7ab 2624
227c0bf4 2625 if (m_dreg_interface.hwdebug_p ())
e0d24f8d 2626 {
6ffbb7ab
TJB
2627 struct ppc_hw_breakpoint p;
2628
e76460db 2629 create_watchpoint_request (&p, addr, len, type, cond, 1);
6ffbb7ab 2630
227c0bf4 2631 register_hw_breakpoint (inferior_ptid.pid (), p);
e0d24f8d 2632 }
6ffbb7ab
TJB
2633 else
2634 {
227c0bf4
PFC
2635 gdb_assert (m_dreg_interface.debugreg_p ());
2636
2637 long wp_value;
6ffbb7ab 2638 long read_mode, write_mode;
e0d24f8d 2639
82d23ca8 2640 if (linux_get_hwcap () & PPC_FEATURE_BOOKE)
6ffbb7ab
TJB
2641 {
2642 /* PowerPC 440 requires only the read/write flags to be passed
2643 to the kernel. */
ad422571 2644 read_mode = 1;
6ffbb7ab
TJB
2645 write_mode = 2;
2646 }
2647 else
2648 {
2649 /* PowerPC 970 and other DABR-based processors are required to pass
2650 the Breakpoint Translation bit together with the flags. */
ad422571 2651 read_mode = 5;
6ffbb7ab
TJB
2652 write_mode = 6;
2653 }
1c86e440 2654
227c0bf4 2655 wp_value = addr & ~(read_mode | write_mode);
e76460db 2656 switch (type)
6ffbb7ab
TJB
2657 {
2658 case hw_read:
2659 /* Set read and translate bits. */
227c0bf4 2660 wp_value |= read_mode;
6ffbb7ab
TJB
2661 break;
2662 case hw_write:
2663 /* Set write and translate bits. */
227c0bf4 2664 wp_value |= write_mode;
6ffbb7ab
TJB
2665 break;
2666 case hw_access:
2667 /* Set read, write and translate bits. */
227c0bf4 2668 wp_value |= read_mode | write_mode;
6ffbb7ab
TJB
2669 break;
2670 }
1c86e440 2671
227c0bf4 2672 register_wp (inferior_ptid.pid (), wp_value);
6ffbb7ab
TJB
2673 }
2674
227c0bf4 2675 return 0;
e0d24f8d
WZ
2676}
2677
227c0bf4
PFC
2678/* Clear a registration for a hardware watchpoint. It will be removed
2679 from the threads of the group of inferior_ptid when they are next
2680 resumed. */
2681
f6ac5f3d
PA
2682int
2683ppc_linux_nat_target::remove_watchpoint (CORE_ADDR addr, int len,
2684 enum target_hw_bp_type type,
2685 struct expression *cond)
e0d24f8d 2686{
227c0bf4 2687 gdb_assert (!m_dreg_interface.unavailable_p ());
9f0bdab8 2688
227c0bf4 2689 if (m_dreg_interface.hwdebug_p ())
6ffbb7ab
TJB
2690 {
2691 struct ppc_hw_breakpoint p;
2692
e76460db 2693 create_watchpoint_request (&p, addr, len, type, cond, 0);
6ffbb7ab 2694
227c0bf4 2695 clear_hw_breakpoint (inferior_ptid.pid (), p);
6ffbb7ab
TJB
2696 }
2697 else
2698 {
227c0bf4 2699 gdb_assert (m_dreg_interface.debugreg_p ());
6ffbb7ab 2700
227c0bf4 2701 clear_wp (inferior_ptid.pid ());
6ffbb7ab
TJB
2702 }
2703
227c0bf4 2704 return 0;
e0d24f8d
WZ
2705}
2706
227c0bf4
PFC
2707/* Clean up the per-process info associated with PID. When using the
2708 HWDEBUG interface, we also erase the per-thread state of installed
2709 debug registers for all the threads that belong to the group of PID.
2710
2711 Usually the thread state is cleaned up by low_delete_thread. We also
2712 do it here because low_new_thread is not called for the initial LWP,
2713 so low_delete_thread won't be able to clean up this state. */
2714
135340af 2715void
227c0bf4 2716ppc_linux_nat_target::low_forget_process (pid_t pid)
e0d24f8d 2717{
227c0bf4
PFC
2718 if ((!m_dreg_interface.detected_p ())
2719 || (m_dreg_interface.unavailable_p ()))
2720 return;
6ffbb7ab 2721
227c0bf4
PFC
2722 ptid_t pid_ptid (pid, 0, 0);
2723
2724 m_process_info.erase (pid);
2725
2726 if (m_dreg_interface.hwdebug_p ())
6ffbb7ab 2727 {
227c0bf4
PFC
2728 for (auto it = m_installed_hw_bps.begin ();
2729 it != m_installed_hw_bps.end ();)
2730 {
2731 if (it->first.matches (pid_ptid))
2732 it = m_installed_hw_bps.erase (it);
2733 else
2734 it++;
2735 }
2736 }
2737}
6ffbb7ab 2738
227c0bf4 2739/* Copy the per-process state associated with the pid of PARENT to the
3bfdcabb 2740 state of CHILD_PID. GDB expects that a forked process will have the
227c0bf4 2741 same hardware breakpoints and watchpoints as the parent.
6ffbb7ab 2742
227c0bf4
PFC
2743 If we're using the HWDEBUG interface, also copy the thread debug
2744 register state for the ptid of PARENT to the state for CHILD_PID.
6ffbb7ab 2745
227c0bf4
PFC
2746 Like for clone events, we assume the kernel will copy the debug
2747 registers from the parent thread to the child. The
2748 low_prepare_to_resume function is made to work even if it doesn't.
aacbb8a5 2749
227c0bf4
PFC
2750 We copy the thread state here and not in low_new_thread since we don't
2751 have the pid of the parent in low_new_thread. Even if we did,
2752 low_new_thread might not be called immediately after the fork event is
2753 detected. For instance, with the checkpointing system (see
2754 linux-fork.c), the thread won't be added until GDB decides to switch
2755 to a new checkpointed process. At that point, the debug register
2756 state of the parent thread is unlikely to correspond to the state it
2757 had at the point when it forked. */
aacbb8a5 2758
227c0bf4
PFC
2759void
2760ppc_linux_nat_target::low_new_fork (struct lwp_info *parent,
2761 pid_t child_pid)
2762{
2763 if ((!m_dreg_interface.detected_p ())
2764 || (m_dreg_interface.unavailable_p ()))
2765 return;
2766
2767 auto process_it = m_process_info.find (parent->ptid.pid ());
2768
2769 if (process_it != m_process_info.end ())
2770 m_process_info[child_pid] = m_process_info[parent->ptid.pid ()];
2771
2772 if (m_dreg_interface.hwdebug_p ())
2773 {
2774 ptid_t child_ptid (child_pid, child_pid, 0);
2775
2776 copy_thread_dreg_state (parent->ptid, child_ptid);
6ffbb7ab 2777 }
6ffbb7ab
TJB
2778}
2779
227c0bf4
PFC
2780/* Copy the thread debug register state from the PARENT thread to the the
2781 state for CHILD_LWP, if we're using the HWDEBUG interface. We assume
2782 the kernel copies the debug registers from one thread to another after
2783 a clone event. The low_prepare_to_resume function is made to work
2784 even if it doesn't. */
2785
2786void
2787ppc_linux_nat_target::low_new_clone (struct lwp_info *parent,
2788 pid_t child_lwp)
6ffbb7ab 2789{
227c0bf4
PFC
2790 if ((!m_dreg_interface.detected_p ())
2791 || (m_dreg_interface.unavailable_p ()))
2792 return;
2793
2794 if (m_dreg_interface.hwdebug_p ())
2795 {
2796 ptid_t child_ptid (parent->ptid.pid (), child_lwp, 0);
2797
2798 copy_thread_dreg_state (parent->ptid, child_ptid);
2799 }
2800}
2801
2802/* Initialize the arch-specific thread state for LP so that it contains
2803 the ptid for lp, so that we can use it in low_delete_thread. Mark the
2804 new thread LP as stale so that we update its debug registers before
2805 resuming it. This is not called for the initial thread. */
2806
2807void
2808ppc_linux_nat_target::low_new_thread (struct lwp_info *lp)
2809{
2810 init_arch_lwp_info (lp);
2811
2812 mark_thread_stale (lp);
2813}
2814
2815/* Delete the per-thread debug register stale flag. */
2816
2817void
2818ppc_linux_nat_target::low_delete_thread (struct arch_lwp_info
2819 *lp_arch_info)
2820{
2821 if (lp_arch_info != NULL)
2822 {
2823 if (m_dreg_interface.detected_p ()
2824 && m_dreg_interface.hwdebug_p ())
2825 m_installed_hw_bps.erase (lp_arch_info->lwp_ptid);
2826
2827 xfree (lp_arch_info);
2828 }
2829}
2830
2831/* Install or delete debug registers in thread LP so that it matches what
2832 GDB requested before it is resumed. */
2833
2834void
2835ppc_linux_nat_target::low_prepare_to_resume (struct lwp_info *lp)
2836{
2837 if ((!m_dreg_interface.detected_p ())
2838 || (m_dreg_interface.unavailable_p ()))
2839 return;
2840
2841 /* We have to re-install or clear the debug registers if we set the
2842 stale flag.
2843
2844 In addition, some kernels configurations can disable a hardware
2845 watchpoint after it is hit. Usually, GDB will remove and re-install
2846 a hardware watchpoint when the thread stops if "breakpoint
2847 always-inserted" is off, or to single-step a watchpoint. But so
2848 that we don't rely on this behavior, if we stop due to a hardware
2849 breakpoint or watchpoint, we also refresh our debug registers. */
2850
2851 arch_lwp_info *lp_arch_info = get_arch_lwp_info (lp);
6ffbb7ab 2852
227c0bf4
PFC
2853 bool stale_dregs = (lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT
2854 || lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT
2855 || lp_arch_info->debug_regs_stale);
2856
2857 if (!stale_dregs)
6ffbb7ab
TJB
2858 return;
2859
227c0bf4
PFC
2860 gdb_assert (lp->ptid.lwp_p ());
2861
2862 auto process_it = m_process_info.find (lp->ptid.pid ());
2863
2864 if (m_dreg_interface.hwdebug_p ())
5da01df5 2865 {
227c0bf4
PFC
2866 /* First, delete any hardware watchpoint or breakpoint installed in
2867 the inferior and update the thread state. */
2868 auto installed_it = m_installed_hw_bps.find (lp->ptid);
2869
2870 if (installed_it != m_installed_hw_bps.end ())
5da01df5 2871 {
227c0bf4
PFC
2872 auto &bp_list = installed_it->second;
2873
2874 for (auto bp_it = bp_list.begin (); bp_it != bp_list.end ();)
2875 {
2876 /* We ignore ENOENT to account for various possible kernel
2877 behaviors, e.g. the kernel might or might not copy debug
2878 registers across forks and clones, and we always copy
2879 the debug register state when fork and clone events are
2880 detected. */
2881 if (ptrace (PPC_PTRACE_DELHWDEBUG, lp->ptid.lwp (), 0,
6e562fa3 2882 bp_it->first) < 0)
227c0bf4
PFC
2883 if (errno != ENOENT)
2884 perror_with_name (_("Error deleting hardware "
2885 "breakpoint or watchpoint"));
2886
33b5899f 2887 /* We erase the entries one at a time after successfully
227c0bf4
PFC
2888 removing the corresponding slot form the thread so that
2889 if we throw an exception above in a future iteration the
2890 map remains consistent. */
2891 bp_it = bp_list.erase (bp_it);
2892 }
2893
2894 gdb_assert (bp_list.empty ());
2895 }
2896
2897 /* Now we install all the requested hardware breakpoints and
2898 watchpoints and update the thread state. */
2899
2900 if (process_it != m_process_info.end ())
2901 {
2902 auto &bp_list = m_installed_hw_bps[lp->ptid];
2903
2904 for (ppc_hw_breakpoint bp
2905 : process_it->second.requested_hw_bps)
2906 {
2907 long slot = ptrace (PPC_PTRACE_SETHWDEBUG, lp->ptid.lwp (),
2908 0, &bp);
2909
2910 if (slot < 0)
2911 perror_with_name (_("Error setting hardware "
2912 "breakpoint or watchpoint"));
2913
2914 /* Keep track of which slots we installed in this
2915 thread. */
2916 bp_list.emplace (bp_list.begin (), slot, bp);
2917 }
5da01df5
TT
2918 }
2919 }
227c0bf4
PFC
2920 else
2921 {
2922 gdb_assert (m_dreg_interface.debugreg_p ());
6ffbb7ab 2923
6ea815e7
PFC
2924 /* Passing 0 to PTRACE_SET_DEBUGREG will clear the watchpoint. We
2925 always clear the watchpoint instead of just overwriting it, in
2926 case there is a request for a new watchpoint, because on some
2927 older kernel versions and configurations simply overwriting the
2928 watchpoint after it was hit would not re-enable it. */
2929 if (ptrace (PTRACE_SET_DEBUGREG, lp->ptid.lwp (), 0, 0) < 0)
2930 perror_with_name (_("Error clearing hardware watchpoint"));
6ffbb7ab 2931
227c0bf4
PFC
2932 /* GDB requested a watchpoint to be installed. */
2933 if (process_it != m_process_info.end ()
2934 && process_it->second.requested_wp_val.has_value ())
6ea815e7
PFC
2935 {
2936 long wp = *(process_it->second.requested_wp_val);
6ffbb7ab 2937
6ea815e7
PFC
2938 if (ptrace (PTRACE_SET_DEBUGREG, lp->ptid.lwp (), 0, wp) < 0)
2939 perror_with_name (_("Error setting hardware watchpoint"));
2940 }
227c0bf4 2941 }
6ffbb7ab 2942
227c0bf4 2943 lp_arch_info->debug_regs_stale = false;
e0d24f8d
WZ
2944}
2945
227c0bf4
PFC
2946/* Return true if INFERIOR_PTID is known to have been stopped by a
2947 hardware watchpoint, false otherwise. If true is returned, write the
2948 address that the kernel reported as causing the SIGTRAP in ADDR_P. */
2949
57810aa7 2950bool
227c0bf4 2951ppc_linux_nat_target::low_stopped_data_address (CORE_ADDR *addr_p)
e0d24f8d 2952{
f865ee35 2953 siginfo_t siginfo;
e0d24f8d 2954
f865ee35 2955 if (!linux_nat_get_siginfo (inferior_ptid, &siginfo))
57810aa7 2956 return false;
e0d24f8d 2957
f865ee35
JK
2958 if (siginfo.si_signo != SIGTRAP
2959 || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
57810aa7 2960 return false;
e0d24f8d 2961
227c0bf4
PFC
2962 gdb_assert (!m_dreg_interface.unavailable_p ());
2963
2964 /* Check if this signal corresponds to a hardware breakpoint. We only
2965 need to check this if we're using the HWDEBUG interface, since the
2966 DEBUGREG interface only allows setting one hardware watchpoint. */
2967 if (m_dreg_interface.hwdebug_p ())
6ffbb7ab 2968 {
227c0bf4
PFC
2969 /* The index (or slot) of the *point is passed in the si_errno
2970 field. Currently, this is only the case if the kernel was
2971 configured with CONFIG_PPC_ADV_DEBUG_REGS. If not, we assume
2972 the kernel will set si_errno to a value that doesn't correspond
2973 to any real slot. */
f865ee35 2974 int slot = siginfo.si_errno;
6ffbb7ab 2975
227c0bf4 2976 auto installed_it = m_installed_hw_bps.find (inferior_ptid);
6ffbb7ab 2977
227c0bf4
PFC
2978 /* We must have installed slots for the thread if it got a
2979 TRAP_HWBKPT signal. */
2980 gdb_assert (installed_it != m_installed_hw_bps.end ());
2981
2982 for (const auto & slot_bp_pair : installed_it->second)
2983 if (slot_bp_pair.first == slot
2984 && (slot_bp_pair.second.trigger_type
2985 == PPC_BREAKPOINT_TRIGGER_EXECUTE))
2986 return false;
6ffbb7ab
TJB
2987 }
2988
f865ee35 2989 *addr_p = (CORE_ADDR) (uintptr_t) siginfo.si_addr;
57810aa7 2990 return true;
e0d24f8d
WZ
2991}
2992
227c0bf4
PFC
2993/* Return true if INFERIOR_PTID is known to have been stopped by a
2994 hardware watchpoint, false otherwise. */
2995
57810aa7 2996bool
227c0bf4 2997ppc_linux_nat_target::low_stopped_by_watchpoint ()
9f0bdab8
DJ
2998{
2999 CORE_ADDR addr;
227c0bf4 3000 return low_stopped_data_address (&addr);
9f0bdab8
DJ
3001}
3002
57810aa7 3003bool
f6ac5f3d
PA
3004ppc_linux_nat_target::watchpoint_addr_within_range (CORE_ADDR addr,
3005 CORE_ADDR start,
3006 int length)
5009afc5 3007{
227c0bf4
PFC
3008 gdb_assert (!m_dreg_interface.unavailable_p ());
3009
b7622095
LM
3010 int mask;
3011
227c0bf4 3012 if (m_dreg_interface.hwdebug_p ()
82d23ca8 3013 && (linux_get_hwcap () & PPC_FEATURE_BOOKE))
6ffbb7ab 3014 return start <= addr && start + length >= addr;
82d23ca8 3015 else if (linux_get_hwcap () & PPC_FEATURE_BOOKE)
b7622095
LM
3016 mask = 3;
3017 else
3018 mask = 7;
3019
3020 addr &= ~mask;
3021
0df8b418 3022 /* Check whether [start, start+length-1] intersects [addr, addr+mask]. */
b7622095 3023 return start <= addr + mask && start + length - 1 >= addr;
5009afc5
AS
3024}
3025
9c06b0b4
TJB
3026/* Return the number of registers needed for a masked hardware watchpoint. */
3027
f6ac5f3d 3028int
227c0bf4
PFC
3029ppc_linux_nat_target::masked_watch_num_registers (CORE_ADDR addr,
3030 CORE_ADDR mask)
9c06b0b4 3031{
227c0bf4
PFC
3032 m_dreg_interface.detect (inferior_ptid);
3033
3034 if (!m_dreg_interface.hwdebug_p ()
3035 || (m_dreg_interface.hwdebug_info ().features
3036 & PPC_DEBUG_FEATURE_DATA_BP_MASK) == 0)
9c06b0b4
TJB
3037 return -1;
3038 else if ((mask & 0xC0000000) != 0xC0000000)
3039 {
3040 warning (_("The given mask covers kernel address space "
3041 "and cannot be used.\n"));
3042
3043 return -2;
3044 }
3045 else
3046 return 2;
3047}
3048
227c0bf4
PFC
3049/* Copy the per-thread debug register state, if any, from thread
3050 PARENT_PTID to thread CHILD_PTID, if the debug register being used is
3051 HWDEBUG. */
3052
3053void
3054ppc_linux_nat_target::copy_thread_dreg_state (const ptid_t &parent_ptid,
3055 const ptid_t &child_ptid)
3056{
3057 gdb_assert (m_dreg_interface.hwdebug_p ());
3058
3059 auto installed_it = m_installed_hw_bps.find (parent_ptid);
3060
3061 if (installed_it != m_installed_hw_bps.end ())
3062 m_installed_hw_bps[child_ptid] = m_installed_hw_bps[parent_ptid];
3063}
3064
3065/* Mark the debug register stale flag for the new thread, if we have
3066 already detected which debug register interface we use. */
3067
3068void
3069ppc_linux_nat_target::mark_thread_stale (struct lwp_info *lp)
3070{
3071 if ((!m_dreg_interface.detected_p ())
3072 || (m_dreg_interface.unavailable_p ()))
3073 return;
3074
3075 arch_lwp_info *lp_arch_info = get_arch_lwp_info (lp);
3076
3077 lp_arch_info->debug_regs_stale = true;
3078}
3079
3080/* Mark all the threads of the group of PID as stale with respect to
3081 debug registers and issue a stop request to each such thread that
3082 isn't already stopped. */
3083
3084void
3085ppc_linux_nat_target::mark_debug_registers_changed (pid_t pid)
3086{
3087 /* We do this in two passes to make sure all threads are marked even if
3088 we get an exception when stopping one of them. */
3089
3090 iterate_over_lwps (ptid_t (pid),
3091 [this] (struct lwp_info *lp) -> int {
3092 this->mark_thread_stale (lp);
3093 return 0;
3094 });
3095
3096 iterate_over_lwps (ptid_t (pid),
3097 [] (struct lwp_info *lp) -> int {
3098 if (!lwp_is_stopped (lp))
3099 linux_stop_lwp (lp);
3100 return 0;
3101 });
3102}
3103
3104/* Register a hardware breakpoint or watchpoint BP for the pid PID, then
3105 mark the stale flag for all threads of the group of PID, and issue a
3106 stop request for them. The breakpoint or watchpoint will be installed
3107 the next time each thread is resumed. Should only be used if the
3108 debug register interface is HWDEBUG. */
3109
3110void
3111ppc_linux_nat_target::register_hw_breakpoint (pid_t pid,
3112 const struct
3113 ppc_hw_breakpoint &bp)
3114{
3115 gdb_assert (m_dreg_interface.hwdebug_p ());
3116
3117 m_process_info[pid].requested_hw_bps.push_back (bp);
3118
3119 mark_debug_registers_changed (pid);
3120}
3121
3122/* Clear a registration for a hardware breakpoint or watchpoint BP for
3123 the pid PID, then mark the stale flag for all threads of the group of
3124 PID, and issue a stop request for them. The breakpoint or watchpoint
3125 will be removed the next time each thread is resumed. Should only be
3126 used if the debug register interface is HWDEBUG. */
3127
3128void
3129ppc_linux_nat_target::clear_hw_breakpoint (pid_t pid,
3130 const struct ppc_hw_breakpoint &bp)
3131{
3132 gdb_assert (m_dreg_interface.hwdebug_p ());
3133
3134 auto process_it = m_process_info.find (pid);
3135
3136 gdb_assert (process_it != m_process_info.end ());
3137
3138 auto bp_it = std::find_if (process_it->second.requested_hw_bps.begin (),
3139 process_it->second.requested_hw_bps.end (),
3140 [&bp, this]
3141 (const struct ppc_hw_breakpoint &curr)
3142 { return hwdebug_point_cmp (bp, curr); }
3143 );
3144
3145 /* If GDB is removing a watchpoint, it must have been inserted. */
3146 gdb_assert (bp_it != process_it->second.requested_hw_bps.end ());
3147
3148 process_it->second.requested_hw_bps.erase (bp_it);
3149
3150 mark_debug_registers_changed (pid);
3151}
3152
3153/* Register the hardware watchpoint value WP_VALUE for the pid PID,
3154 then mark the stale flag for all threads of the group of PID, and
3155 issue a stop request for them. The breakpoint or watchpoint will be
3156 installed the next time each thread is resumed. Should only be used
3157 if the debug register interface is DEBUGREG. */
3158
3159void
3160ppc_linux_nat_target::register_wp (pid_t pid, long wp_value)
3161{
3162 gdb_assert (m_dreg_interface.debugreg_p ());
3163
3164 /* Our other functions should have told GDB that we only have one
3165 hardware watchpoint with this interface. */
3166 gdb_assert (!m_process_info[pid].requested_wp_val.has_value ());
3167
3168 m_process_info[pid].requested_wp_val.emplace (wp_value);
3169
3170 mark_debug_registers_changed (pid);
3171}
3172
3173/* Clear the hardware watchpoint registration for the pid PID, then mark
3174 the stale flag for all threads of the group of PID, and issue a stop
3175 request for them. The breakpoint or watchpoint will be installed the
3176 next time each thread is resumed. Should only be used if the debug
3177 register interface is DEBUGREG. */
3178
3179void
3180ppc_linux_nat_target::clear_wp (pid_t pid)
3181{
3182 gdb_assert (m_dreg_interface.debugreg_p ());
3183
3184 auto process_it = m_process_info.find (pid);
3185
3186 gdb_assert (process_it != m_process_info.end ());
3187 gdb_assert (process_it->second.requested_wp_val.has_value ());
3188
3189 process_it->second.requested_wp_val.reset ();
3190
3191 mark_debug_registers_changed (pid);
3192}
3193
3194/* Initialize the arch-specific thread state for LWP, if it not already
3195 created. */
3196
3197void
3198ppc_linux_nat_target::init_arch_lwp_info (struct lwp_info *lp)
3199{
3200 if (lwp_arch_private_info (lp) == NULL)
3201 {
3202 lwp_set_arch_private_info (lp, XCNEW (struct arch_lwp_info));
3203 lwp_arch_private_info (lp)->debug_regs_stale = false;
3204 lwp_arch_private_info (lp)->lwp_ptid = lp->ptid;
3205 }
3206}
3207
3208/* Get the arch-specific thread state for LWP, creating it if
3209 necessary. */
3210
3211arch_lwp_info *
3212ppc_linux_nat_target::get_arch_lwp_info (struct lwp_info *lp)
3213{
3214 init_arch_lwp_info (lp);
3215
3216 return lwp_arch_private_info (lp);
3217}
3218
6c265988 3219void _initialize_ppc_linux_nat ();
10d6c8cd 3220void
6c265988 3221_initialize_ppc_linux_nat ()
10d6c8cd 3222{
f6ac5f3d 3223 linux_target = &the_ppc_linux_nat_target;
310a98e1 3224
10d6c8cd 3225 /* Register the target. */
d9f719f1 3226 add_inf_child_target (linux_target);
10d6c8cd 3227}