use gnulib's update-copyright script to update copyright years
[deliverable/binutils-gdb.git] / gdb / gdbserver / linux-arm-low.c
CommitLineData
0a30fbc4 1/* GNU/Linux/ARM specific low level interface, for the remote server for GDB.
9308fc88 2 Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
7b6bb8da 3 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
0a30fbc4
DJ
4
5 This file is part of GDB.
6
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
0a30fbc4
DJ
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0a30fbc4
DJ
19
20#include "server.h"
58caa3dc 21#include "linux-low.h"
0a30fbc4 22
3743bb4f
DE
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. */
25#ifndef ELFMAG0
58d6951d 26#include <elf.h>
3743bb4f 27#endif
9308fc88 28#include <sys/ptrace.h>
09b4ad9f 29#include <signal.h>
9308fc88 30
58d6951d 31/* Defined in auto-generated files. */
d05b4ac3 32void init_registers_arm (void);
d05b4ac3 33void init_registers_arm_with_iwmmxt (void);
58d6951d
DJ
34void init_registers_arm_with_vfpv2 (void);
35void init_registers_arm_with_vfpv3 (void);
36void init_registers_arm_with_neon (void);
d05b4ac3 37
9308fc88
DJ
38#ifndef PTRACE_GET_THREAD_AREA
39#define PTRACE_GET_THREAD_AREA 22
40#endif
41
fb1e4ffc
DJ
42#ifndef PTRACE_GETWMMXREGS
43# define PTRACE_GETWMMXREGS 18
44# define PTRACE_SETWMMXREGS 19
45#endif
46
58d6951d
DJ
47#ifndef PTRACE_GETVFPREGS
48# define PTRACE_GETVFPREGS 27
49# define PTRACE_SETVFPREGS 28
50#endif
51
09b4ad9f
UW
52#ifndef PTRACE_GETHBPREGS
53#define PTRACE_GETHBPREGS 29
54#define PTRACE_SETHBPREGS 30
55#endif
56
57/* Information describing the hardware breakpoint capabilities. */
71487fd7 58static struct
09b4ad9f
UW
59{
60 unsigned char arch;
61 unsigned char max_wp_length;
62 unsigned char wp_count;
63 unsigned char bp_count;
71487fd7 64} arm_linux_hwbp_cap;
09b4ad9f
UW
65
66/* Enum describing the different types of ARM hardware break-/watch-points. */
67typedef enum
68{
69 arm_hwbp_break = 0,
70 arm_hwbp_load = 1,
71 arm_hwbp_store = 2,
72 arm_hwbp_access = 3
73} arm_hwbp_type;
74
75/* Type describing an ARM Hardware Breakpoint Control register value. */
76typedef unsigned int arm_hwbp_control_t;
77
78/* Structure used to keep track of hardware break-/watch-points. */
79struct arm_linux_hw_breakpoint
80{
81 /* Address to break on, or being watched. */
82 unsigned int address;
83 /* Control register for break-/watch- point. */
84 arm_hwbp_control_t control;
85};
86
87/* Since we cannot dynamically allocate subfields of arch_process_info,
88 assume a maximum number of supported break-/watchpoints. */
89#define MAX_BPTS 32
90#define MAX_WPTS 32
91
92/* Per-process arch-specific data we want to keep. */
93struct arch_process_info
94{
95 /* Hardware breakpoints for this process. */
96 struct arm_linux_hw_breakpoint bpts[MAX_BPTS];
97 /* Hardware watchpoints for this process. */
98 struct arm_linux_hw_breakpoint wpts[MAX_WPTS];
99};
100
101/* Per-thread arch-specific data we want to keep. */
102struct arch_lwp_info
103{
104 /* Non-zero if our copy differs from what's recorded in the thread. */
105 char bpts_changed[MAX_BPTS];
106 char wpts_changed[MAX_WPTS];
107 /* Cached stopped data address. */
108 CORE_ADDR stopped_data_address;
109};
110
58d6951d
DJ
111static unsigned long arm_hwcap;
112
113/* These are in <asm/elf.h> in current kernels. */
114#define HWCAP_VFP 64
115#define HWCAP_IWMMXT 512
116#define HWCAP_NEON 4096
117#define HWCAP_VFPv3 8192
118#define HWCAP_VFPv3D16 16384
119
0a30fbc4
DJ
120#ifdef HAVE_SYS_REG_H
121#include <sys/reg.h>
122#endif
123
23ce3b1c 124#define arm_num_regs 26
0a30fbc4 125
2ec06d2e 126static int arm_regmap[] = {
0a30fbc4
DJ
127 0, 4, 8, 12, 16, 20, 24, 28,
128 32, 36, 40, 44, 48, 52, 56, 60,
23ce3b1c
DJ
129 -1, -1, -1, -1, -1, -1, -1, -1, -1,
130 64
0a30fbc4
DJ
131};
132
2ec06d2e
DJ
133static int
134arm_cannot_store_register (int regno)
0a30fbc4 135{
2ec06d2e 136 return (regno >= arm_num_regs);
0a30fbc4
DJ
137}
138
2ec06d2e
DJ
139static int
140arm_cannot_fetch_register (int regno)
0a30fbc4 141{
2ec06d2e 142 return (regno >= arm_num_regs);
0a30fbc4
DJ
143}
144
fb1e4ffc 145static void
442ea881 146arm_fill_gregset (struct regcache *regcache, void *buf)
fb1e4ffc
DJ
147{
148 int i;
149
150 for (i = 0; i < arm_num_regs; i++)
151 if (arm_regmap[i] != -1)
442ea881 152 collect_register (regcache, i, ((char *) buf) + arm_regmap[i]);
fb1e4ffc
DJ
153}
154
155static void
442ea881 156arm_store_gregset (struct regcache *regcache, const void *buf)
fb1e4ffc
DJ
157{
158 int i;
159 char zerobuf[8];
160
161 memset (zerobuf, 0, 8);
162 for (i = 0; i < arm_num_regs; i++)
163 if (arm_regmap[i] != -1)
442ea881 164 supply_register (regcache, i, ((char *) buf) + arm_regmap[i]);
fb1e4ffc 165 else
442ea881 166 supply_register (regcache, i, zerobuf);
fb1e4ffc
DJ
167}
168
fb1e4ffc 169static void
442ea881 170arm_fill_wmmxregset (struct regcache *regcache, void *buf)
fb1e4ffc
DJ
171{
172 int i;
173
58d6951d
DJ
174 if (!(arm_hwcap & HWCAP_IWMMXT))
175 return;
176
fb1e4ffc 177 for (i = 0; i < 16; i++)
442ea881 178 collect_register (regcache, arm_num_regs + i, (char *) buf + i * 8);
fb1e4ffc
DJ
179
180 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
181 for (i = 0; i < 6; i++)
442ea881
PA
182 collect_register (regcache, arm_num_regs + i + 16,
183 (char *) buf + 16 * 8 + i * 4);
fb1e4ffc
DJ
184}
185
186static void
442ea881 187arm_store_wmmxregset (struct regcache *regcache, const void *buf)
fb1e4ffc
DJ
188{
189 int i;
190
58d6951d
DJ
191 if (!(arm_hwcap & HWCAP_IWMMXT))
192 return;
193
fb1e4ffc 194 for (i = 0; i < 16; i++)
442ea881 195 supply_register (regcache, arm_num_regs + i, (char *) buf + i * 8);
fb1e4ffc
DJ
196
197 /* We only have access to wcssf, wcasf, and wcgr0-wcgr3. */
198 for (i = 0; i < 6; i++)
442ea881
PA
199 supply_register (regcache, arm_num_regs + i + 16,
200 (char *) buf + 16 * 8 + i * 4);
fb1e4ffc
DJ
201}
202
58d6951d 203static void
442ea881 204arm_fill_vfpregset (struct regcache *regcache, void *buf)
58d6951d
DJ
205{
206 int i, num, base;
207
208 if (!(arm_hwcap & HWCAP_VFP))
209 return;
210
211 if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
212 num = 32;
213 else
214 num = 16;
215
216 base = find_regno ("d0");
217 for (i = 0; i < num; i++)
442ea881 218 collect_register (regcache, base + i, (char *) buf + i * 8);
58d6951d 219
442ea881 220 collect_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
58d6951d
DJ
221}
222
223static void
442ea881 224arm_store_vfpregset (struct regcache *regcache, const void *buf)
58d6951d
DJ
225{
226 int i, num, base;
227
228 if (!(arm_hwcap & HWCAP_VFP))
229 return;
230
231 if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
232 num = 32;
233 else
234 num = 16;
235
236 base = find_regno ("d0");
237 for (i = 0; i < num; i++)
442ea881 238 supply_register (regcache, base + i, (char *) buf + i * 8);
58d6951d 239
442ea881 240 supply_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8);
58d6951d 241}
fb1e4ffc 242
d677d77d
DJ
243extern int debug_threads;
244
0d62e5e8 245static CORE_ADDR
442ea881 246arm_get_pc (struct regcache *regcache)
0d62e5e8
DJ
247{
248 unsigned long pc;
442ea881 249 collect_register_by_name (regcache, "pc", &pc);
d677d77d
DJ
250 if (debug_threads)
251 fprintf (stderr, "stop pc is %08lx\n", pc);
0d62e5e8
DJ
252 return pc;
253}
254
255static void
442ea881 256arm_set_pc (struct regcache *regcache, CORE_ADDR pc)
0d62e5e8
DJ
257{
258 unsigned long newpc = pc;
442ea881 259 supply_register_by_name (regcache, "pc", &newpc);
0d62e5e8
DJ
260}
261
aeb75bf5 262/* Correct in either endianness. */
0d62e5e8
DJ
263static const unsigned long arm_breakpoint = 0xef9f0001;
264#define arm_breakpoint_len 4
aeb75bf5 265static const unsigned short thumb_breakpoint = 0xde01;
177321bd 266static const unsigned short thumb2_breakpoint[] = { 0xf7f0, 0xa000 };
0d62e5e8 267
9d1fb177
DJ
268/* For new EABI binaries. We recognize it regardless of which ABI
269 is used for gdbserver, so single threaded debugging should work
270 OK, but for multi-threaded debugging we only insert the current
271 ABI's breakpoint instruction. For now at least. */
272static const unsigned long arm_eabi_breakpoint = 0xe7f001f0;
273
0d62e5e8
DJ
274static int
275arm_breakpoint_at (CORE_ADDR where)
276{
442ea881 277 struct regcache *regcache = get_thread_regcache (current_inferior, 1);
aeb75bf5 278 unsigned long cpsr;
0d62e5e8 279
442ea881 280 collect_register_by_name (regcache, "cpsr", &cpsr);
0d62e5e8 281
aeb75bf5
DJ
282 if (cpsr & 0x20)
283 {
284 /* Thumb mode. */
285 unsigned short insn;
9d1fb177 286
aeb75bf5
DJ
287 (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
288 if (insn == thumb_breakpoint)
289 return 1;
177321bd
DJ
290
291 if (insn == thumb2_breakpoint[0])
292 {
293 (*the_target->read_memory) (where + 2, (unsigned char *) &insn, 2);
294 if (insn == thumb2_breakpoint[1])
295 return 1;
296 }
aeb75bf5
DJ
297 }
298 else
299 {
300 /* ARM mode. */
301 unsigned long insn;
302
303 (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
304 if (insn == arm_breakpoint)
305 return 1;
306
307 if (insn == arm_eabi_breakpoint)
308 return 1;
309 }
9d1fb177 310
0d62e5e8
DJ
311 return 0;
312}
313
3b2fc2ea
DJ
314/* We only place breakpoints in empty marker functions, and thread locking
315 is outside of the function. So rather than importing software single-step,
316 we can just run until exit. */
317static CORE_ADDR
442ea881 318arm_reinsert_addr (void)
3b2fc2ea 319{
442ea881 320 struct regcache *regcache = get_thread_regcache (current_inferior, 1);
3b2fc2ea 321 unsigned long pc;
442ea881 322 collect_register_by_name (regcache, "lr", &pc);
3b2fc2ea
DJ
323 return pc;
324}
325
9308fc88
DJ
326/* Fetch the thread-local storage pointer for libthread_db. */
327
328ps_err_e
329ps_get_thread_area (const struct ps_prochandle *ph,
1b3f6016 330 lwpid_t lwpid, int idx, void **base)
9308fc88
DJ
331{
332 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
333 return PS_ERR;
334
335 /* IDX is the bias from the thread pointer to the beginning of the
336 thread descriptor. It has to be subtracted due to implementation
337 quirks in libthread_db. */
338 *base = (void *) ((char *)*base - idx);
339
340 return PS_OK;
341}
342
09b4ad9f 343
71487fd7
UW
344/* Query Hardware Breakpoint information for the target we are attached to
345 (using PID as ptrace argument) and set up arm_linux_hwbp_cap. */
346static void
347arm_linux_init_hwbp_cap (int pid)
09b4ad9f 348{
71487fd7 349 unsigned int val;
09b4ad9f 350
71487fd7
UW
351 if (ptrace (PTRACE_GETHBPREGS, pid, 0, &val) < 0)
352 return;
09b4ad9f 353
71487fd7
UW
354 arm_linux_hwbp_cap.arch = (unsigned char)((val >> 24) & 0xff);
355 if (arm_linux_hwbp_cap.arch == 0)
356 return;
09b4ad9f 357
71487fd7
UW
358 arm_linux_hwbp_cap.max_wp_length = (unsigned char)((val >> 16) & 0xff);
359 arm_linux_hwbp_cap.wp_count = (unsigned char)((val >> 8) & 0xff);
360 arm_linux_hwbp_cap.bp_count = (unsigned char)(val & 0xff);
09b4ad9f 361
71487fd7
UW
362 if (arm_linux_hwbp_cap.wp_count > MAX_WPTS)
363 internal_error (__FILE__, __LINE__, "Unsupported number of watchpoints");
364 if (arm_linux_hwbp_cap.bp_count > MAX_BPTS)
365 internal_error (__FILE__, __LINE__, "Unsupported number of breakpoints");
09b4ad9f
UW
366}
367
368/* How many hardware breakpoints are available? */
369static int
370arm_linux_get_hw_breakpoint_count (void)
371{
71487fd7 372 return arm_linux_hwbp_cap.bp_count;
09b4ad9f
UW
373}
374
375/* How many hardware watchpoints are available? */
376static int
377arm_linux_get_hw_watchpoint_count (void)
378{
71487fd7 379 return arm_linux_hwbp_cap.wp_count;
09b4ad9f
UW
380}
381
382/* Maximum length of area watched by hardware watchpoint. */
383static int
384arm_linux_get_hw_watchpoint_max_length (void)
385{
71487fd7 386 return arm_linux_hwbp_cap.max_wp_length;
09b4ad9f
UW
387}
388
389/* Initialize an ARM hardware break-/watch-point control register value.
390 BYTE_ADDRESS_SELECT is the mask of bytes to trigger on; HWBP_TYPE is the
391 type of break-/watch-point; ENABLE indicates whether the point is enabled.
392 */
393static arm_hwbp_control_t
394arm_hwbp_control_initialize (unsigned byte_address_select,
395 arm_hwbp_type hwbp_type,
396 int enable)
397{
398 gdb_assert ((byte_address_select & ~0xffU) == 0);
399 gdb_assert (hwbp_type != arm_hwbp_break
400 || ((byte_address_select & 0xfU) != 0));
401
402 return (byte_address_select << 5) | (hwbp_type << 3) | (3 << 1) | enable;
403}
404
405/* Does the breakpoint control value CONTROL have the enable bit set? */
406static int
407arm_hwbp_control_is_enabled (arm_hwbp_control_t control)
408{
409 return control & 0x1;
410}
411
412/* Is the breakpoint control value CONTROL initialized? */
413static int
414arm_hwbp_control_is_initialized (arm_hwbp_control_t control)
415{
416 return control != 0;
417}
418
419/* Change a breakpoint control word so that it is in the disabled state. */
420static arm_hwbp_control_t
421arm_hwbp_control_disable (arm_hwbp_control_t control)
422{
423 return control & ~0x1;
424}
425
426/* Are two break-/watch-points equal? */
427static int
428arm_linux_hw_breakpoint_equal (const struct arm_linux_hw_breakpoint *p1,
429 const struct arm_linux_hw_breakpoint *p2)
430{
431 return p1->address == p2->address && p1->control == p2->control;
432}
433
434/* Initialize the hardware breakpoint structure P for a breakpoint or
435 watchpoint at ADDR to LEN. The type of watchpoint is given in TYPE.
436 Returns -1 if TYPE is unsupported, 0 if TYPE represents a breakpoint,
437 and 1 if type represents a watchpoint. */
438static int
439arm_linux_hw_point_initialize (char type, CORE_ADDR addr, int len,
440 struct arm_linux_hw_breakpoint *p)
441{
442 arm_hwbp_type hwbp_type;
443 unsigned mask;
444
445 /* Breakpoint/watchpoint types (GDB terminology):
446 0 = memory breakpoint for instructions
447 (not supported; done via memory write instead)
448 1 = hardware breakpoint for instructions (supported)
449 2 = write watchpoint (supported)
450 3 = read watchpoint (supported)
451 4 = access watchpoint (supported). */
452 switch (type)
453 {
454 case '1':
455 hwbp_type = arm_hwbp_break;
456 break;
457 case '2':
458 hwbp_type = arm_hwbp_store;
459 break;
460 case '3':
461 hwbp_type = arm_hwbp_load;
462 break;
463 case '4':
464 hwbp_type = arm_hwbp_access;
465 break;
466 default:
467 /* Unsupported. */
468 return -1;
469 }
470
471 if (hwbp_type == arm_hwbp_break)
472 {
473 /* For breakpoints, the length field encodes the mode. */
474 switch (len)
475 {
476 case 2: /* 16-bit Thumb mode breakpoint */
477 case 3: /* 32-bit Thumb mode breakpoint */
478 mask = 0x3 << (addr & 2);
479 break;
480 case 4: /* 32-bit ARM mode breakpoint */
481 mask = 0xf;
482 break;
483 default:
484 /* Unsupported. */
485 return -1;
486 }
487
488 addr &= ~3;
489 }
490 else
491 {
492 CORE_ADDR max_wp_length = arm_linux_get_hw_watchpoint_max_length ();
493 CORE_ADDR aligned_addr;
494
495 /* Can not set watchpoints for zero or negative lengths. */
496 if (len <= 0)
497 return -1;
498 /* The current ptrace interface can only handle watchpoints that are a
499 power of 2. */
500 if ((len & (len - 1)) != 0)
501 return -1;
502
503 /* Test that the range [ADDR, ADDR + LEN) fits into the largest address
504 range covered by a watchpoint. */
505 aligned_addr = addr & ~(max_wp_length - 1);
506 if (aligned_addr + max_wp_length < addr + len)
507 return -1;
508
509 mask = (1 << len) - 1;
510 }
511
512 p->address = (unsigned int) addr;
513 p->control = arm_hwbp_control_initialize (mask, hwbp_type, 1);
514
515 return hwbp_type != arm_hwbp_break;
516}
517
518/* Callback to mark a watch-/breakpoint to be updated in all threads of
519 the current process. */
520
521struct update_registers_data
522{
523 int watch;
524 int i;
525};
526
527static int
528update_registers_callback (struct inferior_list_entry *entry, void *arg)
529{
530 struct lwp_info *lwp = (struct lwp_info *) entry;
531 struct update_registers_data *data = (struct update_registers_data *) arg;
532
533 /* Only update the threads of the current process. */
534 if (pid_of (lwp) == pid_of (get_thread_lwp (current_inferior)))
535 {
536 /* The actual update is done later just before resuming the lwp,
537 we just mark that the registers need updating. */
538 if (data->watch)
539 lwp->arch_private->wpts_changed[data->i] = 1;
540 else
541 lwp->arch_private->bpts_changed[data->i] = 1;
542
543 /* If the lwp isn't stopped, force it to momentarily pause, so
544 we can update its breakpoint registers. */
545 if (!lwp->stopped)
546 linux_stop_lwp (lwp);
547 }
548
549 return 0;
550}
551
552/* Insert hardware break-/watchpoint. */
553static int
554arm_insert_point (char type, CORE_ADDR addr, int len)
555{
556 struct process_info *proc = current_process ();
557 struct arm_linux_hw_breakpoint p, *pts;
558 int watch, i, count;
559
560 watch = arm_linux_hw_point_initialize (type, addr, len, &p);
561 if (watch < 0)
562 {
563 /* Unsupported. */
564 return 1;
565 }
566
567 if (watch)
568 {
569 count = arm_linux_get_hw_watchpoint_count ();
570 pts = proc->private->arch_private->wpts;
571 }
572 else
573 {
574 count = arm_linux_get_hw_breakpoint_count ();
575 pts = proc->private->arch_private->bpts;
576 }
577
578 for (i = 0; i < count; i++)
579 if (!arm_hwbp_control_is_enabled (pts[i].control))
580 {
581 struct update_registers_data data = { watch, i };
582 pts[i] = p;
583 find_inferior (&all_lwps, update_registers_callback, &data);
584 return 0;
585 }
586
587 /* We're out of watchpoints. */
588 return -1;
589}
590
591/* Remove hardware break-/watchpoint. */
592static int
593arm_remove_point (char type, CORE_ADDR addr, int len)
594{
595 struct process_info *proc = current_process ();
596 struct arm_linux_hw_breakpoint p, *pts;
597 int watch, i, count;
598
599 watch = arm_linux_hw_point_initialize (type, addr, len, &p);
600 if (watch < 0)
601 {
602 /* Unsupported. */
603 return -1;
604 }
605
606 if (watch)
607 {
608 count = arm_linux_get_hw_watchpoint_count ();
609 pts = proc->private->arch_private->wpts;
610 }
611 else
612 {
613 count = arm_linux_get_hw_breakpoint_count ();
614 pts = proc->private->arch_private->bpts;
615 }
616
617 for (i = 0; i < count; i++)
618 if (arm_linux_hw_breakpoint_equal (&p, pts + i))
619 {
620 struct update_registers_data data = { watch, i };
621 pts[i].control = arm_hwbp_control_disable (pts[i].control);
622 find_inferior (&all_lwps, update_registers_callback, &data);
623 return 0;
624 }
625
626 /* No watchpoint matched. */
627 return -1;
628}
629
630/* Return whether current thread is stopped due to a watchpoint. */
631static int
632arm_stopped_by_watchpoint (void)
633{
634 struct lwp_info *lwp = get_thread_lwp (current_inferior);
635 struct siginfo siginfo;
636
637 /* We must be able to set hardware watchpoints. */
638 if (arm_linux_get_hw_watchpoint_count () == 0)
639 return 0;
640
641 /* Retrieve siginfo. */
642 errno = 0;
643 ptrace (PTRACE_GETSIGINFO, lwpid_of (lwp), 0, &siginfo);
644 if (errno != 0)
645 return 0;
646
647 /* This must be a hardware breakpoint. */
648 if (siginfo.si_signo != SIGTRAP
649 || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
650 return 0;
651
652 /* If we are in a positive slot then we're looking at a breakpoint and not
653 a watchpoint. */
654 if (siginfo.si_errno >= 0)
655 return 0;
656
657 /* Cache stopped data address for use by arm_stopped_data_address. */
658 lwp->arch_private->stopped_data_address
659 = (CORE_ADDR) (uintptr_t) siginfo.si_addr;
660
661 return 1;
662}
663
664/* Return data address that triggered watchpoint. Called only if
665 arm_stopped_by_watchpoint returned true. */
666static CORE_ADDR
667arm_stopped_data_address (void)
668{
669 struct lwp_info *lwp = get_thread_lwp (current_inferior);
670 return lwp->arch_private->stopped_data_address;
671}
672
673/* Called when a new process is created. */
674static struct arch_process_info *
675arm_new_process (void)
676{
677 struct arch_process_info *info = xcalloc (1, sizeof (*info));
678 return info;
679}
680
681/* Called when a new thread is detected. */
682static struct arch_lwp_info *
683arm_new_thread (void)
684{
685 struct arch_lwp_info *info = xcalloc (1, sizeof (*info));
686 int i;
687
688 for (i = 0; i < MAX_BPTS; i++)
689 info->bpts_changed[i] = 1;
690 for (i = 0; i < MAX_WPTS; i++)
691 info->wpts_changed[i] = 1;
692
693 return info;
694}
695
696/* Called when resuming a thread.
697 If the debug regs have changed, update the thread's copies. */
698static void
699arm_prepare_to_resume (struct lwp_info *lwp)
700{
701 int pid = lwpid_of (lwp);
702 struct process_info *proc = find_process_pid (pid_of (lwp));
703 struct arch_process_info *proc_info = proc->private->arch_private;
704 struct arch_lwp_info *lwp_info = lwp->arch_private;
705 int i;
706
707 for (i = 0; i < arm_linux_get_hw_breakpoint_count (); i++)
708 if (lwp_info->bpts_changed[i])
709 {
710 errno = 0;
711
712 if (arm_hwbp_control_is_enabled (proc_info->bpts[i].control))
713 if (ptrace (PTRACE_SETHBPREGS, pid, ((i << 1) + 1),
714 &proc_info->bpts[i].address) < 0)
71487fd7 715 perror_with_name ("Unexpected error setting breakpoint address");
09b4ad9f
UW
716
717 if (arm_hwbp_control_is_initialized (proc_info->bpts[i].control))
718 if (ptrace (PTRACE_SETHBPREGS, pid, ((i << 1) + 2),
719 &proc_info->bpts[i].control) < 0)
71487fd7 720 perror_with_name ("Unexpected error setting breakpoint");
09b4ad9f
UW
721
722 lwp_info->bpts_changed[i] = 0;
723 }
724
725 for (i = 0; i < arm_linux_get_hw_watchpoint_count (); i++)
726 if (lwp_info->wpts_changed[i])
727 {
728 errno = 0;
729
730 if (arm_hwbp_control_is_enabled (proc_info->wpts[i].control))
731 if (ptrace (PTRACE_SETHBPREGS, pid, -((i << 1) + 1),
732 &proc_info->wpts[i].address) < 0)
71487fd7 733 perror_with_name ("Unexpected error setting watchpoint address");
09b4ad9f
UW
734
735 if (arm_hwbp_control_is_initialized (proc_info->wpts[i].control))
736 if (ptrace (PTRACE_SETHBPREGS, pid, -((i << 1) + 2),
737 &proc_info->wpts[i].control) < 0)
71487fd7 738 perror_with_name ("Unexpected error setting watchpoint");
09b4ad9f
UW
739
740 lwp_info->wpts_changed[i] = 0;
741 }
742}
743
744
58d6951d
DJ
745static int
746arm_get_hwcap (unsigned long *valp)
747{
748 unsigned char *data = alloca (8);
749 int offset = 0;
750
751 while ((*the_target->read_auxv) (offset, data, 8) == 8)
752 {
753 unsigned int *data_p = (unsigned int *)data;
754 if (data_p[0] == AT_HWCAP)
755 {
756 *valp = data_p[1];
757 return 1;
758 }
759
760 offset += 8;
761 }
762
763 *valp = 0;
764 return 0;
765}
766
767static void
768arm_arch_setup (void)
769{
71487fd7
UW
770 int pid = lwpid_of (get_thread_lwp (current_inferior));
771
772 /* Query hardware watchpoint/breakpoint capabilities. */
773 arm_linux_init_hwbp_cap (pid);
774
58d6951d
DJ
775 arm_hwcap = 0;
776 if (arm_get_hwcap (&arm_hwcap) == 0)
777 {
778 init_registers_arm ();
779 return;
780 }
781
782 if (arm_hwcap & HWCAP_IWMMXT)
783 {
784 init_registers_arm_with_iwmmxt ();
785 return;
786 }
787
788 if (arm_hwcap & HWCAP_VFP)
789 {
58d6951d
DJ
790 char *buf;
791
792 /* NEON implies either no VFP, or VFPv3-D32. We only support
793 it with VFP. */
794 if (arm_hwcap & HWCAP_NEON)
795 init_registers_arm_with_neon ();
796 else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
797 init_registers_arm_with_vfpv3 ();
798 else
799 init_registers_arm_with_vfpv2 ();
800
801 /* Now make sure that the kernel supports reading these
802 registers. Support was added in 2.6.30. */
58d6951d 803 errno = 0;
c3e8aadd 804 buf = xmalloc (32 * 8 + 4);
58d6951d
DJ
805 if (ptrace (PTRACE_GETVFPREGS, pid, 0, buf) < 0
806 && errno == EIO)
807 {
808 arm_hwcap = 0;
809 init_registers_arm ();
810 }
811 free (buf);
812
813 return;
814 }
815
816 /* The default configuration uses legacy FPA registers, probably
817 simulated. */
818 init_registers_arm ();
819}
820
fb1e4ffc 821struct regset_info target_regsets[] = {
1570b33e 822 { PTRACE_GETREGS, PTRACE_SETREGS, 0, 18 * 4,
fb1e4ffc
DJ
823 GENERAL_REGS,
824 arm_fill_gregset, arm_store_gregset },
1570b33e 825 { PTRACE_GETWMMXREGS, PTRACE_SETWMMXREGS, 0, 16 * 8 + 6 * 4,
fb1e4ffc
DJ
826 EXTENDED_REGS,
827 arm_fill_wmmxregset, arm_store_wmmxregset },
1570b33e 828 { PTRACE_GETVFPREGS, PTRACE_SETVFPREGS, 0, 32 * 8 + 4,
58d6951d
DJ
829 EXTENDED_REGS,
830 arm_fill_vfpregset, arm_store_vfpregset },
1570b33e 831 { 0, 0, 0, -1, -1, NULL, NULL }
fb1e4ffc
DJ
832};
833
2ec06d2e 834struct linux_target_ops the_low_target = {
58d6951d 835 arm_arch_setup,
2ec06d2e
DJ
836 arm_num_regs,
837 arm_regmap,
838 arm_cannot_fetch_register,
839 arm_cannot_store_register,
0d62e5e8
DJ
840 arm_get_pc,
841 arm_set_pc,
aeb75bf5
DJ
842
843 /* Define an ARM-mode breakpoint; we only set breakpoints in the C
844 library, which is most likely to be ARM. If the kernel supports
845 clone events, we will never insert a breakpoint, so even a Thumb
846 C library will work; so will mixing EABI/non-EABI gdbserver and
847 application. */
9d1fb177 848#ifndef __ARM_EABI__
f450004a 849 (const unsigned char *) &arm_breakpoint,
9d1fb177
DJ
850#else
851 (const unsigned char *) &arm_eabi_breakpoint,
852#endif
0d62e5e8 853 arm_breakpoint_len,
3b2fc2ea 854 arm_reinsert_addr,
0d62e5e8
DJ
855 0,
856 arm_breakpoint_at,
09b4ad9f
UW
857 arm_insert_point,
858 arm_remove_point,
859 arm_stopped_by_watchpoint,
860 arm_stopped_data_address,
861 NULL, /* collect_ptrace_register */
862 NULL, /* supply_ptrace_register */
863 NULL, /* siginfo_fixup */
864 arm_new_process,
865 arm_new_thread,
866 arm_prepare_to_resume,
2ec06d2e 867};
This page took 0.730465 seconds and 4 git commands to generate.