1 /* Target-dependent code for GNU/Linux AArch64.
3 Copyright (C) 2009-2023 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 "glibc-tdep.h"
25 #include "linux-tdep.h"
26 #include "aarch64-tdep.h"
27 #include "aarch64-linux-tdep.h"
29 #include "solib-svr4.h"
31 #include "tramp-frame.h"
32 #include "trad-frame.h"
34 #include "target/target.h"
41 #include "stap-probe.h"
42 #include "parser-defs.h"
43 #include "user-regs.h"
44 #include "xml-syscall.h"
47 #include "record-full.h"
48 #include "linux-record.h"
50 #include "arch/aarch64-mte-linux.h"
51 #include "arch/aarch64-scalable-linux.h"
53 #include "arch-utils.h"
56 #include "gdbsupport/selftest.h"
58 #include "elf/common.h"
59 #include "elf/aarch64.h"
60 #include "arch/aarch64-insn.h"
65 /* Signal frame handling.
80 | | | SIGTRAMP_FRAME (struct rt_sigframe)
82 +--| saved sp |--> interrupted_sp
83 | | saved pc |--> interrupted_pc
86 | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
92 On signal delivery, the kernel will create a signal handler stack
93 frame and setup the return address in LR to point at restorer stub.
94 The signal stack frame is defined by:
102 The ucontext has the following form:
105 unsigned long uc_flags;
106 struct ucontext *uc_link;
109 struct sigcontext uc_mcontext;
114 unsigned long fault_address;
115 unsigned long regs[31];
116 unsigned long sp; / * 31 * /
117 unsigned long pc; / * 32 * /
118 unsigned long pstate; / * 33 * /
119 __u8 __reserved[4096]
122 The reserved space in sigcontext contains additional structures, each starting
123 with a aarch64_ctx, which specifies a unique identifier and the total size of
124 the structure. The final structure in reserved will start will a null
125 aarch64_ctx. The penultimate entry in reserved may be a extra_context which
126 then points to a further block of reserved space.
133 The restorer stub will always have the form:
135 d28015a8 movz x8, #0xad
138 This is a system call sys_rt_sigreturn.
140 We detect signal frames by snooping the return code for the restorer
141 instruction sequence.
143 The handler then needs to recover the saved register set from
144 ucontext.uc_mcontext. */
146 /* These magic numbers need to reflect the layout of the kernel
147 defined struct rt_sigframe and ucontext. */
148 #define AARCH64_SIGCONTEXT_REG_SIZE 8
149 #define AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET 128
150 #define AARCH64_UCONTEXT_SIGCONTEXT_OFFSET 176
151 #define AARCH64_SIGCONTEXT_XO_OFFSET 8
152 #define AARCH64_SIGCONTEXT_RESERVED_OFFSET 288
154 #define AARCH64_SIGCONTEXT_RESERVED_SIZE 4096
156 /* Unique identifiers that may be used for aarch64_ctx.magic. */
157 #define AARCH64_EXTRA_MAGIC 0x45585401
158 #define AARCH64_FPSIMD_MAGIC 0x46508001
159 #define AARCH64_SVE_MAGIC 0x53564501
160 #define AARCH64_ZA_MAGIC 0x54366345
161 #define AARCH64_TPIDR2_MAGIC 0x54504902
162 #define AARCH64_ZT_MAGIC 0x5a544e01
164 /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC. */
165 #define AARCH64_EXTRA_DATAP_OFFSET 8
167 /* Defines for the fpsimd that follows an AARCH64_FPSIMD_MAGIC. */
168 #define AARCH64_FPSIMD_FPSR_OFFSET 8
169 #define AARCH64_FPSIMD_FPCR_OFFSET 12
170 #define AARCH64_FPSIMD_V0_OFFSET 16
171 #define AARCH64_FPSIMD_VREG_SIZE 16
173 /* Defines for the sve structure that follows an AARCH64_SVE_MAGIC. */
174 #define AARCH64_SVE_CONTEXT_VL_OFFSET 8
175 #define AARCH64_SVE_CONTEXT_FLAGS_OFFSET 10
176 #define AARCH64_SVE_CONTEXT_REGS_OFFSET 16
177 #define AARCH64_SVE_CONTEXT_P_REGS_OFFSET(vq) (32 * vq * 16)
178 #define AARCH64_SVE_CONTEXT_FFR_OFFSET(vq) \
179 (AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq) + (16 * vq * 2))
180 #define AARCH64_SVE_CONTEXT_SIZE(vq) \
181 (AARCH64_SVE_CONTEXT_FFR_OFFSET (vq) + (vq * 2))
182 /* Flag indicating the SVE Context describes streaming mode. */
183 #define SVE_SIG_FLAG_SM 0x1
186 #define AARCH64_SME_CONTEXT_SVL_OFFSET 8
187 #define AARCH64_SME_CONTEXT_REGS_OFFSET 16
188 #define AARCH64_SME_CONTEXT_ZA_SIZE(svq) \
189 ((sve_vl_from_vq (svq) * sve_vl_from_vq (svq)))
190 #define AARCH64_SME_CONTEXT_SIZE(svq) \
191 (AARCH64_SME_CONTEXT_REGS_OFFSET + AARCH64_SME_CONTEXT_ZA_SIZE (svq))
193 /* TPIDR2 register value offset in the TPIDR2 signal frame context. */
194 #define AARCH64_TPIDR2_CONTEXT_TPIDR2_OFFSET 8
196 /* SME2 (ZT) constants. */
197 /* Offset of the field containing the number of registers in the SME2 signal
199 #define AARCH64_SME2_CONTEXT_NREGS_OFFSET 8
200 /* Offset of the beginning of the register data for the first ZT register in
201 the signal context state. */
202 #define AARCH64_SME2_CONTEXT_REGS_OFFSET 16
204 /* Holds information about the signal frame. */
205 struct aarch64_linux_sigframe
207 /* The stack pointer value. */
209 /* The sigcontext address. */
210 CORE_ADDR sigcontext_address
= 0;
211 /* The start/end signal frame section addresses. */
212 CORE_ADDR section
= 0;
213 CORE_ADDR section_end
= 0;
215 /* Starting address of the section containing the general purpose
217 CORE_ADDR gpr_section
= 0;
218 /* Starting address of the section containing the FPSIMD registers. */
219 CORE_ADDR fpsimd_section
= 0;
220 /* Starting address of the section containing the SVE registers. */
221 CORE_ADDR sve_section
= 0;
222 /* Starting address of the section containing the ZA register. */
223 CORE_ADDR za_section
= 0;
224 /* Starting address of the section containing the TPIDR2 register. */
225 CORE_ADDR tpidr2_section
= 0;
226 /* Starting address of the section containing the ZT registers. */
227 CORE_ADDR zt_section
= 0;
228 /* Starting address of the section containing extra information. */
229 CORE_ADDR extra_section
= 0;
231 /* The vector length (SVE or SSVE). */
233 /* The streaming vector length (SSVE/ZA). */
235 /* Number of ZT registers in this context. */
236 unsigned int zt_register_count
= 0;
238 /* True if we are in streaming mode, false otherwise. */
239 bool streaming_mode
= false;
240 /* True if we have a ZA payload, false otherwise. */
241 bool za_payload
= false;
242 /* True if we have a ZT entry in the signal context, false otherwise. */
243 bool zt_available
= false;
246 /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the
247 size, or return 0 on error. */
250 read_aarch64_ctx (CORE_ADDR ctx_addr
, enum bfd_endian byte_order
,
256 if (target_read_memory (ctx_addr
, buf
, 4) != 0)
258 magic
= extract_unsigned_integer (buf
, 4, byte_order
);
260 if (target_read_memory (ctx_addr
+ 4, buf
, 4) != 0)
262 *size
= extract_unsigned_integer (buf
, 4, byte_order
);
267 /* Given CACHE, use the trad_frame* functions to restore the FPSIMD
268 registers from a signal frame.
270 FPSIMD_CONTEXT is the address of the signal frame context containing FPSIMD
274 aarch64_linux_restore_vregs (struct gdbarch
*gdbarch
,
275 struct trad_frame_cache
*cache
,
276 CORE_ADDR fpsimd_context
)
278 /* WARNING: SIMD state is laid out in memory in target-endian format.
280 So we have a couple cases to consider:
282 1 - If the target is big endian, then SIMD state is big endian,
283 requiring a byteswap.
285 2 - If the target is little endian, then SIMD state is little endian, so
286 no byteswap is needed. */
288 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
289 int num_regs
= gdbarch_num_regs (gdbarch
);
290 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
292 for (int i
= 0; i
< 32; i
++)
294 CORE_ADDR offset
= (fpsimd_context
+ AARCH64_FPSIMD_V0_OFFSET
295 + (i
* AARCH64_FPSIMD_VREG_SIZE
));
297 gdb_byte buf
[V_REGISTER_SIZE
];
299 /* Read the contents of the V register. */
300 if (target_read_memory (offset
, buf
, V_REGISTER_SIZE
))
301 error (_("Failed to read fpsimd register from signal context."));
303 if (byte_order
== BFD_ENDIAN_BIG
)
305 size_t size
= V_REGISTER_SIZE
/2;
307 /* Read the two halves of the V register in reverse byte order. */
308 CORE_ADDR u64
= extract_unsigned_integer (buf
, size
,
310 CORE_ADDR l64
= extract_unsigned_integer (buf
+ size
, size
,
313 /* Copy the reversed bytes to the buffer. */
314 store_unsigned_integer (buf
, size
, BFD_ENDIAN_LITTLE
, l64
);
315 store_unsigned_integer (buf
+ size
, size
, BFD_ENDIAN_LITTLE
, u64
);
317 /* Now we can store the correct bytes for the V register. */
318 trad_frame_set_reg_value_bytes (cache
, AARCH64_V0_REGNUM
+ i
,
319 {buf
, V_REGISTER_SIZE
});
320 trad_frame_set_reg_value_bytes (cache
,
321 num_regs
+ AARCH64_Q0_REGNUM
322 + i
, {buf
, Q_REGISTER_SIZE
});
323 trad_frame_set_reg_value_bytes (cache
,
324 num_regs
+ AARCH64_D0_REGNUM
325 + i
, {buf
, D_REGISTER_SIZE
});
326 trad_frame_set_reg_value_bytes (cache
,
327 num_regs
+ AARCH64_S0_REGNUM
328 + i
, {buf
, S_REGISTER_SIZE
});
329 trad_frame_set_reg_value_bytes (cache
,
330 num_regs
+ AARCH64_H0_REGNUM
331 + i
, {buf
, H_REGISTER_SIZE
});
332 trad_frame_set_reg_value_bytes (cache
,
333 num_regs
+ AARCH64_B0_REGNUM
334 + i
, {buf
, B_REGISTER_SIZE
});
336 if (tdep
->has_sve ())
337 trad_frame_set_reg_value_bytes (cache
,
338 num_regs
+ AARCH64_SVE_V0_REGNUM
339 + i
, {buf
, V_REGISTER_SIZE
});
343 /* Little endian, just point at the address containing the register
345 trad_frame_set_reg_addr (cache
, AARCH64_V0_REGNUM
+ i
, offset
);
346 trad_frame_set_reg_addr (cache
, num_regs
+ AARCH64_Q0_REGNUM
+ i
,
348 trad_frame_set_reg_addr (cache
, num_regs
+ AARCH64_D0_REGNUM
+ i
,
350 trad_frame_set_reg_addr (cache
, num_regs
+ AARCH64_S0_REGNUM
+ i
,
352 trad_frame_set_reg_addr (cache
, num_regs
+ AARCH64_H0_REGNUM
+ i
,
354 trad_frame_set_reg_addr (cache
, num_regs
+ AARCH64_B0_REGNUM
+ i
,
357 if (tdep
->has_sve ())
358 trad_frame_set_reg_addr (cache
, num_regs
+ AARCH64_SVE_V0_REGNUM
362 if (tdep
->has_sve ())
364 /* If SVE is supported for this target, zero out the Z
365 registers then copy the first 16 bytes of each of the V
366 registers to the associated Z register. Otherwise the Z
367 registers will contain uninitialized data. */
368 std::vector
<gdb_byte
> z_buffer (tdep
->vq
* 16);
370 /* We have already handled the endianness swap above, so we don't need
371 to worry about it here. */
372 memcpy (z_buffer
.data (), buf
, V_REGISTER_SIZE
);
373 trad_frame_set_reg_value_bytes (cache
,
374 AARCH64_SVE_Z0_REGNUM
+ i
,
380 /* Given a signal frame THIS_FRAME, read the signal frame information into
384 aarch64_linux_read_signal_frame_info (frame_info_ptr this_frame
,
385 struct aarch64_linux_sigframe
&signal_frame
)
387 signal_frame
.sp
= get_frame_register_unsigned (this_frame
, AARCH64_SP_REGNUM
);
388 signal_frame
.sigcontext_address
389 = signal_frame
.sp
+ AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
390 + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET
;
392 = signal_frame
.sigcontext_address
+ AARCH64_SIGCONTEXT_RESERVED_OFFSET
;
393 signal_frame
.section_end
394 = signal_frame
.section
+ AARCH64_SIGCONTEXT_RESERVED_SIZE
;
396 signal_frame
.gpr_section
397 = signal_frame
.sigcontext_address
+ AARCH64_SIGCONTEXT_XO_OFFSET
;
399 /* Search for all the other sections, stopping at null. */
400 CORE_ADDR section
= signal_frame
.section
;
401 CORE_ADDR section_end
= signal_frame
.section_end
;
402 uint32_t size
, magic
;
403 bool extra_found
= false;
404 enum bfd_endian byte_order
405 = gdbarch_byte_order (get_frame_arch (this_frame
));
407 while ((magic
= read_aarch64_ctx (section
, byte_order
, &size
)) != 0
412 case AARCH64_FPSIMD_MAGIC
:
414 signal_frame
.fpsimd_section
= section
;
419 case AARCH64_SVE_MAGIC
:
421 /* Check if the section is followed by a full SVE dump, and set
422 sve_regs if it is. */
425 /* Extract the vector length. */
426 if (target_read_memory (section
+ AARCH64_SVE_CONTEXT_VL_OFFSET
,
429 warning (_("Failed to read the vector length from the SVE "
430 "signal frame context."));
435 signal_frame
.vl
= extract_unsigned_integer (buf
, 2, byte_order
);
437 /* Extract the flags to check if we are in streaming mode. */
438 if (target_read_memory (section
439 + AARCH64_SVE_CONTEXT_FLAGS_OFFSET
,
442 warning (_("Failed to read the flags from the SVE signal frame"
448 uint16_t flags
= extract_unsigned_integer (buf
, 2, byte_order
);
450 /* Is this SSVE data? If so, we are in streaming mode. */
451 signal_frame
.streaming_mode
452 = (flags
& SVE_SIG_FLAG_SM
) ? true : false;
454 ULONGEST vq
= sve_vq_from_vl (signal_frame
.vl
);
455 if (size
>= AARCH64_SVE_CONTEXT_SIZE (vq
))
457 signal_frame
.sve_section
458 = section
+ AARCH64_SVE_CONTEXT_REGS_OFFSET
;
464 case AARCH64_ZA_MAGIC
:
466 /* Check if the section is followed by a full ZA dump, and set
467 za_state if it is. */
470 /* Extract the streaming vector length. */
471 if (target_read_memory (section
+ AARCH64_SME_CONTEXT_SVL_OFFSET
,
474 warning (_("Failed to read the streaming vector length from "
475 "ZA signal frame context."));
480 signal_frame
.svl
= extract_unsigned_integer (buf
, 2, byte_order
);
481 ULONGEST svq
= sve_vq_from_vl (signal_frame
.svl
);
483 if (size
>= AARCH64_SME_CONTEXT_SIZE (svq
))
485 signal_frame
.za_section
486 = section
+ AARCH64_SME_CONTEXT_REGS_OFFSET
;
487 signal_frame
.za_payload
= true;
493 case AARCH64_TPIDR2_MAGIC
:
495 /* This is context containing the tpidr2 register. */
496 signal_frame
.tpidr2_section
= section
;
500 case AARCH64_ZT_MAGIC
:
504 /* Extract the number of ZT registers available in this
506 if (target_read_memory (section
+ AARCH64_SME2_CONTEXT_NREGS_OFFSET
,
509 warning (_("Failed to read the number of ZT registers from the "
510 "ZT signal frame context."));
515 signal_frame
.zt_register_count
516 = extract_unsigned_integer (buf
, 2, byte_order
);
518 /* This is a context containing the ZT registers. This should only
519 exist if we also have the ZA context. The presence of the ZT
520 context without the ZA context is invalid. */
521 signal_frame
.zt_section
= section
;
522 signal_frame
.zt_available
= true;
527 case AARCH64_EXTRA_MAGIC
:
529 /* Extra is always the last valid section in reserved and points to
530 an additional block of memory filled with more sections. Reset
531 the address to the extra section and continue looking for more
535 if (target_read_memory (section
+ AARCH64_EXTRA_DATAP_OFFSET
,
538 warning (_("Failed to read the extra section address from the"
539 " signal frame context."));
544 section
= extract_unsigned_integer (buf
, 8, byte_order
);
545 signal_frame
.extra_section
= section
;
555 /* Prevent searching past the end of the reserved section. The extra
556 section does not have a hard coded limit - we have to rely on it ending
558 if (!extra_found
&& section
> section_end
)
562 /* Sanity check that if the ZT entry exists, the ZA entry must also
564 if (signal_frame
.zt_available
&& !signal_frame
.za_payload
)
565 error (_("While reading signal context information, found a ZT context "
566 "without a ZA context, which is invalid."));
569 /* Implement the "init" method of struct tramp_frame. */
572 aarch64_linux_sigframe_init (const struct tramp_frame
*self
,
573 frame_info_ptr this_frame
,
574 struct trad_frame_cache
*this_cache
,
577 /* Read the signal context information. */
578 struct aarch64_linux_sigframe signal_frame
;
579 aarch64_linux_read_signal_frame_info (this_frame
, signal_frame
);
581 /* Now we have all the data required to restore the registers from the
584 /* Restore the general purpose registers. */
585 CORE_ADDR offset
= signal_frame
.gpr_section
;
586 for (int i
= 0; i
< 31; i
++)
588 trad_frame_set_reg_addr (this_cache
, AARCH64_X0_REGNUM
+ i
, offset
);
589 offset
+= AARCH64_SIGCONTEXT_REG_SIZE
;
591 trad_frame_set_reg_addr (this_cache
, AARCH64_SP_REGNUM
, offset
);
592 offset
+= AARCH64_SIGCONTEXT_REG_SIZE
;
593 trad_frame_set_reg_addr (this_cache
, AARCH64_PC_REGNUM
, offset
);
595 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
596 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
598 /* Restore the SVE / FPSIMD registers. */
599 if (tdep
->has_sve () && signal_frame
.sve_section
!= 0)
601 ULONGEST vq
= sve_vq_from_vl (signal_frame
.vl
);
602 CORE_ADDR sve_regs
= signal_frame
.sve_section
;
605 trad_frame_set_reg_value (this_cache
, AARCH64_SVE_VG_REGNUM
,
606 sve_vg_from_vl (signal_frame
.vl
));
608 int num_regs
= gdbarch_num_regs (gdbarch
);
609 for (int i
= 0; i
< 32; i
++)
611 offset
= sve_regs
+ (i
* vq
* 16);
612 trad_frame_set_reg_addr (this_cache
, AARCH64_SVE_Z0_REGNUM
+ i
,
614 trad_frame_set_reg_addr (this_cache
,
615 num_regs
+ AARCH64_SVE_V0_REGNUM
+ i
,
617 trad_frame_set_reg_addr (this_cache
, num_regs
+ AARCH64_Q0_REGNUM
+ i
,
619 trad_frame_set_reg_addr (this_cache
, num_regs
+ AARCH64_D0_REGNUM
+ i
,
621 trad_frame_set_reg_addr (this_cache
, num_regs
+ AARCH64_S0_REGNUM
+ i
,
623 trad_frame_set_reg_addr (this_cache
, num_regs
+ AARCH64_H0_REGNUM
+ i
,
625 trad_frame_set_reg_addr (this_cache
, num_regs
+ AARCH64_B0_REGNUM
+ i
,
629 offset
= sve_regs
+ AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq
);
630 for (int i
= 0; i
< 16; i
++)
631 trad_frame_set_reg_addr (this_cache
, AARCH64_SVE_P0_REGNUM
+ i
,
632 offset
+ (i
* vq
* 2));
634 offset
= sve_regs
+ AARCH64_SVE_CONTEXT_FFR_OFFSET (vq
);
635 trad_frame_set_reg_addr (this_cache
, AARCH64_SVE_FFR_REGNUM
, offset
);
638 /* Restore the FPSIMD registers. */
639 if (signal_frame
.fpsimd_section
!= 0)
641 CORE_ADDR fpsimd
= signal_frame
.fpsimd_section
;
643 trad_frame_set_reg_addr (this_cache
, AARCH64_FPSR_REGNUM
,
644 fpsimd
+ AARCH64_FPSIMD_FPSR_OFFSET
);
645 trad_frame_set_reg_addr (this_cache
, AARCH64_FPCR_REGNUM
,
646 fpsimd
+ AARCH64_FPSIMD_FPCR_OFFSET
);
648 /* If there was no SVE section then set up the V registers. */
649 if (!tdep
->has_sve () || signal_frame
.sve_section
== 0)
650 aarch64_linux_restore_vregs (gdbarch
, this_cache
, fpsimd
);
653 /* Restore the SME registers. */
654 if (tdep
->has_sme ())
656 if (signal_frame
.za_section
!= 0)
658 /* Restore the ZA state. */
659 trad_frame_set_reg_addr (this_cache
, tdep
->sme_za_regnum
,
660 signal_frame
.za_section
);
663 /* Restore/Reconstruct SVCR. */
665 svcr
|= signal_frame
.za_payload
? SVCR_ZA_BIT
: 0;
666 svcr
|= signal_frame
.streaming_mode
? SVCR_SM_BIT
: 0;
667 trad_frame_set_reg_value (this_cache
, tdep
->sme_svcr_regnum
, svcr
);
670 trad_frame_set_reg_value (this_cache
, tdep
->sme_svg_regnum
,
671 sve_vg_from_vl (signal_frame
.svl
));
673 /* Handle SME2 (ZT). */
674 if (tdep
->has_sme2 ()
675 && signal_frame
.za_section
!= 0
676 && signal_frame
.zt_register_count
> 0)
678 /* Is ZA state available? */
679 gdb_assert (svcr
& SVCR_ZA_BIT
);
681 /* Restore the ZT state. For now we assume that we only have
682 a single ZT register. If/When more ZT registers appear, we
683 should update the code to handle that case accordingly. */
684 trad_frame_set_reg_addr (this_cache
, tdep
->sme2_zt0_regnum
,
685 signal_frame
.zt_section
686 + AARCH64_SME2_CONTEXT_REGS_OFFSET
);
690 /* Restore the tpidr2 register, if the target supports it and if there is
692 if (signal_frame
.tpidr2_section
!= 0 && tdep
->has_tls ()
693 && tdep
->tls_register_count
>= 2)
695 /* Restore tpidr2. */
696 trad_frame_set_reg_addr (this_cache
, tdep
->tls_regnum_base
+ 1,
697 signal_frame
.tpidr2_section
698 + AARCH64_TPIDR2_CONTEXT_TPIDR2_OFFSET
);
701 trad_frame_set_id (this_cache
, frame_id_build (signal_frame
.sp
, func
));
704 /* Implements the "prev_arch" method of struct tramp_frame. */
706 static struct gdbarch
*
707 aarch64_linux_sigframe_prev_arch (frame_info_ptr this_frame
,
710 struct trad_frame_cache
*cache
711 = (struct trad_frame_cache
*) *frame_cache
;
713 gdb_assert (cache
!= nullptr);
715 struct aarch64_linux_sigframe signal_frame
;
716 aarch64_linux_read_signal_frame_info (this_frame
, signal_frame
);
718 /* The SVE vector length and the SME vector length may change from frame to
719 frame. Make sure we report the correct architecture to the previous
722 We can reuse the next frame's architecture here, as it should be mostly
723 the same, except for potential different vg and svg values. */
724 const struct target_desc
*tdesc
725 = gdbarch_target_desc (get_frame_arch (this_frame
));
726 aarch64_features features
= aarch64_features_from_target_desc (tdesc
);
727 features
.vq
= sve_vq_from_vl (signal_frame
.vl
);
728 features
.svq
= (uint8_t) sve_vq_from_vl (signal_frame
.svl
);
730 struct gdbarch_info info
;
731 info
.bfd_arch_info
= bfd_lookup_arch (bfd_arch_aarch64
, bfd_mach_aarch64
);
732 info
.target_desc
= aarch64_read_description (features
);
733 return gdbarch_find_by_info (info
);
736 static const struct tramp_frame aarch64_linux_rt_sigframe
=
741 /* movz x8, 0x8b (S=1,o=10,h=0,i=0x8b,r=8)
742 Soo1 0010 1hhi iiii iiii iiii iiir rrrr */
743 {0xd2801168, ULONGEST_MAX
},
745 /* svc 0x0 (o=0, l=1)
746 1101 0100 oooi iiii iiii iiii iii0 00ll */
747 {0xd4000001, ULONGEST_MAX
},
748 {TRAMP_SENTINEL_INSN
, ULONGEST_MAX
}
750 aarch64_linux_sigframe_init
,
751 nullptr, /* validate */
752 aarch64_linux_sigframe_prev_arch
, /* prev_arch */
757 static const struct regcache_map_entry aarch64_linux_gregmap
[] =
759 { 31, AARCH64_X0_REGNUM
, 8 }, /* x0 ... x30 */
760 { 1, AARCH64_SP_REGNUM
, 8 },
761 { 1, AARCH64_PC_REGNUM
, 8 },
762 { 1, AARCH64_CPSR_REGNUM
, 8 },
766 static const struct regcache_map_entry aarch64_linux_fpregmap
[] =
768 { 32, AARCH64_V0_REGNUM
, 16 }, /* v0 ... v31 */
769 { 1, AARCH64_FPSR_REGNUM
, 4 },
770 { 1, AARCH64_FPCR_REGNUM
, 4 },
774 /* Register set definitions. */
776 const struct regset aarch64_linux_gregset
=
778 aarch64_linux_gregmap
,
779 regcache_supply_regset
, regcache_collect_regset
782 const struct regset aarch64_linux_fpregset
=
784 aarch64_linux_fpregmap
,
785 regcache_supply_regset
, regcache_collect_regset
788 /* The fields in an SVE header at the start of a SVE regset. */
790 #define SVE_HEADER_SIZE_LENGTH 4
791 #define SVE_HEADER_MAX_SIZE_LENGTH 4
792 #define SVE_HEADER_VL_LENGTH 2
793 #define SVE_HEADER_MAX_VL_LENGTH 2
794 #define SVE_HEADER_FLAGS_LENGTH 2
795 #define SVE_HEADER_RESERVED_LENGTH 2
797 #define SVE_HEADER_SIZE_OFFSET 0
798 #define SVE_HEADER_MAX_SIZE_OFFSET \
799 (SVE_HEADER_SIZE_OFFSET + SVE_HEADER_SIZE_LENGTH)
800 #define SVE_HEADER_VL_OFFSET \
801 (SVE_HEADER_MAX_SIZE_OFFSET + SVE_HEADER_MAX_SIZE_LENGTH)
802 #define SVE_HEADER_MAX_VL_OFFSET \
803 (SVE_HEADER_VL_OFFSET + SVE_HEADER_VL_LENGTH)
804 #define SVE_HEADER_FLAGS_OFFSET \
805 (SVE_HEADER_MAX_VL_OFFSET + SVE_HEADER_MAX_VL_LENGTH)
806 #define SVE_HEADER_RESERVED_OFFSET \
807 (SVE_HEADER_FLAGS_OFFSET + SVE_HEADER_FLAGS_LENGTH)
808 #define SVE_HEADER_SIZE \
809 (SVE_HEADER_RESERVED_OFFSET + SVE_HEADER_RESERVED_LENGTH)
811 #define SVE_HEADER_FLAG_SVE 1
813 /* Get the vector quotient (VQ) or streaming vector quotient (SVQ) value
814 from the section named SECTION_NAME.
816 Return non-zero if successful and 0 otherwise. */
819 aarch64_linux_core_read_vq (struct gdbarch
*gdbarch
, bfd
*abfd
,
820 const char *section_name
)
822 gdb_assert (section_name
!= nullptr);
824 asection
*section
= bfd_get_section_by_name (abfd
, section_name
);
826 if (section
== nullptr)
832 size_t size
= bfd_section_size (section
);
834 /* Check extended state size. */
835 if (size
< SVE_HEADER_SIZE
)
837 warning (_("'%s' core file section is too small. "
838 "Expected %s bytes, got %s bytes"), section_name
,
839 pulongest (SVE_HEADER_SIZE
), pulongest (size
));
843 gdb_byte header
[SVE_HEADER_SIZE
];
845 if (!bfd_get_section_contents (abfd
, section
, header
, 0, SVE_HEADER_SIZE
))
847 warning (_("Couldn't read sve header from "
848 "'%s' core file section."), section_name
);
852 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
854 = sve_vq_from_vl (extract_unsigned_integer (header
+ SVE_HEADER_VL_OFFSET
,
855 SVE_HEADER_VL_LENGTH
,
858 if (vq
> AARCH64_MAX_SVE_VQ
|| vq
== 0)
860 warning (_("SVE/SSVE vector length in core file is invalid."
861 " (max vq=%d) (detected vq=%s)"), AARCH64_MAX_SVE_VQ
,
869 /* Get the vector quotient (VQ) value from CORE_BFD's sections.
871 Return non-zero if successful and 0 otherwise. */
874 aarch64_linux_core_read_vq_from_sections (struct gdbarch
*gdbarch
,
877 /* First check if we have a SSVE section. If so, check if it is active. */
878 asection
*section
= bfd_get_section_by_name (core_bfd
, ".reg-aarch-ssve");
880 if (section
!= nullptr)
882 /* We've found a SSVE section, so now fetch its data. */
883 gdb_byte header
[SVE_HEADER_SIZE
];
885 if (bfd_get_section_contents (core_bfd
, section
, header
, 0,
888 /* Check if the SSVE section has SVE contents. */
889 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
891 = extract_unsigned_integer (header
+ SVE_HEADER_FLAGS_OFFSET
,
892 SVE_HEADER_FLAGS_LENGTH
, byte_order
);
894 if (flags
& SVE_HEADER_FLAG_SVE
)
896 /* The SSVE state is active, so return the vector length from the
898 return aarch64_linux_core_read_vq (gdbarch
, core_bfd
,
904 /* No valid SSVE section. Return the vq from the SVE section (if any). */
905 return aarch64_linux_core_read_vq (gdbarch
, core_bfd
, ".reg-aarch-sve");
908 /* Supply register REGNUM from BUF to REGCACHE, using the register map
909 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
910 If BUF is nullptr, set the registers to "unavailable" status. */
913 supply_sve_regset (const struct regset
*regset
,
914 struct regcache
*regcache
,
915 int regnum
, const void *buf
, size_t size
)
917 gdb_byte
*header
= (gdb_byte
*) buf
;
918 struct gdbarch
*gdbarch
= regcache
->arch ();
919 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
922 return regcache
->supply_regset (regset
, regnum
, nullptr, size
);
923 gdb_assert (size
> SVE_HEADER_SIZE
);
925 /* BUF contains an SVE header followed by a register dump of either the
926 passed in SVE regset or a NEON fpregset. */
928 /* Extract required fields from the header. */
929 ULONGEST vl
= extract_unsigned_integer (header
+ SVE_HEADER_VL_OFFSET
,
930 SVE_HEADER_VL_LENGTH
, byte_order
);
931 uint16_t flags
= extract_unsigned_integer (header
+ SVE_HEADER_FLAGS_OFFSET
,
932 SVE_HEADER_FLAGS_LENGTH
,
935 if (regnum
== -1 || regnum
== AARCH64_SVE_VG_REGNUM
)
937 gdb_byte vg_target
[8];
938 store_integer ((gdb_byte
*)&vg_target
, sizeof (uint64_t), byte_order
,
939 sve_vg_from_vl (vl
));
940 regcache
->raw_supply (AARCH64_SVE_VG_REGNUM
, &vg_target
);
943 if (flags
& SVE_HEADER_FLAG_SVE
)
945 /* Register dump is a SVE structure. */
946 regcache
->supply_regset (regset
, regnum
,
947 (gdb_byte
*) buf
+ SVE_HEADER_SIZE
,
948 size
- SVE_HEADER_SIZE
);
952 /* Register dump is a fpsimd structure. First clear the SVE
954 for (int i
= 0; i
< AARCH64_SVE_Z_REGS_NUM
; i
++)
955 regcache
->raw_supply_zeroed (AARCH64_SVE_Z0_REGNUM
+ i
);
956 for (int i
= 0; i
< AARCH64_SVE_P_REGS_NUM
; i
++)
957 regcache
->raw_supply_zeroed (AARCH64_SVE_P0_REGNUM
+ i
);
958 regcache
->raw_supply_zeroed (AARCH64_SVE_FFR_REGNUM
);
960 /* Then supply the fpsimd registers. */
961 regcache
->supply_regset (&aarch64_linux_fpregset
, regnum
,
962 (gdb_byte
*) buf
+ SVE_HEADER_SIZE
,
963 size
- SVE_HEADER_SIZE
);
967 /* Collect an inactive SVE register set state. This is equivalent to a
970 Collect the data from REGCACHE to BUF, using the register
974 collect_inactive_sve_regset (const struct regcache
*regcache
,
975 void *buf
, size_t size
, int vg_regnum
)
977 gdb_byte
*header
= (gdb_byte
*) buf
;
978 struct gdbarch
*gdbarch
= regcache
->arch ();
979 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
981 gdb_assert (buf
!= nullptr);
982 gdb_assert (size
>= SVE_CORE_DUMMY_SIZE
);
984 /* Zero out everything first. */
985 memset ((gdb_byte
*) buf
, 0, SVE_CORE_DUMMY_SIZE
);
987 /* BUF starts with a SVE header prior to the register dump. */
989 /* Dump the default size of an empty SVE payload. */
990 uint32_t real_size
= SVE_CORE_DUMMY_SIZE
;
991 store_unsigned_integer (header
+ SVE_HEADER_SIZE_OFFSET
,
992 SVE_HEADER_SIZE_LENGTH
, byte_order
, real_size
);
994 /* Dump a dummy max size. */
995 uint32_t max_size
= SVE_CORE_DUMMY_MAX_SIZE
;
996 store_unsigned_integer (header
+ SVE_HEADER_MAX_SIZE_OFFSET
,
997 SVE_HEADER_MAX_SIZE_LENGTH
, byte_order
, max_size
);
999 /* Dump the vector length. */
1001 regcache
->raw_collect (vg_regnum
, &vg
);
1002 uint16_t vl
= sve_vl_from_vg (vg
);
1003 store_unsigned_integer (header
+ SVE_HEADER_VL_OFFSET
, SVE_HEADER_VL_LENGTH
,
1006 /* Dump the standard maximum vector length. */
1007 uint16_t max_vl
= SVE_CORE_DUMMY_MAX_VL
;
1008 store_unsigned_integer (header
+ SVE_HEADER_MAX_VL_OFFSET
,
1009 SVE_HEADER_MAX_VL_LENGTH
, byte_order
,
1012 /* The rest of the fields are zero. */
1013 uint16_t flags
= SVE_CORE_DUMMY_FLAGS
;
1014 store_unsigned_integer (header
+ SVE_HEADER_FLAGS_OFFSET
,
1015 SVE_HEADER_FLAGS_LENGTH
, byte_order
,
1017 uint16_t reserved
= SVE_CORE_DUMMY_RESERVED
;
1018 store_unsigned_integer (header
+ SVE_HEADER_RESERVED_OFFSET
,
1019 SVE_HEADER_RESERVED_LENGTH
, byte_order
, reserved
);
1021 /* We are done with the header part of it. Now dump the register state
1022 in the FPSIMD format. */
1024 /* Dump the first 128 bits of each of the Z registers. */
1025 header
+= AARCH64_SVE_CONTEXT_REGS_OFFSET
;
1026 for (int i
= 0; i
< AARCH64_SVE_Z_REGS_NUM
; i
++)
1027 regcache
->raw_collect_part (AARCH64_SVE_Z0_REGNUM
+ i
, 0, V_REGISTER_SIZE
,
1028 header
+ V_REGISTER_SIZE
* i
);
1030 /* Dump FPSR and FPCR. */
1031 header
+= 32 * V_REGISTER_SIZE
;
1032 regcache
->raw_collect (AARCH64_FPSR_REGNUM
, header
);
1033 regcache
->raw_collect (AARCH64_FPCR_REGNUM
, header
+ 4);
1035 /* Dump two reserved empty fields of 4 bytes. */
1037 memset (header
, 0, 8);
1039 /* We should have a FPSIMD-formatted register dump now. */
1042 /* Collect register REGNUM from REGCACHE to BUF, using the register
1043 map in REGSET. If REGNUM is -1, do this for all registers in
1047 collect_sve_regset (const struct regset
*regset
,
1048 const struct regcache
*regcache
,
1049 int regnum
, void *buf
, size_t size
)
1051 gdb_byte
*header
= (gdb_byte
*) buf
;
1052 struct gdbarch
*gdbarch
= regcache
->arch ();
1053 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1054 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1055 uint64_t vq
= tdep
->vq
;
1057 gdb_assert (buf
!= NULL
);
1058 gdb_assert (size
> SVE_HEADER_SIZE
);
1060 /* BUF starts with a SVE header prior to the register dump. */
1062 store_unsigned_integer (header
+ SVE_HEADER_SIZE_OFFSET
,
1063 SVE_HEADER_SIZE_LENGTH
, byte_order
, size
);
1064 uint32_t max_size
= SVE_CORE_DUMMY_MAX_SIZE
;
1065 store_unsigned_integer (header
+ SVE_HEADER_MAX_SIZE_OFFSET
,
1066 SVE_HEADER_MAX_SIZE_LENGTH
, byte_order
, max_size
);
1067 store_unsigned_integer (header
+ SVE_HEADER_VL_OFFSET
, SVE_HEADER_VL_LENGTH
,
1068 byte_order
, sve_vl_from_vq (vq
));
1069 uint16_t max_vl
= SVE_CORE_DUMMY_MAX_VL
;
1070 store_unsigned_integer (header
+ SVE_HEADER_MAX_VL_OFFSET
,
1071 SVE_HEADER_MAX_VL_LENGTH
, byte_order
,
1073 uint16_t flags
= SVE_HEADER_FLAG_SVE
;
1074 store_unsigned_integer (header
+ SVE_HEADER_FLAGS_OFFSET
,
1075 SVE_HEADER_FLAGS_LENGTH
, byte_order
,
1077 uint16_t reserved
= SVE_CORE_DUMMY_RESERVED
;
1078 store_unsigned_integer (header
+ SVE_HEADER_RESERVED_OFFSET
,
1079 SVE_HEADER_RESERVED_LENGTH
, byte_order
, reserved
);
1081 /* The SVE register dump follows. */
1082 regcache
->collect_regset (regset
, regnum
, (gdb_byte
*) buf
+ SVE_HEADER_SIZE
,
1083 size
- SVE_HEADER_SIZE
);
1086 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1087 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1088 If BUF is NULL, set the registers to "unavailable" status. */
1091 aarch64_linux_supply_sve_regset (const struct regset
*regset
,
1092 struct regcache
*regcache
,
1093 int regnum
, const void *buf
, size_t size
)
1095 struct gdbarch
*gdbarch
= regcache
->arch ();
1096 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1098 if (tdep
->has_sme ())
1101 regcache
->raw_collect (tdep
->sme_svcr_regnum
, &svcr
);
1103 /* Is streaming mode enabled? */
1104 if (svcr
& SVCR_SM_BIT
)
1105 /* If so, don't load SVE data from the SVE section. The data to be
1106 used is in the SSVE section. */
1109 /* If streaming mode is not enabled, load the SVE regcache data from the SVE
1111 supply_sve_regset (regset
, regcache
, regnum
, buf
, size
);
1114 /* Collect register REGNUM from REGCACHE to BUF, using the register
1115 map in REGSET. If REGNUM is -1, do this for all registers in
1119 aarch64_linux_collect_sve_regset (const struct regset
*regset
,
1120 const struct regcache
*regcache
,
1121 int regnum
, void *buf
, size_t size
)
1123 struct gdbarch
*gdbarch
= regcache
->arch ();
1124 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1125 bool streaming_mode
= false;
1127 if (tdep
->has_sme ())
1130 regcache
->raw_collect (tdep
->sme_svcr_regnum
, &svcr
);
1132 /* Is streaming mode enabled? */
1133 if (svcr
& SVCR_SM_BIT
)
1135 /* If so, don't dump SVE regcache data to the SVE section. The SVE
1136 data should be dumped to the SSVE section. Dump an empty SVE
1138 streaming_mode
= true;
1142 /* If streaming mode is not enabled or there is no SME support, dump the
1143 SVE regcache data to the SVE section. */
1145 /* Check if we have an active SVE state (non-zero Z/P/FFR registers).
1146 If so, then we need to dump registers in the SVE format.
1148 Otherwise we should dump the registers in the FPSIMD format. */
1149 if (sve_state_is_empty (regcache
) || streaming_mode
)
1150 collect_inactive_sve_regset (regcache
, buf
, size
, AARCH64_SVE_VG_REGNUM
);
1152 collect_sve_regset (regset
, regcache
, regnum
, buf
, size
);
1155 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1156 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1157 If BUF is NULL, set the registers to "unavailable" status. */
1160 aarch64_linux_supply_ssve_regset (const struct regset
*regset
,
1161 struct regcache
*regcache
,
1162 int regnum
, const void *buf
, size_t size
)
1164 gdb_byte
*header
= (gdb_byte
*) buf
;
1165 struct gdbarch
*gdbarch
= regcache
->arch ();
1166 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1167 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1169 uint16_t flags
= extract_unsigned_integer (header
+ SVE_HEADER_FLAGS_OFFSET
,
1170 SVE_HEADER_FLAGS_LENGTH
,
1173 /* Since SVCR's bits are inferred from the data we have in the header of the
1174 SSVE section, we need to initialize it to zero first, so that it doesn't
1175 carry garbage data. */
1177 regcache
->raw_supply (tdep
->sme_svcr_regnum
, &svcr
);
1179 /* Is streaming mode enabled? */
1180 if (flags
& SVE_HEADER_FLAG_SVE
)
1182 /* Streaming mode is active, so flip the SM bit. */
1184 regcache
->raw_supply (tdep
->sme_svcr_regnum
, &svcr
);
1186 /* Fetch the SVE data from the SSVE section. */
1187 supply_sve_regset (regset
, regcache
, regnum
, buf
, size
);
1191 /* Collect register REGNUM from REGCACHE to BUF, using the register
1192 map in REGSET. If REGNUM is -1, do this for all registers in
1196 aarch64_linux_collect_ssve_regset (const struct regset
*regset
,
1197 const struct regcache
*regcache
,
1198 int regnum
, void *buf
, size_t size
)
1200 struct gdbarch
*gdbarch
= regcache
->arch ();
1201 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1203 regcache
->raw_collect (tdep
->sme_svcr_regnum
, &svcr
);
1205 /* Is streaming mode enabled? */
1206 if (svcr
& SVCR_SM_BIT
)
1208 /* If so, dump SVE regcache data to the SSVE section. */
1209 collect_sve_regset (regset
, regcache
, regnum
, buf
, size
);
1213 /* Otherwise dump an empty SVE block to the SSVE section with the
1214 streaming vector length. */
1215 collect_inactive_sve_regset (regcache
, buf
, size
, tdep
->sme_svg_regnum
);
1219 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1220 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1221 If BUF is NULL, set the registers to "unavailable" status. */
1224 aarch64_linux_supply_za_regset (const struct regset
*regset
,
1225 struct regcache
*regcache
,
1226 int regnum
, const void *buf
, size_t size
)
1228 gdb_byte
*header
= (gdb_byte
*) buf
;
1229 struct gdbarch
*gdbarch
= regcache
->arch ();
1230 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1232 /* Handle an empty buffer. */
1234 return regcache
->supply_regset (regset
, regnum
, nullptr, size
);
1236 if (size
< SVE_HEADER_SIZE
)
1237 error (_("ZA state header size (%s) invalid. Should be at least %s."),
1238 pulongest (size
), pulongest (SVE_HEADER_SIZE
));
1240 /* The ZA register note in a core file can have a couple of states:
1242 1 - Just the header without the payload. This means that there is no
1243 ZA data, and we should populate only SVCR and SVG registers on GDB's
1244 side. The ZA data should be marked as unavailable.
1246 2 - The header with an additional data payload. This means there is
1247 actual ZA data, and we should populate ZA, SVCR and SVG. */
1249 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1253 = sve_vg_from_vl (extract_unsigned_integer (header
+ SVE_HEADER_VL_OFFSET
,
1254 SVE_HEADER_VL_LENGTH
,
1256 regcache
->raw_supply (tdep
->sme_svg_regnum
, &svg
);
1259 = extract_unsigned_integer (header
+ SVE_HEADER_SIZE_OFFSET
,
1260 SVE_HEADER_SIZE_LENGTH
, byte_order
)
1263 /* Populate SVCR. */
1264 bool has_za_payload
= (data_size
> 0);
1266 regcache
->raw_collect (tdep
->sme_svcr_regnum
, &svcr
);
1268 /* If we have a ZA payload, enable bit 2 of SVCR, otherwise clear it. This
1269 register gets updated by the SVE/SSVE-handling functions as well, as they
1270 report the SM bit 1. */
1272 svcr
|= SVCR_ZA_BIT
;
1274 svcr
&= ~SVCR_ZA_BIT
;
1276 /* Update SVCR in the register buffer. */
1277 regcache
->raw_supply (tdep
->sme_svcr_regnum
, &svcr
);
1279 /* Populate the register cache with ZA register contents, if we have any. */
1280 buf
= has_za_payload
? (gdb_byte
*) buf
+ SVE_HEADER_SIZE
: nullptr;
1282 size_t za_bytes
= std::pow (sve_vl_from_vg (svg
), 2);
1284 /* Update ZA in the register buffer. */
1287 /* Check that the payload size is sane. */
1288 if (size
< SVE_HEADER_SIZE
+ za_bytes
)
1290 error (_("ZA header + payload size (%s) invalid. Should be at "
1292 pulongest (size
), pulongest (SVE_HEADER_SIZE
+ za_bytes
));
1295 regcache
->raw_supply (tdep
->sme_za_regnum
, buf
);
1299 gdb_byte za_zeroed
[za_bytes
];
1300 memset (za_zeroed
, 0, za_bytes
);
1301 regcache
->raw_supply (tdep
->sme_za_regnum
, za_zeroed
);
1305 /* Collect register REGNUM from REGCACHE to BUF, using the register
1306 map in REGSET. If REGNUM is -1, do this for all registers in
1310 aarch64_linux_collect_za_regset (const struct regset
*regset
,
1311 const struct regcache
*regcache
,
1312 int regnum
, void *buf
, size_t size
)
1314 gdb_assert (buf
!= nullptr);
1316 /* Sanity check the dump size. */
1317 gdb_assert (size
>= SVE_HEADER_SIZE
);
1319 /* The ZA register note in a core file can have a couple of states:
1321 1 - Just the header without the payload. This means that there is no
1322 ZA data, and we should dump just the header.
1324 2 - The header with an additional data payload. This means there is
1325 actual ZA data, and we should dump both the header and the ZA data
1328 aarch64_gdbarch_tdep
*tdep
1329 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
1331 /* Determine if we have ZA state from the SVCR register ZA bit. */
1333 regcache
->raw_collect (tdep
->sme_svcr_regnum
, &svcr
);
1335 /* Check the ZA payload. */
1336 bool has_za_payload
= (svcr
& SVCR_ZA_BIT
) != 0;
1337 size
= has_za_payload
? size
: SVE_HEADER_SIZE
;
1339 /* Write the size and max_size fields. */
1340 gdb_byte
*header
= (gdb_byte
*) buf
;
1341 enum bfd_endian byte_order
= gdbarch_byte_order (regcache
->arch ());
1342 store_unsigned_integer (header
+ SVE_HEADER_SIZE_OFFSET
,
1343 SVE_HEADER_SIZE_LENGTH
, byte_order
, size
);
1346 = SVE_HEADER_SIZE
+ std::pow (sve_vl_from_vq (tdep
->sme_svq
), 2);
1347 store_unsigned_integer (header
+ SVE_HEADER_MAX_SIZE_OFFSET
,
1348 SVE_HEADER_MAX_SIZE_LENGTH
, byte_order
, max_size
);
1350 /* Output the other fields of the ZA header (vl, max_vl, flags and
1352 uint64_t svq
= tdep
->sme_svq
;
1353 store_unsigned_integer (header
+ SVE_HEADER_VL_OFFSET
, SVE_HEADER_VL_LENGTH
,
1354 byte_order
, sve_vl_from_vq (svq
));
1356 uint16_t max_vl
= SVE_CORE_DUMMY_MAX_VL
;
1357 store_unsigned_integer (header
+ SVE_HEADER_MAX_VL_OFFSET
,
1358 SVE_HEADER_MAX_VL_LENGTH
, byte_order
,
1361 uint16_t flags
= SVE_CORE_DUMMY_FLAGS
;
1362 store_unsigned_integer (header
+ SVE_HEADER_FLAGS_OFFSET
,
1363 SVE_HEADER_FLAGS_LENGTH
, byte_order
, flags
);
1365 uint16_t reserved
= SVE_CORE_DUMMY_RESERVED
;
1366 store_unsigned_integer (header
+ SVE_HEADER_RESERVED_OFFSET
,
1367 SVE_HEADER_RESERVED_LENGTH
, byte_order
, reserved
);
1369 buf
= has_za_payload
? (gdb_byte
*) buf
+ SVE_HEADER_SIZE
: nullptr;
1371 /* Dump the register cache contents for the ZA register to the buffer. */
1372 regcache
->collect_regset (regset
, regnum
, (gdb_byte
*) buf
,
1373 size
- SVE_HEADER_SIZE
);
1376 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1377 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1378 If BUF is NULL, set the registers to "unavailable" status. */
1381 aarch64_linux_supply_zt_regset (const struct regset
*regset
,
1382 struct regcache
*regcache
,
1383 int regnum
, const void *buf
, size_t size
)
1385 /* Read the ZT register note from a core file into the register buffer. */
1387 /* Make sure the buffer contains at least the expected amount of data we are
1389 gdb_assert (size
>= AARCH64_SME2_ZT0_SIZE
);
1391 /* Handle an empty buffer. */
1393 return regcache
->supply_regset (regset
, regnum
, nullptr, size
);
1395 aarch64_gdbarch_tdep
*tdep
1396 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
1398 /* Supply the ZT0 register contents. */
1399 regcache
->raw_supply (tdep
->sme2_zt0_regnum
, buf
);
1402 /* Collect register REGNUM from REGCACHE to BUF, using the register
1403 map in REGSET. If REGNUM is -1, do this for all registers in
1407 aarch64_linux_collect_zt_regset (const struct regset
*regset
,
1408 const struct regcache
*regcache
,
1409 int regnum
, void *buf
, size_t size
)
1411 /* Read the ZT register contents from the register buffer into the core
1414 /* Make sure the buffer can hold the data we need to return. */
1415 gdb_assert (size
>= AARCH64_SME2_ZT0_SIZE
);
1416 gdb_assert (buf
!= nullptr);
1418 aarch64_gdbarch_tdep
*tdep
1419 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regcache
->arch ());
1421 /* Dump the register cache contents for the ZT register to the buffer. */
1422 regcache
->collect_regset (regset
, tdep
->sme2_zt0_regnum
, buf
,
1423 AARCH64_SME2_ZT0_SIZE
);
1426 /* Implement the "iterate_over_regset_sections" gdbarch method. */
1429 aarch64_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
1430 iterate_over_regset_sections_cb
*cb
,
1432 const struct regcache
*regcache
)
1434 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1436 cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET
, AARCH64_LINUX_SIZEOF_GREGSET
,
1437 &aarch64_linux_gregset
, NULL
, cb_data
);
1439 if (tdep
->has_sve ())
1441 /* Create this on the fly in order to handle vector register sizes. */
1442 const struct regcache_map_entry sve_regmap
[] =
1444 { 32, AARCH64_SVE_Z0_REGNUM
, (int) (tdep
->vq
* 16) },
1445 { 16, AARCH64_SVE_P0_REGNUM
, (int) (tdep
->vq
* 16 / 8) },
1446 { 1, AARCH64_SVE_FFR_REGNUM
, (int) (tdep
->vq
* 16 / 8) },
1447 { 1, AARCH64_FPSR_REGNUM
, 4 },
1448 { 1, AARCH64_FPCR_REGNUM
, 4 },
1452 const struct regset aarch64_linux_ssve_regset
=
1455 aarch64_linux_supply_ssve_regset
, aarch64_linux_collect_ssve_regset
,
1456 REGSET_VARIABLE_SIZE
1459 /* If SME is supported in the core file, process the SSVE section first,
1460 and the SVE section last. This is because we need information from
1461 the SSVE set to determine if streaming mode is active. If streaming
1462 mode is active, we need to extract the data from the SSVE section.
1464 Otherwise, if streaming mode is not active, we fetch the data from the
1466 if (tdep
->has_sme ())
1468 cb (".reg-aarch-ssve",
1470 + regcache_map_entry_size (aarch64_linux_fpregmap
),
1471 SVE_HEADER_SIZE
+ regcache_map_entry_size (sve_regmap
),
1472 &aarch64_linux_ssve_regset
, "SSVE registers", cb_data
);
1475 /* Handle the SVE register set. */
1476 const struct regset aarch64_linux_sve_regset
=
1479 aarch64_linux_supply_sve_regset
, aarch64_linux_collect_sve_regset
,
1480 REGSET_VARIABLE_SIZE
1483 cb (".reg-aarch-sve",
1484 SVE_HEADER_SIZE
+ regcache_map_entry_size (aarch64_linux_fpregmap
),
1485 SVE_HEADER_SIZE
+ regcache_map_entry_size (sve_regmap
),
1486 &aarch64_linux_sve_regset
, "SVE registers", cb_data
);
1489 cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET
, AARCH64_LINUX_SIZEOF_FPREGSET
,
1490 &aarch64_linux_fpregset
, NULL
, cb_data
);
1492 if (tdep
->has_sme ())
1494 /* Setup the register set information for a ZA register set core
1497 /* Create this on the fly in order to handle the ZA register size. */
1498 const struct regcache_map_entry za_regmap
[] =
1500 { 1, tdep
->sme_za_regnum
, (int) std::pow (sve_vl_from_vq (tdep
->sme_svq
), 2) }
1503 const struct regset aarch64_linux_za_regset
=
1506 aarch64_linux_supply_za_regset
, aarch64_linux_collect_za_regset
,
1507 REGSET_VARIABLE_SIZE
1510 cb (".reg-aarch-za",
1512 SVE_HEADER_SIZE
+ std::pow (sve_vl_from_vq (tdep
->sme_svq
), 2),
1513 &aarch64_linux_za_regset
, "ZA register", cb_data
);
1515 /* Handle SME2 (ZT) as well, which is only available if SME is
1517 if (tdep
->has_sme2 ())
1519 const struct regcache_map_entry zt_regmap
[] =
1521 { 1, tdep
->sme2_zt0_regnum
, AARCH64_SME2_ZT0_SIZE
}
1524 /* We set the register set size to REGSET_VARIABLE_SIZE here because
1525 in the future there might be more ZT registers. */
1526 const struct regset aarch64_linux_zt_regset
=
1529 aarch64_linux_supply_zt_regset
, aarch64_linux_collect_zt_regset
,
1530 REGSET_VARIABLE_SIZE
1533 cb (".reg-aarch-zt",
1534 AARCH64_SME2_ZT0_SIZE
,
1535 AARCH64_SME2_ZT0_SIZE
,
1536 &aarch64_linux_zt_regset
, "ZT registers", cb_data
);
1540 if (tdep
->has_pauth ())
1542 /* Create this on the fly in order to handle the variable location. */
1543 const struct regcache_map_entry pauth_regmap
[] =
1545 { 2, AARCH64_PAUTH_DMASK_REGNUM (tdep
->pauth_reg_base
), 8},
1549 const struct regset aarch64_linux_pauth_regset
=
1551 pauth_regmap
, regcache_supply_regset
, regcache_collect_regset
1554 cb (".reg-aarch-pauth", AARCH64_LINUX_SIZEOF_PAUTH
,
1555 AARCH64_LINUX_SIZEOF_PAUTH
, &aarch64_linux_pauth_regset
,
1556 "pauth registers", cb_data
);
1559 /* Handle MTE registers. */
1560 if (tdep
->has_mte ())
1562 /* Create this on the fly in order to handle the variable location. */
1563 const struct regcache_map_entry mte_regmap
[] =
1565 { 1, tdep
->mte_reg_base
, 8},
1569 const struct regset aarch64_linux_mte_regset
=
1571 mte_regmap
, regcache_supply_regset
, regcache_collect_regset
1574 cb (".reg-aarch-mte", AARCH64_LINUX_SIZEOF_MTE_REGSET
,
1575 AARCH64_LINUX_SIZEOF_MTE_REGSET
, &aarch64_linux_mte_regset
,
1576 "MTE registers", cb_data
);
1579 /* Handle the TLS registers. */
1580 if (tdep
->has_tls ())
1582 gdb_assert (tdep
->tls_regnum_base
!= -1);
1583 gdb_assert (tdep
->tls_register_count
> 0);
1585 int sizeof_tls_regset
1586 = AARCH64_TLS_REGISTER_SIZE
* tdep
->tls_register_count
;
1588 const struct regcache_map_entry tls_regmap
[] =
1590 { tdep
->tls_register_count
, tdep
->tls_regnum_base
,
1591 AARCH64_TLS_REGISTER_SIZE
},
1595 const struct regset aarch64_linux_tls_regset
=
1597 tls_regmap
, regcache_supply_regset
, regcache_collect_regset
,
1598 REGSET_VARIABLE_SIZE
1601 cb (".reg-aarch-tls", sizeof_tls_regset
, sizeof_tls_regset
,
1602 &aarch64_linux_tls_regset
, "TLS register", cb_data
);
1606 /* Implement the "core_read_description" gdbarch method. */
1608 static const struct target_desc
*
1609 aarch64_linux_core_read_description (struct gdbarch
*gdbarch
,
1610 struct target_ops
*target
, bfd
*abfd
)
1612 gdb::optional
<gdb::byte_vector
> auxv
= target_read_auxv_raw (target
);
1613 CORE_ADDR hwcap
= linux_get_hwcap (auxv
, target
, gdbarch
);
1614 CORE_ADDR hwcap2
= linux_get_hwcap2 (auxv
, target
, gdbarch
);
1616 aarch64_features features
;
1618 /* We need to extract the SVE data from the .reg-aarch-sve section or the
1619 .reg-aarch-ssve section depending on which one was active when the core
1622 If the SSVE section contains SVE data, then it is considered active.
1623 Otherwise the SVE section is considered active. This guarantees we will
1624 have the correct target description with the correct SVE vector
1626 features
.vq
= aarch64_linux_core_read_vq_from_sections (gdbarch
, abfd
);
1627 features
.pauth
= hwcap
& AARCH64_HWCAP_PACA
;
1628 features
.mte
= hwcap2
& HWCAP2_MTE
;
1630 /* Handle the TLS section. */
1631 asection
*tls
= bfd_get_section_by_name (abfd
, ".reg-aarch-tls");
1634 size_t size
= bfd_section_size (tls
);
1635 /* Convert the size to the number of actual registers, by
1637 features
.tls
= size
/ AARCH64_TLS_REGISTER_SIZE
;
1641 = aarch64_linux_core_read_vq (gdbarch
, abfd
, ".reg-aarch-za");
1643 /* Are the ZT registers available? */
1644 if (bfd_get_section_by_name (abfd
, ".reg-aarch-zt") != nullptr)
1646 /* Check if ZA is also available, otherwise this is an invalid
1648 if (bfd_get_section_by_name (abfd
, ".reg-aarch-za") != nullptr)
1649 features
.sme2
= true;
1651 warning (_("While reading core file sections, found ZT registers entry "
1652 "but no ZA register entry. The ZT contents will be "
1656 return aarch64_read_description (features
);
1659 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
1663 aarch64_stap_is_single_operand (struct gdbarch
*gdbarch
, const char *s
)
1665 return (*s
== '#' || isdigit (*s
) /* Literal number. */
1666 || *s
== '[' /* Register indirection. */
1667 || isalpha (*s
)); /* Register value. */
1670 /* This routine is used to parse a special token in AArch64's assembly.
1672 The special tokens parsed by it are:
1674 - Register displacement (e.g, [fp, #-8])
1676 It returns one if the special token has been parsed successfully,
1677 or zero if the current token is not considered special. */
1679 static expr::operation_up
1680 aarch64_stap_parse_special_token (struct gdbarch
*gdbarch
,
1681 struct stap_parse_info
*p
)
1685 /* Temporary holder for lookahead. */
1686 const char *tmp
= p
->arg
;
1688 /* Used to save the register name. */
1697 /* Register name. */
1698 while (isalnum (*tmp
))
1705 std::string
regname (start
, len
);
1707 if (user_reg_map_name_to_regnum (gdbarch
, regname
.c_str (), len
) == -1)
1708 error (_("Invalid register name `%s' on expression `%s'."),
1709 regname
.c_str (), p
->saved_arg
);
1712 tmp
= skip_spaces (tmp
);
1713 /* Now we expect a number. It can begin with '#' or simply
1723 else if (*tmp
== '+')
1726 if (!isdigit (*tmp
))
1729 displacement
= strtol (tmp
, &endp
, 10);
1732 /* Skipping last `]'. */
1737 using namespace expr
;
1739 /* The displacement. */
1740 struct type
*long_type
= builtin_type (gdbarch
)->builtin_long
;
1742 displacement
= -displacement
;
1743 operation_up disp
= make_operation
<long_const_operation
> (long_type
,
1746 /* The register name. */
1748 = make_operation
<register_operation
> (std::move (regname
));
1751 = make_operation
<add_operation
> (std::move (reg
), std::move (disp
));
1753 /* Casting to the expected type. */
1754 struct type
*arg_ptr_type
= lookup_pointer_type (p
->arg_type
);
1755 sum
= make_operation
<unop_cast_operation
> (std::move (sum
),
1757 return make_operation
<unop_ind_operation
> (std::move (sum
));
1762 /* AArch64 process record-replay constructs: syscall, signal etc. */
1764 static linux_record_tdep aarch64_linux_record_tdep
;
1766 /* Enum that defines the AArch64 linux specific syscall identifiers used for
1767 process record/replay. */
1769 enum aarch64_syscall
{
1770 aarch64_sys_io_setup
= 0,
1771 aarch64_sys_io_destroy
= 1,
1772 aarch64_sys_io_submit
= 2,
1773 aarch64_sys_io_cancel
= 3,
1774 aarch64_sys_io_getevents
= 4,
1775 aarch64_sys_setxattr
= 5,
1776 aarch64_sys_lsetxattr
= 6,
1777 aarch64_sys_fsetxattr
= 7,
1778 aarch64_sys_getxattr
= 8,
1779 aarch64_sys_lgetxattr
= 9,
1780 aarch64_sys_fgetxattr
= 10,
1781 aarch64_sys_listxattr
= 11,
1782 aarch64_sys_llistxattr
= 12,
1783 aarch64_sys_flistxattr
= 13,
1784 aarch64_sys_removexattr
= 14,
1785 aarch64_sys_lremovexattr
= 15,
1786 aarch64_sys_fremovexattr
= 16,
1787 aarch64_sys_getcwd
= 17,
1788 aarch64_sys_lookup_dcookie
= 18,
1789 aarch64_sys_eventfd2
= 19,
1790 aarch64_sys_epoll_create1
= 20,
1791 aarch64_sys_epoll_ctl
= 21,
1792 aarch64_sys_epoll_pwait
= 22,
1793 aarch64_sys_dup
= 23,
1794 aarch64_sys_dup3
= 24,
1795 aarch64_sys_fcntl
= 25,
1796 aarch64_sys_inotify_init1
= 26,
1797 aarch64_sys_inotify_add_watch
= 27,
1798 aarch64_sys_inotify_rm_watch
= 28,
1799 aarch64_sys_ioctl
= 29,
1800 aarch64_sys_ioprio_set
= 30,
1801 aarch64_sys_ioprio_get
= 31,
1802 aarch64_sys_flock
= 32,
1803 aarch64_sys_mknodat
= 33,
1804 aarch64_sys_mkdirat
= 34,
1805 aarch64_sys_unlinkat
= 35,
1806 aarch64_sys_symlinkat
= 36,
1807 aarch64_sys_linkat
= 37,
1808 aarch64_sys_renameat
= 38,
1809 aarch64_sys_umount2
= 39,
1810 aarch64_sys_mount
= 40,
1811 aarch64_sys_pivot_root
= 41,
1812 aarch64_sys_nfsservctl
= 42,
1813 aarch64_sys_statfs
= 43,
1814 aarch64_sys_fstatfs
= 44,
1815 aarch64_sys_truncate
= 45,
1816 aarch64_sys_ftruncate
= 46,
1817 aarch64_sys_fallocate
= 47,
1818 aarch64_sys_faccessat
= 48,
1819 aarch64_sys_chdir
= 49,
1820 aarch64_sys_fchdir
= 50,
1821 aarch64_sys_chroot
= 51,
1822 aarch64_sys_fchmod
= 52,
1823 aarch64_sys_fchmodat
= 53,
1824 aarch64_sys_fchownat
= 54,
1825 aarch64_sys_fchown
= 55,
1826 aarch64_sys_openat
= 56,
1827 aarch64_sys_close
= 57,
1828 aarch64_sys_vhangup
= 58,
1829 aarch64_sys_pipe2
= 59,
1830 aarch64_sys_quotactl
= 60,
1831 aarch64_sys_getdents64
= 61,
1832 aarch64_sys_lseek
= 62,
1833 aarch64_sys_read
= 63,
1834 aarch64_sys_write
= 64,
1835 aarch64_sys_readv
= 65,
1836 aarch64_sys_writev
= 66,
1837 aarch64_sys_pread64
= 67,
1838 aarch64_sys_pwrite64
= 68,
1839 aarch64_sys_preadv
= 69,
1840 aarch64_sys_pwritev
= 70,
1841 aarch64_sys_sendfile
= 71,
1842 aarch64_sys_pselect6
= 72,
1843 aarch64_sys_ppoll
= 73,
1844 aarch64_sys_signalfd4
= 74,
1845 aarch64_sys_vmsplice
= 75,
1846 aarch64_sys_splice
= 76,
1847 aarch64_sys_tee
= 77,
1848 aarch64_sys_readlinkat
= 78,
1849 aarch64_sys_newfstatat
= 79,
1850 aarch64_sys_fstat
= 80,
1851 aarch64_sys_sync
= 81,
1852 aarch64_sys_fsync
= 82,
1853 aarch64_sys_fdatasync
= 83,
1854 aarch64_sys_sync_file_range2
= 84,
1855 aarch64_sys_sync_file_range
= 84,
1856 aarch64_sys_timerfd_create
= 85,
1857 aarch64_sys_timerfd_settime
= 86,
1858 aarch64_sys_timerfd_gettime
= 87,
1859 aarch64_sys_utimensat
= 88,
1860 aarch64_sys_acct
= 89,
1861 aarch64_sys_capget
= 90,
1862 aarch64_sys_capset
= 91,
1863 aarch64_sys_personality
= 92,
1864 aarch64_sys_exit
= 93,
1865 aarch64_sys_exit_group
= 94,
1866 aarch64_sys_waitid
= 95,
1867 aarch64_sys_set_tid_address
= 96,
1868 aarch64_sys_unshare
= 97,
1869 aarch64_sys_futex
= 98,
1870 aarch64_sys_set_robust_list
= 99,
1871 aarch64_sys_get_robust_list
= 100,
1872 aarch64_sys_nanosleep
= 101,
1873 aarch64_sys_getitimer
= 102,
1874 aarch64_sys_setitimer
= 103,
1875 aarch64_sys_kexec_load
= 104,
1876 aarch64_sys_init_module
= 105,
1877 aarch64_sys_delete_module
= 106,
1878 aarch64_sys_timer_create
= 107,
1879 aarch64_sys_timer_gettime
= 108,
1880 aarch64_sys_timer_getoverrun
= 109,
1881 aarch64_sys_timer_settime
= 110,
1882 aarch64_sys_timer_delete
= 111,
1883 aarch64_sys_clock_settime
= 112,
1884 aarch64_sys_clock_gettime
= 113,
1885 aarch64_sys_clock_getres
= 114,
1886 aarch64_sys_clock_nanosleep
= 115,
1887 aarch64_sys_syslog
= 116,
1888 aarch64_sys_ptrace
= 117,
1889 aarch64_sys_sched_setparam
= 118,
1890 aarch64_sys_sched_setscheduler
= 119,
1891 aarch64_sys_sched_getscheduler
= 120,
1892 aarch64_sys_sched_getparam
= 121,
1893 aarch64_sys_sched_setaffinity
= 122,
1894 aarch64_sys_sched_getaffinity
= 123,
1895 aarch64_sys_sched_yield
= 124,
1896 aarch64_sys_sched_get_priority_max
= 125,
1897 aarch64_sys_sched_get_priority_min
= 126,
1898 aarch64_sys_sched_rr_get_interval
= 127,
1899 aarch64_sys_kill
= 129,
1900 aarch64_sys_tkill
= 130,
1901 aarch64_sys_tgkill
= 131,
1902 aarch64_sys_sigaltstack
= 132,
1903 aarch64_sys_rt_sigsuspend
= 133,
1904 aarch64_sys_rt_sigaction
= 134,
1905 aarch64_sys_rt_sigprocmask
= 135,
1906 aarch64_sys_rt_sigpending
= 136,
1907 aarch64_sys_rt_sigtimedwait
= 137,
1908 aarch64_sys_rt_sigqueueinfo
= 138,
1909 aarch64_sys_rt_sigreturn
= 139,
1910 aarch64_sys_setpriority
= 140,
1911 aarch64_sys_getpriority
= 141,
1912 aarch64_sys_reboot
= 142,
1913 aarch64_sys_setregid
= 143,
1914 aarch64_sys_setgid
= 144,
1915 aarch64_sys_setreuid
= 145,
1916 aarch64_sys_setuid
= 146,
1917 aarch64_sys_setresuid
= 147,
1918 aarch64_sys_getresuid
= 148,
1919 aarch64_sys_setresgid
= 149,
1920 aarch64_sys_getresgid
= 150,
1921 aarch64_sys_setfsuid
= 151,
1922 aarch64_sys_setfsgid
= 152,
1923 aarch64_sys_times
= 153,
1924 aarch64_sys_setpgid
= 154,
1925 aarch64_sys_getpgid
= 155,
1926 aarch64_sys_getsid
= 156,
1927 aarch64_sys_setsid
= 157,
1928 aarch64_sys_getgroups
= 158,
1929 aarch64_sys_setgroups
= 159,
1930 aarch64_sys_uname
= 160,
1931 aarch64_sys_sethostname
= 161,
1932 aarch64_sys_setdomainname
= 162,
1933 aarch64_sys_getrlimit
= 163,
1934 aarch64_sys_setrlimit
= 164,
1935 aarch64_sys_getrusage
= 165,
1936 aarch64_sys_umask
= 166,
1937 aarch64_sys_prctl
= 167,
1938 aarch64_sys_getcpu
= 168,
1939 aarch64_sys_gettimeofday
= 169,
1940 aarch64_sys_settimeofday
= 170,
1941 aarch64_sys_adjtimex
= 171,
1942 aarch64_sys_getpid
= 172,
1943 aarch64_sys_getppid
= 173,
1944 aarch64_sys_getuid
= 174,
1945 aarch64_sys_geteuid
= 175,
1946 aarch64_sys_getgid
= 176,
1947 aarch64_sys_getegid
= 177,
1948 aarch64_sys_gettid
= 178,
1949 aarch64_sys_sysinfo
= 179,
1950 aarch64_sys_mq_open
= 180,
1951 aarch64_sys_mq_unlink
= 181,
1952 aarch64_sys_mq_timedsend
= 182,
1953 aarch64_sys_mq_timedreceive
= 183,
1954 aarch64_sys_mq_notify
= 184,
1955 aarch64_sys_mq_getsetattr
= 185,
1956 aarch64_sys_msgget
= 186,
1957 aarch64_sys_msgctl
= 187,
1958 aarch64_sys_msgrcv
= 188,
1959 aarch64_sys_msgsnd
= 189,
1960 aarch64_sys_semget
= 190,
1961 aarch64_sys_semctl
= 191,
1962 aarch64_sys_semtimedop
= 192,
1963 aarch64_sys_semop
= 193,
1964 aarch64_sys_shmget
= 194,
1965 aarch64_sys_shmctl
= 195,
1966 aarch64_sys_shmat
= 196,
1967 aarch64_sys_shmdt
= 197,
1968 aarch64_sys_socket
= 198,
1969 aarch64_sys_socketpair
= 199,
1970 aarch64_sys_bind
= 200,
1971 aarch64_sys_listen
= 201,
1972 aarch64_sys_accept
= 202,
1973 aarch64_sys_connect
= 203,
1974 aarch64_sys_getsockname
= 204,
1975 aarch64_sys_getpeername
= 205,
1976 aarch64_sys_sendto
= 206,
1977 aarch64_sys_recvfrom
= 207,
1978 aarch64_sys_setsockopt
= 208,
1979 aarch64_sys_getsockopt
= 209,
1980 aarch64_sys_shutdown
= 210,
1981 aarch64_sys_sendmsg
= 211,
1982 aarch64_sys_recvmsg
= 212,
1983 aarch64_sys_readahead
= 213,
1984 aarch64_sys_brk
= 214,
1985 aarch64_sys_munmap
= 215,
1986 aarch64_sys_mremap
= 216,
1987 aarch64_sys_add_key
= 217,
1988 aarch64_sys_request_key
= 218,
1989 aarch64_sys_keyctl
= 219,
1990 aarch64_sys_clone
= 220,
1991 aarch64_sys_execve
= 221,
1992 aarch64_sys_mmap
= 222,
1993 aarch64_sys_fadvise64
= 223,
1994 aarch64_sys_swapon
= 224,
1995 aarch64_sys_swapoff
= 225,
1996 aarch64_sys_mprotect
= 226,
1997 aarch64_sys_msync
= 227,
1998 aarch64_sys_mlock
= 228,
1999 aarch64_sys_munlock
= 229,
2000 aarch64_sys_mlockall
= 230,
2001 aarch64_sys_munlockall
= 231,
2002 aarch64_sys_mincore
= 232,
2003 aarch64_sys_madvise
= 233,
2004 aarch64_sys_remap_file_pages
= 234,
2005 aarch64_sys_mbind
= 235,
2006 aarch64_sys_get_mempolicy
= 236,
2007 aarch64_sys_set_mempolicy
= 237,
2008 aarch64_sys_migrate_pages
= 238,
2009 aarch64_sys_move_pages
= 239,
2010 aarch64_sys_rt_tgsigqueueinfo
= 240,
2011 aarch64_sys_perf_event_open
= 241,
2012 aarch64_sys_accept4
= 242,
2013 aarch64_sys_recvmmsg
= 243,
2014 aarch64_sys_wait4
= 260,
2015 aarch64_sys_prlimit64
= 261,
2016 aarch64_sys_fanotify_init
= 262,
2017 aarch64_sys_fanotify_mark
= 263,
2018 aarch64_sys_name_to_handle_at
= 264,
2019 aarch64_sys_open_by_handle_at
= 265,
2020 aarch64_sys_clock_adjtime
= 266,
2021 aarch64_sys_syncfs
= 267,
2022 aarch64_sys_setns
= 268,
2023 aarch64_sys_sendmmsg
= 269,
2024 aarch64_sys_process_vm_readv
= 270,
2025 aarch64_sys_process_vm_writev
= 271,
2026 aarch64_sys_kcmp
= 272,
2027 aarch64_sys_finit_module
= 273,
2028 aarch64_sys_sched_setattr
= 274,
2029 aarch64_sys_sched_getattr
= 275,
2030 aarch64_sys_getrandom
= 278
2033 /* aarch64_canonicalize_syscall maps syscall ids from the native AArch64
2034 linux set of syscall ids into a canonical set of syscall ids used by
2037 static enum gdb_syscall
2038 aarch64_canonicalize_syscall (enum aarch64_syscall syscall_number
)
2040 #define SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
2041 return gdb_sys_##SYSCALL
2043 #define UNSUPPORTED_SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
2044 return gdb_sys_no_syscall
2046 switch (syscall_number
)
2048 SYSCALL_MAP (io_setup
);
2049 SYSCALL_MAP (io_destroy
);
2050 SYSCALL_MAP (io_submit
);
2051 SYSCALL_MAP (io_cancel
);
2052 SYSCALL_MAP (io_getevents
);
2054 SYSCALL_MAP (setxattr
);
2055 SYSCALL_MAP (lsetxattr
);
2056 SYSCALL_MAP (fsetxattr
);
2057 SYSCALL_MAP (getxattr
);
2058 SYSCALL_MAP (lgetxattr
);
2059 SYSCALL_MAP (fgetxattr
);
2060 SYSCALL_MAP (listxattr
);
2061 SYSCALL_MAP (llistxattr
);
2062 SYSCALL_MAP (flistxattr
);
2063 SYSCALL_MAP (removexattr
);
2064 SYSCALL_MAP (lremovexattr
);
2065 SYSCALL_MAP (fremovexattr
);
2066 SYSCALL_MAP (getcwd
);
2067 SYSCALL_MAP (lookup_dcookie
);
2068 SYSCALL_MAP (eventfd2
);
2069 SYSCALL_MAP (epoll_create1
);
2070 SYSCALL_MAP (epoll_ctl
);
2071 SYSCALL_MAP (epoll_pwait
);
2074 SYSCALL_MAP (fcntl
);
2075 SYSCALL_MAP (inotify_init1
);
2076 SYSCALL_MAP (inotify_add_watch
);
2077 SYSCALL_MAP (inotify_rm_watch
);
2078 SYSCALL_MAP (ioctl
);
2079 SYSCALL_MAP (ioprio_set
);
2080 SYSCALL_MAP (ioprio_get
);
2081 SYSCALL_MAP (flock
);
2082 SYSCALL_MAP (mknodat
);
2083 SYSCALL_MAP (mkdirat
);
2084 SYSCALL_MAP (unlinkat
);
2085 SYSCALL_MAP (symlinkat
);
2086 SYSCALL_MAP (linkat
);
2087 SYSCALL_MAP (renameat
);
2088 UNSUPPORTED_SYSCALL_MAP (umount2
);
2089 SYSCALL_MAP (mount
);
2090 SYSCALL_MAP (pivot_root
);
2091 SYSCALL_MAP (nfsservctl
);
2092 SYSCALL_MAP (statfs
);
2093 SYSCALL_MAP (truncate
);
2094 SYSCALL_MAP (ftruncate
);
2095 SYSCALL_MAP (fallocate
);
2096 SYSCALL_MAP (faccessat
);
2097 SYSCALL_MAP (fchdir
);
2098 SYSCALL_MAP (chroot
);
2099 SYSCALL_MAP (fchmod
);
2100 SYSCALL_MAP (fchmodat
);
2101 SYSCALL_MAP (fchownat
);
2102 SYSCALL_MAP (fchown
);
2103 SYSCALL_MAP (openat
);
2104 SYSCALL_MAP (close
);
2105 SYSCALL_MAP (vhangup
);
2106 SYSCALL_MAP (pipe2
);
2107 SYSCALL_MAP (quotactl
);
2108 SYSCALL_MAP (getdents64
);
2109 SYSCALL_MAP (lseek
);
2111 SYSCALL_MAP (write
);
2112 SYSCALL_MAP (readv
);
2113 SYSCALL_MAP (writev
);
2114 SYSCALL_MAP (pread64
);
2115 SYSCALL_MAP (pwrite64
);
2116 UNSUPPORTED_SYSCALL_MAP (preadv
);
2117 UNSUPPORTED_SYSCALL_MAP (pwritev
);
2118 SYSCALL_MAP (sendfile
);
2119 SYSCALL_MAP (pselect6
);
2120 SYSCALL_MAP (ppoll
);
2121 UNSUPPORTED_SYSCALL_MAP (signalfd4
);
2122 SYSCALL_MAP (vmsplice
);
2123 SYSCALL_MAP (splice
);
2125 SYSCALL_MAP (readlinkat
);
2126 SYSCALL_MAP (newfstatat
);
2128 SYSCALL_MAP (fstat
);
2130 SYSCALL_MAP (fsync
);
2131 SYSCALL_MAP (fdatasync
);
2132 SYSCALL_MAP (sync_file_range
);
2133 UNSUPPORTED_SYSCALL_MAP (timerfd_create
);
2134 UNSUPPORTED_SYSCALL_MAP (timerfd_settime
);
2135 UNSUPPORTED_SYSCALL_MAP (timerfd_gettime
);
2136 UNSUPPORTED_SYSCALL_MAP (utimensat
);
2138 SYSCALL_MAP (capget
);
2139 SYSCALL_MAP (capset
);
2140 SYSCALL_MAP (personality
);
2142 SYSCALL_MAP (exit_group
);
2143 SYSCALL_MAP (waitid
);
2144 SYSCALL_MAP (set_tid_address
);
2145 SYSCALL_MAP (unshare
);
2146 SYSCALL_MAP (futex
);
2147 SYSCALL_MAP (set_robust_list
);
2148 SYSCALL_MAP (get_robust_list
);
2149 SYSCALL_MAP (nanosleep
);
2151 SYSCALL_MAP (getitimer
);
2152 SYSCALL_MAP (setitimer
);
2153 SYSCALL_MAP (kexec_load
);
2154 SYSCALL_MAP (init_module
);
2155 SYSCALL_MAP (delete_module
);
2156 SYSCALL_MAP (timer_create
);
2157 SYSCALL_MAP (timer_settime
);
2158 SYSCALL_MAP (timer_gettime
);
2159 SYSCALL_MAP (timer_getoverrun
);
2160 SYSCALL_MAP (timer_delete
);
2161 SYSCALL_MAP (clock_settime
);
2162 SYSCALL_MAP (clock_gettime
);
2163 SYSCALL_MAP (clock_getres
);
2164 SYSCALL_MAP (clock_nanosleep
);
2165 SYSCALL_MAP (syslog
);
2166 SYSCALL_MAP (ptrace
);
2167 SYSCALL_MAP (sched_setparam
);
2168 SYSCALL_MAP (sched_setscheduler
);
2169 SYSCALL_MAP (sched_getscheduler
);
2170 SYSCALL_MAP (sched_getparam
);
2171 SYSCALL_MAP (sched_setaffinity
);
2172 SYSCALL_MAP (sched_getaffinity
);
2173 SYSCALL_MAP (sched_yield
);
2174 SYSCALL_MAP (sched_get_priority_max
);
2175 SYSCALL_MAP (sched_get_priority_min
);
2176 SYSCALL_MAP (sched_rr_get_interval
);
2178 SYSCALL_MAP (tkill
);
2179 SYSCALL_MAP (tgkill
);
2180 SYSCALL_MAP (sigaltstack
);
2181 SYSCALL_MAP (rt_sigsuspend
);
2182 SYSCALL_MAP (rt_sigaction
);
2183 SYSCALL_MAP (rt_sigprocmask
);
2184 SYSCALL_MAP (rt_sigpending
);
2185 SYSCALL_MAP (rt_sigtimedwait
);
2186 SYSCALL_MAP (rt_sigqueueinfo
);
2187 SYSCALL_MAP (rt_sigreturn
);
2188 SYSCALL_MAP (setpriority
);
2189 SYSCALL_MAP (getpriority
);
2190 SYSCALL_MAP (reboot
);
2191 SYSCALL_MAP (setregid
);
2192 SYSCALL_MAP (setgid
);
2193 SYSCALL_MAP (setreuid
);
2194 SYSCALL_MAP (setuid
);
2195 SYSCALL_MAP (setresuid
);
2196 SYSCALL_MAP (getresuid
);
2197 SYSCALL_MAP (setresgid
);
2198 SYSCALL_MAP (getresgid
);
2199 SYSCALL_MAP (setfsuid
);
2200 SYSCALL_MAP (setfsgid
);
2201 SYSCALL_MAP (times
);
2202 SYSCALL_MAP (setpgid
);
2203 SYSCALL_MAP (getpgid
);
2204 SYSCALL_MAP (getsid
);
2205 SYSCALL_MAP (setsid
);
2206 SYSCALL_MAP (getgroups
);
2207 SYSCALL_MAP (setgroups
);
2208 SYSCALL_MAP (uname
);
2209 SYSCALL_MAP (sethostname
);
2210 SYSCALL_MAP (setdomainname
);
2211 SYSCALL_MAP (getrlimit
);
2212 SYSCALL_MAP (setrlimit
);
2213 SYSCALL_MAP (getrusage
);
2214 SYSCALL_MAP (umask
);
2215 SYSCALL_MAP (prctl
);
2216 SYSCALL_MAP (getcpu
);
2217 SYSCALL_MAP (gettimeofday
);
2218 SYSCALL_MAP (settimeofday
);
2219 SYSCALL_MAP (adjtimex
);
2220 SYSCALL_MAP (getpid
);
2221 SYSCALL_MAP (getppid
);
2222 SYSCALL_MAP (getuid
);
2223 SYSCALL_MAP (geteuid
);
2224 SYSCALL_MAP (getgid
);
2225 SYSCALL_MAP (getegid
);
2226 SYSCALL_MAP (gettid
);
2227 SYSCALL_MAP (sysinfo
);
2228 SYSCALL_MAP (mq_open
);
2229 SYSCALL_MAP (mq_unlink
);
2230 SYSCALL_MAP (mq_timedsend
);
2231 SYSCALL_MAP (mq_timedreceive
);
2232 SYSCALL_MAP (mq_notify
);
2233 SYSCALL_MAP (mq_getsetattr
);
2234 SYSCALL_MAP (msgget
);
2235 SYSCALL_MAP (msgctl
);
2236 SYSCALL_MAP (msgrcv
);
2237 SYSCALL_MAP (msgsnd
);
2238 SYSCALL_MAP (semget
);
2239 SYSCALL_MAP (semctl
);
2240 SYSCALL_MAP (semtimedop
);
2241 SYSCALL_MAP (semop
);
2242 SYSCALL_MAP (shmget
);
2243 SYSCALL_MAP (shmctl
);
2244 SYSCALL_MAP (shmat
);
2245 SYSCALL_MAP (shmdt
);
2246 SYSCALL_MAP (socket
);
2247 SYSCALL_MAP (socketpair
);
2249 SYSCALL_MAP (listen
);
2250 SYSCALL_MAP (accept
);
2251 SYSCALL_MAP (connect
);
2252 SYSCALL_MAP (getsockname
);
2253 SYSCALL_MAP (getpeername
);
2254 SYSCALL_MAP (sendto
);
2255 SYSCALL_MAP (recvfrom
);
2256 SYSCALL_MAP (setsockopt
);
2257 SYSCALL_MAP (getsockopt
);
2258 SYSCALL_MAP (shutdown
);
2259 SYSCALL_MAP (sendmsg
);
2260 SYSCALL_MAP (recvmsg
);
2261 SYSCALL_MAP (readahead
);
2263 SYSCALL_MAP (munmap
);
2264 SYSCALL_MAP (mremap
);
2265 SYSCALL_MAP (add_key
);
2266 SYSCALL_MAP (request_key
);
2267 SYSCALL_MAP (keyctl
);
2268 SYSCALL_MAP (clone
);
2269 SYSCALL_MAP (execve
);
2271 case aarch64_sys_mmap
:
2272 return gdb_sys_mmap2
;
2274 SYSCALL_MAP (fadvise64
);
2275 SYSCALL_MAP (swapon
);
2276 SYSCALL_MAP (swapoff
);
2277 SYSCALL_MAP (mprotect
);
2278 SYSCALL_MAP (msync
);
2279 SYSCALL_MAP (mlock
);
2280 SYSCALL_MAP (munlock
);
2281 SYSCALL_MAP (mlockall
);
2282 SYSCALL_MAP (munlockall
);
2283 SYSCALL_MAP (mincore
);
2284 SYSCALL_MAP (madvise
);
2285 SYSCALL_MAP (remap_file_pages
);
2286 SYSCALL_MAP (mbind
);
2287 SYSCALL_MAP (get_mempolicy
);
2288 SYSCALL_MAP (set_mempolicy
);
2289 SYSCALL_MAP (migrate_pages
);
2290 SYSCALL_MAP (move_pages
);
2291 UNSUPPORTED_SYSCALL_MAP (rt_tgsigqueueinfo
);
2292 UNSUPPORTED_SYSCALL_MAP (perf_event_open
);
2293 UNSUPPORTED_SYSCALL_MAP (accept4
);
2294 UNSUPPORTED_SYSCALL_MAP (recvmmsg
);
2296 SYSCALL_MAP (wait4
);
2298 UNSUPPORTED_SYSCALL_MAP (prlimit64
);
2299 UNSUPPORTED_SYSCALL_MAP (fanotify_init
);
2300 UNSUPPORTED_SYSCALL_MAP (fanotify_mark
);
2301 UNSUPPORTED_SYSCALL_MAP (name_to_handle_at
);
2302 UNSUPPORTED_SYSCALL_MAP (open_by_handle_at
);
2303 UNSUPPORTED_SYSCALL_MAP (clock_adjtime
);
2304 UNSUPPORTED_SYSCALL_MAP (syncfs
);
2305 UNSUPPORTED_SYSCALL_MAP (setns
);
2306 UNSUPPORTED_SYSCALL_MAP (sendmmsg
);
2307 UNSUPPORTED_SYSCALL_MAP (process_vm_readv
);
2308 UNSUPPORTED_SYSCALL_MAP (process_vm_writev
);
2309 UNSUPPORTED_SYSCALL_MAP (kcmp
);
2310 UNSUPPORTED_SYSCALL_MAP (finit_module
);
2311 UNSUPPORTED_SYSCALL_MAP (sched_setattr
);
2312 UNSUPPORTED_SYSCALL_MAP (sched_getattr
);
2313 SYSCALL_MAP (getrandom
);
2315 return gdb_sys_no_syscall
;
2319 /* Retrieve the syscall number at a ptrace syscall-stop, either on syscall entry
2320 or exit. Return -1 upon error. */
2323 aarch64_linux_get_syscall_number (struct gdbarch
*gdbarch
, thread_info
*thread
)
2325 struct regcache
*regs
= get_thread_regcache (thread
);
2328 /* Get the system call number from register x8. */
2329 regs
->cooked_read (AARCH64_X0_REGNUM
+ 8, &ret
);
2331 /* On exit from a successful execve, we will be in a new process and all the
2332 registers will be cleared - x0 to x30 will be 0, except for a 1 in x7.
2333 This function will only ever get called when stopped at the entry or exit
2334 of a syscall, so by checking for 0 in x0 (arg0/retval), x1 (arg1), x8
2335 (syscall), x29 (FP) and x30 (LR) we can infer:
2336 1) Either inferior is at exit from successful execve.
2337 2) Or inferior is at entry to a call to io_setup with invalid arguments and
2338 a corrupted FP and LR.
2339 It should be safe enough to assume case 1. */
2342 LONGEST x1
= -1, fp
= -1, lr
= -1;
2343 regs
->cooked_read (AARCH64_X0_REGNUM
+ 1, &x1
);
2344 regs
->cooked_read (AARCH64_FP_REGNUM
, &fp
);
2345 regs
->cooked_read (AARCH64_LR_REGNUM
, &lr
);
2346 if (x1
== 0 && fp
==0 && lr
== 0)
2347 return aarch64_sys_execve
;
2353 /* Record all registers but PC register for process-record. */
2356 aarch64_all_but_pc_registers_record (struct regcache
*regcache
)
2360 for (i
= AARCH64_X0_REGNUM
; i
< AARCH64_PC_REGNUM
; i
++)
2361 if (record_full_arch_list_add_reg (regcache
, i
))
2364 if (record_full_arch_list_add_reg (regcache
, AARCH64_CPSR_REGNUM
))
2370 /* Handler for aarch64 system call instruction recording. */
2373 aarch64_linux_syscall_record (struct regcache
*regcache
,
2374 unsigned long svc_number
)
2377 enum gdb_syscall syscall_gdb
;
2380 aarch64_canonicalize_syscall ((enum aarch64_syscall
) svc_number
);
2382 if (syscall_gdb
< 0)
2384 gdb_printf (gdb_stderr
,
2385 _("Process record and replay target doesn't "
2386 "support syscall number %s\n"),
2387 plongest (svc_number
));
2391 if (syscall_gdb
== gdb_sys_sigreturn
2392 || syscall_gdb
== gdb_sys_rt_sigreturn
)
2394 if (aarch64_all_but_pc_registers_record (regcache
))
2399 ret
= record_linux_system_call (syscall_gdb
, regcache
,
2400 &aarch64_linux_record_tdep
);
2404 /* Record the return value of the system call. */
2405 if (record_full_arch_list_add_reg (regcache
, AARCH64_X0_REGNUM
))
2408 if (record_full_arch_list_add_reg (regcache
, AARCH64_LR_REGNUM
))
2411 if (record_full_arch_list_add_reg (regcache
, AARCH64_CPSR_REGNUM
))
2417 /* Implement the "gcc_target_options" gdbarch method. */
2420 aarch64_linux_gcc_target_options (struct gdbarch
*gdbarch
)
2422 /* GCC doesn't know "-m64". */
2426 /* Helper to get the allocation tag from a 64-bit ADDRESS.
2428 Return the allocation tag if successful and nullopt otherwise. */
2430 static gdb::optional
<CORE_ADDR
>
2431 aarch64_mte_get_atag (CORE_ADDR address
)
2433 gdb::byte_vector tags
;
2435 /* Attempt to fetch the allocation tag. */
2436 if (!target_fetch_memtags (address
, 1, tags
,
2437 static_cast<int> (memtag_type::allocation
)))
2440 /* Only one tag should've been returned. Make sure we got exactly that. */
2441 if (tags
.size () != 1)
2442 error (_("Target returned an unexpected number of tags."));
2444 /* Although our tags are 4 bits in size, they are stored in a
2449 /* Implement the tagged_address_p gdbarch method. */
2452 aarch64_linux_tagged_address_p (struct gdbarch
*gdbarch
, struct value
*address
)
2454 gdb_assert (address
!= nullptr);
2456 CORE_ADDR addr
= value_as_address (address
);
2458 /* Remove the top byte for the memory range check. */
2459 addr
= gdbarch_remove_non_address_bits (gdbarch
, addr
);
2461 /* Check if the page that contains ADDRESS is mapped with PROT_MTE. */
2462 if (!linux_address_in_memtag_page (addr
))
2465 /* We have a valid tag in the top byte of the 64-bit address. */
2469 /* Implement the memtag_matches_p gdbarch method. */
2472 aarch64_linux_memtag_matches_p (struct gdbarch
*gdbarch
,
2473 struct value
*address
)
2475 gdb_assert (address
!= nullptr);
2477 /* Make sure we are dealing with a tagged address to begin with. */
2478 if (!aarch64_linux_tagged_address_p (gdbarch
, address
))
2481 CORE_ADDR addr
= value_as_address (address
);
2483 /* Fetch the allocation tag for ADDRESS. */
2484 gdb::optional
<CORE_ADDR
> atag
2485 = aarch64_mte_get_atag (gdbarch_remove_non_address_bits (gdbarch
, addr
));
2487 if (!atag
.has_value ())
2490 /* Fetch the logical tag for ADDRESS. */
2491 gdb_byte ltag
= aarch64_mte_get_ltag (addr
);
2493 /* Are the tags the same? */
2494 return ltag
== *atag
;
2497 /* Implement the set_memtags gdbarch method. */
2500 aarch64_linux_set_memtags (struct gdbarch
*gdbarch
, struct value
*address
,
2501 size_t length
, const gdb::byte_vector
&tags
,
2502 memtag_type tag_type
)
2504 gdb_assert (!tags
.empty ());
2505 gdb_assert (address
!= nullptr);
2507 CORE_ADDR addr
= value_as_address (address
);
2509 /* Set the logical tag or the allocation tag. */
2510 if (tag_type
== memtag_type::logical
)
2512 /* When setting logical tags, we don't care about the length, since
2513 we are only setting a single logical tag. */
2514 addr
= aarch64_mte_set_ltag (addr
, tags
[0]);
2516 /* Update the value's content with the tag. */
2517 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2518 gdb_byte
*srcbuf
= address
->contents_raw ().data ();
2519 store_unsigned_integer (srcbuf
, sizeof (addr
), byte_order
, addr
);
2523 /* Remove the top byte. */
2524 addr
= gdbarch_remove_non_address_bits (gdbarch
, addr
);
2526 /* Make sure we are dealing with a tagged address to begin with. */
2527 if (!aarch64_linux_tagged_address_p (gdbarch
, address
))
2530 /* With G being the number of tag granules and N the number of tags
2531 passed in, we can have the following cases:
2533 1 - G == N: Store all the N tags to memory.
2535 2 - G < N : Warn about having more tags than granules, but write G
2538 3 - G > N : This is a "fill tags" operation. We should use the tags
2539 as a pattern to fill the granules repeatedly until we have
2540 written G tags to memory.
2543 size_t g
= aarch64_mte_get_tag_granules (addr
, length
,
2544 AARCH64_MTE_GRANULE_SIZE
);
2545 size_t n
= tags
.size ();
2548 warning (_("Got more tags than memory granules. Tags will be "
2551 warning (_("Using tag pattern to fill memory range."));
2553 if (!target_store_memtags (addr
, length
, tags
,
2554 static_cast<int> (memtag_type::allocation
)))
2560 /* Implement the get_memtag gdbarch method. */
2562 static struct value
*
2563 aarch64_linux_get_memtag (struct gdbarch
*gdbarch
, struct value
*address
,
2564 memtag_type tag_type
)
2566 gdb_assert (address
!= nullptr);
2568 CORE_ADDR addr
= value_as_address (address
);
2571 /* Get the logical tag or the allocation tag. */
2572 if (tag_type
== memtag_type::logical
)
2573 tag
= aarch64_mte_get_ltag (addr
);
2576 /* Make sure we are dealing with a tagged address to begin with. */
2577 if (!aarch64_linux_tagged_address_p (gdbarch
, address
))
2580 /* Remove the top byte. */
2581 addr
= gdbarch_remove_non_address_bits (gdbarch
, addr
);
2582 gdb::optional
<CORE_ADDR
> atag
= aarch64_mte_get_atag (addr
);
2584 if (!atag
.has_value ())
2590 /* Convert the tag to a value. */
2591 return value_from_ulongest (builtin_type (gdbarch
)->builtin_unsigned_int
,
2595 /* Implement the memtag_to_string gdbarch method. */
2598 aarch64_linux_memtag_to_string (struct gdbarch
*gdbarch
, struct value
*tag_value
)
2600 if (tag_value
== nullptr)
2603 CORE_ADDR tag
= value_as_address (tag_value
);
2605 return string_printf ("0x%s", phex_nz (tag
, sizeof (tag
)));
2608 /* AArch64 Linux implementation of the report_signal_info gdbarch
2609 hook. Displays information about possible memory tag violations. */
2612 aarch64_linux_report_signal_info (struct gdbarch
*gdbarch
,
2613 struct ui_out
*uiout
,
2614 enum gdb_signal siggnal
)
2616 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2618 if (!tdep
->has_mte () || siggnal
!= GDB_SIGNAL_SEGV
)
2621 CORE_ADDR fault_addr
= 0;
2626 /* Sigcode tells us if the segfault is actually a memory tag
2628 si_code
= parse_and_eval_long ("$_siginfo.si_code");
2631 = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
2633 catch (const gdb_exception_error
&exception
)
2635 exception_print (gdb_stderr
, exception
);
2639 /* If this is not a memory tag violation, just return. */
2640 if (si_code
!= SEGV_MTEAERR
&& si_code
!= SEGV_MTESERR
)
2645 uiout
->field_string ("sigcode-meaning", _("Memory tag violation"));
2647 /* For synchronous faults, show additional information. */
2648 if (si_code
== SEGV_MTESERR
)
2650 uiout
->text (_(" while accessing address "));
2651 uiout
->field_core_addr ("fault-addr", gdbarch
, fault_addr
);
2654 gdb::optional
<CORE_ADDR
> atag
2655 = aarch64_mte_get_atag (gdbarch_remove_non_address_bits (gdbarch
,
2657 gdb_byte ltag
= aarch64_mte_get_ltag (fault_addr
);
2659 if (!atag
.has_value ())
2660 uiout
->text (_("Allocation tag unavailable"));
2663 uiout
->text (_("Allocation tag "));
2664 uiout
->field_string ("allocation-tag", hex_string (*atag
));
2666 uiout
->text (_("Logical tag "));
2667 uiout
->field_string ("logical-tag", hex_string (ltag
));
2673 uiout
->text (_("Fault address unavailable"));
2677 /* AArch64 Linux implementation of the gdbarch_create_memtag_section hook. */
2680 aarch64_linux_create_memtag_section (struct gdbarch
*gdbarch
, bfd
*obfd
,
2681 CORE_ADDR address
, size_t size
)
2683 gdb_assert (obfd
!= nullptr);
2684 gdb_assert (size
> 0);
2686 /* Create the section and associated program header.
2688 Make sure the section's flags has SEC_HAS_CONTENTS, otherwise BFD will
2689 refuse to write data to this section. */
2690 asection
*mte_section
2691 = bfd_make_section_anyway_with_flags (obfd
, "memtag", SEC_HAS_CONTENTS
);
2693 if (mte_section
== nullptr)
2696 bfd_set_section_vma (mte_section
, address
);
2697 /* The size of the memory range covered by the memory tags. We reuse the
2698 section's rawsize field for this purpose. */
2699 mte_section
->rawsize
= size
;
2701 /* Fetch the number of tags we need to save. */
2703 = aarch64_mte_get_tag_granules (address
, size
, AARCH64_MTE_GRANULE_SIZE
);
2704 /* Tags are stored packed as 2 tags per byte. */
2705 bfd_set_section_size (mte_section
, (tags_count
+ 1) >> 1);
2706 /* Store program header information. */
2707 bfd_record_phdr (obfd
, PT_AARCH64_MEMTAG_MTE
, 1, 0, 0, 0, 0, 0, 1,
2713 /* Maximum number of tags to request. */
2714 #define MAX_TAGS_TO_TRANSFER 1024
2716 /* AArch64 Linux implementation of the gdbarch_fill_memtag_section hook. */
2719 aarch64_linux_fill_memtag_section (struct gdbarch
*gdbarch
, asection
*osec
)
2721 /* We only handle MTE tags for now. */
2723 size_t segment_size
= osec
->rawsize
;
2724 CORE_ADDR start_address
= bfd_section_vma (osec
);
2725 CORE_ADDR end_address
= start_address
+ segment_size
;
2727 /* Figure out how many tags we need to store in this memory range. */
2728 size_t granules
= aarch64_mte_get_tag_granules (start_address
, segment_size
,
2729 AARCH64_MTE_GRANULE_SIZE
);
2731 /* If there are no tag granules to fetch, just return. */
2735 CORE_ADDR address
= start_address
;
2737 /* Vector of tags. */
2738 gdb::byte_vector tags
;
2740 while (granules
> 0)
2742 /* Transfer tags in chunks. */
2743 gdb::byte_vector tags_read
;
2745 = ((granules
>= MAX_TAGS_TO_TRANSFER
)
2746 ? MAX_TAGS_TO_TRANSFER
* AARCH64_MTE_GRANULE_SIZE
2747 : granules
* AARCH64_MTE_GRANULE_SIZE
);
2749 if (!target_fetch_memtags (address
, xfer_len
, tags_read
,
2750 static_cast<int> (memtag_type::allocation
)))
2752 warning (_("Failed to read MTE tags from memory range [%s,%s)."),
2753 phex_nz (start_address
, sizeof (start_address
)),
2754 phex_nz (end_address
, sizeof (end_address
)));
2758 /* Transfer over the tags that have been read. */
2759 tags
.insert (tags
.end (), tags_read
.begin (), tags_read
.end ());
2761 /* Adjust the remaining granules and starting address. */
2762 granules
-= tags_read
.size ();
2763 address
+= tags_read
.size () * AARCH64_MTE_GRANULE_SIZE
;
2766 /* Pack the MTE tag bits. */
2767 aarch64_mte_pack_tags (tags
);
2769 if (!bfd_set_section_contents (osec
->owner
, osec
, tags
.data (),
2772 warning (_("Failed to write %s bytes of corefile memory "
2773 "tag content (%s)."),
2774 pulongest (tags
.size ()),
2775 bfd_errmsg (bfd_get_error ()));
2780 /* AArch64 Linux implementation of the gdbarch_decode_memtag_section
2781 hook. Decode a memory tag section and return the requested tags.
2783 The section is guaranteed to cover the [ADDRESS, ADDRESS + length)
2786 static gdb::byte_vector
2787 aarch64_linux_decode_memtag_section (struct gdbarch
*gdbarch
,
2788 bfd_section
*section
,
2790 CORE_ADDR address
, size_t length
)
2792 gdb_assert (section
!= nullptr);
2794 /* The requested address must not be less than section->vma. */
2795 gdb_assert (section
->vma
<= address
);
2797 /* Figure out how many tags we need to fetch in this memory range. */
2798 size_t granules
= aarch64_mte_get_tag_granules (address
, length
,
2799 AARCH64_MTE_GRANULE_SIZE
);
2801 gdb_assert (granules
> 0);
2803 /* Fetch the total number of tags in the range [VMA, address + length). */
2804 size_t granules_from_vma
2805 = aarch64_mte_get_tag_granules (section
->vma
,
2806 address
- section
->vma
+ length
,
2807 AARCH64_MTE_GRANULE_SIZE
);
2809 /* Adjust the tags vector to contain the exact number of packed bytes. */
2810 gdb::byte_vector
tags (((granules
- 1) >> 1) + 1);
2812 /* Figure out the starting offset into the packed tags data. */
2813 file_ptr offset
= ((granules_from_vma
- granules
) >> 1);
2815 if (!bfd_get_section_contents (section
->owner
, section
, tags
.data (),
2816 offset
, tags
.size ()))
2817 error (_("Couldn't read contents from memtag section."));
2819 /* At this point, the tags are packed 2 per byte. Unpack them before
2821 bool skip_first
= ((granules_from_vma
- granules
) % 2) != 0;
2822 aarch64_mte_unpack_tags (tags
, skip_first
);
2824 /* Resize to the exact number of tags that was requested. */
2825 tags
.resize (granules
);
2830 /* AArch64 Linux implementation of the
2831 gdbarch_use_target_description_from_corefile_notes hook. */
2834 aarch64_use_target_description_from_corefile_notes (gdbarch
*gdbarch
,
2838 gdb_assert (obfd
!= nullptr);
2840 /* If the corefile contains any SVE or SME register data, we don't want to
2841 use the target description note, as it may be incorrect.
2843 Currently the target description note contains a potentially incorrect
2844 target description if the originating program changed the SVE or SME
2845 vector lengths mid-execution.
2847 Once we support per-thread target description notes in the corefiles, we
2848 can always trust those notes whenever they are available. */
2849 if (bfd_get_section_by_name (obfd
, ".reg-aarch-sve") != nullptr
2850 || bfd_get_section_by_name (obfd
, ".reg-aarch-za") != nullptr
2851 || bfd_get_section_by_name (obfd
, ".reg-aarch-zt") != nullptr)
2858 aarch64_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
2860 static const char *const stap_integer_prefixes
[] = { "#", "", NULL
};
2861 static const char *const stap_register_prefixes
[] = { "", NULL
};
2862 static const char *const stap_register_indirection_prefixes
[] = { "[",
2864 static const char *const stap_register_indirection_suffixes
[] = { "]",
2866 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2868 tdep
->lowest_pc
= 0x8000;
2870 linux_init_abi (info
, gdbarch
, 1);
2872 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
2873 linux_lp64_fetch_link_map_offsets
);
2875 /* Enable TLS support. */
2876 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
2877 svr4_fetch_objfile_link_map
);
2879 /* Shared library handling. */
2880 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
2881 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
2883 tramp_frame_prepend_unwinder (gdbarch
, &aarch64_linux_rt_sigframe
);
2885 /* Enable longjmp. */
2888 set_gdbarch_iterate_over_regset_sections
2889 (gdbarch
, aarch64_linux_iterate_over_regset_sections
);
2890 set_gdbarch_core_read_description
2891 (gdbarch
, aarch64_linux_core_read_description
);
2893 /* SystemTap related. */
2894 set_gdbarch_stap_integer_prefixes (gdbarch
, stap_integer_prefixes
);
2895 set_gdbarch_stap_register_prefixes (gdbarch
, stap_register_prefixes
);
2896 set_gdbarch_stap_register_indirection_prefixes (gdbarch
,
2897 stap_register_indirection_prefixes
);
2898 set_gdbarch_stap_register_indirection_suffixes (gdbarch
,
2899 stap_register_indirection_suffixes
);
2900 set_gdbarch_stap_is_single_operand (gdbarch
, aarch64_stap_is_single_operand
);
2901 set_gdbarch_stap_parse_special_token (gdbarch
,
2902 aarch64_stap_parse_special_token
);
2904 /* Reversible debugging, process record. */
2905 set_gdbarch_process_record (gdbarch
, aarch64_process_record
);
2906 /* Syscall record. */
2907 tdep
->aarch64_syscall_record
= aarch64_linux_syscall_record
;
2909 /* MTE-specific settings and hooks. */
2910 if (tdep
->has_mte ())
2912 /* Register a hook for checking if an address is tagged or not. */
2913 set_gdbarch_tagged_address_p (gdbarch
, aarch64_linux_tagged_address_p
);
2915 /* Register a hook for checking if there is a memory tag match. */
2916 set_gdbarch_memtag_matches_p (gdbarch
,
2917 aarch64_linux_memtag_matches_p
);
2919 /* Register a hook for setting the logical/allocation tags for
2920 a range of addresses. */
2921 set_gdbarch_set_memtags (gdbarch
, aarch64_linux_set_memtags
);
2923 /* Register a hook for extracting the logical/allocation tag from an
2925 set_gdbarch_get_memtag (gdbarch
, aarch64_linux_get_memtag
);
2927 /* Set the allocation tag granule size to 16 bytes. */
2928 set_gdbarch_memtag_granule_size (gdbarch
, AARCH64_MTE_GRANULE_SIZE
);
2930 /* Register a hook for converting a memory tag to a string. */
2931 set_gdbarch_memtag_to_string (gdbarch
, aarch64_linux_memtag_to_string
);
2933 set_gdbarch_report_signal_info (gdbarch
,
2934 aarch64_linux_report_signal_info
);
2936 /* Core file helpers. */
2938 /* Core file helper to create a memory tag section for a particular
2940 set_gdbarch_create_memtag_section
2941 (gdbarch
, aarch64_linux_create_memtag_section
);
2943 /* Core file helper to fill a memory tag section with tag data. */
2944 set_gdbarch_fill_memtag_section
2945 (gdbarch
, aarch64_linux_fill_memtag_section
);
2947 /* Core file helper to decode a memory tag section. */
2948 set_gdbarch_decode_memtag_section (gdbarch
,
2949 aarch64_linux_decode_memtag_section
);
2952 /* Initialize the aarch64_linux_record_tdep. */
2953 /* These values are the size of the type that will be used in a system
2954 call. They are obtained from Linux Kernel source. */
2955 aarch64_linux_record_tdep
.size_pointer
2956 = gdbarch_ptr_bit (gdbarch
) / TARGET_CHAR_BIT
;
2957 aarch64_linux_record_tdep
.size__old_kernel_stat
= 32;
2958 aarch64_linux_record_tdep
.size_tms
= 32;
2959 aarch64_linux_record_tdep
.size_loff_t
= 8;
2960 aarch64_linux_record_tdep
.size_flock
= 32;
2961 aarch64_linux_record_tdep
.size_oldold_utsname
= 45;
2962 aarch64_linux_record_tdep
.size_ustat
= 32;
2963 aarch64_linux_record_tdep
.size_old_sigaction
= 32;
2964 aarch64_linux_record_tdep
.size_old_sigset_t
= 8;
2965 aarch64_linux_record_tdep
.size_rlimit
= 16;
2966 aarch64_linux_record_tdep
.size_rusage
= 144;
2967 aarch64_linux_record_tdep
.size_timeval
= 16;
2968 aarch64_linux_record_tdep
.size_timezone
= 8;
2969 aarch64_linux_record_tdep
.size_old_gid_t
= 2;
2970 aarch64_linux_record_tdep
.size_old_uid_t
= 2;
2971 aarch64_linux_record_tdep
.size_fd_set
= 128;
2972 aarch64_linux_record_tdep
.size_old_dirent
= 280;
2973 aarch64_linux_record_tdep
.size_statfs
= 120;
2974 aarch64_linux_record_tdep
.size_statfs64
= 120;
2975 aarch64_linux_record_tdep
.size_sockaddr
= 16;
2976 aarch64_linux_record_tdep
.size_int
2977 = gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
;
2978 aarch64_linux_record_tdep
.size_long
2979 = gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
2980 aarch64_linux_record_tdep
.size_ulong
2981 = gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
;
2982 aarch64_linux_record_tdep
.size_msghdr
= 56;
2983 aarch64_linux_record_tdep
.size_itimerval
= 32;
2984 aarch64_linux_record_tdep
.size_stat
= 144;
2985 aarch64_linux_record_tdep
.size_old_utsname
= 325;
2986 aarch64_linux_record_tdep
.size_sysinfo
= 112;
2987 aarch64_linux_record_tdep
.size_msqid_ds
= 120;
2988 aarch64_linux_record_tdep
.size_shmid_ds
= 112;
2989 aarch64_linux_record_tdep
.size_new_utsname
= 390;
2990 aarch64_linux_record_tdep
.size_timex
= 208;
2991 aarch64_linux_record_tdep
.size_mem_dqinfo
= 24;
2992 aarch64_linux_record_tdep
.size_if_dqblk
= 72;
2993 aarch64_linux_record_tdep
.size_fs_quota_stat
= 80;
2994 aarch64_linux_record_tdep
.size_timespec
= 16;
2995 aarch64_linux_record_tdep
.size_pollfd
= 8;
2996 aarch64_linux_record_tdep
.size_NFS_FHSIZE
= 32;
2997 aarch64_linux_record_tdep
.size_knfsd_fh
= 132;
2998 aarch64_linux_record_tdep
.size_TASK_COMM_LEN
= 16;
2999 aarch64_linux_record_tdep
.size_sigaction
= 32;
3000 aarch64_linux_record_tdep
.size_sigset_t
= 8;
3001 aarch64_linux_record_tdep
.size_siginfo_t
= 128;
3002 aarch64_linux_record_tdep
.size_cap_user_data_t
= 8;
3003 aarch64_linux_record_tdep
.size_stack_t
= 24;
3004 aarch64_linux_record_tdep
.size_off_t
= 8;
3005 aarch64_linux_record_tdep
.size_stat64
= 144;
3006 aarch64_linux_record_tdep
.size_gid_t
= 4;
3007 aarch64_linux_record_tdep
.size_uid_t
= 4;
3008 aarch64_linux_record_tdep
.size_PAGE_SIZE
= 4096;
3009 aarch64_linux_record_tdep
.size_flock64
= 32;
3010 aarch64_linux_record_tdep
.size_user_desc
= 16;
3011 aarch64_linux_record_tdep
.size_io_event
= 32;
3012 aarch64_linux_record_tdep
.size_iocb
= 64;
3013 aarch64_linux_record_tdep
.size_epoll_event
= 12;
3014 aarch64_linux_record_tdep
.size_itimerspec
= 32;
3015 aarch64_linux_record_tdep
.size_mq_attr
= 64;
3016 aarch64_linux_record_tdep
.size_termios
= 36;
3017 aarch64_linux_record_tdep
.size_termios2
= 44;
3018 aarch64_linux_record_tdep
.size_pid_t
= 4;
3019 aarch64_linux_record_tdep
.size_winsize
= 8;
3020 aarch64_linux_record_tdep
.size_serial_struct
= 72;
3021 aarch64_linux_record_tdep
.size_serial_icounter_struct
= 80;
3022 aarch64_linux_record_tdep
.size_hayes_esp_config
= 12;
3023 aarch64_linux_record_tdep
.size_size_t
= 8;
3024 aarch64_linux_record_tdep
.size_iovec
= 16;
3025 aarch64_linux_record_tdep
.size_time_t
= 8;
3027 /* These values are the second argument of system call "sys_ioctl".
3028 They are obtained from Linux Kernel source. */
3029 aarch64_linux_record_tdep
.ioctl_TCGETS
= 0x5401;
3030 aarch64_linux_record_tdep
.ioctl_TCSETS
= 0x5402;
3031 aarch64_linux_record_tdep
.ioctl_TCSETSW
= 0x5403;
3032 aarch64_linux_record_tdep
.ioctl_TCSETSF
= 0x5404;
3033 aarch64_linux_record_tdep
.ioctl_TCGETA
= 0x5405;
3034 aarch64_linux_record_tdep
.ioctl_TCSETA
= 0x5406;
3035 aarch64_linux_record_tdep
.ioctl_TCSETAW
= 0x5407;
3036 aarch64_linux_record_tdep
.ioctl_TCSETAF
= 0x5408;
3037 aarch64_linux_record_tdep
.ioctl_TCSBRK
= 0x5409;
3038 aarch64_linux_record_tdep
.ioctl_TCXONC
= 0x540a;
3039 aarch64_linux_record_tdep
.ioctl_TCFLSH
= 0x540b;
3040 aarch64_linux_record_tdep
.ioctl_TIOCEXCL
= 0x540c;
3041 aarch64_linux_record_tdep
.ioctl_TIOCNXCL
= 0x540d;
3042 aarch64_linux_record_tdep
.ioctl_TIOCSCTTY
= 0x540e;
3043 aarch64_linux_record_tdep
.ioctl_TIOCGPGRP
= 0x540f;
3044 aarch64_linux_record_tdep
.ioctl_TIOCSPGRP
= 0x5410;
3045 aarch64_linux_record_tdep
.ioctl_TIOCOUTQ
= 0x5411;
3046 aarch64_linux_record_tdep
.ioctl_TIOCSTI
= 0x5412;
3047 aarch64_linux_record_tdep
.ioctl_TIOCGWINSZ
= 0x5413;
3048 aarch64_linux_record_tdep
.ioctl_TIOCSWINSZ
= 0x5414;
3049 aarch64_linux_record_tdep
.ioctl_TIOCMGET
= 0x5415;
3050 aarch64_linux_record_tdep
.ioctl_TIOCMBIS
= 0x5416;
3051 aarch64_linux_record_tdep
.ioctl_TIOCMBIC
= 0x5417;
3052 aarch64_linux_record_tdep
.ioctl_TIOCMSET
= 0x5418;
3053 aarch64_linux_record_tdep
.ioctl_TIOCGSOFTCAR
= 0x5419;
3054 aarch64_linux_record_tdep
.ioctl_TIOCSSOFTCAR
= 0x541a;
3055 aarch64_linux_record_tdep
.ioctl_FIONREAD
= 0x541b;
3056 aarch64_linux_record_tdep
.ioctl_TIOCINQ
= 0x541b;
3057 aarch64_linux_record_tdep
.ioctl_TIOCLINUX
= 0x541c;
3058 aarch64_linux_record_tdep
.ioctl_TIOCCONS
= 0x541d;
3059 aarch64_linux_record_tdep
.ioctl_TIOCGSERIAL
= 0x541e;
3060 aarch64_linux_record_tdep
.ioctl_TIOCSSERIAL
= 0x541f;
3061 aarch64_linux_record_tdep
.ioctl_TIOCPKT
= 0x5420;
3062 aarch64_linux_record_tdep
.ioctl_FIONBIO
= 0x5421;
3063 aarch64_linux_record_tdep
.ioctl_TIOCNOTTY
= 0x5422;
3064 aarch64_linux_record_tdep
.ioctl_TIOCSETD
= 0x5423;
3065 aarch64_linux_record_tdep
.ioctl_TIOCGETD
= 0x5424;
3066 aarch64_linux_record_tdep
.ioctl_TCSBRKP
= 0x5425;
3067 aarch64_linux_record_tdep
.ioctl_TIOCTTYGSTRUCT
= 0x5426;
3068 aarch64_linux_record_tdep
.ioctl_TIOCSBRK
= 0x5427;
3069 aarch64_linux_record_tdep
.ioctl_TIOCCBRK
= 0x5428;
3070 aarch64_linux_record_tdep
.ioctl_TIOCGSID
= 0x5429;
3071 aarch64_linux_record_tdep
.ioctl_TCGETS2
= 0x802c542a;
3072 aarch64_linux_record_tdep
.ioctl_TCSETS2
= 0x402c542b;
3073 aarch64_linux_record_tdep
.ioctl_TCSETSW2
= 0x402c542c;
3074 aarch64_linux_record_tdep
.ioctl_TCSETSF2
= 0x402c542d;
3075 aarch64_linux_record_tdep
.ioctl_TIOCGPTN
= 0x80045430;
3076 aarch64_linux_record_tdep
.ioctl_TIOCSPTLCK
= 0x40045431;
3077 aarch64_linux_record_tdep
.ioctl_FIONCLEX
= 0x5450;
3078 aarch64_linux_record_tdep
.ioctl_FIOCLEX
= 0x5451;
3079 aarch64_linux_record_tdep
.ioctl_FIOASYNC
= 0x5452;
3080 aarch64_linux_record_tdep
.ioctl_TIOCSERCONFIG
= 0x5453;
3081 aarch64_linux_record_tdep
.ioctl_TIOCSERGWILD
= 0x5454;
3082 aarch64_linux_record_tdep
.ioctl_TIOCSERSWILD
= 0x5455;
3083 aarch64_linux_record_tdep
.ioctl_TIOCGLCKTRMIOS
= 0x5456;
3084 aarch64_linux_record_tdep
.ioctl_TIOCSLCKTRMIOS
= 0x5457;
3085 aarch64_linux_record_tdep
.ioctl_TIOCSERGSTRUCT
= 0x5458;
3086 aarch64_linux_record_tdep
.ioctl_TIOCSERGETLSR
= 0x5459;
3087 aarch64_linux_record_tdep
.ioctl_TIOCSERGETMULTI
= 0x545a;
3088 aarch64_linux_record_tdep
.ioctl_TIOCSERSETMULTI
= 0x545b;
3089 aarch64_linux_record_tdep
.ioctl_TIOCMIWAIT
= 0x545c;
3090 aarch64_linux_record_tdep
.ioctl_TIOCGICOUNT
= 0x545d;
3091 aarch64_linux_record_tdep
.ioctl_TIOCGHAYESESP
= 0x545e;
3092 aarch64_linux_record_tdep
.ioctl_TIOCSHAYESESP
= 0x545f;
3093 aarch64_linux_record_tdep
.ioctl_FIOQSIZE
= 0x5460;
3095 /* These values are the second argument of system call "sys_fcntl"
3096 and "sys_fcntl64". They are obtained from Linux Kernel source. */
3097 aarch64_linux_record_tdep
.fcntl_F_GETLK
= 5;
3098 aarch64_linux_record_tdep
.fcntl_F_GETLK64
= 12;
3099 aarch64_linux_record_tdep
.fcntl_F_SETLK64
= 13;
3100 aarch64_linux_record_tdep
.fcntl_F_SETLKW64
= 14;
3102 /* The AArch64 syscall calling convention: reg x0-x6 for arguments,
3103 reg x8 for syscall number and return value in reg x0. */
3104 aarch64_linux_record_tdep
.arg1
= AARCH64_X0_REGNUM
+ 0;
3105 aarch64_linux_record_tdep
.arg2
= AARCH64_X0_REGNUM
+ 1;
3106 aarch64_linux_record_tdep
.arg3
= AARCH64_X0_REGNUM
+ 2;
3107 aarch64_linux_record_tdep
.arg4
= AARCH64_X0_REGNUM
+ 3;
3108 aarch64_linux_record_tdep
.arg5
= AARCH64_X0_REGNUM
+ 4;
3109 aarch64_linux_record_tdep
.arg6
= AARCH64_X0_REGNUM
+ 5;
3110 aarch64_linux_record_tdep
.arg7
= AARCH64_X0_REGNUM
+ 6;
3112 /* `catch syscall' */
3113 set_xml_syscall_file_name (gdbarch
, "syscalls/aarch64-linux.xml");
3114 set_gdbarch_get_syscall_number (gdbarch
, aarch64_linux_get_syscall_number
);
3116 /* Displaced stepping. */
3117 set_gdbarch_max_insn_length (gdbarch
, 4);
3118 set_gdbarch_displaced_step_buffer_length
3119 (gdbarch
, 4 * AARCH64_DISPLACED_MODIFIED_INSNS
);
3120 set_gdbarch_displaced_step_copy_insn (gdbarch
,
3121 aarch64_displaced_step_copy_insn
);
3122 set_gdbarch_displaced_step_fixup (gdbarch
, aarch64_displaced_step_fixup
);
3123 set_gdbarch_displaced_step_hw_singlestep (gdbarch
,
3124 aarch64_displaced_step_hw_singlestep
);
3126 set_gdbarch_gcc_target_options (gdbarch
, aarch64_linux_gcc_target_options
);
3128 /* Hook to decide if the target description should be obtained from
3129 corefile target description note(s) or inferred from the corefile
3131 set_gdbarch_use_target_description_from_corefile_notes (gdbarch
,
3132 aarch64_use_target_description_from_corefile_notes
);
3137 namespace selftests
{
3139 /* Verify functions to read and write logical tags. */
3142 aarch64_linux_ltag_tests (void)
3144 /* We have 4 bits of tags, but we test writing all the bits of the top
3146 for (int i
= 0; i
< 1 << 8; i
++)
3148 CORE_ADDR addr
= ((CORE_ADDR
) i
<< 56) | 0xdeadbeef;
3149 SELF_CHECK (aarch64_mte_get_ltag (addr
) == (i
& 0xf));
3151 addr
= aarch64_mte_set_ltag (0xdeadbeef, i
);
3152 SELF_CHECK (addr
= ((CORE_ADDR
) (i
& 0xf) << 56) | 0xdeadbeef);
3156 } // namespace selftests
3157 #endif /* GDB_SELF_TEST */
3159 void _initialize_aarch64_linux_tdep ();
3161 _initialize_aarch64_linux_tdep ()
3163 gdbarch_register_osabi (bfd_arch_aarch64
, 0, GDB_OSABI_LINUX
,
3164 aarch64_linux_init_abi
);
3167 selftests::register_test ("aarch64-linux-tagged-address",
3168 selftests::aarch64_linux_ltag_tests
);