1 /* GNU/Linux/ARM specific low level interface, for the remote server for GDB.
2 Copyright (C) 1995-2020 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "linux-low.h"
22 #include "arch/arm-linux.h"
23 #include "arch/arm-get-next-pcs.h"
24 #include "linux-aarch32-low.h"
25 #include "linux-aarch32-tdesc.h"
26 #include "linux-arm-tdesc.h"
29 /* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
30 On Bionic elf.h and linux/elf.h have conflicting definitions. */
34 #include "nat/gdb_ptrace.h"
36 #include <sys/syscall.h>
38 #ifndef PTRACE_GET_THREAD_AREA
39 #define PTRACE_GET_THREAD_AREA 22
42 #ifndef PTRACE_GETWMMXREGS
43 # define PTRACE_GETWMMXREGS 18
44 # define PTRACE_SETWMMXREGS 19
47 #ifndef PTRACE_GETVFPREGS
48 # define PTRACE_GETVFPREGS 27
49 # define PTRACE_SETVFPREGS 28
52 #ifndef PTRACE_GETHBPREGS
53 #define PTRACE_GETHBPREGS 29
54 #define PTRACE_SETHBPREGS 30
57 /* Linux target op definitions for the ARM architecture. */
59 class arm_target
: public linux_process_target
65 /* The singleton target ops object. */
67 static arm_target the_arm_target
;
69 /* Information describing the hardware breakpoint capabilities. */
73 unsigned char max_wp_length
;
74 unsigned char wp_count
;
75 unsigned char bp_count
;
78 /* Enum describing the different types of ARM hardware break-/watch-points. */
87 /* Type describing an ARM Hardware Breakpoint Control register value. */
88 typedef unsigned int arm_hwbp_control_t
;
90 /* Structure used to keep track of hardware break-/watch-points. */
91 struct arm_linux_hw_breakpoint
93 /* Address to break on, or being watched. */
95 /* Control register for break-/watch- point. */
96 arm_hwbp_control_t control
;
99 /* Since we cannot dynamically allocate subfields of arch_process_info,
100 assume a maximum number of supported break-/watchpoints. */
104 /* Per-process arch-specific data we want to keep. */
105 struct arch_process_info
107 /* Hardware breakpoints for this process. */
108 struct arm_linux_hw_breakpoint bpts
[MAX_BPTS
];
109 /* Hardware watchpoints for this process. */
110 struct arm_linux_hw_breakpoint wpts
[MAX_WPTS
];
113 /* Per-thread arch-specific data we want to keep. */
116 /* Non-zero if our copy differs from what's recorded in the thread. */
117 char bpts_changed
[MAX_BPTS
];
118 char wpts_changed
[MAX_WPTS
];
119 /* Cached stopped data address. */
120 CORE_ADDR stopped_data_address
;
123 /* These are in <asm/elf.h> in current kernels. */
125 #define HWCAP_IWMMXT 512
126 #define HWCAP_NEON 4096
127 #define HWCAP_VFPv3 8192
128 #define HWCAP_VFPv3D16 16384
130 #ifdef HAVE_SYS_REG_H
134 #define arm_num_regs 26
136 static int arm_regmap
[] = {
137 0, 4, 8, 12, 16, 20, 24, 28,
138 32, 36, 40, 44, 48, 52, 56, 60,
139 -1, -1, -1, -1, -1, -1, -1, -1, -1,
143 /* Forward declarations needed for get_next_pcs ops. */
144 static ULONGEST
get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr
,
148 static CORE_ADDR
get_next_pcs_addr_bits_remove (struct arm_get_next_pcs
*self
,
151 static CORE_ADDR
get_next_pcs_syscall_next_pc (struct arm_get_next_pcs
*self
);
153 static int get_next_pcs_is_thumb (struct arm_get_next_pcs
*self
);
155 /* get_next_pcs operations. */
156 static struct arm_get_next_pcs_ops get_next_pcs_ops
= {
157 get_next_pcs_read_memory_unsigned_integer
,
158 get_next_pcs_syscall_next_pc
,
159 get_next_pcs_addr_bits_remove
,
160 get_next_pcs_is_thumb
,
161 arm_linux_get_next_pcs_fixup
,
165 arm_cannot_store_register (int regno
)
167 return (regno
>= arm_num_regs
);
171 arm_cannot_fetch_register (int regno
)
173 return (regno
>= arm_num_regs
);
177 arm_fill_wmmxregset (struct regcache
*regcache
, void *buf
)
179 if (arm_linux_get_tdesc_fp_type (regcache
->tdesc
) != ARM_FP_TYPE_IWMMXT
)
182 for (int i
= 0; i
< 16; i
++)
183 collect_register (regcache
, arm_num_regs
+ i
, (char *) buf
+ i
* 8);
185 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
186 for (int i
= 0; i
< 6; i
++)
187 collect_register (regcache
, arm_num_regs
+ i
+ 16,
188 (char *) buf
+ 16 * 8 + i
* 4);
192 arm_store_wmmxregset (struct regcache
*regcache
, const void *buf
)
194 if (arm_linux_get_tdesc_fp_type (regcache
->tdesc
) != ARM_FP_TYPE_IWMMXT
)
197 for (int i
= 0; i
< 16; i
++)
198 supply_register (regcache
, arm_num_regs
+ i
, (char *) buf
+ i
* 8);
200 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
201 for (int i
= 0; i
< 6; i
++)
202 supply_register (regcache
, arm_num_regs
+ i
+ 16,
203 (char *) buf
+ 16 * 8 + i
* 4);
207 arm_fill_vfpregset (struct regcache
*regcache
, void *buf
)
211 if (is_aarch32_linux_description (regcache
->tdesc
))
215 arm_fp_type fp_type
= arm_linux_get_tdesc_fp_type (regcache
->tdesc
);
217 if (fp_type
== ARM_FP_TYPE_VFPV3
)
219 else if (fp_type
== ARM_FP_TYPE_VFPV2
)
225 arm_fill_vfpregset_num (regcache
, buf
, num
);
228 /* Wrapper of UNMAKE_THUMB_ADDR for get_next_pcs. */
230 get_next_pcs_addr_bits_remove (struct arm_get_next_pcs
*self
, CORE_ADDR val
)
232 return UNMAKE_THUMB_ADDR (val
);
236 arm_store_vfpregset (struct regcache
*regcache
, const void *buf
)
240 if (is_aarch32_linux_description (regcache
->tdesc
))
244 arm_fp_type fp_type
= arm_linux_get_tdesc_fp_type (regcache
->tdesc
);
246 if (fp_type
== ARM_FP_TYPE_VFPV3
)
248 else if (fp_type
== ARM_FP_TYPE_VFPV2
)
254 arm_store_vfpregset_num (regcache
, buf
, num
);
257 /* Wrapper of arm_is_thumb_mode for get_next_pcs. */
259 get_next_pcs_is_thumb (struct arm_get_next_pcs
*self
)
261 return arm_is_thumb_mode ();
264 /* Read memory from the inferior.
265 BYTE_ORDER is ignored and there to keep compatiblity with GDB's
266 read_memory_unsigned_integer. */
268 get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr
,
275 target_read_memory (memaddr
, (unsigned char *) &res
, len
);
280 /* Fetch the thread-local storage pointer for libthread_db. */
283 ps_get_thread_area (struct ps_prochandle
*ph
,
284 lwpid_t lwpid
, int idx
, void **base
)
286 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
289 /* IDX is the bias from the thread pointer to the beginning of the
290 thread descriptor. It has to be subtracted due to implementation
291 quirks in libthread_db. */
292 *base
= (void *) ((char *)*base
- idx
);
298 /* Query Hardware Breakpoint information for the target we are attached to
299 (using PID as ptrace argument) and set up arm_linux_hwbp_cap. */
301 arm_linux_init_hwbp_cap (int pid
)
305 if (ptrace (PTRACE_GETHBPREGS
, pid
, 0, &val
) < 0)
308 arm_linux_hwbp_cap
.arch
= (unsigned char)((val
>> 24) & 0xff);
309 if (arm_linux_hwbp_cap
.arch
== 0)
312 arm_linux_hwbp_cap
.max_wp_length
= (unsigned char)((val
>> 16) & 0xff);
313 arm_linux_hwbp_cap
.wp_count
= (unsigned char)((val
>> 8) & 0xff);
314 arm_linux_hwbp_cap
.bp_count
= (unsigned char)(val
& 0xff);
316 if (arm_linux_hwbp_cap
.wp_count
> MAX_WPTS
)
317 internal_error (__FILE__
, __LINE__
, "Unsupported number of watchpoints");
318 if (arm_linux_hwbp_cap
.bp_count
> MAX_BPTS
)
319 internal_error (__FILE__
, __LINE__
, "Unsupported number of breakpoints");
322 /* How many hardware breakpoints are available? */
324 arm_linux_get_hw_breakpoint_count (void)
326 return arm_linux_hwbp_cap
.bp_count
;
329 /* How many hardware watchpoints are available? */
331 arm_linux_get_hw_watchpoint_count (void)
333 return arm_linux_hwbp_cap
.wp_count
;
336 /* Maximum length of area watched by hardware watchpoint. */
338 arm_linux_get_hw_watchpoint_max_length (void)
340 return arm_linux_hwbp_cap
.max_wp_length
;
343 /* Initialize an ARM hardware break-/watch-point control register value.
344 BYTE_ADDRESS_SELECT is the mask of bytes to trigger on; HWBP_TYPE is the
345 type of break-/watch-point; ENABLE indicates whether the point is enabled.
347 static arm_hwbp_control_t
348 arm_hwbp_control_initialize (unsigned byte_address_select
,
349 arm_hwbp_type hwbp_type
,
352 gdb_assert ((byte_address_select
& ~0xffU
) == 0);
353 gdb_assert (hwbp_type
!= arm_hwbp_break
354 || ((byte_address_select
& 0xfU
) != 0));
356 return (byte_address_select
<< 5) | (hwbp_type
<< 3) | (3 << 1) | enable
;
359 /* Does the breakpoint control value CONTROL have the enable bit set? */
361 arm_hwbp_control_is_enabled (arm_hwbp_control_t control
)
363 return control
& 0x1;
366 /* Is the breakpoint control value CONTROL initialized? */
368 arm_hwbp_control_is_initialized (arm_hwbp_control_t control
)
373 /* Change a breakpoint control word so that it is in the disabled state. */
374 static arm_hwbp_control_t
375 arm_hwbp_control_disable (arm_hwbp_control_t control
)
377 return control
& ~0x1;
380 /* Are two break-/watch-points equal? */
382 arm_linux_hw_breakpoint_equal (const struct arm_linux_hw_breakpoint
*p1
,
383 const struct arm_linux_hw_breakpoint
*p2
)
385 return p1
->address
== p2
->address
&& p1
->control
== p2
->control
;
388 /* Convert a raw breakpoint type to an enum arm_hwbp_type. */
391 raw_bkpt_type_to_arm_hwbp_type (enum raw_bkpt_type raw_type
)
395 case raw_bkpt_type_hw
:
396 return arm_hwbp_break
;
397 case raw_bkpt_type_write_wp
:
398 return arm_hwbp_store
;
399 case raw_bkpt_type_read_wp
:
400 return arm_hwbp_load
;
401 case raw_bkpt_type_access_wp
:
402 return arm_hwbp_access
;
404 gdb_assert_not_reached ("unhandled raw type");
408 /* Initialize the hardware breakpoint structure P for a breakpoint or
409 watchpoint at ADDR to LEN. The type of watchpoint is given in TYPE.
410 Returns -1 if TYPE is unsupported, or -2 if the particular combination
411 of ADDR and LEN cannot be implemented. Otherwise, returns 0 if TYPE
412 represents a breakpoint and 1 if type represents a watchpoint. */
414 arm_linux_hw_point_initialize (enum raw_bkpt_type raw_type
, CORE_ADDR addr
,
415 int len
, struct arm_linux_hw_breakpoint
*p
)
417 arm_hwbp_type hwbp_type
;
420 hwbp_type
= raw_bkpt_type_to_arm_hwbp_type (raw_type
);
422 if (hwbp_type
== arm_hwbp_break
)
424 /* For breakpoints, the length field encodes the mode. */
427 case 2: /* 16-bit Thumb mode breakpoint */
428 case 3: /* 32-bit Thumb mode breakpoint */
432 case 4: /* 32-bit ARM mode breakpoint */
443 CORE_ADDR max_wp_length
= arm_linux_get_hw_watchpoint_max_length ();
444 CORE_ADDR aligned_addr
;
446 /* Can not set watchpoints for zero or negative lengths. */
449 /* The current ptrace interface can only handle watchpoints that are a
451 if ((len
& (len
- 1)) != 0)
454 /* Test that the range [ADDR, ADDR + LEN) fits into the largest address
455 range covered by a watchpoint. */
456 aligned_addr
= addr
& ~(max_wp_length
- 1);
457 if (aligned_addr
+ max_wp_length
< addr
+ len
)
460 mask
= (1 << len
) - 1;
463 p
->address
= (unsigned int) addr
;
464 p
->control
= arm_hwbp_control_initialize (mask
, hwbp_type
, 1);
466 return hwbp_type
!= arm_hwbp_break
;
469 /* Callback to mark a watch-/breakpoint to be updated in all threads of
470 the current process. */
473 update_registers_callback (thread_info
*thread
, int watch
, int i
)
475 struct lwp_info
*lwp
= get_thread_lwp (thread
);
477 /* The actual update is done later just before resuming the lwp,
478 we just mark that the registers need updating. */
480 lwp
->arch_private
->wpts_changed
[i
] = 1;
482 lwp
->arch_private
->bpts_changed
[i
] = 1;
484 /* If the lwp isn't stopped, force it to momentarily pause, so
485 we can update its breakpoint registers. */
487 linux_stop_lwp (lwp
);
491 arm_supports_z_point_type (char z_type
)
497 case Z_PACKET_WRITE_WP
:
498 case Z_PACKET_READ_WP
:
499 case Z_PACKET_ACCESS_WP
:
502 /* Leave the handling of sw breakpoints with the gdb client. */
507 /* Insert hardware break-/watchpoint. */
509 arm_insert_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
510 int len
, struct raw_breakpoint
*bp
)
512 struct process_info
*proc
= current_process ();
513 struct arm_linux_hw_breakpoint p
, *pts
;
516 watch
= arm_linux_hw_point_initialize (type
, addr
, len
, &p
);
520 return watch
== -1 ? 1 : -1;
525 count
= arm_linux_get_hw_watchpoint_count ();
526 pts
= proc
->priv
->arch_private
->wpts
;
530 count
= arm_linux_get_hw_breakpoint_count ();
531 pts
= proc
->priv
->arch_private
->bpts
;
534 for (i
= 0; i
< count
; i
++)
535 if (!arm_hwbp_control_is_enabled (pts
[i
].control
))
539 /* Only update the threads of the current process. */
540 for_each_thread (current_thread
->id
.pid (), [&] (thread_info
*thread
)
542 update_registers_callback (thread
, watch
, i
);
548 /* We're out of watchpoints. */
552 /* Remove hardware break-/watchpoint. */
554 arm_remove_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
555 int len
, struct raw_breakpoint
*bp
)
557 struct process_info
*proc
= current_process ();
558 struct arm_linux_hw_breakpoint p
, *pts
;
561 watch
= arm_linux_hw_point_initialize (type
, addr
, len
, &p
);
570 count
= arm_linux_get_hw_watchpoint_count ();
571 pts
= proc
->priv
->arch_private
->wpts
;
575 count
= arm_linux_get_hw_breakpoint_count ();
576 pts
= proc
->priv
->arch_private
->bpts
;
579 for (i
= 0; i
< count
; i
++)
580 if (arm_linux_hw_breakpoint_equal (&p
, pts
+ i
))
582 pts
[i
].control
= arm_hwbp_control_disable (pts
[i
].control
);
584 /* Only update the threads of the current process. */
585 for_each_thread (current_thread
->id
.pid (), [&] (thread_info
*thread
)
587 update_registers_callback (thread
, watch
, i
);
593 /* No watchpoint matched. */
597 /* Return whether current thread is stopped due to a watchpoint. */
599 arm_stopped_by_watchpoint (void)
601 struct lwp_info
*lwp
= get_thread_lwp (current_thread
);
604 /* We must be able to set hardware watchpoints. */
605 if (arm_linux_get_hw_watchpoint_count () == 0)
608 /* Retrieve siginfo. */
610 ptrace (PTRACE_GETSIGINFO
, lwpid_of (current_thread
), 0, &siginfo
);
614 /* This must be a hardware breakpoint. */
615 if (siginfo
.si_signo
!= SIGTRAP
616 || (siginfo
.si_code
& 0xffff) != 0x0004 /* TRAP_HWBKPT */)
619 /* If we are in a positive slot then we're looking at a breakpoint and not
621 if (siginfo
.si_errno
>= 0)
624 /* Cache stopped data address for use by arm_stopped_data_address. */
625 lwp
->arch_private
->stopped_data_address
626 = (CORE_ADDR
) (uintptr_t) siginfo
.si_addr
;
631 /* Return data address that triggered watchpoint. Called only if
632 arm_stopped_by_watchpoint returned true. */
634 arm_stopped_data_address (void)
636 struct lwp_info
*lwp
= get_thread_lwp (current_thread
);
637 return lwp
->arch_private
->stopped_data_address
;
640 /* Called when a new process is created. */
641 static struct arch_process_info
*
642 arm_new_process (void)
644 struct arch_process_info
*info
= XCNEW (struct arch_process_info
);
648 /* Called when a process is being deleted. */
651 arm_delete_process (struct arch_process_info
*info
)
656 /* Called when a new thread is detected. */
658 arm_new_thread (struct lwp_info
*lwp
)
660 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
663 for (i
= 0; i
< MAX_BPTS
; i
++)
664 info
->bpts_changed
[i
] = 1;
665 for (i
= 0; i
< MAX_WPTS
; i
++)
666 info
->wpts_changed
[i
] = 1;
668 lwp
->arch_private
= info
;
671 /* Function to call when a thread is being deleted. */
674 arm_delete_thread (struct arch_lwp_info
*arch_lwp
)
680 arm_new_fork (struct process_info
*parent
, struct process_info
*child
)
682 struct arch_process_info
*parent_proc_info
;
683 struct arch_process_info
*child_proc_info
;
684 struct lwp_info
*child_lwp
;
685 struct arch_lwp_info
*child_lwp_info
;
688 /* These are allocated by linux_add_process. */
689 gdb_assert (parent
->priv
!= NULL
690 && parent
->priv
->arch_private
!= NULL
);
691 gdb_assert (child
->priv
!= NULL
692 && child
->priv
->arch_private
!= NULL
);
694 parent_proc_info
= parent
->priv
->arch_private
;
695 child_proc_info
= child
->priv
->arch_private
;
697 /* Linux kernel before 2.6.33 commit
698 72f674d203cd230426437cdcf7dd6f681dad8b0d
699 will inherit hardware debug registers from parent
700 on fork/vfork/clone. Newer Linux kernels create such tasks with
701 zeroed debug registers.
703 GDB core assumes the child inherits the watchpoints/hw
704 breakpoints of the parent, and will remove them all from the
705 forked off process. Copy the debug registers mirrors into the
706 new process so that all breakpoints and watchpoints can be
707 removed together. The debug registers mirror will become zeroed
708 in the end before detaching the forked off process, thus making
709 this compatible with older Linux kernels too. */
711 *child_proc_info
= *parent_proc_info
;
713 /* Mark all the hardware breakpoints and watchpoints as changed to
714 make sure that the registers will be updated. */
715 child_lwp
= find_lwp_pid (ptid_t (child
->pid
));
716 child_lwp_info
= child_lwp
->arch_private
;
717 for (i
= 0; i
< MAX_BPTS
; i
++)
718 child_lwp_info
->bpts_changed
[i
] = 1;
719 for (i
= 0; i
< MAX_WPTS
; i
++)
720 child_lwp_info
->wpts_changed
[i
] = 1;
723 /* Called when resuming a thread.
724 If the debug regs have changed, update the thread's copies. */
726 arm_prepare_to_resume (struct lwp_info
*lwp
)
728 struct thread_info
*thread
= get_lwp_thread (lwp
);
729 int pid
= lwpid_of (thread
);
730 struct process_info
*proc
= find_process_pid (pid_of (thread
));
731 struct arch_process_info
*proc_info
= proc
->priv
->arch_private
;
732 struct arch_lwp_info
*lwp_info
= lwp
->arch_private
;
735 for (i
= 0; i
< arm_linux_get_hw_breakpoint_count (); i
++)
736 if (lwp_info
->bpts_changed
[i
])
740 if (arm_hwbp_control_is_enabled (proc_info
->bpts
[i
].control
))
741 if (ptrace (PTRACE_SETHBPREGS
, pid
,
742 (PTRACE_TYPE_ARG3
) ((i
<< 1) + 1),
743 &proc_info
->bpts
[i
].address
) < 0)
744 perror_with_name ("Unexpected error setting breakpoint address");
746 if (arm_hwbp_control_is_initialized (proc_info
->bpts
[i
].control
))
747 if (ptrace (PTRACE_SETHBPREGS
, pid
,
748 (PTRACE_TYPE_ARG3
) ((i
<< 1) + 2),
749 &proc_info
->bpts
[i
].control
) < 0)
750 perror_with_name ("Unexpected error setting breakpoint");
752 lwp_info
->bpts_changed
[i
] = 0;
755 for (i
= 0; i
< arm_linux_get_hw_watchpoint_count (); i
++)
756 if (lwp_info
->wpts_changed
[i
])
760 if (arm_hwbp_control_is_enabled (proc_info
->wpts
[i
].control
))
761 if (ptrace (PTRACE_SETHBPREGS
, pid
,
762 (PTRACE_TYPE_ARG3
) -((i
<< 1) + 1),
763 &proc_info
->wpts
[i
].address
) < 0)
764 perror_with_name ("Unexpected error setting watchpoint address");
766 if (arm_hwbp_control_is_initialized (proc_info
->wpts
[i
].control
))
767 if (ptrace (PTRACE_SETHBPREGS
, pid
,
768 (PTRACE_TYPE_ARG3
) -((i
<< 1) + 2),
769 &proc_info
->wpts
[i
].control
) < 0)
770 perror_with_name ("Unexpected error setting watchpoint");
772 lwp_info
->wpts_changed
[i
] = 0;
776 /* Find the next pc for a sigreturn or rt_sigreturn syscall. In
777 addition, set IS_THUMB depending on whether we will return to ARM
779 See arm-linux.h for stack layout details. */
781 arm_sigreturn_next_pc (struct regcache
*regcache
, int svc_number
,
785 unsigned long sp_data
;
786 /* Offset of PC register. */
788 CORE_ADDR next_pc
= 0;
791 gdb_assert (svc_number
== __NR_sigreturn
|| svc_number
== __NR_rt_sigreturn
);
793 collect_register_by_name (regcache
, "sp", &sp
);
794 the_target
->read_memory (sp
, (unsigned char *) &sp_data
, 4);
796 pc_offset
= arm_linux_sigreturn_next_pc_offset
797 (sp
, sp_data
, svc_number
, __NR_sigreturn
== svc_number
? 1 : 0);
799 the_target
->read_memory (sp
+ pc_offset
, (unsigned char *) &next_pc
, 4);
801 /* Set IS_THUMB according the CPSR saved on the stack. */
802 the_target
->read_memory (sp
+ pc_offset
+ 4, (unsigned char *) &cpsr
, 4);
803 *is_thumb
= ((cpsr
& CPSR_T
) != 0);
808 /* When PC is at a syscall instruction, return the PC of the next
809 instruction to be executed. */
811 get_next_pcs_syscall_next_pc (struct arm_get_next_pcs
*self
)
813 CORE_ADDR next_pc
= 0;
814 CORE_ADDR pc
= regcache_read_pc (self
->regcache
);
815 int is_thumb
= arm_is_thumb_mode ();
816 ULONGEST svc_number
= 0;
817 struct regcache
*regcache
= self
->regcache
;
821 collect_register (regcache
, 7, &svc_number
);
826 unsigned long this_instr
;
827 unsigned long svc_operand
;
829 target_read_memory (pc
, (unsigned char *) &this_instr
, 4);
830 svc_operand
= (0x00ffffff & this_instr
);
832 if (svc_operand
) /* OABI. */
834 svc_number
= svc_operand
- 0x900000;
838 collect_register (regcache
, 7, &svc_number
);
844 /* This is a sigreturn or sigreturn_rt syscall. */
845 if (svc_number
== __NR_sigreturn
|| svc_number
== __NR_rt_sigreturn
)
847 /* SIGRETURN or RT_SIGRETURN may affect the arm thumb mode, so
849 next_pc
= arm_sigreturn_next_pc (regcache
, svc_number
, &is_thumb
);
852 /* Addresses for calling Thumb functions have the bit 0 set. */
854 next_pc
= MAKE_THUMB_ADDR (next_pc
);
859 static const struct target_desc
*
860 arm_read_description (void)
862 unsigned long arm_hwcap
= linux_get_hwcap (4);
864 if (arm_hwcap
& HWCAP_IWMMXT
)
865 return arm_linux_read_description (ARM_FP_TYPE_IWMMXT
);
867 if (arm_hwcap
& HWCAP_VFP
)
869 /* Make sure that the kernel supports reading VFP registers. Support was
871 int pid
= lwpid_of (current_thread
);
873 char *buf
= (char *) alloca (ARM_VFP3_REGS_SIZE
);
874 if (ptrace (PTRACE_GETVFPREGS
, pid
, 0, buf
) < 0 && errno
== EIO
)
875 return arm_linux_read_description (ARM_FP_TYPE_NONE
);
877 /* NEON implies either no VFP, or VFPv3-D32. We only support
879 if (arm_hwcap
& HWCAP_NEON
)
880 return aarch32_linux_read_description ();
881 else if ((arm_hwcap
& (HWCAP_VFPv3
| HWCAP_VFPv3D16
)) == HWCAP_VFPv3
)
882 return arm_linux_read_description (ARM_FP_TYPE_VFPV3
);
884 return arm_linux_read_description (ARM_FP_TYPE_VFPV2
);
887 /* The default configuration uses legacy FPA registers, probably
889 return arm_linux_read_description (ARM_FP_TYPE_NONE
);
893 arm_arch_setup (void)
895 int tid
= lwpid_of (current_thread
);
899 /* Query hardware watchpoint/breakpoint capabilities. */
900 arm_linux_init_hwbp_cap (tid
);
902 current_process ()->tdesc
= arm_read_description ();
904 iov
.iov_base
= gpregs
;
905 iov
.iov_len
= sizeof (gpregs
);
907 /* Check if PTRACE_GETREGSET works. */
908 if (ptrace (PTRACE_GETREGSET
, tid
, NT_PRSTATUS
, &iov
) == 0)
909 have_ptrace_getregset
= 1;
911 have_ptrace_getregset
= 0;
914 /* Fetch the next possible PCs after the current instruction executes. */
916 static std::vector
<CORE_ADDR
>
917 arm_gdbserver_get_next_pcs (struct regcache
*regcache
)
919 struct arm_get_next_pcs next_pcs_ctx
;
921 arm_get_next_pcs_ctor (&next_pcs_ctx
,
923 /* Byte order is ignored assumed as host. */
929 return arm_get_next_pcs (&next_pcs_ctx
);
932 /* Support for hardware single step. */
935 arm_supports_hardware_single_step (void)
940 /* Implementation of linux_target_ops method "get_syscall_trapinfo". */
943 arm_get_syscall_trapinfo (struct regcache
*regcache
, int *sysno
)
945 if (arm_is_thumb_mode ())
946 collect_register_by_name (regcache
, "r7", sysno
);
952 collect_register_by_name (regcache
, "pc", &pc
);
954 if (the_target
->read_memory (pc
- 4, (unsigned char *) &insn
, 4))
955 *sysno
= UNKNOWN_SYSCALL
;
958 unsigned long svc_operand
= (0x00ffffff & insn
);
963 *sysno
= svc_operand
- 0x900000;
968 collect_register_by_name (regcache
, "r7", sysno
);
974 /* Register sets without using PTRACE_GETREGSET. */
976 static struct regset_info arm_regsets
[] = {
977 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0,
978 ARM_CORE_REGS_SIZE
+ ARM_INT_REGISTER_SIZE
, GENERAL_REGS
,
979 arm_fill_gregset
, arm_store_gregset
},
980 { PTRACE_GETWMMXREGS
, PTRACE_SETWMMXREGS
, 0, IWMMXT_REGS_SIZE
, EXTENDED_REGS
,
981 arm_fill_wmmxregset
, arm_store_wmmxregset
},
982 { PTRACE_GETVFPREGS
, PTRACE_SETVFPREGS
, 0, ARM_VFP3_REGS_SIZE
, EXTENDED_REGS
,
983 arm_fill_vfpregset
, arm_store_vfpregset
},
987 static struct regsets_info arm_regsets_info
=
989 arm_regsets
, /* regsets */
991 NULL
, /* disabled_regsets */
994 static struct usrregs_info arm_usrregs_info
=
1000 static struct regs_info regs_info_arm
=
1002 NULL
, /* regset_bitmap */
1007 static const struct regs_info
*
1008 arm_regs_info (void)
1010 const struct target_desc
*tdesc
= current_process ()->tdesc
;
1012 if (have_ptrace_getregset
== 1
1013 && (is_aarch32_linux_description (tdesc
)
1014 || arm_linux_get_tdesc_fp_type (tdesc
) == ARM_FP_TYPE_VFPV3
))
1015 return ®s_info_aarch32
;
1017 return ®s_info_arm
;
1020 struct linux_target_ops the_low_target
= {
1023 arm_cannot_fetch_register
,
1024 arm_cannot_store_register
,
1025 NULL
, /* fetch_register */
1028 arm_breakpoint_kind_from_pc
,
1029 arm_sw_breakpoint_from_kind
,
1030 arm_gdbserver_get_next_pcs
,
1033 arm_supports_z_point_type
,
1036 arm_stopped_by_watchpoint
,
1037 arm_stopped_data_address
,
1038 NULL
, /* collect_ptrace_register */
1039 NULL
, /* supply_ptrace_register */
1040 NULL
, /* siginfo_fixup */
1046 arm_prepare_to_resume
,
1047 NULL
, /* process_qsupported */
1048 NULL
, /* supports_tracepoints */
1049 NULL
, /* get_thread_area */
1050 NULL
, /* install_fast_tracepoint_jump_pad */
1051 NULL
, /* emit_ops */
1052 NULL
, /* get_min_fast_tracepoint_insn_len */
1053 NULL
, /* supports_range_stepping */
1054 arm_breakpoint_kind_from_current_state
,
1055 arm_supports_hardware_single_step
,
1056 arm_get_syscall_trapinfo
,
1059 /* The linux target ops object. */
1061 linux_process_target
*the_linux_target
= &the_arm_target
;
1064 initialize_low_arch (void)
1066 initialize_low_arch_aarch32 ();
1067 initialize_regsets_info (&arm_regsets_info
);