linux-arm-low.cc revision 1.1.1.3 1 1.1 christos /* GNU/Linux/ARM specific low level interface, for the remote server for GDB.
2 1.1.1.3 christos Copyright (C) 1995-2024 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos This file is part of GDB.
5 1.1 christos
6 1.1 christos This program is free software; you can redistribute it and/or modify
7 1.1 christos it under the terms of the GNU General Public License as published by
8 1.1 christos the Free Software Foundation; either version 3 of the License, or
9 1.1 christos (at your option) any later version.
10 1.1 christos
11 1.1 christos This program is distributed in the hope that it will be useful,
12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 christos GNU General Public License for more details.
15 1.1 christos
16 1.1 christos You should have received a copy of the GNU General Public License
17 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 1.1 christos
19 1.1 christos #include "linux-low.h"
20 1.1 christos #include "arch/arm.h"
21 1.1 christos #include "arch/arm-linux.h"
22 1.1 christos #include "arch/arm-get-next-pcs.h"
23 1.1 christos #include "linux-aarch32-low.h"
24 1.1 christos #include "linux-aarch32-tdesc.h"
25 1.1 christos #include "linux-arm-tdesc.h"
26 1.1.1.3 christos #include "gdbsupport/gdb-checked-static-cast.h"
27 1.1 christos
28 1.1 christos #include <sys/uio.h>
29 1.1 christos /* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h.
30 1.1 christos On Bionic elf.h and linux/elf.h have conflicting definitions. */
31 1.1 christos #ifndef ELFMAG0
32 1.1 christos #include <elf.h>
33 1.1 christos #endif
34 1.1 christos #include "nat/gdb_ptrace.h"
35 1.1 christos #include <signal.h>
36 1.1 christos #include <sys/syscall.h>
37 1.1 christos
38 1.1 christos #ifndef PTRACE_GET_THREAD_AREA
39 1.1 christos #define PTRACE_GET_THREAD_AREA 22
40 1.1 christos #endif
41 1.1 christos
42 1.1 christos #ifndef PTRACE_GETWMMXREGS
43 1.1 christos # define PTRACE_GETWMMXREGS 18
44 1.1 christos # define PTRACE_SETWMMXREGS 19
45 1.1 christos #endif
46 1.1 christos
47 1.1 christos #ifndef PTRACE_GETVFPREGS
48 1.1 christos # define PTRACE_GETVFPREGS 27
49 1.1 christos # define PTRACE_SETVFPREGS 28
50 1.1 christos #endif
51 1.1 christos
52 1.1 christos #ifndef PTRACE_GETHBPREGS
53 1.1 christos #define PTRACE_GETHBPREGS 29
54 1.1 christos #define PTRACE_SETHBPREGS 30
55 1.1 christos #endif
56 1.1 christos
57 1.1 christos /* Linux target op definitions for the ARM architecture. */
58 1.1 christos
59 1.1 christos class arm_target : public linux_process_target
60 1.1 christos {
61 1.1 christos public:
62 1.1 christos
63 1.1 christos const regs_info *get_regs_info () override;
64 1.1 christos
65 1.1 christos int breakpoint_kind_from_pc (CORE_ADDR *pcptr) override;
66 1.1 christos
67 1.1 christos int breakpoint_kind_from_current_state (CORE_ADDR *pcptr) override;
68 1.1 christos
69 1.1 christos const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
70 1.1 christos
71 1.1 christos bool supports_software_single_step () override;
72 1.1 christos
73 1.1 christos bool supports_z_point_type (char z_type) override;
74 1.1 christos
75 1.1 christos bool supports_hardware_single_step () override;
76 1.1 christos
77 1.1 christos protected:
78 1.1 christos
79 1.1 christos void low_arch_setup () override;
80 1.1 christos
81 1.1 christos bool low_cannot_fetch_register (int regno) override;
82 1.1 christos
83 1.1 christos bool low_cannot_store_register (int regno) override;
84 1.1 christos
85 1.1 christos bool low_supports_breakpoints () override;
86 1.1 christos
87 1.1 christos CORE_ADDR low_get_pc (regcache *regcache) override;
88 1.1 christos
89 1.1 christos void low_set_pc (regcache *regcache, CORE_ADDR newpc) override;
90 1.1 christos
91 1.1 christos std::vector<CORE_ADDR> low_get_next_pcs (regcache *regcache) override;
92 1.1 christos
93 1.1 christos bool low_breakpoint_at (CORE_ADDR pc) override;
94 1.1 christos
95 1.1 christos int low_insert_point (raw_bkpt_type type, CORE_ADDR addr,
96 1.1 christos int size, raw_breakpoint *bp) override;
97 1.1 christos
98 1.1 christos int low_remove_point (raw_bkpt_type type, CORE_ADDR addr,
99 1.1 christos int size, raw_breakpoint *bp) override;
100 1.1 christos
101 1.1 christos bool low_stopped_by_watchpoint () override;
102 1.1 christos
103 1.1 christos CORE_ADDR low_stopped_data_address () override;
104 1.1 christos
105 1.1 christos arch_process_info *low_new_process () override;
106 1.1 christos
107 1.1 christos void low_delete_process (arch_process_info *info) override;
108 1.1 christos
109 1.1 christos void low_new_thread (lwp_info *) override;
110 1.1 christos
111 1.1 christos void low_delete_thread (arch_lwp_info *) override;
112 1.1 christos
113 1.1 christos void low_new_fork (process_info *parent, process_info *child) override;
114 1.1 christos
115 1.1 christos void low_prepare_to_resume (lwp_info *lwp) override;
116 1.1 christos
117 1.1 christos bool low_supports_catch_syscall () override;
118 1.1 christos
119 1.1 christos void low_get_syscall_trapinfo (regcache *regcache, int *sysno) override;
120 1.1 christos };
121 1.1 christos
122 1.1 christos /* The singleton target ops object. */
123 1.1 christos
124 1.1 christos static arm_target the_arm_target;
125 1.1 christos
126 1.1 christos bool
127 1.1 christos arm_target::low_supports_breakpoints ()
128 1.1 christos {
129 1.1 christos return true;
130 1.1 christos }
131 1.1 christos
132 1.1 christos CORE_ADDR
133 1.1 christos arm_target::low_get_pc (regcache *regcache)
134 1.1 christos {
135 1.1 christos return linux_get_pc_32bit (regcache);
136 1.1 christos }
137 1.1 christos
138 1.1 christos void
139 1.1 christos arm_target::low_set_pc (regcache *regcache, CORE_ADDR pc)
140 1.1 christos {
141 1.1 christos linux_set_pc_32bit (regcache, pc);
142 1.1 christos }
143 1.1 christos
144 1.1 christos int
145 1.1 christos arm_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
146 1.1 christos {
147 1.1 christos return arm_breakpoint_kind_from_pc (pcptr);
148 1.1 christos }
149 1.1 christos
150 1.1 christos int
151 1.1 christos arm_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
152 1.1 christos {
153 1.1 christos return arm_breakpoint_kind_from_current_state (pcptr);
154 1.1 christos }
155 1.1 christos
156 1.1 christos const gdb_byte *
157 1.1 christos arm_target::sw_breakpoint_from_kind (int kind, int *size)
158 1.1 christos {
159 1.1 christos return arm_sw_breakpoint_from_kind (kind, size);
160 1.1 christos }
161 1.1 christos
162 1.1 christos bool
163 1.1 christos arm_target::low_breakpoint_at (CORE_ADDR pc)
164 1.1 christos {
165 1.1 christos return arm_breakpoint_at (pc);
166 1.1 christos }
167 1.1 christos
168 1.1 christos /* Information describing the hardware breakpoint capabilities. */
169 1.1 christos static struct
170 1.1 christos {
171 1.1 christos unsigned char arch;
172 1.1 christos unsigned char max_wp_length;
173 1.1 christos unsigned char wp_count;
174 1.1 christos unsigned char bp_count;
175 1.1 christos } arm_linux_hwbp_cap;
176 1.1 christos
177 1.1 christos /* Enum describing the different types of ARM hardware break-/watch-points. */
178 1.1 christos typedef enum
179 1.1 christos {
180 1.1 christos arm_hwbp_break = 0,
181 1.1 christos arm_hwbp_load = 1,
182 1.1 christos arm_hwbp_store = 2,
183 1.1 christos arm_hwbp_access = 3
184 1.1 christos } arm_hwbp_type;
185 1.1 christos
186 1.1 christos /* Type describing an ARM Hardware Breakpoint Control register value. */
187 1.1 christos typedef unsigned int arm_hwbp_control_t;
188 1.1 christos
189 1.1 christos /* Structure used to keep track of hardware break-/watch-points. */
190 1.1 christos struct arm_linux_hw_breakpoint
191 1.1 christos {
192 1.1 christos /* Address to break on, or being watched. */
193 1.1 christos unsigned int address;
194 1.1 christos /* Control register for break-/watch- point. */
195 1.1 christos arm_hwbp_control_t control;
196 1.1 christos };
197 1.1 christos
198 1.1 christos /* Since we cannot dynamically allocate subfields of arch_process_info,
199 1.1 christos assume a maximum number of supported break-/watchpoints. */
200 1.1 christos #define MAX_BPTS 32
201 1.1 christos #define MAX_WPTS 32
202 1.1 christos
203 1.1 christos /* Per-process arch-specific data we want to keep. */
204 1.1 christos struct arch_process_info
205 1.1 christos {
206 1.1 christos /* Hardware breakpoints for this process. */
207 1.1 christos struct arm_linux_hw_breakpoint bpts[MAX_BPTS];
208 1.1 christos /* Hardware watchpoints for this process. */
209 1.1 christos struct arm_linux_hw_breakpoint wpts[MAX_WPTS];
210 1.1 christos };
211 1.1 christos
212 1.1 christos /* Per-thread arch-specific data we want to keep. */
213 1.1 christos struct arch_lwp_info
214 1.1 christos {
215 1.1 christos /* Non-zero if our copy differs from what's recorded in the thread. */
216 1.1 christos char bpts_changed[MAX_BPTS];
217 1.1 christos char wpts_changed[MAX_WPTS];
218 1.1 christos /* Cached stopped data address. */
219 1.1 christos CORE_ADDR stopped_data_address;
220 1.1 christos };
221 1.1 christos
222 1.1 christos /* These are in <asm/elf.h> in current kernels. */
223 1.1 christos #define HWCAP_VFP 64
224 1.1 christos #define HWCAP_IWMMXT 512
225 1.1 christos #define HWCAP_NEON 4096
226 1.1 christos #define HWCAP_VFPv3 8192
227 1.1 christos #define HWCAP_VFPv3D16 16384
228 1.1 christos
229 1.1 christos #ifdef HAVE_SYS_REG_H
230 1.1 christos #include <sys/reg.h>
231 1.1 christos #endif
232 1.1 christos
233 1.1 christos #define arm_num_regs 26
234 1.1 christos
235 1.1 christos static int arm_regmap[] = {
236 1.1 christos 0, 4, 8, 12, 16, 20, 24, 28,
237 1.1 christos 32, 36, 40, 44, 48, 52, 56, 60,
238 1.1 christos -1, -1, -1, -1, -1, -1, -1, -1, -1,
239 1.1 christos 64
240 1.1 christos };
241 1.1 christos
242 1.1 christos /* Forward declarations needed for get_next_pcs ops. */
243 1.1 christos static ULONGEST get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr,
244 1.1 christos int len,
245 1.1 christos int byte_order);
246 1.1 christos
247 1.1 christos static CORE_ADDR get_next_pcs_addr_bits_remove (struct arm_get_next_pcs *self,
248 1.1 christos CORE_ADDR val);
249 1.1 christos
250 1.1 christos static CORE_ADDR get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self);
251 1.1 christos
252 1.1 christos static int get_next_pcs_is_thumb (struct arm_get_next_pcs *self);
253 1.1 christos
254 1.1 christos /* get_next_pcs operations. */
255 1.1 christos static struct arm_get_next_pcs_ops get_next_pcs_ops = {
256 1.1 christos get_next_pcs_read_memory_unsigned_integer,
257 1.1 christos get_next_pcs_syscall_next_pc,
258 1.1 christos get_next_pcs_addr_bits_remove,
259 1.1 christos get_next_pcs_is_thumb,
260 1.1 christos arm_linux_get_next_pcs_fixup,
261 1.1 christos };
262 1.1 christos
263 1.1 christos bool
264 1.1 christos arm_target::low_cannot_store_register (int regno)
265 1.1 christos {
266 1.1 christos return (regno >= arm_num_regs);
267 1.1 christos }
268 1.1 christos
269 1.1 christos bool
270 1.1 christos arm_target::low_cannot_fetch_register (int regno)
271 1.1 christos {
272 1.1 christos return (regno >= arm_num_regs);
273 1.1 christos }
274 1.1 christos
275 1.1 christos static void
276 1.1 christos arm_fill_wmmxregset (struct regcache *regcache, void *buf)
277 1.1 christos {
278 1.1 christos if (arm_linux_get_tdesc_fp_type (regcache->tdesc) != ARM_FP_TYPE_IWMMXT)
279 1.1 christos return;
280 1.1 christos
281 1.1 christos for (int i = 0; i < 16; i++)
282 1.1 christos collect_register (regcache, arm_num_regs + i, (char *) buf + i * 8);
283 1.1 christos
284 1.1 christos /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
285 1.1 christos for (int i = 0; i < 6; i++)
286 1.1 christos collect_register (regcache, arm_num_regs + i + 16,
287 1.1 christos (char *) buf + 16 * 8 + i * 4);
288 1.1 christos }
289 1.1 christos
290 1.1 christos static void
291 1.1 christos arm_store_wmmxregset (struct regcache *regcache, const void *buf)
292 1.1 christos {
293 1.1 christos if (arm_linux_get_tdesc_fp_type (regcache->tdesc) != ARM_FP_TYPE_IWMMXT)
294 1.1 christos return;
295 1.1 christos
296 1.1 christos for (int i = 0; i < 16; i++)
297 1.1 christos supply_register (regcache, arm_num_regs + i, (char *) buf + i * 8);
298 1.1 christos
299 1.1 christos /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
300 1.1 christos for (int i = 0; i < 6; i++)
301 1.1 christos supply_register (regcache, arm_num_regs + i + 16,
302 1.1 christos (char *) buf + 16 * 8 + i * 4);
303 1.1 christos }
304 1.1 christos
305 1.1 christos static void
306 1.1 christos arm_fill_vfpregset (struct regcache *regcache, void *buf)
307 1.1 christos {
308 1.1 christos int num;
309 1.1 christos
310 1.1 christos if (is_aarch32_linux_description (regcache->tdesc))
311 1.1 christos num = 32;
312 1.1 christos else
313 1.1 christos {
314 1.1 christos arm_fp_type fp_type = arm_linux_get_tdesc_fp_type (regcache->tdesc);
315 1.1 christos
316 1.1 christos if (fp_type == ARM_FP_TYPE_VFPV3)
317 1.1 christos num = 32;
318 1.1 christos else if (fp_type == ARM_FP_TYPE_VFPV2)
319 1.1 christos num = 16;
320 1.1 christos else
321 1.1 christos return;
322 1.1 christos }
323 1.1 christos
324 1.1 christos arm_fill_vfpregset_num (regcache, buf, num);
325 1.1 christos }
326 1.1 christos
327 1.1 christos /* Wrapper of UNMAKE_THUMB_ADDR for get_next_pcs. */
328 1.1 christos static CORE_ADDR
329 1.1 christos get_next_pcs_addr_bits_remove (struct arm_get_next_pcs *self, CORE_ADDR val)
330 1.1 christos {
331 1.1 christos return UNMAKE_THUMB_ADDR (val);
332 1.1 christos }
333 1.1 christos
334 1.1 christos static void
335 1.1 christos arm_store_vfpregset (struct regcache *regcache, const void *buf)
336 1.1 christos {
337 1.1 christos int num;
338 1.1 christos
339 1.1 christos if (is_aarch32_linux_description (regcache->tdesc))
340 1.1 christos num = 32;
341 1.1 christos else
342 1.1 christos {
343 1.1 christos arm_fp_type fp_type = arm_linux_get_tdesc_fp_type (regcache->tdesc);
344 1.1 christos
345 1.1 christos if (fp_type == ARM_FP_TYPE_VFPV3)
346 1.1 christos num = 32;
347 1.1 christos else if (fp_type == ARM_FP_TYPE_VFPV2)
348 1.1 christos num = 16;
349 1.1 christos else
350 1.1 christos return;
351 1.1 christos }
352 1.1 christos
353 1.1 christos arm_store_vfpregset_num (regcache, buf, num);
354 1.1 christos }
355 1.1 christos
356 1.1 christos /* Wrapper of arm_is_thumb_mode for get_next_pcs. */
357 1.1 christos static int
358 1.1 christos get_next_pcs_is_thumb (struct arm_get_next_pcs *self)
359 1.1 christos {
360 1.1 christos return arm_is_thumb_mode ();
361 1.1 christos }
362 1.1 christos
363 1.1 christos /* Read memory from the inferior.
364 1.1 christos BYTE_ORDER is ignored and there to keep compatiblity with GDB's
365 1.1 christos read_memory_unsigned_integer. */
366 1.1 christos static ULONGEST
367 1.1 christos get_next_pcs_read_memory_unsigned_integer (CORE_ADDR memaddr,
368 1.1 christos int len,
369 1.1 christos int byte_order)
370 1.1 christos {
371 1.1 christos ULONGEST res;
372 1.1 christos
373 1.1 christos res = 0;
374 1.1 christos target_read_memory (memaddr, (unsigned char *) &res, len);
375 1.1 christos
376 1.1 christos return res;
377 1.1 christos }
378 1.1 christos
379 1.1 christos /* Fetch the thread-local storage pointer for libthread_db. */
380 1.1 christos
381 1.1 christos ps_err_e
382 1.1 christos ps_get_thread_area (struct ps_prochandle *ph,
383 1.1 christos lwpid_t lwpid, int idx, void **base)
384 1.1 christos {
385 1.1 christos if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
386 1.1 christos return PS_ERR;
387 1.1 christos
388 1.1 christos /* IDX is the bias from the thread pointer to the beginning of the
389 1.1 christos thread descriptor. It has to be subtracted due to implementation
390 1.1 christos quirks in libthread_db. */
391 1.1 christos *base = (void *) ((char *)*base - idx);
392 1.1 christos
393 1.1 christos return PS_OK;
394 1.1 christos }
395 1.1 christos
396 1.1 christos
397 1.1 christos /* Query Hardware Breakpoint information for the target we are attached to
398 1.1 christos (using PID as ptrace argument) and set up arm_linux_hwbp_cap. */
399 1.1 christos static void
400 1.1 christos arm_linux_init_hwbp_cap (int pid)
401 1.1 christos {
402 1.1 christos unsigned int val;
403 1.1 christos
404 1.1 christos if (ptrace (PTRACE_GETHBPREGS, pid, 0, &val) < 0)
405 1.1 christos return;
406 1.1 christos
407 1.1 christos arm_linux_hwbp_cap.arch = (unsigned char)((val >> 24) & 0xff);
408 1.1 christos if (arm_linux_hwbp_cap.arch == 0)
409 1.1 christos return;
410 1.1 christos
411 1.1 christos arm_linux_hwbp_cap.max_wp_length = (unsigned char)((val >> 16) & 0xff);
412 1.1 christos arm_linux_hwbp_cap.wp_count = (unsigned char)((val >> 8) & 0xff);
413 1.1 christos arm_linux_hwbp_cap.bp_count = (unsigned char)(val & 0xff);
414 1.1 christos
415 1.1 christos if (arm_linux_hwbp_cap.wp_count > MAX_WPTS)
416 1.1.1.2 christos internal_error ("Unsupported number of watchpoints");
417 1.1 christos if (arm_linux_hwbp_cap.bp_count > MAX_BPTS)
418 1.1.1.2 christos internal_error ("Unsupported number of breakpoints");
419 1.1 christos }
420 1.1 christos
421 1.1 christos /* How many hardware breakpoints are available? */
422 1.1 christos static int
423 1.1 christos arm_linux_get_hw_breakpoint_count (void)
424 1.1 christos {
425 1.1 christos return arm_linux_hwbp_cap.bp_count;
426 1.1 christos }
427 1.1 christos
428 1.1 christos /* How many hardware watchpoints are available? */
429 1.1 christos static int
430 1.1 christos arm_linux_get_hw_watchpoint_count (void)
431 1.1 christos {
432 1.1 christos return arm_linux_hwbp_cap.wp_count;
433 1.1 christos }
434 1.1 christos
435 1.1 christos /* Maximum length of area watched by hardware watchpoint. */
436 1.1 christos static int
437 1.1 christos arm_linux_get_hw_watchpoint_max_length (void)
438 1.1 christos {
439 1.1 christos return arm_linux_hwbp_cap.max_wp_length;
440 1.1 christos }
441 1.1 christos
442 1.1 christos /* Initialize an ARM hardware break-/watch-point control register value.
443 1.1 christos BYTE_ADDRESS_SELECT is the mask of bytes to trigger on; HWBP_TYPE is the
444 1.1 christos type of break-/watch-point; ENABLE indicates whether the point is enabled.
445 1.1 christos */
446 1.1 christos static arm_hwbp_control_t
447 1.1 christos arm_hwbp_control_initialize (unsigned byte_address_select,
448 1.1 christos arm_hwbp_type hwbp_type,
449 1.1 christos int enable)
450 1.1 christos {
451 1.1 christos gdb_assert ((byte_address_select & ~0xffU) == 0);
452 1.1 christos gdb_assert (hwbp_type != arm_hwbp_break
453 1.1 christos || ((byte_address_select & 0xfU) != 0));
454 1.1 christos
455 1.1 christos return (byte_address_select << 5) | (hwbp_type << 3) | (3 << 1) | enable;
456 1.1 christos }
457 1.1 christos
458 1.1 christos /* Does the breakpoint control value CONTROL have the enable bit set? */
459 1.1 christos static int
460 1.1 christos arm_hwbp_control_is_enabled (arm_hwbp_control_t control)
461 1.1 christos {
462 1.1 christos return control & 0x1;
463 1.1 christos }
464 1.1 christos
465 1.1 christos /* Is the breakpoint control value CONTROL initialized? */
466 1.1 christos static int
467 1.1 christos arm_hwbp_control_is_initialized (arm_hwbp_control_t control)
468 1.1 christos {
469 1.1 christos return control != 0;
470 1.1 christos }
471 1.1 christos
472 1.1 christos /* Change a breakpoint control word so that it is in the disabled state. */
473 1.1 christos static arm_hwbp_control_t
474 1.1 christos arm_hwbp_control_disable (arm_hwbp_control_t control)
475 1.1 christos {
476 1.1 christos return control & ~0x1;
477 1.1 christos }
478 1.1 christos
479 1.1 christos /* Are two break-/watch-points equal? */
480 1.1 christos static int
481 1.1 christos arm_linux_hw_breakpoint_equal (const struct arm_linux_hw_breakpoint *p1,
482 1.1 christos const struct arm_linux_hw_breakpoint *p2)
483 1.1 christos {
484 1.1 christos return p1->address == p2->address && p1->control == p2->control;
485 1.1 christos }
486 1.1 christos
487 1.1 christos /* Convert a raw breakpoint type to an enum arm_hwbp_type. */
488 1.1 christos
489 1.1 christos static arm_hwbp_type
490 1.1 christos raw_bkpt_type_to_arm_hwbp_type (enum raw_bkpt_type raw_type)
491 1.1 christos {
492 1.1 christos switch (raw_type)
493 1.1 christos {
494 1.1 christos case raw_bkpt_type_hw:
495 1.1 christos return arm_hwbp_break;
496 1.1 christos case raw_bkpt_type_write_wp:
497 1.1 christos return arm_hwbp_store;
498 1.1 christos case raw_bkpt_type_read_wp:
499 1.1 christos return arm_hwbp_load;
500 1.1 christos case raw_bkpt_type_access_wp:
501 1.1 christos return arm_hwbp_access;
502 1.1 christos default:
503 1.1 christos gdb_assert_not_reached ("unhandled raw type");
504 1.1 christos }
505 1.1 christos }
506 1.1 christos
507 1.1 christos /* Initialize the hardware breakpoint structure P for a breakpoint or
508 1.1 christos watchpoint at ADDR to LEN. The type of watchpoint is given in TYPE.
509 1.1 christos Returns -1 if TYPE is unsupported, or -2 if the particular combination
510 1.1 christos of ADDR and LEN cannot be implemented. Otherwise, returns 0 if TYPE
511 1.1 christos represents a breakpoint and 1 if type represents a watchpoint. */
512 1.1 christos static int
513 1.1 christos arm_linux_hw_point_initialize (enum raw_bkpt_type raw_type, CORE_ADDR addr,
514 1.1 christos int len, struct arm_linux_hw_breakpoint *p)
515 1.1 christos {
516 1.1 christos arm_hwbp_type hwbp_type;
517 1.1 christos unsigned mask;
518 1.1 christos
519 1.1 christos hwbp_type = raw_bkpt_type_to_arm_hwbp_type (raw_type);
520 1.1 christos
521 1.1 christos if (hwbp_type == arm_hwbp_break)
522 1.1 christos {
523 1.1 christos /* For breakpoints, the length field encodes the mode. */
524 1.1 christos switch (len)
525 1.1 christos {
526 1.1 christos case 2: /* 16-bit Thumb mode breakpoint */
527 1.1 christos case 3: /* 32-bit Thumb mode breakpoint */
528 1.1 christos mask = 0x3;
529 1.1 christos addr &= ~1;
530 1.1 christos break;
531 1.1 christos case 4: /* 32-bit ARM mode breakpoint */
532 1.1 christos mask = 0xf;
533 1.1 christos addr &= ~3;
534 1.1 christos break;
535 1.1 christos default:
536 1.1 christos /* Unsupported. */
537 1.1 christos return -2;
538 1.1 christos }
539 1.1 christos }
540 1.1 christos else
541 1.1 christos {
542 1.1 christos CORE_ADDR max_wp_length = arm_linux_get_hw_watchpoint_max_length ();
543 1.1 christos CORE_ADDR aligned_addr;
544 1.1 christos
545 1.1 christos /* Can not set watchpoints for zero or negative lengths. */
546 1.1 christos if (len <= 0)
547 1.1 christos return -2;
548 1.1 christos /* The current ptrace interface can only handle watchpoints that are a
549 1.1 christos power of 2. */
550 1.1 christos if ((len & (len - 1)) != 0)
551 1.1 christos return -2;
552 1.1 christos
553 1.1 christos /* Test that the range [ADDR, ADDR + LEN) fits into the largest address
554 1.1 christos range covered by a watchpoint. */
555 1.1 christos aligned_addr = addr & ~(max_wp_length - 1);
556 1.1 christos if (aligned_addr + max_wp_length < addr + len)
557 1.1 christos return -2;
558 1.1 christos
559 1.1 christos mask = (1 << len) - 1;
560 1.1 christos }
561 1.1 christos
562 1.1 christos p->address = (unsigned int) addr;
563 1.1 christos p->control = arm_hwbp_control_initialize (mask, hwbp_type, 1);
564 1.1 christos
565 1.1 christos return hwbp_type != arm_hwbp_break;
566 1.1 christos }
567 1.1 christos
568 1.1 christos /* Callback to mark a watch-/breakpoint to be updated in all threads of
569 1.1 christos the current process. */
570 1.1 christos
571 1.1 christos static void
572 1.1 christos update_registers_callback (thread_info *thread, int watch, int i)
573 1.1 christos {
574 1.1 christos struct lwp_info *lwp = get_thread_lwp (thread);
575 1.1 christos
576 1.1 christos /* The actual update is done later just before resuming the lwp,
577 1.1 christos we just mark that the registers need updating. */
578 1.1 christos if (watch)
579 1.1 christos lwp->arch_private->wpts_changed[i] = 1;
580 1.1 christos else
581 1.1 christos lwp->arch_private->bpts_changed[i] = 1;
582 1.1 christos
583 1.1 christos /* If the lwp isn't stopped, force it to momentarily pause, so
584 1.1 christos we can update its breakpoint registers. */
585 1.1 christos if (!lwp->stopped)
586 1.1 christos linux_stop_lwp (lwp);
587 1.1 christos }
588 1.1 christos
589 1.1 christos bool
590 1.1 christos arm_target::supports_z_point_type (char z_type)
591 1.1 christos {
592 1.1 christos switch (z_type)
593 1.1 christos {
594 1.1 christos case Z_PACKET_SW_BP:
595 1.1 christos case Z_PACKET_HW_BP:
596 1.1 christos case Z_PACKET_WRITE_WP:
597 1.1 christos case Z_PACKET_READ_WP:
598 1.1 christos case Z_PACKET_ACCESS_WP:
599 1.1 christos return true;
600 1.1 christos default:
601 1.1 christos /* Leave the handling of sw breakpoints with the gdb client. */
602 1.1 christos return false;
603 1.1 christos }
604 1.1 christos }
605 1.1 christos
606 1.1 christos /* Insert hardware break-/watchpoint. */
607 1.1 christos int
608 1.1 christos arm_target::low_insert_point (raw_bkpt_type type, CORE_ADDR addr,
609 1.1 christos int len, raw_breakpoint *bp)
610 1.1 christos {
611 1.1 christos struct process_info *proc = current_process ();
612 1.1 christos struct arm_linux_hw_breakpoint p, *pts;
613 1.1 christos int watch, i, count;
614 1.1 christos
615 1.1 christos watch = arm_linux_hw_point_initialize (type, addr, len, &p);
616 1.1 christos if (watch < 0)
617 1.1 christos {
618 1.1 christos /* Unsupported. */
619 1.1 christos return watch == -1 ? 1 : -1;
620 1.1 christos }
621 1.1 christos
622 1.1 christos if (watch)
623 1.1 christos {
624 1.1 christos count = arm_linux_get_hw_watchpoint_count ();
625 1.1 christos pts = proc->priv->arch_private->wpts;
626 1.1 christos }
627 1.1 christos else
628 1.1 christos {
629 1.1 christos count = arm_linux_get_hw_breakpoint_count ();
630 1.1 christos pts = proc->priv->arch_private->bpts;
631 1.1 christos }
632 1.1 christos
633 1.1 christos for (i = 0; i < count; i++)
634 1.1 christos if (!arm_hwbp_control_is_enabled (pts[i].control))
635 1.1 christos {
636 1.1 christos pts[i] = p;
637 1.1 christos
638 1.1 christos /* Only update the threads of the current process. */
639 1.1 christos for_each_thread (current_thread->id.pid (), [&] (thread_info *thread)
640 1.1 christos {
641 1.1 christos update_registers_callback (thread, watch, i);
642 1.1 christos });
643 1.1 christos
644 1.1 christos return 0;
645 1.1 christos }
646 1.1 christos
647 1.1 christos /* We're out of watchpoints. */
648 1.1 christos return -1;
649 1.1 christos }
650 1.1 christos
651 1.1 christos /* Remove hardware break-/watchpoint. */
652 1.1 christos int
653 1.1 christos arm_target::low_remove_point (raw_bkpt_type type, CORE_ADDR addr,
654 1.1 christos int len, raw_breakpoint *bp)
655 1.1 christos {
656 1.1 christos struct process_info *proc = current_process ();
657 1.1 christos struct arm_linux_hw_breakpoint p, *pts;
658 1.1 christos int watch, i, count;
659 1.1 christos
660 1.1 christos watch = arm_linux_hw_point_initialize (type, addr, len, &p);
661 1.1 christos if (watch < 0)
662 1.1 christos {
663 1.1 christos /* Unsupported. */
664 1.1 christos return -1;
665 1.1 christos }
666 1.1 christos
667 1.1 christos if (watch)
668 1.1 christos {
669 1.1 christos count = arm_linux_get_hw_watchpoint_count ();
670 1.1 christos pts = proc->priv->arch_private->wpts;
671 1.1 christos }
672 1.1 christos else
673 1.1 christos {
674 1.1 christos count = arm_linux_get_hw_breakpoint_count ();
675 1.1 christos pts = proc->priv->arch_private->bpts;
676 1.1 christos }
677 1.1 christos
678 1.1 christos for (i = 0; i < count; i++)
679 1.1 christos if (arm_linux_hw_breakpoint_equal (&p, pts + i))
680 1.1 christos {
681 1.1 christos pts[i].control = arm_hwbp_control_disable (pts[i].control);
682 1.1 christos
683 1.1 christos /* Only update the threads of the current process. */
684 1.1 christos for_each_thread (current_thread->id.pid (), [&] (thread_info *thread)
685 1.1 christos {
686 1.1 christos update_registers_callback (thread, watch, i);
687 1.1 christos });
688 1.1 christos
689 1.1 christos return 0;
690 1.1 christos }
691 1.1 christos
692 1.1 christos /* No watchpoint matched. */
693 1.1 christos return -1;
694 1.1 christos }
695 1.1 christos
696 1.1 christos /* Return whether current thread is stopped due to a watchpoint. */
697 1.1 christos bool
698 1.1 christos arm_target::low_stopped_by_watchpoint ()
699 1.1 christos {
700 1.1 christos struct lwp_info *lwp = get_thread_lwp (current_thread);
701 1.1 christos siginfo_t siginfo;
702 1.1 christos
703 1.1 christos /* We must be able to set hardware watchpoints. */
704 1.1 christos if (arm_linux_get_hw_watchpoint_count () == 0)
705 1.1 christos return false;
706 1.1 christos
707 1.1 christos /* Retrieve siginfo. */
708 1.1 christos errno = 0;
709 1.1 christos ptrace (PTRACE_GETSIGINFO, lwpid_of (current_thread), 0, &siginfo);
710 1.1 christos if (errno != 0)
711 1.1 christos return false;
712 1.1 christos
713 1.1 christos /* This must be a hardware breakpoint. */
714 1.1 christos if (siginfo.si_signo != SIGTRAP
715 1.1 christos || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
716 1.1 christos return false;
717 1.1 christos
718 1.1 christos /* If we are in a positive slot then we're looking at a breakpoint and not
719 1.1 christos a watchpoint. */
720 1.1 christos if (siginfo.si_errno >= 0)
721 1.1 christos return false;
722 1.1 christos
723 1.1 christos /* Cache stopped data address for use by arm_stopped_data_address. */
724 1.1 christos lwp->arch_private->stopped_data_address
725 1.1 christos = (CORE_ADDR) (uintptr_t) siginfo.si_addr;
726 1.1 christos
727 1.1 christos return true;
728 1.1 christos }
729 1.1 christos
730 1.1 christos /* Return data address that triggered watchpoint. Called only if
731 1.1 christos low_stopped_by_watchpoint returned true. */
732 1.1 christos CORE_ADDR
733 1.1 christos arm_target::low_stopped_data_address ()
734 1.1 christos {
735 1.1 christos struct lwp_info *lwp = get_thread_lwp (current_thread);
736 1.1 christos return lwp->arch_private->stopped_data_address;
737 1.1 christos }
738 1.1 christos
739 1.1 christos /* Called when a new process is created. */
740 1.1 christos arch_process_info *
741 1.1 christos arm_target::low_new_process ()
742 1.1 christos {
743 1.1 christos struct arch_process_info *info = XCNEW (struct arch_process_info);
744 1.1 christos return info;
745 1.1 christos }
746 1.1 christos
747 1.1 christos /* Called when a process is being deleted. */
748 1.1 christos
749 1.1 christos void
750 1.1 christos arm_target::low_delete_process (arch_process_info *info)
751 1.1 christos {
752 1.1 christos xfree (info);
753 1.1 christos }
754 1.1 christos
755 1.1 christos /* Called when a new thread is detected. */
756 1.1 christos void
757 1.1 christos arm_target::low_new_thread (lwp_info *lwp)
758 1.1 christos {
759 1.1 christos struct arch_lwp_info *info = XCNEW (struct arch_lwp_info);
760 1.1 christos int i;
761 1.1 christos
762 1.1 christos for (i = 0; i < MAX_BPTS; i++)
763 1.1 christos info->bpts_changed[i] = 1;
764 1.1 christos for (i = 0; i < MAX_WPTS; i++)
765 1.1 christos info->wpts_changed[i] = 1;
766 1.1 christos
767 1.1 christos lwp->arch_private = info;
768 1.1 christos }
769 1.1 christos
770 1.1 christos /* Function to call when a thread is being deleted. */
771 1.1 christos
772 1.1 christos void
773 1.1 christos arm_target::low_delete_thread (arch_lwp_info *arch_lwp)
774 1.1 christos {
775 1.1 christos xfree (arch_lwp);
776 1.1 christos }
777 1.1 christos
778 1.1 christos void
779 1.1 christos arm_target::low_new_fork (process_info *parent, process_info *child)
780 1.1 christos {
781 1.1 christos struct arch_process_info *parent_proc_info;
782 1.1 christos struct arch_process_info *child_proc_info;
783 1.1 christos struct lwp_info *child_lwp;
784 1.1 christos struct arch_lwp_info *child_lwp_info;
785 1.1 christos int i;
786 1.1 christos
787 1.1 christos /* These are allocated by linux_add_process. */
788 1.1 christos gdb_assert (parent->priv != NULL
789 1.1 christos && parent->priv->arch_private != NULL);
790 1.1 christos gdb_assert (child->priv != NULL
791 1.1 christos && child->priv->arch_private != NULL);
792 1.1 christos
793 1.1 christos parent_proc_info = parent->priv->arch_private;
794 1.1 christos child_proc_info = child->priv->arch_private;
795 1.1 christos
796 1.1 christos /* Linux kernel before 2.6.33 commit
797 1.1 christos 72f674d203cd230426437cdcf7dd6f681dad8b0d
798 1.1 christos will inherit hardware debug registers from parent
799 1.1 christos on fork/vfork/clone. Newer Linux kernels create such tasks with
800 1.1 christos zeroed debug registers.
801 1.1 christos
802 1.1 christos GDB core assumes the child inherits the watchpoints/hw
803 1.1 christos breakpoints of the parent, and will remove them all from the
804 1.1 christos forked off process. Copy the debug registers mirrors into the
805 1.1 christos new process so that all breakpoints and watchpoints can be
806 1.1 christos removed together. The debug registers mirror will become zeroed
807 1.1 christos in the end before detaching the forked off process, thus making
808 1.1 christos this compatible with older Linux kernels too. */
809 1.1 christos
810 1.1 christos *child_proc_info = *parent_proc_info;
811 1.1 christos
812 1.1 christos /* Mark all the hardware breakpoints and watchpoints as changed to
813 1.1 christos make sure that the registers will be updated. */
814 1.1 christos child_lwp = find_lwp_pid (ptid_t (child->pid));
815 1.1 christos child_lwp_info = child_lwp->arch_private;
816 1.1 christos for (i = 0; i < MAX_BPTS; i++)
817 1.1 christos child_lwp_info->bpts_changed[i] = 1;
818 1.1 christos for (i = 0; i < MAX_WPTS; i++)
819 1.1 christos child_lwp_info->wpts_changed[i] = 1;
820 1.1 christos }
821 1.1 christos
822 1.1 christos /* Called when resuming a thread.
823 1.1 christos If the debug regs have changed, update the thread's copies. */
824 1.1 christos void
825 1.1 christos arm_target::low_prepare_to_resume (lwp_info *lwp)
826 1.1 christos {
827 1.1 christos struct thread_info *thread = get_lwp_thread (lwp);
828 1.1 christos int pid = lwpid_of (thread);
829 1.1 christos struct process_info *proc = find_process_pid (pid_of (thread));
830 1.1 christos struct arch_process_info *proc_info = proc->priv->arch_private;
831 1.1 christos struct arch_lwp_info *lwp_info = lwp->arch_private;
832 1.1 christos int i;
833 1.1 christos
834 1.1 christos for (i = 0; i < arm_linux_get_hw_breakpoint_count (); i++)
835 1.1 christos if (lwp_info->bpts_changed[i])
836 1.1 christos {
837 1.1 christos errno = 0;
838 1.1 christos
839 1.1 christos if (arm_hwbp_control_is_enabled (proc_info->bpts[i].control))
840 1.1 christos if (ptrace (PTRACE_SETHBPREGS, pid,
841 1.1 christos (PTRACE_TYPE_ARG3) ((i << 1) + 1),
842 1.1 christos &proc_info->bpts[i].address) < 0)
843 1.1 christos perror_with_name ("Unexpected error setting breakpoint address");
844 1.1 christos
845 1.1 christos if (arm_hwbp_control_is_initialized (proc_info->bpts[i].control))
846 1.1 christos if (ptrace (PTRACE_SETHBPREGS, pid,
847 1.1 christos (PTRACE_TYPE_ARG3) ((i << 1) + 2),
848 1.1 christos &proc_info->bpts[i].control) < 0)
849 1.1 christos perror_with_name ("Unexpected error setting breakpoint");
850 1.1 christos
851 1.1 christos lwp_info->bpts_changed[i] = 0;
852 1.1 christos }
853 1.1 christos
854 1.1 christos for (i = 0; i < arm_linux_get_hw_watchpoint_count (); i++)
855 1.1 christos if (lwp_info->wpts_changed[i])
856 1.1 christos {
857 1.1 christos errno = 0;
858 1.1 christos
859 1.1 christos if (arm_hwbp_control_is_enabled (proc_info->wpts[i].control))
860 1.1 christos if (ptrace (PTRACE_SETHBPREGS, pid,
861 1.1 christos (PTRACE_TYPE_ARG3) -((i << 1) + 1),
862 1.1 christos &proc_info->wpts[i].address) < 0)
863 1.1 christos perror_with_name ("Unexpected error setting watchpoint address");
864 1.1 christos
865 1.1 christos if (arm_hwbp_control_is_initialized (proc_info->wpts[i].control))
866 1.1 christos if (ptrace (PTRACE_SETHBPREGS, pid,
867 1.1 christos (PTRACE_TYPE_ARG3) -((i << 1) + 2),
868 1.1 christos &proc_info->wpts[i].control) < 0)
869 1.1 christos perror_with_name ("Unexpected error setting watchpoint");
870 1.1 christos
871 1.1 christos lwp_info->wpts_changed[i] = 0;
872 1.1 christos }
873 1.1 christos }
874 1.1 christos
875 1.1 christos /* Find the next pc for a sigreturn or rt_sigreturn syscall. In
876 1.1 christos addition, set IS_THUMB depending on whether we will return to ARM
877 1.1 christos or Thumb code.
878 1.1 christos See arm-linux.h for stack layout details. */
879 1.1 christos static CORE_ADDR
880 1.1 christos arm_sigreturn_next_pc (struct regcache *regcache, int svc_number,
881 1.1 christos int *is_thumb)
882 1.1 christos {
883 1.1 christos unsigned long sp;
884 1.1 christos unsigned long sp_data;
885 1.1 christos /* Offset of PC register. */
886 1.1 christos int pc_offset = 0;
887 1.1 christos CORE_ADDR next_pc = 0;
888 1.1 christos uint32_t cpsr;
889 1.1 christos
890 1.1 christos gdb_assert (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn);
891 1.1 christos
892 1.1 christos collect_register_by_name (regcache, "sp", &sp);
893 1.1 christos the_target->read_memory (sp, (unsigned char *) &sp_data, 4);
894 1.1 christos
895 1.1 christos pc_offset = arm_linux_sigreturn_next_pc_offset
896 1.1 christos (sp, sp_data, svc_number, __NR_sigreturn == svc_number ? 1 : 0);
897 1.1 christos
898 1.1 christos the_target->read_memory (sp + pc_offset, (unsigned char *) &next_pc, 4);
899 1.1 christos
900 1.1 christos /* Set IS_THUMB according the CPSR saved on the stack. */
901 1.1 christos the_target->read_memory (sp + pc_offset + 4, (unsigned char *) &cpsr, 4);
902 1.1 christos *is_thumb = ((cpsr & CPSR_T) != 0);
903 1.1 christos
904 1.1 christos return next_pc;
905 1.1 christos }
906 1.1 christos
907 1.1 christos /* When PC is at a syscall instruction, return the PC of the next
908 1.1 christos instruction to be executed. */
909 1.1 christos static CORE_ADDR
910 1.1 christos get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self)
911 1.1 christos {
912 1.1 christos CORE_ADDR next_pc = 0;
913 1.1 christos CORE_ADDR pc = regcache_read_pc (self->regcache);
914 1.1 christos int is_thumb = arm_is_thumb_mode ();
915 1.1 christos ULONGEST svc_number = 0;
916 1.1.1.3 christos regcache *regcache
917 1.1.1.3 christos = gdb::checked_static_cast<struct regcache *> (self->regcache);
918 1.1 christos
919 1.1 christos if (is_thumb)
920 1.1 christos {
921 1.1 christos collect_register (regcache, 7, &svc_number);
922 1.1 christos next_pc = pc + 2;
923 1.1 christos }
924 1.1 christos else
925 1.1 christos {
926 1.1 christos unsigned long this_instr;
927 1.1 christos unsigned long svc_operand;
928 1.1 christos
929 1.1 christos target_read_memory (pc, (unsigned char *) &this_instr, 4);
930 1.1 christos svc_operand = (0x00ffffff & this_instr);
931 1.1 christos
932 1.1 christos if (svc_operand) /* OABI. */
933 1.1 christos {
934 1.1 christos svc_number = svc_operand - 0x900000;
935 1.1 christos }
936 1.1 christos else /* EABI. */
937 1.1 christos {
938 1.1 christos collect_register (regcache, 7, &svc_number);
939 1.1 christos }
940 1.1 christos
941 1.1 christos next_pc = pc + 4;
942 1.1 christos }
943 1.1 christos
944 1.1 christos /* This is a sigreturn or sigreturn_rt syscall. */
945 1.1 christos if (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn)
946 1.1 christos {
947 1.1 christos /* SIGRETURN or RT_SIGRETURN may affect the arm thumb mode, so
948 1.1 christos update IS_THUMB. */
949 1.1 christos next_pc = arm_sigreturn_next_pc (regcache, svc_number, &is_thumb);
950 1.1 christos }
951 1.1 christos
952 1.1 christos /* Addresses for calling Thumb functions have the bit 0 set. */
953 1.1 christos if (is_thumb)
954 1.1 christos next_pc = MAKE_THUMB_ADDR (next_pc);
955 1.1 christos
956 1.1 christos return next_pc;
957 1.1 christos }
958 1.1 christos
959 1.1 christos static const struct target_desc *
960 1.1 christos arm_read_description (void)
961 1.1 christos {
962 1.1.1.3 christos unsigned long arm_hwcap = linux_get_hwcap (current_thread->id.pid (), 4);
963 1.1 christos
964 1.1 christos if (arm_hwcap & HWCAP_IWMMXT)
965 1.1 christos return arm_linux_read_description (ARM_FP_TYPE_IWMMXT);
966 1.1 christos
967 1.1 christos if (arm_hwcap & HWCAP_VFP)
968 1.1 christos {
969 1.1 christos /* Make sure that the kernel supports reading VFP registers. Support was
970 1.1 christos added in 2.6.30. */
971 1.1 christos int pid = lwpid_of (current_thread);
972 1.1 christos errno = 0;
973 1.1 christos char *buf = (char *) alloca (ARM_VFP3_REGS_SIZE);
974 1.1 christos if (ptrace (PTRACE_GETVFPREGS, pid, 0, buf) < 0 && errno == EIO)
975 1.1 christos return arm_linux_read_description (ARM_FP_TYPE_NONE);
976 1.1 christos
977 1.1 christos /* NEON implies either no VFP, or VFPv3-D32. We only support
978 1.1 christos it with VFP. */
979 1.1 christos if (arm_hwcap & HWCAP_NEON)
980 1.1 christos return aarch32_linux_read_description ();
981 1.1 christos else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
982 1.1 christos return arm_linux_read_description (ARM_FP_TYPE_VFPV3);
983 1.1 christos else
984 1.1 christos return arm_linux_read_description (ARM_FP_TYPE_VFPV2);
985 1.1 christos }
986 1.1 christos
987 1.1 christos /* The default configuration uses legacy FPA registers, probably
988 1.1 christos simulated. */
989 1.1 christos return arm_linux_read_description (ARM_FP_TYPE_NONE);
990 1.1 christos }
991 1.1 christos
992 1.1 christos void
993 1.1 christos arm_target::low_arch_setup ()
994 1.1 christos {
995 1.1 christos int tid = lwpid_of (current_thread);
996 1.1 christos int gpregs[18];
997 1.1 christos struct iovec iov;
998 1.1 christos
999 1.1 christos /* Query hardware watchpoint/breakpoint capabilities. */
1000 1.1 christos arm_linux_init_hwbp_cap (tid);
1001 1.1 christos
1002 1.1 christos current_process ()->tdesc = arm_read_description ();
1003 1.1 christos
1004 1.1 christos iov.iov_base = gpregs;
1005 1.1 christos iov.iov_len = sizeof (gpregs);
1006 1.1 christos
1007 1.1 christos /* Check if PTRACE_GETREGSET works. */
1008 1.1 christos if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov) == 0)
1009 1.1.1.3 christos have_ptrace_getregset = TRIBOOL_TRUE;
1010 1.1 christos else
1011 1.1.1.3 christos have_ptrace_getregset = TRIBOOL_FALSE;
1012 1.1 christos }
1013 1.1 christos
1014 1.1 christos bool
1015 1.1 christos arm_target::supports_software_single_step ()
1016 1.1 christos {
1017 1.1 christos return true;
1018 1.1 christos }
1019 1.1 christos
1020 1.1 christos /* Fetch the next possible PCs after the current instruction executes. */
1021 1.1 christos
1022 1.1 christos std::vector<CORE_ADDR>
1023 1.1 christos arm_target::low_get_next_pcs (regcache *regcache)
1024 1.1 christos {
1025 1.1 christos struct arm_get_next_pcs next_pcs_ctx;
1026 1.1 christos
1027 1.1 christos arm_get_next_pcs_ctor (&next_pcs_ctx,
1028 1.1 christos &get_next_pcs_ops,
1029 1.1 christos /* Byte order is ignored assumed as host. */
1030 1.1 christos 0,
1031 1.1 christos 0,
1032 1.1 christos 1,
1033 1.1 christos regcache);
1034 1.1 christos
1035 1.1 christos return arm_get_next_pcs (&next_pcs_ctx);
1036 1.1 christos }
1037 1.1 christos
1038 1.1 christos /* Support for hardware single step. */
1039 1.1 christos
1040 1.1 christos bool
1041 1.1 christos arm_target::supports_hardware_single_step ()
1042 1.1 christos {
1043 1.1 christos return false;
1044 1.1 christos }
1045 1.1 christos
1046 1.1 christos bool
1047 1.1 christos arm_target::low_supports_catch_syscall ()
1048 1.1 christos {
1049 1.1 christos return true;
1050 1.1 christos }
1051 1.1 christos
1052 1.1 christos /* Implementation of linux target ops method "low_get_syscall_trapinfo". */
1053 1.1 christos
1054 1.1 christos void
1055 1.1 christos arm_target::low_get_syscall_trapinfo (regcache *regcache, int *sysno)
1056 1.1 christos {
1057 1.1 christos if (arm_is_thumb_mode ())
1058 1.1 christos collect_register_by_name (regcache, "r7", sysno);
1059 1.1 christos else
1060 1.1 christos {
1061 1.1 christos unsigned long pc;
1062 1.1 christos unsigned long insn;
1063 1.1 christos
1064 1.1 christos collect_register_by_name (regcache, "pc", &pc);
1065 1.1 christos
1066 1.1 christos if (read_memory (pc - 4, (unsigned char *) &insn, 4))
1067 1.1 christos *sysno = UNKNOWN_SYSCALL;
1068 1.1 christos else
1069 1.1 christos {
1070 1.1 christos unsigned long svc_operand = (0x00ffffff & insn);
1071 1.1 christos
1072 1.1 christos if (svc_operand)
1073 1.1 christos {
1074 1.1 christos /* OABI */
1075 1.1 christos *sysno = svc_operand - 0x900000;
1076 1.1 christos }
1077 1.1 christos else
1078 1.1 christos {
1079 1.1 christos /* EABI */
1080 1.1 christos collect_register_by_name (regcache, "r7", sysno);
1081 1.1 christos }
1082 1.1 christos }
1083 1.1 christos }
1084 1.1 christos }
1085 1.1 christos
1086 1.1 christos /* Register sets without using PTRACE_GETREGSET. */
1087 1.1 christos
1088 1.1 christos static struct regset_info arm_regsets[] = {
1089 1.1 christos { PTRACE_GETREGS, PTRACE_SETREGS, 0,
1090 1.1 christos ARM_CORE_REGS_SIZE + ARM_INT_REGISTER_SIZE, GENERAL_REGS,
1091 1.1 christos arm_fill_gregset, arm_store_gregset },
1092 1.1 christos { PTRACE_GETWMMXREGS, PTRACE_SETWMMXREGS, 0, IWMMXT_REGS_SIZE, EXTENDED_REGS,
1093 1.1 christos arm_fill_wmmxregset, arm_store_wmmxregset },
1094 1.1 christos { PTRACE_GETVFPREGS, PTRACE_SETVFPREGS, 0, ARM_VFP3_REGS_SIZE, EXTENDED_REGS,
1095 1.1 christos arm_fill_vfpregset, arm_store_vfpregset },
1096 1.1 christos NULL_REGSET
1097 1.1 christos };
1098 1.1 christos
1099 1.1 christos static struct regsets_info arm_regsets_info =
1100 1.1 christos {
1101 1.1 christos arm_regsets, /* regsets */
1102 1.1 christos 0, /* num_regsets */
1103 1.1 christos NULL, /* disabled_regsets */
1104 1.1 christos };
1105 1.1 christos
1106 1.1 christos static struct usrregs_info arm_usrregs_info =
1107 1.1 christos {
1108 1.1 christos arm_num_regs,
1109 1.1 christos arm_regmap,
1110 1.1 christos };
1111 1.1 christos
1112 1.1 christos static struct regs_info regs_info_arm =
1113 1.1 christos {
1114 1.1 christos NULL, /* regset_bitmap */
1115 1.1 christos &arm_usrregs_info,
1116 1.1 christos &arm_regsets_info
1117 1.1 christos };
1118 1.1 christos
1119 1.1 christos const regs_info *
1120 1.1 christos arm_target::get_regs_info ()
1121 1.1 christos {
1122 1.1 christos const struct target_desc *tdesc = current_process ()->tdesc;
1123 1.1 christos
1124 1.1.1.3 christos if (have_ptrace_getregset == TRIBOOL_TRUE
1125 1.1 christos && (is_aarch32_linux_description (tdesc)
1126 1.1 christos || arm_linux_get_tdesc_fp_type (tdesc) == ARM_FP_TYPE_VFPV3))
1127 1.1 christos return ®s_info_aarch32;
1128 1.1 christos
1129 1.1 christos return ®s_info_arm;
1130 1.1 christos }
1131 1.1 christos
1132 1.1 christos /* The linux target ops object. */
1133 1.1 christos
1134 1.1 christos linux_process_target *the_linux_target = &the_arm_target;
1135 1.1 christos
1136 1.1 christos void
1137 1.1 christos initialize_low_arch (void)
1138 1.1 christos {
1139 1.1 christos initialize_low_arch_aarch32 ();
1140 1.1 christos initialize_regsets_info (&arm_regsets_info);
1141 1.1 christos }
1142