1 /* GNU/Linux/ARM specific low level interface, for the remote server for GDB.
2 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "linux-low.h"
23 /* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
24 On Bionic elf.h and linux/elf.h have conflicting definitions. */
28 #include <sys/ptrace.h>
30 /* Defined in auto-generated files. */
31 void init_registers_arm (void);
32 void init_registers_arm_with_iwmmxt (void);
33 void init_registers_arm_with_vfpv2 (void);
34 void init_registers_arm_with_vfpv3 (void);
35 void init_registers_arm_with_neon (void);
37 #ifndef PTRACE_GET_THREAD_AREA
38 #define PTRACE_GET_THREAD_AREA 22
41 #ifndef PTRACE_GETWMMXREGS
42 # define PTRACE_GETWMMXREGS 18
43 # define PTRACE_SETWMMXREGS 19
46 #ifndef PTRACE_GETVFPREGS
47 # define PTRACE_GETVFPREGS 27
48 # define PTRACE_SETVFPREGS 28
51 static unsigned long arm_hwcap;
53 /* These are in <asm/elf.h> in current kernels. */
55 #define HWCAP_IWMMXT 512
56 #define HWCAP_NEON 4096
57 #define HWCAP_VFPv3 8192
58 #define HWCAP_VFPv3D16 16384
64 #define arm_num_regs 26
66 static int arm_regmap[] = {
67 0, 4, 8, 12, 16, 20, 24, 28,
68 32, 36, 40, 44, 48, 52, 56, 60,
69 -1, -1, -1, -1, -1, -1, -1, -1, -1,
74 arm_cannot_store_register (int regno)
76 return (regno >= arm_num_regs);
80 arm_cannot_fetch_register (int regno)
82 return (regno >= arm_num_regs);
86 arm_fill_gregset (struct regcache *regcache, void *buf)
90 for (i = 0; i < arm_num_regs; i++)
91 if (arm_regmap[i] != -1)
92 collect_register (regcache, i, ((char *) buf) + arm_regmap[i]);
96 arm_store_gregset (struct regcache *regcache, const void *buf)
101 memset (zerobuf, 0, 8);
102 for (i = 0; i < arm_num_regs; i++)
103 if (arm_regmap[i] != -1)
104 supply_register (regcache, i, ((char *) buf) + arm_regmap[i]);
106 supply_register (regcache, i, zerobuf);
110 arm_fill_wmmxregset (struct regcache *regcache, void *buf)
114 if (!(arm_hwcap & HWCAP_IWMMXT))
117 for (i = 0; i < 16; i++)
118 collect_register (regcache, arm_num_regs + i, (char *) buf + i * 8);
120 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
121 for (i = 0; i < 6; i++)
122 collect_register (regcache, arm_num_regs + i + 16,
123 (char *) buf + 16 * 8 + i * 4);
127 arm_store_wmmxregset (struct regcache *regcache, const void *buf)
131 if (!(arm_hwcap & HWCAP_IWMMXT))
134 for (i = 0; i < 16; i++)
135 supply_register (regcache, arm_num_regs + i, (char *) buf + i * 8);
137 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
138 for (i = 0; i < 6; i++)
139 supply_register (regcache, arm_num_regs + i + 16,
140 (char *) buf + 16 * 8 + i * 4);
144 arm_fill_vfpregset (struct regcache *regcache, void *buf)
148 if (!(arm_hwcap & HWCAP_VFP))
151 if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
156 base = find_regno ("d0");
157 for (i = 0; i < num; i++)
158 collect_register (regcache, base + i, (char *) buf + i * 8);
160 collect_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
164 arm_store_vfpregset (struct regcache *regcache, const void *buf)
168 if (!(arm_hwcap & HWCAP_VFP))
171 if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
176 base = find_regno ("d0");
177 for (i = 0; i < num; i++)
178 supply_register (regcache, base + i, (char *) buf + i * 8);
180 supply_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
183 extern int debug_threads;
186 arm_get_pc (struct regcache *regcache)
189 collect_register_by_name (regcache, "pc", &pc);
191 fprintf (stderr, "stop pc is %08lx\n", pc);
196 arm_set_pc (struct regcache *regcache, CORE_ADDR pc)
198 unsigned long newpc = pc;
199 supply_register_by_name (regcache, "pc", &newpc);
202 /* Correct in either endianness. */
203 static const unsigned long arm_breakpoint = 0xef9f0001;
204 #define arm_breakpoint_len 4
205 static const unsigned short thumb_breakpoint = 0xde01;
206 static const unsigned short thumb2_breakpoint[] = { 0xf7f0, 0xa000 };
208 /* For new EABI binaries. We recognize it regardless of which ABI
209 is used for gdbserver, so single threaded debugging should work
210 OK, but for multi-threaded debugging we only insert the current
211 ABI's breakpoint instruction. For now at least. */
212 static const unsigned long arm_eabi_breakpoint = 0xe7f001f0;
215 arm_breakpoint_at (CORE_ADDR where)
217 struct regcache *regcache = get_thread_regcache (current_inferior, 1);
220 collect_register_by_name (regcache, "cpsr", &cpsr);
227 (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
228 if (insn == thumb_breakpoint)
231 if (insn == thumb2_breakpoint[0])
233 (*the_target->read_memory) (where + 2, (unsigned char *) &insn, 2);
234 if (insn == thumb2_breakpoint[1])
243 (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
244 if (insn == arm_breakpoint)
247 if (insn == arm_eabi_breakpoint)
254 /* We only place breakpoints in empty marker functions, and thread locking
255 is outside of the function. So rather than importing software single-step,
256 we can just run until exit. */
258 arm_reinsert_addr (void)
260 struct regcache *regcache = get_thread_regcache (current_inferior, 1);
262 collect_register_by_name (regcache, "lr", &pc);
266 /* Fetch the thread-local storage pointer for libthread_db. */
269 ps_get_thread_area (const struct ps_prochandle *ph,
270 lwpid_t lwpid, int idx, void **base)
272 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
275 /* IDX is the bias from the thread pointer to the beginning of the
276 thread descriptor. It has to be subtracted due to implementation
277 quirks in libthread_db. */
278 *base = (void *) ((char *)*base - idx);
284 arm_get_hwcap (unsigned long *valp)
286 unsigned char *data = alloca (8);
289 while ((*the_target->read_auxv) (offset, data, 8) == 8)
291 unsigned int *data_p = (unsigned int *)data;
292 if (data_p[0] == AT_HWCAP)
306 arm_arch_setup (void)
309 if (arm_get_hwcap (&arm_hwcap) == 0)
311 init_registers_arm ();
315 if (arm_hwcap & HWCAP_IWMMXT)
317 init_registers_arm_with_iwmmxt ();
321 if (arm_hwcap & HWCAP_VFP)
326 /* NEON implies either no VFP, or VFPv3-D32. We only support
328 if (arm_hwcap & HWCAP_NEON)
329 init_registers_arm_with_neon ();
330 else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
331 init_registers_arm_with_vfpv3 ();
333 init_registers_arm_with_vfpv2 ();
335 /* Now make sure that the kernel supports reading these
336 registers. Support was added in 2.6.30. */
337 pid = lwpid_of (get_thread_lwp (current_inferior));
339 buf = xmalloc (32 * 8 + 4);
340 if (ptrace (PTRACE_GETVFPREGS, pid, 0, buf) < 0
344 init_registers_arm ();
351 /* The default configuration uses legacy FPA registers, probably
353 init_registers_arm ();
356 struct regset_info target_regsets[] = {
357 { PTRACE_GETREGS, PTRACE_SETREGS, 0, 18 * 4,
359 arm_fill_gregset, arm_store_gregset },
360 { PTRACE_GETWMMXREGS, PTRACE_SETWMMXREGS, 0, 16 * 8 + 6 * 4,
362 arm_fill_wmmxregset, arm_store_wmmxregset },
363 { PTRACE_GETVFPREGS, PTRACE_SETVFPREGS, 0, 32 * 8 + 4,
365 arm_fill_vfpregset, arm_store_vfpregset },
366 { 0, 0, 0, -1, -1, NULL, NULL }
369 struct linux_target_ops the_low_target = {
373 arm_cannot_fetch_register,
374 arm_cannot_store_register,
378 /* Define an ARM-mode breakpoint; we only set breakpoints in the C
379 library, which is most likely to be ARM. If the kernel supports
380 clone events, we will never insert a breakpoint, so even a Thumb
381 C library will work; so will mixing EABI/non-EABI gdbserver and
384 (const unsigned char *) &arm_breakpoint,
386 (const unsigned char *) &arm_eabi_breakpoint,