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 /* Information describing the hardware breakpoint capabilities. */
61 unsigned char max_wp_length
;
62 unsigned char wp_count
;
63 unsigned char bp_count
;
66 /* Enum describing the different types of ARM hardware break-/watch-points. */
75 /* Type describing an ARM Hardware Breakpoint Control register value. */
76 typedef unsigned int arm_hwbp_control_t
;
78 /* Structure used to keep track of hardware break-/watch-points. */
79 struct arm_linux_hw_breakpoint
81 /* Address to break on, or being watched. */
83 /* Control register for break-/watch- point. */
84 arm_hwbp_control_t control
;
87 /* Since we cannot dynamically allocate subfields of arch_process_info,
88 assume a maximum number of supported break-/watchpoints. */
92 /* Per-process arch-specific data we want to keep. */
93 struct arch_process_info
95 /* Hardware breakpoints for this process. */
96 struct arm_linux_hw_breakpoint bpts
[MAX_BPTS
];
97 /* Hardware watchpoints for this process. */
98 struct arm_linux_hw_breakpoint wpts
[MAX_WPTS
];
101 /* Per-thread arch-specific data we want to keep. */
104 /* Non-zero if our copy differs from what's recorded in the thread. */
105 char bpts_changed
[MAX_BPTS
];
106 char wpts_changed
[MAX_WPTS
];
107 /* Cached stopped data address. */
108 CORE_ADDR stopped_data_address
;
111 /* These are in <asm/elf.h> in current kernels. */
113 #define HWCAP_IWMMXT 512
114 #define HWCAP_NEON 4096
115 #define HWCAP_VFPv3 8192
116 #define HWCAP_VFPv3D16 16384
118 #ifdef HAVE_SYS_REG_H
122 #define arm_num_regs 26
124 static int arm_regmap
[] = {
125 0, 4, 8, 12, 16, 20, 24, 28,
126 32, 36, 40, 44, 48, 52, 56, 60,
127 -1, -1, -1, -1, -1, -1, -1, -1, -1,
131 /* Forward declarations needed for get_next_pcs ops. */
132 static ULONGEST
get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr
,
136 static CORE_ADDR
get_next_pcs_addr_bits_remove (struct arm_get_next_pcs
*self
,
139 static CORE_ADDR
get_next_pcs_syscall_next_pc (struct arm_get_next_pcs
*self
);
141 static int get_next_pcs_is_thumb (struct arm_get_next_pcs
*self
);
143 /* get_next_pcs operations. */
144 static struct arm_get_next_pcs_ops get_next_pcs_ops
= {
145 get_next_pcs_read_memory_unsigned_integer
,
146 get_next_pcs_syscall_next_pc
,
147 get_next_pcs_addr_bits_remove
,
148 get_next_pcs_is_thumb
,
149 arm_linux_get_next_pcs_fixup
,
153 arm_cannot_store_register (int regno
)
155 return (regno
>= arm_num_regs
);
159 arm_cannot_fetch_register (int regno
)
161 return (regno
>= arm_num_regs
);
165 arm_fill_wmmxregset (struct regcache
*regcache
, void *buf
)
167 if (arm_linux_get_tdesc_fp_type (regcache
->tdesc
) != ARM_FP_TYPE_IWMMXT
)
170 for (int i
= 0; i
< 16; i
++)
171 collect_register (regcache
, arm_num_regs
+ i
, (char *) buf
+ i
* 8);
173 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
174 for (int i
= 0; i
< 6; i
++)
175 collect_register (regcache
, arm_num_regs
+ i
+ 16,
176 (char *) buf
+ 16 * 8 + i
* 4);
180 arm_store_wmmxregset (struct regcache
*regcache
, const void *buf
)
182 if (arm_linux_get_tdesc_fp_type (regcache
->tdesc
) != ARM_FP_TYPE_IWMMXT
)
185 for (int i
= 0; i
< 16; i
++)
186 supply_register (regcache
, arm_num_regs
+ i
, (char *) buf
+ i
* 8);
188 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
189 for (int i
= 0; i
< 6; i
++)
190 supply_register (regcache
, arm_num_regs
+ i
+ 16,
191 (char *) buf
+ 16 * 8 + i
* 4);
195 arm_fill_vfpregset (struct regcache
*regcache
, void *buf
)
199 if (is_aarch32_linux_description (regcache
->tdesc
))
203 arm_fp_type fp_type
= arm_linux_get_tdesc_fp_type (regcache
->tdesc
);
205 if (fp_type
== ARM_FP_TYPE_VFPV3
)
207 else if (fp_type
== ARM_FP_TYPE_VFPV2
)
213 arm_fill_vfpregset_num (regcache
, buf
, num
);
216 /* Wrapper of UNMAKE_THUMB_ADDR for get_next_pcs. */
218 get_next_pcs_addr_bits_remove (struct arm_get_next_pcs
*self
, CORE_ADDR val
)
220 return UNMAKE_THUMB_ADDR (val
);
224 arm_store_vfpregset (struct regcache
*regcache
, const void *buf
)
228 if (is_aarch32_linux_description (regcache
->tdesc
))
232 arm_fp_type fp_type
= arm_linux_get_tdesc_fp_type (regcache
->tdesc
);
234 if (fp_type
== ARM_FP_TYPE_VFPV3
)
236 else if (fp_type
== ARM_FP_TYPE_VFPV2
)
242 arm_store_vfpregset_num (regcache
, buf
, num
);
245 /* Wrapper of arm_is_thumb_mode for get_next_pcs. */
247 get_next_pcs_is_thumb (struct arm_get_next_pcs
*self
)
249 return arm_is_thumb_mode ();
252 /* Read memory from the inferior.
253 BYTE_ORDER is ignored and there to keep compatiblity with GDB's
254 read_memory_unsigned_integer. */
256 get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr
,
263 target_read_memory (memaddr
, (unsigned char *) &res
, len
);
268 /* Fetch the thread-local storage pointer for libthread_db. */
271 ps_get_thread_area (struct ps_prochandle
*ph
,
272 lwpid_t lwpid
, int idx
, void **base
)
274 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
277 /* IDX is the bias from the thread pointer to the beginning of the
278 thread descriptor. It has to be subtracted due to implementation
279 quirks in libthread_db. */
280 *base
= (void *) ((char *)*base
- idx
);
286 /* Query Hardware Breakpoint information for the target we are attached to
287 (using PID as ptrace argument) and set up arm_linux_hwbp_cap. */
289 arm_linux_init_hwbp_cap (int pid
)
293 if (ptrace (PTRACE_GETHBPREGS
, pid
, 0, &val
) < 0)
296 arm_linux_hwbp_cap
.arch
= (unsigned char)((val
>> 24) & 0xff);
297 if (arm_linux_hwbp_cap
.arch
== 0)
300 arm_linux_hwbp_cap
.max_wp_length
= (unsigned char)((val
>> 16) & 0xff);
301 arm_linux_hwbp_cap
.wp_count
= (unsigned char)((val
>> 8) & 0xff);
302 arm_linux_hwbp_cap
.bp_count
= (unsigned char)(val
& 0xff);
304 if (arm_linux_hwbp_cap
.wp_count
> MAX_WPTS
)
305 internal_error (__FILE__
, __LINE__
, "Unsupported number of watchpoints");
306 if (arm_linux_hwbp_cap
.bp_count
> MAX_BPTS
)
307 internal_error (__FILE__
, __LINE__
, "Unsupported number of breakpoints");
310 /* How many hardware breakpoints are available? */
312 arm_linux_get_hw_breakpoint_count (void)
314 return arm_linux_hwbp_cap
.bp_count
;
317 /* How many hardware watchpoints are available? */
319 arm_linux_get_hw_watchpoint_count (void)
321 return arm_linux_hwbp_cap
.wp_count
;
324 /* Maximum length of area watched by hardware watchpoint. */
326 arm_linux_get_hw_watchpoint_max_length (void)
328 return arm_linux_hwbp_cap
.max_wp_length
;
331 /* Initialize an ARM hardware break-/watch-point control register value.
332 BYTE_ADDRESS_SELECT is the mask of bytes to trigger on; HWBP_TYPE is the
333 type of break-/watch-point; ENABLE indicates whether the point is enabled.
335 static arm_hwbp_control_t
336 arm_hwbp_control_initialize (unsigned byte_address_select
,
337 arm_hwbp_type hwbp_type
,
340 gdb_assert ((byte_address_select
& ~0xffU
) == 0);
341 gdb_assert (hwbp_type
!= arm_hwbp_break
342 || ((byte_address_select
& 0xfU
) != 0));
344 return (byte_address_select
<< 5) | (hwbp_type
<< 3) | (3 << 1) | enable
;
347 /* Does the breakpoint control value CONTROL have the enable bit set? */
349 arm_hwbp_control_is_enabled (arm_hwbp_control_t control
)
351 return control
& 0x1;
354 /* Is the breakpoint control value CONTROL initialized? */
356 arm_hwbp_control_is_initialized (arm_hwbp_control_t control
)
361 /* Change a breakpoint control word so that it is in the disabled state. */
362 static arm_hwbp_control_t
363 arm_hwbp_control_disable (arm_hwbp_control_t control
)
365 return control
& ~0x1;
368 /* Are two break-/watch-points equal? */
370 arm_linux_hw_breakpoint_equal (const struct arm_linux_hw_breakpoint
*p1
,
371 const struct arm_linux_hw_breakpoint
*p2
)
373 return p1
->address
== p2
->address
&& p1
->control
== p2
->control
;
376 /* Convert a raw breakpoint type to an enum arm_hwbp_type. */
379 raw_bkpt_type_to_arm_hwbp_type (enum raw_bkpt_type raw_type
)
383 case raw_bkpt_type_hw
:
384 return arm_hwbp_break
;
385 case raw_bkpt_type_write_wp
:
386 return arm_hwbp_store
;
387 case raw_bkpt_type_read_wp
:
388 return arm_hwbp_load
;
389 case raw_bkpt_type_access_wp
:
390 return arm_hwbp_access
;
392 gdb_assert_not_reached ("unhandled raw type");
396 /* Initialize the hardware breakpoint structure P for a breakpoint or
397 watchpoint at ADDR to LEN. The type of watchpoint is given in TYPE.
398 Returns -1 if TYPE is unsupported, or -2 if the particular combination
399 of ADDR and LEN cannot be implemented. Otherwise, returns 0 if TYPE
400 represents a breakpoint and 1 if type represents a watchpoint. */
402 arm_linux_hw_point_initialize (enum raw_bkpt_type raw_type
, CORE_ADDR addr
,
403 int len
, struct arm_linux_hw_breakpoint
*p
)
405 arm_hwbp_type hwbp_type
;
408 hwbp_type
= raw_bkpt_type_to_arm_hwbp_type (raw_type
);
410 if (hwbp_type
== arm_hwbp_break
)
412 /* For breakpoints, the length field encodes the mode. */
415 case 2: /* 16-bit Thumb mode breakpoint */
416 case 3: /* 32-bit Thumb mode breakpoint */
420 case 4: /* 32-bit ARM mode breakpoint */
431 CORE_ADDR max_wp_length
= arm_linux_get_hw_watchpoint_max_length ();
432 CORE_ADDR aligned_addr
;
434 /* Can not set watchpoints for zero or negative lengths. */
437 /* The current ptrace interface can only handle watchpoints that are a
439 if ((len
& (len
- 1)) != 0)
442 /* Test that the range [ADDR, ADDR + LEN) fits into the largest address
443 range covered by a watchpoint. */
444 aligned_addr
= addr
& ~(max_wp_length
- 1);
445 if (aligned_addr
+ max_wp_length
< addr
+ len
)
448 mask
= (1 << len
) - 1;
451 p
->address
= (unsigned int) addr
;
452 p
->control
= arm_hwbp_control_initialize (mask
, hwbp_type
, 1);
454 return hwbp_type
!= arm_hwbp_break
;
457 /* Callback to mark a watch-/breakpoint to be updated in all threads of
458 the current process. */
461 update_registers_callback (thread_info
*thread
, int watch
, int i
)
463 struct lwp_info
*lwp
= get_thread_lwp (thread
);
465 /* The actual update is done later just before resuming the lwp,
466 we just mark that the registers need updating. */
468 lwp
->arch_private
->wpts_changed
[i
] = 1;
470 lwp
->arch_private
->bpts_changed
[i
] = 1;
472 /* If the lwp isn't stopped, force it to momentarily pause, so
473 we can update its breakpoint registers. */
475 linux_stop_lwp (lwp
);
479 arm_supports_z_point_type (char z_type
)
485 case Z_PACKET_WRITE_WP
:
486 case Z_PACKET_READ_WP
:
487 case Z_PACKET_ACCESS_WP
:
490 /* Leave the handling of sw breakpoints with the gdb client. */
495 /* Insert hardware break-/watchpoint. */
497 arm_insert_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
498 int len
, struct raw_breakpoint
*bp
)
500 struct process_info
*proc
= current_process ();
501 struct arm_linux_hw_breakpoint p
, *pts
;
504 watch
= arm_linux_hw_point_initialize (type
, addr
, len
, &p
);
508 return watch
== -1 ? 1 : -1;
513 count
= arm_linux_get_hw_watchpoint_count ();
514 pts
= proc
->priv
->arch_private
->wpts
;
518 count
= arm_linux_get_hw_breakpoint_count ();
519 pts
= proc
->priv
->arch_private
->bpts
;
522 for (i
= 0; i
< count
; i
++)
523 if (!arm_hwbp_control_is_enabled (pts
[i
].control
))
527 /* Only update the threads of the current process. */
528 for_each_thread (current_thread
->id
.pid (), [&] (thread_info
*thread
)
530 update_registers_callback (thread
, watch
, i
);
536 /* We're out of watchpoints. */
540 /* Remove hardware break-/watchpoint. */
542 arm_remove_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
543 int len
, struct raw_breakpoint
*bp
)
545 struct process_info
*proc
= current_process ();
546 struct arm_linux_hw_breakpoint p
, *pts
;
549 watch
= arm_linux_hw_point_initialize (type
, addr
, len
, &p
);
558 count
= arm_linux_get_hw_watchpoint_count ();
559 pts
= proc
->priv
->arch_private
->wpts
;
563 count
= arm_linux_get_hw_breakpoint_count ();
564 pts
= proc
->priv
->arch_private
->bpts
;
567 for (i
= 0; i
< count
; i
++)
568 if (arm_linux_hw_breakpoint_equal (&p
, pts
+ i
))
570 pts
[i
].control
= arm_hwbp_control_disable (pts
[i
].control
);
572 /* Only update the threads of the current process. */
573 for_each_thread (current_thread
->id
.pid (), [&] (thread_info
*thread
)
575 update_registers_callback (thread
, watch
, i
);
581 /* No watchpoint matched. */
585 /* Return whether current thread is stopped due to a watchpoint. */
587 arm_stopped_by_watchpoint (void)
589 struct lwp_info
*lwp
= get_thread_lwp (current_thread
);
592 /* We must be able to set hardware watchpoints. */
593 if (arm_linux_get_hw_watchpoint_count () == 0)
596 /* Retrieve siginfo. */
598 ptrace (PTRACE_GETSIGINFO
, lwpid_of (current_thread
), 0, &siginfo
);
602 /* This must be a hardware breakpoint. */
603 if (siginfo
.si_signo
!= SIGTRAP
604 || (siginfo
.si_code
& 0xffff) != 0x0004 /* TRAP_HWBKPT */)
607 /* If we are in a positive slot then we're looking at a breakpoint and not
609 if (siginfo
.si_errno
>= 0)
612 /* Cache stopped data address for use by arm_stopped_data_address. */
613 lwp
->arch_private
->stopped_data_address
614 = (CORE_ADDR
) (uintptr_t) siginfo
.si_addr
;
619 /* Return data address that triggered watchpoint. Called only if
620 arm_stopped_by_watchpoint returned true. */
622 arm_stopped_data_address (void)
624 struct lwp_info
*lwp
= get_thread_lwp (current_thread
);
625 return lwp
->arch_private
->stopped_data_address
;
628 /* Called when a new process is created. */
629 static struct arch_process_info
*
630 arm_new_process (void)
632 struct arch_process_info
*info
= XCNEW (struct arch_process_info
);
636 /* Called when a process is being deleted. */
639 arm_delete_process (struct arch_process_info
*info
)
644 /* Called when a new thread is detected. */
646 arm_new_thread (struct lwp_info
*lwp
)
648 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
651 for (i
= 0; i
< MAX_BPTS
; i
++)
652 info
->bpts_changed
[i
] = 1;
653 for (i
= 0; i
< MAX_WPTS
; i
++)
654 info
->wpts_changed
[i
] = 1;
656 lwp
->arch_private
= info
;
659 /* Function to call when a thread is being deleted. */
662 arm_delete_thread (struct arch_lwp_info
*arch_lwp
)
668 arm_new_fork (struct process_info
*parent
, struct process_info
*child
)
670 struct arch_process_info
*parent_proc_info
;
671 struct arch_process_info
*child_proc_info
;
672 struct lwp_info
*child_lwp
;
673 struct arch_lwp_info
*child_lwp_info
;
676 /* These are allocated by linux_add_process. */
677 gdb_assert (parent
->priv
!= NULL
678 && parent
->priv
->arch_private
!= NULL
);
679 gdb_assert (child
->priv
!= NULL
680 && child
->priv
->arch_private
!= NULL
);
682 parent_proc_info
= parent
->priv
->arch_private
;
683 child_proc_info
= child
->priv
->arch_private
;
685 /* Linux kernel before 2.6.33 commit
686 72f674d203cd230426437cdcf7dd6f681dad8b0d
687 will inherit hardware debug registers from parent
688 on fork/vfork/clone. Newer Linux kernels create such tasks with
689 zeroed debug registers.
691 GDB core assumes the child inherits the watchpoints/hw
692 breakpoints of the parent, and will remove them all from the
693 forked off process. Copy the debug registers mirrors into the
694 new process so that all breakpoints and watchpoints can be
695 removed together. The debug registers mirror will become zeroed
696 in the end before detaching the forked off process, thus making
697 this compatible with older Linux kernels too. */
699 *child_proc_info
= *parent_proc_info
;
701 /* Mark all the hardware breakpoints and watchpoints as changed to
702 make sure that the registers will be updated. */
703 child_lwp
= find_lwp_pid (ptid_t (child
->pid
));
704 child_lwp_info
= child_lwp
->arch_private
;
705 for (i
= 0; i
< MAX_BPTS
; i
++)
706 child_lwp_info
->bpts_changed
[i
] = 1;
707 for (i
= 0; i
< MAX_WPTS
; i
++)
708 child_lwp_info
->wpts_changed
[i
] = 1;
711 /* Called when resuming a thread.
712 If the debug regs have changed, update the thread's copies. */
714 arm_prepare_to_resume (struct lwp_info
*lwp
)
716 struct thread_info
*thread
= get_lwp_thread (lwp
);
717 int pid
= lwpid_of (thread
);
718 struct process_info
*proc
= find_process_pid (pid_of (thread
));
719 struct arch_process_info
*proc_info
= proc
->priv
->arch_private
;
720 struct arch_lwp_info
*lwp_info
= lwp
->arch_private
;
723 for (i
= 0; i
< arm_linux_get_hw_breakpoint_count (); i
++)
724 if (lwp_info
->bpts_changed
[i
])
728 if (arm_hwbp_control_is_enabled (proc_info
->bpts
[i
].control
))
729 if (ptrace (PTRACE_SETHBPREGS
, pid
,
730 (PTRACE_TYPE_ARG3
) ((i
<< 1) + 1),
731 &proc_info
->bpts
[i
].address
) < 0)
732 perror_with_name ("Unexpected error setting breakpoint address");
734 if (arm_hwbp_control_is_initialized (proc_info
->bpts
[i
].control
))
735 if (ptrace (PTRACE_SETHBPREGS
, pid
,
736 (PTRACE_TYPE_ARG3
) ((i
<< 1) + 2),
737 &proc_info
->bpts
[i
].control
) < 0)
738 perror_with_name ("Unexpected error setting breakpoint");
740 lwp_info
->bpts_changed
[i
] = 0;
743 for (i
= 0; i
< arm_linux_get_hw_watchpoint_count (); i
++)
744 if (lwp_info
->wpts_changed
[i
])
748 if (arm_hwbp_control_is_enabled (proc_info
->wpts
[i
].control
))
749 if (ptrace (PTRACE_SETHBPREGS
, pid
,
750 (PTRACE_TYPE_ARG3
) -((i
<< 1) + 1),
751 &proc_info
->wpts
[i
].address
) < 0)
752 perror_with_name ("Unexpected error setting watchpoint address");
754 if (arm_hwbp_control_is_initialized (proc_info
->wpts
[i
].control
))
755 if (ptrace (PTRACE_SETHBPREGS
, pid
,
756 (PTRACE_TYPE_ARG3
) -((i
<< 1) + 2),
757 &proc_info
->wpts
[i
].control
) < 0)
758 perror_with_name ("Unexpected error setting watchpoint");
760 lwp_info
->wpts_changed
[i
] = 0;
764 /* Find the next pc for a sigreturn or rt_sigreturn syscall. In
765 addition, set IS_THUMB depending on whether we will return to ARM
767 See arm-linux.h for stack layout details. */
769 arm_sigreturn_next_pc (struct regcache
*regcache
, int svc_number
,
773 unsigned long sp_data
;
774 /* Offset of PC register. */
776 CORE_ADDR next_pc
= 0;
779 gdb_assert (svc_number
== __NR_sigreturn
|| svc_number
== __NR_rt_sigreturn
);
781 collect_register_by_name (regcache
, "sp", &sp
);
782 (*the_target
->read_memory
) (sp
, (unsigned char *) &sp_data
, 4);
784 pc_offset
= arm_linux_sigreturn_next_pc_offset
785 (sp
, sp_data
, svc_number
, __NR_sigreturn
== svc_number
? 1 : 0);
787 (*the_target
->read_memory
) (sp
+ pc_offset
, (unsigned char *) &next_pc
, 4);
789 /* Set IS_THUMB according the CPSR saved on the stack. */
790 (*the_target
->read_memory
) (sp
+ pc_offset
+ 4, (unsigned char *) &cpsr
, 4);
791 *is_thumb
= ((cpsr
& CPSR_T
) != 0);
796 /* When PC is at a syscall instruction, return the PC of the next
797 instruction to be executed. */
799 get_next_pcs_syscall_next_pc (struct arm_get_next_pcs
*self
)
801 CORE_ADDR next_pc
= 0;
802 CORE_ADDR pc
= regcache_read_pc (self
->regcache
);
803 int is_thumb
= arm_is_thumb_mode ();
804 ULONGEST svc_number
= 0;
805 struct regcache
*regcache
= self
->regcache
;
809 collect_register (regcache
, 7, &svc_number
);
814 unsigned long this_instr
;
815 unsigned long svc_operand
;
817 target_read_memory (pc
, (unsigned char *) &this_instr
, 4);
818 svc_operand
= (0x00ffffff & this_instr
);
820 if (svc_operand
) /* OABI. */
822 svc_number
= svc_operand
- 0x900000;
826 collect_register (regcache
, 7, &svc_number
);
832 /* This is a sigreturn or sigreturn_rt syscall. */
833 if (svc_number
== __NR_sigreturn
|| svc_number
== __NR_rt_sigreturn
)
835 /* SIGRETURN or RT_SIGRETURN may affect the arm thumb mode, so
837 next_pc
= arm_sigreturn_next_pc (regcache
, svc_number
, &is_thumb
);
840 /* Addresses for calling Thumb functions have the bit 0 set. */
842 next_pc
= MAKE_THUMB_ADDR (next_pc
);
847 static const struct target_desc
*
848 arm_read_description (void)
850 unsigned long arm_hwcap
= linux_get_hwcap (4);
852 if (arm_hwcap
& HWCAP_IWMMXT
)
853 return arm_linux_read_description (ARM_FP_TYPE_IWMMXT
);
855 if (arm_hwcap
& HWCAP_VFP
)
857 /* Make sure that the kernel supports reading VFP registers. Support was
859 int pid
= lwpid_of (current_thread
);
861 char *buf
= (char *) alloca (ARM_VFP3_REGS_SIZE
);
862 if (ptrace (PTRACE_GETVFPREGS
, pid
, 0, buf
) < 0 && errno
== EIO
)
863 return arm_linux_read_description (ARM_FP_TYPE_NONE
);
865 /* NEON implies either no VFP, or VFPv3-D32. We only support
867 if (arm_hwcap
& HWCAP_NEON
)
868 return aarch32_linux_read_description ();
869 else if ((arm_hwcap
& (HWCAP_VFPv3
| HWCAP_VFPv3D16
)) == HWCAP_VFPv3
)
870 return arm_linux_read_description (ARM_FP_TYPE_VFPV3
);
872 return arm_linux_read_description (ARM_FP_TYPE_VFPV2
);
875 /* The default configuration uses legacy FPA registers, probably
877 return arm_linux_read_description (ARM_FP_TYPE_NONE
);
881 arm_arch_setup (void)
883 int tid
= lwpid_of (current_thread
);
887 /* Query hardware watchpoint/breakpoint capabilities. */
888 arm_linux_init_hwbp_cap (tid
);
890 current_process ()->tdesc
= arm_read_description ();
892 iov
.iov_base
= gpregs
;
893 iov
.iov_len
= sizeof (gpregs
);
895 /* Check if PTRACE_GETREGSET works. */
896 if (ptrace (PTRACE_GETREGSET
, tid
, NT_PRSTATUS
, &iov
) == 0)
897 have_ptrace_getregset
= 1;
899 have_ptrace_getregset
= 0;
902 /* Fetch the next possible PCs after the current instruction executes. */
904 static std::vector
<CORE_ADDR
>
905 arm_gdbserver_get_next_pcs (struct regcache
*regcache
)
907 struct arm_get_next_pcs next_pcs_ctx
;
909 arm_get_next_pcs_ctor (&next_pcs_ctx
,
911 /* Byte order is ignored assumed as host. */
917 return arm_get_next_pcs (&next_pcs_ctx
);
920 /* Support for hardware single step. */
923 arm_supports_hardware_single_step (void)
928 /* Implementation of linux_target_ops method "get_syscall_trapinfo". */
931 arm_get_syscall_trapinfo (struct regcache
*regcache
, int *sysno
)
933 if (arm_is_thumb_mode ())
934 collect_register_by_name (regcache
, "r7", sysno
);
940 collect_register_by_name (regcache
, "pc", &pc
);
942 if ((*the_target
->read_memory
) (pc
- 4, (unsigned char *) &insn
, 4))
943 *sysno
= UNKNOWN_SYSCALL
;
946 unsigned long svc_operand
= (0x00ffffff & insn
);
951 *sysno
= svc_operand
- 0x900000;
956 collect_register_by_name (regcache
, "r7", sysno
);
962 /* Register sets without using PTRACE_GETREGSET. */
964 static struct regset_info arm_regsets
[] = {
965 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0,
966 ARM_CORE_REGS_SIZE
+ ARM_INT_REGISTER_SIZE
, GENERAL_REGS
,
967 arm_fill_gregset
, arm_store_gregset
},
968 { PTRACE_GETWMMXREGS
, PTRACE_SETWMMXREGS
, 0, IWMMXT_REGS_SIZE
, EXTENDED_REGS
,
969 arm_fill_wmmxregset
, arm_store_wmmxregset
},
970 { PTRACE_GETVFPREGS
, PTRACE_SETVFPREGS
, 0, ARM_VFP3_REGS_SIZE
, EXTENDED_REGS
,
971 arm_fill_vfpregset
, arm_store_vfpregset
},
975 static struct regsets_info arm_regsets_info
=
977 arm_regsets
, /* regsets */
979 NULL
, /* disabled_regsets */
982 static struct usrregs_info arm_usrregs_info
=
988 static struct regs_info regs_info_arm
=
990 NULL
, /* regset_bitmap */
995 static const struct regs_info
*
998 const struct target_desc
*tdesc
= current_process ()->tdesc
;
1000 if (have_ptrace_getregset
== 1
1001 && (is_aarch32_linux_description (tdesc
)
1002 || arm_linux_get_tdesc_fp_type (tdesc
) == ARM_FP_TYPE_VFPV3
))
1003 return ®s_info_aarch32
;
1005 return ®s_info_arm
;
1008 struct linux_target_ops the_low_target
= {
1011 arm_cannot_fetch_register
,
1012 arm_cannot_store_register
,
1013 NULL
, /* fetch_register */
1016 arm_breakpoint_kind_from_pc
,
1017 arm_sw_breakpoint_from_kind
,
1018 arm_gdbserver_get_next_pcs
,
1021 arm_supports_z_point_type
,
1024 arm_stopped_by_watchpoint
,
1025 arm_stopped_data_address
,
1026 NULL
, /* collect_ptrace_register */
1027 NULL
, /* supply_ptrace_register */
1028 NULL
, /* siginfo_fixup */
1034 arm_prepare_to_resume
,
1035 NULL
, /* process_qsupported */
1036 NULL
, /* supports_tracepoints */
1037 NULL
, /* get_thread_area */
1038 NULL
, /* install_fast_tracepoint_jump_pad */
1039 NULL
, /* emit_ops */
1040 NULL
, /* get_min_fast_tracepoint_insn_len */
1041 NULL
, /* supports_range_stepping */
1042 arm_breakpoint_kind_from_current_state
,
1043 arm_supports_hardware_single_step
,
1044 arm_get_syscall_trapinfo
,
1048 initialize_low_arch (void)
1050 initialize_low_arch_aarch32 ();
1051 initialize_regsets_info (&arm_regsets_info
);