1 /* Common target dependent code for GDB on AArch64 systems.
3 Copyright (C) 2009-2025 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/>. */
22 #include "extract-store-integer.h"
25 #include "cli/cli-cmds.h"
29 #include "reggroups.h"
31 #include "arch-utils.h"
33 #include "frame-unwind.h"
34 #include "frame-base.h"
35 #include "trad-frame.h"
38 #include "dwarf2/frame.h"
40 #include "prologue-value.h"
41 #include "target-descriptions.h"
42 #include "user-regs.h"
44 #include "gdbsupport/selftest.h"
46 #include "aarch64-tdep.h"
47 #include "aarch64-ravenscar-thread.h"
48 #include "arch/aarch64-mte.h"
51 #include "record-full.h"
52 #include "arch/aarch64-insn.h"
55 #include "opcode/aarch64.h"
57 #include <unordered_map>
59 /* For inferior_ptid and current_inferior (). */
61 /* For std::sqrt and std::pow. */
64 /* A Homogeneous Floating-Point or Short-Vector Aggregate may have at most
66 #define HA_MAX_NUM_FLDS 4
68 /* All possible aarch64 target descriptors. */
69 static std::unordered_map
<aarch64_features
, target_desc
*> tdesc_aarch64_map
;
71 /* The standard register names, and all the valid aliases for them.
72 We're not adding fp here, that name is already taken, see
73 _initialize_frame_reg. */
76 const char *const name
;
78 } aarch64_register_aliases
[] =
80 /* Link register alias for x30. */
81 {"lr", AARCH64_LR_REGNUM
},
82 /* SP is the canonical name for x31 according to aarch64_r_register_names,
83 so we're adding an x31 alias for sp. */
84 {"x31", AARCH64_SP_REGNUM
},
86 {"ip0", AARCH64_X0_REGNUM
+ 16},
87 {"ip1", AARCH64_X0_REGNUM
+ 17}
90 /* The required core 'R' registers. */
91 static const char *const aarch64_r_register_names
[] =
93 /* These registers must appear in consecutive RAW register number
94 order and they must begin with AARCH64_X0_REGNUM! */
95 "x0", "x1", "x2", "x3",
96 "x4", "x5", "x6", "x7",
97 "x8", "x9", "x10", "x11",
98 "x12", "x13", "x14", "x15",
99 "x16", "x17", "x18", "x19",
100 "x20", "x21", "x22", "x23",
101 "x24", "x25", "x26", "x27",
102 "x28", "x29", "x30", "sp",
106 /* The FP/SIMD 'V' registers. */
107 static const char *const aarch64_v_register_names
[] =
109 /* These registers must appear in consecutive RAW register number
110 order and they must begin with AARCH64_V0_REGNUM! */
111 "v0", "v1", "v2", "v3",
112 "v4", "v5", "v6", "v7",
113 "v8", "v9", "v10", "v11",
114 "v12", "v13", "v14", "v15",
115 "v16", "v17", "v18", "v19",
116 "v20", "v21", "v22", "v23",
117 "v24", "v25", "v26", "v27",
118 "v28", "v29", "v30", "v31",
123 /* The SVE 'Z' and 'P' registers. */
124 static const char *const aarch64_sve_register_names
[] =
126 /* These registers must appear in consecutive RAW register number
127 order and they must begin with AARCH64_SVE_Z0_REGNUM! */
128 "z0", "z1", "z2", "z3",
129 "z4", "z5", "z6", "z7",
130 "z8", "z9", "z10", "z11",
131 "z12", "z13", "z14", "z15",
132 "z16", "z17", "z18", "z19",
133 "z20", "z21", "z22", "z23",
134 "z24", "z25", "z26", "z27",
135 "z28", "z29", "z30", "z31",
137 "p0", "p1", "p2", "p3",
138 "p4", "p5", "p6", "p7",
139 "p8", "p9", "p10", "p11",
140 "p12", "p13", "p14", "p15",
144 static const char *const aarch64_pauth_register_names
[] =
146 /* Authentication mask for data pointer, low half/user pointers. */
148 /* Authentication mask for code pointer, low half/user pointers. */
150 /* Authentication mask for data pointer, high half / kernel pointers. */
152 /* Authentication mask for code pointer, high half / kernel pointers. */
156 static const char *const aarch64_mte_register_names
[] =
158 /* Tag Control Register. */
162 static int aarch64_stack_frame_destroyed_p (struct gdbarch
*, CORE_ADDR
);
164 /* AArch64 prologue cache structure. */
165 struct aarch64_prologue_cache
167 /* The program counter at the start of the function. It is used to
168 identify this frame as a prologue frame. */
171 /* The program counter at the time this frame was created; i.e. where
172 this function was called from. It is used to identify this frame as a
176 /* The stack pointer at the time this frame was created; i.e. the
177 caller's stack pointer when this function was called. It is used
178 to identify this frame. */
181 /* Is the target available to read from? */
184 /* The frame base for this frame is just prev_sp - frame size.
185 FRAMESIZE is the distance from the frame pointer to the
186 initial stack pointer. */
189 /* The register used to hold the frame pointer for this frame. */
192 /* Saved register offsets. */
193 trad_frame_saved_reg
*saved_regs
;
196 /* Holds information used to read/write from/to ZA
199 With this information, the read/write code can be simplified so it
200 deals only with the required information to map a ZA pseudo-register
201 to the exact bytes into the ZA contents buffer. Otherwise we'd need
202 to use a lot of conditionals. */
206 /* Offset, into ZA, of the starting byte of the pseudo-register. */
207 size_t starting_offset
;
208 /* The size of the contiguous chunks of the pseudo-register. */
210 /* The number of pseudo-register chunks contained in ZA. */
212 /* The offset between each contiguous chunk. */
216 /* Holds data that is helpful to determine the individual fields that make
217 up the names of the ZA pseudo-registers. It is also very helpful to
218 determine offsets, stride and sizes for reading ZA tiles and tile
221 struct za_pseudo_encoding
223 /* The slice index (0 ~ svl). Only used for tile slices. */
225 /* The tile number (0 ~ 15). */
227 /* Direction (horizontal/vertical). Only used for tile slices. */
229 /* Qualifier index (0 ~ 4). These map to B, H, S, D and Q. */
230 uint8_t qualifier_index
;
234 show_aarch64_debug (struct ui_file
*file
, int from_tty
,
235 struct cmd_list_element
*c
, const char *value
)
237 gdb_printf (file
, _("AArch64 debugging is %s.\n"), value
);
242 /* Abstract instruction reader. */
244 class abstract_instruction_reader
247 /* Read in one instruction. */
248 virtual ULONGEST
read (CORE_ADDR memaddr
, int len
,
249 enum bfd_endian byte_order
) = 0;
252 /* Instruction reader from real target. */
254 class instruction_reader
: public abstract_instruction_reader
257 ULONGEST
read (CORE_ADDR memaddr
, int len
, enum bfd_endian byte_order
)
260 return read_code_unsigned_integer (memaddr
, len
, byte_order
);
266 /* If address signing is enabled, mask off the signature bits from the link
267 register, which is passed by value in ADDR, using the register values in
271 aarch64_frame_unmask_lr (aarch64_gdbarch_tdep
*tdep
,
272 const frame_info_ptr
&this_frame
, CORE_ADDR addr
)
274 if (tdep
->has_pauth ()
275 && frame_unwind_register_unsigned (this_frame
,
276 tdep
->ra_sign_state_regnum
))
278 /* VA range select (bit 55) tells us whether to use the low half masks
279 or the high half masks. */
281 if (tdep
->pauth_reg_count
> 2 && addr
& VA_RANGE_SELECT_BIT_MASK
)
282 cmask_num
= AARCH64_PAUTH_CMASK_HIGH_REGNUM (tdep
->pauth_reg_base
);
284 cmask_num
= AARCH64_PAUTH_CMASK_REGNUM (tdep
->pauth_reg_base
);
286 /* By default, we assume TBI and discard the top 8 bits plus the VA range
288 CORE_ADDR mask
= AARCH64_TOP_BITS_MASK
;
289 mask
|= frame_unwind_register_unsigned (this_frame
, cmask_num
);
290 addr
= aarch64_remove_top_bits (addr
, mask
);
292 /* Record in the frame that the link register required unmasking. */
293 set_frame_previous_pc_masked (this_frame
);
299 /* Implement the "get_pc_address_flags" gdbarch method. */
302 aarch64_get_pc_address_flags (const frame_info_ptr
&frame
, CORE_ADDR pc
)
304 if (pc
!= 0 && get_frame_pc_masked (frame
))
310 /* Analyze a prologue, looking for a recognizable stack frame
311 and frame pointer. Scan until we encounter a store that could
312 clobber the stack frame unexpectedly, or an unknown instruction. */
315 aarch64_analyze_prologue (struct gdbarch
*gdbarch
,
316 CORE_ADDR start
, CORE_ADDR limit
,
317 struct aarch64_prologue_cache
*cache
,
318 abstract_instruction_reader
& reader
)
320 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
323 /* Whether the stack has been set. This should be true when we notice a SP
324 to FP move or if we are using the SP as the base register for storing
325 data, in case the FP is omitted. */
326 bool seen_stack_set
= false;
328 /* Track X registers and D registers in prologue. */
329 pv_t regs
[AARCH64_X_REGISTER_COUNT
+ AARCH64_D_REGISTER_COUNT
];
331 for (i
= 0; i
< AARCH64_X_REGISTER_COUNT
+ AARCH64_D_REGISTER_COUNT
; i
++)
332 regs
[i
] = pv_register (i
, 0);
333 pv_area
stack (AARCH64_SP_REGNUM
, gdbarch_addr_bit (gdbarch
));
335 for (; start
< limit
; start
+= 4)
340 insn
= reader
.read (start
, 4, byte_order_for_code
);
342 if (aarch64_decode_insn (insn
, &inst
, 1, NULL
) != 0)
345 if (inst
.opcode
->iclass
== addsub_imm
346 && (inst
.opcode
->op
== OP_ADD
347 || strcmp ("sub", inst
.opcode
->name
) == 0))
349 unsigned rd
= inst
.operands
[0].reg
.regno
;
350 unsigned rn
= inst
.operands
[1].reg
.regno
;
352 gdb_assert (aarch64_num_of_operands (inst
.opcode
) == 3);
353 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rd_SP
);
354 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_Rn_SP
);
355 gdb_assert (inst
.operands
[2].type
== AARCH64_OPND_AIMM
);
357 if (inst
.opcode
->op
== OP_ADD
)
359 regs
[rd
] = pv_add_constant (regs
[rn
],
360 inst
.operands
[2].imm
.value
);
364 regs
[rd
] = pv_add_constant (regs
[rn
],
365 -inst
.operands
[2].imm
.value
);
368 /* Did we move SP to FP? */
369 if (rn
== AARCH64_SP_REGNUM
&& rd
== AARCH64_FP_REGNUM
)
370 seen_stack_set
= true;
372 else if (inst
.opcode
->iclass
== addsub_ext
373 && strcmp ("sub", inst
.opcode
->name
) == 0)
375 unsigned rd
= inst
.operands
[0].reg
.regno
;
376 unsigned rn
= inst
.operands
[1].reg
.regno
;
377 unsigned rm
= inst
.operands
[2].reg
.regno
;
379 gdb_assert (aarch64_num_of_operands (inst
.opcode
) == 3);
380 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rd_SP
);
381 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_Rn_SP
);
382 gdb_assert (inst
.operands
[2].type
== AARCH64_OPND_Rm_EXT
);
384 regs
[rd
] = pv_subtract (regs
[rn
], regs
[rm
]);
386 else if (inst
.opcode
->iclass
== branch_imm
)
388 /* Stop analysis on branch. */
391 else if (inst
.opcode
->iclass
== condbranch
)
393 /* Stop analysis on branch. */
396 else if (inst
.opcode
->iclass
== branch_reg
)
398 /* Stop analysis on branch. */
401 else if (inst
.opcode
->iclass
== compbranch
)
403 /* Stop analysis on branch. */
406 else if (inst
.opcode
->op
== OP_MOVZ
)
408 unsigned rd
= inst
.operands
[0].reg
.regno
;
410 gdb_assert (aarch64_num_of_operands (inst
.opcode
) == 2);
411 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rd
);
412 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_HALF
);
413 gdb_assert (inst
.operands
[1].shifter
.kind
== AARCH64_MOD_LSL
);
415 /* If this shows up before we set the stack, keep going. Otherwise
416 stop the analysis. */
420 regs
[rd
] = pv_constant (inst
.operands
[1].imm
.value
421 << inst
.operands
[1].shifter
.amount
);
423 else if (inst
.opcode
->iclass
== log_shift
424 && strcmp (inst
.opcode
->name
, "orr") == 0)
426 unsigned rd
= inst
.operands
[0].reg
.regno
;
427 unsigned rn
= inst
.operands
[1].reg
.regno
;
428 unsigned rm
= inst
.operands
[2].reg
.regno
;
430 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rd
);
431 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_Rn
);
432 gdb_assert (inst
.operands
[2].type
== AARCH64_OPND_Rm_SFT
);
434 if (inst
.operands
[2].shifter
.amount
== 0
435 && rn
== AARCH64_SP_REGNUM
)
439 aarch64_debug_printf ("prologue analysis gave up "
440 "addr=%s opcode=0x%x (orr x register)",
441 core_addr_to_string_nz (start
), insn
);
446 else if (inst
.opcode
->op
== OP_STUR
)
448 unsigned rt
= inst
.operands
[0].reg
.regno
;
449 unsigned rn
= inst
.operands
[1].addr
.base_regno
;
450 int size
= aarch64_get_qualifier_esize (inst
.operands
[0].qualifier
);
452 gdb_assert (aarch64_num_of_operands (inst
.opcode
) == 2);
453 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rt
);
454 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_ADDR_SIMM9
);
455 gdb_assert (!inst
.operands
[1].addr
.offset
.is_reg
);
458 (pv_add_constant (regs
[rn
], inst
.operands
[1].addr
.offset
.imm
),
461 /* Are we storing with SP as a base? */
462 if (rn
== AARCH64_SP_REGNUM
)
463 seen_stack_set
= true;
465 else if ((inst
.opcode
->iclass
== ldstpair_off
466 || (inst
.opcode
->iclass
== ldstpair_indexed
467 && inst
.operands
[2].addr
.preind
))
468 && strcmp ("stp", inst
.opcode
->name
) == 0)
470 /* STP with addressing mode Pre-indexed and Base register. */
473 unsigned rn
= inst
.operands
[2].addr
.base_regno
;
474 int32_t imm
= inst
.operands
[2].addr
.offset
.imm
;
475 int size
= aarch64_get_qualifier_esize (inst
.operands
[0].qualifier
);
477 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rt
478 || inst
.operands
[0].type
== AARCH64_OPND_Ft
);
479 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_Rt2
480 || inst
.operands
[1].type
== AARCH64_OPND_Ft2
);
481 gdb_assert (inst
.operands
[2].type
== AARCH64_OPND_ADDR_SIMM7
);
482 gdb_assert (!inst
.operands
[2].addr
.offset
.is_reg
);
484 /* If recording this store would invalidate the store area
485 (perhaps because rn is not known) then we should abandon
486 further prologue analysis. */
487 if (stack
.store_would_trash (pv_add_constant (regs
[rn
], imm
)))
490 if (stack
.store_would_trash (pv_add_constant (regs
[rn
], imm
+ 8)))
493 rt1
= inst
.operands
[0].reg
.regno
;
494 rt2
= inst
.operands
[1].reg
.regno
;
495 if (inst
.operands
[0].type
== AARCH64_OPND_Ft
)
497 rt1
+= AARCH64_X_REGISTER_COUNT
;
498 rt2
+= AARCH64_X_REGISTER_COUNT
;
501 stack
.store (pv_add_constant (regs
[rn
], imm
), size
, regs
[rt1
]);
502 stack
.store (pv_add_constant (regs
[rn
], imm
+ size
), size
, regs
[rt2
]);
504 if (inst
.operands
[2].addr
.writeback
)
505 regs
[rn
] = pv_add_constant (regs
[rn
], imm
);
507 /* Ignore the instruction that allocates stack space and sets
509 if (rn
== AARCH64_SP_REGNUM
&& !inst
.operands
[2].addr
.writeback
)
510 seen_stack_set
= true;
512 else if ((inst
.opcode
->iclass
== ldst_imm9
/* Signed immediate. */
513 || (inst
.opcode
->iclass
== ldst_pos
/* Unsigned immediate. */
514 && (inst
.opcode
->op
== OP_STR_POS
515 || inst
.opcode
->op
== OP_STRF_POS
)))
516 && inst
.operands
[1].addr
.base_regno
== AARCH64_SP_REGNUM
517 && strcmp ("str", inst
.opcode
->name
) == 0)
519 /* STR (immediate) */
520 unsigned int rt
= inst
.operands
[0].reg
.regno
;
521 int32_t imm
= inst
.operands
[1].addr
.offset
.imm
;
522 unsigned int rn
= inst
.operands
[1].addr
.base_regno
;
523 int size
= aarch64_get_qualifier_esize (inst
.operands
[0].qualifier
);
524 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rt
525 || inst
.operands
[0].type
== AARCH64_OPND_Ft
);
527 if (inst
.operands
[0].type
== AARCH64_OPND_Ft
)
528 rt
+= AARCH64_X_REGISTER_COUNT
;
530 stack
.store (pv_add_constant (regs
[rn
], imm
), size
, regs
[rt
]);
531 if (inst
.operands
[1].addr
.writeback
)
532 regs
[rn
] = pv_add_constant (regs
[rn
], imm
);
534 /* Are we storing with SP as a base? */
535 if (rn
== AARCH64_SP_REGNUM
)
536 seen_stack_set
= true;
538 else if (inst
.opcode
->iclass
== testbranch
)
540 /* Stop analysis on branch. */
543 else if (inst
.opcode
->iclass
== ic_system
)
545 aarch64_gdbarch_tdep
*tdep
546 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
547 int ra_state_val
= 0;
549 if (insn
== 0xd503233f /* paciasp. */
550 || insn
== 0xd503237f /* pacibsp. */)
552 /* Return addresses are mangled. */
555 else if (insn
== 0xd50323bf /* autiasp. */
556 || insn
== 0xd50323ff /* autibsp. */)
558 /* Return addresses are not mangled. */
561 else if (IS_BTI (insn
))
562 /* We don't need to do anything special for a BTI instruction. */
566 aarch64_debug_printf ("prologue analysis gave up addr=%s"
567 " opcode=0x%x (iclass)",
568 core_addr_to_string_nz (start
), insn
);
572 if (tdep
->has_pauth () && cache
!= nullptr)
574 int regnum
= tdep
->ra_sign_state_regnum
;
575 cache
->saved_regs
[regnum
].set_value (ra_state_val
);
580 aarch64_debug_printf ("prologue analysis gave up addr=%s"
582 core_addr_to_string_nz (start
), insn
);
591 if (pv_is_register (regs
[AARCH64_FP_REGNUM
], AARCH64_SP_REGNUM
))
593 /* Frame pointer is fp. Frame size is constant. */
594 cache
->framereg
= AARCH64_FP_REGNUM
;
595 cache
->framesize
= -regs
[AARCH64_FP_REGNUM
].k
;
597 else if (pv_is_register (regs
[AARCH64_SP_REGNUM
], AARCH64_SP_REGNUM
))
599 /* Try the stack pointer. */
600 cache
->framesize
= -regs
[AARCH64_SP_REGNUM
].k
;
601 cache
->framereg
= AARCH64_SP_REGNUM
;
605 /* We're just out of luck. We don't know where the frame is. */
606 cache
->framereg
= -1;
607 cache
->framesize
= 0;
610 for (i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
614 if (stack
.find_reg (gdbarch
, i
, &offset
))
615 cache
->saved_regs
[i
].set_addr (offset
);
618 for (i
= 0; i
< AARCH64_D_REGISTER_COUNT
; i
++)
620 int regnum
= gdbarch_num_regs (gdbarch
);
623 if (stack
.find_reg (gdbarch
, i
+ AARCH64_X_REGISTER_COUNT
,
625 cache
->saved_regs
[i
+ regnum
+ AARCH64_D0_REGNUM
].set_addr (offset
);
632 aarch64_analyze_prologue (struct gdbarch
*gdbarch
,
633 CORE_ADDR start
, CORE_ADDR limit
,
634 struct aarch64_prologue_cache
*cache
)
636 instruction_reader reader
;
638 return aarch64_analyze_prologue (gdbarch
, start
, limit
, cache
,
644 namespace selftests
{
646 /* Instruction reader from manually cooked instruction sequences. */
648 class instruction_reader_test
: public abstract_instruction_reader
651 template<size_t SIZE
>
652 explicit instruction_reader_test (const uint32_t (&insns
)[SIZE
])
653 : m_insns (insns
), m_insns_size (SIZE
)
656 ULONGEST
read (CORE_ADDR memaddr
, int len
, enum bfd_endian byte_order
)
659 SELF_CHECK (len
== 4);
660 SELF_CHECK (memaddr
% 4 == 0);
661 SELF_CHECK (memaddr
/ 4 < m_insns_size
);
663 return m_insns
[memaddr
/ 4];
667 const uint32_t *m_insns
;
672 aarch64_analyze_prologue_test (void)
674 struct gdbarch_info info
;
676 info
.bfd_arch_info
= bfd_scan_arch ("aarch64");
678 struct gdbarch
*gdbarch
= gdbarch_find_by_info (info
);
679 SELF_CHECK (gdbarch
!= NULL
);
681 struct aarch64_prologue_cache cache
;
682 cache
.saved_regs
= trad_frame_alloc_saved_regs (gdbarch
);
684 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
686 /* Test the simple prologue in which frame pointer is used. */
688 static const uint32_t insns
[] = {
689 0xa9af7bfd, /* stp x29, x30, [sp,#-272]! */
690 0x910003fd, /* mov x29, sp */
691 0x97ffffe6, /* bl 0x400580 */
693 instruction_reader_test
reader (insns
);
695 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
696 SELF_CHECK (end
== 4 * 2);
698 SELF_CHECK (cache
.framereg
== AARCH64_FP_REGNUM
);
699 SELF_CHECK (cache
.framesize
== 272);
701 for (int i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
703 if (i
== AARCH64_FP_REGNUM
)
704 SELF_CHECK (cache
.saved_regs
[i
].addr () == -272);
705 else if (i
== AARCH64_LR_REGNUM
)
706 SELF_CHECK (cache
.saved_regs
[i
].addr () == -264);
708 SELF_CHECK (cache
.saved_regs
[i
].is_realreg ()
709 && cache
.saved_regs
[i
].realreg () == i
);
712 for (int i
= 0; i
< AARCH64_D_REGISTER_COUNT
; i
++)
714 int num_regs
= gdbarch_num_regs (gdbarch
);
715 int regnum
= i
+ num_regs
+ AARCH64_D0_REGNUM
;
717 SELF_CHECK (cache
.saved_regs
[regnum
].is_realreg ()
718 && cache
.saved_regs
[regnum
].realreg () == regnum
);
722 /* Test a prologue in which STR is used and frame pointer is not
725 static const uint32_t insns
[] = {
726 0xf81d0ff3, /* str x19, [sp, #-48]! */
727 0xb9002fe0, /* str w0, [sp, #44] */
728 0xf90013e1, /* str x1, [sp, #32]*/
729 0xfd000fe0, /* str d0, [sp, #24] */
730 0xaa0203f3, /* mov x19, x2 */
731 0xf94013e0, /* ldr x0, [sp, #32] */
733 instruction_reader_test
reader (insns
);
735 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
736 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
738 SELF_CHECK (end
== 4 * 5);
740 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
741 SELF_CHECK (cache
.framesize
== 48);
743 for (int i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
746 SELF_CHECK (cache
.saved_regs
[i
].addr () == -16);
748 SELF_CHECK (cache
.saved_regs
[i
].addr () == -48);
750 SELF_CHECK (cache
.saved_regs
[i
].is_realreg ()
751 && cache
.saved_regs
[i
].realreg () == i
);
754 for (int i
= 0; i
< AARCH64_D_REGISTER_COUNT
; i
++)
756 int num_regs
= gdbarch_num_regs (gdbarch
);
757 int regnum
= i
+ num_regs
+ AARCH64_D0_REGNUM
;
761 SELF_CHECK (cache
.saved_regs
[regnum
].addr () == -24);
763 SELF_CHECK (cache
.saved_regs
[regnum
].is_realreg ()
764 && cache
.saved_regs
[regnum
].realreg () == regnum
);
768 /* Test handling of movz before setting the frame pointer. */
770 static const uint32_t insns
[] = {
771 0xa9bf7bfd, /* stp x29, x30, [sp, #-16]! */
772 0x52800020, /* mov w0, #0x1 */
773 0x910003fd, /* mov x29, sp */
774 0x528000a2, /* mov w2, #0x5 */
775 0x97fffff8, /* bl 6e4 */
778 instruction_reader_test
reader (insns
);
780 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
781 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
783 /* We should stop at the 4th instruction. */
784 SELF_CHECK (end
== (4 - 1) * 4);
785 SELF_CHECK (cache
.framereg
== AARCH64_FP_REGNUM
);
786 SELF_CHECK (cache
.framesize
== 16);
789 /* Test handling of movz/stp when using the stack pointer as frame
792 static const uint32_t insns
[] = {
793 0xa9bc7bfd, /* stp x29, x30, [sp, #-64]! */
794 0x52800020, /* mov w0, #0x1 */
795 0x290207e0, /* stp w0, w1, [sp, #16] */
796 0xa9018fe2, /* stp x2, x3, [sp, #24] */
797 0x528000a2, /* mov w2, #0x5 */
798 0x97fffff8, /* bl 6e4 */
801 instruction_reader_test
reader (insns
);
803 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
804 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
806 /* We should stop at the 5th instruction. */
807 SELF_CHECK (end
== (5 - 1) * 4);
808 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
809 SELF_CHECK (cache
.framesize
== 64);
812 /* Test handling of movz/str when using the stack pointer as frame
815 static const uint32_t insns
[] = {
816 0xa9bc7bfd, /* stp x29, x30, [sp, #-64]! */
817 0x52800020, /* mov w0, #0x1 */
818 0xb9002be4, /* str w4, [sp, #40] */
819 0xf9001be5, /* str x5, [sp, #48] */
820 0x528000a2, /* mov w2, #0x5 */
821 0x97fffff8, /* bl 6e4 */
824 instruction_reader_test
reader (insns
);
826 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
827 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
829 /* We should stop at the 5th instruction. */
830 SELF_CHECK (end
== (5 - 1) * 4);
831 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
832 SELF_CHECK (cache
.framesize
== 64);
835 /* Test handling of movz/stur when using the stack pointer as frame
838 static const uint32_t insns
[] = {
839 0xa9bc7bfd, /* stp x29, x30, [sp, #-64]! */
840 0x52800020, /* mov w0, #0x1 */
841 0xb80343e6, /* stur w6, [sp, #52] */
842 0xf80383e7, /* stur x7, [sp, #56] */
843 0x528000a2, /* mov w2, #0x5 */
844 0x97fffff8, /* bl 6e4 */
847 instruction_reader_test
reader (insns
);
849 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
850 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
852 /* We should stop at the 5th instruction. */
853 SELF_CHECK (end
== (5 - 1) * 4);
854 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
855 SELF_CHECK (cache
.framesize
== 64);
858 /* Test handling of movz when there is no frame pointer set or no stack
861 static const uint32_t insns
[] = {
862 0xa9bf7bfd, /* stp x29, x30, [sp, #-16]! */
863 0x52800020, /* mov w0, #0x1 */
864 0x528000a2, /* mov w2, #0x5 */
865 0x97fffff8, /* bl 6e4 */
868 instruction_reader_test
reader (insns
);
870 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
871 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
873 /* We should stop at the 4th instruction. */
874 SELF_CHECK (end
== (4 - 1) * 4);
875 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
876 SELF_CHECK (cache
.framesize
== 16);
879 /* Test a prologue in which there is a return address signing instruction. */
880 if (tdep
->has_pauth ())
882 static const uint32_t insns
[] = {
883 0xd503233f, /* paciasp */
884 0xa9bd7bfd, /* stp x29, x30, [sp, #-48]! */
885 0x910003fd, /* mov x29, sp */
886 0xf801c3f3, /* str x19, [sp, #28] */
887 0xb9401fa0, /* ldr x19, [x29, #28] */
889 instruction_reader_test
reader (insns
);
891 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
892 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
,
895 SELF_CHECK (end
== 4 * 4);
896 SELF_CHECK (cache
.framereg
== AARCH64_FP_REGNUM
);
897 SELF_CHECK (cache
.framesize
== 48);
899 for (int i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
902 SELF_CHECK (cache
.saved_regs
[i
].addr () == -20);
903 else if (i
== AARCH64_FP_REGNUM
)
904 SELF_CHECK (cache
.saved_regs
[i
].addr () == -48);
905 else if (i
== AARCH64_LR_REGNUM
)
906 SELF_CHECK (cache
.saved_regs
[i
].addr () == -40);
908 SELF_CHECK (cache
.saved_regs
[i
].is_realreg ()
909 && cache
.saved_regs
[i
].realreg () == i
);
912 if (tdep
->has_pauth ())
914 int regnum
= tdep
->ra_sign_state_regnum
;
915 SELF_CHECK (cache
.saved_regs
[regnum
].is_value ());
919 /* Test a prologue with a BTI instruction. */
921 static const uint32_t insns
[] = {
922 0xd503245f, /* bti */
923 0xa9bd7bfd, /* stp x29, x30, [sp, #-48]! */
924 0x910003fd, /* mov x29, sp */
925 0xf801c3f3, /* str x19, [sp, #28] */
926 0xb9401fa0, /* ldr x19, [x29, #28] */
928 instruction_reader_test
reader (insns
);
930 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
931 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
,
934 SELF_CHECK (end
== 4 * 4);
935 SELF_CHECK (cache
.framereg
== AARCH64_FP_REGNUM
);
936 SELF_CHECK (cache
.framesize
== 48);
938 for (int i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
941 SELF_CHECK (cache
.saved_regs
[i
].addr () == -20);
942 else if (i
== AARCH64_FP_REGNUM
)
943 SELF_CHECK (cache
.saved_regs
[i
].addr () == -48);
944 else if (i
== AARCH64_LR_REGNUM
)
945 SELF_CHECK (cache
.saved_regs
[i
].addr () == -40);
947 SELF_CHECK (cache
.saved_regs
[i
].is_realreg ()
948 && cache
.saved_regs
[i
].realreg () == i
);
952 } /* namespace selftests */
953 #endif /* GDB_SELF_TEST */
955 /* Implement the "skip_prologue" gdbarch method. */
958 aarch64_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
960 CORE_ADDR func_addr
, func_end_addr
, limit_pc
;
962 /* See if we can determine the end of the prologue via the symbol
963 table. If so, then return either PC, or the PC after the
964 prologue, whichever is greater. */
966 = find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end_addr
);
970 CORE_ADDR post_prologue_pc
971 = skip_prologue_using_sal (gdbarch
, func_addr
);
973 if (post_prologue_pc
!= 0)
974 return std::max (pc
, post_prologue_pc
);
977 /* Can't determine prologue from the symbol table, need to examine
980 /* Find an upper limit on the function prologue using the debug
981 information. If the debug information could not be used to
982 provide that bound, then use an arbitrary large number as the
984 limit_pc
= skip_prologue_using_sal (gdbarch
, pc
);
986 limit_pc
= pc
+ 128; /* Magic. */
989 = func_end_addr
== 0 ? limit_pc
: std::min (limit_pc
, func_end_addr
- 4);
991 /* Try disassembling prologue. */
992 return aarch64_analyze_prologue (gdbarch
, pc
, limit_pc
, NULL
);
995 /* Scan the function prologue for THIS_FRAME and populate the prologue
999 aarch64_scan_prologue (const frame_info_ptr
&this_frame
,
1000 struct aarch64_prologue_cache
*cache
)
1002 CORE_ADDR block_addr
= get_frame_address_in_block (this_frame
);
1003 CORE_ADDR prologue_start
;
1004 CORE_ADDR prologue_end
;
1005 CORE_ADDR prev_pc
= get_frame_pc (this_frame
);
1006 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1008 cache
->prev_pc
= prev_pc
;
1010 /* Assume we do not find a frame. */
1011 cache
->framereg
= -1;
1012 cache
->framesize
= 0;
1014 if (find_pc_partial_function (block_addr
, NULL
, &prologue_start
,
1017 struct symtab_and_line sal
= find_pc_line (prologue_start
, 0);
1021 /* No line info so use the current PC. */
1022 prologue_end
= prev_pc
;
1024 else if (sal
.end
< prologue_end
)
1026 /* The next line begins after the function end. */
1027 prologue_end
= sal
.end
;
1030 prologue_end
= std::min (prologue_end
, prev_pc
);
1031 aarch64_analyze_prologue (gdbarch
, prologue_start
, prologue_end
, cache
);
1035 CORE_ADDR frame_loc
;
1037 frame_loc
= get_frame_register_unsigned (this_frame
, AARCH64_FP_REGNUM
);
1041 cache
->framereg
= AARCH64_FP_REGNUM
;
1042 cache
->framesize
= 16;
1043 cache
->saved_regs
[29].set_addr (0);
1044 cache
->saved_regs
[30].set_addr (8);
1048 /* Fill in *CACHE with information about the prologue of *THIS_FRAME. This
1049 function may throw an exception if the inferior's registers or memory is
1053 aarch64_make_prologue_cache_1 (const frame_info_ptr
&this_frame
,
1054 struct aarch64_prologue_cache
*cache
)
1056 CORE_ADDR unwound_fp
;
1059 aarch64_scan_prologue (this_frame
, cache
);
1061 if (cache
->framereg
== -1)
1064 unwound_fp
= get_frame_register_unsigned (this_frame
, cache
->framereg
);
1065 if (unwound_fp
== 0)
1068 cache
->prev_sp
= unwound_fp
;
1069 if (!aarch64_stack_frame_destroyed_p (get_frame_arch (this_frame
),
1071 cache
->prev_sp
+= cache
->framesize
;
1073 /* Calculate actual addresses of saved registers using offsets
1074 determined by aarch64_analyze_prologue. */
1075 for (reg
= 0; reg
< gdbarch_num_regs (get_frame_arch (this_frame
)); reg
++)
1076 if (cache
->saved_regs
[reg
].is_addr ())
1077 cache
->saved_regs
[reg
].set_addr (cache
->saved_regs
[reg
].addr ()
1080 cache
->func
= get_frame_func (this_frame
);
1082 cache
->available_p
= 1;
1085 /* Allocate and fill in *THIS_CACHE with information about the prologue of
1086 *THIS_FRAME. Do not do this is if *THIS_CACHE was already allocated.
1087 Return a pointer to the current aarch64_prologue_cache in
1090 static struct aarch64_prologue_cache
*
1091 aarch64_make_prologue_cache (const frame_info_ptr
&this_frame
, void **this_cache
)
1093 struct aarch64_prologue_cache
*cache
;
1095 if (*this_cache
!= NULL
)
1096 return (struct aarch64_prologue_cache
*) *this_cache
;
1098 cache
= FRAME_OBSTACK_ZALLOC (struct aarch64_prologue_cache
);
1099 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1100 *this_cache
= cache
;
1104 aarch64_make_prologue_cache_1 (this_frame
, cache
);
1106 catch (const gdb_exception_error
&ex
)
1108 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
1115 /* Implement the "stop_reason" frame_unwind method. */
1117 static enum unwind_stop_reason
1118 aarch64_prologue_frame_unwind_stop_reason (const frame_info_ptr
&this_frame
,
1121 struct aarch64_prologue_cache
*cache
1122 = aarch64_make_prologue_cache (this_frame
, this_cache
);
1124 if (!cache
->available_p
)
1125 return UNWIND_UNAVAILABLE
;
1127 /* Halt the backtrace at "_start". */
1128 gdbarch
*arch
= get_frame_arch (this_frame
);
1129 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (arch
);
1130 if (cache
->prev_pc
<= tdep
->lowest_pc
)
1131 return UNWIND_OUTERMOST
;
1133 /* We've hit a wall, stop. */
1134 if (cache
->prev_sp
== 0)
1135 return UNWIND_OUTERMOST
;
1137 return UNWIND_NO_REASON
;
1140 /* Our frame ID for a normal frame is the current function's starting
1141 PC and the caller's SP when we were called. */
1144 aarch64_prologue_this_id (const frame_info_ptr
&this_frame
,
1145 void **this_cache
, struct frame_id
*this_id
)
1147 struct aarch64_prologue_cache
*cache
1148 = aarch64_make_prologue_cache (this_frame
, this_cache
);
1150 if (!cache
->available_p
)
1151 *this_id
= frame_id_build_unavailable_stack (cache
->func
);
1153 *this_id
= frame_id_build (cache
->prev_sp
, cache
->func
);
1156 /* Implement the "prev_register" frame_unwind method. */
1158 static struct value
*
1159 aarch64_prologue_prev_register (const frame_info_ptr
&this_frame
,
1160 void **this_cache
, int prev_regnum
)
1162 struct aarch64_prologue_cache
*cache
1163 = aarch64_make_prologue_cache (this_frame
, this_cache
);
1165 /* If we are asked to unwind the PC, then we need to return the LR
1166 instead. The prologue may save PC, but it will point into this
1167 frame's prologue, not the next frame's resume location. */
1168 if (prev_regnum
== AARCH64_PC_REGNUM
)
1171 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1172 aarch64_gdbarch_tdep
*tdep
1173 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1175 lr
= frame_unwind_register_unsigned (this_frame
, AARCH64_LR_REGNUM
);
1177 if (tdep
->has_pauth ()
1178 && cache
->saved_regs
[tdep
->ra_sign_state_regnum
].is_value ())
1179 lr
= aarch64_frame_unmask_lr (tdep
, this_frame
, lr
);
1181 return frame_unwind_got_constant (this_frame
, prev_regnum
, lr
);
1184 /* SP is generally not saved to the stack, but this frame is
1185 identified by the next frame's stack pointer at the time of the
1186 call. The value was already reconstructed into PREV_SP. */
1192 | | | <- Previous SP
1195 +--| saved fp |<- FP
1199 if (prev_regnum
== AARCH64_SP_REGNUM
)
1200 return frame_unwind_got_constant (this_frame
, prev_regnum
,
1203 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
,
1207 /* AArch64 prologue unwinder. */
1208 static const frame_unwind_legacy
aarch64_prologue_unwind (
1212 aarch64_prologue_frame_unwind_stop_reason
,
1213 aarch64_prologue_this_id
,
1214 aarch64_prologue_prev_register
,
1216 default_frame_sniffer
1219 /* Allocate and fill in *THIS_CACHE with information about the prologue of
1220 *THIS_FRAME. Do not do this is if *THIS_CACHE was already allocated.
1221 Return a pointer to the current aarch64_prologue_cache in
1224 static struct aarch64_prologue_cache
*
1225 aarch64_make_stub_cache (const frame_info_ptr
&this_frame
, void **this_cache
)
1227 struct aarch64_prologue_cache
*cache
;
1229 if (*this_cache
!= NULL
)
1230 return (struct aarch64_prologue_cache
*) *this_cache
;
1232 cache
= FRAME_OBSTACK_ZALLOC (struct aarch64_prologue_cache
);
1233 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1234 *this_cache
= cache
;
1238 cache
->prev_sp
= get_frame_register_unsigned (this_frame
,
1240 cache
->prev_pc
= get_frame_pc (this_frame
);
1241 cache
->available_p
= 1;
1243 catch (const gdb_exception_error
&ex
)
1245 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
1252 /* Implement the "stop_reason" frame_unwind method. */
1254 static enum unwind_stop_reason
1255 aarch64_stub_frame_unwind_stop_reason (const frame_info_ptr
&this_frame
,
1258 struct aarch64_prologue_cache
*cache
1259 = aarch64_make_stub_cache (this_frame
, this_cache
);
1261 if (!cache
->available_p
)
1262 return UNWIND_UNAVAILABLE
;
1264 return UNWIND_NO_REASON
;
1267 /* Our frame ID for a stub frame is the current SP and LR. */
1270 aarch64_stub_this_id (const frame_info_ptr
&this_frame
,
1271 void **this_cache
, struct frame_id
*this_id
)
1273 struct aarch64_prologue_cache
*cache
1274 = aarch64_make_stub_cache (this_frame
, this_cache
);
1276 if (cache
->available_p
)
1277 *this_id
= frame_id_build (cache
->prev_sp
, cache
->prev_pc
);
1279 *this_id
= frame_id_build_unavailable_stack (cache
->prev_pc
);
1282 /* Implement the "sniffer" frame_unwind method. */
1285 aarch64_stub_unwind_sniffer (const struct frame_unwind
*self
,
1286 const frame_info_ptr
&this_frame
,
1287 void **this_prologue_cache
)
1289 CORE_ADDR addr_in_block
;
1292 addr_in_block
= get_frame_address_in_block (this_frame
);
1293 if (in_plt_section (addr_in_block
)
1294 /* We also use the stub winder if the target memory is unreadable
1295 to avoid having the prologue unwinder trying to read it. */
1296 || target_read_memory (get_frame_pc (this_frame
), dummy
, 4) != 0)
1302 /* AArch64 stub unwinder. */
1303 static const frame_unwind_legacy
aarch64_stub_unwind (
1307 aarch64_stub_frame_unwind_stop_reason
,
1308 aarch64_stub_this_id
,
1309 aarch64_prologue_prev_register
,
1311 aarch64_stub_unwind_sniffer
1314 /* Return the frame base address of *THIS_FRAME. */
1317 aarch64_normal_frame_base (const frame_info_ptr
&this_frame
, void **this_cache
)
1319 struct aarch64_prologue_cache
*cache
1320 = aarch64_make_prologue_cache (this_frame
, this_cache
);
1322 return cache
->prev_sp
- cache
->framesize
;
1325 /* AArch64 default frame base information. */
1326 static frame_base aarch64_normal_base
=
1328 &aarch64_prologue_unwind
,
1329 aarch64_normal_frame_base
,
1330 aarch64_normal_frame_base
,
1331 aarch64_normal_frame_base
1334 /* Return the value of the REGNUM register in the previous frame of
1337 static struct value
*
1338 aarch64_dwarf2_prev_register (const frame_info_ptr
&this_frame
,
1339 void **this_cache
, int regnum
)
1341 gdbarch
*arch
= get_frame_arch (this_frame
);
1342 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (arch
);
1347 case AARCH64_PC_REGNUM
:
1348 lr
= frame_unwind_register_unsigned (this_frame
, AARCH64_LR_REGNUM
);
1349 lr
= aarch64_frame_unmask_lr (tdep
, this_frame
, lr
);
1350 return frame_unwind_got_constant (this_frame
, regnum
, lr
);
1353 internal_error (_("Unexpected register %d"), regnum
);
1357 static const unsigned char op_lit0
= DW_OP_lit0
;
1358 static const unsigned char op_lit1
= DW_OP_lit1
;
1360 /* Implement the "init_reg" dwarf2_frame_ops method. */
1363 aarch64_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
1364 struct dwarf2_frame_state_reg
*reg
,
1365 const frame_info_ptr
&this_frame
)
1367 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1371 case AARCH64_PC_REGNUM
:
1372 reg
->how
= DWARF2_FRAME_REG_FN
;
1373 reg
->loc
.fn
= aarch64_dwarf2_prev_register
;
1376 case AARCH64_SP_REGNUM
:
1377 reg
->how
= DWARF2_FRAME_REG_CFA
;
1381 /* Init pauth registers. */
1382 if (tdep
->has_pauth ())
1384 if (regnum
== tdep
->ra_sign_state_regnum
)
1386 /* Initialize RA_STATE to zero. */
1387 reg
->how
= DWARF2_FRAME_REG_SAVED_VAL_EXP
;
1388 reg
->loc
.exp
.start
= &op_lit0
;
1389 reg
->loc
.exp
.len
= 1;
1392 else if (regnum
>= tdep
->pauth_reg_base
1393 && regnum
< tdep
->pauth_reg_base
+ tdep
->pauth_reg_count
)
1395 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1401 /* Implement the execute_dwarf_cfa_vendor_op method. */
1404 aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch
*gdbarch
, gdb_byte op
,
1405 struct dwarf2_frame_state
*fs
)
1407 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1408 struct dwarf2_frame_state_reg
*ra_state
;
1410 if (op
== DW_CFA_AARCH64_negate_ra_state
)
1412 /* On systems without pauth, treat as a nop. */
1413 if (!tdep
->has_pauth ())
1416 /* Allocate RA_STATE column if it's not allocated yet. */
1417 fs
->regs
.alloc_regs (AARCH64_DWARF_RA_SIGN_STATE
+ 1);
1419 /* Toggle the status of RA_STATE between 0 and 1. */
1420 ra_state
= &(fs
->regs
.reg
[AARCH64_DWARF_RA_SIGN_STATE
]);
1421 ra_state
->how
= DWARF2_FRAME_REG_SAVED_VAL_EXP
;
1423 if (ra_state
->loc
.exp
.start
== nullptr
1424 || ra_state
->loc
.exp
.start
== &op_lit0
)
1425 ra_state
->loc
.exp
.start
= &op_lit1
;
1427 ra_state
->loc
.exp
.start
= &op_lit0
;
1429 ra_state
->loc
.exp
.len
= 1;
1437 /* Used for matching BRK instructions for AArch64. */
1438 static constexpr uint32_t BRK_INSN_MASK
= 0xffe0001f;
1439 static constexpr uint32_t BRK_INSN_BASE
= 0xd4200000;
1441 /* Implementation of gdbarch_program_breakpoint_here_p for aarch64. */
1444 aarch64_program_breakpoint_here_p (gdbarch
*gdbarch
, CORE_ADDR address
)
1446 const uint32_t insn_len
= 4;
1447 gdb_byte target_mem
[4];
1449 /* Enable the automatic memory restoration from breakpoints while
1450 we read the memory. Otherwise we may find temporary breakpoints, ones
1451 inserted by GDB, and flag them as permanent breakpoints. */
1452 scoped_restore restore_memory
1453 = make_scoped_restore_show_memory_breakpoints (0);
1455 if (target_read_memory (address
, target_mem
, insn_len
) == 0)
1458 (uint32_t) extract_unsigned_integer (target_mem
, insn_len
,
1459 gdbarch_byte_order_for_code (gdbarch
));
1461 /* Check if INSN is a BRK instruction pattern. There are multiple choices
1462 of such instructions with different immediate values. Different OS'
1463 may use a different variation, but they have the same outcome. */
1464 return ((insn
& BRK_INSN_MASK
) == BRK_INSN_BASE
);
1470 /* When arguments must be pushed onto the stack, they go on in reverse
1471 order. The code below implements a FILO (stack) to do this. */
1475 /* Value to pass on stack. It can be NULL if this item is for stack
1477 const gdb_byte
*data
;
1479 /* Size in bytes of value to pass on stack. */
1483 /* Implement the gdbarch type alignment method, overrides the generic
1484 alignment algorithm for anything that is aarch64 specific. */
1487 aarch64_type_align (gdbarch
*gdbarch
, struct type
*t
)
1489 t
= check_typedef (t
);
1490 if (t
->code () == TYPE_CODE_ARRAY
&& t
->is_vector ())
1492 /* Use the natural alignment for vector types (the same for
1493 scalar type), but the maximum alignment is 128-bit. */
1494 if (t
->length () > 16)
1497 return t
->length ();
1500 /* Allow the common code to calculate the alignment. */
1504 /* Worker function for aapcs_is_vfp_call_or_return_candidate.
1506 Return the number of register required, or -1 on failure.
1508 When encountering a base element, if FUNDAMENTAL_TYPE is not set then set it
1509 to the element, else fail if the type of this element does not match the
1513 aapcs_is_vfp_call_or_return_candidate_1 (struct type
*type
,
1514 struct type
**fundamental_type
)
1516 if (type
== nullptr)
1519 switch (type
->code ())
1522 case TYPE_CODE_DECFLOAT
:
1523 if (type
->length () > 16)
1526 if (*fundamental_type
== nullptr)
1527 *fundamental_type
= type
;
1528 else if (type
->length () != (*fundamental_type
)->length ()
1529 || type
->code () != (*fundamental_type
)->code ())
1534 case TYPE_CODE_COMPLEX
:
1536 struct type
*target_type
= check_typedef (type
->target_type ());
1537 if (target_type
->length () > 16)
1540 if (*fundamental_type
== nullptr)
1541 *fundamental_type
= target_type
;
1542 else if (target_type
->length () != (*fundamental_type
)->length ()
1543 || target_type
->code () != (*fundamental_type
)->code ())
1549 case TYPE_CODE_ARRAY
:
1551 if (type
->is_vector ())
1553 if (type
->length () != 8 && type
->length () != 16)
1556 if (*fundamental_type
== nullptr)
1557 *fundamental_type
= type
;
1558 else if (type
->length () != (*fundamental_type
)->length ()
1559 || type
->code () != (*fundamental_type
)->code ())
1566 struct type
*target_type
= type
->target_type ();
1567 int count
= aapcs_is_vfp_call_or_return_candidate_1
1568 (target_type
, fundamental_type
);
1573 count
*= (type
->length () / target_type
->length ());
1578 case TYPE_CODE_STRUCT
:
1579 case TYPE_CODE_UNION
:
1583 for (int i
= 0; i
< type
->num_fields (); i
++)
1585 /* Ignore any static fields. */
1586 if (type
->field (i
).is_static ())
1589 struct type
*member
= check_typedef (type
->field (i
).type ());
1591 int sub_count
= aapcs_is_vfp_call_or_return_candidate_1
1592 (member
, fundamental_type
);
1593 if (sub_count
== -1)
1598 /* Ensure there is no padding between the fields (allowing for empty
1599 zero length structs) */
1600 int ftype_length
= (*fundamental_type
== nullptr)
1601 ? 0 : (*fundamental_type
)->length ();
1602 if (count
* ftype_length
!= type
->length ())
1615 /* Return true if an argument, whose type is described by TYPE, can be passed or
1616 returned in simd/fp registers, providing enough parameter passing registers
1617 are available. This is as described in the AAPCS64.
1619 Upon successful return, *COUNT returns the number of needed registers,
1620 *FUNDAMENTAL_TYPE contains the type of those registers.
1622 Candidate as per the AAPCS64 5.4.2.C is either a:
1625 - HFA (Homogeneous Floating-point Aggregate, 4.3.5.1). A Composite type where
1626 all the members are floats and has at most 4 members.
1627 - HVA (Homogeneous Short-vector Aggregate, 4.3.5.2). A Composite type where
1628 all the members are short vectors and has at most 4 members.
1631 Note that HFAs and HVAs can include nested structures and arrays. */
1634 aapcs_is_vfp_call_or_return_candidate (struct type
*type
, int *count
,
1635 struct type
**fundamental_type
)
1637 if (type
== nullptr)
1640 *fundamental_type
= nullptr;
1642 int ag_count
= aapcs_is_vfp_call_or_return_candidate_1 (type
,
1645 if (ag_count
> 0 && ag_count
<= HA_MAX_NUM_FLDS
)
1654 /* AArch64 function call information structure. */
1655 struct aarch64_call_info
1657 /* the current argument number. */
1658 unsigned argnum
= 0;
1660 /* The next general purpose register number, equivalent to NGRN as
1661 described in the AArch64 Procedure Call Standard. */
1664 /* The next SIMD and floating point register number, equivalent to
1665 NSRN as described in the AArch64 Procedure Call Standard. */
1668 /* The next stacked argument address, equivalent to NSAA as
1669 described in the AArch64 Procedure Call Standard. */
1672 /* Stack item vector. */
1673 std::vector
<stack_item_t
> si
;
1676 /* Pass a value in a sequence of consecutive X registers. The caller
1677 is responsible for ensuring sufficient registers are available. */
1680 pass_in_x (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1681 struct aarch64_call_info
*info
, struct type
*type
,
1684 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1685 int len
= type
->length ();
1686 enum type_code typecode
= type
->code ();
1687 int regnum
= AARCH64_X0_REGNUM
+ info
->ngrn
;
1688 const bfd_byte
*buf
= arg
->contents ().data ();
1694 int partial_len
= len
< X_REGISTER_SIZE
? len
: X_REGISTER_SIZE
;
1695 CORE_ADDR regval
= extract_unsigned_integer (buf
, partial_len
,
1699 /* Adjust sub-word struct/union args when big-endian. */
1700 if (byte_order
== BFD_ENDIAN_BIG
1701 && partial_len
< X_REGISTER_SIZE
1702 && (typecode
== TYPE_CODE_STRUCT
|| typecode
== TYPE_CODE_UNION
))
1703 regval
<<= ((X_REGISTER_SIZE
- partial_len
) * TARGET_CHAR_BIT
);
1705 aarch64_debug_printf ("arg %d in %s = 0x%s", info
->argnum
,
1706 gdbarch_register_name (gdbarch
, regnum
),
1707 phex (regval
, X_REGISTER_SIZE
));
1709 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
1716 /* Attempt to marshall a value in a V register. Return 1 if
1717 successful, or 0 if insufficient registers are available. This
1718 function, unlike the equivalent pass_in_x() function does not
1719 handle arguments spread across multiple registers. */
1722 pass_in_v (struct gdbarch
*gdbarch
,
1723 struct regcache
*regcache
,
1724 struct aarch64_call_info
*info
,
1725 int len
, const bfd_byte
*buf
)
1729 int regnum
= AARCH64_V0_REGNUM
+ info
->nsrn
;
1730 /* Enough space for a full vector register. */
1731 gdb::byte_vector
reg (register_size (gdbarch
, regnum
), 0);
1732 gdb_assert (len
<= reg
.size ());
1737 /* PCS C.1, the argument is allocated to the least significant
1738 bits of V register. */
1739 memcpy (reg
.data (), buf
, len
);
1740 regcache
->cooked_write (regnum
, reg
);
1742 aarch64_debug_printf ("arg %d in %s", info
->argnum
,
1743 gdbarch_register_name (gdbarch
, regnum
));
1751 /* Marshall an argument onto the stack. */
1754 pass_on_stack (struct aarch64_call_info
*info
, struct type
*type
,
1757 const bfd_byte
*buf
= arg
->contents ().data ();
1758 int len
= type
->length ();
1764 align
= type_align (type
);
1766 /* PCS C.17 Stack should be aligned to the larger of 8 bytes or the
1767 Natural alignment of the argument's type. */
1768 align
= align_up (align
, 8);
1770 /* The AArch64 PCS requires at most doubleword alignment. */
1774 aarch64_debug_printf ("arg %d len=%d @ sp + %d\n", info
->argnum
, len
,
1779 info
->si
.push_back (item
);
1782 if (info
->nsaa
& (align
- 1))
1784 /* Push stack alignment padding. */
1785 int pad
= align
- (info
->nsaa
& (align
- 1));
1790 info
->si
.push_back (item
);
1795 /* Marshall an argument into a sequence of one or more consecutive X
1796 registers or, if insufficient X registers are available then onto
1800 pass_in_x_or_stack (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1801 struct aarch64_call_info
*info
, struct type
*type
,
1804 int len
= type
->length ();
1805 int nregs
= (len
+ X_REGISTER_SIZE
- 1) / X_REGISTER_SIZE
;
1807 /* PCS C.13 - Pass in registers if we have enough spare */
1808 if (info
->ngrn
+ nregs
<= 8)
1810 pass_in_x (gdbarch
, regcache
, info
, type
, arg
);
1811 info
->ngrn
+= nregs
;
1816 pass_on_stack (info
, type
, arg
);
1820 /* Pass a value, which is of type arg_type, in a V register. Assumes value is a
1821 aapcs_is_vfp_call_or_return_candidate and there are enough spare V
1822 registers. A return value of false is an error state as the value will have
1823 been partially passed to the stack. */
1825 pass_in_v_vfp_candidate (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1826 struct aarch64_call_info
*info
, struct type
*arg_type
,
1829 switch (arg_type
->code ())
1832 case TYPE_CODE_DECFLOAT
:
1833 return pass_in_v (gdbarch
, regcache
, info
, arg_type
->length (),
1834 arg
->contents ().data ());
1837 case TYPE_CODE_COMPLEX
:
1839 const bfd_byte
*buf
= arg
->contents ().data ();
1840 struct type
*target_type
= check_typedef (arg_type
->target_type ());
1842 if (!pass_in_v (gdbarch
, regcache
, info
, target_type
->length (),
1846 return pass_in_v (gdbarch
, regcache
, info
, target_type
->length (),
1847 buf
+ target_type
->length ());
1850 case TYPE_CODE_ARRAY
:
1851 if (arg_type
->is_vector ())
1852 return pass_in_v (gdbarch
, regcache
, info
, arg_type
->length (),
1853 arg
->contents ().data ());
1856 case TYPE_CODE_STRUCT
:
1857 case TYPE_CODE_UNION
:
1858 for (int i
= 0; i
< arg_type
->num_fields (); i
++)
1860 /* Don't include static fields. */
1861 if (arg_type
->field (i
).is_static ())
1864 struct value
*field
= arg
->primitive_field (0, i
, arg_type
);
1865 struct type
*field_type
= check_typedef (field
->type ());
1867 if (!pass_in_v_vfp_candidate (gdbarch
, regcache
, info
, field_type
,
1878 /* Implement the "push_dummy_call" gdbarch method. */
1881 aarch64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
1882 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1884 struct value
**args
, CORE_ADDR sp
,
1885 function_call_return_method return_method
,
1886 CORE_ADDR struct_addr
)
1889 struct aarch64_call_info info
;
1891 /* We need to know what the type of the called function is in order
1892 to determine the number of named/anonymous arguments for the
1893 actual argument placement, and the return type in order to handle
1894 return value correctly.
1896 The generic code above us views the decision of return in memory
1897 or return in registers as a two stage processes. The language
1898 handler is consulted first and may decide to return in memory (eg
1899 class with copy constructor returned by value), this will cause
1900 the generic code to allocate space AND insert an initial leading
1903 If the language code does not decide to pass in memory then the
1904 target code is consulted.
1906 If the language code decides to pass in memory we want to move
1907 the pointer inserted as the initial argument from the argument
1908 list and into X8, the conventional AArch64 struct return pointer
1911 /* Set the return address. For the AArch64, the return breakpoint
1912 is always at BP_ADDR. */
1913 regcache_cooked_write_unsigned (regcache
, AARCH64_LR_REGNUM
, bp_addr
);
1915 /* If we were given an initial argument for the return slot, lose it. */
1916 if (return_method
== return_method_hidden_param
)
1922 /* The struct_return pointer occupies X8. */
1923 if (return_method
!= return_method_normal
)
1925 aarch64_debug_printf ("struct return in %s = 0x%s",
1926 gdbarch_register_name
1927 (gdbarch
, AARCH64_STRUCT_RETURN_REGNUM
),
1928 paddress (gdbarch
, struct_addr
));
1930 regcache_cooked_write_unsigned (regcache
, AARCH64_STRUCT_RETURN_REGNUM
,
1934 for (argnum
= 0; argnum
< nargs
; argnum
++)
1936 struct value
*arg
= args
[argnum
];
1937 struct type
*arg_type
, *fundamental_type
;
1940 arg_type
= check_typedef (arg
->type ());
1941 len
= arg_type
->length ();
1943 /* If arg can be passed in v registers as per the AAPCS64, then do so if
1944 if there are enough spare registers. */
1945 if (aapcs_is_vfp_call_or_return_candidate (arg_type
, &elements
,
1948 if (info
.nsrn
+ elements
<= 8)
1950 /* We know that we have sufficient registers available therefore
1951 this will never need to fallback to the stack. */
1952 if (!pass_in_v_vfp_candidate (gdbarch
, regcache
, &info
, arg_type
,
1954 gdb_assert_not_reached ("Failed to push args");
1959 pass_on_stack (&info
, arg_type
, arg
);
1964 switch (arg_type
->code ())
1967 case TYPE_CODE_BOOL
:
1968 case TYPE_CODE_CHAR
:
1969 case TYPE_CODE_RANGE
:
1970 case TYPE_CODE_ENUM
:
1971 if (len
< 4 && !is_fixed_point_type (arg_type
))
1973 /* Promote to 32 bit integer. */
1974 if (arg_type
->is_unsigned ())
1975 arg_type
= builtin_type (gdbarch
)->builtin_uint32
;
1977 arg_type
= builtin_type (gdbarch
)->builtin_int32
;
1978 arg
= value_cast (arg_type
, arg
);
1980 pass_in_x_or_stack (gdbarch
, regcache
, &info
, arg_type
, arg
);
1983 case TYPE_CODE_STRUCT
:
1984 case TYPE_CODE_ARRAY
:
1985 case TYPE_CODE_UNION
:
1988 /* PCS B.7 Aggregates larger than 16 bytes are passed by
1989 invisible reference. */
1991 /* Allocate aligned storage. */
1992 sp
= align_down (sp
- len
, 16);
1994 /* Write the real data into the stack. */
1995 write_memory (sp
, arg
->contents ().data (), len
);
1997 /* Construct the indirection. */
1998 arg_type
= lookup_pointer_type (arg_type
);
1999 arg
= value_from_pointer (arg_type
, sp
);
2000 pass_in_x_or_stack (gdbarch
, regcache
, &info
, arg_type
, arg
);
2003 /* PCS C.15 / C.18 multiple values pass. */
2004 pass_in_x_or_stack (gdbarch
, regcache
, &info
, arg_type
, arg
);
2008 pass_in_x_or_stack (gdbarch
, regcache
, &info
, arg_type
, arg
);
2013 /* Make sure stack retains 16 byte alignment. */
2015 sp
-= 16 - (info
.nsaa
& 15);
2017 while (!info
.si
.empty ())
2019 const stack_item_t
&si
= info
.si
.back ();
2022 if (si
.data
!= NULL
)
2023 write_memory (sp
, si
.data
, si
.len
);
2024 info
.si
.pop_back ();
2027 /* Finally, update the SP register. */
2028 regcache_cooked_write_unsigned (regcache
, AARCH64_SP_REGNUM
, sp
);
2033 /* Implement the "frame_align" gdbarch method. */
2036 aarch64_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
2038 /* Align the stack to sixteen bytes. */
2039 return sp
& ~(CORE_ADDR
) 15;
2042 /* Return the type for an AdvSISD Q register. */
2044 static struct type
*
2045 aarch64_vnq_type (struct gdbarch
*gdbarch
)
2047 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2049 if (tdep
->vnq_type
== NULL
)
2054 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnq",
2057 elem
= builtin_type (gdbarch
)->builtin_uint128
;
2058 append_composite_type_field (t
, "u", elem
);
2060 elem
= builtin_type (gdbarch
)->builtin_int128
;
2061 append_composite_type_field (t
, "s", elem
);
2066 return tdep
->vnq_type
;
2069 /* Return the type for an AdvSISD D register. */
2071 static struct type
*
2072 aarch64_vnd_type (struct gdbarch
*gdbarch
)
2074 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2076 if (tdep
->vnd_type
== NULL
)
2081 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnd",
2084 elem
= builtin_type (gdbarch
)->builtin_double
;
2085 append_composite_type_field (t
, "f", elem
);
2087 elem
= builtin_type (gdbarch
)->builtin_uint64
;
2088 append_composite_type_field (t
, "u", elem
);
2090 elem
= builtin_type (gdbarch
)->builtin_int64
;
2091 append_composite_type_field (t
, "s", elem
);
2096 return tdep
->vnd_type
;
2099 /* Return the type for an AdvSISD S register. */
2101 static struct type
*
2102 aarch64_vns_type (struct gdbarch
*gdbarch
)
2104 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2106 if (tdep
->vns_type
== NULL
)
2111 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vns",
2114 elem
= builtin_type (gdbarch
)->builtin_float
;
2115 append_composite_type_field (t
, "f", elem
);
2117 elem
= builtin_type (gdbarch
)->builtin_uint32
;
2118 append_composite_type_field (t
, "u", elem
);
2120 elem
= builtin_type (gdbarch
)->builtin_int32
;
2121 append_composite_type_field (t
, "s", elem
);
2126 return tdep
->vns_type
;
2129 /* Return the type for an AdvSISD H register. */
2131 static struct type
*
2132 aarch64_vnh_type (struct gdbarch
*gdbarch
)
2134 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2136 if (tdep
->vnh_type
== NULL
)
2141 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnh",
2144 elem
= builtin_type (gdbarch
)->builtin_bfloat16
;
2145 append_composite_type_field (t
, "bf", elem
);
2147 elem
= builtin_type (gdbarch
)->builtin_half
;
2148 append_composite_type_field (t
, "f", elem
);
2150 elem
= builtin_type (gdbarch
)->builtin_uint16
;
2151 append_composite_type_field (t
, "u", elem
);
2153 elem
= builtin_type (gdbarch
)->builtin_int16
;
2154 append_composite_type_field (t
, "s", elem
);
2159 return tdep
->vnh_type
;
2162 /* Return the type for an AdvSISD B register. */
2164 static struct type
*
2165 aarch64_vnb_type (struct gdbarch
*gdbarch
)
2167 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2169 if (tdep
->vnb_type
== NULL
)
2174 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnb",
2177 elem
= builtin_type (gdbarch
)->builtin_uint8
;
2178 append_composite_type_field (t
, "u", elem
);
2180 elem
= builtin_type (gdbarch
)->builtin_int8
;
2181 append_composite_type_field (t
, "s", elem
);
2186 return tdep
->vnb_type
;
2189 /* Return TRUE if REGNUM is a ZA tile slice pseudo-register number. Return
2193 is_sme_tile_slice_pseudo_register (struct gdbarch
*gdbarch
, int regnum
)
2195 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2197 gdb_assert (tdep
->has_sme ());
2198 gdb_assert (tdep
->sme_svq
> 0);
2199 gdb_assert (tdep
->sme_pseudo_base
<= regnum
);
2200 gdb_assert (regnum
< tdep
->sme_pseudo_base
+ tdep
->sme_pseudo_count
);
2202 if (tdep
->sme_tile_slice_pseudo_base
<= regnum
2203 && regnum
< tdep
->sme_tile_slice_pseudo_base
2204 + tdep
->sme_tile_slice_pseudo_count
)
2210 /* Given REGNUM, a ZA pseudo-register number, return, in ENCODING, the
2211 decoded fields that make up its name. */
2214 aarch64_za_decode_pseudos (struct gdbarch
*gdbarch
, int regnum
,
2215 struct za_pseudo_encoding
&encoding
)
2217 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2219 gdb_assert (tdep
->has_sme ());
2220 gdb_assert (tdep
->sme_svq
> 0);
2221 gdb_assert (tdep
->sme_pseudo_base
<= regnum
);
2222 gdb_assert (regnum
< tdep
->sme_pseudo_base
+ tdep
->sme_pseudo_count
);
2224 if (is_sme_tile_slice_pseudo_register (gdbarch
, regnum
))
2226 /* Calculate the tile slice pseudo-register offset relative to the other
2227 tile slice pseudo-registers. */
2228 int offset
= regnum
- tdep
->sme_tile_slice_pseudo_base
;
2230 /* Fetch the qualifier. We can have 160 to 2560 possible tile slice
2231 pseudo-registers. Each qualifier (we have 5 of them: B, H, S, D
2232 and Q) covers 32 * svq pseudo-registers, so we divide the offset by
2234 size_t qualifier
= offset
/ (tdep
->sme_svq
* 32);
2235 encoding
.qualifier_index
= qualifier
;
2237 /* Prepare to fetch the direction (d), tile number (t) and slice
2239 int dts
= offset
% (tdep
->sme_svq
* 32);
2241 /* The direction is represented by the even/odd numbers. Even-numbered
2242 pseudo-registers are horizontal tile slices and odd-numbered
2243 pseudo-registers are vertical tile slices. */
2244 encoding
.horizontal
= !(dts
& 1);
2246 /* Fetch the tile number. The tile number is closely related to the
2247 qualifier. B has 1 tile, H has 2 tiles, S has 4 tiles, D has 8 tiles
2248 and Q has 16 tiles. */
2249 encoding
.tile_index
= (dts
>> 1) & ((1 << qualifier
) - 1);
2251 /* Fetch the slice number. The slice number is closely related to the
2252 qualifier and the svl. */
2253 encoding
.slice_index
= dts
>> (qualifier
+ 1);
2257 /* Calculate the tile pseudo-register offset relative to the other
2258 tile pseudo-registers. */
2259 int offset
= regnum
- tdep
->sme_tile_pseudo_base
;
2261 encoding
.qualifier_index
= std::floor (std::log2 (offset
+ 1));
2262 /* Calculate the tile number. */
2263 encoding
.tile_index
= (offset
+ 1) - (1 << encoding
.qualifier_index
);
2264 /* Direction and slice index don't get used for tiles. Set them to
2266 encoding
.slice_index
= 0;
2267 encoding
.horizontal
= false;
2271 /* Return the type for a ZA tile slice pseudo-register based on ENCODING. */
2273 static struct type
*
2274 aarch64_za_tile_slice_type (struct gdbarch
*gdbarch
,
2275 const struct za_pseudo_encoding
&encoding
)
2277 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2279 gdb_assert (tdep
->has_sme ());
2280 gdb_assert (tdep
->sme_svq
> 0);
2282 if (tdep
->sme_tile_slice_type_q
== nullptr)
2284 /* Q tile slice type. */
2285 tdep
->sme_tile_slice_type_q
2286 = init_vector_type (builtin_type (gdbarch
)->builtin_uint128
,
2288 /* D tile slice type. */
2289 tdep
->sme_tile_slice_type_d
2290 = init_vector_type (builtin_type (gdbarch
)->builtin_uint64
,
2292 /* S tile slice type. */
2293 tdep
->sme_tile_slice_type_s
2294 = init_vector_type (builtin_type (gdbarch
)->builtin_uint32
,
2296 /* H tile slice type. */
2297 tdep
->sme_tile_slice_type_h
2298 = init_vector_type (builtin_type (gdbarch
)->builtin_uint16
,
2300 /* B tile slice type. */
2301 tdep
->sme_tile_slice_type_b
2302 = init_vector_type (builtin_type (gdbarch
)->builtin_uint8
,
2303 tdep
->sme_svq
* 16);
2306 switch (encoding
.qualifier_index
)
2309 return tdep
->sme_tile_slice_type_q
;
2311 return tdep
->sme_tile_slice_type_d
;
2313 return tdep
->sme_tile_slice_type_s
;
2315 return tdep
->sme_tile_slice_type_h
;
2317 return tdep
->sme_tile_slice_type_b
;
2319 error (_("Invalid qualifier index %s for tile slice pseudo register."),
2320 pulongest (encoding
.qualifier_index
));
2323 gdb_assert_not_reached ("Unknown qualifier for ZA tile slice register");
2326 /* Return the type for a ZA tile pseudo-register based on ENCODING. */
2328 static struct type
*
2329 aarch64_za_tile_type (struct gdbarch
*gdbarch
,
2330 const struct za_pseudo_encoding
&encoding
)
2332 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2334 gdb_assert (tdep
->has_sme ());
2335 gdb_assert (tdep
->sme_svq
> 0);
2337 if (tdep
->sme_tile_type_q
== nullptr)
2339 struct type
*inner_vectors_type
;
2343 = init_vector_type (builtin_type (gdbarch
)->builtin_uint128
,
2345 tdep
->sme_tile_type_q
2346 = init_vector_type (inner_vectors_type
, tdep
->sme_svq
);
2350 = init_vector_type (builtin_type (gdbarch
)->builtin_uint64
,
2352 tdep
->sme_tile_type_d
2353 = init_vector_type (inner_vectors_type
, tdep
->sme_svq
* 2);
2357 = init_vector_type (builtin_type (gdbarch
)->builtin_uint32
,
2359 tdep
->sme_tile_type_s
2360 = init_vector_type (inner_vectors_type
, tdep
->sme_svq
* 4);
2364 = init_vector_type (builtin_type (gdbarch
)->builtin_uint16
,
2366 tdep
->sme_tile_type_h
2367 = init_vector_type (inner_vectors_type
, tdep
->sme_svq
* 8);
2371 = init_vector_type (builtin_type (gdbarch
)->builtin_uint8
,
2372 tdep
->sme_svq
* 16);
2373 tdep
->sme_tile_type_b
2374 = init_vector_type (inner_vectors_type
, tdep
->sme_svq
* 16);
2377 switch (encoding
.qualifier_index
)
2380 return tdep
->sme_tile_type_q
;
2382 return tdep
->sme_tile_type_d
;
2384 return tdep
->sme_tile_type_s
;
2386 return tdep
->sme_tile_type_h
;
2388 return tdep
->sme_tile_type_b
;
2390 error (_("Invalid qualifier index %s for ZA tile pseudo register."),
2391 pulongest (encoding
.qualifier_index
));
2394 gdb_assert_not_reached ("unknown qualifier for tile pseudo-register");
2397 /* Return the type for an AdvSISD V register. */
2399 static struct type
*
2400 aarch64_vnv_type (struct gdbarch
*gdbarch
)
2402 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2404 if (tdep
->vnv_type
== NULL
)
2406 /* The other AArch64 pseudo registers (Q,D,H,S,B) refer to a single value
2407 slice from the non-pseudo vector registers. However NEON V registers
2408 are always vector registers, and need constructing as such. */
2409 const struct builtin_type
*bt
= builtin_type (gdbarch
);
2411 struct type
*t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnv",
2414 struct type
*sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnd",
2416 append_composite_type_field (sub
, "f",
2417 init_vector_type (bt
->builtin_double
, 2));
2418 append_composite_type_field (sub
, "u",
2419 init_vector_type (bt
->builtin_uint64
, 2));
2420 append_composite_type_field (sub
, "s",
2421 init_vector_type (bt
->builtin_int64
, 2));
2422 append_composite_type_field (t
, "d", sub
);
2424 sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vns",
2426 append_composite_type_field (sub
, "f",
2427 init_vector_type (bt
->builtin_float
, 4));
2428 append_composite_type_field (sub
, "u",
2429 init_vector_type (bt
->builtin_uint32
, 4));
2430 append_composite_type_field (sub
, "s",
2431 init_vector_type (bt
->builtin_int32
, 4));
2432 append_composite_type_field (t
, "s", sub
);
2434 sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnh",
2436 append_composite_type_field (sub
, "bf",
2437 init_vector_type (bt
->builtin_bfloat16
, 8));
2438 append_composite_type_field (sub
, "f",
2439 init_vector_type (bt
->builtin_half
, 8));
2440 append_composite_type_field (sub
, "u",
2441 init_vector_type (bt
->builtin_uint16
, 8));
2442 append_composite_type_field (sub
, "s",
2443 init_vector_type (bt
->builtin_int16
, 8));
2444 append_composite_type_field (t
, "h", sub
);
2446 sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnb",
2448 append_composite_type_field (sub
, "u",
2449 init_vector_type (bt
->builtin_uint8
, 16));
2450 append_composite_type_field (sub
, "s",
2451 init_vector_type (bt
->builtin_int8
, 16));
2452 append_composite_type_field (t
, "b", sub
);
2454 sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnq",
2456 append_composite_type_field (sub
, "u",
2457 init_vector_type (bt
->builtin_uint128
, 1));
2458 append_composite_type_field (sub
, "s",
2459 init_vector_type (bt
->builtin_int128
, 1));
2460 append_composite_type_field (t
, "q", sub
);
2465 return tdep
->vnv_type
;
2468 /* Implement the "dwarf2_reg_to_regnum" gdbarch method. */
2471 aarch64_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
2473 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2475 if (reg
>= AARCH64_DWARF_X0
&& reg
<= AARCH64_DWARF_X0
+ 30)
2476 return AARCH64_X0_REGNUM
+ reg
- AARCH64_DWARF_X0
;
2478 if (reg
== AARCH64_DWARF_SP
)
2479 return AARCH64_SP_REGNUM
;
2481 if (reg
== AARCH64_DWARF_PC
)
2482 return AARCH64_PC_REGNUM
;
2484 if (reg
>= AARCH64_DWARF_V0
&& reg
<= AARCH64_DWARF_V0
+ 31)
2485 return AARCH64_V0_REGNUM
+ reg
- AARCH64_DWARF_V0
;
2487 if (reg
== AARCH64_DWARF_SVE_VG
)
2488 return AARCH64_SVE_VG_REGNUM
;
2490 if (reg
== AARCH64_DWARF_SVE_FFR
)
2491 return AARCH64_SVE_FFR_REGNUM
;
2493 if (reg
>= AARCH64_DWARF_SVE_P0
&& reg
<= AARCH64_DWARF_SVE_P0
+ 15)
2494 return AARCH64_SVE_P0_REGNUM
+ reg
- AARCH64_DWARF_SVE_P0
;
2496 if (reg
>= AARCH64_DWARF_SVE_Z0
&& reg
<= AARCH64_DWARF_SVE_Z0
+ 15)
2497 return AARCH64_SVE_Z0_REGNUM
+ reg
- AARCH64_DWARF_SVE_Z0
;
2499 if (tdep
->has_pauth ())
2501 if (reg
== AARCH64_DWARF_RA_SIGN_STATE
)
2502 return tdep
->ra_sign_state_regnum
;
2508 /* Implement the "print_insn" gdbarch method. */
2511 aarch64_gdb_print_insn (bfd_vma memaddr
, disassemble_info
*info
)
2513 info
->symbols
= NULL
;
2514 return default_print_insn (memaddr
, info
);
2517 /* AArch64 BRK software debug mode instruction.
2518 Note that AArch64 code is always little-endian.
2519 1101.0100.0010.0000.0000.0000.0000.0000 = 0xd4200000. */
2520 constexpr gdb_byte aarch64_default_breakpoint
[] = {0x00, 0x00, 0x20, 0xd4};
2522 typedef BP_MANIPULATION (aarch64_default_breakpoint
) aarch64_breakpoint
;
2524 /* Extract from an array REGS containing the (raw) register state a
2525 function return value of type TYPE, and copy that, in virtual
2526 format, into VALBUF. */
2529 aarch64_extract_return_value (struct type
*type
, struct regcache
*regs
,
2532 struct gdbarch
*gdbarch
= regs
->arch ();
2533 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2535 struct type
*fundamental_type
;
2537 if (aapcs_is_vfp_call_or_return_candidate (type
, &elements
,
2540 int len
= fundamental_type
->length ();
2542 for (int i
= 0; i
< elements
; i
++)
2544 int regno
= AARCH64_V0_REGNUM
+ i
;
2545 /* Enough space for a full vector register. */
2546 gdb::byte_vector
buf (register_size (gdbarch
, regno
));
2547 gdb_assert (len
<= buf
.size ());
2549 aarch64_debug_printf
2550 ("read HFA or HVA return value element %d from %s",
2551 i
+ 1, gdbarch_register_name (gdbarch
, regno
));
2553 regs
->cooked_read (regno
, buf
);
2555 memcpy (valbuf
, buf
.data (), len
);
2559 else if (type
->code () == TYPE_CODE_INT
2560 || type
->code () == TYPE_CODE_CHAR
2561 || type
->code () == TYPE_CODE_BOOL
2562 || type
->code () == TYPE_CODE_PTR
2563 || TYPE_IS_REFERENCE (type
)
2564 || type
->code () == TYPE_CODE_ENUM
)
2566 /* If the type is a plain integer, then the access is
2567 straight-forward. Otherwise we have to play around a bit
2569 int len
= type
->length ();
2570 int regno
= AARCH64_X0_REGNUM
;
2575 /* By using store_unsigned_integer we avoid having to do
2576 anything special for small big-endian values. */
2577 regcache_cooked_read_unsigned (regs
, regno
++, &tmp
);
2578 store_unsigned_integer (valbuf
,
2579 (len
> X_REGISTER_SIZE
2580 ? X_REGISTER_SIZE
: len
), byte_order
, tmp
);
2581 len
-= X_REGISTER_SIZE
;
2582 valbuf
+= X_REGISTER_SIZE
;
2587 /* For a structure or union the behavior is as if the value had
2588 been stored to word-aligned memory and then loaded into
2589 registers with 64-bit load instruction(s). */
2590 int len
= type
->length ();
2591 int regno
= AARCH64_X0_REGNUM
;
2592 bfd_byte buf
[X_REGISTER_SIZE
];
2596 regs
->cooked_read (regno
++, buf
);
2597 memcpy (valbuf
, buf
, len
> X_REGISTER_SIZE
? X_REGISTER_SIZE
: len
);
2598 len
-= X_REGISTER_SIZE
;
2599 valbuf
+= X_REGISTER_SIZE
;
2605 /* Will a function return an aggregate type in memory or in a
2606 register? Return 0 if an aggregate type can be returned in a
2607 register, 1 if it must be returned in memory. */
2610 aarch64_return_in_memory (struct gdbarch
*gdbarch
, struct type
*type
)
2612 type
= check_typedef (type
);
2614 struct type
*fundamental_type
;
2616 if (TYPE_HAS_DYNAMIC_LENGTH (type
))
2619 if (aapcs_is_vfp_call_or_return_candidate (type
, &elements
,
2622 /* v0-v7 are used to return values and one register is allocated
2623 for one member. However, HFA or HVA has at most four members. */
2627 if (type
->length () > 16
2628 || !language_pass_by_reference (type
).trivially_copyable
)
2630 /* PCS B.6 Aggregates larger than 16 bytes are passed by
2631 invisible reference. */
2639 /* Write into appropriate registers a function return value of type
2640 TYPE, given in virtual format. */
2643 aarch64_store_return_value (struct type
*type
, struct regcache
*regs
,
2644 const gdb_byte
*valbuf
)
2646 struct gdbarch
*gdbarch
= regs
->arch ();
2647 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2649 struct type
*fundamental_type
;
2651 if (aapcs_is_vfp_call_or_return_candidate (type
, &elements
,
2654 int len
= fundamental_type
->length ();
2656 for (int i
= 0; i
< elements
; i
++)
2658 int regno
= AARCH64_V0_REGNUM
+ i
;
2659 /* Enough space for a full vector register. */
2660 gdb::byte_vector
tmpbuf (register_size (gdbarch
, regno
));
2661 gdb_assert (len
<= tmpbuf
.size ());
2663 aarch64_debug_printf
2664 ("write HFA or HVA return value element %d to %s",
2665 i
+ 1, gdbarch_register_name (gdbarch
, regno
));
2667 /* Depending on whether the target supports SVE or not, the V
2668 registers may report a size > 16 bytes. In that case, read the
2669 original contents of the register before overriding it with a new
2670 value that has a potential size <= 16 bytes. */
2671 regs
->cooked_read (regno
, tmpbuf
);
2672 memcpy (tmpbuf
.data (), valbuf
,
2673 len
> V_REGISTER_SIZE
? V_REGISTER_SIZE
: len
);
2674 regs
->cooked_write (regno
, tmpbuf
);
2678 else if (type
->code () == TYPE_CODE_INT
2679 || type
->code () == TYPE_CODE_CHAR
2680 || type
->code () == TYPE_CODE_BOOL
2681 || type
->code () == TYPE_CODE_PTR
2682 || TYPE_IS_REFERENCE (type
)
2683 || type
->code () == TYPE_CODE_ENUM
)
2685 if (type
->length () <= X_REGISTER_SIZE
)
2687 /* Values of one word or less are zero/sign-extended and
2689 bfd_byte tmpbuf
[X_REGISTER_SIZE
];
2690 LONGEST val
= unpack_long (type
, valbuf
);
2692 store_signed_integer (tmpbuf
, X_REGISTER_SIZE
, byte_order
, val
);
2693 regs
->cooked_write (AARCH64_X0_REGNUM
, tmpbuf
);
2697 /* Integral values greater than one word are stored in
2698 consecutive registers starting with r0. This will always
2699 be a multiple of the register size. */
2700 int len
= type
->length ();
2701 int regno
= AARCH64_X0_REGNUM
;
2705 regs
->cooked_write (regno
++, valbuf
);
2706 len
-= X_REGISTER_SIZE
;
2707 valbuf
+= X_REGISTER_SIZE
;
2713 /* For a structure or union the behavior is as if the value had
2714 been stored to word-aligned memory and then loaded into
2715 registers with 64-bit load instruction(s). */
2716 int len
= type
->length ();
2717 int regno
= AARCH64_X0_REGNUM
;
2718 bfd_byte tmpbuf
[X_REGISTER_SIZE
];
2722 memcpy (tmpbuf
, valbuf
,
2723 len
> X_REGISTER_SIZE
? X_REGISTER_SIZE
: len
);
2724 regs
->cooked_write (regno
++, tmpbuf
);
2725 len
-= X_REGISTER_SIZE
;
2726 valbuf
+= X_REGISTER_SIZE
;
2731 /* Implement the "return_value" gdbarch method. */
2733 static enum return_value_convention
2734 aarch64_return_value (struct gdbarch
*gdbarch
, struct value
*func_value
,
2735 struct type
*valtype
, struct regcache
*regcache
,
2736 struct value
**read_value
, const gdb_byte
*writebuf
)
2738 if (valtype
->code () == TYPE_CODE_STRUCT
2739 || valtype
->code () == TYPE_CODE_UNION
2740 || valtype
->code () == TYPE_CODE_ARRAY
)
2742 if (aarch64_return_in_memory (gdbarch
, valtype
))
2744 /* From the AAPCS64's Result Return section:
2746 "Otherwise, the caller shall reserve a block of memory of
2747 sufficient size and alignment to hold the result. The address
2748 of the memory block shall be passed as an additional argument to
2749 the function in x8. */
2751 aarch64_debug_printf ("return value in memory");
2753 if (read_value
!= nullptr)
2757 regcache
->cooked_read (AARCH64_STRUCT_RETURN_REGNUM
, &addr
);
2758 *read_value
= value_at_non_lval (valtype
, addr
);
2761 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
2766 aarch64_store_return_value (valtype
, regcache
, writebuf
);
2770 *read_value
= value::allocate (valtype
);
2771 aarch64_extract_return_value (valtype
, regcache
,
2772 (*read_value
)->contents_raw ().data ());
2775 aarch64_debug_printf ("return value in registers");
2777 return RETURN_VALUE_REGISTER_CONVENTION
;
2780 /* Implement the "get_longjmp_target" gdbarch method. */
2783 aarch64_get_longjmp_target (const frame_info_ptr
&frame
, CORE_ADDR
*pc
)
2786 gdb_byte buf
[X_REGISTER_SIZE
];
2787 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2788 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2789 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2791 jb_addr
= get_frame_register_unsigned (frame
, AARCH64_X0_REGNUM
);
2793 if (target_read_memory (jb_addr
+ tdep
->jb_pc
* tdep
->jb_elt_size
, buf
,
2797 *pc
= extract_unsigned_integer (buf
, X_REGISTER_SIZE
, byte_order
);
2801 /* Implement the "gen_return_address" gdbarch method. */
2804 aarch64_gen_return_address (struct gdbarch
*gdbarch
,
2805 struct agent_expr
*ax
, struct axs_value
*value
,
2808 value
->type
= register_type (gdbarch
, AARCH64_LR_REGNUM
);
2809 value
->kind
= axs_lvalue_register
;
2810 value
->u
.reg
= AARCH64_LR_REGNUM
;
2814 /* Return TRUE if REGNUM is a W pseudo-register number. Return FALSE
2818 is_w_pseudo_register (struct gdbarch
*gdbarch
, int regnum
)
2820 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2822 if (tdep
->w_pseudo_base
<= regnum
2823 && regnum
< tdep
->w_pseudo_base
+ tdep
->w_pseudo_count
)
2829 /* Return TRUE if REGNUM is a SME pseudo-register number. Return FALSE
2833 is_sme_pseudo_register (struct gdbarch
*gdbarch
, int regnum
)
2835 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2837 if (tdep
->has_sme () && tdep
->sme_pseudo_base
<= regnum
2838 && regnum
< tdep
->sme_pseudo_base
+ tdep
->sme_pseudo_count
)
2844 /* Convert ENCODING into a ZA tile slice name. */
2846 static const std::string
2847 aarch64_za_tile_slice_name (const struct za_pseudo_encoding
&encoding
)
2849 gdb_assert (encoding
.qualifier_index
>= 0);
2850 gdb_assert (encoding
.qualifier_index
<= 4);
2851 gdb_assert (encoding
.tile_index
>= 0);
2852 gdb_assert (encoding
.tile_index
<= 15);
2853 gdb_assert (encoding
.slice_index
>= 0);
2854 gdb_assert (encoding
.slice_index
<= 255);
2856 const char orientation
= encoding
.horizontal
? 'h' : 'v';
2858 const char qualifiers
[6] = "bhsdq";
2859 const char qualifier
= qualifiers
[encoding
.qualifier_index
];
2860 return string_printf ("za%d%c%c%d", encoding
.tile_index
, orientation
,
2861 qualifier
, encoding
.slice_index
);
2864 /* Convert ENCODING into a ZA tile name. */
2866 static const std::string
2867 aarch64_za_tile_name (const struct za_pseudo_encoding
&encoding
)
2869 /* Tiles don't use the slice number and the direction fields. */
2870 gdb_assert (encoding
.qualifier_index
>= 0);
2871 gdb_assert (encoding
.qualifier_index
<= 4);
2872 gdb_assert (encoding
.tile_index
>= 0);
2873 gdb_assert (encoding
.tile_index
<= 15);
2875 const char qualifiers
[6] = "bhsdq";
2876 const char qualifier
= qualifiers
[encoding
.qualifier_index
];
2877 return (string_printf ("za%d%c", encoding
.tile_index
, qualifier
));
2880 /* Given a SME pseudo-register REGNUM, return its type. */
2882 static struct type
*
2883 aarch64_sme_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
2885 struct za_pseudo_encoding encoding
;
2887 /* Decode the SME pseudo-register number. */
2888 aarch64_za_decode_pseudos (gdbarch
, regnum
, encoding
);
2890 if (is_sme_tile_slice_pseudo_register (gdbarch
, regnum
))
2891 return aarch64_za_tile_slice_type (gdbarch
, encoding
);
2893 return aarch64_za_tile_type (gdbarch
, encoding
);
2896 /* Return the pseudo register name corresponding to register regnum. */
2899 aarch64_pseudo_register_name (struct gdbarch
*gdbarch
, int regnum
)
2901 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2903 /* W pseudo-registers. Bottom halves of the X registers. */
2904 static const char *const w_name
[] =
2906 "w0", "w1", "w2", "w3",
2907 "w4", "w5", "w6", "w7",
2908 "w8", "w9", "w10", "w11",
2909 "w12", "w13", "w14", "w15",
2910 "w16", "w17", "w18", "w19",
2911 "w20", "w21", "w22", "w23",
2912 "w24", "w25", "w26", "w27",
2913 "w28", "w29", "w30",
2916 static const char *const q_name
[] =
2918 "q0", "q1", "q2", "q3",
2919 "q4", "q5", "q6", "q7",
2920 "q8", "q9", "q10", "q11",
2921 "q12", "q13", "q14", "q15",
2922 "q16", "q17", "q18", "q19",
2923 "q20", "q21", "q22", "q23",
2924 "q24", "q25", "q26", "q27",
2925 "q28", "q29", "q30", "q31",
2928 static const char *const d_name
[] =
2930 "d0", "d1", "d2", "d3",
2931 "d4", "d5", "d6", "d7",
2932 "d8", "d9", "d10", "d11",
2933 "d12", "d13", "d14", "d15",
2934 "d16", "d17", "d18", "d19",
2935 "d20", "d21", "d22", "d23",
2936 "d24", "d25", "d26", "d27",
2937 "d28", "d29", "d30", "d31",
2940 static const char *const s_name
[] =
2942 "s0", "s1", "s2", "s3",
2943 "s4", "s5", "s6", "s7",
2944 "s8", "s9", "s10", "s11",
2945 "s12", "s13", "s14", "s15",
2946 "s16", "s17", "s18", "s19",
2947 "s20", "s21", "s22", "s23",
2948 "s24", "s25", "s26", "s27",
2949 "s28", "s29", "s30", "s31",
2952 static const char *const h_name
[] =
2954 "h0", "h1", "h2", "h3",
2955 "h4", "h5", "h6", "h7",
2956 "h8", "h9", "h10", "h11",
2957 "h12", "h13", "h14", "h15",
2958 "h16", "h17", "h18", "h19",
2959 "h20", "h21", "h22", "h23",
2960 "h24", "h25", "h26", "h27",
2961 "h28", "h29", "h30", "h31",
2964 static const char *const b_name
[] =
2966 "b0", "b1", "b2", "b3",
2967 "b4", "b5", "b6", "b7",
2968 "b8", "b9", "b10", "b11",
2969 "b12", "b13", "b14", "b15",
2970 "b16", "b17", "b18", "b19",
2971 "b20", "b21", "b22", "b23",
2972 "b24", "b25", "b26", "b27",
2973 "b28", "b29", "b30", "b31",
2976 int p_regnum
= regnum
- gdbarch_num_regs (gdbarch
);
2978 if (p_regnum
>= AARCH64_Q0_REGNUM
&& p_regnum
< AARCH64_Q0_REGNUM
+ 32)
2979 return q_name
[p_regnum
- AARCH64_Q0_REGNUM
];
2981 if (p_regnum
>= AARCH64_D0_REGNUM
&& p_regnum
< AARCH64_D0_REGNUM
+ 32)
2982 return d_name
[p_regnum
- AARCH64_D0_REGNUM
];
2984 if (p_regnum
>= AARCH64_S0_REGNUM
&& p_regnum
< AARCH64_S0_REGNUM
+ 32)
2985 return s_name
[p_regnum
- AARCH64_S0_REGNUM
];
2987 if (p_regnum
>= AARCH64_H0_REGNUM
&& p_regnum
< AARCH64_H0_REGNUM
+ 32)
2988 return h_name
[p_regnum
- AARCH64_H0_REGNUM
];
2990 if (p_regnum
>= AARCH64_B0_REGNUM
&& p_regnum
< AARCH64_B0_REGNUM
+ 32)
2991 return b_name
[p_regnum
- AARCH64_B0_REGNUM
];
2993 /* W pseudo-registers? */
2994 if (is_w_pseudo_register (gdbarch
, regnum
))
2995 return w_name
[regnum
- tdep
->w_pseudo_base
];
2997 if (tdep
->has_sve ())
2999 static const char *const sve_v_name
[] =
3001 "v0", "v1", "v2", "v3",
3002 "v4", "v5", "v6", "v7",
3003 "v8", "v9", "v10", "v11",
3004 "v12", "v13", "v14", "v15",
3005 "v16", "v17", "v18", "v19",
3006 "v20", "v21", "v22", "v23",
3007 "v24", "v25", "v26", "v27",
3008 "v28", "v29", "v30", "v31",
3011 if (p_regnum
>= AARCH64_SVE_V0_REGNUM
3012 && p_regnum
< AARCH64_SVE_V0_REGNUM
+ AARCH64_V_REGS_NUM
)
3013 return sve_v_name
[p_regnum
- AARCH64_SVE_V0_REGNUM
];
3016 if (is_sme_pseudo_register (gdbarch
, regnum
))
3017 return tdep
->sme_pseudo_names
[regnum
- tdep
->sme_pseudo_base
].c_str ();
3019 /* RA_STATE is used for unwinding only. Do not assign it a name - this
3020 prevents it from being read by methods such as
3021 mi_cmd_trace_frame_collected. */
3022 if (tdep
->has_pauth () && regnum
== tdep
->ra_sign_state_regnum
)
3025 internal_error (_("aarch64_pseudo_register_name: bad register number %d"),
3029 /* Implement the "pseudo_register_type" tdesc_arch_data method. */
3031 static struct type
*
3032 aarch64_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
3034 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3036 int p_regnum
= regnum
- gdbarch_num_regs (gdbarch
);
3038 if (p_regnum
>= AARCH64_Q0_REGNUM
&& p_regnum
< AARCH64_Q0_REGNUM
+ 32)
3039 return aarch64_vnq_type (gdbarch
);
3041 if (p_regnum
>= AARCH64_D0_REGNUM
&& p_regnum
< AARCH64_D0_REGNUM
+ 32)
3042 return aarch64_vnd_type (gdbarch
);
3044 if (p_regnum
>= AARCH64_S0_REGNUM
&& p_regnum
< AARCH64_S0_REGNUM
+ 32)
3045 return aarch64_vns_type (gdbarch
);
3047 if (p_regnum
>= AARCH64_H0_REGNUM
&& p_regnum
< AARCH64_H0_REGNUM
+ 32)
3048 return aarch64_vnh_type (gdbarch
);
3050 if (p_regnum
>= AARCH64_B0_REGNUM
&& p_regnum
< AARCH64_B0_REGNUM
+ 32)
3051 return aarch64_vnb_type (gdbarch
);
3053 if (tdep
->has_sve () && p_regnum
>= AARCH64_SVE_V0_REGNUM
3054 && p_regnum
< AARCH64_SVE_V0_REGNUM
+ AARCH64_V_REGS_NUM
)
3055 return aarch64_vnv_type (gdbarch
);
3057 /* W pseudo-registers are 32-bit. */
3058 if (is_w_pseudo_register (gdbarch
, regnum
))
3059 return builtin_type (gdbarch
)->builtin_uint32
;
3061 if (is_sme_pseudo_register (gdbarch
, regnum
))
3062 return aarch64_sme_pseudo_register_type (gdbarch
, regnum
);
3064 if (tdep
->has_pauth () && regnum
== tdep
->ra_sign_state_regnum
)
3065 return builtin_type (gdbarch
)->builtin_uint64
;
3067 internal_error (_("aarch64_pseudo_register_type: bad register number %d"),
3071 /* Implement the "pseudo_register_reggroup_p" tdesc_arch_data method. */
3074 aarch64_pseudo_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
3075 const struct reggroup
*group
)
3077 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3079 int p_regnum
= regnum
- gdbarch_num_regs (gdbarch
);
3081 if (p_regnum
>= AARCH64_Q0_REGNUM
&& p_regnum
< AARCH64_Q0_REGNUM
+ 32)
3082 return group
== all_reggroup
|| group
== vector_reggroup
;
3083 else if (p_regnum
>= AARCH64_D0_REGNUM
&& p_regnum
< AARCH64_D0_REGNUM
+ 32)
3084 return (group
== all_reggroup
|| group
== vector_reggroup
3085 || group
== float_reggroup
);
3086 else if (p_regnum
>= AARCH64_S0_REGNUM
&& p_regnum
< AARCH64_S0_REGNUM
+ 32)
3087 return (group
== all_reggroup
|| group
== vector_reggroup
3088 || group
== float_reggroup
);
3089 else if (p_regnum
>= AARCH64_H0_REGNUM
&& p_regnum
< AARCH64_H0_REGNUM
+ 32)
3090 return group
== all_reggroup
|| group
== vector_reggroup
;
3091 else if (p_regnum
>= AARCH64_B0_REGNUM
&& p_regnum
< AARCH64_B0_REGNUM
+ 32)
3092 return group
== all_reggroup
|| group
== vector_reggroup
;
3093 else if (tdep
->has_sve () && p_regnum
>= AARCH64_SVE_V0_REGNUM
3094 && p_regnum
< AARCH64_SVE_V0_REGNUM
+ AARCH64_V_REGS_NUM
)
3095 return group
== all_reggroup
|| group
== vector_reggroup
;
3096 else if (is_sme_pseudo_register (gdbarch
, regnum
))
3097 return group
== all_reggroup
|| group
== vector_reggroup
;
3098 /* RA_STATE is used for unwinding only. Do not assign it to any groups. */
3099 if (tdep
->has_pauth () && regnum
== tdep
->ra_sign_state_regnum
)
3102 return group
== all_reggroup
;
3105 /* Helper for aarch64_pseudo_read_value. */
3108 aarch64_pseudo_read_value_1 (const frame_info_ptr
&next_frame
,
3109 const int pseudo_reg_num
, int raw_regnum_offset
)
3111 unsigned v_regnum
= AARCH64_V0_REGNUM
+ raw_regnum_offset
;
3113 return pseudo_from_raw_part (next_frame
, pseudo_reg_num
, v_regnum
, 0);
3116 /* Helper function for reading/writing ZA pseudo-registers. Given REGNUM,
3117 a ZA pseudo-register number, return the information on positioning of the
3118 bytes that must be read from/written to. */
3121 aarch64_za_offsets_from_regnum (struct gdbarch
*gdbarch
, int regnum
)
3123 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3125 gdb_assert (tdep
->has_sme ());
3126 gdb_assert (tdep
->sme_svq
> 0);
3127 gdb_assert (tdep
->sme_pseudo_base
<= regnum
);
3128 gdb_assert (regnum
< tdep
->sme_pseudo_base
+ tdep
->sme_pseudo_count
);
3130 struct za_pseudo_encoding encoding
;
3132 /* Decode the ZA pseudo-register number. */
3133 aarch64_za_decode_pseudos (gdbarch
, regnum
, encoding
);
3135 /* Fetch the streaming vector length. */
3136 size_t svl
= sve_vl_from_vq (tdep
->sme_svq
);
3139 if (is_sme_tile_slice_pseudo_register (gdbarch
, regnum
))
3141 if (encoding
.horizontal
)
3143 /* Horizontal tile slices are contiguous ranges of svl bytes. */
3145 /* The starting offset depends on the tile index (to locate the tile
3146 in the ZA buffer), the slice index (to locate the slice within the
3147 tile) and the qualifier. */
3148 offsets
.starting_offset
3149 = encoding
.tile_index
* svl
+ encoding
.slice_index
3150 * (svl
>> encoding
.qualifier_index
);
3151 /* Horizontal tile slice data is contiguous and thus doesn't have
3153 offsets
.stride_size
= 0;
3154 /* Horizontal tile slice data is contiguous and thus only has 1
3157 /* The chunk size is always svl bytes. */
3158 offsets
.chunk_size
= svl
;
3162 /* Vertical tile slices are non-contiguous ranges of
3163 (1 << qualifier_index) bytes. */
3165 /* The starting offset depends on the tile number (to locate the
3166 tile in the ZA buffer), the slice index (to locate the element
3167 within the tile slice) and the qualifier. */
3168 offsets
.starting_offset
3169 = encoding
.tile_index
* svl
+ encoding
.slice_index
3170 * (1 << encoding
.qualifier_index
);
3171 /* The offset between vertical tile slices depends on the qualifier
3173 offsets
.stride_size
= svl
<< encoding
.qualifier_index
;
3174 /* The number of chunks depends on svl and the qualifier size. */
3175 offsets
.chunks
= svl
>> encoding
.qualifier_index
;
3176 /* The chunk size depends on the qualifier. */
3177 offsets
.chunk_size
= 1 << encoding
.qualifier_index
;
3182 /* ZA tile pseudo-register. */
3184 /* Starting offset depends on the tile index and qualifier. */
3185 offsets
.starting_offset
= encoding
.tile_index
* svl
;
3186 /* The offset between tile slices depends on the qualifier and svl. */
3187 offsets
.stride_size
= svl
<< encoding
.qualifier_index
;
3188 /* The number of chunks depends on the qualifier and svl. */
3189 offsets
.chunks
= svl
>> encoding
.qualifier_index
;
3190 /* The chunk size is always svl bytes. */
3191 offsets
.chunk_size
= svl
;
3197 /* Given REGNUM, a SME pseudo-register number, return its value in RESULT. */
3200 aarch64_sme_pseudo_register_read (gdbarch
*gdbarch
, const frame_info_ptr
&next_frame
,
3201 const int pseudo_reg_num
)
3203 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3205 gdb_assert (tdep
->has_sme ());
3206 gdb_assert (tdep
->sme_svq
> 0);
3207 gdb_assert (tdep
->sme_pseudo_base
<= pseudo_reg_num
);
3208 gdb_assert (pseudo_reg_num
< tdep
->sme_pseudo_base
+ tdep
->sme_pseudo_count
);
3210 /* Fetch the offsets that we need in order to read from the correct blocks
3213 = aarch64_za_offsets_from_regnum (gdbarch
, pseudo_reg_num
);
3215 /* Fetch the contents of ZA. */
3216 value
*za_value
= value_of_register (tdep
->sme_za_regnum
, next_frame
);
3217 value
*result
= value::allocate_register (next_frame
, pseudo_reg_num
);
3219 /* Copy the requested data. */
3220 for (int chunks
= 0; chunks
< offsets
.chunks
; chunks
++)
3222 int src_offset
= offsets
.starting_offset
+ chunks
* offsets
.stride_size
;
3223 int dst_offset
= chunks
* offsets
.chunk_size
;
3224 za_value
->contents_copy (result
, dst_offset
, src_offset
,
3225 offsets
.chunk_size
);
3231 /* Implement the "pseudo_register_read_value" gdbarch method. */
3234 aarch64_pseudo_read_value (gdbarch
*gdbarch
, const frame_info_ptr
&next_frame
,
3235 const int pseudo_reg_num
)
3237 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3239 if (is_w_pseudo_register (gdbarch
, pseudo_reg_num
))
3241 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3242 /* Default offset for little endian. */
3245 if (byte_order
== BFD_ENDIAN_BIG
)
3248 /* Find the correct X register to extract the data from. */
3250 = AARCH64_X0_REGNUM
+ (pseudo_reg_num
- tdep
->w_pseudo_base
);
3252 /* Read the bottom 4 bytes of X. */
3253 return pseudo_from_raw_part (next_frame
, pseudo_reg_num
, x_regnum
,
3256 else if (is_sme_pseudo_register (gdbarch
, pseudo_reg_num
))
3257 return aarch64_sme_pseudo_register_read (gdbarch
, next_frame
,
3260 /* Offset in the "pseudo-register space". */
3261 int pseudo_offset
= pseudo_reg_num
- gdbarch_num_regs (gdbarch
);
3263 if (pseudo_offset
>= AARCH64_Q0_REGNUM
3264 && pseudo_offset
< AARCH64_Q0_REGNUM
+ 32)
3265 return aarch64_pseudo_read_value_1 (next_frame
, pseudo_reg_num
,
3266 pseudo_offset
- AARCH64_Q0_REGNUM
);
3268 if (pseudo_offset
>= AARCH64_D0_REGNUM
3269 && pseudo_offset
< AARCH64_D0_REGNUM
+ 32)
3270 return aarch64_pseudo_read_value_1 (next_frame
, pseudo_reg_num
,
3271 pseudo_offset
- AARCH64_D0_REGNUM
);
3273 if (pseudo_offset
>= AARCH64_S0_REGNUM
3274 && pseudo_offset
< AARCH64_S0_REGNUM
+ 32)
3275 return aarch64_pseudo_read_value_1 (next_frame
, pseudo_reg_num
,
3276 pseudo_offset
- AARCH64_S0_REGNUM
);
3278 if (pseudo_offset
>= AARCH64_H0_REGNUM
3279 && pseudo_offset
< AARCH64_H0_REGNUM
+ 32)
3280 return aarch64_pseudo_read_value_1 (next_frame
, pseudo_reg_num
,
3281 pseudo_offset
- AARCH64_H0_REGNUM
);
3283 if (pseudo_offset
>= AARCH64_B0_REGNUM
3284 && pseudo_offset
< AARCH64_B0_REGNUM
+ 32)
3285 return aarch64_pseudo_read_value_1 (next_frame
, pseudo_reg_num
,
3286 pseudo_offset
- AARCH64_B0_REGNUM
);
3288 if (tdep
->has_sve () && pseudo_offset
>= AARCH64_SVE_V0_REGNUM
3289 && pseudo_offset
< AARCH64_SVE_V0_REGNUM
+ 32)
3290 return aarch64_pseudo_read_value_1 (next_frame
, pseudo_reg_num
,
3291 pseudo_offset
- AARCH64_SVE_V0_REGNUM
);
3293 if (tdep
->has_pauth () && pseudo_reg_num
== tdep
->ra_sign_state_regnum
)
3294 return value::zero (builtin_type (gdbarch
)->builtin_uint64
, lval_register
);
3296 gdb_assert_not_reached ("regnum out of bound");
3299 /* Helper for aarch64_pseudo_write. */
3302 aarch64_pseudo_write_1 (gdbarch
*gdbarch
, const frame_info_ptr
&next_frame
,
3304 gdb::array_view
<const gdb_byte
> buf
)
3306 unsigned raw_regnum
= AARCH64_V0_REGNUM
+ regnum_offset
;
3308 /* Enough space for a full vector register.
3310 Ensure the register buffer is zero, we want gdb writes of the
3311 various 'scalar' pseudo registers to behavior like architectural
3312 writes, register width bytes are written the remainder are set to
3314 gdb::byte_vector
raw_buf (register_size (gdbarch
, raw_regnum
), 0);
3315 static_assert (AARCH64_V0_REGNUM
== AARCH64_SVE_Z0_REGNUM
);
3317 gdb::array_view
<gdb_byte
> raw_view (raw_buf
);
3318 copy (buf
, raw_view
.slice (0, buf
.size ()));
3319 put_frame_register (next_frame
, raw_regnum
, raw_view
);
3322 /* Given REGNUM, a SME pseudo-register number, store the bytes from DATA to the
3326 aarch64_sme_pseudo_register_write (gdbarch
*gdbarch
, const frame_info_ptr
&next_frame
,
3328 gdb::array_view
<const gdb_byte
> data
)
3330 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3332 gdb_assert (tdep
->has_sme ());
3333 gdb_assert (tdep
->sme_svq
> 0);
3334 gdb_assert (tdep
->sme_pseudo_base
<= regnum
);
3335 gdb_assert (regnum
< tdep
->sme_pseudo_base
+ tdep
->sme_pseudo_count
);
3337 /* Fetch the offsets that we need in order to write to the correct blocks
3339 za_offsets offsets
= aarch64_za_offsets_from_regnum (gdbarch
, regnum
);
3341 /* Fetch the contents of ZA. */
3342 value
*za_value
= value_of_register (tdep
->sme_za_regnum
, next_frame
);
3345 /* Create a view only on the portion of za we want to write. */
3346 gdb::array_view
<gdb_byte
> za_view
3347 = za_value
->contents_writeable ().slice (offsets
.starting_offset
);
3349 /* Copy the requested data. */
3350 for (int chunks
= 0; chunks
< offsets
.chunks
; chunks
++)
3352 gdb::array_view
<const gdb_byte
> src
3353 = data
.slice (chunks
* offsets
.chunk_size
, offsets
.chunk_size
);
3354 gdb::array_view
<gdb_byte
> dst
3355 = za_view
.slice (chunks
* offsets
.stride_size
, offsets
.chunk_size
);
3360 /* Write back to ZA. */
3361 put_frame_register (next_frame
, tdep
->sme_za_regnum
,
3362 za_value
->contents_raw ());
3365 /* Implement the "pseudo_register_write" gdbarch method. */
3368 aarch64_pseudo_write (gdbarch
*gdbarch
, const frame_info_ptr
&next_frame
,
3369 const int pseudo_reg_num
,
3370 gdb::array_view
<const gdb_byte
> buf
)
3372 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3374 if (is_w_pseudo_register (gdbarch
, pseudo_reg_num
))
3376 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
3377 /* Default offset for little endian. */
3380 if (byte_order
== BFD_ENDIAN_BIG
)
3383 /* Find the correct X register to extract the data from. */
3384 int x_regnum
= AARCH64_X0_REGNUM
+ (pseudo_reg_num
- tdep
->w_pseudo_base
);
3386 /* First zero-out the contents of X. */
3387 gdb_byte bytes
[8] {};
3388 gdb::array_view
<gdb_byte
> bytes_view (bytes
);
3389 copy (buf
, bytes_view
.slice (offset
, 4));
3391 /* Write to the bottom 4 bytes of X. */
3392 put_frame_register (next_frame
, x_regnum
, bytes_view
);
3395 else if (is_sme_pseudo_register (gdbarch
, pseudo_reg_num
))
3397 aarch64_sme_pseudo_register_write (gdbarch
, next_frame
, pseudo_reg_num
,
3402 /* Offset in the "pseudo-register space". */
3403 int pseudo_offset
= pseudo_reg_num
- gdbarch_num_regs (gdbarch
);
3405 if (pseudo_offset
>= AARCH64_Q0_REGNUM
3406 && pseudo_offset
< AARCH64_Q0_REGNUM
+ 32)
3407 return aarch64_pseudo_write_1 (gdbarch
, next_frame
,
3408 pseudo_offset
- AARCH64_Q0_REGNUM
, buf
);
3410 if (pseudo_offset
>= AARCH64_D0_REGNUM
3411 && pseudo_offset
< AARCH64_D0_REGNUM
+ 32)
3412 return aarch64_pseudo_write_1 (gdbarch
, next_frame
,
3413 pseudo_offset
- AARCH64_D0_REGNUM
, buf
);
3415 if (pseudo_offset
>= AARCH64_S0_REGNUM
3416 && pseudo_offset
< AARCH64_S0_REGNUM
+ 32)
3417 return aarch64_pseudo_write_1 (gdbarch
, next_frame
,
3418 pseudo_offset
- AARCH64_S0_REGNUM
, buf
);
3420 if (pseudo_offset
>= AARCH64_H0_REGNUM
3421 && pseudo_offset
< AARCH64_H0_REGNUM
+ 32)
3422 return aarch64_pseudo_write_1 (gdbarch
, next_frame
,
3423 pseudo_offset
- AARCH64_H0_REGNUM
, buf
);
3425 if (pseudo_offset
>= AARCH64_B0_REGNUM
3426 && pseudo_offset
< AARCH64_B0_REGNUM
+ 32)
3427 return aarch64_pseudo_write_1 (gdbarch
, next_frame
,
3428 pseudo_offset
- AARCH64_B0_REGNUM
, buf
);
3430 if (tdep
->has_sve () && pseudo_offset
>= AARCH64_SVE_V0_REGNUM
3431 && pseudo_offset
< AARCH64_SVE_V0_REGNUM
+ 32)
3432 return aarch64_pseudo_write_1 (gdbarch
, next_frame
,
3433 pseudo_offset
- AARCH64_SVE_V0_REGNUM
, buf
);
3435 gdb_assert_not_reached ("regnum out of bound");
3438 /* Callback function for user_reg_add. */
3440 static struct value
*
3441 value_of_aarch64_user_reg (const frame_info_ptr
&frame
, const void *baton
)
3443 const int *reg_p
= (const int *) baton
;
3445 return value_of_register (*reg_p
, get_next_frame_sentinel_okay (frame
));
3448 /* Implement the "software_single_step" gdbarch method, needed to
3449 single step through atomic sequences on AArch64. */
3451 static std::vector
<CORE_ADDR
>
3452 aarch64_software_single_step (struct regcache
*regcache
)
3454 struct gdbarch
*gdbarch
= regcache
->arch ();
3455 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
3456 const int insn_size
= 4;
3457 const int atomic_sequence_length
= 16; /* Instruction sequence length. */
3458 CORE_ADDR pc
= regcache_read_pc (regcache
);
3459 CORE_ADDR breaks
[2] = { CORE_ADDR_MAX
, CORE_ADDR_MAX
};
3461 CORE_ADDR closing_insn
= 0;
3463 ULONGEST insn_from_memory
;
3464 if (!safe_read_memory_unsigned_integer (loc
, insn_size
,
3465 byte_order_for_code
,
3468 /* Assume we don't have a atomic sequence, as we couldn't read the
3469 instruction in this location. */
3473 uint32_t insn
= insn_from_memory
;
3476 int bc_insn_count
= 0; /* Conditional branch instruction count. */
3477 int last_breakpoint
= 0; /* Defaults to 0 (no breakpoints placed). */
3480 if (aarch64_decode_insn (insn
, &inst
, 1, NULL
) != 0)
3483 /* Look for a Load Exclusive instruction which begins the sequence. */
3484 if (inst
.opcode
->iclass
!= ldstexcl
|| bit (insn
, 22) == 0)
3487 for (insn_count
= 0; insn_count
< atomic_sequence_length
; ++insn_count
)
3491 if (!safe_read_memory_unsigned_integer (loc
, insn_size
,
3492 byte_order_for_code
,
3495 /* Assume we don't have a atomic sequence, as we couldn't read the
3496 instruction in this location. */
3500 insn
= insn_from_memory
;
3501 if (aarch64_decode_insn (insn
, &inst
, 1, NULL
) != 0)
3503 /* Check if the instruction is a conditional branch. */
3504 if (inst
.opcode
->iclass
== condbranch
)
3506 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_ADDR_PCREL19
);
3508 if (bc_insn_count
>= 1)
3511 /* It is, so we'll try to set a breakpoint at the destination. */
3512 breaks
[1] = loc
+ inst
.operands
[0].imm
.value
;
3518 /* Look for the Store Exclusive which closes the atomic sequence. */
3519 if (inst
.opcode
->iclass
== ldstexcl
&& bit (insn
, 22) == 0)
3526 /* We didn't find a closing Store Exclusive instruction, fall back. */
3530 /* Insert breakpoint after the end of the atomic sequence. */
3531 breaks
[0] = loc
+ insn_size
;
3533 /* Check for duplicated breakpoints, and also check that the second
3534 breakpoint is not within the atomic sequence. */
3536 && (breaks
[1] == breaks
[0]
3537 || (breaks
[1] >= pc
&& breaks
[1] <= closing_insn
)))
3538 last_breakpoint
= 0;
3540 std::vector
<CORE_ADDR
> next_pcs
;
3542 /* Insert the breakpoint at the end of the sequence, and one at the
3543 destination of the conditional branch, if it exists. */
3544 for (index
= 0; index
<= last_breakpoint
; index
++)
3545 next_pcs
.push_back (breaks
[index
]);
3550 struct aarch64_displaced_step_copy_insn_closure
3551 : public displaced_step_copy_insn_closure
3553 /* It is true when condition instruction, such as B.CON, TBZ, etc,
3554 is being displaced stepping. */
3557 /* PC adjustment offset after displaced stepping. If 0, then we don't
3558 write the PC back, assuming the PC is already the right address. */
3559 int32_t pc_adjust
= 0;
3562 /* Data when visiting instructions for displaced stepping. */
3564 struct aarch64_displaced_step_data
3566 struct aarch64_insn_data base
;
3568 /* The address where the instruction will be executed at. */
3570 /* Buffer of instructions to be copied to NEW_ADDR to execute. */
3571 uint32_t insn_buf
[AARCH64_DISPLACED_MODIFIED_INSNS
];
3572 /* Number of instructions in INSN_BUF. */
3573 unsigned insn_count
;
3574 /* Registers when doing displaced stepping. */
3575 struct regcache
*regs
;
3577 aarch64_displaced_step_copy_insn_closure
*dsc
;
3580 /* Implementation of aarch64_insn_visitor method "b". */
3583 aarch64_displaced_step_b (const int is_bl
, const int32_t offset
,
3584 struct aarch64_insn_data
*data
)
3586 struct aarch64_displaced_step_data
*dsd
3587 = (struct aarch64_displaced_step_data
*) data
;
3588 int64_t new_offset
= data
->insn_addr
- dsd
->new_addr
+ offset
;
3590 if (can_encode_int32 (new_offset
, 28))
3592 /* Emit B rather than BL, because executing BL on a new address
3593 will get the wrong address into LR. In order to avoid this,
3594 we emit B, and update LR if the instruction is BL. */
3595 emit_b (dsd
->insn_buf
, 0, new_offset
);
3601 emit_nop (dsd
->insn_buf
);
3603 dsd
->dsc
->pc_adjust
= offset
;
3609 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_LR_REGNUM
,
3610 data
->insn_addr
+ 4);
3614 /* Implementation of aarch64_insn_visitor method "b_cond". */
3617 aarch64_displaced_step_b_cond (const unsigned cond
, const int32_t offset
,
3618 struct aarch64_insn_data
*data
)
3620 struct aarch64_displaced_step_data
*dsd
3621 = (struct aarch64_displaced_step_data
*) data
;
3623 /* GDB has to fix up PC after displaced step this instruction
3624 differently according to the condition is true or false. Instead
3625 of checking COND against conditional flags, we can use
3626 the following instructions, and GDB can tell how to fix up PC
3627 according to the PC value.
3629 B.COND TAKEN ; If cond is true, then jump to TAKEN.
3635 emit_bcond (dsd
->insn_buf
, cond
, 8);
3636 dsd
->dsc
->cond
= true;
3637 dsd
->dsc
->pc_adjust
= offset
;
3638 dsd
->insn_count
= 1;
3641 /* Dynamically allocate a new register. If we know the register
3642 statically, we should make it a global as above instead of using this
3645 static struct aarch64_register
3646 aarch64_register (unsigned num
, int is64
)
3648 return (struct aarch64_register
) { num
, is64
};
3651 /* Implementation of aarch64_insn_visitor method "cb". */
3654 aarch64_displaced_step_cb (const int32_t offset
, const int is_cbnz
,
3655 const unsigned rn
, int is64
,
3656 struct aarch64_insn_data
*data
)
3658 struct aarch64_displaced_step_data
*dsd
3659 = (struct aarch64_displaced_step_data
*) data
;
3661 /* The offset is out of range for a compare and branch
3662 instruction. We can use the following instructions instead:
3664 CBZ xn, TAKEN ; xn == 0, then jump to TAKEN.
3669 emit_cb (dsd
->insn_buf
, is_cbnz
, aarch64_register (rn
, is64
), 8);
3670 dsd
->insn_count
= 1;
3671 dsd
->dsc
->cond
= true;
3672 dsd
->dsc
->pc_adjust
= offset
;
3675 /* Implementation of aarch64_insn_visitor method "tb". */
3678 aarch64_displaced_step_tb (const int32_t offset
, int is_tbnz
,
3679 const unsigned rt
, unsigned bit
,
3680 struct aarch64_insn_data
*data
)
3682 struct aarch64_displaced_step_data
*dsd
3683 = (struct aarch64_displaced_step_data
*) data
;
3685 /* The offset is out of range for a test bit and branch
3686 instruction We can use the following instructions instead:
3688 TBZ xn, #bit, TAKEN ; xn[bit] == 0, then jump to TAKEN.
3694 emit_tb (dsd
->insn_buf
, is_tbnz
, bit
, aarch64_register (rt
, 1), 8);
3695 dsd
->insn_count
= 1;
3696 dsd
->dsc
->cond
= true;
3697 dsd
->dsc
->pc_adjust
= offset
;
3700 /* Implementation of aarch64_insn_visitor method "adr". */
3703 aarch64_displaced_step_adr (const int32_t offset
, const unsigned rd
,
3704 const int is_adrp
, struct aarch64_insn_data
*data
)
3706 struct aarch64_displaced_step_data
*dsd
3707 = (struct aarch64_displaced_step_data
*) data
;
3708 /* We know exactly the address the ADR{P,} instruction will compute.
3709 We can just write it to the destination register. */
3710 CORE_ADDR address
= data
->insn_addr
+ offset
;
3714 /* Clear the lower 12 bits of the offset to get the 4K page. */
3715 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_X0_REGNUM
+ rd
,
3719 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_X0_REGNUM
+ rd
,
3722 dsd
->dsc
->pc_adjust
= 4;
3723 emit_nop (dsd
->insn_buf
);
3724 dsd
->insn_count
= 1;
3727 /* Implementation of aarch64_insn_visitor method "ldr_literal". */
3730 aarch64_displaced_step_ldr_literal (const int32_t offset
, const int is_sw
,
3731 const unsigned rt
, const int is64
,
3732 struct aarch64_insn_data
*data
)
3734 struct aarch64_displaced_step_data
*dsd
3735 = (struct aarch64_displaced_step_data
*) data
;
3736 CORE_ADDR address
= data
->insn_addr
+ offset
;
3737 struct aarch64_memory_operand zero
= { MEMORY_OPERAND_OFFSET
, 0 };
3739 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_X0_REGNUM
+ rt
,
3743 dsd
->insn_count
= emit_ldrsw (dsd
->insn_buf
, aarch64_register (rt
, 1),
3744 aarch64_register (rt
, 1), zero
);
3746 dsd
->insn_count
= emit_ldr (dsd
->insn_buf
, aarch64_register (rt
, is64
),
3747 aarch64_register (rt
, 1), zero
);
3749 dsd
->dsc
->pc_adjust
= 4;
3752 /* Implementation of aarch64_insn_visitor method "others". */
3755 aarch64_displaced_step_others (const uint32_t insn
,
3756 struct aarch64_insn_data
*data
)
3758 struct aarch64_displaced_step_data
*dsd
3759 = (struct aarch64_displaced_step_data
*) data
;
3761 uint32_t masked_insn
= (insn
& CLEAR_Rn_MASK
);
3762 if (masked_insn
== BLR
)
3764 /* Emit a BR to the same register and then update LR to the original
3765 address (similar to aarch64_displaced_step_b). */
3766 aarch64_emit_insn (dsd
->insn_buf
, insn
& 0xffdfffff);
3767 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_LR_REGNUM
,
3768 data
->insn_addr
+ 4);
3771 aarch64_emit_insn (dsd
->insn_buf
, insn
);
3772 dsd
->insn_count
= 1;
3774 if (masked_insn
== RET
|| masked_insn
== BR
|| masked_insn
== BLR
)
3775 dsd
->dsc
->pc_adjust
= 0;
3777 dsd
->dsc
->pc_adjust
= 4;
3780 static const struct aarch64_insn_visitor visitor
=
3782 aarch64_displaced_step_b
,
3783 aarch64_displaced_step_b_cond
,
3784 aarch64_displaced_step_cb
,
3785 aarch64_displaced_step_tb
,
3786 aarch64_displaced_step_adr
,
3787 aarch64_displaced_step_ldr_literal
,
3788 aarch64_displaced_step_others
,
3791 /* Implement the "displaced_step_copy_insn" gdbarch method. */
3793 displaced_step_copy_insn_closure_up
3794 aarch64_displaced_step_copy_insn (struct gdbarch
*gdbarch
,
3795 CORE_ADDR from
, CORE_ADDR to
,
3796 struct regcache
*regs
)
3798 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
3799 struct aarch64_displaced_step_data dsd
;
3801 ULONGEST insn_from_memory
;
3803 if (!safe_read_memory_unsigned_integer (from
, 4, byte_order_for_code
,
3807 uint32_t insn
= insn_from_memory
;
3809 if (aarch64_decode_insn (insn
, &inst
, 1, NULL
) != 0)
3812 /* Look for a Load Exclusive instruction which begins the sequence,
3813 or for a MOPS instruction. */
3814 if ((inst
.opcode
->iclass
== ldstexcl
&& bit (insn
, 22))
3815 || AARCH64_CPU_HAS_FEATURE (*inst
.opcode
->avariant
, MOPS
))
3817 /* We can't displaced step atomic sequences nor MOPS instructions. */
3821 std::unique_ptr
<aarch64_displaced_step_copy_insn_closure
> dsc
3822 (new aarch64_displaced_step_copy_insn_closure
);
3823 dsd
.base
.insn_addr
= from
;
3826 dsd
.dsc
= dsc
.get ();
3828 aarch64_relocate_instruction (insn
, &visitor
,
3829 (struct aarch64_insn_data
*) &dsd
);
3830 gdb_assert (dsd
.insn_count
<= AARCH64_DISPLACED_MODIFIED_INSNS
);
3832 if (dsd
.insn_count
!= 0)
3836 /* Instruction can be relocated to scratch pad. Copy
3837 relocated instruction(s) there. */
3838 for (i
= 0; i
< dsd
.insn_count
; i
++)
3840 displaced_debug_printf ("writing insn %.8x at %s",
3842 paddress (gdbarch
, to
+ i
* 4));
3844 write_memory_unsigned_integer (to
+ i
* 4, 4, byte_order_for_code
,
3845 (ULONGEST
) dsd
.insn_buf
[i
]);
3853 /* This is a work around for a problem with g++ 4.8. */
3854 return displaced_step_copy_insn_closure_up (dsc
.release ());
3857 /* Implement the "displaced_step_fixup" gdbarch method. */
3860 aarch64_displaced_step_fixup (struct gdbarch
*gdbarch
,
3861 struct displaced_step_copy_insn_closure
*dsc_
,
3862 CORE_ADDR from
, CORE_ADDR to
,
3863 struct regcache
*regs
, bool completed_p
)
3865 CORE_ADDR pc
= regcache_read_pc (regs
);
3867 /* If the displaced instruction didn't complete successfully then all we
3868 need to do is restore the program counter. */
3871 pc
= from
+ (pc
- to
);
3872 regcache_write_pc (regs
, pc
);
3876 aarch64_displaced_step_copy_insn_closure
*dsc
3877 = (aarch64_displaced_step_copy_insn_closure
*) dsc_
;
3879 displaced_debug_printf ("PC after stepping: %s (was %s).",
3880 paddress (gdbarch
, pc
), paddress (gdbarch
, to
));
3884 displaced_debug_printf ("[Conditional] pc_adjust before: %d",
3889 /* Condition is true. */
3891 else if (pc
- to
== 4)
3893 /* Condition is false. */
3897 gdb_assert_not_reached ("Unexpected PC value after displaced stepping");
3899 displaced_debug_printf ("[Conditional] pc_adjust after: %d",
3903 displaced_debug_printf ("%s PC by %d",
3904 dsc
->pc_adjust
? "adjusting" : "not adjusting",
3907 if (dsc
->pc_adjust
!= 0)
3909 /* Make sure the previous instruction was executed (that is, the PC
3910 has changed). If the PC didn't change, then discard the adjustment
3911 offset. Otherwise we may skip an instruction before its execution
3915 displaced_debug_printf ("PC did not move. Discarding PC adjustment.");
3919 displaced_debug_printf ("fixup: set PC to %s:%d",
3920 paddress (gdbarch
, from
), dsc
->pc_adjust
);
3922 regcache_cooked_write_unsigned (regs
, AARCH64_PC_REGNUM
,
3923 from
+ dsc
->pc_adjust
);
3927 /* Implement the "displaced_step_hw_singlestep" gdbarch method. */
3930 aarch64_displaced_step_hw_singlestep (struct gdbarch
*gdbarch
)
3935 /* Get the correct target description for the given VQ value.
3936 If VQ is zero then it is assumed SVE is not supported.
3937 (It is not possible to set VQ to zero on an SVE system).
3939 MTE_P indicates the presence of the Memory Tagging Extension feature.
3941 TLS_P indicates the presence of the Thread Local Storage feature. */
3944 aarch64_read_description (const aarch64_features
&features
)
3946 if (features
.vq
> AARCH64_MAX_SVE_VQ
)
3947 error (_("VQ is %" PRIu64
", maximum supported value is %d"), features
.vq
,
3948 AARCH64_MAX_SVE_VQ
);
3950 struct target_desc
*tdesc
= tdesc_aarch64_map
[features
];
3954 tdesc
= aarch64_create_target_description (features
);
3955 tdesc_aarch64_map
[features
] = tdesc
;
3961 /* Return the VQ used when creating the target description TDESC. */
3964 aarch64_get_tdesc_vq (const struct target_desc
*tdesc
)
3966 const struct tdesc_feature
*feature_sve
;
3968 if (!tdesc_has_registers (tdesc
))
3971 feature_sve
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.sve");
3973 if (feature_sve
== nullptr)
3976 uint64_t vl
= tdesc_register_bitsize (feature_sve
,
3977 aarch64_sve_register_names
[0]) / 8;
3978 return sve_vq_from_vl (vl
);
3982 /* Return the svq (streaming vector quotient) used when creating the target
3983 description TDESC. */
3986 aarch64_get_tdesc_svq (const struct target_desc
*tdesc
)
3988 const struct tdesc_feature
*feature_sme
;
3990 if (!tdesc_has_registers (tdesc
))
3993 feature_sme
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.sme");
3995 if (feature_sme
== nullptr)
3998 size_t svl_squared
= tdesc_register_bitsize (feature_sme
, "za");
4000 /* We have the total size of the ZA matrix, in bits. Figure out the svl
4002 size_t svl
= std::sqrt (svl_squared
/ 8);
4004 /* Now extract svq. */
4005 return sve_vq_from_vl (svl
);
4008 /* Get the AArch64 features present in the given target description. */
4011 aarch64_features_from_target_desc (const struct target_desc
*tdesc
)
4013 aarch64_features features
;
4015 if (tdesc
== nullptr)
4018 features
.vq
= aarch64_get_tdesc_vq (tdesc
);
4020 /* We need to look for a couple pauth feature name variations. */
4022 = (tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.pauth") != nullptr);
4024 if (!features
.pauth
)
4025 features
.pauth
= (tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.pauth_v2")
4029 = (tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.mte") != nullptr);
4031 const struct tdesc_feature
*tls_feature
4032 = tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.tls");
4034 if (tls_feature
!= nullptr)
4036 /* We have TLS registers. Find out how many. */
4037 if (tdesc_unnumbered_register (tls_feature
, "tpidr2"))
4043 features
.svq
= aarch64_get_tdesc_svq (tdesc
);
4045 /* Check for the SME2 feature. */
4046 features
.sme2
= (tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.sme2")
4052 /* Implement the "cannot_store_register" gdbarch method. */
4055 aarch64_cannot_store_register (struct gdbarch
*gdbarch
, int regnum
)
4057 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
4059 if (!tdep
->has_pauth ())
4062 /* Pointer authentication registers are read-only. */
4063 return (regnum
>= tdep
->pauth_reg_base
4064 && regnum
< tdep
->pauth_reg_base
+ tdep
->pauth_reg_count
);
4067 /* Implement the stack_frame_destroyed_p gdbarch method. */
4070 aarch64_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4072 CORE_ADDR func_start
, func_end
;
4073 if (!find_pc_partial_function (pc
, NULL
, &func_start
, &func_end
))
4076 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
4078 ULONGEST insn_from_memory
;
4079 if (!safe_read_memory_unsigned_integer (pc
, 4, byte_order_for_code
,
4083 uint32_t insn
= insn_from_memory
;
4086 if (aarch64_decode_insn (insn
, &inst
, 1, nullptr) != 0)
4089 return streq (inst
.opcode
->name
, "ret");
4092 /* Helper to get the allocation tag from a 64-bit ADDRESS.
4094 Return the allocation tag if successful and nullopt otherwise. */
4096 std::optional
<CORE_ADDR
>
4097 aarch64_mte_get_atag (CORE_ADDR address
)
4099 gdb::byte_vector tags
;
4101 /* Attempt to fetch the allocation tag. */
4102 if (!target_fetch_memtags (address
, 1, tags
,
4103 static_cast<int> (memtag_type::allocation
)))
4106 /* Only one tag should've been returned. Make sure we got exactly that. */
4107 if (tags
.size () != 1)
4108 error (_("Target returned an unexpected number of tags."));
4110 /* Although our tags are 4 bits in size, they are stored in a
4115 /* Implement the memtag_matches_p gdbarch method. */
4118 aarch64_memtag_matches_p (struct gdbarch
*gdbarch
,
4119 struct value
*address
)
4121 gdb_assert (address
!= nullptr);
4123 CORE_ADDR addr
= value_as_address (address
);
4125 /* Fetch the allocation tag for ADDRESS. */
4126 std::optional
<CORE_ADDR
> atag
4127 = aarch64_mte_get_atag (aarch64_remove_non_address_bits (gdbarch
, addr
));
4129 if (!atag
.has_value ())
4132 /* Fetch the logical tag for ADDRESS. */
4133 gdb_byte ltag
= aarch64_mte_get_ltag (addr
);
4135 /* Are the tags the same? */
4136 return ltag
== *atag
;
4139 /* Implement the set_memtags gdbarch method. */
4142 aarch64_set_memtags (struct gdbarch
*gdbarch
, struct value
*address
,
4143 size_t length
, const gdb::byte_vector
&tags
,
4144 memtag_type tag_type
)
4146 gdb_assert (!tags
.empty ());
4147 gdb_assert (address
!= nullptr);
4149 CORE_ADDR addr
= value_as_address (address
);
4151 /* Set the logical tag or the allocation tag. */
4152 if (tag_type
== memtag_type::logical
)
4154 /* When setting logical tags, we don't care about the length, since
4155 we are only setting a single logical tag. */
4156 addr
= aarch64_mte_set_ltag (addr
, tags
[0]);
4158 /* Update the value's content with the tag. */
4159 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
4160 gdb_byte
*srcbuf
= address
->contents_raw ().data ();
4161 store_unsigned_integer (srcbuf
, sizeof (addr
), byte_order
, addr
);
4165 /* Remove the top byte. */
4166 addr
= aarch64_remove_non_address_bits (gdbarch
, addr
);
4168 /* With G being the number of tag granules and N the number of tags
4169 passed in, we can have the following cases:
4171 1 - G == N: Store all the N tags to memory.
4173 2 - G < N : Warn about having more tags than granules, but write G
4176 3 - G > N : This is a "fill tags" operation. We should use the tags
4177 as a pattern to fill the granules repeatedly until we have
4178 written G tags to memory.
4181 size_t g
= aarch64_mte_get_tag_granules (addr
, length
,
4182 AARCH64_MTE_GRANULE_SIZE
);
4183 size_t n
= tags
.size ();
4186 warning (_("Got more tags than memory granules. Tags will be "
4189 warning (_("Using tag pattern to fill memory range."));
4191 if (!target_store_memtags (addr
, length
, tags
,
4192 static_cast<int> (memtag_type::allocation
)))
4198 /* Implement the get_memtag gdbarch method. */
4200 static struct value
*
4201 aarch64_get_memtag (struct gdbarch
*gdbarch
, struct value
*address
,
4202 memtag_type tag_type
)
4204 gdb_assert (address
!= nullptr);
4206 CORE_ADDR addr
= value_as_address (address
);
4209 /* Get the logical tag or the allocation tag. */
4210 if (tag_type
== memtag_type::logical
)
4211 tag
= aarch64_mte_get_ltag (addr
);
4214 /* Remove the top byte. */
4215 addr
= aarch64_remove_non_address_bits (gdbarch
, addr
);
4216 std::optional
<CORE_ADDR
> atag
= aarch64_mte_get_atag (addr
);
4218 if (!atag
.has_value ())
4224 /* Convert the tag to a value. */
4225 return value_from_ulongest (builtin_type (gdbarch
)->builtin_unsigned_int
,
4229 /* Implement the memtag_to_string gdbarch method. */
4232 aarch64_memtag_to_string (struct gdbarch
*gdbarch
, struct value
*tag_value
)
4234 if (tag_value
== nullptr)
4237 CORE_ADDR tag
= value_as_address (tag_value
);
4239 return string_printf ("0x%s", phex_nz (tag
));
4242 /* See aarch64-tdep.h. */
4245 aarch64_remove_non_address_bits (struct gdbarch
*gdbarch
, CORE_ADDR pointer
)
4247 /* By default, we assume TBI and discard the top 8 bits plus the VA range
4248 select bit (55). Below we try to fetch information about pointer
4249 authentication masks in order to make non-address removal more
4251 CORE_ADDR mask
= AARCH64_TOP_BITS_MASK
;
4253 /* Check if we have an inferior first. If not, just use the default
4256 We use the inferior_ptid here because the pointer authentication masks
4257 should be the same across threads of a process. Since we may not have
4258 access to the current thread (gdb may have switched to no inferiors
4259 momentarily), we use the inferior ptid. */
4260 if (inferior_ptid
!= null_ptid
)
4262 /* If we do have an inferior, attempt to fetch its thread's thread_info
4264 thread_info
*thread
= current_inferior ()->find_thread (inferior_ptid
);
4266 /* If the thread is running, we will not be able to fetch the mask
4268 if (thread
!= nullptr && thread
->state
!= THREAD_RUNNING
)
4270 /* Otherwise, fetch the register cache and the masks. */
4271 struct regcache
*regs
4272 = get_thread_regcache (current_inferior ()->process_target (),
4275 /* Use the gdbarch from the register cache to check for pointer
4276 authentication support, as it matches the features found in
4277 that particular thread. */
4278 aarch64_gdbarch_tdep
*tdep
4279 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (regs
->arch ());
4281 /* Is there pointer authentication support? */
4282 if (tdep
->has_pauth ())
4284 CORE_ADDR cmask
, dmask
;
4286 = AARCH64_PAUTH_DMASK_REGNUM (tdep
->pauth_reg_base
);
4288 = AARCH64_PAUTH_CMASK_REGNUM (tdep
->pauth_reg_base
);
4290 /* If we have a kernel address and we have kernel-mode address
4291 mask registers, use those instead. */
4292 if (tdep
->pauth_reg_count
> 2
4293 && pointer
& VA_RANGE_SELECT_BIT_MASK
)
4296 = AARCH64_PAUTH_DMASK_HIGH_REGNUM (tdep
->pauth_reg_base
);
4298 = AARCH64_PAUTH_CMASK_HIGH_REGNUM (tdep
->pauth_reg_base
);
4301 /* We have both a code mask and a data mask. For now they are
4302 the same, but this may change in the future. */
4303 if (regs
->cooked_read (dmask_regnum
, &dmask
) != REG_VALID
)
4306 if (regs
->cooked_read (cmask_regnum
, &cmask
) != REG_VALID
)
4309 mask
|= aarch64_mask_from_pac_registers (cmask
, dmask
);
4314 return aarch64_remove_top_bits (pointer
, mask
);
4317 /* Given NAMES, a vector of strings, initialize it with all the SME
4318 pseudo-register names for the current streaming vector length. */
4321 aarch64_initialize_sme_pseudo_names (struct gdbarch
*gdbarch
,
4322 std::vector
<std::string
> &names
)
4324 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
4326 gdb_assert (tdep
->has_sme ());
4327 gdb_assert (tdep
->sme_tile_slice_pseudo_base
> 0);
4328 gdb_assert (tdep
->sme_tile_pseudo_base
> 0);
4330 for (int i
= 0; i
< tdep
->sme_tile_slice_pseudo_count
; i
++)
4332 int regnum
= tdep
->sme_tile_slice_pseudo_base
+ i
;
4333 struct za_pseudo_encoding encoding
;
4334 aarch64_za_decode_pseudos (gdbarch
, regnum
, encoding
);
4335 names
.push_back (aarch64_za_tile_slice_name (encoding
));
4337 for (int i
= 0; i
< AARCH64_ZA_TILES_NUM
; i
++)
4339 int regnum
= tdep
->sme_tile_pseudo_base
+ i
;
4340 struct za_pseudo_encoding encoding
;
4341 aarch64_za_decode_pseudos (gdbarch
, regnum
, encoding
);
4342 names
.push_back (aarch64_za_tile_name (encoding
));
4346 /* Initialize the current architecture based on INFO. If possible,
4347 reuse an architecture from ARCHES, which is a list of
4348 architectures already created during this debugging session.
4350 Called e.g. at program startup, when reading a core file, and when
4351 reading a binary file. */
4353 static struct gdbarch
*
4354 aarch64_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
4356 const struct tdesc_feature
*feature_core
, *feature_fpu
, *feature_sve
;
4357 const struct tdesc_feature
*feature_pauth
;
4358 bool valid_p
= true;
4359 int i
, num_regs
= 0, num_pseudo_regs
= 0;
4360 int first_pauth_regnum
= -1, ra_sign_state_offset
= -1;
4361 int first_mte_regnum
= -1, first_tls_regnum
= -1;
4362 uint64_t vq
= aarch64_get_tdesc_vq (info
.target_desc
);
4363 uint64_t svq
= aarch64_get_tdesc_svq (info
.target_desc
);
4365 if (vq
> AARCH64_MAX_SVE_VQ
)
4366 internal_error (_("VQ out of bounds: %s (max %d)"),
4367 pulongest (vq
), AARCH64_MAX_SVE_VQ
);
4369 if (svq
> AARCH64_MAX_SVE_VQ
)
4370 internal_error (_("Streaming vector quotient (svq) out of bounds: %s"
4372 pulongest (svq
), AARCH64_MAX_SVE_VQ
);
4374 /* If there is already a candidate, use it. */
4375 for (gdbarch_list
*best_arch
= gdbarch_list_lookup_by_info (arches
, &info
);
4376 best_arch
!= nullptr;
4377 best_arch
= gdbarch_list_lookup_by_info (best_arch
->next
, &info
))
4379 aarch64_gdbarch_tdep
*tdep
4380 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (best_arch
->gdbarch
);
4381 if (tdep
&& tdep
->vq
== vq
&& tdep
->sme_svq
== svq
)
4382 return best_arch
->gdbarch
;
4385 /* Ensure we always have a target descriptor, and that it is for the given VQ
4387 const struct target_desc
*tdesc
= info
.target_desc
;
4388 if (!tdesc_has_registers (tdesc
) || vq
!= aarch64_get_tdesc_vq (tdesc
)
4389 || svq
!= aarch64_get_tdesc_svq (tdesc
))
4391 aarch64_features features
;
4394 tdesc
= aarch64_read_description (features
);
4398 feature_core
= tdesc_find_feature (tdesc
,"org.gnu.gdb.aarch64.core");
4399 feature_fpu
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.fpu");
4400 feature_sve
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.sve");
4401 const struct tdesc_feature
*feature_mte
4402 = tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.mte");
4403 const struct tdesc_feature
*feature_tls
4404 = tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.tls");
4406 if (feature_core
== nullptr)
4409 tdesc_arch_data_up tdesc_data
= tdesc_data_alloc ();
4411 /* Validate the description provides the mandatory core R registers
4412 and allocate their numbers. */
4413 for (i
= 0; i
< ARRAY_SIZE (aarch64_r_register_names
); i
++)
4414 valid_p
&= tdesc_numbered_register (feature_core
, tdesc_data
.get (),
4415 AARCH64_X0_REGNUM
+ i
,
4416 aarch64_r_register_names
[i
]);
4418 num_regs
= AARCH64_X0_REGNUM
+ i
;
4420 /* Add the V registers. */
4421 if (feature_fpu
!= nullptr)
4423 if (feature_sve
!= nullptr)
4424 error (_("Program contains both fpu and SVE features."));
4426 /* Validate the description provides the mandatory V registers
4427 and allocate their numbers. */
4428 for (i
= 0; i
< ARRAY_SIZE (aarch64_v_register_names
); i
++)
4429 valid_p
&= tdesc_numbered_register (feature_fpu
, tdesc_data
.get (),
4430 AARCH64_V0_REGNUM
+ i
,
4431 aarch64_v_register_names
[i
]);
4433 num_regs
= AARCH64_V0_REGNUM
+ i
;
4436 /* Add the SVE registers. */
4437 if (feature_sve
!= nullptr)
4439 /* Validate the description provides the mandatory SVE registers
4440 and allocate their numbers. */
4441 for (i
= 0; i
< ARRAY_SIZE (aarch64_sve_register_names
); i
++)
4442 valid_p
&= tdesc_numbered_register (feature_sve
, tdesc_data
.get (),
4443 AARCH64_SVE_Z0_REGNUM
+ i
,
4444 aarch64_sve_register_names
[i
]);
4446 num_regs
= AARCH64_SVE_Z0_REGNUM
+ i
;
4447 num_pseudo_regs
+= 32; /* add the Vn register pseudos. */
4450 if (feature_fpu
!= nullptr || feature_sve
!= nullptr)
4452 num_pseudo_regs
+= 32; /* add the Qn scalar register pseudos */
4453 num_pseudo_regs
+= 32; /* add the Dn scalar register pseudos */
4454 num_pseudo_regs
+= 32; /* add the Sn scalar register pseudos */
4455 num_pseudo_regs
+= 32; /* add the Hn scalar register pseudos */
4456 num_pseudo_regs
+= 32; /* add the Bn scalar register pseudos */
4459 int first_sme_regnum
= -1;
4460 int first_sme2_regnum
= -1;
4461 int first_sme_pseudo_regnum
= -1;
4462 const struct tdesc_feature
*feature_sme
4463 = tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.sme");
4464 if (feature_sme
!= nullptr)
4466 /* Record the first SME register. */
4467 first_sme_regnum
= num_regs
;
4469 valid_p
&= tdesc_numbered_register (feature_sme
, tdesc_data
.get (),
4472 valid_p
&= tdesc_numbered_register (feature_sme
, tdesc_data
.get (),
4473 num_regs
++, "svcr");
4475 valid_p
&= tdesc_numbered_register (feature_sme
, tdesc_data
.get (),
4478 /* Record the first SME pseudo register. */
4479 first_sme_pseudo_regnum
= num_pseudo_regs
;
4481 /* Add the ZA tile slice pseudo registers. The number of tile slice
4482 pseudo-registers depend on the svl, and is always a multiple of 5. */
4483 num_pseudo_regs
+= (svq
<< 5) * 5;
4485 /* Add the ZA tile pseudo registers. */
4486 num_pseudo_regs
+= AARCH64_ZA_TILES_NUM
;
4488 /* Now check for the SME2 feature. SME2 is only available if SME is
4490 const struct tdesc_feature
*feature_sme2
4491 = tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.sme2");
4492 if (feature_sme2
!= nullptr)
4494 /* Record the first SME2 register. */
4495 first_sme2_regnum
= num_regs
;
4497 valid_p
&= tdesc_numbered_register (feature_sme2
, tdesc_data
.get (),
4502 /* Add the TLS register. */
4503 int tls_register_count
= 0;
4504 if (feature_tls
!= nullptr)
4506 first_tls_regnum
= num_regs
;
4508 /* Look for the TLS registers. tpidr is required, but tpidr2 is
4511 = tdesc_numbered_register (feature_tls
, tdesc_data
.get (),
4512 first_tls_regnum
, "tpidr");
4516 tls_register_count
++;
4519 = tdesc_numbered_register (feature_tls
, tdesc_data
.get (),
4520 first_tls_regnum
+ tls_register_count
,
4523 /* Figure out how many TLS registers we have. */
4525 tls_register_count
++;
4527 num_regs
+= tls_register_count
;
4531 warning (_("Provided TLS register feature doesn't contain "
4532 "required tpidr register."));
4537 /* We have two versions of the pauth target description due to a past bug
4538 where GDB would crash when seeing the first version of the pauth target
4540 feature_pauth
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.pauth");
4541 if (feature_pauth
== nullptr)
4542 feature_pauth
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.pauth_v2");
4544 /* Add the pauth registers. */
4545 int pauth_masks
= 0;
4546 if (feature_pauth
!= NULL
)
4548 first_pauth_regnum
= num_regs
;
4549 ra_sign_state_offset
= num_pseudo_regs
;
4551 /* Size of the expected register set with all 4 masks. */
4552 int set_size
= ARRAY_SIZE (aarch64_pauth_register_names
);
4554 /* QEMU exposes a couple additional masks for the high half of the
4555 address. We should either have 2 registers or 4 registers. */
4556 if (tdesc_unnumbered_register (feature_pauth
,
4557 "pauth_dmask_high") == 0)
4559 /* We did not find pauth_dmask_high, assume we only have
4560 2 masks. We are not dealing with QEMU/Emulators then. */
4564 /* Validate the descriptor provides the mandatory PAUTH registers and
4565 allocate their numbers. */
4566 for (i
= 0; i
< set_size
; i
++)
4567 valid_p
&= tdesc_numbered_register (feature_pauth
, tdesc_data
.get (),
4568 first_pauth_regnum
+ i
,
4569 aarch64_pauth_register_names
[i
]);
4572 num_pseudo_regs
+= 1; /* Count RA_STATE pseudo register. */
4573 pauth_masks
= set_size
;
4576 /* Add the MTE registers. */
4577 if (feature_mte
!= NULL
)
4579 first_mte_regnum
= num_regs
;
4580 /* Validate the descriptor provides the mandatory MTE registers and
4581 allocate their numbers. */
4582 for (i
= 0; i
< ARRAY_SIZE (aarch64_mte_register_names
); i
++)
4583 valid_p
&= tdesc_numbered_register (feature_mte
, tdesc_data
.get (),
4584 first_mte_regnum
+ i
,
4585 aarch64_mte_register_names
[i
]);
4589 /* W pseudo-registers */
4590 int first_w_regnum
= num_pseudo_regs
;
4591 num_pseudo_regs
+= 31;
4596 /* AArch64 code is always little-endian. */
4597 info
.byte_order_for_code
= BFD_ENDIAN_LITTLE
;
4600 = gdbarch_alloc (&info
, gdbarch_tdep_up (new aarch64_gdbarch_tdep
));
4601 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
4603 /* This should be low enough for everything. */
4604 tdep
->lowest_pc
= 0x20;
4605 tdep
->jb_pc
= -1; /* Longjump support not enabled by default. */
4606 tdep
->jb_elt_size
= 8;
4608 tdep
->pauth_reg_base
= first_pauth_regnum
;
4609 tdep
->pauth_reg_count
= pauth_masks
;
4610 tdep
->ra_sign_state_regnum
= -1;
4611 tdep
->mte_reg_base
= first_mte_regnum
;
4612 tdep
->tls_regnum_base
= first_tls_regnum
;
4613 tdep
->tls_register_count
= tls_register_count
;
4615 /* Set the SME register set details. The pseudo-registers will be adjusted
4617 tdep
->sme_reg_base
= first_sme_regnum
;
4618 tdep
->sme_svg_regnum
= first_sme_regnum
;
4619 tdep
->sme_svcr_regnum
= first_sme_regnum
+ 1;
4620 tdep
->sme_za_regnum
= first_sme_regnum
+ 2;
4621 tdep
->sme_svq
= svq
;
4623 /* Set the SME2 register set details. */
4624 tdep
->sme2_zt0_regnum
= first_sme2_regnum
;
4626 set_gdbarch_push_dummy_call (gdbarch
, aarch64_push_dummy_call
);
4627 set_gdbarch_frame_align (gdbarch
, aarch64_frame_align
);
4629 /* Advance PC across function entry code. */
4630 set_gdbarch_skip_prologue (gdbarch
, aarch64_skip_prologue
);
4632 /* The stack grows downward. */
4633 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
4635 /* Breakpoint manipulation. */
4636 set_gdbarch_breakpoint_kind_from_pc (gdbarch
,
4637 aarch64_breakpoint::kind_from_pc
);
4638 set_gdbarch_sw_breakpoint_from_kind (gdbarch
,
4639 aarch64_breakpoint::bp_from_kind
);
4640 set_gdbarch_have_nonsteppable_watchpoint (gdbarch
, 1);
4641 set_gdbarch_software_single_step (gdbarch
, aarch64_software_single_step
);
4643 /* Information about registers, etc. */
4644 set_gdbarch_sp_regnum (gdbarch
, AARCH64_SP_REGNUM
);
4645 set_gdbarch_pc_regnum (gdbarch
, AARCH64_PC_REGNUM
);
4646 set_gdbarch_num_regs (gdbarch
, num_regs
);
4648 set_gdbarch_num_pseudo_regs (gdbarch
, num_pseudo_regs
);
4649 set_gdbarch_pseudo_register_read_value (gdbarch
, aarch64_pseudo_read_value
);
4650 set_gdbarch_pseudo_register_write (gdbarch
, aarch64_pseudo_write
);
4651 set_tdesc_pseudo_register_name (gdbarch
, aarch64_pseudo_register_name
);
4652 set_tdesc_pseudo_register_type (gdbarch
, aarch64_pseudo_register_type
);
4653 set_tdesc_pseudo_register_reggroup_p (gdbarch
,
4654 aarch64_pseudo_register_reggroup_p
);
4655 set_gdbarch_cannot_store_register (gdbarch
, aarch64_cannot_store_register
);
4657 /* Set the allocation tag granule size to 16 bytes. */
4658 set_gdbarch_memtag_granule_size (gdbarch
, AARCH64_MTE_GRANULE_SIZE
);
4660 /* Register a hook for checking if there is a memory tag match. */
4661 set_gdbarch_memtag_matches_p (gdbarch
, aarch64_memtag_matches_p
);
4663 /* Register a hook for setting the logical/allocation tags for
4664 a range of addresses. */
4665 set_gdbarch_set_memtags (gdbarch
, aarch64_set_memtags
);
4667 /* Register a hook for extracting the logical/allocation tag from an
4669 set_gdbarch_get_memtag (gdbarch
, aarch64_get_memtag
);
4671 /* Register a hook for converting a memory tag to a string. */
4672 set_gdbarch_memtag_to_string (gdbarch
, aarch64_memtag_to_string
);
4675 set_gdbarch_short_bit (gdbarch
, 16);
4676 set_gdbarch_int_bit (gdbarch
, 32);
4677 set_gdbarch_float_bit (gdbarch
, 32);
4678 set_gdbarch_double_bit (gdbarch
, 64);
4679 set_gdbarch_long_double_bit (gdbarch
, 128);
4680 set_gdbarch_long_bit (gdbarch
, 64);
4681 set_gdbarch_long_long_bit (gdbarch
, 64);
4682 set_gdbarch_ptr_bit (gdbarch
, 64);
4683 set_gdbarch_char_signed (gdbarch
, 0);
4684 set_gdbarch_wchar_signed (gdbarch
, 0);
4685 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
4686 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
4687 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_quad
);
4688 set_gdbarch_type_align (gdbarch
, aarch64_type_align
);
4690 /* Detect whether PC is at a point where the stack has been destroyed. */
4691 set_gdbarch_stack_frame_destroyed_p (gdbarch
, aarch64_stack_frame_destroyed_p
);
4693 /* Internal <-> external register number maps. */
4694 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, aarch64_dwarf_reg_to_regnum
);
4696 /* Returning results. */
4697 set_gdbarch_return_value_as_value (gdbarch
, aarch64_return_value
);
4700 set_gdbarch_print_insn (gdbarch
, aarch64_gdb_print_insn
);
4702 /* Virtual tables. */
4703 set_gdbarch_vbit_in_delta (gdbarch
, 1);
4705 /* Hook in the ABI-specific overrides, if they have been registered. */
4706 info
.target_desc
= tdesc
;
4707 info
.tdesc_data
= tdesc_data
.get ();
4708 gdbarch_init_osabi (info
, gdbarch
);
4710 dwarf2_frame_set_init_reg (gdbarch
, aarch64_dwarf2_frame_init_reg
);
4711 /* Register DWARF CFA vendor handler. */
4712 set_gdbarch_execute_dwarf_cfa_vendor_op (gdbarch
,
4713 aarch64_execute_dwarf_cfa_vendor_op
);
4715 /* Permanent/Program breakpoint handling. */
4716 set_gdbarch_program_breakpoint_here_p (gdbarch
,
4717 aarch64_program_breakpoint_here_p
);
4719 /* Add some default predicates. */
4720 frame_unwind_append_unwinder (gdbarch
, &aarch64_stub_unwind
);
4721 dwarf2_append_unwinders (gdbarch
);
4722 frame_unwind_append_unwinder (gdbarch
, &aarch64_prologue_unwind
);
4724 frame_base_set_default (gdbarch
, &aarch64_normal_base
);
4726 /* Now we have tuned the configuration, set a few final things,
4727 based on what the OS ABI has told us. */
4729 if (tdep
->jb_pc
>= 0)
4730 set_gdbarch_get_longjmp_target (gdbarch
, aarch64_get_longjmp_target
);
4732 set_gdbarch_gen_return_address (gdbarch
, aarch64_gen_return_address
);
4734 set_gdbarch_get_pc_address_flags (gdbarch
, aarch64_get_pc_address_flags
);
4736 tdesc_use_registers (gdbarch
, tdesc
, std::move (tdesc_data
));
4738 /* Fetch the updated number of registers after we're done adding all
4739 entries from features we don't explicitly care about. This is the case
4740 for bare metal debugging stubs that include a lot of system registers. */
4741 num_regs
= gdbarch_num_regs (gdbarch
);
4743 /* With the number of real registers updated, setup the pseudo-registers and
4744 record their numbers. */
4746 /* Setup W pseudo-register numbers. */
4747 tdep
->w_pseudo_base
= first_w_regnum
+ num_regs
;
4748 tdep
->w_pseudo_count
= 31;
4750 /* Pointer authentication pseudo-registers. */
4751 if (tdep
->has_pauth ())
4752 tdep
->ra_sign_state_regnum
= ra_sign_state_offset
+ num_regs
;
4754 /* Architecture hook to remove bits of a pointer that are not part of the
4755 address, like memory tags (MTE) and pointer authentication signatures.
4756 Configure address adjustment for watchpoints, breakpoints and memory
4758 set_gdbarch_remove_non_address_bits_watchpoint
4759 (gdbarch
, aarch64_remove_non_address_bits
);
4760 set_gdbarch_remove_non_address_bits_breakpoint
4761 (gdbarch
, aarch64_remove_non_address_bits
);
4762 set_gdbarch_remove_non_address_bits_memory
4763 (gdbarch
, aarch64_remove_non_address_bits
);
4765 /* SME pseudo-registers. */
4766 if (tdep
->has_sme ())
4768 tdep
->sme_pseudo_base
= num_regs
+ first_sme_pseudo_regnum
;
4769 tdep
->sme_tile_slice_pseudo_base
= tdep
->sme_pseudo_base
;
4770 tdep
->sme_tile_slice_pseudo_count
= (svq
* 32) * 5;
4771 tdep
->sme_tile_pseudo_base
4772 = tdep
->sme_pseudo_base
+ tdep
->sme_tile_slice_pseudo_count
;
4773 tdep
->sme_pseudo_count
4774 = tdep
->sme_tile_slice_pseudo_count
+ AARCH64_ZA_TILES_NUM
;
4776 /* The SME ZA pseudo-registers are a set of 160 to 2560 pseudo-registers
4777 depending on the value of svl.
4779 The tile pseudo-registers are organized around their qualifiers
4780 (b, h, s, d and q). Their numbers are distributed as follows:
4788 The naming of the tile pseudo-registers follows the pattern za<t><q>,
4791 <t> is the tile number, with the following possible values based on
4794 Qualifier - Allocated indexes
4802 <q> is the qualifier: b, h, s, d and q.
4804 The tile slice pseudo-registers are organized around their
4805 qualifiers as well (b, h, s, d and q), but also around their
4806 direction (h - horizontal and v - vertical).
4808 Even-numbered tile slice pseudo-registers are horizontally-oriented
4809 and odd-numbered tile slice pseudo-registers are vertically-oriented.
4811 Their numbers are distributed as follows:
4813 Qualifier - Allocated indexes
4815 b tile slices - 0~511
4816 h tile slices - 512~1023
4817 s tile slices - 1024~1535
4818 d tile slices - 1536~2047
4819 q tile slices - 2048~2559
4821 The naming of the tile slice pseudo-registers follows the pattern
4822 za<t><d><q><s>, where:
4824 <t> is the tile number as described for the tile pseudo-registers.
4825 <d> is the direction of the tile slice (h or v)
4826 <q> is the qualifier of the tile slice (b, h, s, d or q)
4827 <s> is the slice number, defined as follows:
4829 Qualifier - Allocated indexes
4837 We have helper functions to translate to/from register index from/to
4838 the set of fields that make the pseudo-register names. */
4840 /* Build the array of pseudo-register names available for this
4841 particular gdbarch configuration. */
4842 aarch64_initialize_sme_pseudo_names (gdbarch
, tdep
->sme_pseudo_names
);
4845 /* Add standard register aliases. */
4846 for (i
= 0; i
< ARRAY_SIZE (aarch64_register_aliases
); i
++)
4847 user_reg_add (gdbarch
, aarch64_register_aliases
[i
].name
,
4848 value_of_aarch64_user_reg
,
4849 &aarch64_register_aliases
[i
].regnum
);
4851 register_aarch64_ravenscar_ops (gdbarch
);
4857 aarch64_dump_tdep (struct gdbarch
*gdbarch
, struct ui_file
*file
)
4859 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
4864 gdb_printf (file
, _("aarch64_dump_tdep: Lowest pc = 0x%s\n"),
4865 paddress (gdbarch
, tdep
->lowest_pc
));
4868 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_type_q = %s\n"),
4869 host_address_to_string (tdep
->sme_tile_type_q
));
4870 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_type_d = %s\n"),
4871 host_address_to_string (tdep
->sme_tile_type_d
));
4872 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_type_s = %s\n"),
4873 host_address_to_string (tdep
->sme_tile_type_s
));
4874 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_type_h = %s\n"),
4875 host_address_to_string (tdep
->sme_tile_type_h
));
4876 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_type_n = %s\n"),
4877 host_address_to_string (tdep
->sme_tile_type_b
));
4878 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_slice_type_q = %s\n"),
4879 host_address_to_string (tdep
->sme_tile_slice_type_q
));
4880 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_slice_type_d = %s\n"),
4881 host_address_to_string (tdep
->sme_tile_slice_type_d
));
4882 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_slice_type_s = %s\n"),
4883 host_address_to_string (tdep
->sme_tile_slice_type_s
));
4884 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_slice_type_h = %s\n"),
4885 host_address_to_string (tdep
->sme_tile_slice_type_h
));
4886 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_slice_type_b = %s\n"),
4887 host_address_to_string (tdep
->sme_tile_slice_type_b
));
4888 gdb_printf (file
, _("aarch64_dump_tdep: sme_reg_base = %s\n"),
4889 pulongest (tdep
->sme_reg_base
));
4890 gdb_printf (file
, _("aarch64_dump_tdep: sme_svg_regnum = %s\n"),
4891 pulongest (tdep
->sme_svg_regnum
));
4892 gdb_printf (file
, _("aarch64_dump_tdep: sme_svcr_regnum = %s\n"),
4893 pulongest (tdep
->sme_svcr_regnum
));
4894 gdb_printf (file
, _("aarch64_dump_tdep: sme_za_regnum = %s\n"),
4895 pulongest (tdep
->sme_za_regnum
));
4896 gdb_printf (file
, _("aarch64_dump_tdep: sme_pseudo_base = %s\n"),
4897 pulongest (tdep
->sme_pseudo_base
));
4898 gdb_printf (file
, _("aarch64_dump_tdep: sme_pseudo_count = %s\n"),
4899 pulongest (tdep
->sme_pseudo_count
));
4900 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_slice_pseudo_base = %s\n"),
4901 pulongest (tdep
->sme_tile_slice_pseudo_base
));
4902 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_slice_pseudo_count = %s\n"),
4903 pulongest (tdep
->sme_tile_slice_pseudo_count
));
4904 gdb_printf (file
, _("aarch64_dump_tdep: sme_tile_pseudo_base = %s\n"),
4905 pulongest (tdep
->sme_tile_pseudo_base
));
4906 gdb_printf (file
, _("aarch64_dump_tdep: sme_svq = %s\n"),
4907 pulongest (tdep
->sme_svq
));
4913 static void aarch64_process_record_test (void);
4917 INIT_GDB_FILE (aarch64_tdep
)
4919 gdbarch_register (bfd_arch_aarch64
, aarch64_gdbarch_init
,
4922 /* Debug this file's internals. */
4923 add_setshow_boolean_cmd ("aarch64", class_maintenance
, &aarch64_debug
, _("\
4924 Set AArch64 debugging."), _("\
4925 Show AArch64 debugging."), _("\
4926 When on, AArch64 specific debugging is enabled."),
4929 &setdebuglist
, &showdebuglist
);
4932 selftests::register_test ("aarch64-analyze-prologue",
4933 selftests::aarch64_analyze_prologue_test
);
4934 selftests::register_test ("aarch64-process-record",
4935 selftests::aarch64_process_record_test
);
4939 /* AArch64 process record-replay related structures, defines etc. */
4941 #define REG_ALLOC(REGS, LENGTH, RECORD_BUF) \
4944 unsigned int reg_len = LENGTH; \
4947 REGS = XNEWVEC (uint32_t, reg_len); \
4948 memcpy(®S[0], &RECORD_BUF[0], sizeof(uint32_t)*LENGTH); \
4953 #define MEM_ALLOC(MEMS, LENGTH, RECORD_BUF) \
4956 unsigned int mem_len = LENGTH; \
4959 MEMS = XNEWVEC (struct aarch64_mem_r, mem_len); \
4960 memcpy(MEMS, &RECORD_BUF[0], \
4961 sizeof(struct aarch64_mem_r) * LENGTH); \
4966 /* AArch64 record/replay structures and enumerations. */
4968 struct aarch64_mem_r
4970 uint64_t len
; /* Record length. */
4971 uint64_t addr
; /* Memory address. */
4974 enum aarch64_record_result
4976 AARCH64_RECORD_SUCCESS
,
4977 AARCH64_RECORD_UNSUPPORTED
,
4978 AARCH64_RECORD_UNKNOWN
4981 struct aarch64_insn_decode_record
4983 struct gdbarch
*gdbarch
;
4984 struct regcache
*regcache
;
4985 CORE_ADDR this_addr
; /* Address of insn to be recorded. */
4986 uint32_t aarch64_insn
; /* Insn to be recorded. */
4987 uint32_t mem_rec_count
; /* Count of memory records. */
4988 uint32_t reg_rec_count
; /* Count of register records. */
4989 uint32_t *aarch64_regs
; /* Registers to be recorded. */
4990 struct aarch64_mem_r
*aarch64_mems
; /* Memory locations to be recorded. */
4993 /* Record handler for data processing - register instructions. */
4996 aarch64_record_data_proc_reg (aarch64_insn_decode_record
*aarch64_insn_r
)
4998 uint8_t reg_rd
, insn_bits24_27
, insn_bits21_23
;
4999 uint32_t record_buf
[4];
5001 reg_rd
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
5002 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
5003 insn_bits21_23
= bits (aarch64_insn_r
->aarch64_insn
, 21, 23);
5005 if (!bit (aarch64_insn_r
->aarch64_insn
, 28))
5009 /* Logical (shifted register). */
5010 if (insn_bits24_27
== 0x0a)
5011 setflags
= (bits (aarch64_insn_r
->aarch64_insn
, 29, 30) == 0x03);
5013 else if (insn_bits24_27
== 0x0b)
5014 setflags
= bit (aarch64_insn_r
->aarch64_insn
, 29);
5016 return AARCH64_RECORD_UNKNOWN
;
5018 record_buf
[0] = reg_rd
;
5019 aarch64_insn_r
->reg_rec_count
= 1;
5021 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_CPSR_REGNUM
;
5025 if (insn_bits24_27
== 0x0b)
5027 /* Data-processing (3 source). */
5028 record_buf
[0] = reg_rd
;
5029 aarch64_insn_r
->reg_rec_count
= 1;
5031 else if (insn_bits24_27
== 0x0a)
5033 if (insn_bits21_23
== 0x00)
5035 /* Add/subtract (with carry). */
5036 record_buf
[0] = reg_rd
;
5037 aarch64_insn_r
->reg_rec_count
= 1;
5038 if (bit (aarch64_insn_r
->aarch64_insn
, 29))
5040 record_buf
[1] = AARCH64_CPSR_REGNUM
;
5041 aarch64_insn_r
->reg_rec_count
= 2;
5044 else if (insn_bits21_23
== 0x02)
5046 /* Conditional compare (register) and conditional compare
5047 (immediate) instructions. */
5048 record_buf
[0] = AARCH64_CPSR_REGNUM
;
5049 aarch64_insn_r
->reg_rec_count
= 1;
5051 else if (insn_bits21_23
== 0x04 || insn_bits21_23
== 0x06)
5053 /* Conditional select. */
5054 /* Data-processing (2 source). */
5055 /* Data-processing (1 source). */
5056 record_buf
[0] = reg_rd
;
5057 aarch64_insn_r
->reg_rec_count
= 1;
5060 return AARCH64_RECORD_UNKNOWN
;
5064 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
5066 return AARCH64_RECORD_SUCCESS
;
5069 /* Record handler for data processing - immediate instructions. */
5072 aarch64_record_data_proc_imm (aarch64_insn_decode_record
*aarch64_insn_r
)
5074 uint8_t reg_rd
, insn_bit23
, insn_bits24_27
, setflags
;
5075 uint32_t record_buf
[4];
5077 reg_rd
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
5078 insn_bit23
= bit (aarch64_insn_r
->aarch64_insn
, 23);
5079 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
5081 if (insn_bits24_27
== 0x00 /* PC rel addressing. */
5082 || insn_bits24_27
== 0x03 /* Bitfield and Extract. */
5083 || (insn_bits24_27
== 0x02 && insn_bit23
)) /* Move wide (immediate). */
5085 record_buf
[0] = reg_rd
;
5086 aarch64_insn_r
->reg_rec_count
= 1;
5088 else if (insn_bits24_27
== 0x01)
5090 /* Add/Subtract (immediate). */
5091 setflags
= bit (aarch64_insn_r
->aarch64_insn
, 29);
5092 record_buf
[0] = reg_rd
;
5093 aarch64_insn_r
->reg_rec_count
= 1;
5095 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_CPSR_REGNUM
;
5097 else if (insn_bits24_27
== 0x02 && !insn_bit23
)
5099 /* Logical (immediate). */
5100 setflags
= bits (aarch64_insn_r
->aarch64_insn
, 29, 30) == 0x03;
5101 record_buf
[0] = reg_rd
;
5102 aarch64_insn_r
->reg_rec_count
= 1;
5104 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_CPSR_REGNUM
;
5107 return AARCH64_RECORD_UNKNOWN
;
5109 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
5111 return AARCH64_RECORD_SUCCESS
;
5114 /* Record handler for branch, exception generation and system instructions. */
5117 aarch64_record_branch_except_sys (aarch64_insn_decode_record
*aarch64_insn_r
)
5120 aarch64_gdbarch_tdep
*tdep
5121 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (aarch64_insn_r
->gdbarch
);
5122 uint8_t insn_bits24_27
, insn_bits28_31
, insn_bits22_23
;
5123 uint32_t record_buf
[4];
5125 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
5126 insn_bits28_31
= bits (aarch64_insn_r
->aarch64_insn
, 28, 31);
5127 insn_bits22_23
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
5129 if (insn_bits28_31
== 0x0d)
5131 /* Exception generation instructions. */
5132 if (insn_bits24_27
== 0x04)
5134 if (!bits (aarch64_insn_r
->aarch64_insn
, 2, 4)
5135 && !bits (aarch64_insn_r
->aarch64_insn
, 21, 23)
5136 && bits (aarch64_insn_r
->aarch64_insn
, 0, 1) == 0x01)
5138 ULONGEST svc_number
;
5140 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, 8,
5142 return tdep
->aarch64_syscall_record (aarch64_insn_r
->regcache
,
5146 return AARCH64_RECORD_UNSUPPORTED
;
5148 /* System instructions. */
5149 else if (insn_bits24_27
== 0x05 && insn_bits22_23
== 0x00)
5151 uint32_t reg_rt
, reg_crn
;
5153 reg_rt
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
5154 reg_crn
= bits (aarch64_insn_r
->aarch64_insn
, 12, 15);
5156 /* Record rt in case of sysl and mrs instructions. */
5157 if (bit (aarch64_insn_r
->aarch64_insn
, 21))
5159 record_buf
[0] = reg_rt
;
5160 aarch64_insn_r
->reg_rec_count
= 1;
5162 /* Record cpsr for hint and msr(immediate) instructions. */
5163 else if (reg_crn
== 0x02 || reg_crn
== 0x04)
5165 record_buf
[0] = AARCH64_CPSR_REGNUM
;
5166 aarch64_insn_r
->reg_rec_count
= 1;
5169 /* Unconditional branch (register). */
5170 else if((insn_bits24_27
& 0x0e) == 0x06)
5172 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_PC_REGNUM
;
5173 if (bits (aarch64_insn_r
->aarch64_insn
, 21, 22) == 0x01)
5174 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_LR_REGNUM
;
5177 return AARCH64_RECORD_UNKNOWN
;
5179 /* Unconditional branch (immediate). */
5180 else if ((insn_bits28_31
& 0x07) == 0x01 && (insn_bits24_27
& 0x0c) == 0x04)
5182 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_PC_REGNUM
;
5183 if (bit (aarch64_insn_r
->aarch64_insn
, 31))
5184 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_LR_REGNUM
;
5187 /* Compare & branch (immediate), Test & branch (immediate) and
5188 Conditional branch (immediate). */
5189 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_PC_REGNUM
;
5191 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
5193 return AARCH64_RECORD_SUCCESS
;
5196 /* Record handler for advanced SIMD load and store instructions. */
5199 aarch64_record_asimd_load_store (aarch64_insn_decode_record
*aarch64_insn_r
)
5202 uint64_t addr_offset
= 0;
5203 uint32_t record_buf
[24];
5204 std::vector
<uint64_t> record_buf_mem
;
5205 uint32_t reg_rn
, reg_rt
;
5206 uint32_t reg_index
= 0;
5207 uint8_t opcode_bits
, size_bits
;
5209 reg_rt
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
5210 reg_rn
= bits (aarch64_insn_r
->aarch64_insn
, 5, 9);
5211 size_bits
= bits (aarch64_insn_r
->aarch64_insn
, 10, 11);
5212 opcode_bits
= bits (aarch64_insn_r
->aarch64_insn
, 12, 15);
5213 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
, &address
);
5216 debug_printf ("Process record: Advanced SIMD load/store\n");
5218 /* Load/store single structure. */
5219 if (bit (aarch64_insn_r
->aarch64_insn
, 24))
5221 uint8_t sindex
, scale
, selem
, esize
, replicate
= 0;
5222 scale
= opcode_bits
>> 2;
5223 selem
= ((opcode_bits
& 0x02) |
5224 bit (aarch64_insn_r
->aarch64_insn
, 21)) + 1;
5228 if (size_bits
& 0x01)
5229 return AARCH64_RECORD_UNKNOWN
;
5232 if ((size_bits
>> 1) & 0x01)
5233 return AARCH64_RECORD_UNKNOWN
;
5234 if (size_bits
& 0x01)
5236 if (!((opcode_bits
>> 1) & 0x01))
5239 return AARCH64_RECORD_UNKNOWN
;
5243 if (bit (aarch64_insn_r
->aarch64_insn
, 22) && !(opcode_bits
& 0x01))
5250 return AARCH64_RECORD_UNKNOWN
;
5256 for (sindex
= 0; sindex
< selem
; sindex
++)
5258 record_buf
[reg_index
++] = reg_rt
+ AARCH64_V0_REGNUM
;
5259 reg_rt
= (reg_rt
+ 1) % 32;
5263 for (sindex
= 0; sindex
< selem
; sindex
++)
5265 if (bit (aarch64_insn_r
->aarch64_insn
, 22))
5266 record_buf
[reg_index
++] = reg_rt
+ AARCH64_V0_REGNUM
;
5269 record_buf_mem
.push_back (esize
/ 8);
5270 record_buf_mem
.push_back (address
+ addr_offset
);
5272 addr_offset
= addr_offset
+ (esize
/ 8);
5273 reg_rt
= (reg_rt
+ 1) % 32;
5277 /* Load/store multiple structure. */
5280 uint8_t selem
, esize
, rpt
, elements
;
5281 uint8_t eindex
, rindex
;
5283 esize
= 8 << size_bits
;
5284 if (bit (aarch64_insn_r
->aarch64_insn
, 30))
5285 elements
= 128 / esize
;
5287 elements
= 64 / esize
;
5289 switch (opcode_bits
)
5291 /*LD/ST4 (4 Registers). */
5296 /*LD/ST1 (4 Registers). */
5301 /*LD/ST3 (3 Registers). */
5306 /*LD/ST1 (3 Registers). */
5311 /*LD/ST1 (1 Register). */
5316 /*LD/ST2 (2 Registers). */
5321 /*LD/ST1 (2 Registers). */
5327 return AARCH64_RECORD_UNSUPPORTED
;
5330 for (rindex
= 0; rindex
< rpt
; rindex
++)
5331 for (eindex
= 0; eindex
< elements
; eindex
++)
5333 uint8_t reg_tt
, sindex
;
5334 reg_tt
= (reg_rt
+ rindex
) % 32;
5335 for (sindex
= 0; sindex
< selem
; sindex
++)
5337 if (bit (aarch64_insn_r
->aarch64_insn
, 22))
5338 record_buf
[reg_index
++] = reg_tt
+ AARCH64_V0_REGNUM
;
5341 record_buf_mem
.push_back (esize
/ 8);
5342 record_buf_mem
.push_back (address
+ addr_offset
);
5344 addr_offset
= addr_offset
+ (esize
/ 8);
5345 reg_tt
= (reg_tt
+ 1) % 32;
5350 if (bit (aarch64_insn_r
->aarch64_insn
, 23))
5351 record_buf
[reg_index
++] = reg_rn
;
5353 aarch64_insn_r
->reg_rec_count
= reg_index
;
5354 aarch64_insn_r
->mem_rec_count
= record_buf_mem
.size () / 2;
5355 MEM_ALLOC (aarch64_insn_r
->aarch64_mems
, aarch64_insn_r
->mem_rec_count
,
5356 record_buf_mem
.data ());
5357 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
5359 return AARCH64_RECORD_SUCCESS
;
5362 /* Record handler for Memory Copy and Memory Set instructions. */
5365 aarch64_record_memcopy_memset (aarch64_insn_decode_record
*aarch64_insn_r
)
5368 debug_printf ("Process record: memory copy and memory set\n");
5370 uint8_t op1
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
5371 uint8_t op2
= bits (aarch64_insn_r
->aarch64_insn
, 12, 15);
5372 uint32_t reg_rd
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
5373 uint32_t reg_rn
= bits (aarch64_insn_r
->aarch64_insn
, 5, 9);
5374 uint32_t record_buf
[3];
5375 uint64_t record_buf_mem
[4];
5377 if (op1
== 3 && op2
> 11)
5378 /* Unallocated instructions. */
5379 return AARCH64_RECORD_UNKNOWN
;
5381 /* Set instructions have two registers and one memory region to be
5383 record_buf
[0] = reg_rd
;
5384 record_buf
[1] = reg_rn
;
5385 aarch64_insn_r
->reg_rec_count
= 2;
5388 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rd
, &dest_addr
);
5391 regcache_raw_read_signed (aarch64_insn_r
->regcache
, reg_rn
, &length
);
5393 /* In one of the algorithm options a processor can implement, the length
5394 in Rn has an inverted sign. */
5398 record_buf_mem
[0] = length
;
5399 record_buf_mem
[1] = dest_addr
;
5400 aarch64_insn_r
->mem_rec_count
= 1;
5404 /* Copy instructions have an additional register and an additional
5405 memory region to be recorded. */
5406 uint32_t reg_rs
= bits (aarch64_insn_r
->aarch64_insn
, 16, 20);
5408 record_buf
[2] = reg_rs
;
5409 aarch64_insn_r
->reg_rec_count
++;
5411 ULONGEST source_addr
;
5412 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rs
,
5415 record_buf_mem
[2] = length
;
5416 record_buf_mem
[3] = source_addr
;
5417 aarch64_insn_r
->mem_rec_count
++;
5420 MEM_ALLOC (aarch64_insn_r
->aarch64_mems
, aarch64_insn_r
->mem_rec_count
,
5422 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
5424 return AARCH64_RECORD_SUCCESS
;
5427 /* Record handler for load and store instructions. */
5430 aarch64_record_load_store (aarch64_insn_decode_record
*aarch64_insn_r
)
5432 uint8_t insn_bits24_27
, insn_bits28_29
, insn_bits10_11
;
5433 uint8_t insn_bit23
, insn_bit21
;
5434 uint8_t opc
, size_bits
, ld_flag
, vector_flag
;
5435 uint32_t reg_rn
, reg_rt
, reg_rt2
;
5436 uint64_t datasize
, offset
;
5437 uint32_t record_buf
[8];
5438 uint64_t record_buf_mem
[8];
5441 insn_bits10_11
= bits (aarch64_insn_r
->aarch64_insn
, 10, 11);
5442 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
5443 insn_bits28_29
= bits (aarch64_insn_r
->aarch64_insn
, 28, 29);
5444 insn_bit21
= bit (aarch64_insn_r
->aarch64_insn
, 21);
5445 insn_bit23
= bit (aarch64_insn_r
->aarch64_insn
, 23);
5446 ld_flag
= bit (aarch64_insn_r
->aarch64_insn
, 22);
5447 vector_flag
= bit (aarch64_insn_r
->aarch64_insn
, 26);
5448 reg_rt
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
5449 reg_rn
= bits (aarch64_insn_r
->aarch64_insn
, 5, 9);
5450 reg_rt2
= bits (aarch64_insn_r
->aarch64_insn
, 10, 14);
5451 size_bits
= bits (aarch64_insn_r
->aarch64_insn
, 30, 31);
5453 /* Load/store exclusive. */
5454 if (insn_bits24_27
== 0x08 && insn_bits28_29
== 0x00)
5457 debug_printf ("Process record: load/store exclusive\n");
5461 record_buf
[0] = reg_rt
;
5462 aarch64_insn_r
->reg_rec_count
= 1;
5465 record_buf
[1] = reg_rt2
;
5466 aarch64_insn_r
->reg_rec_count
= 2;
5472 datasize
= (8 << size_bits
) * 2;
5474 datasize
= (8 << size_bits
);
5475 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
5477 record_buf_mem
[0] = datasize
/ 8;
5478 record_buf_mem
[1] = address
;
5479 aarch64_insn_r
->mem_rec_count
= 1;
5482 /* Save register rs. */
5483 record_buf
[0] = bits (aarch64_insn_r
->aarch64_insn
, 16, 20);
5484 aarch64_insn_r
->reg_rec_count
= 1;
5488 /* Load register (literal) instructions decoding. */
5489 else if ((insn_bits24_27
& 0x0b) == 0x08 && insn_bits28_29
== 0x01)
5492 debug_printf ("Process record: load register (literal)\n");
5494 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
5496 record_buf
[0] = reg_rt
;
5497 aarch64_insn_r
->reg_rec_count
= 1;
5499 /* All types of load/store pair instructions decoding. */
5500 else if ((insn_bits24_27
& 0x0a) == 0x08 && insn_bits28_29
== 0x02)
5503 debug_printf ("Process record: load/store pair\n");
5509 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
5510 record_buf
[1] = reg_rt2
+ AARCH64_V0_REGNUM
;
5514 record_buf
[0] = reg_rt
;
5515 record_buf
[1] = reg_rt2
;
5517 aarch64_insn_r
->reg_rec_count
= 2;
5522 imm7_off
= bits (aarch64_insn_r
->aarch64_insn
, 15, 21);
5524 size_bits
= size_bits
>> 1;
5525 datasize
= 8 << (2 + size_bits
);
5526 offset
= (imm7_off
& 0x40) ? (~imm7_off
& 0x007f) + 1 : imm7_off
;
5527 offset
= offset
<< (2 + size_bits
);
5528 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
5530 if (!((insn_bits24_27
& 0x0b) == 0x08 && insn_bit23
))
5532 if (imm7_off
& 0x40)
5533 address
= address
- offset
;
5535 address
= address
+ offset
;
5538 record_buf_mem
[0] = datasize
/ 8;
5539 record_buf_mem
[1] = address
;
5540 record_buf_mem
[2] = datasize
/ 8;
5541 record_buf_mem
[3] = address
+ (datasize
/ 8);
5542 aarch64_insn_r
->mem_rec_count
= 2;
5544 if (bit (aarch64_insn_r
->aarch64_insn
, 23))
5545 record_buf
[aarch64_insn_r
->reg_rec_count
++] = reg_rn
;
5547 /* Load/store register (unsigned immediate) instructions. */
5548 else if ((insn_bits24_27
& 0x0b) == 0x09 && insn_bits28_29
== 0x03)
5550 opc
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
5560 if (size_bits
== 0x3 && vector_flag
== 0x0 && opc
== 0x2)
5562 /* PRFM (immediate) */
5563 return AARCH64_RECORD_SUCCESS
;
5565 else if (size_bits
== 0x2 && vector_flag
== 0x0 && opc
== 0x2)
5567 /* LDRSW (immediate) */
5581 debug_printf ("Process record: load/store (unsigned immediate):"
5582 " size %x V %d opc %x\n", size_bits
, vector_flag
,
5588 offset
= bits (aarch64_insn_r
->aarch64_insn
, 10, 21);
5589 datasize
= 8 << size_bits
;
5590 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
5592 offset
= offset
<< size_bits
;
5593 address
= address
+ offset
;
5595 record_buf_mem
[0] = datasize
>> 3;
5596 record_buf_mem
[1] = address
;
5597 aarch64_insn_r
->mem_rec_count
= 1;
5602 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
5604 record_buf
[0] = reg_rt
;
5605 aarch64_insn_r
->reg_rec_count
= 1;
5608 /* Load/store register (register offset) instructions. */
5609 else if ((insn_bits24_27
& 0x0b) == 0x08 && insn_bits28_29
== 0x03
5610 && insn_bits10_11
== 0x02 && insn_bit21
)
5613 debug_printf ("Process record: load/store (register offset)\n");
5614 opc
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
5621 if (size_bits
!= 0x03)
5624 return AARCH64_RECORD_UNKNOWN
;
5628 ULONGEST reg_rm_val
;
5630 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
,
5631 bits (aarch64_insn_r
->aarch64_insn
, 16, 20), ®_rm_val
);
5632 if (bit (aarch64_insn_r
->aarch64_insn
, 12))
5633 offset
= reg_rm_val
<< size_bits
;
5635 offset
= reg_rm_val
;
5636 datasize
= 8 << size_bits
;
5637 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
5639 address
= address
+ offset
;
5640 record_buf_mem
[0] = datasize
>> 3;
5641 record_buf_mem
[1] = address
;
5642 aarch64_insn_r
->mem_rec_count
= 1;
5647 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
5649 record_buf
[0] = reg_rt
;
5650 aarch64_insn_r
->reg_rec_count
= 1;
5653 /* Load/store register (immediate and unprivileged) instructions. */
5654 else if ((insn_bits24_27
& 0x0b) == 0x08 && insn_bits28_29
== 0x03
5659 debug_printf ("Process record: load/store "
5660 "(immediate and unprivileged)\n");
5662 opc
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
5669 if (size_bits
!= 0x03)
5672 return AARCH64_RECORD_UNKNOWN
;
5677 imm9_off
= bits (aarch64_insn_r
->aarch64_insn
, 12, 20);
5678 offset
= (imm9_off
& 0x0100) ? (((~imm9_off
) & 0x01ff) + 1) : imm9_off
;
5679 datasize
= 8 << size_bits
;
5680 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
5682 if (insn_bits10_11
!= 0x01)
5684 if (imm9_off
& 0x0100)
5685 address
= address
- offset
;
5687 address
= address
+ offset
;
5689 record_buf_mem
[0] = datasize
>> 3;
5690 record_buf_mem
[1] = address
;
5691 aarch64_insn_r
->mem_rec_count
= 1;
5696 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
5698 record_buf
[0] = reg_rt
;
5699 aarch64_insn_r
->reg_rec_count
= 1;
5701 if (insn_bits10_11
== 0x01 || insn_bits10_11
== 0x03)
5702 record_buf
[aarch64_insn_r
->reg_rec_count
++] = reg_rn
;
5704 /* Memory Copy and Memory Set instructions. */
5705 else if ((insn_bits24_27
& 1) == 1 && insn_bits28_29
== 1
5706 && insn_bits10_11
== 1 && !insn_bit21
)
5707 return aarch64_record_memcopy_memset (aarch64_insn_r
);
5708 /* Advanced SIMD load/store instructions. */
5710 return aarch64_record_asimd_load_store (aarch64_insn_r
);
5712 MEM_ALLOC (aarch64_insn_r
->aarch64_mems
, aarch64_insn_r
->mem_rec_count
,
5714 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
5716 return AARCH64_RECORD_SUCCESS
;
5719 /* Record handler for data processing SIMD and floating point instructions. */
5722 aarch64_record_data_proc_simd_fp (aarch64_insn_decode_record
*aarch64_insn_r
)
5724 uint8_t insn_bit21
, opcode
, rmode
, reg_rd
;
5725 uint8_t insn_bits24_27
, insn_bits28_31
, insn_bits10_11
, insn_bits12_15
;
5726 uint8_t insn_bits11_14
;
5727 uint32_t record_buf
[2];
5729 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
5730 insn_bits28_31
= bits (aarch64_insn_r
->aarch64_insn
, 28, 31);
5731 insn_bits10_11
= bits (aarch64_insn_r
->aarch64_insn
, 10, 11);
5732 insn_bits12_15
= bits (aarch64_insn_r
->aarch64_insn
, 12, 15);
5733 insn_bits11_14
= bits (aarch64_insn_r
->aarch64_insn
, 11, 14);
5734 opcode
= bits (aarch64_insn_r
->aarch64_insn
, 16, 18);
5735 rmode
= bits (aarch64_insn_r
->aarch64_insn
, 19, 20);
5736 reg_rd
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
5737 insn_bit21
= bit (aarch64_insn_r
->aarch64_insn
, 21);
5740 debug_printf ("Process record: data processing SIMD/FP: ");
5742 if ((insn_bits28_31
& 0x05) == 0x01 && insn_bits24_27
== 0x0e)
5744 /* Floating point - fixed point conversion instructions. */
5748 debug_printf ("FP - fixed point conversion");
5750 if ((opcode
>> 1) == 0x0 && rmode
== 0x03)
5751 record_buf
[0] = reg_rd
;
5753 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
5755 /* Floating point - conditional compare instructions. */
5756 else if (insn_bits10_11
== 0x01)
5759 debug_printf ("FP - conditional compare");
5761 record_buf
[0] = AARCH64_CPSR_REGNUM
;
5763 /* Floating point - data processing (2-source) and
5764 conditional select instructions. */
5765 else if (insn_bits10_11
== 0x02 || insn_bits10_11
== 0x03)
5768 debug_printf ("FP - DP (2-source)");
5770 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
5772 else if (insn_bits10_11
== 0x00)
5774 /* Floating point - immediate instructions. */
5775 if ((insn_bits12_15
& 0x01) == 0x01
5776 || (insn_bits12_15
& 0x07) == 0x04)
5779 debug_printf ("FP - immediate");
5780 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
5782 /* Floating point - compare instructions. */
5783 else if ((insn_bits12_15
& 0x03) == 0x02)
5786 debug_printf ("FP - immediate");
5787 record_buf
[0] = AARCH64_CPSR_REGNUM
;
5789 /* Floating point - integer conversions instructions. */
5790 else if (insn_bits12_15
== 0x00)
5792 /* Convert float to integer instruction. */
5793 if (!(opcode
>> 1) || ((opcode
>> 1) == 0x02 && !rmode
))
5796 debug_printf ("float to int conversion");
5798 record_buf
[0] = reg_rd
+ AARCH64_X0_REGNUM
;
5800 /* Convert integer to float instruction. */
5801 else if ((opcode
>> 1) == 0x01 && !rmode
)
5804 debug_printf ("int to float conversion");
5806 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
5808 /* Move float to integer instruction. */
5809 else if ((opcode
>> 1) == 0x03)
5812 debug_printf ("move float to int");
5814 if (!(opcode
& 0x01))
5815 record_buf
[0] = reg_rd
+ AARCH64_X0_REGNUM
;
5817 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
5820 return AARCH64_RECORD_UNKNOWN
;
5823 return AARCH64_RECORD_UNKNOWN
;
5826 return AARCH64_RECORD_UNKNOWN
;
5828 else if ((insn_bits28_31
& 0x09) == 0x00 && insn_bits24_27
== 0x0e)
5831 debug_printf ("SIMD copy");
5833 /* Advanced SIMD copy instructions. */
5834 if (!bits (aarch64_insn_r
->aarch64_insn
, 21, 23)
5835 && !bit (aarch64_insn_r
->aarch64_insn
, 15)
5836 && bit (aarch64_insn_r
->aarch64_insn
, 10))
5838 if (insn_bits11_14
== 0x05 || insn_bits11_14
== 0x07)
5839 record_buf
[0] = reg_rd
+ AARCH64_X0_REGNUM
;
5841 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
5844 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
5846 /* All remaining floating point or advanced SIMD instructions. */
5850 debug_printf ("all remain");
5852 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
5856 debug_printf ("\n");
5858 /* Record the V/X register. */
5859 aarch64_insn_r
->reg_rec_count
++;
5861 /* Some of these instructions may set bits in the FPSR, so record it
5863 record_buf
[1] = AARCH64_FPSR_REGNUM
;
5864 aarch64_insn_r
->reg_rec_count
++;
5866 gdb_assert (aarch64_insn_r
->reg_rec_count
== 2);
5867 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
5869 return AARCH64_RECORD_SUCCESS
;
5872 /* Decodes insns type and invokes its record handler. */
5875 aarch64_record_decode_insn_handler (aarch64_insn_decode_record
*aarch64_insn_r
)
5877 uint32_t ins_bit25
, ins_bit26
, ins_bit27
, ins_bit28
;
5879 ins_bit25
= bit (aarch64_insn_r
->aarch64_insn
, 25);
5880 ins_bit26
= bit (aarch64_insn_r
->aarch64_insn
, 26);
5881 ins_bit27
= bit (aarch64_insn_r
->aarch64_insn
, 27);
5882 ins_bit28
= bit (aarch64_insn_r
->aarch64_insn
, 28);
5884 /* Data processing - immediate instructions. */
5885 if (!ins_bit26
&& !ins_bit27
&& ins_bit28
)
5886 return aarch64_record_data_proc_imm (aarch64_insn_r
);
5888 /* Branch, exception generation and system instructions. */
5889 if (ins_bit26
&& !ins_bit27
&& ins_bit28
)
5890 return aarch64_record_branch_except_sys (aarch64_insn_r
);
5892 /* Load and store instructions. */
5893 if (!ins_bit25
&& ins_bit27
)
5894 return aarch64_record_load_store (aarch64_insn_r
);
5896 /* Data processing - register instructions. */
5897 if (ins_bit25
&& !ins_bit26
&& ins_bit27
)
5898 return aarch64_record_data_proc_reg (aarch64_insn_r
);
5900 /* Data processing - SIMD and floating point instructions. */
5901 if (ins_bit25
&& ins_bit26
&& ins_bit27
)
5902 return aarch64_record_data_proc_simd_fp (aarch64_insn_r
);
5904 return AARCH64_RECORD_UNSUPPORTED
;
5907 /* Cleans up local record registers and memory allocations. */
5910 deallocate_reg_mem (aarch64_insn_decode_record
*record
)
5912 xfree (record
->aarch64_regs
);
5913 xfree (record
->aarch64_mems
);
5917 namespace selftests
{
5920 aarch64_process_record_test (void)
5922 struct gdbarch_info info
;
5925 info
.bfd_arch_info
= bfd_scan_arch ("aarch64");
5927 struct gdbarch
*gdbarch
= gdbarch_find_by_info (info
);
5928 SELF_CHECK (gdbarch
!= NULL
);
5930 aarch64_insn_decode_record aarch64_record
;
5932 memset (&aarch64_record
, 0, sizeof (aarch64_insn_decode_record
));
5933 aarch64_record
.regcache
= NULL
;
5934 aarch64_record
.this_addr
= 0;
5935 aarch64_record
.gdbarch
= gdbarch
;
5937 /* 20 00 80 f9 prfm pldl1keep, [x1] */
5938 aarch64_record
.aarch64_insn
= 0xf9800020;
5939 ret
= aarch64_record_decode_insn_handler (&aarch64_record
);
5940 SELF_CHECK (ret
== AARCH64_RECORD_SUCCESS
);
5941 SELF_CHECK (aarch64_record
.reg_rec_count
== 0);
5942 SELF_CHECK (aarch64_record
.mem_rec_count
== 0);
5944 deallocate_reg_mem (&aarch64_record
);
5947 } /* namespace selftests */
5948 #endif /* GDB_SELF_TEST */
5950 /* Parse the current instruction and record the values of the registers and
5951 memory that will be changed in current instruction to record_arch_list
5952 return -1 if something is wrong. */
5955 aarch64_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
5956 CORE_ADDR insn_addr
)
5958 uint32_t rec_no
= 0;
5959 const uint8_t insn_size
= 4;
5961 gdb_byte buf
[insn_size
];
5962 aarch64_insn_decode_record aarch64_record
;
5964 memset (&buf
[0], 0, insn_size
);
5965 memset (&aarch64_record
, 0, sizeof (aarch64_insn_decode_record
));
5966 target_read_memory (insn_addr
, &buf
[0], insn_size
);
5967 aarch64_record
.aarch64_insn
5968 = (uint32_t) extract_unsigned_integer (&buf
[0],
5970 gdbarch_byte_order (gdbarch
));
5971 aarch64_record
.regcache
= regcache
;
5972 aarch64_record
.this_addr
= insn_addr
;
5973 aarch64_record
.gdbarch
= gdbarch
;
5975 ret
= aarch64_record_decode_insn_handler (&aarch64_record
);
5976 if (ret
== AARCH64_RECORD_UNSUPPORTED
)
5978 gdb_printf (gdb_stderr
,
5979 _("Process record does not support instruction "
5980 "0x%0x at address %s.\n"),
5981 aarch64_record
.aarch64_insn
,
5982 paddress (gdbarch
, insn_addr
));
5988 /* Record registers. */
5989 record_full_arch_list_add_reg (aarch64_record
.regcache
,
5991 /* Always record register CPSR. */
5992 record_full_arch_list_add_reg (aarch64_record
.regcache
,
5993 AARCH64_CPSR_REGNUM
);
5994 if (aarch64_record
.aarch64_regs
)
5995 for (rec_no
= 0; rec_no
< aarch64_record
.reg_rec_count
; rec_no
++)
5996 if (record_full_arch_list_add_reg (aarch64_record
.regcache
,
5997 aarch64_record
.aarch64_regs
[rec_no
]))
6000 /* Record memories. */
6001 if (aarch64_record
.aarch64_mems
)
6002 for (rec_no
= 0; rec_no
< aarch64_record
.mem_rec_count
; rec_no
++)
6003 if (record_full_arch_list_add_mem
6004 ((CORE_ADDR
)aarch64_record
.aarch64_mems
[rec_no
].addr
,
6005 aarch64_record
.aarch64_mems
[rec_no
].len
))
6008 if (record_full_arch_list_add_end ())
6012 deallocate_reg_mem (&aarch64_record
);