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 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. We do not support Thumb yet. */
140 static const unsigned long arm_breakpoint
= 0xef9f0001;
141 #define arm_breakpoint_len 4
143 /* For new EABI binaries. We recognize it regardless of which ABI
144 is used for gdbserver, so single threaded debugging should work
145 OK, but for multi-threaded debugging we only insert the current
146 ABI's breakpoint instruction. For now at least. */
147 static const unsigned long arm_eabi_breakpoint
= 0xe7f001f0;
150 arm_breakpoint_at (CORE_ADDR where
)
154 (*the_target
->read_memory
) (where
, (unsigned char *) &insn
, 4);
155 if (insn
== arm_breakpoint
)
158 if (insn
== arm_eabi_breakpoint
)
161 /* If necessary, recognize more trap instructions here. GDB only uses the
167 /* We only place breakpoints in empty marker functions, and thread locking
168 is outside of the function. So rather than importing software single-step,
169 we can just run until exit. */
174 collect_register_by_name ("lr", &pc
);
178 /* Fetch the thread-local storage pointer for libthread_db. */
181 ps_get_thread_area (const struct ps_prochandle
*ph
,
182 lwpid_t lwpid
, int idx
, void **base
)
184 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
187 /* IDX is the bias from the thread pointer to the beginning of the
188 thread descriptor. It has to be subtracted due to implementation
189 quirks in libthread_db. */
190 *base
= (void *) ((char *)*base
- idx
);
195 struct regset_info target_regsets
[] = {
196 { PTRACE_GETREGS
, PTRACE_SETREGS
, 18 * 4,
198 arm_fill_gregset
, arm_store_gregset
},
200 { PTRACE_GETWMMXREGS
, PTRACE_SETWMMXREGS
, 16 * 8 + 6 * 4,
202 arm_fill_wmmxregset
, arm_store_wmmxregset
},
204 { 0, 0, -1, -1, NULL
, NULL
}
207 struct linux_target_ops the_low_target
= {
209 init_registers_arm_with_iwmmxt
,
215 arm_cannot_fetch_register
,
216 arm_cannot_store_register
,
220 (const unsigned char *) &arm_breakpoint
,
222 (const unsigned char *) &arm_eabi_breakpoint
,