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 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"
24 #include <sys/ptrace.h>
26 #include "gdb_proc_service.h"
28 /* Defined in auto-generated files. */
29 void init_registers_arm (void);
30 void init_registers_arm_with_iwmmxt (void);
31 void init_registers_arm_with_vfpv2 (void);
32 void init_registers_arm_with_vfpv3 (void);
33 void init_registers_arm_with_neon (void);
35 #ifndef PTRACE_GET_THREAD_AREA
36 #define PTRACE_GET_THREAD_AREA 22
39 #ifndef PTRACE_GETWMMXREGS
40 # define PTRACE_GETWMMXREGS 18
41 # define PTRACE_SETWMMXREGS 19
44 #ifndef PTRACE_GETVFPREGS
45 # define PTRACE_GETVFPREGS 27
46 # define PTRACE_SETVFPREGS 28
49 static unsigned long arm_hwcap
;
51 /* These are in <asm/elf.h> in current kernels. */
53 #define HWCAP_IWMMXT 512
54 #define HWCAP_NEON 4096
55 #define HWCAP_VFPv3 8192
56 #define HWCAP_VFPv3D16 16384
62 #define arm_num_regs 26
64 static int arm_regmap
[] = {
65 0, 4, 8, 12, 16, 20, 24, 28,
66 32, 36, 40, 44, 48, 52, 56, 60,
67 -1, -1, -1, -1, -1, -1, -1, -1, -1,
72 arm_cannot_store_register (int regno
)
74 return (regno
>= arm_num_regs
);
78 arm_cannot_fetch_register (int regno
)
80 return (regno
>= arm_num_regs
);
84 arm_fill_gregset (void *buf
)
88 for (i
= 0; i
< arm_num_regs
; i
++)
89 if (arm_regmap
[i
] != -1)
90 collect_register (i
, ((char *) buf
) + arm_regmap
[i
]);
94 arm_store_gregset (const void *buf
)
99 memset (zerobuf
, 0, 8);
100 for (i
= 0; i
< arm_num_regs
; i
++)
101 if (arm_regmap
[i
] != -1)
102 supply_register (i
, ((char *) buf
) + arm_regmap
[i
]);
104 supply_register (i
, zerobuf
);
108 arm_fill_wmmxregset (void *buf
)
112 if (!(arm_hwcap
& HWCAP_IWMMXT
))
115 for (i
= 0; i
< 16; i
++)
116 collect_register (arm_num_regs
+ i
, (char *) buf
+ i
* 8);
118 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
119 for (i
= 0; i
< 6; i
++)
120 collect_register (arm_num_regs
+ i
+ 16, (char *) buf
+ 16 * 8 + i
* 4);
124 arm_store_wmmxregset (const void *buf
)
128 if (!(arm_hwcap
& HWCAP_IWMMXT
))
131 for (i
= 0; i
< 16; i
++)
132 supply_register (arm_num_regs
+ i
, (char *) buf
+ i
* 8);
134 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
135 for (i
= 0; i
< 6; i
++)
136 supply_register (arm_num_regs
+ i
+ 16, (char *) buf
+ 16 * 8 + i
* 4);
140 arm_fill_vfpregset (void *buf
)
144 if (!(arm_hwcap
& HWCAP_VFP
))
147 if ((arm_hwcap
& (HWCAP_VFPv3
| HWCAP_VFPv3D16
)) == HWCAP_VFPv3
)
152 base
= find_regno ("d0");
153 for (i
= 0; i
< num
; i
++)
154 collect_register (base
+ i
, (char *) buf
+ i
* 8);
156 collect_register_by_name ("fpscr", (char *) buf
+ 32 * 8);
160 arm_store_vfpregset (const void *buf
)
164 if (!(arm_hwcap
& HWCAP_VFP
))
167 if ((arm_hwcap
& (HWCAP_VFPv3
| HWCAP_VFPv3D16
)) == HWCAP_VFPv3
)
172 base
= find_regno ("d0");
173 for (i
= 0; i
< num
; i
++)
174 supply_register (base
+ i
, (char *) buf
+ i
* 8);
176 supply_register_by_name ("fpscr", (char *) buf
+ 32 * 8);
179 extern int debug_threads
;
185 collect_register_by_name ("pc", &pc
);
187 fprintf (stderr
, "stop pc is %08lx\n", pc
);
192 arm_set_pc (CORE_ADDR pc
)
194 unsigned long newpc
= pc
;
195 supply_register_by_name ("pc", &newpc
);
198 /* Correct in either endianness. */
199 static const unsigned long arm_breakpoint
= 0xef9f0001;
200 #define arm_breakpoint_len 4
201 static const unsigned short thumb_breakpoint
= 0xde01;
202 #define thumb_breakpoint_len 2
204 /* For new EABI binaries. We recognize it regardless of which ABI
205 is used for gdbserver, so single threaded debugging should work
206 OK, but for multi-threaded debugging we only insert the current
207 ABI's breakpoint instruction. For now at least. */
208 static const unsigned long arm_eabi_breakpoint
= 0xe7f001f0;
211 arm_breakpoint_at (CORE_ADDR where
)
215 collect_register_by_name ("cpsr", &cpsr
);
222 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
, 2);
223 if (insn
== thumb_breakpoint
)
231 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
, 4);
232 if (insn
== arm_breakpoint
)
235 if (insn
== arm_eabi_breakpoint
)
242 /* We only place breakpoints in empty marker functions, and thread locking
243 is outside of the function. So rather than importing software single-step,
244 we can just run until exit. */
249 collect_register_by_name ("lr", &pc
);
253 /* Fetch the thread-local storage pointer for libthread_db. */
256 ps_get_thread_area (const struct ps_prochandle
*ph
,
257 lwpid_t lwpid
, int idx
, void **base
)
259 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
262 /* IDX is the bias from the thread pointer to the beginning of the
263 thread descriptor. It has to be subtracted due to implementation
264 quirks in libthread_db. */
265 *base
= (void *) ((char *)*base
- idx
);
271 arm_get_hwcap (unsigned long *valp
)
273 unsigned char *data
= alloca (8);
276 while ((*the_target
->read_auxv
) (offset
, data
, 8) == 8)
278 unsigned int *data_p
= (unsigned int *)data
;
279 if (data_p
[0] == AT_HWCAP
)
293 arm_arch_setup (void)
296 if (arm_get_hwcap (&arm_hwcap
) == 0)
298 init_registers_arm ();
302 if (arm_hwcap
& HWCAP_IWMMXT
)
304 init_registers_arm_with_iwmmxt ();
308 if (arm_hwcap
& HWCAP_VFP
)
313 /* NEON implies either no VFP, or VFPv3-D32. We only support
315 if (arm_hwcap
& HWCAP_NEON
)
316 init_registers_arm_with_neon ();
317 else if ((arm_hwcap
& (HWCAP_VFPv3
| HWCAP_VFPv3D16
)) == HWCAP_VFPv3
)
318 init_registers_arm_with_vfpv3 ();
320 init_registers_arm_with_vfpv2 ();
322 /* Now make sure that the kernel supports reading these
323 registers. Support was added in 2.6.30. */
324 pid
= lwpid_of (get_thread_lwp (current_inferior
));
326 buf
= malloc (32 * 8 + 4);
327 if (ptrace (PTRACE_GETVFPREGS
, pid
, 0, buf
) < 0
331 init_registers_arm ();
338 /* The default configuration uses legacy FPA registers, probably
340 init_registers_arm ();
343 struct regset_info target_regsets
[] = {
344 { PTRACE_GETREGS
, PTRACE_SETREGS
, 18 * 4,
346 arm_fill_gregset
, arm_store_gregset
},
347 { PTRACE_GETWMMXREGS
, PTRACE_SETWMMXREGS
, 16 * 8 + 6 * 4,
349 arm_fill_wmmxregset
, arm_store_wmmxregset
},
350 { PTRACE_GETVFPREGS
, PTRACE_SETVFPREGS
, 32 * 8 + 4,
352 arm_fill_vfpregset
, arm_store_vfpregset
},
353 { 0, 0, -1, -1, NULL
, NULL
}
356 struct linux_target_ops the_low_target
= {
360 arm_cannot_fetch_register
,
361 arm_cannot_store_register
,
365 /* Define an ARM-mode breakpoint; we only set breakpoints in the C
366 library, which is most likely to be ARM. If the kernel supports
367 clone events, we will never insert a breakpoint, so even a Thumb
368 C library will work; so will mixing EABI/non-EABI gdbserver and
371 (const unsigned char *) &arm_breakpoint
,
373 (const unsigned char *) &arm_eabi_breakpoint
,