Make debug_reg_change_callback the same on GDB and GDBserver
[deliverable/binutils-gdb.git] / gdb / gdbserver / linux-aarch64-low.c
CommitLineData
176eb98c
MS
1/* GNU/Linux/AArch64 specific low level interface, for the remote server for
2 GDB.
3
32d0add0 4 Copyright (C) 2009-2015 Free Software Foundation, Inc.
176eb98c
MS
5 Contributed by ARM Ltd.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22#include "server.h"
23#include "linux-low.h"
554717a3 24#include "nat/aarch64-linux-hw-point.h"
3b53ae99 25#include "linux-aarch32-low.h"
176eb98c
MS
26#include "elf/common.h"
27
28#include <signal.h>
29#include <sys/user.h>
5826e159 30#include "nat/gdb_ptrace.h"
e9dae05e 31#include <asm/ptrace.h>
176eb98c
MS
32#include <sys/uio.h>
33
34#include "gdb_proc_service.h"
35
36/* Defined in auto-generated files. */
37void init_registers_aarch64 (void);
3aee8918 38extern const struct target_desc *tdesc_aarch64;
176eb98c 39
176eb98c
MS
40#ifdef HAVE_SYS_REG_H
41#include <sys/reg.h>
42#endif
43
44#define AARCH64_X_REGS_NUM 31
45#define AARCH64_V_REGS_NUM 32
46#define AARCH64_X0_REGNO 0
47#define AARCH64_SP_REGNO 31
48#define AARCH64_PC_REGNO 32
49#define AARCH64_CPSR_REGNO 33
50#define AARCH64_V0_REGNO 34
bf330350
CU
51#define AARCH64_FPSR_REGNO (AARCH64_V0_REGNO + AARCH64_V_REGS_NUM)
52#define AARCH64_FPCR_REGNO (AARCH64_V0_REGNO + AARCH64_V_REGS_NUM + 1)
176eb98c 53
bf330350 54#define AARCH64_NUM_REGS (AARCH64_V0_REGNO + AARCH64_V_REGS_NUM + 2)
176eb98c 55
176eb98c
MS
56/* Per-process arch-specific data we want to keep. */
57
58struct arch_process_info
59{
60 /* Hardware breakpoint/watchpoint data.
61 The reason for them to be per-process rather than per-thread is
62 due to the lack of information in the gdbserver environment;
63 gdbserver is not told that whether a requested hardware
64 breakpoint/watchpoint is thread specific or not, so it has to set
65 each hw bp/wp for every thread in the current process. The
66 higher level bp/wp management in gdb will resume a thread if a hw
67 bp/wp trap is not expected for it. Since the hw bp/wp setting is
68 same for each thread, it is reasonable for the data to live here.
69 */
70 struct aarch64_debug_reg_state debug_reg_state;
71};
72
3b53ae99
YQ
73/* Return true if the size of register 0 is 8 byte. */
74
75static int
76is_64bit_tdesc (void)
77{
78 struct regcache *regcache = get_thread_regcache (current_thread, 0);
79
80 return register_size (regcache->tdesc, 0) == 8;
81}
82
421530db
PL
83/* Implementation of linux_target_ops method "cannot_store_register". */
84
176eb98c
MS
85static int
86aarch64_cannot_store_register (int regno)
87{
88 return regno >= AARCH64_NUM_REGS;
89}
90
421530db
PL
91/* Implementation of linux_target_ops method "cannot_fetch_register". */
92
176eb98c
MS
93static int
94aarch64_cannot_fetch_register (int regno)
95{
96 return regno >= AARCH64_NUM_REGS;
97}
98
99static void
100aarch64_fill_gregset (struct regcache *regcache, void *buf)
101{
102 struct user_pt_regs *regset = buf;
103 int i;
104
105 for (i = 0; i < AARCH64_X_REGS_NUM; i++)
106 collect_register (regcache, AARCH64_X0_REGNO + i, &regset->regs[i]);
107 collect_register (regcache, AARCH64_SP_REGNO, &regset->sp);
108 collect_register (regcache, AARCH64_PC_REGNO, &regset->pc);
109 collect_register (regcache, AARCH64_CPSR_REGNO, &regset->pstate);
110}
111
112static void
113aarch64_store_gregset (struct regcache *regcache, const void *buf)
114{
115 const struct user_pt_regs *regset = buf;
116 int i;
117
118 for (i = 0; i < AARCH64_X_REGS_NUM; i++)
119 supply_register (regcache, AARCH64_X0_REGNO + i, &regset->regs[i]);
120 supply_register (regcache, AARCH64_SP_REGNO, &regset->sp);
121 supply_register (regcache, AARCH64_PC_REGNO, &regset->pc);
122 supply_register (regcache, AARCH64_CPSR_REGNO, &regset->pstate);
123}
124
125static void
126aarch64_fill_fpregset (struct regcache *regcache, void *buf)
127{
128 struct user_fpsimd_state *regset = buf;
129 int i;
130
131 for (i = 0; i < AARCH64_V_REGS_NUM; i++)
132 collect_register (regcache, AARCH64_V0_REGNO + i, &regset->vregs[i]);
bf330350
CU
133 collect_register (regcache, AARCH64_FPSR_REGNO, &regset->fpsr);
134 collect_register (regcache, AARCH64_FPCR_REGNO, &regset->fpcr);
176eb98c
MS
135}
136
137static void
138aarch64_store_fpregset (struct regcache *regcache, const void *buf)
139{
140 const struct user_fpsimd_state *regset = buf;
141 int i;
142
143 for (i = 0; i < AARCH64_V_REGS_NUM; i++)
144 supply_register (regcache, AARCH64_V0_REGNO + i, &regset->vregs[i]);
bf330350
CU
145 supply_register (regcache, AARCH64_FPSR_REGNO, &regset->fpsr);
146 supply_register (regcache, AARCH64_FPCR_REGNO, &regset->fpcr);
176eb98c
MS
147}
148
176eb98c
MS
149/* Enable miscellaneous debugging output. The name is historical - it
150 was originally used to debug LinuxThreads support. */
151extern int debug_threads;
152
421530db
PL
153/* Implementation of linux_target_ops method "get_pc". */
154
176eb98c
MS
155static CORE_ADDR
156aarch64_get_pc (struct regcache *regcache)
157{
8a7e4587
YQ
158 if (register_size (regcache->tdesc, 0) == 8)
159 {
160 unsigned long pc;
161
162 collect_register_by_name (regcache, "pc", &pc);
163 if (debug_threads)
164 debug_printf ("stop pc is %08lx\n", pc);
165 return pc;
166 }
167 else
168 {
169 unsigned int pc;
170
171 collect_register_by_name (regcache, "pc", &pc);
172 if (debug_threads)
173 debug_printf ("stop pc is %04x\n", pc);
174 return pc;
175 }
176eb98c
MS
176}
177
421530db
PL
178/* Implementation of linux_target_ops method "set_pc". */
179
176eb98c
MS
180static void
181aarch64_set_pc (struct regcache *regcache, CORE_ADDR pc)
182{
8a7e4587
YQ
183 if (register_size (regcache->tdesc, 0) == 8)
184 {
185 unsigned long newpc = pc;
186 supply_register_by_name (regcache, "pc", &newpc);
187 }
188 else
189 {
190 unsigned int newpc = pc;
191 supply_register_by_name (regcache, "pc", &newpc);
192 }
176eb98c
MS
193}
194
176eb98c
MS
195#define aarch64_breakpoint_len 4
196
37d66942
PL
197/* AArch64 BRK software debug mode instruction.
198 This instruction needs to match gdb/aarch64-tdep.c
199 (aarch64_default_breakpoint). */
200static const gdb_byte aarch64_breakpoint[] = {0x00, 0x00, 0x20, 0xd4};
176eb98c 201
421530db
PL
202/* Implementation of linux_target_ops method "breakpoint_at". */
203
176eb98c
MS
204static int
205aarch64_breakpoint_at (CORE_ADDR where)
206{
37d66942 207 gdb_byte insn[aarch64_breakpoint_len];
176eb98c 208
37d66942
PL
209 (*the_target->read_memory) (where, (unsigned char *) &insn,
210 aarch64_breakpoint_len);
211 if (memcmp (insn, aarch64_breakpoint, aarch64_breakpoint_len) == 0)
176eb98c
MS
212 return 1;
213
214 return 0;
215}
216
176eb98c
MS
217static void
218aarch64_init_debug_reg_state (struct aarch64_debug_reg_state *state)
219{
220 int i;
221
222 for (i = 0; i < AARCH64_HBP_MAX_NUM; ++i)
223 {
224 state->dr_addr_bp[i] = 0;
225 state->dr_ctrl_bp[i] = 0;
226 state->dr_ref_count_bp[i] = 0;
227 }
228
229 for (i = 0; i < AARCH64_HWP_MAX_NUM; ++i)
230 {
231 state->dr_addr_wp[i] = 0;
232 state->dr_ctrl_wp[i] = 0;
233 state->dr_ref_count_wp[i] = 0;
234 }
235}
236
176eb98c
MS
237struct aarch64_dr_update_callback_param
238{
176eb98c
MS
239 int is_watchpoint;
240 unsigned int idx;
241};
242
ff3f0f45
YQ
243/* Callback for iterate_over_lwps. Records the
244 information about the change of one hardware breakpoint/watchpoint
245 setting for the thread LWP.
176eb98c
MS
246 The information is passed in via PTR.
247 N.B. The actual updating of hardware debug registers is not
248 carried out until the moment the thread is resumed. */
249
250static int
ff3f0f45 251debug_reg_change_callback (struct lwp_info *lwp, void *ptr)
176eb98c 252{
176eb98c
MS
253 struct aarch64_dr_update_callback_param *param_p
254 = (struct aarch64_dr_update_callback_param *) ptr;
75e1f0f7 255 int pid = ptid_get_pid (ptid_of_lwp (lwp));
176eb98c
MS
256 int idx = param_p->idx;
257 int is_watchpoint = param_p->is_watchpoint;
258 struct arch_lwp_info *info = lwp->arch_private;
259 dr_changed_t *dr_changed_ptr;
260 dr_changed_t dr_changed;
261
c5e92cca 262 if (show_debug_regs)
176eb98c 263 {
32a271ee
YQ
264 debug_printf ("debug_reg_change_callback: \n\tOn entry:\n");
265 debug_printf ("\tpid%d, dr_changed_bp=0x%s, "
266 "dr_changed_wp=0x%s\n", pid,
267 phex (info->dr_changed_bp, 8),
268 phex (info->dr_changed_wp, 8));
176eb98c
MS
269 }
270
271 dr_changed_ptr = is_watchpoint ? &info->dr_changed_wp
272 : &info->dr_changed_bp;
273 dr_changed = *dr_changed_ptr;
274
8ee52567
YQ
275 gdb_assert (idx >= 0
276 && (idx <= (is_watchpoint ? aarch64_num_wp_regs
277 : aarch64_num_bp_regs)));
278
8ee52567
YQ
279 /* The actual update is done later just before resuming the lwp,
280 we just mark that one register pair needs updating. */
281 DR_MARK_N_CHANGED (dr_changed, idx);
282 *dr_changed_ptr = dr_changed;
283
284 /* If the lwp isn't stopped, force it to momentarily pause, so
285 we can update its debug registers. */
286 if (!lwp->stopped)
287 linux_stop_lwp (lwp);
176eb98c 288
c5e92cca 289 if (show_debug_regs)
176eb98c 290 {
32a271ee
YQ
291 debug_printf ("\tOn exit:\n\tpid%d, dr_changed_bp=0x%s, "
292 "dr_changed_wp=0x%s\n", pid,
293 phex (info->dr_changed_bp, 8),
294 phex (info->dr_changed_wp, 8));
176eb98c
MS
295 }
296
297 return 0;
298}
299
300/* Notify each thread that their IDXth breakpoint/watchpoint register
301 pair needs to be updated. The message will be recorded in each
302 thread's arch-specific data area, the actual updating will be done
303 when the thread is resumed. */
304
305void
306aarch64_notify_debug_reg_change (const struct aarch64_debug_reg_state *state,
307 int is_watchpoint, unsigned int idx)
308{
309 struct aarch64_dr_update_callback_param param;
4a8a7965 310 ptid_t pid_ptid = pid_to_ptid (ptid_get_pid (current_lwp_ptid ()));
176eb98c
MS
311
312 param.is_watchpoint = is_watchpoint;
313 param.idx = idx;
314
ff3f0f45 315 iterate_over_lwps (pid_ptid, debug_reg_change_callback, (void *) &param);
176eb98c
MS
316}
317
318
319/* Return the pointer to the debug register state structure in the
320 current process' arch-specific data area. */
321
322static struct aarch64_debug_reg_state *
323aarch64_get_debug_reg_state ()
324{
325 struct process_info *proc;
326
327 proc = current_process ();
fe978cb0 328 return &proc->priv->arch_private->debug_reg_state;
176eb98c
MS
329}
330
421530db
PL
331/* Implementation of linux_target_ops method "supports_z_point_type". */
332
4ff0d3d8
PA
333static int
334aarch64_supports_z_point_type (char z_type)
335{
336 switch (z_type)
337 {
96c97461 338 case Z_PACKET_SW_BP:
6085d6f6
YQ
339 {
340 if (!extended_protocol && is_64bit_tdesc ())
341 {
342 /* Only enable Z0 packet in non-multi-arch debugging. If
343 extended protocol is used, don't enable Z0 packet because
344 GDBserver may attach to 32-bit process. */
345 return 1;
346 }
347 else
348 {
349 /* Disable Z0 packet so that GDBserver doesn't have to handle
350 different breakpoint instructions (aarch64, arm, thumb etc)
351 in multi-arch debugging. */
352 return 0;
353 }
354 }
4ff0d3d8
PA
355 case Z_PACKET_HW_BP:
356 case Z_PACKET_WRITE_WP:
357 case Z_PACKET_READ_WP:
358 case Z_PACKET_ACCESS_WP:
359 return 1;
360 default:
4ff0d3d8
PA
361 return 0;
362 }
363}
364
421530db 365/* Implementation of linux_target_ops method "insert_point".
176eb98c 366
421530db
PL
367 It actually only records the info of the to-be-inserted bp/wp;
368 the actual insertion will happen when threads are resumed. */
176eb98c
MS
369
370static int
802e8e6d
PA
371aarch64_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
372 int len, struct raw_breakpoint *bp)
176eb98c
MS
373{
374 int ret;
4ff0d3d8 375 enum target_hw_bp_type targ_type;
c67ca4de 376 struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state ();
4ff0d3d8 377
c5e92cca 378 if (show_debug_regs)
176eb98c
MS
379 fprintf (stderr, "insert_point on entry (addr=0x%08lx, len=%d)\n",
380 (unsigned long) addr, len);
381
802e8e6d
PA
382 /* Determine the type from the raw breakpoint type. */
383 targ_type = raw_bkpt_type_to_target_hw_bp_type (type);
176eb98c
MS
384
385 if (targ_type != hw_execute)
386 ret =
c67ca4de
YQ
387 aarch64_handle_watchpoint (targ_type, addr, len, 1 /* is_insert */,
388 state);
176eb98c
MS
389 else
390 ret =
c67ca4de
YQ
391 aarch64_handle_breakpoint (targ_type, addr, len, 1 /* is_insert */,
392 state);
176eb98c 393
60a191ed 394 if (show_debug_regs)
176eb98c
MS
395 aarch64_show_debug_reg_state (aarch64_get_debug_reg_state (),
396 "insert_point", addr, len, targ_type);
397
398 return ret;
399}
400
421530db 401/* Implementation of linux_target_ops method "remove_point".
176eb98c 402
421530db
PL
403 It actually only records the info of the to-be-removed bp/wp,
404 the actual removal will be done when threads are resumed. */
176eb98c
MS
405
406static int
802e8e6d
PA
407aarch64_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
408 int len, struct raw_breakpoint *bp)
176eb98c
MS
409{
410 int ret;
4ff0d3d8 411 enum target_hw_bp_type targ_type;
c67ca4de 412 struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state ();
4ff0d3d8 413
c5e92cca 414 if (show_debug_regs)
176eb98c
MS
415 fprintf (stderr, "remove_point on entry (addr=0x%08lx, len=%d)\n",
416 (unsigned long) addr, len);
417
802e8e6d
PA
418 /* Determine the type from the raw breakpoint type. */
419 targ_type = raw_bkpt_type_to_target_hw_bp_type (type);
176eb98c
MS
420
421 /* Set up state pointers. */
422 if (targ_type != hw_execute)
423 ret =
c67ca4de
YQ
424 aarch64_handle_watchpoint (targ_type, addr, len, 0 /* is_insert */,
425 state);
176eb98c
MS
426 else
427 ret =
c67ca4de
YQ
428 aarch64_handle_breakpoint (targ_type, addr, len, 0 /* is_insert */,
429 state);
176eb98c 430
60a191ed 431 if (show_debug_regs)
176eb98c
MS
432 aarch64_show_debug_reg_state (aarch64_get_debug_reg_state (),
433 "remove_point", addr, len, targ_type);
434
435 return ret;
436}
437
421530db 438/* Implementation of linux_target_ops method "stopped_data_address". */
176eb98c
MS
439
440static CORE_ADDR
441aarch64_stopped_data_address (void)
442{
443 siginfo_t siginfo;
444 int pid, i;
445 struct aarch64_debug_reg_state *state;
446
0bfdf32f 447 pid = lwpid_of (current_thread);
176eb98c
MS
448
449 /* Get the siginfo. */
450 if (ptrace (PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0)
451 return (CORE_ADDR) 0;
452
453 /* Need to be a hardware breakpoint/watchpoint trap. */
454 if (siginfo.si_signo != SIGTRAP
455 || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
456 return (CORE_ADDR) 0;
457
458 /* Check if the address matches any watched address. */
459 state = aarch64_get_debug_reg_state ();
460 for (i = aarch64_num_wp_regs - 1; i >= 0; --i)
461 {
462 const unsigned int len = aarch64_watchpoint_length (state->dr_ctrl_wp[i]);
463 const CORE_ADDR addr_trap = (CORE_ADDR) siginfo.si_addr;
464 const CORE_ADDR addr_watch = state->dr_addr_wp[i];
465 if (state->dr_ref_count_wp[i]
466 && DR_CONTROL_ENABLED (state->dr_ctrl_wp[i])
467 && addr_trap >= addr_watch
468 && addr_trap < addr_watch + len)
469 return addr_trap;
470 }
471
472 return (CORE_ADDR) 0;
473}
474
421530db 475/* Implementation of linux_target_ops method "stopped_by_watchpoint". */
176eb98c
MS
476
477static int
478aarch64_stopped_by_watchpoint (void)
479{
480 if (aarch64_stopped_data_address () != 0)
481 return 1;
482 else
483 return 0;
484}
485
486/* Fetch the thread-local storage pointer for libthread_db. */
487
488ps_err_e
55fac6e0 489ps_get_thread_area (const struct ps_prochandle *ph,
176eb98c
MS
490 lwpid_t lwpid, int idx, void **base)
491{
55fac6e0
MS
492 struct iovec iovec;
493 uint64_t reg;
494
495 iovec.iov_base = &reg;
496 iovec.iov_len = sizeof (reg);
497
498 if (ptrace (PTRACE_GETREGSET, lwpid, NT_ARM_TLS, &iovec) != 0)
176eb98c
MS
499 return PS_ERR;
500
501 /* IDX is the bias from the thread pointer to the beginning of the
502 thread descriptor. It has to be subtracted due to implementation
503 quirks in libthread_db. */
55fac6e0 504 *base = (void *) (reg - idx);
176eb98c
MS
505
506 return PS_OK;
507}
508
421530db 509/* Implementation of linux_target_ops method "linux_new_process". */
176eb98c
MS
510
511static struct arch_process_info *
512aarch64_linux_new_process (void)
513{
514 struct arch_process_info *info = xcalloc (1, sizeof (*info));
515
516 aarch64_init_debug_reg_state (&info->debug_reg_state);
517
518 return info;
519}
520
421530db 521/* Implementation of linux_target_ops method "linux_new_thread". */
176eb98c 522
34c703da
GB
523static void
524aarch64_linux_new_thread (struct lwp_info *lwp)
176eb98c
MS
525{
526 struct arch_lwp_info *info = xcalloc (1, sizeof (*info));
527
528 /* Mark that all the hardware breakpoint/watchpoint register pairs
529 for this thread need to be initialized (with data from
530 aarch_process_info.debug_reg_state). */
531 DR_MARK_ALL_CHANGED (info->dr_changed_bp, aarch64_num_bp_regs);
532 DR_MARK_ALL_CHANGED (info->dr_changed_wp, aarch64_num_wp_regs);
533
34c703da 534 lwp->arch_private = info;
176eb98c
MS
535}
536
421530db
PL
537/* Implementation of linux_target_ops method "linux_new_fork". */
538
3a8a0396
DB
539static void
540aarch64_linux_new_fork (struct process_info *parent,
541 struct process_info *child)
542{
543 /* These are allocated by linux_add_process. */
61a7418c
DB
544 gdb_assert (parent->priv != NULL
545 && parent->priv->arch_private != NULL);
546 gdb_assert (child->priv != NULL
547 && child->priv->arch_private != NULL);
3a8a0396
DB
548
549 /* Linux kernel before 2.6.33 commit
550 72f674d203cd230426437cdcf7dd6f681dad8b0d
551 will inherit hardware debug registers from parent
552 on fork/vfork/clone. Newer Linux kernels create such tasks with
553 zeroed debug registers.
554
555 GDB core assumes the child inherits the watchpoints/hw
556 breakpoints of the parent, and will remove them all from the
557 forked off process. Copy the debug registers mirrors into the
558 new process so that all breakpoints and watchpoints can be
559 removed together. The debug registers mirror will become zeroed
560 in the end before detaching the forked off process, thus making
561 this compatible with older Linux kernels too. */
562
61a7418c 563 *child->priv->arch_private = *parent->priv->arch_private;
3a8a0396
DB
564}
565
421530db
PL
566/* Implementation of linux_target_ops method "linux_prepare_to_resume".
567
176eb98c
MS
568 If the debug regs have changed, update the thread's copies. */
569
570static void
571aarch64_linux_prepare_to_resume (struct lwp_info *lwp)
572{
d86d4aaf
DE
573 struct thread_info *thread = get_lwp_thread (lwp);
574 ptid_t ptid = ptid_of (thread);
176eb98c
MS
575 struct arch_lwp_info *info = lwp->arch_private;
576
577 if (DR_HAS_CHANGED (info->dr_changed_bp)
578 || DR_HAS_CHANGED (info->dr_changed_wp))
579 {
580 int tid = ptid_get_lwp (ptid);
581 struct process_info *proc = find_process_pid (ptid_get_pid (ptid));
582 struct aarch64_debug_reg_state *state
fe978cb0 583 = &proc->priv->arch_private->debug_reg_state;
176eb98c 584
c5e92cca 585 if (show_debug_regs)
d86d4aaf 586 fprintf (stderr, "prepare_to_resume thread %ld\n", lwpid_of (thread));
176eb98c
MS
587
588 /* Watchpoints. */
589 if (DR_HAS_CHANGED (info->dr_changed_wp))
590 {
591 aarch64_linux_set_debug_regs (state, tid, 1);
592 DR_CLEAR_CHANGED (info->dr_changed_wp);
593 }
594
595 /* Breakpoints. */
596 if (DR_HAS_CHANGED (info->dr_changed_bp))
597 {
598 aarch64_linux_set_debug_regs (state, tid, 0);
599 DR_CLEAR_CHANGED (info->dr_changed_bp);
600 }
601 }
602}
603
3b53ae99
YQ
604/* Return the right target description according to the ELF file of
605 current thread. */
606
607static const struct target_desc *
608aarch64_linux_read_description (void)
609{
610 unsigned int machine;
611 int is_elf64;
612 int tid;
613
614 tid = lwpid_of (current_thread);
615
616 is_elf64 = linux_pid_exe_is_elf_64_file (tid, &machine);
617
618 if (is_elf64)
619 return tdesc_aarch64;
620 else
621 return tdesc_arm_with_neon;
622}
623
421530db
PL
624/* Implementation of linux_target_ops method "arch_setup". */
625
176eb98c
MS
626static void
627aarch64_arch_setup (void)
628{
3b53ae99 629 current_process ()->tdesc = aarch64_linux_read_description ();
176eb98c 630
af1b22f3 631 aarch64_linux_get_debug_reg_capacity (lwpid_of (current_thread));
176eb98c
MS
632}
633
3aee8918 634static struct regset_info aarch64_regsets[] =
176eb98c
MS
635{
636 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS,
637 sizeof (struct user_pt_regs), GENERAL_REGS,
638 aarch64_fill_gregset, aarch64_store_gregset },
639 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_FPREGSET,
640 sizeof (struct user_fpsimd_state), FP_REGS,
641 aarch64_fill_fpregset, aarch64_store_fpregset
642 },
643 { 0, 0, 0, -1, -1, NULL, NULL }
644};
645
3aee8918
PA
646static struct regsets_info aarch64_regsets_info =
647 {
648 aarch64_regsets, /* regsets */
649 0, /* num_regsets */
650 NULL, /* disabled_regsets */
651 };
652
3b53ae99 653static struct regs_info regs_info_aarch64 =
3aee8918
PA
654 {
655 NULL, /* regset_bitmap */
c2d65f38 656 NULL, /* usrregs */
3aee8918
PA
657 &aarch64_regsets_info,
658 };
659
421530db
PL
660/* Implementation of linux_target_ops method "regs_info". */
661
3aee8918
PA
662static const struct regs_info *
663aarch64_regs_info (void)
664{
3b53ae99
YQ
665 if (is_64bit_tdesc ())
666 return &regs_info_aarch64;
667 else
668 return &regs_info_aarch32;
3aee8918
PA
669}
670
7671bf47
PL
671/* Implementation of linux_target_ops method "supports_tracepoints". */
672
673static int
674aarch64_supports_tracepoints (void)
675{
524b57e6
YQ
676 if (current_thread == NULL)
677 return 1;
678 else
679 {
680 /* We don't support tracepoints on aarch32 now. */
681 return is_64bit_tdesc ();
682 }
7671bf47
PL
683}
684
d1d0aea1
PL
685/* Implementation of linux_target_ops method "supports_range_stepping". */
686
687static int
688aarch64_supports_range_stepping (void)
689{
690 return 1;
691}
692
176eb98c
MS
693struct linux_target_ops the_low_target =
694{
695 aarch64_arch_setup,
3aee8918 696 aarch64_regs_info,
176eb98c
MS
697 aarch64_cannot_fetch_register,
698 aarch64_cannot_store_register,
421530db 699 NULL, /* fetch_register */
176eb98c
MS
700 aarch64_get_pc,
701 aarch64_set_pc,
702 (const unsigned char *) &aarch64_breakpoint,
703 aarch64_breakpoint_len,
421530db
PL
704 NULL, /* breakpoint_reinsert_addr */
705 0, /* decr_pc_after_break */
176eb98c 706 aarch64_breakpoint_at,
802e8e6d 707 aarch64_supports_z_point_type,
176eb98c
MS
708 aarch64_insert_point,
709 aarch64_remove_point,
710 aarch64_stopped_by_watchpoint,
711 aarch64_stopped_data_address,
421530db
PL
712 NULL, /* collect_ptrace_register */
713 NULL, /* supply_ptrace_register */
714 NULL, /* siginfo_fixup */
176eb98c
MS
715 aarch64_linux_new_process,
716 aarch64_linux_new_thread,
3a8a0396 717 aarch64_linux_new_fork,
176eb98c 718 aarch64_linux_prepare_to_resume,
421530db 719 NULL, /* process_qsupported */
7671bf47 720 aarch64_supports_tracepoints,
d1d0aea1
PL
721 NULL, /* get_thread_area */
722 NULL, /* install_fast_tracepoint_jump_pad */
723 NULL, /* emit_ops */
724 NULL, /* get_min_fast_tracepoint_insn_len */
725 aarch64_supports_range_stepping,
176eb98c 726};
3aee8918
PA
727
728void
729initialize_low_arch (void)
730{
731 init_registers_aarch64 ();
732
3b53ae99
YQ
733 initialize_low_arch_aarch32 ();
734
3aee8918
PA
735 initialize_regsets_info (&aarch64_regsets_info);
736}
This page took 0.263243 seconds and 4 git commands to generate.