IBM zSystems: Add support for z16 as CPU name.
[binutils-gdb.git] / gdb / aarch64-linux-tdep.c
blob55094b3d88b5571659d24e6800e53afa64be0d30
1 /* Target-dependent code for GNU/Linux AArch64.
3 Copyright (C) 2009-2022 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/>. */
21 #include "defs.h"
23 #include "gdbarch.h"
24 #include "glibc-tdep.h"
25 #include "linux-tdep.h"
26 #include "aarch64-tdep.h"
27 #include "aarch64-linux-tdep.h"
28 #include "osabi.h"
29 #include "solib-svr4.h"
30 #include "symtab.h"
31 #include "tramp-frame.h"
32 #include "trad-frame.h"
33 #include "target.h"
34 #include "target/target.h"
35 #include "expop.h"
37 #include "regcache.h"
38 #include "regset.h"
40 #include "stap-probe.h"
41 #include "parser-defs.h"
42 #include "user-regs.h"
43 #include "xml-syscall.h"
44 #include <ctype.h>
46 #include "record-full.h"
47 #include "linux-record.h"
49 #include "arch/aarch64-mte-linux.h"
51 #include "arch-utils.h"
52 #include "value.h"
54 #include "gdbsupport/selftest.h"
56 /* Signal frame handling.
58 +------------+ ^
59 | saved lr | |
60 +->| saved fp |--+
61 | | |
62 | | |
63 | +------------+
64 | | saved lr |
65 +--| saved fp |
66 ^ | |
67 | | |
68 | +------------+
69 ^ | |
70 | | signal |
71 | | | SIGTRAMP_FRAME (struct rt_sigframe)
72 | | saved regs |
73 +--| saved sp |--> interrupted_sp
74 | | saved pc |--> interrupted_pc
75 | | |
76 | +------------+
77 | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
78 +--| saved fp |<- FP
79 | | NORMAL_FRAME
80 | |<- SP
81 +------------+
83 On signal delivery, the kernel will create a signal handler stack
84 frame and setup the return address in LR to point at restorer stub.
85 The signal stack frame is defined by:
87 struct rt_sigframe
89 siginfo_t info;
90 struct ucontext uc;
93 The ucontext has the following form:
94 struct ucontext
96 unsigned long uc_flags;
97 struct ucontext *uc_link;
98 stack_t uc_stack;
99 sigset_t uc_sigmask;
100 struct sigcontext uc_mcontext;
103 struct sigcontext
105 unsigned long fault_address;
106 unsigned long regs[31];
107 unsigned long sp; / * 31 * /
108 unsigned long pc; / * 32 * /
109 unsigned long pstate; / * 33 * /
110 __u8 __reserved[4096]
113 The reserved space in sigcontext contains additional structures, each starting
114 with a aarch64_ctx, which specifies a unique identifier and the total size of
115 the structure. The final structure in reserved will start will a null
116 aarch64_ctx. The penultimate entry in reserved may be a extra_context which
117 then points to a further block of reserved space.
119 struct aarch64_ctx {
120 u32 magic;
121 u32 size;
124 The restorer stub will always have the form:
126 d28015a8 movz x8, #0xad
127 d4000001 svc #0x0
129 This is a system call sys_rt_sigreturn.
131 We detect signal frames by snooping the return code for the restorer
132 instruction sequence.
134 The handler then needs to recover the saved register set from
135 ucontext.uc_mcontext. */
137 /* These magic numbers need to reflect the layout of the kernel
138 defined struct rt_sigframe and ucontext. */
139 #define AARCH64_SIGCONTEXT_REG_SIZE 8
140 #define AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET 128
141 #define AARCH64_UCONTEXT_SIGCONTEXT_OFFSET 176
142 #define AARCH64_SIGCONTEXT_XO_OFFSET 8
143 #define AARCH64_SIGCONTEXT_RESERVED_OFFSET 288
145 #define AARCH64_SIGCONTEXT_RESERVED_SIZE 4096
147 /* Unique identifiers that may be used for aarch64_ctx.magic. */
148 #define AARCH64_EXTRA_MAGIC 0x45585401
149 #define AARCH64_FPSIMD_MAGIC 0x46508001
150 #define AARCH64_SVE_MAGIC 0x53564501
152 /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC. */
153 #define AARCH64_EXTRA_DATAP_OFFSET 8
155 /* Defines for the fpsimd that follows an AARCH64_FPSIMD_MAGIC. */
156 #define AARCH64_FPSIMD_FPSR_OFFSET 8
157 #define AARCH64_FPSIMD_FPCR_OFFSET 12
158 #define AARCH64_FPSIMD_V0_OFFSET 16
159 #define AARCH64_FPSIMD_VREG_SIZE 16
161 /* Defines for the sve structure that follows an AARCH64_SVE_MAGIC. */
162 #define AARCH64_SVE_CONTEXT_VL_OFFSET 8
163 #define AARCH64_SVE_CONTEXT_REGS_OFFSET 16
164 #define AARCH64_SVE_CONTEXT_P_REGS_OFFSET(vq) (32 * vq * 16)
165 #define AARCH64_SVE_CONTEXT_FFR_OFFSET(vq) \
166 (AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq) + (16 * vq * 2))
167 #define AARCH64_SVE_CONTEXT_SIZE(vq) \
168 (AARCH64_SVE_CONTEXT_FFR_OFFSET (vq) + (vq * 2))
171 /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the
172 size, or return 0 on error. */
174 static uint32_t
175 read_aarch64_ctx (CORE_ADDR ctx_addr, enum bfd_endian byte_order,
176 uint32_t *size)
178 uint32_t magic = 0;
179 gdb_byte buf[4];
181 if (target_read_memory (ctx_addr, buf, 4) != 0)
182 return 0;
183 magic = extract_unsigned_integer (buf, 4, byte_order);
185 if (target_read_memory (ctx_addr + 4, buf, 4) != 0)
186 return 0;
187 *size = extract_unsigned_integer (buf, 4, byte_order);
189 return magic;
192 /* Given CACHE, use the trad_frame* functions to restore the FPSIMD
193 registers from a signal frame.
195 VREG_NUM is the number of the V register being restored, OFFSET is the
196 address containing the register value, BYTE_ORDER is the endianness and
197 HAS_SVE tells us if we have a valid SVE context or not. */
199 static void
200 aarch64_linux_restore_vreg (struct trad_frame_cache *cache, int num_regs,
201 int vreg_num, CORE_ADDR offset,
202 enum bfd_endian byte_order, bool has_sve)
204 /* WARNING: SIMD state is laid out in memory in target-endian format.
206 So we have a couple cases to consider:
208 1 - If the target is big endian, then SIMD state is big endian,
209 requiring a byteswap.
211 2 - If the target is little endian, then SIMD state is little endian, so
212 no byteswap is needed. */
214 if (byte_order == BFD_ENDIAN_BIG)
216 gdb_byte buf[V_REGISTER_SIZE];
218 if (target_read_memory (offset, buf, V_REGISTER_SIZE) != 0)
220 size_t size = V_REGISTER_SIZE/2;
222 /* Read the two halves of the V register in reverse byte order. */
223 CORE_ADDR u64 = extract_unsigned_integer (buf, size,
224 byte_order);
225 CORE_ADDR l64 = extract_unsigned_integer (buf + size, size,
226 byte_order);
228 /* Copy the reversed bytes to the buffer. */
229 store_unsigned_integer (buf, size, BFD_ENDIAN_LITTLE, l64);
230 store_unsigned_integer (buf + size , size, BFD_ENDIAN_LITTLE, u64);
232 /* Now we can store the correct bytes for the V register. */
233 trad_frame_set_reg_value_bytes (cache, AARCH64_V0_REGNUM + vreg_num,
234 {buf, V_REGISTER_SIZE});
235 trad_frame_set_reg_value_bytes (cache,
236 num_regs + AARCH64_Q0_REGNUM
237 + vreg_num, {buf, Q_REGISTER_SIZE});
238 trad_frame_set_reg_value_bytes (cache,
239 num_regs + AARCH64_D0_REGNUM
240 + vreg_num, {buf, D_REGISTER_SIZE});
241 trad_frame_set_reg_value_bytes (cache,
242 num_regs + AARCH64_S0_REGNUM
243 + vreg_num, {buf, S_REGISTER_SIZE});
244 trad_frame_set_reg_value_bytes (cache,
245 num_regs + AARCH64_H0_REGNUM
246 + vreg_num, {buf, H_REGISTER_SIZE});
247 trad_frame_set_reg_value_bytes (cache,
248 num_regs + AARCH64_B0_REGNUM
249 + vreg_num, {buf, B_REGISTER_SIZE});
251 if (has_sve)
252 trad_frame_set_reg_value_bytes (cache,
253 num_regs + AARCH64_SVE_V0_REGNUM
254 + vreg_num, {buf, V_REGISTER_SIZE});
256 return;
259 /* Little endian, just point at the address containing the register
260 value. */
261 trad_frame_set_reg_addr (cache, AARCH64_V0_REGNUM + vreg_num, offset);
262 trad_frame_set_reg_addr (cache, num_regs + AARCH64_Q0_REGNUM + vreg_num,
263 offset);
264 trad_frame_set_reg_addr (cache, num_regs + AARCH64_D0_REGNUM + vreg_num,
265 offset);
266 trad_frame_set_reg_addr (cache, num_regs + AARCH64_S0_REGNUM + vreg_num,
267 offset);
268 trad_frame_set_reg_addr (cache, num_regs + AARCH64_H0_REGNUM + vreg_num,
269 offset);
270 trad_frame_set_reg_addr (cache, num_regs + AARCH64_B0_REGNUM + vreg_num,
271 offset);
273 if (has_sve)
274 trad_frame_set_reg_addr (cache, num_regs + AARCH64_SVE_V0_REGNUM
275 + vreg_num, offset);
279 /* Implement the "init" method of struct tramp_frame. */
281 static void
282 aarch64_linux_sigframe_init (const struct tramp_frame *self,
283 struct frame_info *this_frame,
284 struct trad_frame_cache *this_cache,
285 CORE_ADDR func)
287 struct gdbarch *gdbarch = get_frame_arch (this_frame);
288 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
289 aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
290 CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
291 CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
292 + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
293 CORE_ADDR section = sigcontext_addr + AARCH64_SIGCONTEXT_RESERVED_OFFSET;
294 CORE_ADDR section_end = section + AARCH64_SIGCONTEXT_RESERVED_SIZE;
295 CORE_ADDR fpsimd = 0;
296 CORE_ADDR sve_regs = 0;
297 uint32_t size, magic;
298 bool extra_found = false;
299 int num_regs = gdbarch_num_regs (gdbarch);
301 /* Read in the integer registers. */
303 for (int i = 0; i < 31; i++)
305 trad_frame_set_reg_addr (this_cache,
306 AARCH64_X0_REGNUM + i,
307 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
308 + i * AARCH64_SIGCONTEXT_REG_SIZE);
310 trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM,
311 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
312 + 31 * AARCH64_SIGCONTEXT_REG_SIZE);
313 trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM,
314 sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
315 + 32 * AARCH64_SIGCONTEXT_REG_SIZE);
317 /* Search for the FP and SVE sections, stopping at null. */
318 while ((magic = read_aarch64_ctx (section, byte_order, &size)) != 0
319 && size != 0)
321 switch (magic)
323 case AARCH64_FPSIMD_MAGIC:
324 fpsimd = section;
325 section += size;
326 break;
328 case AARCH64_SVE_MAGIC:
330 /* Check if the section is followed by a full SVE dump, and set
331 sve_regs if it is. */
332 gdb_byte buf[4];
333 uint16_t vq;
335 if (!tdep->has_sve ())
336 break;
338 if (target_read_memory (section + AARCH64_SVE_CONTEXT_VL_OFFSET,
339 buf, 2) != 0)
341 section += size;
342 break;
344 vq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, byte_order));
346 if (vq != tdep->vq)
347 error (_("Invalid vector length in signal frame %d vs %s."), vq,
348 pulongest (tdep->vq));
350 if (size >= AARCH64_SVE_CONTEXT_SIZE (vq))
351 sve_regs = section + AARCH64_SVE_CONTEXT_REGS_OFFSET;
353 section += size;
354 break;
357 case AARCH64_EXTRA_MAGIC:
359 /* Extra is always the last valid section in reserved and points to
360 an additional block of memory filled with more sections. Reset
361 the address to the extra section and continue looking for more
362 structures. */
363 gdb_byte buf[8];
365 if (target_read_memory (section + AARCH64_EXTRA_DATAP_OFFSET,
366 buf, 8) != 0)
368 section += size;
369 break;
372 section = extract_unsigned_integer (buf, 8, byte_order);
373 extra_found = true;
374 break;
377 default:
378 section += size;
379 break;
382 /* Prevent searching past the end of the reserved section. The extra
383 section does not have a hard coded limit - we have to rely on it ending
384 with nulls. */
385 if (!extra_found && section > section_end)
386 break;
389 if (sve_regs != 0)
391 CORE_ADDR offset;
393 for (int i = 0; i < 32; i++)
395 offset = sve_regs + (i * tdep->vq * 16);
396 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_Z0_REGNUM + i,
397 offset);
398 trad_frame_set_reg_addr (this_cache,
399 num_regs + AARCH64_SVE_V0_REGNUM + i,
400 offset);
401 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_Q0_REGNUM + i,
402 offset);
403 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_D0_REGNUM + i,
404 offset);
405 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_S0_REGNUM + i,
406 offset);
407 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_H0_REGNUM + i,
408 offset);
409 trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_B0_REGNUM + i,
410 offset);
413 offset = sve_regs + AARCH64_SVE_CONTEXT_P_REGS_OFFSET (tdep->vq);
414 for (int i = 0; i < 16; i++)
415 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_P0_REGNUM + i,
416 offset + (i * tdep->vq * 2));
418 offset = sve_regs + AARCH64_SVE_CONTEXT_FFR_OFFSET (tdep->vq);
419 trad_frame_set_reg_addr (this_cache, AARCH64_SVE_FFR_REGNUM, offset);
422 if (fpsimd != 0)
424 trad_frame_set_reg_addr (this_cache, AARCH64_FPSR_REGNUM,
425 fpsimd + AARCH64_FPSIMD_FPSR_OFFSET);
426 trad_frame_set_reg_addr (this_cache, AARCH64_FPCR_REGNUM,
427 fpsimd + AARCH64_FPSIMD_FPCR_OFFSET);
429 /* If there was no SVE section then set up the V registers. */
430 if (sve_regs == 0)
432 for (int i = 0; i < 32; i++)
434 CORE_ADDR offset = (fpsimd + AARCH64_FPSIMD_V0_OFFSET
435 + (i * AARCH64_FPSIMD_VREG_SIZE));
437 aarch64_linux_restore_vreg (this_cache, num_regs, i, offset,
438 byte_order, tdep->has_sve ());
443 trad_frame_set_id (this_cache, frame_id_build (sp, func));
446 static const struct tramp_frame aarch64_linux_rt_sigframe =
448 SIGTRAMP_FRAME,
451 /* movz x8, 0x8b (S=1,o=10,h=0,i=0x8b,r=8)
452 Soo1 0010 1hhi iiii iiii iiii iiir rrrr */
453 {0xd2801168, ULONGEST_MAX},
455 /* svc 0x0 (o=0, l=1)
456 1101 0100 oooi iiii iiii iiii iii0 00ll */
457 {0xd4000001, ULONGEST_MAX},
458 {TRAMP_SENTINEL_INSN, ULONGEST_MAX}
460 aarch64_linux_sigframe_init
463 /* Register maps. */
465 static const struct regcache_map_entry aarch64_linux_gregmap[] =
467 { 31, AARCH64_X0_REGNUM, 8 }, /* x0 ... x30 */
468 { 1, AARCH64_SP_REGNUM, 8 },
469 { 1, AARCH64_PC_REGNUM, 8 },
470 { 1, AARCH64_CPSR_REGNUM, 8 },
471 { 0 }
474 static const struct regcache_map_entry aarch64_linux_fpregmap[] =
476 { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */
477 { 1, AARCH64_FPSR_REGNUM, 4 },
478 { 1, AARCH64_FPCR_REGNUM, 4 },
479 { 0 }
482 /* Register set definitions. */
484 const struct regset aarch64_linux_gregset =
486 aarch64_linux_gregmap,
487 regcache_supply_regset, regcache_collect_regset
490 const struct regset aarch64_linux_fpregset =
492 aarch64_linux_fpregmap,
493 regcache_supply_regset, regcache_collect_regset
496 /* The fields in an SVE header at the start of a SVE regset. */
498 #define SVE_HEADER_SIZE_LENGTH 4
499 #define SVE_HEADER_MAX_SIZE_LENGTH 4
500 #define SVE_HEADER_VL_LENGTH 2
501 #define SVE_HEADER_MAX_VL_LENGTH 2
502 #define SVE_HEADER_FLAGS_LENGTH 2
503 #define SVE_HEADER_RESERVED_LENGTH 2
505 #define SVE_HEADER_SIZE_OFFSET 0
506 #define SVE_HEADER_MAX_SIZE_OFFSET \
507 (SVE_HEADER_SIZE_OFFSET + SVE_HEADER_SIZE_LENGTH)
508 #define SVE_HEADER_VL_OFFSET \
509 (SVE_HEADER_MAX_SIZE_OFFSET + SVE_HEADER_MAX_SIZE_LENGTH)
510 #define SVE_HEADER_MAX_VL_OFFSET \
511 (SVE_HEADER_VL_OFFSET + SVE_HEADER_VL_LENGTH)
512 #define SVE_HEADER_FLAGS_OFFSET \
513 (SVE_HEADER_MAX_VL_OFFSET + SVE_HEADER_MAX_VL_LENGTH)
514 #define SVE_HEADER_RESERVED_OFFSET \
515 (SVE_HEADER_FLAGS_OFFSET + SVE_HEADER_FLAGS_LENGTH)
516 #define SVE_HEADER_SIZE \
517 (SVE_HEADER_RESERVED_OFFSET + SVE_HEADER_RESERVED_LENGTH)
519 #define SVE_HEADER_FLAG_SVE 1
521 /* Get VQ value from SVE section in the core dump. */
523 static uint64_t
524 aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd)
526 gdb_byte header[SVE_HEADER_SIZE];
527 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
528 asection *sve_section = bfd_get_section_by_name (abfd, ".reg-aarch-sve");
530 if (sve_section == nullptr)
532 /* No SVE state. */
533 return 0;
536 size_t size = bfd_section_size (sve_section);
538 /* Check extended state size. */
539 if (size < SVE_HEADER_SIZE)
541 warning (_("'.reg-aarch-sve' section in core file too small."));
542 return 0;
545 if (!bfd_get_section_contents (abfd, sve_section, header, 0, SVE_HEADER_SIZE))
547 warning (_("Couldn't read sve header from "
548 "'.reg-aarch-sve' section in core file."));
549 return 0;
552 uint64_t vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
553 SVE_HEADER_VL_LENGTH, byte_order);
554 uint64_t vq = sve_vq_from_vl (vl);
556 if (vq > AARCH64_MAX_SVE_VQ)
558 warning (_("SVE Vector length in core file not supported by this version"
559 " of GDB. (VQ=%s)"), pulongest (vq));
560 return 0;
562 else if (vq == 0)
564 warning (_("SVE Vector length in core file is invalid. (VQ=%s"),
565 pulongest (vq));
566 return 0;
569 return vq;
572 /* Supply register REGNUM from BUF to REGCACHE, using the register map
573 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
574 If BUF is NULL, set the registers to "unavailable" status. */
576 static void
577 aarch64_linux_supply_sve_regset (const struct regset *regset,
578 struct regcache *regcache,
579 int regnum, const void *buf, size_t size)
581 gdb_byte *header = (gdb_byte *) buf;
582 struct gdbarch *gdbarch = regcache->arch ();
583 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
585 if (buf == nullptr)
586 return regcache->supply_regset (regset, regnum, nullptr, size);
587 gdb_assert (size > SVE_HEADER_SIZE);
589 /* BUF contains an SVE header followed by a register dump of either the
590 passed in SVE regset or a NEON fpregset. */
592 /* Extract required fields from the header. */
593 ULONGEST vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
594 SVE_HEADER_VL_LENGTH, byte_order);
595 uint16_t flags = extract_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET,
596 SVE_HEADER_FLAGS_LENGTH,
597 byte_order);
599 if (regnum == -1 || regnum == AARCH64_SVE_VG_REGNUM)
601 gdb_byte vg_target[8];
602 store_integer ((gdb_byte *)&vg_target, sizeof (uint64_t), byte_order,
603 sve_vg_from_vl (vl));
604 regcache->raw_supply (AARCH64_SVE_VG_REGNUM, &vg_target);
607 if (flags & SVE_HEADER_FLAG_SVE)
609 /* Register dump is a SVE structure. */
610 regcache->supply_regset (regset, regnum,
611 (gdb_byte *) buf + SVE_HEADER_SIZE,
612 size - SVE_HEADER_SIZE);
614 else
616 /* Register dump is a fpsimd structure. First clear the SVE
617 registers. */
618 for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++)
619 regcache->raw_supply_zeroed (AARCH64_SVE_Z0_REGNUM + i);
620 for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++)
621 regcache->raw_supply_zeroed (AARCH64_SVE_P0_REGNUM + i);
622 regcache->raw_supply_zeroed (AARCH64_SVE_FFR_REGNUM);
624 /* Then supply the fpsimd registers. */
625 regcache->supply_regset (&aarch64_linux_fpregset, regnum,
626 (gdb_byte *) buf + SVE_HEADER_SIZE,
627 size - SVE_HEADER_SIZE);
631 /* Collect register REGNUM from REGCACHE to BUF, using the register
632 map in REGSET. If REGNUM is -1, do this for all registers in
633 REGSET. */
635 static void
636 aarch64_linux_collect_sve_regset (const struct regset *regset,
637 const struct regcache *regcache,
638 int regnum, void *buf, size_t size)
640 gdb_byte *header = (gdb_byte *) buf;
641 struct gdbarch *gdbarch = regcache->arch ();
642 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
643 aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
644 uint64_t vq = tdep->vq;
646 gdb_assert (buf != NULL);
647 gdb_assert (size > SVE_HEADER_SIZE);
649 /* BUF starts with a SVE header prior to the register dump. */
651 store_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET,
652 SVE_HEADER_SIZE_LENGTH, byte_order, size);
653 store_unsigned_integer (header + SVE_HEADER_MAX_SIZE_OFFSET,
654 SVE_HEADER_MAX_SIZE_LENGTH, byte_order, size);
655 store_unsigned_integer (header + SVE_HEADER_VL_OFFSET, SVE_HEADER_VL_LENGTH,
656 byte_order, sve_vl_from_vq (vq));
657 store_unsigned_integer (header + SVE_HEADER_MAX_VL_OFFSET,
658 SVE_HEADER_MAX_VL_LENGTH, byte_order,
659 sve_vl_from_vq (vq));
660 store_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET,
661 SVE_HEADER_FLAGS_LENGTH, byte_order,
662 SVE_HEADER_FLAG_SVE);
663 store_unsigned_integer (header + SVE_HEADER_RESERVED_OFFSET,
664 SVE_HEADER_RESERVED_LENGTH, byte_order, 0);
666 /* The SVE register dump follows. */
667 regcache->collect_regset (regset, regnum, (gdb_byte *) buf + SVE_HEADER_SIZE,
668 size - SVE_HEADER_SIZE);
671 /* Implement the "iterate_over_regset_sections" gdbarch method. */
673 static void
674 aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
675 iterate_over_regset_sections_cb *cb,
676 void *cb_data,
677 const struct regcache *regcache)
679 aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
681 cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
682 &aarch64_linux_gregset, NULL, cb_data);
684 if (tdep->has_sve ())
686 /* Create this on the fly in order to handle vector register sizes. */
687 const struct regcache_map_entry sve_regmap[] =
689 { 32, AARCH64_SVE_Z0_REGNUM, (int) (tdep->vq * 16) },
690 { 16, AARCH64_SVE_P0_REGNUM, (int) (tdep->vq * 16 / 8) },
691 { 1, AARCH64_SVE_FFR_REGNUM, (int) (tdep->vq * 16 / 8) },
692 { 1, AARCH64_FPSR_REGNUM, 4 },
693 { 1, AARCH64_FPCR_REGNUM, 4 },
694 { 0 }
697 const struct regset aarch64_linux_sve_regset =
699 sve_regmap,
700 aarch64_linux_supply_sve_regset, aarch64_linux_collect_sve_regset,
701 REGSET_VARIABLE_SIZE
704 cb (".reg-aarch-sve",
705 SVE_HEADER_SIZE + regcache_map_entry_size (aarch64_linux_fpregmap),
706 SVE_HEADER_SIZE + regcache_map_entry_size (sve_regmap),
707 &aarch64_linux_sve_regset, "SVE registers", cb_data);
709 else
710 cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, AARCH64_LINUX_SIZEOF_FPREGSET,
711 &aarch64_linux_fpregset, NULL, cb_data);
714 if (tdep->has_pauth ())
716 /* Create this on the fly in order to handle the variable location. */
717 const struct regcache_map_entry pauth_regmap[] =
719 { 2, AARCH64_PAUTH_DMASK_REGNUM (tdep->pauth_reg_base), 8},
720 { 0 }
723 const struct regset aarch64_linux_pauth_regset =
725 pauth_regmap, regcache_supply_regset, regcache_collect_regset
728 cb (".reg-aarch-pauth", AARCH64_LINUX_SIZEOF_PAUTH,
729 AARCH64_LINUX_SIZEOF_PAUTH, &aarch64_linux_pauth_regset,
730 "pauth registers", cb_data);
733 /* Handle MTE registers. */
734 if (tdep->has_mte ())
736 /* Create this on the fly in order to handle the variable location. */
737 const struct regcache_map_entry mte_regmap[] =
739 { 1, tdep->mte_reg_base, 8},
740 { 0 }
743 const struct regset aarch64_linux_mte_regset =
745 mte_regmap, regcache_supply_regset, regcache_collect_regset
748 cb (".reg-aarch-mte", AARCH64_LINUX_SIZEOF_MTE_REGSET,
749 AARCH64_LINUX_SIZEOF_MTE_REGSET, &aarch64_linux_mte_regset,
750 "MTE registers", cb_data);
754 /* Implement the "core_read_description" gdbarch method. */
756 static const struct target_desc *
757 aarch64_linux_core_read_description (struct gdbarch *gdbarch,
758 struct target_ops *target, bfd *abfd)
760 CORE_ADDR hwcap = linux_get_hwcap (target);
761 CORE_ADDR hwcap2 = linux_get_hwcap2 (target);
763 bool pauth_p = hwcap & AARCH64_HWCAP_PACA;
764 bool mte_p = hwcap2 & HWCAP2_MTE;
765 return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd),
766 pauth_p, mte_p);
769 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
770 gdbarch.h. */
772 static int
773 aarch64_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
775 return (*s == '#' || isdigit (*s) /* Literal number. */
776 || *s == '[' /* Register indirection. */
777 || isalpha (*s)); /* Register value. */
780 /* This routine is used to parse a special token in AArch64's assembly.
782 The special tokens parsed by it are:
784 - Register displacement (e.g, [fp, #-8])
786 It returns one if the special token has been parsed successfully,
787 or zero if the current token is not considered special. */
789 static expr::operation_up
790 aarch64_stap_parse_special_token (struct gdbarch *gdbarch,
791 struct stap_parse_info *p)
793 if (*p->arg == '[')
795 /* Temporary holder for lookahead. */
796 const char *tmp = p->arg;
797 char *endp;
798 /* Used to save the register name. */
799 const char *start;
800 int len;
801 int got_minus = 0;
802 long displacement;
804 ++tmp;
805 start = tmp;
807 /* Register name. */
808 while (isalnum (*tmp))
809 ++tmp;
811 if (*tmp != ',')
812 return {};
814 len = tmp - start;
815 std::string regname (start, len);
817 if (user_reg_map_name_to_regnum (gdbarch, regname.c_str (), len) == -1)
818 error (_("Invalid register name `%s' on expression `%s'."),
819 regname.c_str (), p->saved_arg);
821 ++tmp;
822 tmp = skip_spaces (tmp);
823 /* Now we expect a number. It can begin with '#' or simply
824 a digit. */
825 if (*tmp == '#')
826 ++tmp;
828 if (*tmp == '-')
830 ++tmp;
831 got_minus = 1;
833 else if (*tmp == '+')
834 ++tmp;
836 if (!isdigit (*tmp))
837 return {};
839 displacement = strtol (tmp, &endp, 10);
840 tmp = endp;
842 /* Skipping last `]'. */
843 if (*tmp++ != ']')
844 return {};
845 p->arg = tmp;
847 using namespace expr;
849 /* The displacement. */
850 struct type *long_type = builtin_type (gdbarch)->builtin_long;
851 if (got_minus)
852 displacement = -displacement;
853 operation_up disp = make_operation<long_const_operation> (long_type,
854 displacement);
856 /* The register name. */
857 operation_up reg
858 = make_operation<register_operation> (std::move (regname));
860 operation_up sum
861 = make_operation<add_operation> (std::move (reg), std::move (disp));
863 /* Casting to the expected type. */
864 struct type *arg_ptr_type = lookup_pointer_type (p->arg_type);
865 sum = make_operation<unop_cast_operation> (std::move (sum),
866 arg_ptr_type);
867 return make_operation<unop_ind_operation> (std::move (sum));
869 return {};
872 /* AArch64 process record-replay constructs: syscall, signal etc. */
874 static linux_record_tdep aarch64_linux_record_tdep;
876 /* Enum that defines the AArch64 linux specific syscall identifiers used for
877 process record/replay. */
879 enum aarch64_syscall {
880 aarch64_sys_io_setup = 0,
881 aarch64_sys_io_destroy = 1,
882 aarch64_sys_io_submit = 2,
883 aarch64_sys_io_cancel = 3,
884 aarch64_sys_io_getevents = 4,
885 aarch64_sys_setxattr = 5,
886 aarch64_sys_lsetxattr = 6,
887 aarch64_sys_fsetxattr = 7,
888 aarch64_sys_getxattr = 8,
889 aarch64_sys_lgetxattr = 9,
890 aarch64_sys_fgetxattr = 10,
891 aarch64_sys_listxattr = 11,
892 aarch64_sys_llistxattr = 12,
893 aarch64_sys_flistxattr = 13,
894 aarch64_sys_removexattr = 14,
895 aarch64_sys_lremovexattr = 15,
896 aarch64_sys_fremovexattr = 16,
897 aarch64_sys_getcwd = 17,
898 aarch64_sys_lookup_dcookie = 18,
899 aarch64_sys_eventfd2 = 19,
900 aarch64_sys_epoll_create1 = 20,
901 aarch64_sys_epoll_ctl = 21,
902 aarch64_sys_epoll_pwait = 22,
903 aarch64_sys_dup = 23,
904 aarch64_sys_dup3 = 24,
905 aarch64_sys_fcntl = 25,
906 aarch64_sys_inotify_init1 = 26,
907 aarch64_sys_inotify_add_watch = 27,
908 aarch64_sys_inotify_rm_watch = 28,
909 aarch64_sys_ioctl = 29,
910 aarch64_sys_ioprio_set = 30,
911 aarch64_sys_ioprio_get = 31,
912 aarch64_sys_flock = 32,
913 aarch64_sys_mknodat = 33,
914 aarch64_sys_mkdirat = 34,
915 aarch64_sys_unlinkat = 35,
916 aarch64_sys_symlinkat = 36,
917 aarch64_sys_linkat = 37,
918 aarch64_sys_renameat = 38,
919 aarch64_sys_umount2 = 39,
920 aarch64_sys_mount = 40,
921 aarch64_sys_pivot_root = 41,
922 aarch64_sys_nfsservctl = 42,
923 aarch64_sys_statfs = 43,
924 aarch64_sys_fstatfs = 44,
925 aarch64_sys_truncate = 45,
926 aarch64_sys_ftruncate = 46,
927 aarch64_sys_fallocate = 47,
928 aarch64_sys_faccessat = 48,
929 aarch64_sys_chdir = 49,
930 aarch64_sys_fchdir = 50,
931 aarch64_sys_chroot = 51,
932 aarch64_sys_fchmod = 52,
933 aarch64_sys_fchmodat = 53,
934 aarch64_sys_fchownat = 54,
935 aarch64_sys_fchown = 55,
936 aarch64_sys_openat = 56,
937 aarch64_sys_close = 57,
938 aarch64_sys_vhangup = 58,
939 aarch64_sys_pipe2 = 59,
940 aarch64_sys_quotactl = 60,
941 aarch64_sys_getdents64 = 61,
942 aarch64_sys_lseek = 62,
943 aarch64_sys_read = 63,
944 aarch64_sys_write = 64,
945 aarch64_sys_readv = 65,
946 aarch64_sys_writev = 66,
947 aarch64_sys_pread64 = 67,
948 aarch64_sys_pwrite64 = 68,
949 aarch64_sys_preadv = 69,
950 aarch64_sys_pwritev = 70,
951 aarch64_sys_sendfile = 71,
952 aarch64_sys_pselect6 = 72,
953 aarch64_sys_ppoll = 73,
954 aarch64_sys_signalfd4 = 74,
955 aarch64_sys_vmsplice = 75,
956 aarch64_sys_splice = 76,
957 aarch64_sys_tee = 77,
958 aarch64_sys_readlinkat = 78,
959 aarch64_sys_newfstatat = 79,
960 aarch64_sys_fstat = 80,
961 aarch64_sys_sync = 81,
962 aarch64_sys_fsync = 82,
963 aarch64_sys_fdatasync = 83,
964 aarch64_sys_sync_file_range2 = 84,
965 aarch64_sys_sync_file_range = 84,
966 aarch64_sys_timerfd_create = 85,
967 aarch64_sys_timerfd_settime = 86,
968 aarch64_sys_timerfd_gettime = 87,
969 aarch64_sys_utimensat = 88,
970 aarch64_sys_acct = 89,
971 aarch64_sys_capget = 90,
972 aarch64_sys_capset = 91,
973 aarch64_sys_personality = 92,
974 aarch64_sys_exit = 93,
975 aarch64_sys_exit_group = 94,
976 aarch64_sys_waitid = 95,
977 aarch64_sys_set_tid_address = 96,
978 aarch64_sys_unshare = 97,
979 aarch64_sys_futex = 98,
980 aarch64_sys_set_robust_list = 99,
981 aarch64_sys_get_robust_list = 100,
982 aarch64_sys_nanosleep = 101,
983 aarch64_sys_getitimer = 102,
984 aarch64_sys_setitimer = 103,
985 aarch64_sys_kexec_load = 104,
986 aarch64_sys_init_module = 105,
987 aarch64_sys_delete_module = 106,
988 aarch64_sys_timer_create = 107,
989 aarch64_sys_timer_gettime = 108,
990 aarch64_sys_timer_getoverrun = 109,
991 aarch64_sys_timer_settime = 110,
992 aarch64_sys_timer_delete = 111,
993 aarch64_sys_clock_settime = 112,
994 aarch64_sys_clock_gettime = 113,
995 aarch64_sys_clock_getres = 114,
996 aarch64_sys_clock_nanosleep = 115,
997 aarch64_sys_syslog = 116,
998 aarch64_sys_ptrace = 117,
999 aarch64_sys_sched_setparam = 118,
1000 aarch64_sys_sched_setscheduler = 119,
1001 aarch64_sys_sched_getscheduler = 120,
1002 aarch64_sys_sched_getparam = 121,
1003 aarch64_sys_sched_setaffinity = 122,
1004 aarch64_sys_sched_getaffinity = 123,
1005 aarch64_sys_sched_yield = 124,
1006 aarch64_sys_sched_get_priority_max = 125,
1007 aarch64_sys_sched_get_priority_min = 126,
1008 aarch64_sys_sched_rr_get_interval = 127,
1009 aarch64_sys_kill = 129,
1010 aarch64_sys_tkill = 130,
1011 aarch64_sys_tgkill = 131,
1012 aarch64_sys_sigaltstack = 132,
1013 aarch64_sys_rt_sigsuspend = 133,
1014 aarch64_sys_rt_sigaction = 134,
1015 aarch64_sys_rt_sigprocmask = 135,
1016 aarch64_sys_rt_sigpending = 136,
1017 aarch64_sys_rt_sigtimedwait = 137,
1018 aarch64_sys_rt_sigqueueinfo = 138,
1019 aarch64_sys_rt_sigreturn = 139,
1020 aarch64_sys_setpriority = 140,
1021 aarch64_sys_getpriority = 141,
1022 aarch64_sys_reboot = 142,
1023 aarch64_sys_setregid = 143,
1024 aarch64_sys_setgid = 144,
1025 aarch64_sys_setreuid = 145,
1026 aarch64_sys_setuid = 146,
1027 aarch64_sys_setresuid = 147,
1028 aarch64_sys_getresuid = 148,
1029 aarch64_sys_setresgid = 149,
1030 aarch64_sys_getresgid = 150,
1031 aarch64_sys_setfsuid = 151,
1032 aarch64_sys_setfsgid = 152,
1033 aarch64_sys_times = 153,
1034 aarch64_sys_setpgid = 154,
1035 aarch64_sys_getpgid = 155,
1036 aarch64_sys_getsid = 156,
1037 aarch64_sys_setsid = 157,
1038 aarch64_sys_getgroups = 158,
1039 aarch64_sys_setgroups = 159,
1040 aarch64_sys_uname = 160,
1041 aarch64_sys_sethostname = 161,
1042 aarch64_sys_setdomainname = 162,
1043 aarch64_sys_getrlimit = 163,
1044 aarch64_sys_setrlimit = 164,
1045 aarch64_sys_getrusage = 165,
1046 aarch64_sys_umask = 166,
1047 aarch64_sys_prctl = 167,
1048 aarch64_sys_getcpu = 168,
1049 aarch64_sys_gettimeofday = 169,
1050 aarch64_sys_settimeofday = 170,
1051 aarch64_sys_adjtimex = 171,
1052 aarch64_sys_getpid = 172,
1053 aarch64_sys_getppid = 173,
1054 aarch64_sys_getuid = 174,
1055 aarch64_sys_geteuid = 175,
1056 aarch64_sys_getgid = 176,
1057 aarch64_sys_getegid = 177,
1058 aarch64_sys_gettid = 178,
1059 aarch64_sys_sysinfo = 179,
1060 aarch64_sys_mq_open = 180,
1061 aarch64_sys_mq_unlink = 181,
1062 aarch64_sys_mq_timedsend = 182,
1063 aarch64_sys_mq_timedreceive = 183,
1064 aarch64_sys_mq_notify = 184,
1065 aarch64_sys_mq_getsetattr = 185,
1066 aarch64_sys_msgget = 186,
1067 aarch64_sys_msgctl = 187,
1068 aarch64_sys_msgrcv = 188,
1069 aarch64_sys_msgsnd = 189,
1070 aarch64_sys_semget = 190,
1071 aarch64_sys_semctl = 191,
1072 aarch64_sys_semtimedop = 192,
1073 aarch64_sys_semop = 193,
1074 aarch64_sys_shmget = 194,
1075 aarch64_sys_shmctl = 195,
1076 aarch64_sys_shmat = 196,
1077 aarch64_sys_shmdt = 197,
1078 aarch64_sys_socket = 198,
1079 aarch64_sys_socketpair = 199,
1080 aarch64_sys_bind = 200,
1081 aarch64_sys_listen = 201,
1082 aarch64_sys_accept = 202,
1083 aarch64_sys_connect = 203,
1084 aarch64_sys_getsockname = 204,
1085 aarch64_sys_getpeername = 205,
1086 aarch64_sys_sendto = 206,
1087 aarch64_sys_recvfrom = 207,
1088 aarch64_sys_setsockopt = 208,
1089 aarch64_sys_getsockopt = 209,
1090 aarch64_sys_shutdown = 210,
1091 aarch64_sys_sendmsg = 211,
1092 aarch64_sys_recvmsg = 212,
1093 aarch64_sys_readahead = 213,
1094 aarch64_sys_brk = 214,
1095 aarch64_sys_munmap = 215,
1096 aarch64_sys_mremap = 216,
1097 aarch64_sys_add_key = 217,
1098 aarch64_sys_request_key = 218,
1099 aarch64_sys_keyctl = 219,
1100 aarch64_sys_clone = 220,
1101 aarch64_sys_execve = 221,
1102 aarch64_sys_mmap = 222,
1103 aarch64_sys_fadvise64 = 223,
1104 aarch64_sys_swapon = 224,
1105 aarch64_sys_swapoff = 225,
1106 aarch64_sys_mprotect = 226,
1107 aarch64_sys_msync = 227,
1108 aarch64_sys_mlock = 228,
1109 aarch64_sys_munlock = 229,
1110 aarch64_sys_mlockall = 230,
1111 aarch64_sys_munlockall = 231,
1112 aarch64_sys_mincore = 232,
1113 aarch64_sys_madvise = 233,
1114 aarch64_sys_remap_file_pages = 234,
1115 aarch64_sys_mbind = 235,
1116 aarch64_sys_get_mempolicy = 236,
1117 aarch64_sys_set_mempolicy = 237,
1118 aarch64_sys_migrate_pages = 238,
1119 aarch64_sys_move_pages = 239,
1120 aarch64_sys_rt_tgsigqueueinfo = 240,
1121 aarch64_sys_perf_event_open = 241,
1122 aarch64_sys_accept4 = 242,
1123 aarch64_sys_recvmmsg = 243,
1124 aarch64_sys_wait4 = 260,
1125 aarch64_sys_prlimit64 = 261,
1126 aarch64_sys_fanotify_init = 262,
1127 aarch64_sys_fanotify_mark = 263,
1128 aarch64_sys_name_to_handle_at = 264,
1129 aarch64_sys_open_by_handle_at = 265,
1130 aarch64_sys_clock_adjtime = 266,
1131 aarch64_sys_syncfs = 267,
1132 aarch64_sys_setns = 268,
1133 aarch64_sys_sendmmsg = 269,
1134 aarch64_sys_process_vm_readv = 270,
1135 aarch64_sys_process_vm_writev = 271,
1136 aarch64_sys_kcmp = 272,
1137 aarch64_sys_finit_module = 273,
1138 aarch64_sys_sched_setattr = 274,
1139 aarch64_sys_sched_getattr = 275,
1142 /* aarch64_canonicalize_syscall maps syscall ids from the native AArch64
1143 linux set of syscall ids into a canonical set of syscall ids used by
1144 process record. */
1146 static enum gdb_syscall
1147 aarch64_canonicalize_syscall (enum aarch64_syscall syscall_number)
1149 #define SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
1150 return gdb_sys_##SYSCALL
1152 #define UNSUPPORTED_SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
1153 return gdb_sys_no_syscall
1155 switch (syscall_number)
1157 SYSCALL_MAP (io_setup);
1158 SYSCALL_MAP (io_destroy);
1159 SYSCALL_MAP (io_submit);
1160 SYSCALL_MAP (io_cancel);
1161 SYSCALL_MAP (io_getevents);
1163 SYSCALL_MAP (setxattr);
1164 SYSCALL_MAP (lsetxattr);
1165 SYSCALL_MAP (fsetxattr);
1166 SYSCALL_MAP (getxattr);
1167 SYSCALL_MAP (lgetxattr);
1168 SYSCALL_MAP (fgetxattr);
1169 SYSCALL_MAP (listxattr);
1170 SYSCALL_MAP (llistxattr);
1171 SYSCALL_MAP (flistxattr);
1172 SYSCALL_MAP (removexattr);
1173 SYSCALL_MAP (lremovexattr);
1174 SYSCALL_MAP (fremovexattr);
1175 SYSCALL_MAP (getcwd);
1176 SYSCALL_MAP (lookup_dcookie);
1177 SYSCALL_MAP (eventfd2);
1178 SYSCALL_MAP (epoll_create1);
1179 SYSCALL_MAP (epoll_ctl);
1180 SYSCALL_MAP (epoll_pwait);
1181 SYSCALL_MAP (dup);
1182 SYSCALL_MAP (dup3);
1183 SYSCALL_MAP (fcntl);
1184 SYSCALL_MAP (inotify_init1);
1185 SYSCALL_MAP (inotify_add_watch);
1186 SYSCALL_MAP (inotify_rm_watch);
1187 SYSCALL_MAP (ioctl);
1188 SYSCALL_MAP (ioprio_set);
1189 SYSCALL_MAP (ioprio_get);
1190 SYSCALL_MAP (flock);
1191 SYSCALL_MAP (mknodat);
1192 SYSCALL_MAP (mkdirat);
1193 SYSCALL_MAP (unlinkat);
1194 SYSCALL_MAP (symlinkat);
1195 SYSCALL_MAP (linkat);
1196 SYSCALL_MAP (renameat);
1197 UNSUPPORTED_SYSCALL_MAP (umount2);
1198 SYSCALL_MAP (mount);
1199 SYSCALL_MAP (pivot_root);
1200 SYSCALL_MAP (nfsservctl);
1201 SYSCALL_MAP (statfs);
1202 SYSCALL_MAP (truncate);
1203 SYSCALL_MAP (ftruncate);
1204 SYSCALL_MAP (fallocate);
1205 SYSCALL_MAP (faccessat);
1206 SYSCALL_MAP (fchdir);
1207 SYSCALL_MAP (chroot);
1208 SYSCALL_MAP (fchmod);
1209 SYSCALL_MAP (fchmodat);
1210 SYSCALL_MAP (fchownat);
1211 SYSCALL_MAP (fchown);
1212 SYSCALL_MAP (openat);
1213 SYSCALL_MAP (close);
1214 SYSCALL_MAP (vhangup);
1215 SYSCALL_MAP (pipe2);
1216 SYSCALL_MAP (quotactl);
1217 SYSCALL_MAP (getdents64);
1218 SYSCALL_MAP (lseek);
1219 SYSCALL_MAP (read);
1220 SYSCALL_MAP (write);
1221 SYSCALL_MAP (readv);
1222 SYSCALL_MAP (writev);
1223 SYSCALL_MAP (pread64);
1224 SYSCALL_MAP (pwrite64);
1225 UNSUPPORTED_SYSCALL_MAP (preadv);
1226 UNSUPPORTED_SYSCALL_MAP (pwritev);
1227 SYSCALL_MAP (sendfile);
1228 SYSCALL_MAP (pselect6);
1229 SYSCALL_MAP (ppoll);
1230 UNSUPPORTED_SYSCALL_MAP (signalfd4);
1231 SYSCALL_MAP (vmsplice);
1232 SYSCALL_MAP (splice);
1233 SYSCALL_MAP (tee);
1234 SYSCALL_MAP (readlinkat);
1235 SYSCALL_MAP (newfstatat);
1237 SYSCALL_MAP (fstat);
1238 SYSCALL_MAP (sync);
1239 SYSCALL_MAP (fsync);
1240 SYSCALL_MAP (fdatasync);
1241 SYSCALL_MAP (sync_file_range);
1242 UNSUPPORTED_SYSCALL_MAP (timerfd_create);
1243 UNSUPPORTED_SYSCALL_MAP (timerfd_settime);
1244 UNSUPPORTED_SYSCALL_MAP (timerfd_gettime);
1245 UNSUPPORTED_SYSCALL_MAP (utimensat);
1246 SYSCALL_MAP (acct);
1247 SYSCALL_MAP (capget);
1248 SYSCALL_MAP (capset);
1249 SYSCALL_MAP (personality);
1250 SYSCALL_MAP (exit);
1251 SYSCALL_MAP (exit_group);
1252 SYSCALL_MAP (waitid);
1253 SYSCALL_MAP (set_tid_address);
1254 SYSCALL_MAP (unshare);
1255 SYSCALL_MAP (futex);
1256 SYSCALL_MAP (set_robust_list);
1257 SYSCALL_MAP (get_robust_list);
1258 SYSCALL_MAP (nanosleep);
1260 SYSCALL_MAP (getitimer);
1261 SYSCALL_MAP (setitimer);
1262 SYSCALL_MAP (kexec_load);
1263 SYSCALL_MAP (init_module);
1264 SYSCALL_MAP (delete_module);
1265 SYSCALL_MAP (timer_create);
1266 SYSCALL_MAP (timer_settime);
1267 SYSCALL_MAP (timer_gettime);
1268 SYSCALL_MAP (timer_getoverrun);
1269 SYSCALL_MAP (timer_delete);
1270 SYSCALL_MAP (clock_settime);
1271 SYSCALL_MAP (clock_gettime);
1272 SYSCALL_MAP (clock_getres);
1273 SYSCALL_MAP (clock_nanosleep);
1274 SYSCALL_MAP (syslog);
1275 SYSCALL_MAP (ptrace);
1276 SYSCALL_MAP (sched_setparam);
1277 SYSCALL_MAP (sched_setscheduler);
1278 SYSCALL_MAP (sched_getscheduler);
1279 SYSCALL_MAP (sched_getparam);
1280 SYSCALL_MAP (sched_setaffinity);
1281 SYSCALL_MAP (sched_getaffinity);
1282 SYSCALL_MAP (sched_yield);
1283 SYSCALL_MAP (sched_get_priority_max);
1284 SYSCALL_MAP (sched_get_priority_min);
1285 SYSCALL_MAP (sched_rr_get_interval);
1286 SYSCALL_MAP (kill);
1287 SYSCALL_MAP (tkill);
1288 SYSCALL_MAP (tgkill);
1289 SYSCALL_MAP (sigaltstack);
1290 SYSCALL_MAP (rt_sigsuspend);
1291 SYSCALL_MAP (rt_sigaction);
1292 SYSCALL_MAP (rt_sigprocmask);
1293 SYSCALL_MAP (rt_sigpending);
1294 SYSCALL_MAP (rt_sigtimedwait);
1295 SYSCALL_MAP (rt_sigqueueinfo);
1296 SYSCALL_MAP (rt_sigreturn);
1297 SYSCALL_MAP (setpriority);
1298 SYSCALL_MAP (getpriority);
1299 SYSCALL_MAP (reboot);
1300 SYSCALL_MAP (setregid);
1301 SYSCALL_MAP (setgid);
1302 SYSCALL_MAP (setreuid);
1303 SYSCALL_MAP (setuid);
1304 SYSCALL_MAP (setresuid);
1305 SYSCALL_MAP (getresuid);
1306 SYSCALL_MAP (setresgid);
1307 SYSCALL_MAP (getresgid);
1308 SYSCALL_MAP (setfsuid);
1309 SYSCALL_MAP (setfsgid);
1310 SYSCALL_MAP (times);
1311 SYSCALL_MAP (setpgid);
1312 SYSCALL_MAP (getpgid);
1313 SYSCALL_MAP (getsid);
1314 SYSCALL_MAP (setsid);
1315 SYSCALL_MAP (getgroups);
1316 SYSCALL_MAP (setgroups);
1317 SYSCALL_MAP (uname);
1318 SYSCALL_MAP (sethostname);
1319 SYSCALL_MAP (setdomainname);
1320 SYSCALL_MAP (getrlimit);
1321 SYSCALL_MAP (setrlimit);
1322 SYSCALL_MAP (getrusage);
1323 SYSCALL_MAP (umask);
1324 SYSCALL_MAP (prctl);
1325 SYSCALL_MAP (getcpu);
1326 SYSCALL_MAP (gettimeofday);
1327 SYSCALL_MAP (settimeofday);
1328 SYSCALL_MAP (adjtimex);
1329 SYSCALL_MAP (getpid);
1330 SYSCALL_MAP (getppid);
1331 SYSCALL_MAP (getuid);
1332 SYSCALL_MAP (geteuid);
1333 SYSCALL_MAP (getgid);
1334 SYSCALL_MAP (getegid);
1335 SYSCALL_MAP (gettid);
1336 SYSCALL_MAP (sysinfo);
1337 SYSCALL_MAP (mq_open);
1338 SYSCALL_MAP (mq_unlink);
1339 SYSCALL_MAP (mq_timedsend);
1340 SYSCALL_MAP (mq_timedreceive);
1341 SYSCALL_MAP (mq_notify);
1342 SYSCALL_MAP (mq_getsetattr);
1343 SYSCALL_MAP (msgget);
1344 SYSCALL_MAP (msgctl);
1345 SYSCALL_MAP (msgrcv);
1346 SYSCALL_MAP (msgsnd);
1347 SYSCALL_MAP (semget);
1348 SYSCALL_MAP (semctl);
1349 SYSCALL_MAP (semtimedop);
1350 SYSCALL_MAP (semop);
1351 SYSCALL_MAP (shmget);
1352 SYSCALL_MAP (shmctl);
1353 SYSCALL_MAP (shmat);
1354 SYSCALL_MAP (shmdt);
1355 SYSCALL_MAP (socket);
1356 SYSCALL_MAP (socketpair);
1357 SYSCALL_MAP (bind);
1358 SYSCALL_MAP (listen);
1359 SYSCALL_MAP (accept);
1360 SYSCALL_MAP (connect);
1361 SYSCALL_MAP (getsockname);
1362 SYSCALL_MAP (getpeername);
1363 SYSCALL_MAP (sendto);
1364 SYSCALL_MAP (recvfrom);
1365 SYSCALL_MAP (setsockopt);
1366 SYSCALL_MAP (getsockopt);
1367 SYSCALL_MAP (shutdown);
1368 SYSCALL_MAP (sendmsg);
1369 SYSCALL_MAP (recvmsg);
1370 SYSCALL_MAP (readahead);
1371 SYSCALL_MAP (brk);
1372 SYSCALL_MAP (munmap);
1373 SYSCALL_MAP (mremap);
1374 SYSCALL_MAP (add_key);
1375 SYSCALL_MAP (request_key);
1376 SYSCALL_MAP (keyctl);
1377 SYSCALL_MAP (clone);
1378 SYSCALL_MAP (execve);
1380 case aarch64_sys_mmap:
1381 return gdb_sys_mmap2;
1383 SYSCALL_MAP (fadvise64);
1384 SYSCALL_MAP (swapon);
1385 SYSCALL_MAP (swapoff);
1386 SYSCALL_MAP (mprotect);
1387 SYSCALL_MAP (msync);
1388 SYSCALL_MAP (mlock);
1389 SYSCALL_MAP (munlock);
1390 SYSCALL_MAP (mlockall);
1391 SYSCALL_MAP (munlockall);
1392 SYSCALL_MAP (mincore);
1393 SYSCALL_MAP (madvise);
1394 SYSCALL_MAP (remap_file_pages);
1395 SYSCALL_MAP (mbind);
1396 SYSCALL_MAP (get_mempolicy);
1397 SYSCALL_MAP (set_mempolicy);
1398 SYSCALL_MAP (migrate_pages);
1399 SYSCALL_MAP (move_pages);
1400 UNSUPPORTED_SYSCALL_MAP (rt_tgsigqueueinfo);
1401 UNSUPPORTED_SYSCALL_MAP (perf_event_open);
1402 UNSUPPORTED_SYSCALL_MAP (accept4);
1403 UNSUPPORTED_SYSCALL_MAP (recvmmsg);
1405 SYSCALL_MAP (wait4);
1407 UNSUPPORTED_SYSCALL_MAP (prlimit64);
1408 UNSUPPORTED_SYSCALL_MAP (fanotify_init);
1409 UNSUPPORTED_SYSCALL_MAP (fanotify_mark);
1410 UNSUPPORTED_SYSCALL_MAP (name_to_handle_at);
1411 UNSUPPORTED_SYSCALL_MAP (open_by_handle_at);
1412 UNSUPPORTED_SYSCALL_MAP (clock_adjtime);
1413 UNSUPPORTED_SYSCALL_MAP (syncfs);
1414 UNSUPPORTED_SYSCALL_MAP (setns);
1415 UNSUPPORTED_SYSCALL_MAP (sendmmsg);
1416 UNSUPPORTED_SYSCALL_MAP (process_vm_readv);
1417 UNSUPPORTED_SYSCALL_MAP (process_vm_writev);
1418 UNSUPPORTED_SYSCALL_MAP (kcmp);
1419 UNSUPPORTED_SYSCALL_MAP (finit_module);
1420 UNSUPPORTED_SYSCALL_MAP (sched_setattr);
1421 UNSUPPORTED_SYSCALL_MAP (sched_getattr);
1422 default:
1423 return gdb_sys_no_syscall;
1427 /* Retrieve the syscall number at a ptrace syscall-stop, either on syscall entry
1428 or exit. Return -1 upon error. */
1430 static LONGEST
1431 aarch64_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
1433 struct regcache *regs = get_thread_regcache (thread);
1434 LONGEST ret;
1436 /* Get the system call number from register x8. */
1437 regs->cooked_read (AARCH64_X0_REGNUM + 8, &ret);
1439 /* On exit from a successful execve, we will be in a new process and all the
1440 registers will be cleared - x0 to x30 will be 0, except for a 1 in x7.
1441 This function will only ever get called when stopped at the entry or exit
1442 of a syscall, so by checking for 0 in x0 (arg0/retval), x1 (arg1), x8
1443 (syscall), x29 (FP) and x30 (LR) we can infer:
1444 1) Either inferior is at exit from successful execve.
1445 2) Or inferior is at entry to a call to io_setup with invalid arguments and
1446 a corrupted FP and LR.
1447 It should be safe enough to assume case 1. */
1448 if (ret == 0)
1450 LONGEST x1 = -1, fp = -1, lr = -1;
1451 regs->cooked_read (AARCH64_X0_REGNUM + 1, &x1);
1452 regs->cooked_read (AARCH64_FP_REGNUM, &fp);
1453 regs->cooked_read (AARCH64_LR_REGNUM, &lr);
1454 if (x1 == 0 && fp ==0 && lr == 0)
1455 return aarch64_sys_execve;
1458 return ret;
1461 /* Record all registers but PC register for process-record. */
1463 static int
1464 aarch64_all_but_pc_registers_record (struct regcache *regcache)
1466 int i;
1468 for (i = AARCH64_X0_REGNUM; i < AARCH64_PC_REGNUM; i++)
1469 if (record_full_arch_list_add_reg (regcache, i))
1470 return -1;
1472 if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM))
1473 return -1;
1475 return 0;
1478 /* Handler for aarch64 system call instruction recording. */
1480 static int
1481 aarch64_linux_syscall_record (struct regcache *regcache,
1482 unsigned long svc_number)
1484 int ret = 0;
1485 enum gdb_syscall syscall_gdb;
1487 syscall_gdb =
1488 aarch64_canonicalize_syscall ((enum aarch64_syscall) svc_number);
1490 if (syscall_gdb < 0)
1492 gdb_printf (gdb_stderr,
1493 _("Process record and replay target doesn't "
1494 "support syscall number %s\n"),
1495 plongest (svc_number));
1496 return -1;
1499 if (syscall_gdb == gdb_sys_sigreturn
1500 || syscall_gdb == gdb_sys_rt_sigreturn)
1502 if (aarch64_all_but_pc_registers_record (regcache))
1503 return -1;
1504 return 0;
1507 ret = record_linux_system_call (syscall_gdb, regcache,
1508 &aarch64_linux_record_tdep);
1509 if (ret != 0)
1510 return ret;
1512 /* Record the return value of the system call. */
1513 if (record_full_arch_list_add_reg (regcache, AARCH64_X0_REGNUM))
1514 return -1;
1515 /* Record LR. */
1516 if (record_full_arch_list_add_reg (regcache, AARCH64_LR_REGNUM))
1517 return -1;
1518 /* Record CPSR. */
1519 if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM))
1520 return -1;
1522 return 0;
1525 /* Implement the "gcc_target_options" gdbarch method. */
1527 static std::string
1528 aarch64_linux_gcc_target_options (struct gdbarch *gdbarch)
1530 /* GCC doesn't know "-m64". */
1531 return {};
1534 /* Helper to get the allocation tag from a 64-bit ADDRESS.
1536 Return the allocation tag if successful and nullopt otherwise. */
1538 static gdb::optional<CORE_ADDR>
1539 aarch64_mte_get_atag (CORE_ADDR address)
1541 gdb::byte_vector tags;
1543 /* Attempt to fetch the allocation tag. */
1544 if (!target_fetch_memtags (address, 1, tags,
1545 static_cast<int> (memtag_type::allocation)))
1546 return {};
1548 /* Only one tag should've been returned. Make sure we got exactly that. */
1549 if (tags.size () != 1)
1550 error (_("Target returned an unexpected number of tags."));
1552 /* Although our tags are 4 bits in size, they are stored in a
1553 byte. */
1554 return tags[0];
1557 /* Implement the tagged_address_p gdbarch method. */
1559 static bool
1560 aarch64_linux_tagged_address_p (struct gdbarch *gdbarch, struct value *address)
1562 gdb_assert (address != nullptr);
1564 CORE_ADDR addr = value_as_address (address);
1566 /* Remove the top byte for the memory range check. */
1567 addr = address_significant (gdbarch, addr);
1569 /* Check if the page that contains ADDRESS is mapped with PROT_MTE. */
1570 if (!linux_address_in_memtag_page (addr))
1571 return false;
1573 /* We have a valid tag in the top byte of the 64-bit address. */
1574 return true;
1577 /* Implement the memtag_matches_p gdbarch method. */
1579 static bool
1580 aarch64_linux_memtag_matches_p (struct gdbarch *gdbarch,
1581 struct value *address)
1583 gdb_assert (address != nullptr);
1585 /* Make sure we are dealing with a tagged address to begin with. */
1586 if (!aarch64_linux_tagged_address_p (gdbarch, address))
1587 return true;
1589 CORE_ADDR addr = value_as_address (address);
1591 /* Fetch the allocation tag for ADDRESS. */
1592 gdb::optional<CORE_ADDR> atag
1593 = aarch64_mte_get_atag (address_significant (gdbarch, addr));
1595 if (!atag.has_value ())
1596 return true;
1598 /* Fetch the logical tag for ADDRESS. */
1599 gdb_byte ltag = aarch64_mte_get_ltag (addr);
1601 /* Are the tags the same? */
1602 return ltag == *atag;
1605 /* Implement the set_memtags gdbarch method. */
1607 static bool
1608 aarch64_linux_set_memtags (struct gdbarch *gdbarch, struct value *address,
1609 size_t length, const gdb::byte_vector &tags,
1610 memtag_type tag_type)
1612 gdb_assert (!tags.empty ());
1613 gdb_assert (address != nullptr);
1615 CORE_ADDR addr = value_as_address (address);
1617 /* Set the logical tag or the allocation tag. */
1618 if (tag_type == memtag_type::logical)
1620 /* When setting logical tags, we don't care about the length, since
1621 we are only setting a single logical tag. */
1622 addr = aarch64_mte_set_ltag (addr, tags[0]);
1624 /* Update the value's content with the tag. */
1625 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1626 gdb_byte *srcbuf = value_contents_raw (address).data ();
1627 store_unsigned_integer (srcbuf, sizeof (addr), byte_order, addr);
1629 else
1631 /* Remove the top byte. */
1632 addr = address_significant (gdbarch, addr);
1634 /* Make sure we are dealing with a tagged address to begin with. */
1635 if (!aarch64_linux_tagged_address_p (gdbarch, address))
1636 return false;
1638 /* With G being the number of tag granules and N the number of tags
1639 passed in, we can have the following cases:
1641 1 - G == N: Store all the N tags to memory.
1643 2 - G < N : Warn about having more tags than granules, but write G
1644 tags.
1646 3 - G > N : This is a "fill tags" operation. We should use the tags
1647 as a pattern to fill the granules repeatedly until we have
1648 written G tags to memory.
1651 size_t g = aarch64_mte_get_tag_granules (addr, length,
1652 AARCH64_MTE_GRANULE_SIZE);
1653 size_t n = tags.size ();
1655 if (g < n)
1656 warning (_("Got more tags than memory granules. Tags will be "
1657 "truncated."));
1658 else if (g > n)
1659 warning (_("Using tag pattern to fill memory range."));
1661 if (!target_store_memtags (addr, length, tags,
1662 static_cast<int> (memtag_type::allocation)))
1663 return false;
1665 return true;
1668 /* Implement the get_memtag gdbarch method. */
1670 static struct value *
1671 aarch64_linux_get_memtag (struct gdbarch *gdbarch, struct value *address,
1672 memtag_type tag_type)
1674 gdb_assert (address != nullptr);
1676 CORE_ADDR addr = value_as_address (address);
1677 CORE_ADDR tag = 0;
1679 /* Get the logical tag or the allocation tag. */
1680 if (tag_type == memtag_type::logical)
1681 tag = aarch64_mte_get_ltag (addr);
1682 else
1684 /* Make sure we are dealing with a tagged address to begin with. */
1685 if (!aarch64_linux_tagged_address_p (gdbarch, address))
1686 return nullptr;
1688 /* Remove the top byte. */
1689 addr = address_significant (gdbarch, addr);
1690 gdb::optional<CORE_ADDR> atag = aarch64_mte_get_atag (addr);
1692 if (!atag.has_value ())
1693 return nullptr;
1695 tag = *atag;
1698 /* Convert the tag to a value. */
1699 return value_from_ulongest (builtin_type (gdbarch)->builtin_unsigned_int,
1700 tag);
1703 /* Implement the memtag_to_string gdbarch method. */
1705 static std::string
1706 aarch64_linux_memtag_to_string (struct gdbarch *gdbarch, struct value *tag_value)
1708 if (tag_value == nullptr)
1709 return "";
1711 CORE_ADDR tag = value_as_address (tag_value);
1713 return string_printf ("0x%s", phex_nz (tag, sizeof (tag)));
1716 /* AArch64 Linux implementation of the report_signal_info gdbarch
1717 hook. Displays information about possible memory tag violations. */
1719 static void
1720 aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
1721 struct ui_out *uiout,
1722 enum gdb_signal siggnal)
1724 aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
1726 if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
1727 return;
1729 CORE_ADDR fault_addr = 0;
1730 long si_code = 0;
1734 /* Sigcode tells us if the segfault is actually a memory tag
1735 violation. */
1736 si_code = parse_and_eval_long ("$_siginfo.si_code");
1738 fault_addr
1739 = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
1741 catch (const gdb_exception_error &exception)
1743 exception_print (gdb_stderr, exception);
1744 return;
1747 /* If this is not a memory tag violation, just return. */
1748 if (si_code != SEGV_MTEAERR && si_code != SEGV_MTESERR)
1749 return;
1751 uiout->text ("\n");
1753 uiout->field_string ("sigcode-meaning", _("Memory tag violation"));
1755 /* For synchronous faults, show additional information. */
1756 if (si_code == SEGV_MTESERR)
1758 uiout->text (_(" while accessing address "));
1759 uiout->field_core_addr ("fault-addr", gdbarch, fault_addr);
1760 uiout->text ("\n");
1762 gdb::optional<CORE_ADDR> atag
1763 = aarch64_mte_get_atag (address_significant (gdbarch, fault_addr));
1764 gdb_byte ltag = aarch64_mte_get_ltag (fault_addr);
1766 if (!atag.has_value ())
1767 uiout->text (_("Allocation tag unavailable"));
1768 else
1770 uiout->text (_("Allocation tag "));
1771 uiout->field_string ("allocation-tag", hex_string (*atag));
1772 uiout->text ("\n");
1773 uiout->text (_("Logical tag "));
1774 uiout->field_string ("logical-tag", hex_string (ltag));
1777 else
1779 uiout->text ("\n");
1780 uiout->text (_("Fault address unavailable"));
1784 static void
1785 aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1787 static const char *const stap_integer_prefixes[] = { "#", "", NULL };
1788 static const char *const stap_register_prefixes[] = { "", NULL };
1789 static const char *const stap_register_indirection_prefixes[] = { "[",
1790 NULL };
1791 static const char *const stap_register_indirection_suffixes[] = { "]",
1792 NULL };
1793 aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
1795 tdep->lowest_pc = 0x8000;
1797 linux_init_abi (info, gdbarch, 1);
1799 set_solib_svr4_fetch_link_map_offsets (gdbarch,
1800 linux_lp64_fetch_link_map_offsets);
1802 /* Enable TLS support. */
1803 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1804 svr4_fetch_objfile_link_map);
1806 /* Shared library handling. */
1807 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
1808 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
1810 tramp_frame_prepend_unwinder (gdbarch, &aarch64_linux_rt_sigframe);
1812 /* Enable longjmp. */
1813 tdep->jb_pc = 11;
1815 set_gdbarch_iterate_over_regset_sections
1816 (gdbarch, aarch64_linux_iterate_over_regset_sections);
1817 set_gdbarch_core_read_description
1818 (gdbarch, aarch64_linux_core_read_description);
1820 /* SystemTap related. */
1821 set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
1822 set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
1823 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
1824 stap_register_indirection_prefixes);
1825 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
1826 stap_register_indirection_suffixes);
1827 set_gdbarch_stap_is_single_operand (gdbarch, aarch64_stap_is_single_operand);
1828 set_gdbarch_stap_parse_special_token (gdbarch,
1829 aarch64_stap_parse_special_token);
1831 /* Reversible debugging, process record. */
1832 set_gdbarch_process_record (gdbarch, aarch64_process_record);
1833 /* Syscall record. */
1834 tdep->aarch64_syscall_record = aarch64_linux_syscall_record;
1836 /* The top byte of a user space address known as the "tag",
1837 is ignored by the kernel and can be regarded as additional
1838 data associated with the address. */
1839 set_gdbarch_significant_addr_bit (gdbarch, 56);
1841 /* MTE-specific settings and hooks. */
1842 if (tdep->has_mte ())
1844 /* Register a hook for checking if an address is tagged or not. */
1845 set_gdbarch_tagged_address_p (gdbarch, aarch64_linux_tagged_address_p);
1847 /* Register a hook for checking if there is a memory tag match. */
1848 set_gdbarch_memtag_matches_p (gdbarch,
1849 aarch64_linux_memtag_matches_p);
1851 /* Register a hook for setting the logical/allocation tags for
1852 a range of addresses. */
1853 set_gdbarch_set_memtags (gdbarch, aarch64_linux_set_memtags);
1855 /* Register a hook for extracting the logical/allocation tag from an
1856 address. */
1857 set_gdbarch_get_memtag (gdbarch, aarch64_linux_get_memtag);
1859 /* Set the allocation tag granule size to 16 bytes. */
1860 set_gdbarch_memtag_granule_size (gdbarch, AARCH64_MTE_GRANULE_SIZE);
1862 /* Register a hook for converting a memory tag to a string. */
1863 set_gdbarch_memtag_to_string (gdbarch, aarch64_linux_memtag_to_string);
1865 set_gdbarch_report_signal_info (gdbarch,
1866 aarch64_linux_report_signal_info);
1869 /* Initialize the aarch64_linux_record_tdep. */
1870 /* These values are the size of the type that will be used in a system
1871 call. They are obtained from Linux Kernel source. */
1872 aarch64_linux_record_tdep.size_pointer
1873 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
1874 aarch64_linux_record_tdep.size__old_kernel_stat = 32;
1875 aarch64_linux_record_tdep.size_tms = 32;
1876 aarch64_linux_record_tdep.size_loff_t = 8;
1877 aarch64_linux_record_tdep.size_flock = 32;
1878 aarch64_linux_record_tdep.size_oldold_utsname = 45;
1879 aarch64_linux_record_tdep.size_ustat = 32;
1880 aarch64_linux_record_tdep.size_old_sigaction = 32;
1881 aarch64_linux_record_tdep.size_old_sigset_t = 8;
1882 aarch64_linux_record_tdep.size_rlimit = 16;
1883 aarch64_linux_record_tdep.size_rusage = 144;
1884 aarch64_linux_record_tdep.size_timeval = 16;
1885 aarch64_linux_record_tdep.size_timezone = 8;
1886 aarch64_linux_record_tdep.size_old_gid_t = 2;
1887 aarch64_linux_record_tdep.size_old_uid_t = 2;
1888 aarch64_linux_record_tdep.size_fd_set = 128;
1889 aarch64_linux_record_tdep.size_old_dirent = 280;
1890 aarch64_linux_record_tdep.size_statfs = 120;
1891 aarch64_linux_record_tdep.size_statfs64 = 120;
1892 aarch64_linux_record_tdep.size_sockaddr = 16;
1893 aarch64_linux_record_tdep.size_int
1894 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
1895 aarch64_linux_record_tdep.size_long
1896 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
1897 aarch64_linux_record_tdep.size_ulong
1898 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
1899 aarch64_linux_record_tdep.size_msghdr = 56;
1900 aarch64_linux_record_tdep.size_itimerval = 32;
1901 aarch64_linux_record_tdep.size_stat = 144;
1902 aarch64_linux_record_tdep.size_old_utsname = 325;
1903 aarch64_linux_record_tdep.size_sysinfo = 112;
1904 aarch64_linux_record_tdep.size_msqid_ds = 120;
1905 aarch64_linux_record_tdep.size_shmid_ds = 112;
1906 aarch64_linux_record_tdep.size_new_utsname = 390;
1907 aarch64_linux_record_tdep.size_timex = 208;
1908 aarch64_linux_record_tdep.size_mem_dqinfo = 24;
1909 aarch64_linux_record_tdep.size_if_dqblk = 72;
1910 aarch64_linux_record_tdep.size_fs_quota_stat = 80;
1911 aarch64_linux_record_tdep.size_timespec = 16;
1912 aarch64_linux_record_tdep.size_pollfd = 8;
1913 aarch64_linux_record_tdep.size_NFS_FHSIZE = 32;
1914 aarch64_linux_record_tdep.size_knfsd_fh = 132;
1915 aarch64_linux_record_tdep.size_TASK_COMM_LEN = 16;
1916 aarch64_linux_record_tdep.size_sigaction = 32;
1917 aarch64_linux_record_tdep.size_sigset_t = 8;
1918 aarch64_linux_record_tdep.size_siginfo_t = 128;
1919 aarch64_linux_record_tdep.size_cap_user_data_t = 8;
1920 aarch64_linux_record_tdep.size_stack_t = 24;
1921 aarch64_linux_record_tdep.size_off_t = 8;
1922 aarch64_linux_record_tdep.size_stat64 = 144;
1923 aarch64_linux_record_tdep.size_gid_t = 4;
1924 aarch64_linux_record_tdep.size_uid_t = 4;
1925 aarch64_linux_record_tdep.size_PAGE_SIZE = 4096;
1926 aarch64_linux_record_tdep.size_flock64 = 32;
1927 aarch64_linux_record_tdep.size_user_desc = 16;
1928 aarch64_linux_record_tdep.size_io_event = 32;
1929 aarch64_linux_record_tdep.size_iocb = 64;
1930 aarch64_linux_record_tdep.size_epoll_event = 12;
1931 aarch64_linux_record_tdep.size_itimerspec = 32;
1932 aarch64_linux_record_tdep.size_mq_attr = 64;
1933 aarch64_linux_record_tdep.size_termios = 36;
1934 aarch64_linux_record_tdep.size_termios2 = 44;
1935 aarch64_linux_record_tdep.size_pid_t = 4;
1936 aarch64_linux_record_tdep.size_winsize = 8;
1937 aarch64_linux_record_tdep.size_serial_struct = 72;
1938 aarch64_linux_record_tdep.size_serial_icounter_struct = 80;
1939 aarch64_linux_record_tdep.size_hayes_esp_config = 12;
1940 aarch64_linux_record_tdep.size_size_t = 8;
1941 aarch64_linux_record_tdep.size_iovec = 16;
1942 aarch64_linux_record_tdep.size_time_t = 8;
1944 /* These values are the second argument of system call "sys_ioctl".
1945 They are obtained from Linux Kernel source. */
1946 aarch64_linux_record_tdep.ioctl_TCGETS = 0x5401;
1947 aarch64_linux_record_tdep.ioctl_TCSETS = 0x5402;
1948 aarch64_linux_record_tdep.ioctl_TCSETSW = 0x5403;
1949 aarch64_linux_record_tdep.ioctl_TCSETSF = 0x5404;
1950 aarch64_linux_record_tdep.ioctl_TCGETA = 0x5405;
1951 aarch64_linux_record_tdep.ioctl_TCSETA = 0x5406;
1952 aarch64_linux_record_tdep.ioctl_TCSETAW = 0x5407;
1953 aarch64_linux_record_tdep.ioctl_TCSETAF = 0x5408;
1954 aarch64_linux_record_tdep.ioctl_TCSBRK = 0x5409;
1955 aarch64_linux_record_tdep.ioctl_TCXONC = 0x540a;
1956 aarch64_linux_record_tdep.ioctl_TCFLSH = 0x540b;
1957 aarch64_linux_record_tdep.ioctl_TIOCEXCL = 0x540c;
1958 aarch64_linux_record_tdep.ioctl_TIOCNXCL = 0x540d;
1959 aarch64_linux_record_tdep.ioctl_TIOCSCTTY = 0x540e;
1960 aarch64_linux_record_tdep.ioctl_TIOCGPGRP = 0x540f;
1961 aarch64_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
1962 aarch64_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
1963 aarch64_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
1964 aarch64_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
1965 aarch64_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
1966 aarch64_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
1967 aarch64_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
1968 aarch64_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
1969 aarch64_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
1970 aarch64_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
1971 aarch64_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541a;
1972 aarch64_linux_record_tdep.ioctl_FIONREAD = 0x541b;
1973 aarch64_linux_record_tdep.ioctl_TIOCINQ = 0x541b;
1974 aarch64_linux_record_tdep.ioctl_TIOCLINUX = 0x541c;
1975 aarch64_linux_record_tdep.ioctl_TIOCCONS = 0x541d;
1976 aarch64_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541e;
1977 aarch64_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541f;
1978 aarch64_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
1979 aarch64_linux_record_tdep.ioctl_FIONBIO = 0x5421;
1980 aarch64_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
1981 aarch64_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
1982 aarch64_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
1983 aarch64_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
1984 aarch64_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
1985 aarch64_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
1986 aarch64_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
1987 aarch64_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
1988 aarch64_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
1989 aarch64_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
1990 aarch64_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
1991 aarch64_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
1992 aarch64_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
1993 aarch64_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
1994 aarch64_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
1995 aarch64_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
1996 aarch64_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
1997 aarch64_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
1998 aarch64_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
1999 aarch64_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
2000 aarch64_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
2001 aarch64_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
2002 aarch64_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
2003 aarch64_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
2004 aarch64_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545a;
2005 aarch64_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545b;
2006 aarch64_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545c;
2007 aarch64_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545d;
2008 aarch64_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545e;
2009 aarch64_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545f;
2010 aarch64_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
2012 /* These values are the second argument of system call "sys_fcntl"
2013 and "sys_fcntl64". They are obtained from Linux Kernel source. */
2014 aarch64_linux_record_tdep.fcntl_F_GETLK = 5;
2015 aarch64_linux_record_tdep.fcntl_F_GETLK64 = 12;
2016 aarch64_linux_record_tdep.fcntl_F_SETLK64 = 13;
2017 aarch64_linux_record_tdep.fcntl_F_SETLKW64 = 14;
2019 /* The AArch64 syscall calling convention: reg x0-x6 for arguments,
2020 reg x8 for syscall number and return value in reg x0. */
2021 aarch64_linux_record_tdep.arg1 = AARCH64_X0_REGNUM + 0;
2022 aarch64_linux_record_tdep.arg2 = AARCH64_X0_REGNUM + 1;
2023 aarch64_linux_record_tdep.arg3 = AARCH64_X0_REGNUM + 2;
2024 aarch64_linux_record_tdep.arg4 = AARCH64_X0_REGNUM + 3;
2025 aarch64_linux_record_tdep.arg5 = AARCH64_X0_REGNUM + 4;
2026 aarch64_linux_record_tdep.arg6 = AARCH64_X0_REGNUM + 5;
2027 aarch64_linux_record_tdep.arg7 = AARCH64_X0_REGNUM + 6;
2029 /* `catch syscall' */
2030 set_xml_syscall_file_name (gdbarch, "syscalls/aarch64-linux.xml");
2031 set_gdbarch_get_syscall_number (gdbarch, aarch64_linux_get_syscall_number);
2033 /* Displaced stepping. */
2034 set_gdbarch_max_insn_length (gdbarch, 4 * AARCH64_DISPLACED_MODIFIED_INSNS);
2035 set_gdbarch_displaced_step_copy_insn (gdbarch,
2036 aarch64_displaced_step_copy_insn);
2037 set_gdbarch_displaced_step_fixup (gdbarch, aarch64_displaced_step_fixup);
2038 set_gdbarch_displaced_step_hw_singlestep (gdbarch,
2039 aarch64_displaced_step_hw_singlestep);
2041 set_gdbarch_gcc_target_options (gdbarch, aarch64_linux_gcc_target_options);
2044 #if GDB_SELF_TEST
2046 namespace selftests {
2048 /* Verify functions to read and write logical tags. */
2050 static void
2051 aarch64_linux_ltag_tests (void)
2053 /* We have 4 bits of tags, but we test writing all the bits of the top
2054 byte of address. */
2055 for (int i = 0; i < 1 << 8; i++)
2057 CORE_ADDR addr = ((CORE_ADDR) i << 56) | 0xdeadbeef;
2058 SELF_CHECK (aarch64_mte_get_ltag (addr) == (i & 0xf));
2060 addr = aarch64_mte_set_ltag (0xdeadbeef, i);
2061 SELF_CHECK (addr = ((CORE_ADDR) (i & 0xf) << 56) | 0xdeadbeef);
2065 } // namespace selftests
2066 #endif /* GDB_SELF_TEST */
2068 void _initialize_aarch64_linux_tdep ();
2069 void
2070 _initialize_aarch64_linux_tdep ()
2072 gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_LINUX,
2073 aarch64_linux_init_abi);
2075 #if GDB_SELF_TEST
2076 selftests::register_test ("aarch64-linux-tagged-address",
2077 selftests::aarch64_linux_ltag_tests);
2078 #endif