1 /* Target-dependent code for GNU/Linux AArch64.
3 Copyright (C) 2009-2018 Free Software Foundation, Inc.
4 Contributed by ARM Ltd.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "arch-utils.h"
25 #include "glibc-tdep.h"
26 #include "linux-tdep.h"
27 #include "aarch64-tdep.h"
28 #include "aarch64-linux-tdep.h"
30 #include "solib-svr4.h"
32 #include "tramp-frame.h"
33 #include "trad-frame.h"
39 #include "cli/cli-utils.h"
40 #include "stap-probe.h"
41 #include "parser-defs.h"
42 #include "user-regs.h"
43 #include "xml-syscall.h"
46 #include "record-full.h"
47 #include "linux-record.h"
49 #include "elf/common.h"
51 /* Signal frame handling.
66 | | | SIGTRAMP_FRAME (struct rt_sigframe)
68 +--| saved sp |--> interrupted_sp
69 | | saved pc |--> interrupted_pc
72 | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
78 On signal delivery, the kernel will create a signal handler stack
79 frame and setup the return address in LR to point at restorer stub.
80 The signal stack frame is defined by:
88 The ucontext has the following form:
91 unsigned long uc_flags;
92 struct ucontext *uc_link;
95 struct sigcontext uc_mcontext;
100 unsigned long fault_address;
101 unsigned long regs[31];
102 unsigned long sp; / * 31 * /
103 unsigned long pc; / * 32 * /
104 unsigned long pstate; / * 33 * /
105 __u8 __reserved[4096]
108 The reserved space in sigcontext contains additional structures, each starting
109 with a aarch64_ctx, which specifies a unique identifier and the total size of
110 the structure. The final structure in reserved will start will a null
111 aarch64_ctx. The penultimate entry in reserved may be a extra_context which
112 then points to a further block of reserved space.
119 The restorer stub will always have the form:
121 d28015a8 movz x8, #0xad
124 This is a system call sys_rt_sigreturn.
126 We detect signal frames by snooping the return code for the restorer
127 instruction sequence.
129 The handler then needs to recover the saved register set from
130 ucontext.uc_mcontext. */
132 /* These magic numbers need to reflect the layout of the kernel
133 defined struct rt_sigframe and ucontext. */
134 #define AARCH64_SIGCONTEXT_REG_SIZE 8
135 #define AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET 128
136 #define AARCH64_UCONTEXT_SIGCONTEXT_OFFSET 176
137 #define AARCH64_SIGCONTEXT_XO_OFFSET 8
138 #define AARCH64_SIGCONTEXT_RESERVED_OFFSET 288
140 #define AARCH64_SIGCONTEXT_RESERVED_SIZE 4096
142 /* Unique identifiers that may be used for aarch64_ctx.magic. */
143 #define AARCH64_EXTRA_MAGIC 0x45585401
144 #define AARCH64_FPSIMD_MAGIC 0x46508001
145 #define AARCH64_SVE_MAGIC 0x53564501
147 /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC. */
148 #define AARCH64_EXTRA_DATAP_OFFSET 8
150 /* Defines for the fpsimd that follows an AARCH64_FPSIMD_MAGIC. */
151 #define AARCH64_FPSIMD_FPSR_OFFSET 8
152 #define AARCH64_FPSIMD_FPCR_OFFSET 12
153 #define AARCH64_FPSIMD_V0_OFFSET 16
154 #define AARCH64_FPSIMD_VREG_SIZE 16
156 /* Defines for the sve structure that follows an AARCH64_SVE_MAGIC. */
157 #define AARCH64_SVE_CONTEXT_VL_OFFSET 8
158 #define AARCH64_SVE_CONTEXT_REGS_OFFSET 16
159 #define AARCH64_SVE_CONTEXT_P_REGS_OFFSET(vq) (32 * vq * 16)
160 #define AARCH64_SVE_CONTEXT_FFR_OFFSET(vq) \
161 (AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq) + (16 * vq * 2))
162 #define AARCH64_SVE_CONTEXT_SIZE(vq) \
163 (AARCH64_SVE_CONTEXT_FFR_OFFSET (vq) + (vq * 2))
166 /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the
167 size, or return 0 on error. */
170 read_aarch64_ctx (CORE_ADDR ctx_addr, enum bfd_endian byte_order,
176 if (target_read_memory (ctx_addr, buf, 4) != 0)
178 magic = extract_unsigned_integer (buf, 4, byte_order);
180 if (target_read_memory (ctx_addr + 4, buf, 4) != 0)
182 *size = extract_unsigned_integer (buf, 4, byte_order);
187 /* Implement the "init" method of struct tramp_frame. */
190 aarch64_linux_sigframe_init (const struct tramp_frame *self,
191 struct frame_info *this_frame,
192 struct trad_frame_cache *this_cache,
195 struct gdbarch *gdbarch = get_frame_arch (this_frame);
196 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
197 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
198 CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
199 CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
200 + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
201 CORE_ADDR section = sigcontext_addr + AARCH64_SIGCONTEXT_RESERVED_OFFSET;
202 CORE_ADDR section_end = section + AARCH64_SIGCONTEXT_RESERVED_SIZE;
203 CORE_ADDR fpsimd = 0;
204 CORE_ADDR sve_regs = 0;
205 uint32_t size, magic;
206 bool extra_found = false;
207 int num_regs = gdbarch_num_regs (gdbarch);
209 /* Read in the integer registers. */
211 for (int i = 0; i < 31; i++)
213 trad_frame_set_reg_addr (this_cache,
214 AARCH64_X0_REGNUM + i,
215 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
216 + i * AARCH64_SIGCONTEXT_REG_SIZE);
218 trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM,
219 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
220 + 31 * AARCH64_SIGCONTEXT_REG_SIZE);
221 trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM,
222 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
223 + 32 * AARCH64_SIGCONTEXT_REG_SIZE);
225 /* Search for the FP and SVE sections, stopping at null. */
226 while ((magic = read_aarch64_ctx (section, byte_order, &size)) != 0
231 case AARCH64_FPSIMD_MAGIC:
236 case AARCH64_SVE_MAGIC:
238 /* Check if the section is followed by a full SVE dump, and set
239 sve_regs if it is. */
243 if (!tdep->has_sve ())
246 if (target_read_memory (section + AARCH64_SVE_CONTEXT_VL_OFFSET,
252 vq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, byte_order));
255 error (_("Invalid vector length in signal frame %d vs %s."), vq,
256 pulongest (tdep->vq));
258 if (size >= AARCH64_SVE_CONTEXT_SIZE (vq))
259 sve_regs = section + AARCH64_SVE_CONTEXT_REGS_OFFSET;
265 case AARCH64_EXTRA_MAGIC:
267 /* Extra is always the last valid section in reserved and points to
268 an additional block of memory filled with more sections. Reset
269 the address to the extra section and continue looking for more
273 if (target_read_memory (section + AARCH64_EXTRA_DATAP_OFFSET,
280 section = extract_unsigned_integer (buf, 8, byte_order);
290 /* Prevent searching past the end of the reserved section. The extra
291 section does not have a hard coded limit - we have to rely on it ending
293 if (!extra_found && section > section_end)
301 for (int i = 0; i < 32; i++)
303 offset = sve_regs + (i * tdep->vq * 16);
304 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_Z0_REGNUM + i,
306 trad_frame_set_reg_addr (this_cache,
307 num_regs + AARCH64_SVE_V0_REGNUM + i,
309 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_Q0_REGNUM + i,
311 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_D0_REGNUM + i,
313 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_S0_REGNUM + i,
315 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_H0_REGNUM + i,
317 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_B0_REGNUM + i,
321 offset = sve_regs + AARCH64_SVE_CONTEXT_P_REGS_OFFSET (tdep->vq);
322 for (int i = 0; i < 16; i++)
323 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_P0_REGNUM + i,
324 offset + (i * tdep->vq * 2));
326 offset = sve_regs + AARCH64_SVE_CONTEXT_FFR_OFFSET (tdep->vq);
327 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_FFR_REGNUM, offset);
332 trad_frame_set_reg_addr (this_cache, AARCH64_FPSR_REGNUM,
333 fpsimd + AARCH64_FPSIMD_FPSR_OFFSET);
334 trad_frame_set_reg_addr (this_cache, AARCH64_FPCR_REGNUM,
335 fpsimd + AARCH64_FPSIMD_FPCR_OFFSET);
337 /* If there was no SVE section then set up the V registers. */
339 for (int i = 0; i < 32; i++)
341 CORE_ADDR offset = (fpsimd + AARCH64_FPSIMD_V0_OFFSET
342 + (i * AARCH64_FPSIMD_VREG_SIZE));
344 trad_frame_set_reg_addr (this_cache, AARCH64_V0_REGNUM + i, offset);
345 trad_frame_set_reg_addr (this_cache,
346 num_regs + AARCH64_Q0_REGNUM + i, offset);
347 trad_frame_set_reg_addr (this_cache,
348 num_regs + AARCH64_D0_REGNUM + i, offset);
349 trad_frame_set_reg_addr (this_cache,
350 num_regs + AARCH64_S0_REGNUM + i, offset);
351 trad_frame_set_reg_addr (this_cache,
352 num_regs + AARCH64_H0_REGNUM + i, offset);
353 trad_frame_set_reg_addr (this_cache,
354 num_regs + AARCH64_B0_REGNUM + i, offset);
355 if (tdep->has_sve ())
356 trad_frame_set_reg_addr (this_cache,
357 num_regs + AARCH64_SVE_V0_REGNUM + i,
362 trad_frame_set_id (this_cache, frame_id_build (sp, func));
365 static const struct tramp_frame aarch64_linux_rt_sigframe =
370 /* movz x8, 0x8b (S=1,o=10,h=0,i=0x8b,r=8)
371 Soo1 0010 1hhi iiii iiii iiii iiir rrrr */
372 {0xd2801168, ULONGEST_MAX},
374 /* svc 0x0 (o=0, l=1)
375 1101 0100 oooi iiii iiii iiii iii0 00ll */
376 {0xd4000001, ULONGEST_MAX},
377 {TRAMP_SENTINEL_INSN, ULONGEST_MAX}
379 aarch64_linux_sigframe_init
384 static const struct regcache_map_entry aarch64_linux_gregmap[] =
386 { 31, AARCH64_X0_REGNUM, 8 }, /* x0 ... x30 */
387 { 1, AARCH64_SP_REGNUM, 8 },
388 { 1, AARCH64_PC_REGNUM, 8 },
389 { 1, AARCH64_CPSR_REGNUM, 8 },
393 static const struct regcache_map_entry aarch64_linux_fpregmap[] =
395 { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */
396 { 1, AARCH64_FPSR_REGNUM, 4 },
397 { 1, AARCH64_FPCR_REGNUM, 4 },
401 /* Register set definitions. */
403 const struct regset aarch64_linux_gregset =
405 aarch64_linux_gregmap,
406 regcache_supply_regset, regcache_collect_regset
409 const struct regset aarch64_linux_fpregset =
411 aarch64_linux_fpregmap,
412 regcache_supply_regset, regcache_collect_regset
415 /* The fields in an SVE header at the start of a SVE regset. */
417 #define SVE_HEADER_SIZE_LENGTH 4
418 #define SVE_HEADER_MAX_SIZE_LENGTH 4
419 #define SVE_HEADER_VL_LENGTH 2
420 #define SVE_HEADER_MAX_VL_LENGTH 2
421 #define SVE_HEADER_FLAGS_LENGTH 2
422 #define SVE_HEADER_RESERVED_LENGTH 2
424 #define SVE_HEADER_SIZE_OFFSET 0
425 #define SVE_HEADER_MAX_SIZE_OFFSET \
426 (SVE_HEADER_SIZE_OFFSET + SVE_HEADER_SIZE_LENGTH)
427 #define SVE_HEADER_VL_OFFSET \
428 (SVE_HEADER_MAX_SIZE_OFFSET + SVE_HEADER_MAX_SIZE_LENGTH)
429 #define SVE_HEADER_MAX_VL_OFFSET \
430 (SVE_HEADER_VL_OFFSET + SVE_HEADER_VL_LENGTH)
431 #define SVE_HEADER_FLAGS_OFFSET \
432 (SVE_HEADER_MAX_VL_OFFSET + SVE_HEADER_MAX_VL_LENGTH)
433 #define SVE_HEADER_RESERVED_OFFSET \
434 (SVE_HEADER_FLAGS_OFFSET + SVE_HEADER_FLAGS_LENGTH)
435 #define SVE_HEADER_SIZE \
436 (SVE_HEADER_RESERVED_OFFSET + SVE_HEADER_RESERVED_LENGTH)
438 #define SVE_HEADER_FLAG_SVE 1
440 /* Get VQ value from SVE section in the core dump. */
443 aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd)
445 gdb_byte header[SVE_HEADER_SIZE];
446 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
447 asection *sve_section = bfd_get_section_by_name (abfd, ".reg-aarch-sve");
449 if (sve_section == nullptr)
455 size_t size = bfd_section_size (abfd, sve_section);
457 /* Check extended state size. */
458 if (size < SVE_HEADER_SIZE)
460 warning (_("'.reg-aarch-sve' section in core file too small."));
464 if (!bfd_get_section_contents (abfd, sve_section, header, 0, SVE_HEADER_SIZE))
466 warning (_("Couldn't read sve header from "
467 "'.reg-aarch-sve' section in core file."));
471 uint64_t vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
472 SVE_HEADER_VL_LENGTH, byte_order);
473 uint64_t vq = sve_vq_from_vl (vl);
475 if (vq > AARCH64_MAX_SVE_VQ)
477 warning (_("SVE Vector length in core file not supported by this version"
478 " of GDB. (VQ=%s)"), pulongest (vq));
483 warning (_("SVE Vector length in core file is invalid. (VQ=%s"),
491 /* Supply register REGNUM from BUF to REGCACHE, using the register map
492 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
493 If BUF is NULL, set the registers to "unavailable" status. */
496 aarch64_linux_supply_sve_regset (const struct regset *regset,
497 struct regcache *regcache,
498 int regnum, const void *buf, size_t size)
500 gdb_byte *header = (gdb_byte *) buf;
501 struct gdbarch *gdbarch = regcache->arch ();
502 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
505 return regcache->supply_regset (regset, regnum, nullptr, size);
506 gdb_assert (size > SVE_HEADER_SIZE);
508 /* BUF contains an SVE header followed by a register dump of either the
509 passed in SVE regset or a NEON fpregset. */
511 /* Extract required fields from the header. */
512 ULONGEST vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
513 SVE_HEADER_VL_LENGTH, byte_order);
514 uint16_t flags = extract_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET,
515 SVE_HEADER_FLAGS_LENGTH,
518 if (regnum == -1 || regnum == AARCH64_SVE_VG_REGNUM)
520 gdb_byte vg_target[8];
521 store_integer ((gdb_byte *)&vg_target, sizeof (uint64_t), byte_order,
522 sve_vg_from_vl (vl));
523 regcache->raw_supply (AARCH64_SVE_VG_REGNUM, &vg_target);
526 if (flags & SVE_HEADER_FLAG_SVE)
528 /* Register dump is a SVE structure. */
529 regcache->supply_regset (regset, regnum,
530 (gdb_byte *) buf + SVE_HEADER_SIZE,
531 size - SVE_HEADER_SIZE);
535 /* Register dump is a fpsimd structure. First clear the SVE
537 for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++)
538 regcache->raw_supply_zeroed (AARCH64_SVE_Z0_REGNUM + i);
539 for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++)
540 regcache->raw_supply_zeroed (AARCH64_SVE_P0_REGNUM + i);
541 regcache->raw_supply_zeroed (AARCH64_SVE_FFR_REGNUM);
543 /* Then supply the fpsimd registers. */
544 regcache->supply_regset (&aarch64_linux_fpregset, regnum,
545 (gdb_byte *) buf + SVE_HEADER_SIZE,
546 size - SVE_HEADER_SIZE);
550 /* Collect register REGNUM from REGCACHE to BUF, using the register
551 map in REGSET. If REGNUM is -1, do this for all registers in
555 aarch64_linux_collect_sve_regset (const struct regset *regset,
556 const struct regcache *regcache,
557 int regnum, void *buf, size_t size)
559 gdb_byte *header = (gdb_byte *) buf;
560 struct gdbarch *gdbarch = regcache->arch ();
561 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
562 uint64_t vq = gdbarch_tdep (gdbarch)->vq;
564 gdb_assert (buf != NULL);
565 gdb_assert (size > SVE_HEADER_SIZE);
567 /* BUF starts with a SVE header prior to the register dump. */
569 store_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET,
570 SVE_HEADER_SIZE_LENGTH, byte_order, size);
571 store_unsigned_integer (header + SVE_HEADER_MAX_SIZE_OFFSET,
572 SVE_HEADER_MAX_SIZE_LENGTH, byte_order, size);
573 store_unsigned_integer (header + SVE_HEADER_VL_OFFSET, SVE_HEADER_VL_LENGTH,
574 byte_order, sve_vl_from_vq (vq));
575 store_unsigned_integer (header + SVE_HEADER_MAX_VL_OFFSET,
576 SVE_HEADER_MAX_VL_LENGTH, byte_order,
577 sve_vl_from_vq (vq));
578 store_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET,
579 SVE_HEADER_FLAGS_LENGTH, byte_order,
580 SVE_HEADER_FLAG_SVE);
581 store_unsigned_integer (header + SVE_HEADER_RESERVED_OFFSET,
582 SVE_HEADER_RESERVED_LENGTH, byte_order, 0);
584 /* The SVE register dump follows. */
585 regcache->collect_regset (regset, regnum, (gdb_byte *) buf + SVE_HEADER_SIZE,
586 size - SVE_HEADER_SIZE);
589 /* Implement the "regset_from_core_section" gdbarch method. */
592 aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
593 iterate_over_regset_sections_cb *cb,
595 const struct regcache *regcache)
597 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
599 cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
600 &aarch64_linux_gregset, NULL, cb_data);
602 if (tdep->has_sve ())
604 /* Create this on the fly in order to handle vector register sizes. */
605 const struct regcache_map_entry sve_regmap[] =
607 { 32, AARCH64_SVE_Z0_REGNUM, (int) (tdep->vq * 16) },
608 { 16, AARCH64_SVE_P0_REGNUM, (int) (tdep->vq * 16 / 8) },
609 { 1, AARCH64_SVE_FFR_REGNUM, 4 },
610 { 1, AARCH64_FPSR_REGNUM, 4 },
611 { 1, AARCH64_FPCR_REGNUM, 4 },
615 const struct regset aarch64_linux_sve_regset =
618 aarch64_linux_supply_sve_regset, aarch64_linux_collect_sve_regset,
622 cb (".reg-aarch-sve",
623 SVE_HEADER_SIZE + regcache_map_entry_size (aarch64_linux_fpregmap),
624 SVE_HEADER_SIZE + regcache_map_entry_size (sve_regmap),
625 &aarch64_linux_sve_regset, "SVE registers", cb_data);
628 cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, AARCH64_LINUX_SIZEOF_FPREGSET,
629 &aarch64_linux_fpregset, NULL, cb_data);
632 /* Implement the "core_read_description" gdbarch method. */
634 static const struct target_desc *
635 aarch64_linux_core_read_description (struct gdbarch *gdbarch,
636 struct target_ops *target, bfd *abfd)
638 CORE_ADDR aarch64_hwcap = 0;
640 if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) != 1)
643 return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd));
646 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
650 aarch64_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
652 return (*s == '#' || isdigit (*s) /* Literal number. */
653 || *s == '[' /* Register indirection. */
654 || isalpha (*s)); /* Register value. */
657 /* This routine is used to parse a special token in AArch64's assembly.
659 The special tokens parsed by it are:
661 - Register displacement (e.g, [fp, #-8])
663 It returns one if the special token has been parsed successfully,
664 or zero if the current token is not considered special. */
667 aarch64_stap_parse_special_token (struct gdbarch *gdbarch,
668 struct stap_parse_info *p)
672 /* Temporary holder for lookahead. */
673 const char *tmp = p->arg;
675 /* Used to save the register name. */
687 while (isalnum (*tmp))
694 regname = (char *) alloca (len + 2);
696 strncpy (regname, start, len);
699 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
700 error (_("Invalid register name `%s' on expression `%s'."),
701 regname, p->saved_arg);
704 tmp = skip_spaces (tmp);
705 /* Now we expect a number. It can begin with '#' or simply
715 else if (*tmp == '+')
721 displacement = strtol (tmp, &endp, 10);
724 /* Skipping last `]'. */
728 /* The displacement. */
729 write_exp_elt_opcode (&p->pstate, OP_LONG);
730 write_exp_elt_type (&p->pstate, builtin_type (gdbarch)->builtin_long);
731 write_exp_elt_longcst (&p->pstate, displacement);
732 write_exp_elt_opcode (&p->pstate, OP_LONG);
734 write_exp_elt_opcode (&p->pstate, UNOP_NEG);
736 /* The register name. */
737 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
740 write_exp_string (&p->pstate, str);
741 write_exp_elt_opcode (&p->pstate, OP_REGISTER);
743 write_exp_elt_opcode (&p->pstate, BINOP_ADD);
745 /* Casting to the expected type. */
746 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
747 write_exp_elt_type (&p->pstate, lookup_pointer_type (p->arg_type));
748 write_exp_elt_opcode (&p->pstate, UNOP_CAST);
750 write_exp_elt_opcode (&p->pstate, UNOP_IND);
760 /* Implement the "get_syscall_number" gdbarch method. */
763 aarch64_linux_get_syscall_number (struct gdbarch *gdbarch,
766 struct regcache *regs = get_thread_regcache (thread);
767 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
769 /* The content of register x8. */
770 gdb_byte buf[X_REGISTER_SIZE];
774 /* Getting the system call number from the register x8. */
775 regs->cooked_read (AARCH64_DWARF_X0 + 8, buf);
777 ret = extract_signed_integer (buf, X_REGISTER_SIZE, byte_order);
782 /* AArch64 process record-replay constructs: syscall, signal etc. */
784 struct linux_record_tdep aarch64_linux_record_tdep;
786 /* Enum that defines the AArch64 linux specific syscall identifiers used for
787 process record/replay. */
789 enum aarch64_syscall {
790 aarch64_sys_io_setup = 0,
791 aarch64_sys_io_destroy = 1,
792 aarch64_sys_io_submit = 2,
793 aarch64_sys_io_cancel = 3,
794 aarch64_sys_io_getevents = 4,
795 aarch64_sys_setxattr = 5,
796 aarch64_sys_lsetxattr = 6,
797 aarch64_sys_fsetxattr = 7,
798 aarch64_sys_getxattr = 8,
799 aarch64_sys_lgetxattr = 9,
800 aarch64_sys_fgetxattr = 10,
801 aarch64_sys_listxattr = 11,
802 aarch64_sys_llistxattr = 12,
803 aarch64_sys_flistxattr = 13,
804 aarch64_sys_removexattr = 14,
805 aarch64_sys_lremovexattr = 15,
806 aarch64_sys_fremovexattr = 16,
807 aarch64_sys_getcwd = 17,
808 aarch64_sys_lookup_dcookie = 18,
809 aarch64_sys_eventfd2 = 19,
810 aarch64_sys_epoll_create1 = 20,
811 aarch64_sys_epoll_ctl = 21,
812 aarch64_sys_epoll_pwait = 22,
813 aarch64_sys_dup = 23,
814 aarch64_sys_dup3 = 24,
815 aarch64_sys_fcntl = 25,
816 aarch64_sys_inotify_init1 = 26,
817 aarch64_sys_inotify_add_watch = 27,
818 aarch64_sys_inotify_rm_watch = 28,
819 aarch64_sys_ioctl = 29,
820 aarch64_sys_ioprio_set = 30,
821 aarch64_sys_ioprio_get = 31,
822 aarch64_sys_flock = 32,
823 aarch64_sys_mknodat = 33,
824 aarch64_sys_mkdirat = 34,
825 aarch64_sys_unlinkat = 35,
826 aarch64_sys_symlinkat = 36,
827 aarch64_sys_linkat = 37,
828 aarch64_sys_renameat = 38,
829 aarch64_sys_umount2 = 39,
830 aarch64_sys_mount = 40,
831 aarch64_sys_pivot_root = 41,
832 aarch64_sys_nfsservctl = 42,
833 aarch64_sys_statfs = 43,
834 aarch64_sys_fstatfs = 44,
835 aarch64_sys_truncate = 45,
836 aarch64_sys_ftruncate = 46,
837 aarch64_sys_fallocate = 47,
838 aarch64_sys_faccessat = 48,
839 aarch64_sys_chdir = 49,
840 aarch64_sys_fchdir = 50,
841 aarch64_sys_chroot = 51,
842 aarch64_sys_fchmod = 52,
843 aarch64_sys_fchmodat = 53,
844 aarch64_sys_fchownat = 54,
845 aarch64_sys_fchown = 55,
846 aarch64_sys_openat = 56,
847 aarch64_sys_close = 57,
848 aarch64_sys_vhangup = 58,
849 aarch64_sys_pipe2 = 59,
850 aarch64_sys_quotactl = 60,
851 aarch64_sys_getdents64 = 61,
852 aarch64_sys_lseek = 62,
853 aarch64_sys_read = 63,
854 aarch64_sys_write = 64,
855 aarch64_sys_readv = 65,
856 aarch64_sys_writev = 66,
857 aarch64_sys_pread64 = 67,
858 aarch64_sys_pwrite64 = 68,
859 aarch64_sys_preadv = 69,
860 aarch64_sys_pwritev = 70,
861 aarch64_sys_sendfile = 71,
862 aarch64_sys_pselect6 = 72,
863 aarch64_sys_ppoll = 73,
864 aarch64_sys_signalfd4 = 74,
865 aarch64_sys_vmsplice = 75,
866 aarch64_sys_splice = 76,
867 aarch64_sys_tee = 77,
868 aarch64_sys_readlinkat = 78,
869 aarch64_sys_newfstatat = 79,
870 aarch64_sys_fstat = 80,
871 aarch64_sys_sync = 81,
872 aarch64_sys_fsync = 82,
873 aarch64_sys_fdatasync = 83,
874 aarch64_sys_sync_file_range2 = 84,
875 aarch64_sys_sync_file_range = 84,
876 aarch64_sys_timerfd_create = 85,
877 aarch64_sys_timerfd_settime = 86,
878 aarch64_sys_timerfd_gettime = 87,
879 aarch64_sys_utimensat = 88,
880 aarch64_sys_acct = 89,
881 aarch64_sys_capget = 90,
882 aarch64_sys_capset = 91,
883 aarch64_sys_personality = 92,
884 aarch64_sys_exit = 93,
885 aarch64_sys_exit_group = 94,
886 aarch64_sys_waitid = 95,
887 aarch64_sys_set_tid_address = 96,
888 aarch64_sys_unshare = 97,
889 aarch64_sys_futex = 98,
890 aarch64_sys_set_robust_list = 99,
891 aarch64_sys_get_robust_list = 100,
892 aarch64_sys_nanosleep = 101,
893 aarch64_sys_getitimer = 102,
894 aarch64_sys_setitimer = 103,
895 aarch64_sys_kexec_load = 104,
896 aarch64_sys_init_module = 105,
897 aarch64_sys_delete_module = 106,
898 aarch64_sys_timer_create = 107,
899 aarch64_sys_timer_gettime = 108,
900 aarch64_sys_timer_getoverrun = 109,
901 aarch64_sys_timer_settime = 110,
902 aarch64_sys_timer_delete = 111,
903 aarch64_sys_clock_settime = 112,
904 aarch64_sys_clock_gettime = 113,
905 aarch64_sys_clock_getres = 114,
906 aarch64_sys_clock_nanosleep = 115,
907 aarch64_sys_syslog = 116,
908 aarch64_sys_ptrace = 117,
909 aarch64_sys_sched_setparam = 118,
910 aarch64_sys_sched_setscheduler = 119,
911 aarch64_sys_sched_getscheduler = 120,
912 aarch64_sys_sched_getparam = 121,
913 aarch64_sys_sched_setaffinity = 122,
914 aarch64_sys_sched_getaffinity = 123,
915 aarch64_sys_sched_yield = 124,
916 aarch64_sys_sched_get_priority_max = 125,
917 aarch64_sys_sched_get_priority_min = 126,
918 aarch64_sys_sched_rr_get_interval = 127,
919 aarch64_sys_kill = 129,
920 aarch64_sys_tkill = 130,
921 aarch64_sys_tgkill = 131,
922 aarch64_sys_sigaltstack = 132,
923 aarch64_sys_rt_sigsuspend = 133,
924 aarch64_sys_rt_sigaction = 134,
925 aarch64_sys_rt_sigprocmask = 135,
926 aarch64_sys_rt_sigpending = 136,
927 aarch64_sys_rt_sigtimedwait = 137,
928 aarch64_sys_rt_sigqueueinfo = 138,
929 aarch64_sys_rt_sigreturn = 139,
930 aarch64_sys_setpriority = 140,
931 aarch64_sys_getpriority = 141,
932 aarch64_sys_reboot = 142,
933 aarch64_sys_setregid = 143,
934 aarch64_sys_setgid = 144,
935 aarch64_sys_setreuid = 145,
936 aarch64_sys_setuid = 146,
937 aarch64_sys_setresuid = 147,
938 aarch64_sys_getresuid = 148,
939 aarch64_sys_setresgid = 149,
940 aarch64_sys_getresgid = 150,
941 aarch64_sys_setfsuid = 151,
942 aarch64_sys_setfsgid = 152,
943 aarch64_sys_times = 153,
944 aarch64_sys_setpgid = 154,
945 aarch64_sys_getpgid = 155,
946 aarch64_sys_getsid = 156,
947 aarch64_sys_setsid = 157,
948 aarch64_sys_getgroups = 158,
949 aarch64_sys_setgroups = 159,
950 aarch64_sys_uname = 160,
951 aarch64_sys_sethostname = 161,
952 aarch64_sys_setdomainname = 162,
953 aarch64_sys_getrlimit = 163,
954 aarch64_sys_setrlimit = 164,
955 aarch64_sys_getrusage = 165,
956 aarch64_sys_umask = 166,
957 aarch64_sys_prctl = 167,
958 aarch64_sys_getcpu = 168,
959 aarch64_sys_gettimeofday = 169,
960 aarch64_sys_settimeofday = 170,
961 aarch64_sys_adjtimex = 171,
962 aarch64_sys_getpid = 172,
963 aarch64_sys_getppid = 173,
964 aarch64_sys_getuid = 174,
965 aarch64_sys_geteuid = 175,
966 aarch64_sys_getgid = 176,
967 aarch64_sys_getegid = 177,
968 aarch64_sys_gettid = 178,
969 aarch64_sys_sysinfo = 179,
970 aarch64_sys_mq_open = 180,
971 aarch64_sys_mq_unlink = 181,
972 aarch64_sys_mq_timedsend = 182,
973 aarch64_sys_mq_timedreceive = 183,
974 aarch64_sys_mq_notify = 184,
975 aarch64_sys_mq_getsetattr = 185,
976 aarch64_sys_msgget = 186,
977 aarch64_sys_msgctl = 187,
978 aarch64_sys_msgrcv = 188,
979 aarch64_sys_msgsnd = 189,
980 aarch64_sys_semget = 190,
981 aarch64_sys_semctl = 191,
982 aarch64_sys_semtimedop = 192,
983 aarch64_sys_semop = 193,
984 aarch64_sys_shmget = 194,
985 aarch64_sys_shmctl = 195,
986 aarch64_sys_shmat = 196,
987 aarch64_sys_shmdt = 197,
988 aarch64_sys_socket = 198,
989 aarch64_sys_socketpair = 199,
990 aarch64_sys_bind = 200,
991 aarch64_sys_listen = 201,
992 aarch64_sys_accept = 202,
993 aarch64_sys_connect = 203,
994 aarch64_sys_getsockname = 204,
995 aarch64_sys_getpeername = 205,
996 aarch64_sys_sendto = 206,
997 aarch64_sys_recvfrom = 207,
998 aarch64_sys_setsockopt = 208,
999 aarch64_sys_getsockopt = 209,
1000 aarch64_sys_shutdown = 210,
1001 aarch64_sys_sendmsg = 211,
1002 aarch64_sys_recvmsg = 212,
1003 aarch64_sys_readahead = 213,
1004 aarch64_sys_brk = 214,
1005 aarch64_sys_munmap = 215,
1006 aarch64_sys_mremap = 216,
1007 aarch64_sys_add_key = 217,
1008 aarch64_sys_request_key = 218,
1009 aarch64_sys_keyctl = 219,
1010 aarch64_sys_clone = 220,
1011 aarch64_sys_execve = 221,
1012 aarch64_sys_mmap = 222,
1013 aarch64_sys_fadvise64 = 223,
1014 aarch64_sys_swapon = 224,
1015 aarch64_sys_swapoff = 225,
1016 aarch64_sys_mprotect = 226,
1017 aarch64_sys_msync = 227,
1018 aarch64_sys_mlock = 228,
1019 aarch64_sys_munlock = 229,
1020 aarch64_sys_mlockall = 230,
1021 aarch64_sys_munlockall = 231,
1022 aarch64_sys_mincore = 232,
1023 aarch64_sys_madvise = 233,
1024 aarch64_sys_remap_file_pages = 234,
1025 aarch64_sys_mbind = 235,
1026 aarch64_sys_get_mempolicy = 236,
1027 aarch64_sys_set_mempolicy = 237,
1028 aarch64_sys_migrate_pages = 238,
1029 aarch64_sys_move_pages = 239,
1030 aarch64_sys_rt_tgsigqueueinfo = 240,
1031 aarch64_sys_perf_event_open = 241,
1032 aarch64_sys_accept4 = 242,
1033 aarch64_sys_recvmmsg = 243,
1034 aarch64_sys_wait4 = 260,
1035 aarch64_sys_prlimit64 = 261,
1036 aarch64_sys_fanotify_init = 262,
1037 aarch64_sys_fanotify_mark = 263,
1038 aarch64_sys_name_to_handle_at = 264,
1039 aarch64_sys_open_by_handle_at = 265,
1040 aarch64_sys_clock_adjtime = 266,
1041 aarch64_sys_syncfs = 267,
1042 aarch64_sys_setns = 268,
1043 aarch64_sys_sendmmsg = 269,
1044 aarch64_sys_process_vm_readv = 270,
1045 aarch64_sys_process_vm_writev = 271,
1046 aarch64_sys_kcmp = 272,
1047 aarch64_sys_finit_module = 273,
1048 aarch64_sys_sched_setattr = 274,
1049 aarch64_sys_sched_getattr = 275,
1052 /* aarch64_canonicalize_syscall maps syscall ids from the native AArch64
1053 linux set of syscall ids into a canonical set of syscall ids used by
1056 static enum gdb_syscall
1057 aarch64_canonicalize_syscall (enum aarch64_syscall syscall_number)
1059 #define SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
1060 return gdb_sys_##SYSCALL
1062 #define UNSUPPORTED_SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
1063 return gdb_sys_no_syscall
1065 switch (syscall_number)
1067 SYSCALL_MAP (io_setup);
1068 SYSCALL_MAP (io_destroy);
1069 SYSCALL_MAP (io_submit);
1070 SYSCALL_MAP (io_cancel);
1071 SYSCALL_MAP (io_getevents);
1073 SYSCALL_MAP (setxattr);
1074 SYSCALL_MAP (lsetxattr);
1075 SYSCALL_MAP (fsetxattr);
1076 SYSCALL_MAP (getxattr);
1077 SYSCALL_MAP (lgetxattr);
1078 SYSCALL_MAP (fgetxattr);
1079 SYSCALL_MAP (listxattr);
1080 SYSCALL_MAP (llistxattr);
1081 SYSCALL_MAP (flistxattr);
1082 SYSCALL_MAP (removexattr);
1083 SYSCALL_MAP (lremovexattr);
1084 SYSCALL_MAP (fremovexattr);
1085 SYSCALL_MAP (getcwd);
1086 SYSCALL_MAP (lookup_dcookie);
1087 SYSCALL_MAP (eventfd2);
1088 SYSCALL_MAP (epoll_create1);
1089 SYSCALL_MAP (epoll_ctl);
1090 SYSCALL_MAP (epoll_pwait);
1093 SYSCALL_MAP (fcntl);
1094 SYSCALL_MAP (inotify_init1);
1095 SYSCALL_MAP (inotify_add_watch);
1096 SYSCALL_MAP (inotify_rm_watch);
1097 SYSCALL_MAP (ioctl);
1098 SYSCALL_MAP (ioprio_set);
1099 SYSCALL_MAP (ioprio_get);
1100 SYSCALL_MAP (flock);
1101 SYSCALL_MAP (mknodat);
1102 SYSCALL_MAP (mkdirat);
1103 SYSCALL_MAP (unlinkat);
1104 SYSCALL_MAP (symlinkat);
1105 SYSCALL_MAP (linkat);
1106 SYSCALL_MAP (renameat);
1107 UNSUPPORTED_SYSCALL_MAP (umount2);
1108 SYSCALL_MAP (mount);
1109 SYSCALL_MAP (pivot_root);
1110 SYSCALL_MAP (nfsservctl);
1111 SYSCALL_MAP (statfs);
1112 SYSCALL_MAP (truncate);
1113 SYSCALL_MAP (ftruncate);
1114 SYSCALL_MAP (fallocate);
1115 SYSCALL_MAP (faccessat);
1116 SYSCALL_MAP (fchdir);
1117 SYSCALL_MAP (chroot);
1118 SYSCALL_MAP (fchmod);
1119 SYSCALL_MAP (fchmodat);
1120 SYSCALL_MAP (fchownat);
1121 SYSCALL_MAP (fchown);
1122 SYSCALL_MAP (openat);
1123 SYSCALL_MAP (close);
1124 SYSCALL_MAP (vhangup);
1125 SYSCALL_MAP (pipe2);
1126 SYSCALL_MAP (quotactl);
1127 SYSCALL_MAP (getdents64);
1128 SYSCALL_MAP (lseek);
1130 SYSCALL_MAP (write);
1131 SYSCALL_MAP (readv);
1132 SYSCALL_MAP (writev);
1133 SYSCALL_MAP (pread64);
1134 SYSCALL_MAP (pwrite64);
1135 UNSUPPORTED_SYSCALL_MAP (preadv);
1136 UNSUPPORTED_SYSCALL_MAP (pwritev);
1137 SYSCALL_MAP (sendfile);
1138 SYSCALL_MAP (pselect6);
1139 SYSCALL_MAP (ppoll);
1140 UNSUPPORTED_SYSCALL_MAP (signalfd4);
1141 SYSCALL_MAP (vmsplice);
1142 SYSCALL_MAP (splice);
1144 SYSCALL_MAP (readlinkat);
1145 SYSCALL_MAP (newfstatat);
1147 SYSCALL_MAP (fstat);
1149 SYSCALL_MAP (fsync);
1150 SYSCALL_MAP (fdatasync);
1151 SYSCALL_MAP (sync_file_range);
1152 UNSUPPORTED_SYSCALL_MAP (timerfd_create);
1153 UNSUPPORTED_SYSCALL_MAP (timerfd_settime);
1154 UNSUPPORTED_SYSCALL_MAP (timerfd_gettime);
1155 UNSUPPORTED_SYSCALL_MAP (utimensat);
1157 SYSCALL_MAP (capget);
1158 SYSCALL_MAP (capset);
1159 SYSCALL_MAP (personality);
1161 SYSCALL_MAP (exit_group);
1162 SYSCALL_MAP (waitid);
1163 SYSCALL_MAP (set_tid_address);
1164 SYSCALL_MAP (unshare);
1165 SYSCALL_MAP (futex);
1166 SYSCALL_MAP (set_robust_list);
1167 SYSCALL_MAP (get_robust_list);
1168 SYSCALL_MAP (nanosleep);
1170 SYSCALL_MAP (getitimer);
1171 SYSCALL_MAP (setitimer);
1172 SYSCALL_MAP (kexec_load);
1173 SYSCALL_MAP (init_module);
1174 SYSCALL_MAP (delete_module);
1175 SYSCALL_MAP (timer_create);
1176 SYSCALL_MAP (timer_settime);
1177 SYSCALL_MAP (timer_gettime);
1178 SYSCALL_MAP (timer_getoverrun);
1179 SYSCALL_MAP (timer_delete);
1180 SYSCALL_MAP (clock_settime);
1181 SYSCALL_MAP (clock_gettime);
1182 SYSCALL_MAP (clock_getres);
1183 SYSCALL_MAP (clock_nanosleep);
1184 SYSCALL_MAP (syslog);
1185 SYSCALL_MAP (ptrace);
1186 SYSCALL_MAP (sched_setparam);
1187 SYSCALL_MAP (sched_setscheduler);
1188 SYSCALL_MAP (sched_getscheduler);
1189 SYSCALL_MAP (sched_getparam);
1190 SYSCALL_MAP (sched_setaffinity);
1191 SYSCALL_MAP (sched_getaffinity);
1192 SYSCALL_MAP (sched_yield);
1193 SYSCALL_MAP (sched_get_priority_max);
1194 SYSCALL_MAP (sched_get_priority_min);
1195 SYSCALL_MAP (sched_rr_get_interval);
1197 SYSCALL_MAP (tkill);
1198 SYSCALL_MAP (tgkill);
1199 SYSCALL_MAP (sigaltstack);
1200 SYSCALL_MAP (rt_sigsuspend);
1201 SYSCALL_MAP (rt_sigaction);
1202 SYSCALL_MAP (rt_sigprocmask);
1203 SYSCALL_MAP (rt_sigpending);
1204 SYSCALL_MAP (rt_sigtimedwait);
1205 SYSCALL_MAP (rt_sigqueueinfo);
1206 SYSCALL_MAP (rt_sigreturn);
1207 SYSCALL_MAP (setpriority);
1208 SYSCALL_MAP (getpriority);
1209 SYSCALL_MAP (reboot);
1210 SYSCALL_MAP (setregid);
1211 SYSCALL_MAP (setgid);
1212 SYSCALL_MAP (setreuid);
1213 SYSCALL_MAP (setuid);
1214 SYSCALL_MAP (setresuid);
1215 SYSCALL_MAP (getresuid);
1216 SYSCALL_MAP (setresgid);
1217 SYSCALL_MAP (getresgid);
1218 SYSCALL_MAP (setfsuid);
1219 SYSCALL_MAP (setfsgid);
1220 SYSCALL_MAP (times);
1221 SYSCALL_MAP (setpgid);
1222 SYSCALL_MAP (getpgid);
1223 SYSCALL_MAP (getsid);
1224 SYSCALL_MAP (setsid);
1225 SYSCALL_MAP (getgroups);
1226 SYSCALL_MAP (setgroups);
1227 SYSCALL_MAP (uname);
1228 SYSCALL_MAP (sethostname);
1229 SYSCALL_MAP (setdomainname);
1230 SYSCALL_MAP (getrlimit);
1231 SYSCALL_MAP (setrlimit);
1232 SYSCALL_MAP (getrusage);
1233 SYSCALL_MAP (umask);
1234 SYSCALL_MAP (prctl);
1235 SYSCALL_MAP (getcpu);
1236 SYSCALL_MAP (gettimeofday);
1237 SYSCALL_MAP (settimeofday);
1238 SYSCALL_MAP (adjtimex);
1239 SYSCALL_MAP (getpid);
1240 SYSCALL_MAP (getppid);
1241 SYSCALL_MAP (getuid);
1242 SYSCALL_MAP (geteuid);
1243 SYSCALL_MAP (getgid);
1244 SYSCALL_MAP (getegid);
1245 SYSCALL_MAP (gettid);
1246 SYSCALL_MAP (sysinfo);
1247 SYSCALL_MAP (mq_open);
1248 SYSCALL_MAP (mq_unlink);
1249 SYSCALL_MAP (mq_timedsend);
1250 SYSCALL_MAP (mq_timedreceive);
1251 SYSCALL_MAP (mq_notify);
1252 SYSCALL_MAP (mq_getsetattr);
1253 SYSCALL_MAP (msgget);
1254 SYSCALL_MAP (msgctl);
1255 SYSCALL_MAP (msgrcv);
1256 SYSCALL_MAP (msgsnd);
1257 SYSCALL_MAP (semget);
1258 SYSCALL_MAP (semctl);
1259 SYSCALL_MAP (semtimedop);
1260 SYSCALL_MAP (semop);
1261 SYSCALL_MAP (shmget);
1262 SYSCALL_MAP (shmctl);
1263 SYSCALL_MAP (shmat);
1264 SYSCALL_MAP (shmdt);
1265 SYSCALL_MAP (socket);
1266 SYSCALL_MAP (socketpair);
1268 SYSCALL_MAP (listen);
1269 SYSCALL_MAP (accept);
1270 SYSCALL_MAP (connect);
1271 SYSCALL_MAP (getsockname);
1272 SYSCALL_MAP (getpeername);
1273 SYSCALL_MAP (sendto);
1274 SYSCALL_MAP (recvfrom);
1275 SYSCALL_MAP (setsockopt);
1276 SYSCALL_MAP (getsockopt);
1277 SYSCALL_MAP (shutdown);
1278 SYSCALL_MAP (sendmsg);
1279 SYSCALL_MAP (recvmsg);
1280 SYSCALL_MAP (readahead);
1282 SYSCALL_MAP (munmap);
1283 SYSCALL_MAP (mremap);
1284 SYSCALL_MAP (add_key);
1285 SYSCALL_MAP (request_key);
1286 SYSCALL_MAP (keyctl);
1287 SYSCALL_MAP (clone);
1288 SYSCALL_MAP (execve);
1290 case aarch64_sys_mmap:
1291 return gdb_sys_mmap2;
1293 SYSCALL_MAP (fadvise64);
1294 SYSCALL_MAP (swapon);
1295 SYSCALL_MAP (swapoff);
1296 SYSCALL_MAP (mprotect);
1297 SYSCALL_MAP (msync);
1298 SYSCALL_MAP (mlock);
1299 SYSCALL_MAP (munlock);
1300 SYSCALL_MAP (mlockall);
1301 SYSCALL_MAP (munlockall);
1302 SYSCALL_MAP (mincore);
1303 SYSCALL_MAP (madvise);
1304 SYSCALL_MAP (remap_file_pages);
1305 SYSCALL_MAP (mbind);
1306 SYSCALL_MAP (get_mempolicy);
1307 SYSCALL_MAP (set_mempolicy);
1308 SYSCALL_MAP (migrate_pages);
1309 SYSCALL_MAP (move_pages);
1310 UNSUPPORTED_SYSCALL_MAP (rt_tgsigqueueinfo);
1311 UNSUPPORTED_SYSCALL_MAP (perf_event_open);
1312 UNSUPPORTED_SYSCALL_MAP (accept4);
1313 UNSUPPORTED_SYSCALL_MAP (recvmmsg);
1315 SYSCALL_MAP (wait4);
1317 UNSUPPORTED_SYSCALL_MAP (prlimit64);
1318 UNSUPPORTED_SYSCALL_MAP (fanotify_init);
1319 UNSUPPORTED_SYSCALL_MAP (fanotify_mark);
1320 UNSUPPORTED_SYSCALL_MAP (name_to_handle_at);
1321 UNSUPPORTED_SYSCALL_MAP (open_by_handle_at);
1322 UNSUPPORTED_SYSCALL_MAP (clock_adjtime);
1323 UNSUPPORTED_SYSCALL_MAP (syncfs);
1324 UNSUPPORTED_SYSCALL_MAP (setns);
1325 UNSUPPORTED_SYSCALL_MAP (sendmmsg);
1326 UNSUPPORTED_SYSCALL_MAP (process_vm_readv);
1327 UNSUPPORTED_SYSCALL_MAP (process_vm_writev);
1328 UNSUPPORTED_SYSCALL_MAP (kcmp);
1329 UNSUPPORTED_SYSCALL_MAP (finit_module);
1330 UNSUPPORTED_SYSCALL_MAP (sched_setattr);
1331 UNSUPPORTED_SYSCALL_MAP (sched_getattr);
1333 return gdb_sys_no_syscall;
1337 /* Record all registers but PC register for process-record. */
1340 aarch64_all_but_pc_registers_record (struct regcache *regcache)
1344 for (i = AARCH64_X0_REGNUM; i < AARCH64_PC_REGNUM; i++)
1345 if (record_full_arch_list_add_reg (regcache, i))
1348 if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM))
1354 /* Handler for aarch64 system call instruction recording. */
1357 aarch64_linux_syscall_record (struct regcache *regcache,
1358 unsigned long svc_number)
1361 enum gdb_syscall syscall_gdb;
1364 aarch64_canonicalize_syscall ((enum aarch64_syscall) svc_number);
1366 if (syscall_gdb < 0)
1368 printf_unfiltered (_("Process record and replay target doesn't "
1369 "support syscall number %s\n"),
1370 plongest (svc_number));
1374 if (syscall_gdb == gdb_sys_sigreturn
1375 || syscall_gdb == gdb_sys_rt_sigreturn)
1377 if (aarch64_all_but_pc_registers_record (regcache))
1382 ret = record_linux_system_call (syscall_gdb, regcache,
1383 &aarch64_linux_record_tdep);
1387 /* Record the return value of the system call. */
1388 if (record_full_arch_list_add_reg (regcache, AARCH64_X0_REGNUM))
1391 if (record_full_arch_list_add_reg (regcache, AARCH64_LR_REGNUM))
1394 if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM))
1400 /* Implement the "gcc_target_options" gdbarch method. */
1403 aarch64_linux_gcc_target_options (struct gdbarch *gdbarch)
1405 /* GCC doesn't know "-m64". */
1410 aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1412 static const char *const stap_integer_prefixes[] = { "#", "", NULL };
1413 static const char *const stap_register_prefixes[] = { "", NULL };
1414 static const char *const stap_register_indirection_prefixes[] = { "[",
1416 static const char *const stap_register_indirection_suffixes[] = { "]",
1418 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1420 tdep->lowest_pc = 0x8000;
1422 linux_init_abi (info, gdbarch);
1424 set_solib_svr4_fetch_link_map_offsets (gdbarch,
1425 svr4_lp64_fetch_link_map_offsets);
1427 /* Enable TLS support. */
1428 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1429 svr4_fetch_objfile_link_map);
1431 /* Shared library handling. */
1432 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
1433 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1435 tramp_frame_prepend_unwinder (gdbarch, &aarch64_linux_rt_sigframe);
1437 /* Enable longjmp. */
1440 set_gdbarch_iterate_over_regset_sections
1441 (gdbarch, aarch64_linux_iterate_over_regset_sections);
1442 set_gdbarch_core_read_description
1443 (gdbarch, aarch64_linux_core_read_description);
1445 /* SystemTap related. */
1446 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
1447 set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
1448 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
1449 stap_register_indirection_prefixes);
1450 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
1451 stap_register_indirection_suffixes);
1452 set_gdbarch_stap_is_single_operand (gdbarch, aarch64_stap_is_single_operand);
1453 set_gdbarch_stap_parse_special_token (gdbarch,
1454 aarch64_stap_parse_special_token);
1456 /* Reversible debugging, process record. */
1457 set_gdbarch_process_record (gdbarch, aarch64_process_record);
1458 /* Syscall record. */
1459 tdep->aarch64_syscall_record = aarch64_linux_syscall_record;
1461 /* The top byte of a user space address known as the "tag",
1462 is ignored by the kernel and can be regarded as additional
1463 data associated with the address. */
1464 set_gdbarch_significant_addr_bit (gdbarch, 56);
1466 /* Initialize the aarch64_linux_record_tdep. */
1467 /* These values are the size of the type that will be used in a system
1468 call. They are obtained from Linux Kernel source. */
1469 aarch64_linux_record_tdep.size_pointer
1470 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
1471 aarch64_linux_record_tdep.size__old_kernel_stat = 32;
1472 aarch64_linux_record_tdep.size_tms = 32;
1473 aarch64_linux_record_tdep.size_loff_t = 8;
1474 aarch64_linux_record_tdep.size_flock = 32;
1475 aarch64_linux_record_tdep.size_oldold_utsname = 45;
1476 aarch64_linux_record_tdep.size_ustat = 32;
1477 aarch64_linux_record_tdep.size_old_sigaction = 32;
1478 aarch64_linux_record_tdep.size_old_sigset_t = 8;
1479 aarch64_linux_record_tdep.size_rlimit = 16;
1480 aarch64_linux_record_tdep.size_rusage = 144;
1481 aarch64_linux_record_tdep.size_timeval = 16;
1482 aarch64_linux_record_tdep.size_timezone = 8;
1483 aarch64_linux_record_tdep.size_old_gid_t = 2;
1484 aarch64_linux_record_tdep.size_old_uid_t = 2;
1485 aarch64_linux_record_tdep.size_fd_set = 128;
1486 aarch64_linux_record_tdep.size_old_dirent = 280;
1487 aarch64_linux_record_tdep.size_statfs = 120;
1488 aarch64_linux_record_tdep.size_statfs64 = 120;
1489 aarch64_linux_record_tdep.size_sockaddr = 16;
1490 aarch64_linux_record_tdep.size_int
1491 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
1492 aarch64_linux_record_tdep.size_long
1493 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
1494 aarch64_linux_record_tdep.size_ulong
1495 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
1496 aarch64_linux_record_tdep.size_msghdr = 56;
1497 aarch64_linux_record_tdep.size_itimerval = 32;
1498 aarch64_linux_record_tdep.size_stat = 144;
1499 aarch64_linux_record_tdep.size_old_utsname = 325;
1500 aarch64_linux_record_tdep.size_sysinfo = 112;
1501 aarch64_linux_record_tdep.size_msqid_ds = 120;
1502 aarch64_linux_record_tdep.size_shmid_ds = 112;
1503 aarch64_linux_record_tdep.size_new_utsname = 390;
1504 aarch64_linux_record_tdep.size_timex = 208;
1505 aarch64_linux_record_tdep.size_mem_dqinfo = 24;
1506 aarch64_linux_record_tdep.size_if_dqblk = 72;
1507 aarch64_linux_record_tdep.size_fs_quota_stat = 80;
1508 aarch64_linux_record_tdep.size_timespec = 16;
1509 aarch64_linux_record_tdep.size_pollfd = 8;
1510 aarch64_linux_record_tdep.size_NFS_FHSIZE = 32;
1511 aarch64_linux_record_tdep.size_knfsd_fh = 132;
1512 aarch64_linux_record_tdep.size_TASK_COMM_LEN = 16;
1513 aarch64_linux_record_tdep.size_sigaction = 32;
1514 aarch64_linux_record_tdep.size_sigset_t = 8;
1515 aarch64_linux_record_tdep.size_siginfo_t = 128;
1516 aarch64_linux_record_tdep.size_cap_user_data_t = 8;
1517 aarch64_linux_record_tdep.size_stack_t = 24;
1518 aarch64_linux_record_tdep.size_off_t = 8;
1519 aarch64_linux_record_tdep.size_stat64 = 144;
1520 aarch64_linux_record_tdep.size_gid_t = 4;
1521 aarch64_linux_record_tdep.size_uid_t = 4;
1522 aarch64_linux_record_tdep.size_PAGE_SIZE = 4096;
1523 aarch64_linux_record_tdep.size_flock64 = 32;
1524 aarch64_linux_record_tdep.size_user_desc = 16;
1525 aarch64_linux_record_tdep.size_io_event = 32;
1526 aarch64_linux_record_tdep.size_iocb = 64;
1527 aarch64_linux_record_tdep.size_epoll_event = 12;
1528 aarch64_linux_record_tdep.size_itimerspec = 32;
1529 aarch64_linux_record_tdep.size_mq_attr = 64;
1530 aarch64_linux_record_tdep.size_termios = 36;
1531 aarch64_linux_record_tdep.size_termios2 = 44;
1532 aarch64_linux_record_tdep.size_pid_t = 4;
1533 aarch64_linux_record_tdep.size_winsize = 8;
1534 aarch64_linux_record_tdep.size_serial_struct = 72;
1535 aarch64_linux_record_tdep.size_serial_icounter_struct = 80;
1536 aarch64_linux_record_tdep.size_hayes_esp_config = 12;
1537 aarch64_linux_record_tdep.size_size_t = 8;
1538 aarch64_linux_record_tdep.size_iovec = 16;
1539 aarch64_linux_record_tdep.size_time_t = 8;
1541 /* These values are the second argument of system call "sys_ioctl".
1542 They are obtained from Linux Kernel source. */
1543 aarch64_linux_record_tdep.ioctl_TCGETS = 0x5401;
1544 aarch64_linux_record_tdep.ioctl_TCSETS = 0x5402;
1545 aarch64_linux_record_tdep.ioctl_TCSETSW = 0x5403;
1546 aarch64_linux_record_tdep.ioctl_TCSETSF = 0x5404;
1547 aarch64_linux_record_tdep.ioctl_TCGETA = 0x5405;
1548 aarch64_linux_record_tdep.ioctl_TCSETA = 0x5406;
1549 aarch64_linux_record_tdep.ioctl_TCSETAW = 0x5407;
1550 aarch64_linux_record_tdep.ioctl_TCSETAF = 0x5408;
1551 aarch64_linux_record_tdep.ioctl_TCSBRK = 0x5409;
1552 aarch64_linux_record_tdep.ioctl_TCXONC = 0x540a;
1553 aarch64_linux_record_tdep.ioctl_TCFLSH = 0x540b;
1554 aarch64_linux_record_tdep.ioctl_TIOCEXCL = 0x540c;
1555 aarch64_linux_record_tdep.ioctl_TIOCNXCL = 0x540d;
1556 aarch64_linux_record_tdep.ioctl_TIOCSCTTY = 0x540e;
1557 aarch64_linux_record_tdep.ioctl_TIOCGPGRP = 0x540f;
1558 aarch64_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
1559 aarch64_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
1560 aarch64_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
1561 aarch64_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
1562 aarch64_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
1563 aarch64_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
1564 aarch64_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
1565 aarch64_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
1566 aarch64_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
1567 aarch64_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
1568 aarch64_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541a;
1569 aarch64_linux_record_tdep.ioctl_FIONREAD = 0x541b;
1570 aarch64_linux_record_tdep.ioctl_TIOCINQ = 0x541b;
1571 aarch64_linux_record_tdep.ioctl_TIOCLINUX = 0x541c;
1572 aarch64_linux_record_tdep.ioctl_TIOCCONS = 0x541d;
1573 aarch64_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541e;
1574 aarch64_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541f;
1575 aarch64_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
1576 aarch64_linux_record_tdep.ioctl_FIONBIO = 0x5421;
1577 aarch64_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
1578 aarch64_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
1579 aarch64_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
1580 aarch64_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
1581 aarch64_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
1582 aarch64_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
1583 aarch64_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
1584 aarch64_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
1585 aarch64_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
1586 aarch64_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
1587 aarch64_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
1588 aarch64_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
1589 aarch64_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
1590 aarch64_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
1591 aarch64_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
1592 aarch64_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
1593 aarch64_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
1594 aarch64_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
1595 aarch64_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
1596 aarch64_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
1597 aarch64_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
1598 aarch64_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
1599 aarch64_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
1600 aarch64_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
1601 aarch64_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545a;
1602 aarch64_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545b;
1603 aarch64_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545c;
1604 aarch64_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545d;
1605 aarch64_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545e;
1606 aarch64_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545f;
1607 aarch64_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
1609 /* These values are the second argument of system call "sys_fcntl"
1610 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1611 aarch64_linux_record_tdep.fcntl_F_GETLK = 5;
1612 aarch64_linux_record_tdep.fcntl_F_GETLK64 = 12;
1613 aarch64_linux_record_tdep.fcntl_F_SETLK64 = 13;
1614 aarch64_linux_record_tdep.fcntl_F_SETLKW64 = 14;
1616 /* The AArch64 syscall calling convention: reg x0-x6 for arguments,
1617 reg x8 for syscall number and return value in reg x0. */
1618 aarch64_linux_record_tdep.arg1 = AARCH64_X0_REGNUM + 0;
1619 aarch64_linux_record_tdep.arg2 = AARCH64_X0_REGNUM + 1;
1620 aarch64_linux_record_tdep.arg3 = AARCH64_X0_REGNUM + 2;
1621 aarch64_linux_record_tdep.arg4 = AARCH64_X0_REGNUM + 3;
1622 aarch64_linux_record_tdep.arg5 = AARCH64_X0_REGNUM + 4;
1623 aarch64_linux_record_tdep.arg6 = AARCH64_X0_REGNUM + 5;
1624 aarch64_linux_record_tdep.arg7 = AARCH64_X0_REGNUM + 6;
1626 /* `catch syscall' */
1627 set_xml_syscall_file_name (gdbarch, "syscalls/aarch64-linux.xml");
1628 set_gdbarch_get_syscall_number (gdbarch, aarch64_linux_get_syscall_number);
1630 /* Displaced stepping. */
1631 set_gdbarch_max_insn_length (gdbarch, 4 * DISPLACED_MODIFIED_INSNS);
1632 set_gdbarch_displaced_step_copy_insn (gdbarch,
1633 aarch64_displaced_step_copy_insn);
1634 set_gdbarch_displaced_step_fixup (gdbarch, aarch64_displaced_step_fixup);
1635 set_gdbarch_displaced_step_location (gdbarch, linux_displaced_step_location);
1636 set_gdbarch_displaced_step_hw_singlestep (gdbarch,
1637 aarch64_displaced_step_hw_singlestep);
1639 set_gdbarch_gcc_target_options (gdbarch, aarch64_linux_gcc_target_options);
1643 _initialize_aarch64_linux_tdep (void)
1645 gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_LINUX,
1646 aarch64_linux_init_abi);