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"
23 #include <sys/ptrace.h>
25 #include "gdb_proc_service.h"
27 /* Defined in auto-generated file reg-arm.c. */
28 void init_registers_arm (void);
29 /* Defined in auto-generated file arm-with-iwmmxt.c. */
30 void init_registers_arm_with_iwmmxt (void);
32 #ifndef PTRACE_GET_THREAD_AREA
33 #define PTRACE_GET_THREAD_AREA 22
36 #ifndef PTRACE_GETWMMXREGS
37 # define PTRACE_GETWMMXREGS 18
38 # define PTRACE_SETWMMXREGS 19
45 #define arm_num_regs 26
47 static int arm_regmap[] = {
48 0, 4, 8, 12, 16, 20, 24, 28,
49 32, 36, 40, 44, 48, 52, 56, 60,
50 -1, -1, -1, -1, -1, -1, -1, -1, -1,
55 arm_cannot_store_register (int regno)
57 return (regno >= arm_num_regs);
61 arm_cannot_fetch_register (int regno)
63 return (regno >= arm_num_regs);
67 arm_fill_gregset (void *buf)
71 for (i = 0; i < arm_num_regs; i++)
72 if (arm_regmap[i] != -1)
73 collect_register (i, ((char *) buf) + arm_regmap[i]);
77 arm_store_gregset (const void *buf)
82 memset (zerobuf, 0, 8);
83 for (i = 0; i < arm_num_regs; i++)
84 if (arm_regmap[i] != -1)
85 supply_register (i, ((char *) buf) + arm_regmap[i]);
87 supply_register (i, zerobuf);
93 arm_fill_wmmxregset (void *buf)
97 for (i = 0; i < 16; i++)
98 collect_register (arm_num_regs + i, (char *) buf + i * 8);
100 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
101 for (i = 0; i < 6; i++)
102 collect_register (arm_num_regs + i + 16, (char *) buf + 16 * 8 + i * 4);
106 arm_store_wmmxregset (const void *buf)
110 for (i = 0; i < 16; i++)
111 supply_register (arm_num_regs + i, (char *) buf + i * 8);
113 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
114 for (i = 0; i < 6; i++)
115 supply_register (arm_num_regs + i + 16, (char *) buf + 16 * 8 + i * 4);
118 #endif /* __IWMMXT__ */
120 extern int debug_threads;
126 collect_register_by_name ("pc", &pc);
128 fprintf (stderr, "stop pc is %08lx\n", pc);
133 arm_set_pc (CORE_ADDR pc)
135 unsigned long newpc = pc;
136 supply_register_by_name ("pc", &newpc);
139 /* Correct in either endianness. */
140 static const unsigned long arm_breakpoint = 0xef9f0001;
141 #define arm_breakpoint_len 4
142 static const unsigned short thumb_breakpoint = 0xde01;
143 #define thumb_breakpoint_len 2
145 /* For new EABI binaries. We recognize it regardless of which ABI
146 is used for gdbserver, so single threaded debugging should work
147 OK, but for multi-threaded debugging we only insert the current
148 ABI's breakpoint instruction. For now at least. */
149 static const unsigned long arm_eabi_breakpoint = 0xe7f001f0;
152 arm_breakpoint_at (CORE_ADDR where)
156 collect_register_by_name ("cpsr", &cpsr);
163 (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
164 if (insn == thumb_breakpoint)
172 (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
173 if (insn == arm_breakpoint)
176 if (insn == arm_eabi_breakpoint)
183 /* We only place breakpoints in empty marker functions, and thread locking
184 is outside of the function. So rather than importing software single-step,
185 we can just run until exit. */
190 collect_register_by_name ("lr", &pc);
194 /* Fetch the thread-local storage pointer for libthread_db. */
197 ps_get_thread_area (const struct ps_prochandle *ph,
198 lwpid_t lwpid, int idx, void **base)
200 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
203 /* IDX is the bias from the thread pointer to the beginning of the
204 thread descriptor. It has to be subtracted due to implementation
205 quirks in libthread_db. */
206 *base = (void *) ((char *)*base - idx);
211 struct regset_info target_regsets[] = {
212 { PTRACE_GETREGS, PTRACE_SETREGS, 18 * 4,
214 arm_fill_gregset, arm_store_gregset },
216 { PTRACE_GETWMMXREGS, PTRACE_SETWMMXREGS, 16 * 8 + 6 * 4,
218 arm_fill_wmmxregset, arm_store_wmmxregset },
220 { 0, 0, -1, -1, NULL, NULL }
223 struct linux_target_ops the_low_target = {
225 init_registers_arm_with_iwmmxt,
231 arm_cannot_fetch_register,
232 arm_cannot_store_register,
236 /* Define an ARM-mode breakpoint; we only set breakpoints in the C
237 library, which is most likely to be ARM. If the kernel supports
238 clone events, we will never insert a breakpoint, so even a Thumb
239 C library will work; so will mixing EABI/non-EABI gdbserver and
242 (const unsigned char *) &arm_breakpoint,
244 (const unsigned char *) &arm_eabi_breakpoint,