1 /* Common target dependent code for GDB on AArch64 systems.
3 Copyright (C) 2009-2022 Free Software Foundation, Inc.
4 Contributed by ARM Ltd.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "reggroups.h"
30 #include "arch-utils.h"
32 #include "frame-unwind.h"
33 #include "frame-base.h"
34 #include "trad-frame.h"
37 #include "dwarf2/frame.h"
39 #include "prologue-value.h"
40 #include "target-descriptions.h"
41 #include "user-regs.h"
43 #include "gdbsupport/selftest.h"
45 #include "aarch64-tdep.h"
46 #include "aarch64-ravenscar-thread.h"
49 #include "record-full.h"
50 #include "arch/aarch64-insn.h"
53 #include "opcode/aarch64.h"
55 #include <unordered_map>
57 /* A Homogeneous Floating-Point or Short-Vector Aggregate may have at most
59 #define HA_MAX_NUM_FLDS 4
61 /* All possible aarch64 target descriptors. */
62 static std::unordered_map
<aarch64_features
, target_desc
*> tdesc_aarch64_map
;
64 /* The standard register names, and all the valid aliases for them. */
67 const char *const name
;
69 } aarch64_register_aliases
[] =
71 /* 64-bit register names. */
72 {"fp", AARCH64_FP_REGNUM
},
73 {"lr", AARCH64_LR_REGNUM
},
74 {"sp", AARCH64_SP_REGNUM
},
76 /* 32-bit register names. */
77 {"w0", AARCH64_X0_REGNUM
+ 0},
78 {"w1", AARCH64_X0_REGNUM
+ 1},
79 {"w2", AARCH64_X0_REGNUM
+ 2},
80 {"w3", AARCH64_X0_REGNUM
+ 3},
81 {"w4", AARCH64_X0_REGNUM
+ 4},
82 {"w5", AARCH64_X0_REGNUM
+ 5},
83 {"w6", AARCH64_X0_REGNUM
+ 6},
84 {"w7", AARCH64_X0_REGNUM
+ 7},
85 {"w8", AARCH64_X0_REGNUM
+ 8},
86 {"w9", AARCH64_X0_REGNUM
+ 9},
87 {"w10", AARCH64_X0_REGNUM
+ 10},
88 {"w11", AARCH64_X0_REGNUM
+ 11},
89 {"w12", AARCH64_X0_REGNUM
+ 12},
90 {"w13", AARCH64_X0_REGNUM
+ 13},
91 {"w14", AARCH64_X0_REGNUM
+ 14},
92 {"w15", AARCH64_X0_REGNUM
+ 15},
93 {"w16", AARCH64_X0_REGNUM
+ 16},
94 {"w17", AARCH64_X0_REGNUM
+ 17},
95 {"w18", AARCH64_X0_REGNUM
+ 18},
96 {"w19", AARCH64_X0_REGNUM
+ 19},
97 {"w20", AARCH64_X0_REGNUM
+ 20},
98 {"w21", AARCH64_X0_REGNUM
+ 21},
99 {"w22", AARCH64_X0_REGNUM
+ 22},
100 {"w23", AARCH64_X0_REGNUM
+ 23},
101 {"w24", AARCH64_X0_REGNUM
+ 24},
102 {"w25", AARCH64_X0_REGNUM
+ 25},
103 {"w26", AARCH64_X0_REGNUM
+ 26},
104 {"w27", AARCH64_X0_REGNUM
+ 27},
105 {"w28", AARCH64_X0_REGNUM
+ 28},
106 {"w29", AARCH64_X0_REGNUM
+ 29},
107 {"w30", AARCH64_X0_REGNUM
+ 30},
110 {"ip0", AARCH64_X0_REGNUM
+ 16},
111 {"ip1", AARCH64_X0_REGNUM
+ 17}
114 /* The required core 'R' registers. */
115 static const char *const aarch64_r_register_names
[] =
117 /* These registers must appear in consecutive RAW register number
118 order and they must begin with AARCH64_X0_REGNUM! */
119 "x0", "x1", "x2", "x3",
120 "x4", "x5", "x6", "x7",
121 "x8", "x9", "x10", "x11",
122 "x12", "x13", "x14", "x15",
123 "x16", "x17", "x18", "x19",
124 "x20", "x21", "x22", "x23",
125 "x24", "x25", "x26", "x27",
126 "x28", "x29", "x30", "sp",
130 /* The FP/SIMD 'V' registers. */
131 static const char *const aarch64_v_register_names
[] =
133 /* These registers must appear in consecutive RAW register number
134 order and they must begin with AARCH64_V0_REGNUM! */
135 "v0", "v1", "v2", "v3",
136 "v4", "v5", "v6", "v7",
137 "v8", "v9", "v10", "v11",
138 "v12", "v13", "v14", "v15",
139 "v16", "v17", "v18", "v19",
140 "v20", "v21", "v22", "v23",
141 "v24", "v25", "v26", "v27",
142 "v28", "v29", "v30", "v31",
147 /* The SVE 'Z' and 'P' registers. */
148 static const char *const aarch64_sve_register_names
[] =
150 /* These registers must appear in consecutive RAW register number
151 order and they must begin with AARCH64_SVE_Z0_REGNUM! */
152 "z0", "z1", "z2", "z3",
153 "z4", "z5", "z6", "z7",
154 "z8", "z9", "z10", "z11",
155 "z12", "z13", "z14", "z15",
156 "z16", "z17", "z18", "z19",
157 "z20", "z21", "z22", "z23",
158 "z24", "z25", "z26", "z27",
159 "z28", "z29", "z30", "z31",
161 "p0", "p1", "p2", "p3",
162 "p4", "p5", "p6", "p7",
163 "p8", "p9", "p10", "p11",
164 "p12", "p13", "p14", "p15",
168 static const char *const aarch64_pauth_register_names
[] =
170 /* Authentication mask for data pointer. */
172 /* Authentication mask for code pointer. */
176 static const char *const aarch64_mte_register_names
[] =
178 /* Tag Control Register. */
182 /* AArch64 prologue cache structure. */
183 struct aarch64_prologue_cache
185 /* The program counter at the start of the function. It is used to
186 identify this frame as a prologue frame. */
189 /* The program counter at the time this frame was created; i.e. where
190 this function was called from. It is used to identify this frame as a
194 /* The stack pointer at the time this frame was created; i.e. the
195 caller's stack pointer when this function was called. It is used
196 to identify this frame. */
199 /* Is the target available to read from? */
202 /* The frame base for this frame is just prev_sp - frame size.
203 FRAMESIZE is the distance from the frame pointer to the
204 initial stack pointer. */
207 /* The register used to hold the frame pointer for this frame. */
210 /* Saved register offsets. */
211 trad_frame_saved_reg
*saved_regs
;
215 show_aarch64_debug (struct ui_file
*file
, int from_tty
,
216 struct cmd_list_element
*c
, const char *value
)
218 gdb_printf (file
, _("AArch64 debugging is %s.\n"), value
);
223 /* Abstract instruction reader. */
225 class abstract_instruction_reader
228 /* Read in one instruction. */
229 virtual ULONGEST
read (CORE_ADDR memaddr
, int len
,
230 enum bfd_endian byte_order
) = 0;
233 /* Instruction reader from real target. */
235 class instruction_reader
: public abstract_instruction_reader
238 ULONGEST
read (CORE_ADDR memaddr
, int len
, enum bfd_endian byte_order
)
241 return read_code_unsigned_integer (memaddr
, len
, byte_order
);
247 /* If address signing is enabled, mask off the signature bits from the link
248 register, which is passed by value in ADDR, using the register values in
252 aarch64_frame_unmask_lr (aarch64_gdbarch_tdep
*tdep
,
253 struct frame_info
*this_frame
, CORE_ADDR addr
)
255 if (tdep
->has_pauth ()
256 && frame_unwind_register_unsigned (this_frame
,
257 tdep
->ra_sign_state_regnum
))
259 int cmask_num
= AARCH64_PAUTH_CMASK_REGNUM (tdep
->pauth_reg_base
);
260 CORE_ADDR cmask
= frame_unwind_register_unsigned (this_frame
, cmask_num
);
261 addr
= addr
& ~cmask
;
263 /* Record in the frame that the link register required unmasking. */
264 set_frame_previous_pc_masked (this_frame
);
270 /* Implement the "get_pc_address_flags" gdbarch method. */
273 aarch64_get_pc_address_flags (frame_info
*frame
, CORE_ADDR pc
)
275 if (pc
!= 0 && get_frame_pc_masked (frame
))
281 /* Analyze a prologue, looking for a recognizable stack frame
282 and frame pointer. Scan until we encounter a store that could
283 clobber the stack frame unexpectedly, or an unknown instruction. */
286 aarch64_analyze_prologue (struct gdbarch
*gdbarch
,
287 CORE_ADDR start
, CORE_ADDR limit
,
288 struct aarch64_prologue_cache
*cache
,
289 abstract_instruction_reader
& reader
)
291 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
294 /* Whether the stack has been set. This should be true when we notice a SP
295 to FP move or if we are using the SP as the base register for storing
296 data, in case the FP is ommitted. */
297 bool seen_stack_set
= false;
299 /* Track X registers and D registers in prologue. */
300 pv_t regs
[AARCH64_X_REGISTER_COUNT
+ AARCH64_D_REGISTER_COUNT
];
302 for (i
= 0; i
< AARCH64_X_REGISTER_COUNT
+ AARCH64_D_REGISTER_COUNT
; i
++)
303 regs
[i
] = pv_register (i
, 0);
304 pv_area
stack (AARCH64_SP_REGNUM
, gdbarch_addr_bit (gdbarch
));
306 for (; start
< limit
; start
+= 4)
311 insn
= reader
.read (start
, 4, byte_order_for_code
);
313 if (aarch64_decode_insn (insn
, &inst
, 1, NULL
) != 0)
316 if (inst
.opcode
->iclass
== addsub_imm
317 && (inst
.opcode
->op
== OP_ADD
318 || strcmp ("sub", inst
.opcode
->name
) == 0))
320 unsigned rd
= inst
.operands
[0].reg
.regno
;
321 unsigned rn
= inst
.operands
[1].reg
.regno
;
323 gdb_assert (aarch64_num_of_operands (inst
.opcode
) == 3);
324 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rd_SP
);
325 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_Rn_SP
);
326 gdb_assert (inst
.operands
[2].type
== AARCH64_OPND_AIMM
);
328 if (inst
.opcode
->op
== OP_ADD
)
330 regs
[rd
] = pv_add_constant (regs
[rn
],
331 inst
.operands
[2].imm
.value
);
335 regs
[rd
] = pv_add_constant (regs
[rn
],
336 -inst
.operands
[2].imm
.value
);
339 /* Did we move SP to FP? */
340 if (rn
== AARCH64_SP_REGNUM
&& rd
== AARCH64_FP_REGNUM
)
341 seen_stack_set
= true;
343 else if (inst
.opcode
->iclass
== addsub_ext
344 && strcmp ("sub", inst
.opcode
->name
) == 0)
346 unsigned rd
= inst
.operands
[0].reg
.regno
;
347 unsigned rn
= inst
.operands
[1].reg
.regno
;
348 unsigned rm
= inst
.operands
[2].reg
.regno
;
350 gdb_assert (aarch64_num_of_operands (inst
.opcode
) == 3);
351 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rd_SP
);
352 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_Rn_SP
);
353 gdb_assert (inst
.operands
[2].type
== AARCH64_OPND_Rm_EXT
);
355 regs
[rd
] = pv_subtract (regs
[rn
], regs
[rm
]);
357 else if (inst
.opcode
->iclass
== branch_imm
)
359 /* Stop analysis on branch. */
362 else if (inst
.opcode
->iclass
== condbranch
)
364 /* Stop analysis on branch. */
367 else if (inst
.opcode
->iclass
== branch_reg
)
369 /* Stop analysis on branch. */
372 else if (inst
.opcode
->iclass
== compbranch
)
374 /* Stop analysis on branch. */
377 else if (inst
.opcode
->op
== OP_MOVZ
)
379 unsigned rd
= inst
.operands
[0].reg
.regno
;
381 gdb_assert (aarch64_num_of_operands (inst
.opcode
) == 2);
382 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rd
);
383 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_HALF
);
384 gdb_assert (inst
.operands
[1].shifter
.kind
== AARCH64_MOD_LSL
);
386 /* If this shows up before we set the stack, keep going. Otherwise
387 stop the analysis. */
391 regs
[rd
] = pv_constant (inst
.operands
[1].imm
.value
392 << inst
.operands
[1].shifter
.amount
);
394 else if (inst
.opcode
->iclass
== log_shift
395 && strcmp (inst
.opcode
->name
, "orr") == 0)
397 unsigned rd
= inst
.operands
[0].reg
.regno
;
398 unsigned rn
= inst
.operands
[1].reg
.regno
;
399 unsigned rm
= inst
.operands
[2].reg
.regno
;
401 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rd
);
402 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_Rn
);
403 gdb_assert (inst
.operands
[2].type
== AARCH64_OPND_Rm_SFT
);
405 if (inst
.operands
[2].shifter
.amount
== 0
406 && rn
== AARCH64_SP_REGNUM
)
410 aarch64_debug_printf ("prologue analysis gave up "
411 "addr=%s opcode=0x%x (orr x register)",
412 core_addr_to_string_nz (start
), insn
);
417 else if (inst
.opcode
->op
== OP_STUR
)
419 unsigned rt
= inst
.operands
[0].reg
.regno
;
420 unsigned rn
= inst
.operands
[1].addr
.base_regno
;
421 int size
= aarch64_get_qualifier_esize (inst
.operands
[0].qualifier
);
423 gdb_assert (aarch64_num_of_operands (inst
.opcode
) == 2);
424 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rt
);
425 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_ADDR_SIMM9
);
426 gdb_assert (!inst
.operands
[1].addr
.offset
.is_reg
);
429 (pv_add_constant (regs
[rn
], inst
.operands
[1].addr
.offset
.imm
),
432 /* Are we storing with SP as a base? */
433 if (rn
== AARCH64_SP_REGNUM
)
434 seen_stack_set
= true;
436 else if ((inst
.opcode
->iclass
== ldstpair_off
437 || (inst
.opcode
->iclass
== ldstpair_indexed
438 && inst
.operands
[2].addr
.preind
))
439 && strcmp ("stp", inst
.opcode
->name
) == 0)
441 /* STP with addressing mode Pre-indexed and Base register. */
444 unsigned rn
= inst
.operands
[2].addr
.base_regno
;
445 int32_t imm
= inst
.operands
[2].addr
.offset
.imm
;
446 int size
= aarch64_get_qualifier_esize (inst
.operands
[0].qualifier
);
448 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rt
449 || inst
.operands
[0].type
== AARCH64_OPND_Ft
);
450 gdb_assert (inst
.operands
[1].type
== AARCH64_OPND_Rt2
451 || inst
.operands
[1].type
== AARCH64_OPND_Ft2
);
452 gdb_assert (inst
.operands
[2].type
== AARCH64_OPND_ADDR_SIMM7
);
453 gdb_assert (!inst
.operands
[2].addr
.offset
.is_reg
);
455 /* If recording this store would invalidate the store area
456 (perhaps because rn is not known) then we should abandon
457 further prologue analysis. */
458 if (stack
.store_would_trash (pv_add_constant (regs
[rn
], imm
)))
461 if (stack
.store_would_trash (pv_add_constant (regs
[rn
], imm
+ 8)))
464 rt1
= inst
.operands
[0].reg
.regno
;
465 rt2
= inst
.operands
[1].reg
.regno
;
466 if (inst
.operands
[0].type
== AARCH64_OPND_Ft
)
468 rt1
+= AARCH64_X_REGISTER_COUNT
;
469 rt2
+= AARCH64_X_REGISTER_COUNT
;
472 stack
.store (pv_add_constant (regs
[rn
], imm
), size
, regs
[rt1
]);
473 stack
.store (pv_add_constant (regs
[rn
], imm
+ size
), size
, regs
[rt2
]);
475 if (inst
.operands
[2].addr
.writeback
)
476 regs
[rn
] = pv_add_constant (regs
[rn
], imm
);
478 /* Ignore the instruction that allocates stack space and sets
480 if (rn
== AARCH64_SP_REGNUM
&& !inst
.operands
[2].addr
.writeback
)
481 seen_stack_set
= true;
483 else if ((inst
.opcode
->iclass
== ldst_imm9
/* Signed immediate. */
484 || (inst
.opcode
->iclass
== ldst_pos
/* Unsigned immediate. */
485 && (inst
.opcode
->op
== OP_STR_POS
486 || inst
.opcode
->op
== OP_STRF_POS
)))
487 && inst
.operands
[1].addr
.base_regno
== AARCH64_SP_REGNUM
488 && strcmp ("str", inst
.opcode
->name
) == 0)
490 /* STR (immediate) */
491 unsigned int rt
= inst
.operands
[0].reg
.regno
;
492 int32_t imm
= inst
.operands
[1].addr
.offset
.imm
;
493 unsigned int rn
= inst
.operands
[1].addr
.base_regno
;
494 int size
= aarch64_get_qualifier_esize (inst
.operands
[0].qualifier
);
495 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_Rt
496 || inst
.operands
[0].type
== AARCH64_OPND_Ft
);
498 if (inst
.operands
[0].type
== AARCH64_OPND_Ft
)
499 rt
+= AARCH64_X_REGISTER_COUNT
;
501 stack
.store (pv_add_constant (regs
[rn
], imm
), size
, regs
[rt
]);
502 if (inst
.operands
[1].addr
.writeback
)
503 regs
[rn
] = pv_add_constant (regs
[rn
], imm
);
505 /* Are we storing with SP as a base? */
506 if (rn
== AARCH64_SP_REGNUM
)
507 seen_stack_set
= true;
509 else if (inst
.opcode
->iclass
== testbranch
)
511 /* Stop analysis on branch. */
514 else if (inst
.opcode
->iclass
== ic_system
)
516 aarch64_gdbarch_tdep
*tdep
517 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
518 int ra_state_val
= 0;
520 if (insn
== 0xd503233f /* paciasp. */
521 || insn
== 0xd503237f /* pacibsp. */)
523 /* Return addresses are mangled. */
526 else if (insn
== 0xd50323bf /* autiasp. */
527 || insn
== 0xd50323ff /* autibsp. */)
529 /* Return addresses are not mangled. */
532 else if (IS_BTI (insn
))
533 /* We don't need to do anything special for a BTI instruction. */
537 aarch64_debug_printf ("prologue analysis gave up addr=%s"
538 " opcode=0x%x (iclass)",
539 core_addr_to_string_nz (start
), insn
);
543 if (tdep
->has_pauth () && cache
!= nullptr)
545 int regnum
= tdep
->ra_sign_state_regnum
;
546 cache
->saved_regs
[regnum
].set_value (ra_state_val
);
551 aarch64_debug_printf ("prologue analysis gave up addr=%s"
553 core_addr_to_string_nz (start
), insn
);
562 if (pv_is_register (regs
[AARCH64_FP_REGNUM
], AARCH64_SP_REGNUM
))
564 /* Frame pointer is fp. Frame size is constant. */
565 cache
->framereg
= AARCH64_FP_REGNUM
;
566 cache
->framesize
= -regs
[AARCH64_FP_REGNUM
].k
;
568 else if (pv_is_register (regs
[AARCH64_SP_REGNUM
], AARCH64_SP_REGNUM
))
570 /* Try the stack pointer. */
571 cache
->framesize
= -regs
[AARCH64_SP_REGNUM
].k
;
572 cache
->framereg
= AARCH64_SP_REGNUM
;
576 /* We're just out of luck. We don't know where the frame is. */
577 cache
->framereg
= -1;
578 cache
->framesize
= 0;
581 for (i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
585 if (stack
.find_reg (gdbarch
, i
, &offset
))
586 cache
->saved_regs
[i
].set_addr (offset
);
589 for (i
= 0; i
< AARCH64_D_REGISTER_COUNT
; i
++)
591 int regnum
= gdbarch_num_regs (gdbarch
);
594 if (stack
.find_reg (gdbarch
, i
+ AARCH64_X_REGISTER_COUNT
,
596 cache
->saved_regs
[i
+ regnum
+ AARCH64_D0_REGNUM
].set_addr (offset
);
603 aarch64_analyze_prologue (struct gdbarch
*gdbarch
,
604 CORE_ADDR start
, CORE_ADDR limit
,
605 struct aarch64_prologue_cache
*cache
)
607 instruction_reader reader
;
609 return aarch64_analyze_prologue (gdbarch
, start
, limit
, cache
,
615 namespace selftests
{
617 /* Instruction reader from manually cooked instruction sequences. */
619 class instruction_reader_test
: public abstract_instruction_reader
622 template<size_t SIZE
>
623 explicit instruction_reader_test (const uint32_t (&insns
)[SIZE
])
624 : m_insns (insns
), m_insns_size (SIZE
)
627 ULONGEST
read (CORE_ADDR memaddr
, int len
, enum bfd_endian byte_order
)
630 SELF_CHECK (len
== 4);
631 SELF_CHECK (memaddr
% 4 == 0);
632 SELF_CHECK (memaddr
/ 4 < m_insns_size
);
634 return m_insns
[memaddr
/ 4];
638 const uint32_t *m_insns
;
643 aarch64_analyze_prologue_test (void)
645 struct gdbarch_info info
;
647 info
.bfd_arch_info
= bfd_scan_arch ("aarch64");
649 struct gdbarch
*gdbarch
= gdbarch_find_by_info (info
);
650 SELF_CHECK (gdbarch
!= NULL
);
652 struct aarch64_prologue_cache cache
;
653 cache
.saved_regs
= trad_frame_alloc_saved_regs (gdbarch
);
655 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
657 /* Test the simple prologue in which frame pointer is used. */
659 static const uint32_t insns
[] = {
660 0xa9af7bfd, /* stp x29, x30, [sp,#-272]! */
661 0x910003fd, /* mov x29, sp */
662 0x97ffffe6, /* bl 0x400580 */
664 instruction_reader_test
reader (insns
);
666 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
667 SELF_CHECK (end
== 4 * 2);
669 SELF_CHECK (cache
.framereg
== AARCH64_FP_REGNUM
);
670 SELF_CHECK (cache
.framesize
== 272);
672 for (int i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
674 if (i
== AARCH64_FP_REGNUM
)
675 SELF_CHECK (cache
.saved_regs
[i
].addr () == -272);
676 else if (i
== AARCH64_LR_REGNUM
)
677 SELF_CHECK (cache
.saved_regs
[i
].addr () == -264);
679 SELF_CHECK (cache
.saved_regs
[i
].is_realreg ()
680 && cache
.saved_regs
[i
].realreg () == i
);
683 for (int i
= 0; i
< AARCH64_D_REGISTER_COUNT
; i
++)
685 int num_regs
= gdbarch_num_regs (gdbarch
);
686 int regnum
= i
+ num_regs
+ AARCH64_D0_REGNUM
;
688 SELF_CHECK (cache
.saved_regs
[regnum
].is_realreg ()
689 && cache
.saved_regs
[regnum
].realreg () == regnum
);
693 /* Test a prologue in which STR is used and frame pointer is not
696 static const uint32_t insns
[] = {
697 0xf81d0ff3, /* str x19, [sp, #-48]! */
698 0xb9002fe0, /* str w0, [sp, #44] */
699 0xf90013e1, /* str x1, [sp, #32]*/
700 0xfd000fe0, /* str d0, [sp, #24] */
701 0xaa0203f3, /* mov x19, x2 */
702 0xf94013e0, /* ldr x0, [sp, #32] */
704 instruction_reader_test
reader (insns
);
706 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
707 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
709 SELF_CHECK (end
== 4 * 5);
711 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
712 SELF_CHECK (cache
.framesize
== 48);
714 for (int i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
717 SELF_CHECK (cache
.saved_regs
[i
].addr () == -16);
719 SELF_CHECK (cache
.saved_regs
[i
].addr () == -48);
721 SELF_CHECK (cache
.saved_regs
[i
].is_realreg ()
722 && cache
.saved_regs
[i
].realreg () == i
);
725 for (int i
= 0; i
< AARCH64_D_REGISTER_COUNT
; i
++)
727 int num_regs
= gdbarch_num_regs (gdbarch
);
728 int regnum
= i
+ num_regs
+ AARCH64_D0_REGNUM
;
732 SELF_CHECK (cache
.saved_regs
[regnum
].addr () == -24);
734 SELF_CHECK (cache
.saved_regs
[regnum
].is_realreg ()
735 && cache
.saved_regs
[regnum
].realreg () == regnum
);
739 /* Test handling of movz before setting the frame pointer. */
741 static const uint32_t insns
[] = {
742 0xa9bf7bfd, /* stp x29, x30, [sp, #-16]! */
743 0x52800020, /* mov w0, #0x1 */
744 0x910003fd, /* mov x29, sp */
745 0x528000a2, /* mov w2, #0x5 */
746 0x97fffff8, /* bl 6e4 */
749 instruction_reader_test
reader (insns
);
751 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
752 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
754 /* We should stop at the 4th instruction. */
755 SELF_CHECK (end
== (4 - 1) * 4);
756 SELF_CHECK (cache
.framereg
== AARCH64_FP_REGNUM
);
757 SELF_CHECK (cache
.framesize
== 16);
760 /* Test handling of movz/stp when using the stack pointer as frame
763 static const uint32_t insns
[] = {
764 0xa9bc7bfd, /* stp x29, x30, [sp, #-64]! */
765 0x52800020, /* mov w0, #0x1 */
766 0x290207e0, /* stp w0, w1, [sp, #16] */
767 0xa9018fe2, /* stp x2, x3, [sp, #24] */
768 0x528000a2, /* mov w2, #0x5 */
769 0x97fffff8, /* bl 6e4 */
772 instruction_reader_test
reader (insns
);
774 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
775 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
777 /* We should stop at the 5th instruction. */
778 SELF_CHECK (end
== (5 - 1) * 4);
779 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
780 SELF_CHECK (cache
.framesize
== 64);
783 /* Test handling of movz/str when using the stack pointer as frame
786 static const uint32_t insns
[] = {
787 0xa9bc7bfd, /* stp x29, x30, [sp, #-64]! */
788 0x52800020, /* mov w0, #0x1 */
789 0xb9002be4, /* str w4, [sp, #40] */
790 0xf9001be5, /* str x5, [sp, #48] */
791 0x528000a2, /* mov w2, #0x5 */
792 0x97fffff8, /* bl 6e4 */
795 instruction_reader_test
reader (insns
);
797 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
798 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
800 /* We should stop at the 5th instruction. */
801 SELF_CHECK (end
== (5 - 1) * 4);
802 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
803 SELF_CHECK (cache
.framesize
== 64);
806 /* Test handling of movz/stur when using the stack pointer as frame
809 static const uint32_t insns
[] = {
810 0xa9bc7bfd, /* stp x29, x30, [sp, #-64]! */
811 0x52800020, /* mov w0, #0x1 */
812 0xb80343e6, /* stur w6, [sp, #52] */
813 0xf80383e7, /* stur x7, [sp, #56] */
814 0x528000a2, /* mov w2, #0x5 */
815 0x97fffff8, /* bl 6e4 */
818 instruction_reader_test
reader (insns
);
820 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
821 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
823 /* We should stop at the 5th instruction. */
824 SELF_CHECK (end
== (5 - 1) * 4);
825 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
826 SELF_CHECK (cache
.framesize
== 64);
829 /* Test handling of movz when there is no frame pointer set or no stack
832 static const uint32_t insns
[] = {
833 0xa9bf7bfd, /* stp x29, x30, [sp, #-16]! */
834 0x52800020, /* mov w0, #0x1 */
835 0x528000a2, /* mov w2, #0x5 */
836 0x97fffff8, /* bl 6e4 */
839 instruction_reader_test
reader (insns
);
841 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
842 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
, reader
);
844 /* We should stop at the 4th instruction. */
845 SELF_CHECK (end
== (4 - 1) * 4);
846 SELF_CHECK (cache
.framereg
== AARCH64_SP_REGNUM
);
847 SELF_CHECK (cache
.framesize
== 16);
850 /* Test a prologue in which there is a return address signing instruction. */
851 if (tdep
->has_pauth ())
853 static const uint32_t insns
[] = {
854 0xd503233f, /* paciasp */
855 0xa9bd7bfd, /* stp x29, x30, [sp, #-48]! */
856 0x910003fd, /* mov x29, sp */
857 0xf801c3f3, /* str x19, [sp, #28] */
858 0xb9401fa0, /* ldr x19, [x29, #28] */
860 instruction_reader_test
reader (insns
);
862 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
863 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
,
866 SELF_CHECK (end
== 4 * 4);
867 SELF_CHECK (cache
.framereg
== AARCH64_FP_REGNUM
);
868 SELF_CHECK (cache
.framesize
== 48);
870 for (int i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
873 SELF_CHECK (cache
.saved_regs
[i
].addr () == -20);
874 else if (i
== AARCH64_FP_REGNUM
)
875 SELF_CHECK (cache
.saved_regs
[i
].addr () == -48);
876 else if (i
== AARCH64_LR_REGNUM
)
877 SELF_CHECK (cache
.saved_regs
[i
].addr () == -40);
879 SELF_CHECK (cache
.saved_regs
[i
].is_realreg ()
880 && cache
.saved_regs
[i
].realreg () == i
);
883 if (tdep
->has_pauth ())
885 int regnum
= tdep
->ra_sign_state_regnum
;
886 SELF_CHECK (cache
.saved_regs
[regnum
].is_value ());
890 /* Test a prologue with a BTI instruction. */
892 static const uint32_t insns
[] = {
893 0xd503245f, /* bti */
894 0xa9bd7bfd, /* stp x29, x30, [sp, #-48]! */
895 0x910003fd, /* mov x29, sp */
896 0xf801c3f3, /* str x19, [sp, #28] */
897 0xb9401fa0, /* ldr x19, [x29, #28] */
899 instruction_reader_test
reader (insns
);
901 trad_frame_reset_saved_regs (gdbarch
, cache
.saved_regs
);
902 CORE_ADDR end
= aarch64_analyze_prologue (gdbarch
, 0, 128, &cache
,
905 SELF_CHECK (end
== 4 * 4);
906 SELF_CHECK (cache
.framereg
== AARCH64_FP_REGNUM
);
907 SELF_CHECK (cache
.framesize
== 48);
909 for (int i
= 0; i
< AARCH64_X_REGISTER_COUNT
; i
++)
912 SELF_CHECK (cache
.saved_regs
[i
].addr () == -20);
913 else if (i
== AARCH64_FP_REGNUM
)
914 SELF_CHECK (cache
.saved_regs
[i
].addr () == -48);
915 else if (i
== AARCH64_LR_REGNUM
)
916 SELF_CHECK (cache
.saved_regs
[i
].addr () == -40);
918 SELF_CHECK (cache
.saved_regs
[i
].is_realreg ()
919 && cache
.saved_regs
[i
].realreg () == i
);
923 } // namespace selftests
924 #endif /* GDB_SELF_TEST */
926 /* Implement the "skip_prologue" gdbarch method. */
929 aarch64_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
931 CORE_ADDR func_addr
, limit_pc
;
933 /* See if we can determine the end of the prologue via the symbol
934 table. If so, then return either PC, or the PC after the
935 prologue, whichever is greater. */
936 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
))
938 CORE_ADDR post_prologue_pc
939 = skip_prologue_using_sal (gdbarch
, func_addr
);
941 if (post_prologue_pc
!= 0)
942 return std::max (pc
, post_prologue_pc
);
945 /* Can't determine prologue from the symbol table, need to examine
948 /* Find an upper limit on the function prologue using the debug
949 information. If the debug information could not be used to
950 provide that bound, then use an arbitrary large number as the
952 limit_pc
= skip_prologue_using_sal (gdbarch
, pc
);
954 limit_pc
= pc
+ 128; /* Magic. */
956 /* Try disassembling prologue. */
957 return aarch64_analyze_prologue (gdbarch
, pc
, limit_pc
, NULL
);
960 /* Scan the function prologue for THIS_FRAME and populate the prologue
964 aarch64_scan_prologue (struct frame_info
*this_frame
,
965 struct aarch64_prologue_cache
*cache
)
967 CORE_ADDR block_addr
= get_frame_address_in_block (this_frame
);
968 CORE_ADDR prologue_start
;
969 CORE_ADDR prologue_end
;
970 CORE_ADDR prev_pc
= get_frame_pc (this_frame
);
971 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
973 cache
->prev_pc
= prev_pc
;
975 /* Assume we do not find a frame. */
976 cache
->framereg
= -1;
977 cache
->framesize
= 0;
979 if (find_pc_partial_function (block_addr
, NULL
, &prologue_start
,
982 struct symtab_and_line sal
= find_pc_line (prologue_start
, 0);
986 /* No line info so use the current PC. */
987 prologue_end
= prev_pc
;
989 else if (sal
.end
< prologue_end
)
991 /* The next line begins after the function end. */
992 prologue_end
= sal
.end
;
995 prologue_end
= std::min (prologue_end
, prev_pc
);
996 aarch64_analyze_prologue (gdbarch
, prologue_start
, prologue_end
, cache
);
1000 CORE_ADDR frame_loc
;
1002 frame_loc
= get_frame_register_unsigned (this_frame
, AARCH64_FP_REGNUM
);
1006 cache
->framereg
= AARCH64_FP_REGNUM
;
1007 cache
->framesize
= 16;
1008 cache
->saved_regs
[29].set_addr (0);
1009 cache
->saved_regs
[30].set_addr (8);
1013 /* Fill in *CACHE with information about the prologue of *THIS_FRAME. This
1014 function may throw an exception if the inferior's registers or memory is
1018 aarch64_make_prologue_cache_1 (struct frame_info
*this_frame
,
1019 struct aarch64_prologue_cache
*cache
)
1021 CORE_ADDR unwound_fp
;
1024 aarch64_scan_prologue (this_frame
, cache
);
1026 if (cache
->framereg
== -1)
1029 unwound_fp
= get_frame_register_unsigned (this_frame
, cache
->framereg
);
1030 if (unwound_fp
== 0)
1033 cache
->prev_sp
= unwound_fp
+ cache
->framesize
;
1035 /* Calculate actual addresses of saved registers using offsets
1036 determined by aarch64_analyze_prologue. */
1037 for (reg
= 0; reg
< gdbarch_num_regs (get_frame_arch (this_frame
)); reg
++)
1038 if (cache
->saved_regs
[reg
].is_addr ())
1039 cache
->saved_regs
[reg
].set_addr (cache
->saved_regs
[reg
].addr ()
1042 cache
->func
= get_frame_func (this_frame
);
1044 cache
->available_p
= 1;
1047 /* Allocate and fill in *THIS_CACHE with information about the prologue of
1048 *THIS_FRAME. Do not do this is if *THIS_CACHE was already allocated.
1049 Return a pointer to the current aarch64_prologue_cache in
1052 static struct aarch64_prologue_cache
*
1053 aarch64_make_prologue_cache (struct frame_info
*this_frame
, void **this_cache
)
1055 struct aarch64_prologue_cache
*cache
;
1057 if (*this_cache
!= NULL
)
1058 return (struct aarch64_prologue_cache
*) *this_cache
;
1060 cache
= FRAME_OBSTACK_ZALLOC (struct aarch64_prologue_cache
);
1061 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1062 *this_cache
= cache
;
1066 aarch64_make_prologue_cache_1 (this_frame
, cache
);
1068 catch (const gdb_exception_error
&ex
)
1070 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
1077 /* Implement the "stop_reason" frame_unwind method. */
1079 static enum unwind_stop_reason
1080 aarch64_prologue_frame_unwind_stop_reason (struct frame_info
*this_frame
,
1083 struct aarch64_prologue_cache
*cache
1084 = aarch64_make_prologue_cache (this_frame
, this_cache
);
1086 if (!cache
->available_p
)
1087 return UNWIND_UNAVAILABLE
;
1089 /* Halt the backtrace at "_start". */
1090 gdbarch
*arch
= get_frame_arch (this_frame
);
1091 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (arch
);
1092 if (cache
->prev_pc
<= tdep
->lowest_pc
)
1093 return UNWIND_OUTERMOST
;
1095 /* We've hit a wall, stop. */
1096 if (cache
->prev_sp
== 0)
1097 return UNWIND_OUTERMOST
;
1099 return UNWIND_NO_REASON
;
1102 /* Our frame ID for a normal frame is the current function's starting
1103 PC and the caller's SP when we were called. */
1106 aarch64_prologue_this_id (struct frame_info
*this_frame
,
1107 void **this_cache
, struct frame_id
*this_id
)
1109 struct aarch64_prologue_cache
*cache
1110 = aarch64_make_prologue_cache (this_frame
, this_cache
);
1112 if (!cache
->available_p
)
1113 *this_id
= frame_id_build_unavailable_stack (cache
->func
);
1115 *this_id
= frame_id_build (cache
->prev_sp
, cache
->func
);
1118 /* Implement the "prev_register" frame_unwind method. */
1120 static struct value
*
1121 aarch64_prologue_prev_register (struct frame_info
*this_frame
,
1122 void **this_cache
, int prev_regnum
)
1124 struct aarch64_prologue_cache
*cache
1125 = aarch64_make_prologue_cache (this_frame
, this_cache
);
1127 /* If we are asked to unwind the PC, then we need to return the LR
1128 instead. The prologue may save PC, but it will point into this
1129 frame's prologue, not the next frame's resume location. */
1130 if (prev_regnum
== AARCH64_PC_REGNUM
)
1133 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1134 aarch64_gdbarch_tdep
*tdep
1135 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1137 lr
= frame_unwind_register_unsigned (this_frame
, AARCH64_LR_REGNUM
);
1139 if (tdep
->has_pauth ()
1140 && cache
->saved_regs
[tdep
->ra_sign_state_regnum
].is_value ())
1141 lr
= aarch64_frame_unmask_lr (tdep
, this_frame
, lr
);
1143 return frame_unwind_got_constant (this_frame
, prev_regnum
, lr
);
1146 /* SP is generally not saved to the stack, but this frame is
1147 identified by the next frame's stack pointer at the time of the
1148 call. The value was already reconstructed into PREV_SP. */
1154 | | | <- Previous SP
1157 +--| saved fp |<- FP
1161 if (prev_regnum
== AARCH64_SP_REGNUM
)
1162 return frame_unwind_got_constant (this_frame
, prev_regnum
,
1165 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
,
1169 /* AArch64 prologue unwinder. */
1170 static frame_unwind aarch64_prologue_unwind
=
1174 aarch64_prologue_frame_unwind_stop_reason
,
1175 aarch64_prologue_this_id
,
1176 aarch64_prologue_prev_register
,
1178 default_frame_sniffer
1181 /* Allocate and fill in *THIS_CACHE with information about the prologue of
1182 *THIS_FRAME. Do not do this is if *THIS_CACHE was already allocated.
1183 Return a pointer to the current aarch64_prologue_cache in
1186 static struct aarch64_prologue_cache
*
1187 aarch64_make_stub_cache (struct frame_info
*this_frame
, void **this_cache
)
1189 struct aarch64_prologue_cache
*cache
;
1191 if (*this_cache
!= NULL
)
1192 return (struct aarch64_prologue_cache
*) *this_cache
;
1194 cache
= FRAME_OBSTACK_ZALLOC (struct aarch64_prologue_cache
);
1195 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1196 *this_cache
= cache
;
1200 cache
->prev_sp
= get_frame_register_unsigned (this_frame
,
1202 cache
->prev_pc
= get_frame_pc (this_frame
);
1203 cache
->available_p
= 1;
1205 catch (const gdb_exception_error
&ex
)
1207 if (ex
.error
!= NOT_AVAILABLE_ERROR
)
1214 /* Implement the "stop_reason" frame_unwind method. */
1216 static enum unwind_stop_reason
1217 aarch64_stub_frame_unwind_stop_reason (struct frame_info
*this_frame
,
1220 struct aarch64_prologue_cache
*cache
1221 = aarch64_make_stub_cache (this_frame
, this_cache
);
1223 if (!cache
->available_p
)
1224 return UNWIND_UNAVAILABLE
;
1226 return UNWIND_NO_REASON
;
1229 /* Our frame ID for a stub frame is the current SP and LR. */
1232 aarch64_stub_this_id (struct frame_info
*this_frame
,
1233 void **this_cache
, struct frame_id
*this_id
)
1235 struct aarch64_prologue_cache
*cache
1236 = aarch64_make_stub_cache (this_frame
, this_cache
);
1238 if (cache
->available_p
)
1239 *this_id
= frame_id_build (cache
->prev_sp
, cache
->prev_pc
);
1241 *this_id
= frame_id_build_unavailable_stack (cache
->prev_pc
);
1244 /* Implement the "sniffer" frame_unwind method. */
1247 aarch64_stub_unwind_sniffer (const struct frame_unwind
*self
,
1248 struct frame_info
*this_frame
,
1249 void **this_prologue_cache
)
1251 CORE_ADDR addr_in_block
;
1254 addr_in_block
= get_frame_address_in_block (this_frame
);
1255 if (in_plt_section (addr_in_block
)
1256 /* We also use the stub winder if the target memory is unreadable
1257 to avoid having the prologue unwinder trying to read it. */
1258 || target_read_memory (get_frame_pc (this_frame
), dummy
, 4) != 0)
1264 /* AArch64 stub unwinder. */
1265 static frame_unwind aarch64_stub_unwind
=
1269 aarch64_stub_frame_unwind_stop_reason
,
1270 aarch64_stub_this_id
,
1271 aarch64_prologue_prev_register
,
1273 aarch64_stub_unwind_sniffer
1276 /* Return the frame base address of *THIS_FRAME. */
1279 aarch64_normal_frame_base (struct frame_info
*this_frame
, void **this_cache
)
1281 struct aarch64_prologue_cache
*cache
1282 = aarch64_make_prologue_cache (this_frame
, this_cache
);
1284 return cache
->prev_sp
- cache
->framesize
;
1287 /* AArch64 default frame base information. */
1288 static frame_base aarch64_normal_base
=
1290 &aarch64_prologue_unwind
,
1291 aarch64_normal_frame_base
,
1292 aarch64_normal_frame_base
,
1293 aarch64_normal_frame_base
1296 /* Return the value of the REGNUM register in the previous frame of
1299 static struct value
*
1300 aarch64_dwarf2_prev_register (struct frame_info
*this_frame
,
1301 void **this_cache
, int regnum
)
1303 gdbarch
*arch
= get_frame_arch (this_frame
);
1304 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (arch
);
1309 case AARCH64_PC_REGNUM
:
1310 lr
= frame_unwind_register_unsigned (this_frame
, AARCH64_LR_REGNUM
);
1311 lr
= aarch64_frame_unmask_lr (tdep
, this_frame
, lr
);
1312 return frame_unwind_got_constant (this_frame
, regnum
, lr
);
1315 internal_error (__FILE__
, __LINE__
,
1316 _("Unexpected register %d"), regnum
);
1320 static const unsigned char op_lit0
= DW_OP_lit0
;
1321 static const unsigned char op_lit1
= DW_OP_lit1
;
1323 /* Implement the "init_reg" dwarf2_frame_ops method. */
1326 aarch64_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
1327 struct dwarf2_frame_state_reg
*reg
,
1328 struct frame_info
*this_frame
)
1330 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1334 case AARCH64_PC_REGNUM
:
1335 reg
->how
= DWARF2_FRAME_REG_FN
;
1336 reg
->loc
.fn
= aarch64_dwarf2_prev_register
;
1339 case AARCH64_SP_REGNUM
:
1340 reg
->how
= DWARF2_FRAME_REG_CFA
;
1344 /* Init pauth registers. */
1345 if (tdep
->has_pauth ())
1347 if (regnum
== tdep
->ra_sign_state_regnum
)
1349 /* Initialize RA_STATE to zero. */
1350 reg
->how
= DWARF2_FRAME_REG_SAVED_VAL_EXP
;
1351 reg
->loc
.exp
.start
= &op_lit0
;
1352 reg
->loc
.exp
.len
= 1;
1355 else if (regnum
== AARCH64_PAUTH_DMASK_REGNUM (tdep
->pauth_reg_base
)
1356 || regnum
== AARCH64_PAUTH_CMASK_REGNUM (tdep
->pauth_reg_base
))
1358 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1364 /* Implement the execute_dwarf_cfa_vendor_op method. */
1367 aarch64_execute_dwarf_cfa_vendor_op (struct gdbarch
*gdbarch
, gdb_byte op
,
1368 struct dwarf2_frame_state
*fs
)
1370 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
1371 struct dwarf2_frame_state_reg
*ra_state
;
1373 if (op
== DW_CFA_AARCH64_negate_ra_state
)
1375 /* On systems without pauth, treat as a nop. */
1376 if (!tdep
->has_pauth ())
1379 /* Allocate RA_STATE column if it's not allocated yet. */
1380 fs
->regs
.alloc_regs (AARCH64_DWARF_RA_SIGN_STATE
+ 1);
1382 /* Toggle the status of RA_STATE between 0 and 1. */
1383 ra_state
= &(fs
->regs
.reg
[AARCH64_DWARF_RA_SIGN_STATE
]);
1384 ra_state
->how
= DWARF2_FRAME_REG_SAVED_VAL_EXP
;
1386 if (ra_state
->loc
.exp
.start
== nullptr
1387 || ra_state
->loc
.exp
.start
== &op_lit0
)
1388 ra_state
->loc
.exp
.start
= &op_lit1
;
1390 ra_state
->loc
.exp
.start
= &op_lit0
;
1392 ra_state
->loc
.exp
.len
= 1;
1400 /* Used for matching BRK instructions for AArch64. */
1401 static constexpr uint32_t BRK_INSN_MASK
= 0xffe0001f;
1402 static constexpr uint32_t BRK_INSN_BASE
= 0xd4200000;
1404 /* Implementation of gdbarch_program_breakpoint_here_p for aarch64. */
1407 aarch64_program_breakpoint_here_p (gdbarch
*gdbarch
, CORE_ADDR address
)
1409 const uint32_t insn_len
= 4;
1410 gdb_byte target_mem
[4];
1412 /* Enable the automatic memory restoration from breakpoints while
1413 we read the memory. Otherwise we may find temporary breakpoints, ones
1414 inserted by GDB, and flag them as permanent breakpoints. */
1415 scoped_restore restore_memory
1416 = make_scoped_restore_show_memory_breakpoints (0);
1418 if (target_read_memory (address
, target_mem
, insn_len
) == 0)
1421 (uint32_t) extract_unsigned_integer (target_mem
, insn_len
,
1422 gdbarch_byte_order_for_code (gdbarch
));
1424 /* Check if INSN is a BRK instruction pattern. There are multiple choices
1425 of such instructions with different immediate values. Different OS'
1426 may use a different variation, but they have the same outcome. */
1427 return ((insn
& BRK_INSN_MASK
) == BRK_INSN_BASE
);
1433 /* When arguments must be pushed onto the stack, they go on in reverse
1434 order. The code below implements a FILO (stack) to do this. */
1438 /* Value to pass on stack. It can be NULL if this item is for stack
1440 const gdb_byte
*data
;
1442 /* Size in bytes of value to pass on stack. */
1446 /* Implement the gdbarch type alignment method, overrides the generic
1447 alignment algorithm for anything that is aarch64 specific. */
1450 aarch64_type_align (gdbarch
*gdbarch
, struct type
*t
)
1452 t
= check_typedef (t
);
1453 if (t
->code () == TYPE_CODE_ARRAY
&& t
->is_vector ())
1455 /* Use the natural alignment for vector types (the same for
1456 scalar type), but the maximum alignment is 128-bit. */
1457 if (t
->length () > 16)
1460 return t
->length ();
1463 /* Allow the common code to calculate the alignment. */
1467 /* Worker function for aapcs_is_vfp_call_or_return_candidate.
1469 Return the number of register required, or -1 on failure.
1471 When encountering a base element, if FUNDAMENTAL_TYPE is not set then set it
1472 to the element, else fail if the type of this element does not match the
1476 aapcs_is_vfp_call_or_return_candidate_1 (struct type
*type
,
1477 struct type
**fundamental_type
)
1479 if (type
== nullptr)
1482 switch (type
->code ())
1485 case TYPE_CODE_DECFLOAT
:
1486 if (type
->length () > 16)
1489 if (*fundamental_type
== nullptr)
1490 *fundamental_type
= type
;
1491 else if (type
->length () != (*fundamental_type
)->length ()
1492 || type
->code () != (*fundamental_type
)->code ())
1497 case TYPE_CODE_COMPLEX
:
1499 struct type
*target_type
= check_typedef (type
->target_type ());
1500 if (target_type
->length () > 16)
1503 if (*fundamental_type
== nullptr)
1504 *fundamental_type
= target_type
;
1505 else if (target_type
->length () != (*fundamental_type
)->length ()
1506 || target_type
->code () != (*fundamental_type
)->code ())
1512 case TYPE_CODE_ARRAY
:
1514 if (type
->is_vector ())
1516 if (type
->length () != 8 && type
->length () != 16)
1519 if (*fundamental_type
== nullptr)
1520 *fundamental_type
= type
;
1521 else if (type
->length () != (*fundamental_type
)->length ()
1522 || type
->code () != (*fundamental_type
)->code ())
1529 struct type
*target_type
= type
->target_type ();
1530 int count
= aapcs_is_vfp_call_or_return_candidate_1
1531 (target_type
, fundamental_type
);
1536 count
*= (type
->length () / target_type
->length ());
1541 case TYPE_CODE_STRUCT
:
1542 case TYPE_CODE_UNION
:
1546 for (int i
= 0; i
< type
->num_fields (); i
++)
1548 /* Ignore any static fields. */
1549 if (field_is_static (&type
->field (i
)))
1552 struct type
*member
= check_typedef (type
->field (i
).type ());
1554 int sub_count
= aapcs_is_vfp_call_or_return_candidate_1
1555 (member
, fundamental_type
);
1556 if (sub_count
== -1)
1561 /* Ensure there is no padding between the fields (allowing for empty
1562 zero length structs) */
1563 int ftype_length
= (*fundamental_type
== nullptr)
1564 ? 0 : (*fundamental_type
)->length ();
1565 if (count
* ftype_length
!= type
->length ())
1578 /* Return true if an argument, whose type is described by TYPE, can be passed or
1579 returned in simd/fp registers, providing enough parameter passing registers
1580 are available. This is as described in the AAPCS64.
1582 Upon successful return, *COUNT returns the number of needed registers,
1583 *FUNDAMENTAL_TYPE contains the type of those registers.
1585 Candidate as per the AAPCS64 5.4.2.C is either a:
1588 - HFA (Homogeneous Floating-point Aggregate, 4.3.5.1). A Composite type where
1589 all the members are floats and has at most 4 members.
1590 - HVA (Homogeneous Short-vector Aggregate, 4.3.5.2). A Composite type where
1591 all the members are short vectors and has at most 4 members.
1594 Note that HFAs and HVAs can include nested structures and arrays. */
1597 aapcs_is_vfp_call_or_return_candidate (struct type
*type
, int *count
,
1598 struct type
**fundamental_type
)
1600 if (type
== nullptr)
1603 *fundamental_type
= nullptr;
1605 int ag_count
= aapcs_is_vfp_call_or_return_candidate_1 (type
,
1608 if (ag_count
> 0 && ag_count
<= HA_MAX_NUM_FLDS
)
1617 /* AArch64 function call information structure. */
1618 struct aarch64_call_info
1620 /* the current argument number. */
1621 unsigned argnum
= 0;
1623 /* The next general purpose register number, equivalent to NGRN as
1624 described in the AArch64 Procedure Call Standard. */
1627 /* The next SIMD and floating point register number, equivalent to
1628 NSRN as described in the AArch64 Procedure Call Standard. */
1631 /* The next stacked argument address, equivalent to NSAA as
1632 described in the AArch64 Procedure Call Standard. */
1635 /* Stack item vector. */
1636 std::vector
<stack_item_t
> si
;
1639 /* Pass a value in a sequence of consecutive X registers. The caller
1640 is responsible for ensuring sufficient registers are available. */
1643 pass_in_x (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1644 struct aarch64_call_info
*info
, struct type
*type
,
1647 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1648 int len
= type
->length ();
1649 enum type_code typecode
= type
->code ();
1650 int regnum
= AARCH64_X0_REGNUM
+ info
->ngrn
;
1651 const bfd_byte
*buf
= value_contents (arg
).data ();
1657 int partial_len
= len
< X_REGISTER_SIZE
? len
: X_REGISTER_SIZE
;
1658 CORE_ADDR regval
= extract_unsigned_integer (buf
, partial_len
,
1662 /* Adjust sub-word struct/union args when big-endian. */
1663 if (byte_order
== BFD_ENDIAN_BIG
1664 && partial_len
< X_REGISTER_SIZE
1665 && (typecode
== TYPE_CODE_STRUCT
|| typecode
== TYPE_CODE_UNION
))
1666 regval
<<= ((X_REGISTER_SIZE
- partial_len
) * TARGET_CHAR_BIT
);
1668 aarch64_debug_printf ("arg %d in %s = 0x%s", info
->argnum
,
1669 gdbarch_register_name (gdbarch
, regnum
),
1670 phex (regval
, X_REGISTER_SIZE
));
1672 regcache_cooked_write_unsigned (regcache
, regnum
, regval
);
1679 /* Attempt to marshall a value in a V register. Return 1 if
1680 successful, or 0 if insufficient registers are available. This
1681 function, unlike the equivalent pass_in_x() function does not
1682 handle arguments spread across multiple registers. */
1685 pass_in_v (struct gdbarch
*gdbarch
,
1686 struct regcache
*regcache
,
1687 struct aarch64_call_info
*info
,
1688 int len
, const bfd_byte
*buf
)
1692 int regnum
= AARCH64_V0_REGNUM
+ info
->nsrn
;
1693 /* Enough space for a full vector register. */
1694 gdb_byte reg
[register_size (gdbarch
, regnum
)];
1695 gdb_assert (len
<= sizeof (reg
));
1700 memset (reg
, 0, sizeof (reg
));
1701 /* PCS C.1, the argument is allocated to the least significant
1702 bits of V register. */
1703 memcpy (reg
, buf
, len
);
1704 regcache
->cooked_write (regnum
, reg
);
1706 aarch64_debug_printf ("arg %d in %s", info
->argnum
,
1707 gdbarch_register_name (gdbarch
, regnum
));
1715 /* Marshall an argument onto the stack. */
1718 pass_on_stack (struct aarch64_call_info
*info
, struct type
*type
,
1721 const bfd_byte
*buf
= value_contents (arg
).data ();
1722 int len
= type
->length ();
1728 align
= type_align (type
);
1730 /* PCS C.17 Stack should be aligned to the larger of 8 bytes or the
1731 Natural alignment of the argument's type. */
1732 align
= align_up (align
, 8);
1734 /* The AArch64 PCS requires at most doubleword alignment. */
1738 aarch64_debug_printf ("arg %d len=%d @ sp + %d\n", info
->argnum
, len
,
1743 info
->si
.push_back (item
);
1746 if (info
->nsaa
& (align
- 1))
1748 /* Push stack alignment padding. */
1749 int pad
= align
- (info
->nsaa
& (align
- 1));
1754 info
->si
.push_back (item
);
1759 /* Marshall an argument into a sequence of one or more consecutive X
1760 registers or, if insufficient X registers are available then onto
1764 pass_in_x_or_stack (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1765 struct aarch64_call_info
*info
, struct type
*type
,
1768 int len
= type
->length ();
1769 int nregs
= (len
+ X_REGISTER_SIZE
- 1) / X_REGISTER_SIZE
;
1771 /* PCS C.13 - Pass in registers if we have enough spare */
1772 if (info
->ngrn
+ nregs
<= 8)
1774 pass_in_x (gdbarch
, regcache
, info
, type
, arg
);
1775 info
->ngrn
+= nregs
;
1780 pass_on_stack (info
, type
, arg
);
1784 /* Pass a value, which is of type arg_type, in a V register. Assumes value is a
1785 aapcs_is_vfp_call_or_return_candidate and there are enough spare V
1786 registers. A return value of false is an error state as the value will have
1787 been partially passed to the stack. */
1789 pass_in_v_vfp_candidate (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1790 struct aarch64_call_info
*info
, struct type
*arg_type
,
1793 switch (arg_type
->code ())
1796 case TYPE_CODE_DECFLOAT
:
1797 return pass_in_v (gdbarch
, regcache
, info
, arg_type
->length (),
1798 value_contents (arg
).data ());
1801 case TYPE_CODE_COMPLEX
:
1803 const bfd_byte
*buf
= value_contents (arg
).data ();
1804 struct type
*target_type
= check_typedef (arg_type
->target_type ());
1806 if (!pass_in_v (gdbarch
, regcache
, info
, target_type
->length (),
1810 return pass_in_v (gdbarch
, regcache
, info
, target_type
->length (),
1811 buf
+ target_type
->length ());
1814 case TYPE_CODE_ARRAY
:
1815 if (arg_type
->is_vector ())
1816 return pass_in_v (gdbarch
, regcache
, info
, arg_type
->length (),
1817 value_contents (arg
).data ());
1820 case TYPE_CODE_STRUCT
:
1821 case TYPE_CODE_UNION
:
1822 for (int i
= 0; i
< arg_type
->num_fields (); i
++)
1824 /* Don't include static fields. */
1825 if (field_is_static (&arg_type
->field (i
)))
1828 struct value
*field
= value_primitive_field (arg
, 0, i
, arg_type
);
1829 struct type
*field_type
= check_typedef (value_type (field
));
1831 if (!pass_in_v_vfp_candidate (gdbarch
, regcache
, info
, field_type
,
1842 /* Implement the "push_dummy_call" gdbarch method. */
1845 aarch64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
1846 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1848 struct value
**args
, CORE_ADDR sp
,
1849 function_call_return_method return_method
,
1850 CORE_ADDR struct_addr
)
1853 struct aarch64_call_info info
;
1855 /* We need to know what the type of the called function is in order
1856 to determine the number of named/anonymous arguments for the
1857 actual argument placement, and the return type in order to handle
1858 return value correctly.
1860 The generic code above us views the decision of return in memory
1861 or return in registers as a two stage processes. The language
1862 handler is consulted first and may decide to return in memory (eg
1863 class with copy constructor returned by value), this will cause
1864 the generic code to allocate space AND insert an initial leading
1867 If the language code does not decide to pass in memory then the
1868 target code is consulted.
1870 If the language code decides to pass in memory we want to move
1871 the pointer inserted as the initial argument from the argument
1872 list and into X8, the conventional AArch64 struct return pointer
1875 /* Set the return address. For the AArch64, the return breakpoint
1876 is always at BP_ADDR. */
1877 regcache_cooked_write_unsigned (regcache
, AARCH64_LR_REGNUM
, bp_addr
);
1879 /* If we were given an initial argument for the return slot, lose it. */
1880 if (return_method
== return_method_hidden_param
)
1886 /* The struct_return pointer occupies X8. */
1887 if (return_method
!= return_method_normal
)
1889 aarch64_debug_printf ("struct return in %s = 0x%s",
1890 gdbarch_register_name
1891 (gdbarch
, AARCH64_STRUCT_RETURN_REGNUM
),
1892 paddress (gdbarch
, struct_addr
));
1894 regcache_cooked_write_unsigned (regcache
, AARCH64_STRUCT_RETURN_REGNUM
,
1898 for (argnum
= 0; argnum
< nargs
; argnum
++)
1900 struct value
*arg
= args
[argnum
];
1901 struct type
*arg_type
, *fundamental_type
;
1904 arg_type
= check_typedef (value_type (arg
));
1905 len
= arg_type
->length ();
1907 /* If arg can be passed in v registers as per the AAPCS64, then do so if
1908 if there are enough spare registers. */
1909 if (aapcs_is_vfp_call_or_return_candidate (arg_type
, &elements
,
1912 if (info
.nsrn
+ elements
<= 8)
1914 /* We know that we have sufficient registers available therefore
1915 this will never need to fallback to the stack. */
1916 if (!pass_in_v_vfp_candidate (gdbarch
, regcache
, &info
, arg_type
,
1918 gdb_assert_not_reached ("Failed to push args");
1923 pass_on_stack (&info
, arg_type
, arg
);
1928 switch (arg_type
->code ())
1931 case TYPE_CODE_BOOL
:
1932 case TYPE_CODE_CHAR
:
1933 case TYPE_CODE_RANGE
:
1934 case TYPE_CODE_ENUM
:
1935 if (len
< 4 && !is_fixed_point_type (arg_type
))
1937 /* Promote to 32 bit integer. */
1938 if (arg_type
->is_unsigned ())
1939 arg_type
= builtin_type (gdbarch
)->builtin_uint32
;
1941 arg_type
= builtin_type (gdbarch
)->builtin_int32
;
1942 arg
= value_cast (arg_type
, arg
);
1944 pass_in_x_or_stack (gdbarch
, regcache
, &info
, arg_type
, arg
);
1947 case TYPE_CODE_STRUCT
:
1948 case TYPE_CODE_ARRAY
:
1949 case TYPE_CODE_UNION
:
1952 /* PCS B.7 Aggregates larger than 16 bytes are passed by
1953 invisible reference. */
1955 /* Allocate aligned storage. */
1956 sp
= align_down (sp
- len
, 16);
1958 /* Write the real data into the stack. */
1959 write_memory (sp
, value_contents (arg
).data (), len
);
1961 /* Construct the indirection. */
1962 arg_type
= lookup_pointer_type (arg_type
);
1963 arg
= value_from_pointer (arg_type
, sp
);
1964 pass_in_x_or_stack (gdbarch
, regcache
, &info
, arg_type
, arg
);
1967 /* PCS C.15 / C.18 multiple values pass. */
1968 pass_in_x_or_stack (gdbarch
, regcache
, &info
, arg_type
, arg
);
1972 pass_in_x_or_stack (gdbarch
, regcache
, &info
, arg_type
, arg
);
1977 /* Make sure stack retains 16 byte alignment. */
1979 sp
-= 16 - (info
.nsaa
& 15);
1981 while (!info
.si
.empty ())
1983 const stack_item_t
&si
= info
.si
.back ();
1986 if (si
.data
!= NULL
)
1987 write_memory (sp
, si
.data
, si
.len
);
1988 info
.si
.pop_back ();
1991 /* Finally, update the SP register. */
1992 regcache_cooked_write_unsigned (regcache
, AARCH64_SP_REGNUM
, sp
);
1997 /* Implement the "frame_align" gdbarch method. */
2000 aarch64_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
2002 /* Align the stack to sixteen bytes. */
2003 return sp
& ~(CORE_ADDR
) 15;
2006 /* Return the type for an AdvSISD Q register. */
2008 static struct type
*
2009 aarch64_vnq_type (struct gdbarch
*gdbarch
)
2011 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2013 if (tdep
->vnq_type
== NULL
)
2018 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnq",
2021 elem
= builtin_type (gdbarch
)->builtin_uint128
;
2022 append_composite_type_field (t
, "u", elem
);
2024 elem
= builtin_type (gdbarch
)->builtin_int128
;
2025 append_composite_type_field (t
, "s", elem
);
2030 return tdep
->vnq_type
;
2033 /* Return the type for an AdvSISD D register. */
2035 static struct type
*
2036 aarch64_vnd_type (struct gdbarch
*gdbarch
)
2038 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2040 if (tdep
->vnd_type
== NULL
)
2045 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnd",
2048 elem
= builtin_type (gdbarch
)->builtin_double
;
2049 append_composite_type_field (t
, "f", elem
);
2051 elem
= builtin_type (gdbarch
)->builtin_uint64
;
2052 append_composite_type_field (t
, "u", elem
);
2054 elem
= builtin_type (gdbarch
)->builtin_int64
;
2055 append_composite_type_field (t
, "s", elem
);
2060 return tdep
->vnd_type
;
2063 /* Return the type for an AdvSISD S register. */
2065 static struct type
*
2066 aarch64_vns_type (struct gdbarch
*gdbarch
)
2068 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2070 if (tdep
->vns_type
== NULL
)
2075 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vns",
2078 elem
= builtin_type (gdbarch
)->builtin_float
;
2079 append_composite_type_field (t
, "f", elem
);
2081 elem
= builtin_type (gdbarch
)->builtin_uint32
;
2082 append_composite_type_field (t
, "u", elem
);
2084 elem
= builtin_type (gdbarch
)->builtin_int32
;
2085 append_composite_type_field (t
, "s", elem
);
2090 return tdep
->vns_type
;
2093 /* Return the type for an AdvSISD H register. */
2095 static struct type
*
2096 aarch64_vnh_type (struct gdbarch
*gdbarch
)
2098 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2100 if (tdep
->vnh_type
== NULL
)
2105 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnh",
2108 elem
= builtin_type (gdbarch
)->builtin_bfloat16
;
2109 append_composite_type_field (t
, "bf", elem
);
2111 elem
= builtin_type (gdbarch
)->builtin_half
;
2112 append_composite_type_field (t
, "f", elem
);
2114 elem
= builtin_type (gdbarch
)->builtin_uint16
;
2115 append_composite_type_field (t
, "u", elem
);
2117 elem
= builtin_type (gdbarch
)->builtin_int16
;
2118 append_composite_type_field (t
, "s", elem
);
2123 return tdep
->vnh_type
;
2126 /* Return the type for an AdvSISD B register. */
2128 static struct type
*
2129 aarch64_vnb_type (struct gdbarch
*gdbarch
)
2131 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2133 if (tdep
->vnb_type
== NULL
)
2138 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnb",
2141 elem
= builtin_type (gdbarch
)->builtin_uint8
;
2142 append_composite_type_field (t
, "u", elem
);
2144 elem
= builtin_type (gdbarch
)->builtin_int8
;
2145 append_composite_type_field (t
, "s", elem
);
2150 return tdep
->vnb_type
;
2153 /* Return the type for an AdvSISD V register. */
2155 static struct type
*
2156 aarch64_vnv_type (struct gdbarch
*gdbarch
)
2158 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2160 if (tdep
->vnv_type
== NULL
)
2162 /* The other AArch64 pseudo registers (Q,D,H,S,B) refer to a single value
2163 slice from the non-pseudo vector registers. However NEON V registers
2164 are always vector registers, and need constructing as such. */
2165 const struct builtin_type
*bt
= builtin_type (gdbarch
);
2167 struct type
*t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnv",
2170 struct type
*sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnd",
2172 append_composite_type_field (sub
, "f",
2173 init_vector_type (bt
->builtin_double
, 2));
2174 append_composite_type_field (sub
, "u",
2175 init_vector_type (bt
->builtin_uint64
, 2));
2176 append_composite_type_field (sub
, "s",
2177 init_vector_type (bt
->builtin_int64
, 2));
2178 append_composite_type_field (t
, "d", sub
);
2180 sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vns",
2182 append_composite_type_field (sub
, "f",
2183 init_vector_type (bt
->builtin_float
, 4));
2184 append_composite_type_field (sub
, "u",
2185 init_vector_type (bt
->builtin_uint32
, 4));
2186 append_composite_type_field (sub
, "s",
2187 init_vector_type (bt
->builtin_int32
, 4));
2188 append_composite_type_field (t
, "s", sub
);
2190 sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnh",
2192 append_composite_type_field (sub
, "bf",
2193 init_vector_type (bt
->builtin_bfloat16
, 8));
2194 append_composite_type_field (sub
, "f",
2195 init_vector_type (bt
->builtin_half
, 8));
2196 append_composite_type_field (sub
, "u",
2197 init_vector_type (bt
->builtin_uint16
, 8));
2198 append_composite_type_field (sub
, "s",
2199 init_vector_type (bt
->builtin_int16
, 8));
2200 append_composite_type_field (t
, "h", sub
);
2202 sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnb",
2204 append_composite_type_field (sub
, "u",
2205 init_vector_type (bt
->builtin_uint8
, 16));
2206 append_composite_type_field (sub
, "s",
2207 init_vector_type (bt
->builtin_int8
, 16));
2208 append_composite_type_field (t
, "b", sub
);
2210 sub
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vnq",
2212 append_composite_type_field (sub
, "u",
2213 init_vector_type (bt
->builtin_uint128
, 1));
2214 append_composite_type_field (sub
, "s",
2215 init_vector_type (bt
->builtin_int128
, 1));
2216 append_composite_type_field (t
, "q", sub
);
2221 return tdep
->vnv_type
;
2224 /* Implement the "dwarf2_reg_to_regnum" gdbarch method. */
2227 aarch64_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
2229 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2231 if (reg
>= AARCH64_DWARF_X0
&& reg
<= AARCH64_DWARF_X0
+ 30)
2232 return AARCH64_X0_REGNUM
+ reg
- AARCH64_DWARF_X0
;
2234 if (reg
== AARCH64_DWARF_SP
)
2235 return AARCH64_SP_REGNUM
;
2237 if (reg
== AARCH64_DWARF_PC
)
2238 return AARCH64_PC_REGNUM
;
2240 if (reg
>= AARCH64_DWARF_V0
&& reg
<= AARCH64_DWARF_V0
+ 31)
2241 return AARCH64_V0_REGNUM
+ reg
- AARCH64_DWARF_V0
;
2243 if (reg
== AARCH64_DWARF_SVE_VG
)
2244 return AARCH64_SVE_VG_REGNUM
;
2246 if (reg
== AARCH64_DWARF_SVE_FFR
)
2247 return AARCH64_SVE_FFR_REGNUM
;
2249 if (reg
>= AARCH64_DWARF_SVE_P0
&& reg
<= AARCH64_DWARF_SVE_P0
+ 15)
2250 return AARCH64_SVE_P0_REGNUM
+ reg
- AARCH64_DWARF_SVE_P0
;
2252 if (reg
>= AARCH64_DWARF_SVE_Z0
&& reg
<= AARCH64_DWARF_SVE_Z0
+ 15)
2253 return AARCH64_SVE_Z0_REGNUM
+ reg
- AARCH64_DWARF_SVE_Z0
;
2255 if (tdep
->has_pauth ())
2257 if (reg
== AARCH64_DWARF_RA_SIGN_STATE
)
2258 return tdep
->ra_sign_state_regnum
;
2264 /* Implement the "print_insn" gdbarch method. */
2267 aarch64_gdb_print_insn (bfd_vma memaddr
, disassemble_info
*info
)
2269 info
->symbols
= NULL
;
2270 return default_print_insn (memaddr
, info
);
2273 /* AArch64 BRK software debug mode instruction.
2274 Note that AArch64 code is always little-endian.
2275 1101.0100.0010.0000.0000.0000.0000.0000 = 0xd4200000. */
2276 constexpr gdb_byte aarch64_default_breakpoint
[] = {0x00, 0x00, 0x20, 0xd4};
2278 typedef BP_MANIPULATION (aarch64_default_breakpoint
) aarch64_breakpoint
;
2280 /* Extract from an array REGS containing the (raw) register state a
2281 function return value of type TYPE, and copy that, in virtual
2282 format, into VALBUF. */
2285 aarch64_extract_return_value (struct type
*type
, struct regcache
*regs
,
2288 struct gdbarch
*gdbarch
= regs
->arch ();
2289 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2291 struct type
*fundamental_type
;
2293 if (aapcs_is_vfp_call_or_return_candidate (type
, &elements
,
2296 int len
= fundamental_type
->length ();
2298 for (int i
= 0; i
< elements
; i
++)
2300 int regno
= AARCH64_V0_REGNUM
+ i
;
2301 /* Enough space for a full vector register. */
2302 gdb_byte buf
[register_size (gdbarch
, regno
)];
2303 gdb_assert (len
<= sizeof (buf
));
2305 aarch64_debug_printf
2306 ("read HFA or HVA return value element %d from %s",
2307 i
+ 1, gdbarch_register_name (gdbarch
, regno
));
2309 regs
->cooked_read (regno
, buf
);
2311 memcpy (valbuf
, buf
, len
);
2315 else if (type
->code () == TYPE_CODE_INT
2316 || type
->code () == TYPE_CODE_CHAR
2317 || type
->code () == TYPE_CODE_BOOL
2318 || type
->code () == TYPE_CODE_PTR
2319 || TYPE_IS_REFERENCE (type
)
2320 || type
->code () == TYPE_CODE_ENUM
)
2322 /* If the type is a plain integer, then the access is
2323 straight-forward. Otherwise we have to play around a bit
2325 int len
= type
->length ();
2326 int regno
= AARCH64_X0_REGNUM
;
2331 /* By using store_unsigned_integer we avoid having to do
2332 anything special for small big-endian values. */
2333 regcache_cooked_read_unsigned (regs
, regno
++, &tmp
);
2334 store_unsigned_integer (valbuf
,
2335 (len
> X_REGISTER_SIZE
2336 ? X_REGISTER_SIZE
: len
), byte_order
, tmp
);
2337 len
-= X_REGISTER_SIZE
;
2338 valbuf
+= X_REGISTER_SIZE
;
2343 /* For a structure or union the behaviour is as if the value had
2344 been stored to word-aligned memory and then loaded into
2345 registers with 64-bit load instruction(s). */
2346 int len
= type
->length ();
2347 int regno
= AARCH64_X0_REGNUM
;
2348 bfd_byte buf
[X_REGISTER_SIZE
];
2352 regs
->cooked_read (regno
++, buf
);
2353 memcpy (valbuf
, buf
, len
> X_REGISTER_SIZE
? X_REGISTER_SIZE
: len
);
2354 len
-= X_REGISTER_SIZE
;
2355 valbuf
+= X_REGISTER_SIZE
;
2361 /* Will a function return an aggregate type in memory or in a
2362 register? Return 0 if an aggregate type can be returned in a
2363 register, 1 if it must be returned in memory. */
2366 aarch64_return_in_memory (struct gdbarch
*gdbarch
, struct type
*type
)
2368 type
= check_typedef (type
);
2370 struct type
*fundamental_type
;
2372 if (aapcs_is_vfp_call_or_return_candidate (type
, &elements
,
2375 /* v0-v7 are used to return values and one register is allocated
2376 for one member. However, HFA or HVA has at most four members. */
2380 if (type
->length () > 16
2381 || !language_pass_by_reference (type
).trivially_copyable
)
2383 /* PCS B.6 Aggregates larger than 16 bytes are passed by
2384 invisible reference. */
2392 /* Write into appropriate registers a function return value of type
2393 TYPE, given in virtual format. */
2396 aarch64_store_return_value (struct type
*type
, struct regcache
*regs
,
2397 const gdb_byte
*valbuf
)
2399 struct gdbarch
*gdbarch
= regs
->arch ();
2400 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2402 struct type
*fundamental_type
;
2404 if (aapcs_is_vfp_call_or_return_candidate (type
, &elements
,
2407 int len
= fundamental_type
->length ();
2409 for (int i
= 0; i
< elements
; i
++)
2411 int regno
= AARCH64_V0_REGNUM
+ i
;
2412 /* Enough space for a full vector register. */
2413 gdb_byte tmpbuf
[register_size (gdbarch
, regno
)];
2414 gdb_assert (len
<= sizeof (tmpbuf
));
2416 aarch64_debug_printf
2417 ("write HFA or HVA return value element %d to %s",
2418 i
+ 1, gdbarch_register_name (gdbarch
, regno
));
2420 memcpy (tmpbuf
, valbuf
,
2421 len
> V_REGISTER_SIZE
? V_REGISTER_SIZE
: len
);
2422 regs
->cooked_write (regno
, tmpbuf
);
2426 else if (type
->code () == TYPE_CODE_INT
2427 || type
->code () == TYPE_CODE_CHAR
2428 || type
->code () == TYPE_CODE_BOOL
2429 || type
->code () == TYPE_CODE_PTR
2430 || TYPE_IS_REFERENCE (type
)
2431 || type
->code () == TYPE_CODE_ENUM
)
2433 if (type
->length () <= X_REGISTER_SIZE
)
2435 /* Values of one word or less are zero/sign-extended and
2437 bfd_byte tmpbuf
[X_REGISTER_SIZE
];
2438 LONGEST val
= unpack_long (type
, valbuf
);
2440 store_signed_integer (tmpbuf
, X_REGISTER_SIZE
, byte_order
, val
);
2441 regs
->cooked_write (AARCH64_X0_REGNUM
, tmpbuf
);
2445 /* Integral values greater than one word are stored in
2446 consecutive registers starting with r0. This will always
2447 be a multiple of the regiser size. */
2448 int len
= type
->length ();
2449 int regno
= AARCH64_X0_REGNUM
;
2453 regs
->cooked_write (regno
++, valbuf
);
2454 len
-= X_REGISTER_SIZE
;
2455 valbuf
+= X_REGISTER_SIZE
;
2461 /* For a structure or union the behaviour is as if the value had
2462 been stored to word-aligned memory and then loaded into
2463 registers with 64-bit load instruction(s). */
2464 int len
= type
->length ();
2465 int regno
= AARCH64_X0_REGNUM
;
2466 bfd_byte tmpbuf
[X_REGISTER_SIZE
];
2470 memcpy (tmpbuf
, valbuf
,
2471 len
> X_REGISTER_SIZE
? X_REGISTER_SIZE
: len
);
2472 regs
->cooked_write (regno
++, tmpbuf
);
2473 len
-= X_REGISTER_SIZE
;
2474 valbuf
+= X_REGISTER_SIZE
;
2479 /* Implement the "return_value" gdbarch method. */
2481 static enum return_value_convention
2482 aarch64_return_value (struct gdbarch
*gdbarch
, struct value
*func_value
,
2483 struct type
*valtype
, struct regcache
*regcache
,
2484 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
2487 if (valtype
->code () == TYPE_CODE_STRUCT
2488 || valtype
->code () == TYPE_CODE_UNION
2489 || valtype
->code () == TYPE_CODE_ARRAY
)
2491 if (aarch64_return_in_memory (gdbarch
, valtype
))
2493 /* From the AAPCS64's Result Return section:
2495 "Otherwise, the caller shall reserve a block of memory of
2496 sufficient size and alignment to hold the result. The address
2497 of the memory block shall be passed as an additional argument to
2498 the function in x8. */
2500 aarch64_debug_printf ("return value in memory");
2506 regcache
->cooked_read (AARCH64_STRUCT_RETURN_REGNUM
, &addr
);
2507 read_memory (addr
, readbuf
, valtype
->length ());
2510 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
2515 aarch64_store_return_value (valtype
, regcache
, writebuf
);
2518 aarch64_extract_return_value (valtype
, regcache
, readbuf
);
2520 aarch64_debug_printf ("return value in registers");
2522 return RETURN_VALUE_REGISTER_CONVENTION
;
2525 /* Implement the "get_longjmp_target" gdbarch method. */
2528 aarch64_get_longjmp_target (struct frame_info
*frame
, CORE_ADDR
*pc
)
2531 gdb_byte buf
[X_REGISTER_SIZE
];
2532 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2533 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2534 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2536 jb_addr
= get_frame_register_unsigned (frame
, AARCH64_X0_REGNUM
);
2538 if (target_read_memory (jb_addr
+ tdep
->jb_pc
* tdep
->jb_elt_size
, buf
,
2542 *pc
= extract_unsigned_integer (buf
, X_REGISTER_SIZE
, byte_order
);
2546 /* Implement the "gen_return_address" gdbarch method. */
2549 aarch64_gen_return_address (struct gdbarch
*gdbarch
,
2550 struct agent_expr
*ax
, struct axs_value
*value
,
2553 value
->type
= register_type (gdbarch
, AARCH64_LR_REGNUM
);
2554 value
->kind
= axs_lvalue_register
;
2555 value
->u
.reg
= AARCH64_LR_REGNUM
;
2559 /* Return the pseudo register name corresponding to register regnum. */
2562 aarch64_pseudo_register_name (struct gdbarch
*gdbarch
, int regnum
)
2564 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2566 static const char *const q_name
[] =
2568 "q0", "q1", "q2", "q3",
2569 "q4", "q5", "q6", "q7",
2570 "q8", "q9", "q10", "q11",
2571 "q12", "q13", "q14", "q15",
2572 "q16", "q17", "q18", "q19",
2573 "q20", "q21", "q22", "q23",
2574 "q24", "q25", "q26", "q27",
2575 "q28", "q29", "q30", "q31",
2578 static const char *const d_name
[] =
2580 "d0", "d1", "d2", "d3",
2581 "d4", "d5", "d6", "d7",
2582 "d8", "d9", "d10", "d11",
2583 "d12", "d13", "d14", "d15",
2584 "d16", "d17", "d18", "d19",
2585 "d20", "d21", "d22", "d23",
2586 "d24", "d25", "d26", "d27",
2587 "d28", "d29", "d30", "d31",
2590 static const char *const s_name
[] =
2592 "s0", "s1", "s2", "s3",
2593 "s4", "s5", "s6", "s7",
2594 "s8", "s9", "s10", "s11",
2595 "s12", "s13", "s14", "s15",
2596 "s16", "s17", "s18", "s19",
2597 "s20", "s21", "s22", "s23",
2598 "s24", "s25", "s26", "s27",
2599 "s28", "s29", "s30", "s31",
2602 static const char *const h_name
[] =
2604 "h0", "h1", "h2", "h3",
2605 "h4", "h5", "h6", "h7",
2606 "h8", "h9", "h10", "h11",
2607 "h12", "h13", "h14", "h15",
2608 "h16", "h17", "h18", "h19",
2609 "h20", "h21", "h22", "h23",
2610 "h24", "h25", "h26", "h27",
2611 "h28", "h29", "h30", "h31",
2614 static const char *const b_name
[] =
2616 "b0", "b1", "b2", "b3",
2617 "b4", "b5", "b6", "b7",
2618 "b8", "b9", "b10", "b11",
2619 "b12", "b13", "b14", "b15",
2620 "b16", "b17", "b18", "b19",
2621 "b20", "b21", "b22", "b23",
2622 "b24", "b25", "b26", "b27",
2623 "b28", "b29", "b30", "b31",
2626 int p_regnum
= regnum
- gdbarch_num_regs (gdbarch
);
2628 if (p_regnum
>= AARCH64_Q0_REGNUM
&& p_regnum
< AARCH64_Q0_REGNUM
+ 32)
2629 return q_name
[p_regnum
- AARCH64_Q0_REGNUM
];
2631 if (p_regnum
>= AARCH64_D0_REGNUM
&& p_regnum
< AARCH64_D0_REGNUM
+ 32)
2632 return d_name
[p_regnum
- AARCH64_D0_REGNUM
];
2634 if (p_regnum
>= AARCH64_S0_REGNUM
&& p_regnum
< AARCH64_S0_REGNUM
+ 32)
2635 return s_name
[p_regnum
- AARCH64_S0_REGNUM
];
2637 if (p_regnum
>= AARCH64_H0_REGNUM
&& p_regnum
< AARCH64_H0_REGNUM
+ 32)
2638 return h_name
[p_regnum
- AARCH64_H0_REGNUM
];
2640 if (p_regnum
>= AARCH64_B0_REGNUM
&& p_regnum
< AARCH64_B0_REGNUM
+ 32)
2641 return b_name
[p_regnum
- AARCH64_B0_REGNUM
];
2643 if (tdep
->has_sve ())
2645 static const char *const sve_v_name
[] =
2647 "v0", "v1", "v2", "v3",
2648 "v4", "v5", "v6", "v7",
2649 "v8", "v9", "v10", "v11",
2650 "v12", "v13", "v14", "v15",
2651 "v16", "v17", "v18", "v19",
2652 "v20", "v21", "v22", "v23",
2653 "v24", "v25", "v26", "v27",
2654 "v28", "v29", "v30", "v31",
2657 if (p_regnum
>= AARCH64_SVE_V0_REGNUM
2658 && p_regnum
< AARCH64_SVE_V0_REGNUM
+ AARCH64_V_REGS_NUM
)
2659 return sve_v_name
[p_regnum
- AARCH64_SVE_V0_REGNUM
];
2662 /* RA_STATE is used for unwinding only. Do not assign it a name - this
2663 prevents it from being read by methods such as
2664 mi_cmd_trace_frame_collected. */
2665 if (tdep
->has_pauth () && regnum
== tdep
->ra_sign_state_regnum
)
2668 internal_error (__FILE__
, __LINE__
,
2669 _("aarch64_pseudo_register_name: bad register number %d"),
2673 /* Implement the "pseudo_register_type" tdesc_arch_data method. */
2675 static struct type
*
2676 aarch64_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
2678 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2680 int p_regnum
= regnum
- gdbarch_num_regs (gdbarch
);
2682 if (p_regnum
>= AARCH64_Q0_REGNUM
&& p_regnum
< AARCH64_Q0_REGNUM
+ 32)
2683 return aarch64_vnq_type (gdbarch
);
2685 if (p_regnum
>= AARCH64_D0_REGNUM
&& p_regnum
< AARCH64_D0_REGNUM
+ 32)
2686 return aarch64_vnd_type (gdbarch
);
2688 if (p_regnum
>= AARCH64_S0_REGNUM
&& p_regnum
< AARCH64_S0_REGNUM
+ 32)
2689 return aarch64_vns_type (gdbarch
);
2691 if (p_regnum
>= AARCH64_H0_REGNUM
&& p_regnum
< AARCH64_H0_REGNUM
+ 32)
2692 return aarch64_vnh_type (gdbarch
);
2694 if (p_regnum
>= AARCH64_B0_REGNUM
&& p_regnum
< AARCH64_B0_REGNUM
+ 32)
2695 return aarch64_vnb_type (gdbarch
);
2697 if (tdep
->has_sve () && p_regnum
>= AARCH64_SVE_V0_REGNUM
2698 && p_regnum
< AARCH64_SVE_V0_REGNUM
+ AARCH64_V_REGS_NUM
)
2699 return aarch64_vnv_type (gdbarch
);
2701 if (tdep
->has_pauth () && regnum
== tdep
->ra_sign_state_regnum
)
2702 return builtin_type (gdbarch
)->builtin_uint64
;
2704 internal_error (__FILE__
, __LINE__
,
2705 _("aarch64_pseudo_register_type: bad register number %d"),
2709 /* Implement the "pseudo_register_reggroup_p" tdesc_arch_data method. */
2712 aarch64_pseudo_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
2713 const struct reggroup
*group
)
2715 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2717 int p_regnum
= regnum
- gdbarch_num_regs (gdbarch
);
2719 if (p_regnum
>= AARCH64_Q0_REGNUM
&& p_regnum
< AARCH64_Q0_REGNUM
+ 32)
2720 return group
== all_reggroup
|| group
== vector_reggroup
;
2721 else if (p_regnum
>= AARCH64_D0_REGNUM
&& p_regnum
< AARCH64_D0_REGNUM
+ 32)
2722 return (group
== all_reggroup
|| group
== vector_reggroup
2723 || group
== float_reggroup
);
2724 else if (p_regnum
>= AARCH64_S0_REGNUM
&& p_regnum
< AARCH64_S0_REGNUM
+ 32)
2725 return (group
== all_reggroup
|| group
== vector_reggroup
2726 || group
== float_reggroup
);
2727 else if (p_regnum
>= AARCH64_H0_REGNUM
&& p_regnum
< AARCH64_H0_REGNUM
+ 32)
2728 return group
== all_reggroup
|| group
== vector_reggroup
;
2729 else if (p_regnum
>= AARCH64_B0_REGNUM
&& p_regnum
< AARCH64_B0_REGNUM
+ 32)
2730 return group
== all_reggroup
|| group
== vector_reggroup
;
2731 else if (tdep
->has_sve () && p_regnum
>= AARCH64_SVE_V0_REGNUM
2732 && p_regnum
< AARCH64_SVE_V0_REGNUM
+ AARCH64_V_REGS_NUM
)
2733 return group
== all_reggroup
|| group
== vector_reggroup
;
2734 /* RA_STATE is used for unwinding only. Do not assign it to any groups. */
2735 if (tdep
->has_pauth () && regnum
== tdep
->ra_sign_state_regnum
)
2738 return group
== all_reggroup
;
2741 /* Helper for aarch64_pseudo_read_value. */
2743 static struct value
*
2744 aarch64_pseudo_read_value_1 (struct gdbarch
*gdbarch
,
2745 readable_regcache
*regcache
, int regnum_offset
,
2746 int regsize
, struct value
*result_value
)
2748 unsigned v_regnum
= AARCH64_V0_REGNUM
+ regnum_offset
;
2750 /* Enough space for a full vector register. */
2751 gdb_byte reg_buf
[register_size (gdbarch
, AARCH64_V0_REGNUM
)];
2752 gdb_static_assert (AARCH64_V0_REGNUM
== AARCH64_SVE_Z0_REGNUM
);
2754 if (regcache
->raw_read (v_regnum
, reg_buf
) != REG_VALID
)
2755 mark_value_bytes_unavailable (result_value
, 0,
2756 value_type (result_value
)->length ());
2758 memcpy (value_contents_raw (result_value
).data (), reg_buf
, regsize
);
2760 return result_value
;
2763 /* Implement the "pseudo_register_read_value" gdbarch method. */
2765 static struct value
*
2766 aarch64_pseudo_read_value (struct gdbarch
*gdbarch
, readable_regcache
*regcache
,
2769 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2770 struct value
*result_value
= allocate_value (register_type (gdbarch
, regnum
));
2772 VALUE_LVAL (result_value
) = lval_register
;
2773 VALUE_REGNUM (result_value
) = regnum
;
2775 regnum
-= gdbarch_num_regs (gdbarch
);
2777 if (regnum
>= AARCH64_Q0_REGNUM
&& regnum
< AARCH64_Q0_REGNUM
+ 32)
2778 return aarch64_pseudo_read_value_1 (gdbarch
, regcache
,
2779 regnum
- AARCH64_Q0_REGNUM
,
2780 Q_REGISTER_SIZE
, result_value
);
2782 if (regnum
>= AARCH64_D0_REGNUM
&& regnum
< AARCH64_D0_REGNUM
+ 32)
2783 return aarch64_pseudo_read_value_1 (gdbarch
, regcache
,
2784 regnum
- AARCH64_D0_REGNUM
,
2785 D_REGISTER_SIZE
, result_value
);
2787 if (regnum
>= AARCH64_S0_REGNUM
&& regnum
< AARCH64_S0_REGNUM
+ 32)
2788 return aarch64_pseudo_read_value_1 (gdbarch
, regcache
,
2789 regnum
- AARCH64_S0_REGNUM
,
2790 S_REGISTER_SIZE
, result_value
);
2792 if (regnum
>= AARCH64_H0_REGNUM
&& regnum
< AARCH64_H0_REGNUM
+ 32)
2793 return aarch64_pseudo_read_value_1 (gdbarch
, regcache
,
2794 regnum
- AARCH64_H0_REGNUM
,
2795 H_REGISTER_SIZE
, result_value
);
2797 if (regnum
>= AARCH64_B0_REGNUM
&& regnum
< AARCH64_B0_REGNUM
+ 32)
2798 return aarch64_pseudo_read_value_1 (gdbarch
, regcache
,
2799 regnum
- AARCH64_B0_REGNUM
,
2800 B_REGISTER_SIZE
, result_value
);
2802 if (tdep
->has_sve () && regnum
>= AARCH64_SVE_V0_REGNUM
2803 && regnum
< AARCH64_SVE_V0_REGNUM
+ 32)
2804 return aarch64_pseudo_read_value_1 (gdbarch
, regcache
,
2805 regnum
- AARCH64_SVE_V0_REGNUM
,
2806 V_REGISTER_SIZE
, result_value
);
2808 gdb_assert_not_reached ("regnum out of bound");
2811 /* Helper for aarch64_pseudo_write. */
2814 aarch64_pseudo_write_1 (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
2815 int regnum_offset
, int regsize
, const gdb_byte
*buf
)
2817 unsigned v_regnum
= AARCH64_V0_REGNUM
+ regnum_offset
;
2819 /* Enough space for a full vector register. */
2820 gdb_byte reg_buf
[register_size (gdbarch
, AARCH64_V0_REGNUM
)];
2821 gdb_static_assert (AARCH64_V0_REGNUM
== AARCH64_SVE_Z0_REGNUM
);
2823 /* Ensure the register buffer is zero, we want gdb writes of the
2824 various 'scalar' pseudo registers to behavior like architectural
2825 writes, register width bytes are written the remainder are set to
2827 memset (reg_buf
, 0, register_size (gdbarch
, AARCH64_V0_REGNUM
));
2829 memcpy (reg_buf
, buf
, regsize
);
2830 regcache
->raw_write (v_regnum
, reg_buf
);
2833 /* Implement the "pseudo_register_write" gdbarch method. */
2836 aarch64_pseudo_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
2837 int regnum
, const gdb_byte
*buf
)
2839 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
2840 regnum
-= gdbarch_num_regs (gdbarch
);
2842 if (regnum
>= AARCH64_Q0_REGNUM
&& regnum
< AARCH64_Q0_REGNUM
+ 32)
2843 return aarch64_pseudo_write_1 (gdbarch
, regcache
,
2844 regnum
- AARCH64_Q0_REGNUM
, Q_REGISTER_SIZE
,
2847 if (regnum
>= AARCH64_D0_REGNUM
&& regnum
< AARCH64_D0_REGNUM
+ 32)
2848 return aarch64_pseudo_write_1 (gdbarch
, regcache
,
2849 regnum
- AARCH64_D0_REGNUM
, D_REGISTER_SIZE
,
2852 if (regnum
>= AARCH64_S0_REGNUM
&& regnum
< AARCH64_S0_REGNUM
+ 32)
2853 return aarch64_pseudo_write_1 (gdbarch
, regcache
,
2854 regnum
- AARCH64_S0_REGNUM
, S_REGISTER_SIZE
,
2857 if (regnum
>= AARCH64_H0_REGNUM
&& regnum
< AARCH64_H0_REGNUM
+ 32)
2858 return aarch64_pseudo_write_1 (gdbarch
, regcache
,
2859 regnum
- AARCH64_H0_REGNUM
, H_REGISTER_SIZE
,
2862 if (regnum
>= AARCH64_B0_REGNUM
&& regnum
< AARCH64_B0_REGNUM
+ 32)
2863 return aarch64_pseudo_write_1 (gdbarch
, regcache
,
2864 regnum
- AARCH64_B0_REGNUM
, B_REGISTER_SIZE
,
2867 if (tdep
->has_sve () && regnum
>= AARCH64_SVE_V0_REGNUM
2868 && regnum
< AARCH64_SVE_V0_REGNUM
+ 32)
2869 return aarch64_pseudo_write_1 (gdbarch
, regcache
,
2870 regnum
- AARCH64_SVE_V0_REGNUM
,
2871 V_REGISTER_SIZE
, buf
);
2873 gdb_assert_not_reached ("regnum out of bound");
2876 /* Callback function for user_reg_add. */
2878 static struct value
*
2879 value_of_aarch64_user_reg (struct frame_info
*frame
, const void *baton
)
2881 const int *reg_p
= (const int *) baton
;
2883 return value_of_register (*reg_p
, frame
);
2887 /* Implement the "software_single_step" gdbarch method, needed to
2888 single step through atomic sequences on AArch64. */
2890 static std::vector
<CORE_ADDR
>
2891 aarch64_software_single_step (struct regcache
*regcache
)
2893 struct gdbarch
*gdbarch
= regcache
->arch ();
2894 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
2895 const int insn_size
= 4;
2896 const int atomic_sequence_length
= 16; /* Instruction sequence length. */
2897 CORE_ADDR pc
= regcache_read_pc (regcache
);
2898 CORE_ADDR breaks
[2] = { CORE_ADDR_MAX
, CORE_ADDR_MAX
};
2900 CORE_ADDR closing_insn
= 0;
2901 uint32_t insn
= read_memory_unsigned_integer (loc
, insn_size
,
2902 byte_order_for_code
);
2905 int bc_insn_count
= 0; /* Conditional branch instruction count. */
2906 int last_breakpoint
= 0; /* Defaults to 0 (no breakpoints placed). */
2909 if (aarch64_decode_insn (insn
, &inst
, 1, NULL
) != 0)
2912 /* Look for a Load Exclusive instruction which begins the sequence. */
2913 if (inst
.opcode
->iclass
!= ldstexcl
|| bit (insn
, 22) == 0)
2916 for (insn_count
= 0; insn_count
< atomic_sequence_length
; ++insn_count
)
2919 insn
= read_memory_unsigned_integer (loc
, insn_size
,
2920 byte_order_for_code
);
2922 if (aarch64_decode_insn (insn
, &inst
, 1, NULL
) != 0)
2924 /* Check if the instruction is a conditional branch. */
2925 if (inst
.opcode
->iclass
== condbranch
)
2927 gdb_assert (inst
.operands
[0].type
== AARCH64_OPND_ADDR_PCREL19
);
2929 if (bc_insn_count
>= 1)
2932 /* It is, so we'll try to set a breakpoint at the destination. */
2933 breaks
[1] = loc
+ inst
.operands
[0].imm
.value
;
2939 /* Look for the Store Exclusive which closes the atomic sequence. */
2940 if (inst
.opcode
->iclass
== ldstexcl
&& bit (insn
, 22) == 0)
2947 /* We didn't find a closing Store Exclusive instruction, fall back. */
2951 /* Insert breakpoint after the end of the atomic sequence. */
2952 breaks
[0] = loc
+ insn_size
;
2954 /* Check for duplicated breakpoints, and also check that the second
2955 breakpoint is not within the atomic sequence. */
2957 && (breaks
[1] == breaks
[0]
2958 || (breaks
[1] >= pc
&& breaks
[1] <= closing_insn
)))
2959 last_breakpoint
= 0;
2961 std::vector
<CORE_ADDR
> next_pcs
;
2963 /* Insert the breakpoint at the end of the sequence, and one at the
2964 destination of the conditional branch, if it exists. */
2965 for (index
= 0; index
<= last_breakpoint
; index
++)
2966 next_pcs
.push_back (breaks
[index
]);
2971 struct aarch64_displaced_step_copy_insn_closure
2972 : public displaced_step_copy_insn_closure
2974 /* It is true when condition instruction, such as B.CON, TBZ, etc,
2975 is being displaced stepping. */
2978 /* PC adjustment offset after displaced stepping. If 0, then we don't
2979 write the PC back, assuming the PC is already the right address. */
2980 int32_t pc_adjust
= 0;
2983 /* Data when visiting instructions for displaced stepping. */
2985 struct aarch64_displaced_step_data
2987 struct aarch64_insn_data base
;
2989 /* The address where the instruction will be executed at. */
2991 /* Buffer of instructions to be copied to NEW_ADDR to execute. */
2992 uint32_t insn_buf
[AARCH64_DISPLACED_MODIFIED_INSNS
];
2993 /* Number of instructions in INSN_BUF. */
2994 unsigned insn_count
;
2995 /* Registers when doing displaced stepping. */
2996 struct regcache
*regs
;
2998 aarch64_displaced_step_copy_insn_closure
*dsc
;
3001 /* Implementation of aarch64_insn_visitor method "b". */
3004 aarch64_displaced_step_b (const int is_bl
, const int32_t offset
,
3005 struct aarch64_insn_data
*data
)
3007 struct aarch64_displaced_step_data
*dsd
3008 = (struct aarch64_displaced_step_data
*) data
;
3009 int64_t new_offset
= data
->insn_addr
- dsd
->new_addr
+ offset
;
3011 if (can_encode_int32 (new_offset
, 28))
3013 /* Emit B rather than BL, because executing BL on a new address
3014 will get the wrong address into LR. In order to avoid this,
3015 we emit B, and update LR if the instruction is BL. */
3016 emit_b (dsd
->insn_buf
, 0, new_offset
);
3022 emit_nop (dsd
->insn_buf
);
3024 dsd
->dsc
->pc_adjust
= offset
;
3030 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_LR_REGNUM
,
3031 data
->insn_addr
+ 4);
3035 /* Implementation of aarch64_insn_visitor method "b_cond". */
3038 aarch64_displaced_step_b_cond (const unsigned cond
, const int32_t offset
,
3039 struct aarch64_insn_data
*data
)
3041 struct aarch64_displaced_step_data
*dsd
3042 = (struct aarch64_displaced_step_data
*) data
;
3044 /* GDB has to fix up PC after displaced step this instruction
3045 differently according to the condition is true or false. Instead
3046 of checking COND against conditional flags, we can use
3047 the following instructions, and GDB can tell how to fix up PC
3048 according to the PC value.
3050 B.COND TAKEN ; If cond is true, then jump to TAKEN.
3056 emit_bcond (dsd
->insn_buf
, cond
, 8);
3057 dsd
->dsc
->cond
= true;
3058 dsd
->dsc
->pc_adjust
= offset
;
3059 dsd
->insn_count
= 1;
3062 /* Dynamically allocate a new register. If we know the register
3063 statically, we should make it a global as above instead of using this
3066 static struct aarch64_register
3067 aarch64_register (unsigned num
, int is64
)
3069 return (struct aarch64_register
) { num
, is64
};
3072 /* Implementation of aarch64_insn_visitor method "cb". */
3075 aarch64_displaced_step_cb (const int32_t offset
, const int is_cbnz
,
3076 const unsigned rn
, int is64
,
3077 struct aarch64_insn_data
*data
)
3079 struct aarch64_displaced_step_data
*dsd
3080 = (struct aarch64_displaced_step_data
*) data
;
3082 /* The offset is out of range for a compare and branch
3083 instruction. We can use the following instructions instead:
3085 CBZ xn, TAKEN ; xn == 0, then jump to TAKEN.
3090 emit_cb (dsd
->insn_buf
, is_cbnz
, aarch64_register (rn
, is64
), 8);
3091 dsd
->insn_count
= 1;
3092 dsd
->dsc
->cond
= true;
3093 dsd
->dsc
->pc_adjust
= offset
;
3096 /* Implementation of aarch64_insn_visitor method "tb". */
3099 aarch64_displaced_step_tb (const int32_t offset
, int is_tbnz
,
3100 const unsigned rt
, unsigned bit
,
3101 struct aarch64_insn_data
*data
)
3103 struct aarch64_displaced_step_data
*dsd
3104 = (struct aarch64_displaced_step_data
*) data
;
3106 /* The offset is out of range for a test bit and branch
3107 instruction We can use the following instructions instead:
3109 TBZ xn, #bit, TAKEN ; xn[bit] == 0, then jump to TAKEN.
3115 emit_tb (dsd
->insn_buf
, is_tbnz
, bit
, aarch64_register (rt
, 1), 8);
3116 dsd
->insn_count
= 1;
3117 dsd
->dsc
->cond
= true;
3118 dsd
->dsc
->pc_adjust
= offset
;
3121 /* Implementation of aarch64_insn_visitor method "adr". */
3124 aarch64_displaced_step_adr (const int32_t offset
, const unsigned rd
,
3125 const int is_adrp
, struct aarch64_insn_data
*data
)
3127 struct aarch64_displaced_step_data
*dsd
3128 = (struct aarch64_displaced_step_data
*) data
;
3129 /* We know exactly the address the ADR{P,} instruction will compute.
3130 We can just write it to the destination register. */
3131 CORE_ADDR address
= data
->insn_addr
+ offset
;
3135 /* Clear the lower 12 bits of the offset to get the 4K page. */
3136 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_X0_REGNUM
+ rd
,
3140 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_X0_REGNUM
+ rd
,
3143 dsd
->dsc
->pc_adjust
= 4;
3144 emit_nop (dsd
->insn_buf
);
3145 dsd
->insn_count
= 1;
3148 /* Implementation of aarch64_insn_visitor method "ldr_literal". */
3151 aarch64_displaced_step_ldr_literal (const int32_t offset
, const int is_sw
,
3152 const unsigned rt
, const int is64
,
3153 struct aarch64_insn_data
*data
)
3155 struct aarch64_displaced_step_data
*dsd
3156 = (struct aarch64_displaced_step_data
*) data
;
3157 CORE_ADDR address
= data
->insn_addr
+ offset
;
3158 struct aarch64_memory_operand zero
= { MEMORY_OPERAND_OFFSET
, 0 };
3160 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_X0_REGNUM
+ rt
,
3164 dsd
->insn_count
= emit_ldrsw (dsd
->insn_buf
, aarch64_register (rt
, 1),
3165 aarch64_register (rt
, 1), zero
);
3167 dsd
->insn_count
= emit_ldr (dsd
->insn_buf
, aarch64_register (rt
, is64
),
3168 aarch64_register (rt
, 1), zero
);
3170 dsd
->dsc
->pc_adjust
= 4;
3173 /* Implementation of aarch64_insn_visitor method "others". */
3176 aarch64_displaced_step_others (const uint32_t insn
,
3177 struct aarch64_insn_data
*data
)
3179 struct aarch64_displaced_step_data
*dsd
3180 = (struct aarch64_displaced_step_data
*) data
;
3182 uint32_t masked_insn
= (insn
& CLEAR_Rn_MASK
);
3183 if (masked_insn
== BLR
)
3185 /* Emit a BR to the same register and then update LR to the original
3186 address (similar to aarch64_displaced_step_b). */
3187 aarch64_emit_insn (dsd
->insn_buf
, insn
& 0xffdfffff);
3188 regcache_cooked_write_unsigned (dsd
->regs
, AARCH64_LR_REGNUM
,
3189 data
->insn_addr
+ 4);
3192 aarch64_emit_insn (dsd
->insn_buf
, insn
);
3193 dsd
->insn_count
= 1;
3195 if (masked_insn
== RET
|| masked_insn
== BR
|| masked_insn
== BLR
)
3196 dsd
->dsc
->pc_adjust
= 0;
3198 dsd
->dsc
->pc_adjust
= 4;
3201 static const struct aarch64_insn_visitor visitor
=
3203 aarch64_displaced_step_b
,
3204 aarch64_displaced_step_b_cond
,
3205 aarch64_displaced_step_cb
,
3206 aarch64_displaced_step_tb
,
3207 aarch64_displaced_step_adr
,
3208 aarch64_displaced_step_ldr_literal
,
3209 aarch64_displaced_step_others
,
3212 /* Implement the "displaced_step_copy_insn" gdbarch method. */
3214 displaced_step_copy_insn_closure_up
3215 aarch64_displaced_step_copy_insn (struct gdbarch
*gdbarch
,
3216 CORE_ADDR from
, CORE_ADDR to
,
3217 struct regcache
*regs
)
3219 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
3220 uint32_t insn
= read_memory_unsigned_integer (from
, 4, byte_order_for_code
);
3221 struct aarch64_displaced_step_data dsd
;
3224 if (aarch64_decode_insn (insn
, &inst
, 1, NULL
) != 0)
3227 /* Look for a Load Exclusive instruction which begins the sequence. */
3228 if (inst
.opcode
->iclass
== ldstexcl
&& bit (insn
, 22))
3230 /* We can't displaced step atomic sequences. */
3234 std::unique_ptr
<aarch64_displaced_step_copy_insn_closure
> dsc
3235 (new aarch64_displaced_step_copy_insn_closure
);
3236 dsd
.base
.insn_addr
= from
;
3239 dsd
.dsc
= dsc
.get ();
3241 aarch64_relocate_instruction (insn
, &visitor
,
3242 (struct aarch64_insn_data
*) &dsd
);
3243 gdb_assert (dsd
.insn_count
<= AARCH64_DISPLACED_MODIFIED_INSNS
);
3245 if (dsd
.insn_count
!= 0)
3249 /* Instruction can be relocated to scratch pad. Copy
3250 relocated instruction(s) there. */
3251 for (i
= 0; i
< dsd
.insn_count
; i
++)
3253 displaced_debug_printf ("writing insn %.8x at %s",
3255 paddress (gdbarch
, to
+ i
* 4));
3257 write_memory_unsigned_integer (to
+ i
* 4, 4, byte_order_for_code
,
3258 (ULONGEST
) dsd
.insn_buf
[i
]);
3266 /* This is a work around for a problem with g++ 4.8. */
3267 return displaced_step_copy_insn_closure_up (dsc
.release ());
3270 /* Implement the "displaced_step_fixup" gdbarch method. */
3273 aarch64_displaced_step_fixup (struct gdbarch
*gdbarch
,
3274 struct displaced_step_copy_insn_closure
*dsc_
,
3275 CORE_ADDR from
, CORE_ADDR to
,
3276 struct regcache
*regs
)
3278 aarch64_displaced_step_copy_insn_closure
*dsc
3279 = (aarch64_displaced_step_copy_insn_closure
*) dsc_
;
3283 regcache_cooked_read_unsigned (regs
, AARCH64_PC_REGNUM
, &pc
);
3285 displaced_debug_printf ("PC after stepping: %s (was %s).",
3286 paddress (gdbarch
, pc
), paddress (gdbarch
, to
));
3290 displaced_debug_printf ("[Conditional] pc_adjust before: %d",
3295 /* Condition is true. */
3297 else if (pc
- to
== 4)
3299 /* Condition is false. */
3303 gdb_assert_not_reached ("Unexpected PC value after displaced stepping");
3305 displaced_debug_printf ("[Conditional] pc_adjust after: %d",
3309 displaced_debug_printf ("%s PC by %d",
3310 dsc
->pc_adjust
? "adjusting" : "not adjusting",
3313 if (dsc
->pc_adjust
!= 0)
3315 /* Make sure the previous instruction was executed (that is, the PC
3316 has changed). If the PC didn't change, then discard the adjustment
3317 offset. Otherwise we may skip an instruction before its execution
3321 displaced_debug_printf ("PC did not move. Discarding PC adjustment.");
3325 displaced_debug_printf ("fixup: set PC to %s:%d",
3326 paddress (gdbarch
, from
), dsc
->pc_adjust
);
3328 regcache_cooked_write_unsigned (regs
, AARCH64_PC_REGNUM
,
3329 from
+ dsc
->pc_adjust
);
3333 /* Implement the "displaced_step_hw_singlestep" gdbarch method. */
3336 aarch64_displaced_step_hw_singlestep (struct gdbarch
*gdbarch
)
3341 /* Get the correct target description for the given VQ value.
3342 If VQ is zero then it is assumed SVE is not supported.
3343 (It is not possible to set VQ to zero on an SVE system).
3345 MTE_P indicates the presence of the Memory Tagging Extension feature.
3347 TLS_P indicates the presence of the Thread Local Storage feature. */
3350 aarch64_read_description (const aarch64_features
&features
)
3352 if (features
.vq
> AARCH64_MAX_SVE_VQ
)
3353 error (_("VQ is %" PRIu64
", maximum supported value is %d"), features
.vq
,
3354 AARCH64_MAX_SVE_VQ
);
3356 struct target_desc
*tdesc
= tdesc_aarch64_map
[features
];
3360 tdesc
= aarch64_create_target_description (features
);
3361 tdesc_aarch64_map
[features
] = tdesc
;
3367 /* Return the VQ used when creating the target description TDESC. */
3370 aarch64_get_tdesc_vq (const struct target_desc
*tdesc
)
3372 const struct tdesc_feature
*feature_sve
;
3374 if (!tdesc_has_registers (tdesc
))
3377 feature_sve
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.sve");
3379 if (feature_sve
== nullptr)
3382 uint64_t vl
= tdesc_register_bitsize (feature_sve
,
3383 aarch64_sve_register_names
[0]) / 8;
3384 return sve_vq_from_vl (vl
);
3387 /* Get the AArch64 features present in the given target description. */
3390 aarch64_features_from_target_desc (const struct target_desc
*tdesc
)
3392 aarch64_features features
;
3394 if (tdesc
== nullptr)
3397 features
.vq
= aarch64_get_tdesc_vq (tdesc
);
3399 = (tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.pauth") != nullptr);
3401 = (tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.mte") != nullptr);
3403 = (tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.tls") != nullptr);
3408 /* Implement the "cannot_store_register" gdbarch method. */
3411 aarch64_cannot_store_register (struct gdbarch
*gdbarch
, int regnum
)
3413 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3415 if (!tdep
->has_pauth ())
3418 /* Pointer authentication registers are read-only. */
3419 return (regnum
== AARCH64_PAUTH_DMASK_REGNUM (tdep
->pauth_reg_base
)
3420 || regnum
== AARCH64_PAUTH_CMASK_REGNUM (tdep
->pauth_reg_base
));
3423 /* Implement the stack_frame_destroyed_p gdbarch method. */
3426 aarch64_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
3428 CORE_ADDR func_start
, func_end
;
3429 if (!find_pc_partial_function (pc
, NULL
, &func_start
, &func_end
))
3432 enum bfd_endian byte_order_for_code
= gdbarch_byte_order_for_code (gdbarch
);
3433 uint32_t insn
= read_memory_unsigned_integer (pc
, 4, byte_order_for_code
);
3436 if (aarch64_decode_insn (insn
, &inst
, 1, nullptr) != 0)
3439 return streq (inst
.opcode
->name
, "ret");
3442 /* Initialize the current architecture based on INFO. If possible,
3443 re-use an architecture from ARCHES, which is a list of
3444 architectures already created during this debugging session.
3446 Called e.g. at program startup, when reading a core file, and when
3447 reading a binary file. */
3449 static struct gdbarch
*
3450 aarch64_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
3452 const struct tdesc_feature
*feature_core
, *feature_fpu
, *feature_sve
;
3453 const struct tdesc_feature
*feature_pauth
;
3454 bool valid_p
= true;
3455 int i
, num_regs
= 0, num_pseudo_regs
= 0;
3456 int first_pauth_regnum
= -1, ra_sign_state_offset
= -1;
3457 int first_mte_regnum
= -1, tls_regnum
= -1;
3458 uint64_t vq
= aarch64_get_tdesc_vq (info
.target_desc
);
3460 if (vq
> AARCH64_MAX_SVE_VQ
)
3461 internal_error (__FILE__
, __LINE__
, _("VQ out of bounds: %s (max %d)"),
3462 pulongest (vq
), AARCH64_MAX_SVE_VQ
);
3464 /* If there is already a candidate, use it. */
3465 for (gdbarch_list
*best_arch
= gdbarch_list_lookup_by_info (arches
, &info
);
3466 best_arch
!= nullptr;
3467 best_arch
= gdbarch_list_lookup_by_info (best_arch
->next
, &info
))
3469 aarch64_gdbarch_tdep
*tdep
3470 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (best_arch
->gdbarch
);
3471 if (tdep
&& tdep
->vq
== vq
)
3472 return best_arch
->gdbarch
;
3475 /* Ensure we always have a target descriptor, and that it is for the given VQ
3477 const struct target_desc
*tdesc
= info
.target_desc
;
3478 if (!tdesc_has_registers (tdesc
))
3479 tdesc
= aarch64_read_description ({});
3482 feature_core
= tdesc_find_feature (tdesc
,"org.gnu.gdb.aarch64.core");
3483 feature_fpu
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.fpu");
3484 feature_sve
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.sve");
3485 feature_pauth
= tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.pauth");
3486 const struct tdesc_feature
*feature_mte
3487 = tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.mte");
3488 const struct tdesc_feature
*feature_tls
3489 = tdesc_find_feature (tdesc
, "org.gnu.gdb.aarch64.tls");
3491 if (feature_core
== nullptr)
3494 tdesc_arch_data_up tdesc_data
= tdesc_data_alloc ();
3496 /* Validate the description provides the mandatory core R registers
3497 and allocate their numbers. */
3498 for (i
= 0; i
< ARRAY_SIZE (aarch64_r_register_names
); i
++)
3499 valid_p
&= tdesc_numbered_register (feature_core
, tdesc_data
.get (),
3500 AARCH64_X0_REGNUM
+ i
,
3501 aarch64_r_register_names
[i
]);
3503 num_regs
= AARCH64_X0_REGNUM
+ i
;
3505 /* Add the V registers. */
3506 if (feature_fpu
!= nullptr)
3508 if (feature_sve
!= nullptr)
3509 error (_("Program contains both fpu and SVE features."));
3511 /* Validate the description provides the mandatory V registers
3512 and allocate their numbers. */
3513 for (i
= 0; i
< ARRAY_SIZE (aarch64_v_register_names
); i
++)
3514 valid_p
&= tdesc_numbered_register (feature_fpu
, tdesc_data
.get (),
3515 AARCH64_V0_REGNUM
+ i
,
3516 aarch64_v_register_names
[i
]);
3518 num_regs
= AARCH64_V0_REGNUM
+ i
;
3521 /* Add the SVE registers. */
3522 if (feature_sve
!= nullptr)
3524 /* Validate the description provides the mandatory SVE registers
3525 and allocate their numbers. */
3526 for (i
= 0; i
< ARRAY_SIZE (aarch64_sve_register_names
); i
++)
3527 valid_p
&= tdesc_numbered_register (feature_sve
, tdesc_data
.get (),
3528 AARCH64_SVE_Z0_REGNUM
+ i
,
3529 aarch64_sve_register_names
[i
]);
3531 num_regs
= AARCH64_SVE_Z0_REGNUM
+ i
;
3532 num_pseudo_regs
+= 32; /* add the Vn register pseudos. */
3535 if (feature_fpu
!= nullptr || feature_sve
!= nullptr)
3537 num_pseudo_regs
+= 32; /* add the Qn scalar register pseudos */
3538 num_pseudo_regs
+= 32; /* add the Dn scalar register pseudos */
3539 num_pseudo_regs
+= 32; /* add the Sn scalar register pseudos */
3540 num_pseudo_regs
+= 32; /* add the Hn scalar register pseudos */
3541 num_pseudo_regs
+= 32; /* add the Bn scalar register pseudos */
3544 /* Add the TLS register. */
3545 if (feature_tls
!= nullptr)
3547 tls_regnum
= num_regs
;
3548 /* Validate the descriptor provides the mandatory TLS register
3549 and allocate its number. */
3550 valid_p
= tdesc_numbered_register (feature_tls
, tdesc_data
.get (),
3551 tls_regnum
, "tpidr");
3556 /* Add the pauth registers. */
3557 if (feature_pauth
!= NULL
)
3559 first_pauth_regnum
= num_regs
;
3560 ra_sign_state_offset
= num_pseudo_regs
;
3561 /* Validate the descriptor provides the mandatory PAUTH registers and
3562 allocate their numbers. */
3563 for (i
= 0; i
< ARRAY_SIZE (aarch64_pauth_register_names
); i
++)
3564 valid_p
&= tdesc_numbered_register (feature_pauth
, tdesc_data
.get (),
3565 first_pauth_regnum
+ i
,
3566 aarch64_pauth_register_names
[i
]);
3569 num_pseudo_regs
+= 1; /* Count RA_STATE pseudo register. */
3572 /* Add the MTE registers. */
3573 if (feature_mte
!= NULL
)
3575 first_mte_regnum
= num_regs
;
3576 /* Validate the descriptor provides the mandatory MTE registers and
3577 allocate their numbers. */
3578 for (i
= 0; i
< ARRAY_SIZE (aarch64_mte_register_names
); i
++)
3579 valid_p
&= tdesc_numbered_register (feature_mte
, tdesc_data
.get (),
3580 first_mte_regnum
+ i
,
3581 aarch64_mte_register_names
[i
]);
3589 /* AArch64 code is always little-endian. */
3590 info
.byte_order_for_code
= BFD_ENDIAN_LITTLE
;
3592 aarch64_gdbarch_tdep
*tdep
= new aarch64_gdbarch_tdep
;
3593 struct gdbarch
*gdbarch
= gdbarch_alloc (&info
, tdep
);
3595 /* This should be low enough for everything. */
3596 tdep
->lowest_pc
= 0x20;
3597 tdep
->jb_pc
= -1; /* Longjump support not enabled by default. */
3598 tdep
->jb_elt_size
= 8;
3600 tdep
->pauth_reg_base
= first_pauth_regnum
;
3601 tdep
->ra_sign_state_regnum
= (feature_pauth
== NULL
) ? -1
3602 : ra_sign_state_offset
+ num_regs
;
3603 tdep
->mte_reg_base
= first_mte_regnum
;
3604 tdep
->tls_regnum
= tls_regnum
;
3606 set_gdbarch_push_dummy_call (gdbarch
, aarch64_push_dummy_call
);
3607 set_gdbarch_frame_align (gdbarch
, aarch64_frame_align
);
3609 /* Advance PC across function entry code. */
3610 set_gdbarch_skip_prologue (gdbarch
, aarch64_skip_prologue
);
3612 /* The stack grows downward. */
3613 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
3615 /* Breakpoint manipulation. */
3616 set_gdbarch_breakpoint_kind_from_pc (gdbarch
,
3617 aarch64_breakpoint::kind_from_pc
);
3618 set_gdbarch_sw_breakpoint_from_kind (gdbarch
,
3619 aarch64_breakpoint::bp_from_kind
);
3620 set_gdbarch_have_nonsteppable_watchpoint (gdbarch
, 1);
3621 set_gdbarch_software_single_step (gdbarch
, aarch64_software_single_step
);
3623 /* Information about registers, etc. */
3624 set_gdbarch_sp_regnum (gdbarch
, AARCH64_SP_REGNUM
);
3625 set_gdbarch_pc_regnum (gdbarch
, AARCH64_PC_REGNUM
);
3626 set_gdbarch_num_regs (gdbarch
, num_regs
);
3628 set_gdbarch_num_pseudo_regs (gdbarch
, num_pseudo_regs
);
3629 set_gdbarch_pseudo_register_read_value (gdbarch
, aarch64_pseudo_read_value
);
3630 set_gdbarch_pseudo_register_write (gdbarch
, aarch64_pseudo_write
);
3631 set_tdesc_pseudo_register_name (gdbarch
, aarch64_pseudo_register_name
);
3632 set_tdesc_pseudo_register_type (gdbarch
, aarch64_pseudo_register_type
);
3633 set_tdesc_pseudo_register_reggroup_p (gdbarch
,
3634 aarch64_pseudo_register_reggroup_p
);
3635 set_gdbarch_cannot_store_register (gdbarch
, aarch64_cannot_store_register
);
3638 set_gdbarch_short_bit (gdbarch
, 16);
3639 set_gdbarch_int_bit (gdbarch
, 32);
3640 set_gdbarch_float_bit (gdbarch
, 32);
3641 set_gdbarch_double_bit (gdbarch
, 64);
3642 set_gdbarch_long_double_bit (gdbarch
, 128);
3643 set_gdbarch_long_bit (gdbarch
, 64);
3644 set_gdbarch_long_long_bit (gdbarch
, 64);
3645 set_gdbarch_ptr_bit (gdbarch
, 64);
3646 set_gdbarch_char_signed (gdbarch
, 0);
3647 set_gdbarch_wchar_signed (gdbarch
, 0);
3648 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
3649 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
3650 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_quad
);
3651 set_gdbarch_type_align (gdbarch
, aarch64_type_align
);
3653 /* Detect whether PC is at a point where the stack has been destroyed. */
3654 set_gdbarch_stack_frame_destroyed_p (gdbarch
, aarch64_stack_frame_destroyed_p
);
3656 /* Internal <-> external register number maps. */
3657 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, aarch64_dwarf_reg_to_regnum
);
3659 /* Returning results. */
3660 set_gdbarch_return_value (gdbarch
, aarch64_return_value
);
3663 set_gdbarch_print_insn (gdbarch
, aarch64_gdb_print_insn
);
3665 /* Virtual tables. */
3666 set_gdbarch_vbit_in_delta (gdbarch
, 1);
3668 /* Hook in the ABI-specific overrides, if they have been registered. */
3669 info
.target_desc
= tdesc
;
3670 info
.tdesc_data
= tdesc_data
.get ();
3671 gdbarch_init_osabi (info
, gdbarch
);
3673 dwarf2_frame_set_init_reg (gdbarch
, aarch64_dwarf2_frame_init_reg
);
3674 /* Register DWARF CFA vendor handler. */
3675 set_gdbarch_execute_dwarf_cfa_vendor_op (gdbarch
,
3676 aarch64_execute_dwarf_cfa_vendor_op
);
3678 /* Permanent/Program breakpoint handling. */
3679 set_gdbarch_program_breakpoint_here_p (gdbarch
,
3680 aarch64_program_breakpoint_here_p
);
3682 /* Add some default predicates. */
3683 frame_unwind_append_unwinder (gdbarch
, &aarch64_stub_unwind
);
3684 dwarf2_append_unwinders (gdbarch
);
3685 frame_unwind_append_unwinder (gdbarch
, &aarch64_prologue_unwind
);
3687 frame_base_set_default (gdbarch
, &aarch64_normal_base
);
3689 /* Now we have tuned the configuration, set a few final things,
3690 based on what the OS ABI has told us. */
3692 if (tdep
->jb_pc
>= 0)
3693 set_gdbarch_get_longjmp_target (gdbarch
, aarch64_get_longjmp_target
);
3695 set_gdbarch_gen_return_address (gdbarch
, aarch64_gen_return_address
);
3697 set_gdbarch_get_pc_address_flags (gdbarch
, aarch64_get_pc_address_flags
);
3699 tdesc_use_registers (gdbarch
, tdesc
, std::move (tdesc_data
));
3701 /* Add standard register aliases. */
3702 for (i
= 0; i
< ARRAY_SIZE (aarch64_register_aliases
); i
++)
3703 user_reg_add (gdbarch
, aarch64_register_aliases
[i
].name
,
3704 value_of_aarch64_user_reg
,
3705 &aarch64_register_aliases
[i
].regnum
);
3707 register_aarch64_ravenscar_ops (gdbarch
);
3713 aarch64_dump_tdep (struct gdbarch
*gdbarch
, struct ui_file
*file
)
3715 aarch64_gdbarch_tdep
*tdep
= gdbarch_tdep
<aarch64_gdbarch_tdep
> (gdbarch
);
3720 gdb_printf (file
, _("aarch64_dump_tdep: Lowest pc = 0x%s"),
3721 paddress (gdbarch
, tdep
->lowest_pc
));
3727 static void aarch64_process_record_test (void);
3731 void _initialize_aarch64_tdep ();
3733 _initialize_aarch64_tdep ()
3735 gdbarch_register (bfd_arch_aarch64
, aarch64_gdbarch_init
,
3738 /* Debug this file's internals. */
3739 add_setshow_boolean_cmd ("aarch64", class_maintenance
, &aarch64_debug
, _("\
3740 Set AArch64 debugging."), _("\
3741 Show AArch64 debugging."), _("\
3742 When on, AArch64 specific debugging is enabled."),
3745 &setdebuglist
, &showdebuglist
);
3748 selftests::register_test ("aarch64-analyze-prologue",
3749 selftests::aarch64_analyze_prologue_test
);
3750 selftests::register_test ("aarch64-process-record",
3751 selftests::aarch64_process_record_test
);
3755 /* AArch64 process record-replay related structures, defines etc. */
3757 #define REG_ALLOC(REGS, LENGTH, RECORD_BUF) \
3760 unsigned int reg_len = LENGTH; \
3763 REGS = XNEWVEC (uint32_t, reg_len); \
3764 memcpy(®S[0], &RECORD_BUF[0], sizeof(uint32_t)*LENGTH); \
3769 #define MEM_ALLOC(MEMS, LENGTH, RECORD_BUF) \
3772 unsigned int mem_len = LENGTH; \
3775 MEMS = XNEWVEC (struct aarch64_mem_r, mem_len); \
3776 memcpy(MEMS, &RECORD_BUF[0], \
3777 sizeof(struct aarch64_mem_r) * LENGTH); \
3782 /* AArch64 record/replay structures and enumerations. */
3784 struct aarch64_mem_r
3786 uint64_t len
; /* Record length. */
3787 uint64_t addr
; /* Memory address. */
3790 enum aarch64_record_result
3792 AARCH64_RECORD_SUCCESS
,
3793 AARCH64_RECORD_UNSUPPORTED
,
3794 AARCH64_RECORD_UNKNOWN
3797 struct aarch64_insn_decode_record
3799 struct gdbarch
*gdbarch
;
3800 struct regcache
*regcache
;
3801 CORE_ADDR this_addr
; /* Address of insn to be recorded. */
3802 uint32_t aarch64_insn
; /* Insn to be recorded. */
3803 uint32_t mem_rec_count
; /* Count of memory records. */
3804 uint32_t reg_rec_count
; /* Count of register records. */
3805 uint32_t *aarch64_regs
; /* Registers to be recorded. */
3806 struct aarch64_mem_r
*aarch64_mems
; /* Memory locations to be recorded. */
3809 /* Record handler for data processing - register instructions. */
3812 aarch64_record_data_proc_reg (aarch64_insn_decode_record
*aarch64_insn_r
)
3814 uint8_t reg_rd
, insn_bits24_27
, insn_bits21_23
;
3815 uint32_t record_buf
[4];
3817 reg_rd
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
3818 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
3819 insn_bits21_23
= bits (aarch64_insn_r
->aarch64_insn
, 21, 23);
3821 if (!bit (aarch64_insn_r
->aarch64_insn
, 28))
3825 /* Logical (shifted register). */
3826 if (insn_bits24_27
== 0x0a)
3827 setflags
= (bits (aarch64_insn_r
->aarch64_insn
, 29, 30) == 0x03);
3829 else if (insn_bits24_27
== 0x0b)
3830 setflags
= bit (aarch64_insn_r
->aarch64_insn
, 29);
3832 return AARCH64_RECORD_UNKNOWN
;
3834 record_buf
[0] = reg_rd
;
3835 aarch64_insn_r
->reg_rec_count
= 1;
3837 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_CPSR_REGNUM
;
3841 if (insn_bits24_27
== 0x0b)
3843 /* Data-processing (3 source). */
3844 record_buf
[0] = reg_rd
;
3845 aarch64_insn_r
->reg_rec_count
= 1;
3847 else if (insn_bits24_27
== 0x0a)
3849 if (insn_bits21_23
== 0x00)
3851 /* Add/subtract (with carry). */
3852 record_buf
[0] = reg_rd
;
3853 aarch64_insn_r
->reg_rec_count
= 1;
3854 if (bit (aarch64_insn_r
->aarch64_insn
, 29))
3856 record_buf
[1] = AARCH64_CPSR_REGNUM
;
3857 aarch64_insn_r
->reg_rec_count
= 2;
3860 else if (insn_bits21_23
== 0x02)
3862 /* Conditional compare (register) and conditional compare
3863 (immediate) instructions. */
3864 record_buf
[0] = AARCH64_CPSR_REGNUM
;
3865 aarch64_insn_r
->reg_rec_count
= 1;
3867 else if (insn_bits21_23
== 0x04 || insn_bits21_23
== 0x06)
3869 /* Conditional select. */
3870 /* Data-processing (2 source). */
3871 /* Data-processing (1 source). */
3872 record_buf
[0] = reg_rd
;
3873 aarch64_insn_r
->reg_rec_count
= 1;
3876 return AARCH64_RECORD_UNKNOWN
;
3880 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
3882 return AARCH64_RECORD_SUCCESS
;
3885 /* Record handler for data processing - immediate instructions. */
3888 aarch64_record_data_proc_imm (aarch64_insn_decode_record
*aarch64_insn_r
)
3890 uint8_t reg_rd
, insn_bit23
, insn_bits24_27
, setflags
;
3891 uint32_t record_buf
[4];
3893 reg_rd
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
3894 insn_bit23
= bit (aarch64_insn_r
->aarch64_insn
, 23);
3895 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
3897 if (insn_bits24_27
== 0x00 /* PC rel addressing. */
3898 || insn_bits24_27
== 0x03 /* Bitfield and Extract. */
3899 || (insn_bits24_27
== 0x02 && insn_bit23
)) /* Move wide (immediate). */
3901 record_buf
[0] = reg_rd
;
3902 aarch64_insn_r
->reg_rec_count
= 1;
3904 else if (insn_bits24_27
== 0x01)
3906 /* Add/Subtract (immediate). */
3907 setflags
= bit (aarch64_insn_r
->aarch64_insn
, 29);
3908 record_buf
[0] = reg_rd
;
3909 aarch64_insn_r
->reg_rec_count
= 1;
3911 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_CPSR_REGNUM
;
3913 else if (insn_bits24_27
== 0x02 && !insn_bit23
)
3915 /* Logical (immediate). */
3916 setflags
= bits (aarch64_insn_r
->aarch64_insn
, 29, 30) == 0x03;
3917 record_buf
[0] = reg_rd
;
3918 aarch64_insn_r
->reg_rec_count
= 1;
3920 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_CPSR_REGNUM
;
3923 return AARCH64_RECORD_UNKNOWN
;
3925 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
3927 return AARCH64_RECORD_SUCCESS
;
3930 /* Record handler for branch, exception generation and system instructions. */
3933 aarch64_record_branch_except_sys (aarch64_insn_decode_record
*aarch64_insn_r
)
3936 aarch64_gdbarch_tdep
*tdep
3937 = gdbarch_tdep
<aarch64_gdbarch_tdep
> (aarch64_insn_r
->gdbarch
);
3938 uint8_t insn_bits24_27
, insn_bits28_31
, insn_bits22_23
;
3939 uint32_t record_buf
[4];
3941 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
3942 insn_bits28_31
= bits (aarch64_insn_r
->aarch64_insn
, 28, 31);
3943 insn_bits22_23
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
3945 if (insn_bits28_31
== 0x0d)
3947 /* Exception generation instructions. */
3948 if (insn_bits24_27
== 0x04)
3950 if (!bits (aarch64_insn_r
->aarch64_insn
, 2, 4)
3951 && !bits (aarch64_insn_r
->aarch64_insn
, 21, 23)
3952 && bits (aarch64_insn_r
->aarch64_insn
, 0, 1) == 0x01)
3954 ULONGEST svc_number
;
3956 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, 8,
3958 return tdep
->aarch64_syscall_record (aarch64_insn_r
->regcache
,
3962 return AARCH64_RECORD_UNSUPPORTED
;
3964 /* System instructions. */
3965 else if (insn_bits24_27
== 0x05 && insn_bits22_23
== 0x00)
3967 uint32_t reg_rt
, reg_crn
;
3969 reg_rt
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
3970 reg_crn
= bits (aarch64_insn_r
->aarch64_insn
, 12, 15);
3972 /* Record rt in case of sysl and mrs instructions. */
3973 if (bit (aarch64_insn_r
->aarch64_insn
, 21))
3975 record_buf
[0] = reg_rt
;
3976 aarch64_insn_r
->reg_rec_count
= 1;
3978 /* Record cpsr for hint and msr(immediate) instructions. */
3979 else if (reg_crn
== 0x02 || reg_crn
== 0x04)
3981 record_buf
[0] = AARCH64_CPSR_REGNUM
;
3982 aarch64_insn_r
->reg_rec_count
= 1;
3985 /* Unconditional branch (register). */
3986 else if((insn_bits24_27
& 0x0e) == 0x06)
3988 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_PC_REGNUM
;
3989 if (bits (aarch64_insn_r
->aarch64_insn
, 21, 22) == 0x01)
3990 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_LR_REGNUM
;
3993 return AARCH64_RECORD_UNKNOWN
;
3995 /* Unconditional branch (immediate). */
3996 else if ((insn_bits28_31
& 0x07) == 0x01 && (insn_bits24_27
& 0x0c) == 0x04)
3998 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_PC_REGNUM
;
3999 if (bit (aarch64_insn_r
->aarch64_insn
, 31))
4000 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_LR_REGNUM
;
4003 /* Compare & branch (immediate), Test & branch (immediate) and
4004 Conditional branch (immediate). */
4005 record_buf
[aarch64_insn_r
->reg_rec_count
++] = AARCH64_PC_REGNUM
;
4007 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
4009 return AARCH64_RECORD_SUCCESS
;
4012 /* Record handler for advanced SIMD load and store instructions. */
4015 aarch64_record_asimd_load_store (aarch64_insn_decode_record
*aarch64_insn_r
)
4018 uint64_t addr_offset
= 0;
4019 uint32_t record_buf
[24];
4020 uint64_t record_buf_mem
[24];
4021 uint32_t reg_rn
, reg_rt
;
4022 uint32_t reg_index
= 0, mem_index
= 0;
4023 uint8_t opcode_bits
, size_bits
;
4025 reg_rt
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
4026 reg_rn
= bits (aarch64_insn_r
->aarch64_insn
, 5, 9);
4027 size_bits
= bits (aarch64_insn_r
->aarch64_insn
, 10, 11);
4028 opcode_bits
= bits (aarch64_insn_r
->aarch64_insn
, 12, 15);
4029 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
, &address
);
4032 debug_printf ("Process record: Advanced SIMD load/store\n");
4034 /* Load/store single structure. */
4035 if (bit (aarch64_insn_r
->aarch64_insn
, 24))
4037 uint8_t sindex
, scale
, selem
, esize
, replicate
= 0;
4038 scale
= opcode_bits
>> 2;
4039 selem
= ((opcode_bits
& 0x02) |
4040 bit (aarch64_insn_r
->aarch64_insn
, 21)) + 1;
4044 if (size_bits
& 0x01)
4045 return AARCH64_RECORD_UNKNOWN
;
4048 if ((size_bits
>> 1) & 0x01)
4049 return AARCH64_RECORD_UNKNOWN
;
4050 if (size_bits
& 0x01)
4052 if (!((opcode_bits
>> 1) & 0x01))
4055 return AARCH64_RECORD_UNKNOWN
;
4059 if (bit (aarch64_insn_r
->aarch64_insn
, 22) && !(opcode_bits
& 0x01))
4066 return AARCH64_RECORD_UNKNOWN
;
4072 for (sindex
= 0; sindex
< selem
; sindex
++)
4074 record_buf
[reg_index
++] = reg_rt
+ AARCH64_V0_REGNUM
;
4075 reg_rt
= (reg_rt
+ 1) % 32;
4079 for (sindex
= 0; sindex
< selem
; sindex
++)
4081 if (bit (aarch64_insn_r
->aarch64_insn
, 22))
4082 record_buf
[reg_index
++] = reg_rt
+ AARCH64_V0_REGNUM
;
4085 record_buf_mem
[mem_index
++] = esize
/ 8;
4086 record_buf_mem
[mem_index
++] = address
+ addr_offset
;
4088 addr_offset
= addr_offset
+ (esize
/ 8);
4089 reg_rt
= (reg_rt
+ 1) % 32;
4093 /* Load/store multiple structure. */
4096 uint8_t selem
, esize
, rpt
, elements
;
4097 uint8_t eindex
, rindex
;
4099 esize
= 8 << size_bits
;
4100 if (bit (aarch64_insn_r
->aarch64_insn
, 30))
4101 elements
= 128 / esize
;
4103 elements
= 64 / esize
;
4105 switch (opcode_bits
)
4107 /*LD/ST4 (4 Registers). */
4112 /*LD/ST1 (4 Registers). */
4117 /*LD/ST3 (3 Registers). */
4122 /*LD/ST1 (3 Registers). */
4127 /*LD/ST1 (1 Register). */
4132 /*LD/ST2 (2 Registers). */
4137 /*LD/ST1 (2 Registers). */
4143 return AARCH64_RECORD_UNSUPPORTED
;
4146 for (rindex
= 0; rindex
< rpt
; rindex
++)
4147 for (eindex
= 0; eindex
< elements
; eindex
++)
4149 uint8_t reg_tt
, sindex
;
4150 reg_tt
= (reg_rt
+ rindex
) % 32;
4151 for (sindex
= 0; sindex
< selem
; sindex
++)
4153 if (bit (aarch64_insn_r
->aarch64_insn
, 22))
4154 record_buf
[reg_index
++] = reg_tt
+ AARCH64_V0_REGNUM
;
4157 record_buf_mem
[mem_index
++] = esize
/ 8;
4158 record_buf_mem
[mem_index
++] = address
+ addr_offset
;
4160 addr_offset
= addr_offset
+ (esize
/ 8);
4161 reg_tt
= (reg_tt
+ 1) % 32;
4166 if (bit (aarch64_insn_r
->aarch64_insn
, 23))
4167 record_buf
[reg_index
++] = reg_rn
;
4169 aarch64_insn_r
->reg_rec_count
= reg_index
;
4170 aarch64_insn_r
->mem_rec_count
= mem_index
/ 2;
4171 MEM_ALLOC (aarch64_insn_r
->aarch64_mems
, aarch64_insn_r
->mem_rec_count
,
4173 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
4175 return AARCH64_RECORD_SUCCESS
;
4178 /* Record handler for load and store instructions. */
4181 aarch64_record_load_store (aarch64_insn_decode_record
*aarch64_insn_r
)
4183 uint8_t insn_bits24_27
, insn_bits28_29
, insn_bits10_11
;
4184 uint8_t insn_bit23
, insn_bit21
;
4185 uint8_t opc
, size_bits
, ld_flag
, vector_flag
;
4186 uint32_t reg_rn
, reg_rt
, reg_rt2
;
4187 uint64_t datasize
, offset
;
4188 uint32_t record_buf
[8];
4189 uint64_t record_buf_mem
[8];
4192 insn_bits10_11
= bits (aarch64_insn_r
->aarch64_insn
, 10, 11);
4193 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
4194 insn_bits28_29
= bits (aarch64_insn_r
->aarch64_insn
, 28, 29);
4195 insn_bit21
= bit (aarch64_insn_r
->aarch64_insn
, 21);
4196 insn_bit23
= bit (aarch64_insn_r
->aarch64_insn
, 23);
4197 ld_flag
= bit (aarch64_insn_r
->aarch64_insn
, 22);
4198 vector_flag
= bit (aarch64_insn_r
->aarch64_insn
, 26);
4199 reg_rt
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
4200 reg_rn
= bits (aarch64_insn_r
->aarch64_insn
, 5, 9);
4201 reg_rt2
= bits (aarch64_insn_r
->aarch64_insn
, 10, 14);
4202 size_bits
= bits (aarch64_insn_r
->aarch64_insn
, 30, 31);
4204 /* Load/store exclusive. */
4205 if (insn_bits24_27
== 0x08 && insn_bits28_29
== 0x00)
4208 debug_printf ("Process record: load/store exclusive\n");
4212 record_buf
[0] = reg_rt
;
4213 aarch64_insn_r
->reg_rec_count
= 1;
4216 record_buf
[1] = reg_rt2
;
4217 aarch64_insn_r
->reg_rec_count
= 2;
4223 datasize
= (8 << size_bits
) * 2;
4225 datasize
= (8 << size_bits
);
4226 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
4228 record_buf_mem
[0] = datasize
/ 8;
4229 record_buf_mem
[1] = address
;
4230 aarch64_insn_r
->mem_rec_count
= 1;
4233 /* Save register rs. */
4234 record_buf
[0] = bits (aarch64_insn_r
->aarch64_insn
, 16, 20);
4235 aarch64_insn_r
->reg_rec_count
= 1;
4239 /* Load register (literal) instructions decoding. */
4240 else if ((insn_bits24_27
& 0x0b) == 0x08 && insn_bits28_29
== 0x01)
4243 debug_printf ("Process record: load register (literal)\n");
4245 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
4247 record_buf
[0] = reg_rt
;
4248 aarch64_insn_r
->reg_rec_count
= 1;
4250 /* All types of load/store pair instructions decoding. */
4251 else if ((insn_bits24_27
& 0x0a) == 0x08 && insn_bits28_29
== 0x02)
4254 debug_printf ("Process record: load/store pair\n");
4260 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
4261 record_buf
[1] = reg_rt2
+ AARCH64_V0_REGNUM
;
4265 record_buf
[0] = reg_rt
;
4266 record_buf
[1] = reg_rt2
;
4268 aarch64_insn_r
->reg_rec_count
= 2;
4273 imm7_off
= bits (aarch64_insn_r
->aarch64_insn
, 15, 21);
4275 size_bits
= size_bits
>> 1;
4276 datasize
= 8 << (2 + size_bits
);
4277 offset
= (imm7_off
& 0x40) ? (~imm7_off
& 0x007f) + 1 : imm7_off
;
4278 offset
= offset
<< (2 + size_bits
);
4279 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
4281 if (!((insn_bits24_27
& 0x0b) == 0x08 && insn_bit23
))
4283 if (imm7_off
& 0x40)
4284 address
= address
- offset
;
4286 address
= address
+ offset
;
4289 record_buf_mem
[0] = datasize
/ 8;
4290 record_buf_mem
[1] = address
;
4291 record_buf_mem
[2] = datasize
/ 8;
4292 record_buf_mem
[3] = address
+ (datasize
/ 8);
4293 aarch64_insn_r
->mem_rec_count
= 2;
4295 if (bit (aarch64_insn_r
->aarch64_insn
, 23))
4296 record_buf
[aarch64_insn_r
->reg_rec_count
++] = reg_rn
;
4298 /* Load/store register (unsigned immediate) instructions. */
4299 else if ((insn_bits24_27
& 0x0b) == 0x09 && insn_bits28_29
== 0x03)
4301 opc
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
4311 if (size_bits
== 0x3 && vector_flag
== 0x0 && opc
== 0x2)
4313 /* PRFM (immediate) */
4314 return AARCH64_RECORD_SUCCESS
;
4316 else if (size_bits
== 0x2 && vector_flag
== 0x0 && opc
== 0x2)
4318 /* LDRSW (immediate) */
4332 debug_printf ("Process record: load/store (unsigned immediate):"
4333 " size %x V %d opc %x\n", size_bits
, vector_flag
,
4339 offset
= bits (aarch64_insn_r
->aarch64_insn
, 10, 21);
4340 datasize
= 8 << size_bits
;
4341 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
4343 offset
= offset
<< size_bits
;
4344 address
= address
+ offset
;
4346 record_buf_mem
[0] = datasize
>> 3;
4347 record_buf_mem
[1] = address
;
4348 aarch64_insn_r
->mem_rec_count
= 1;
4353 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
4355 record_buf
[0] = reg_rt
;
4356 aarch64_insn_r
->reg_rec_count
= 1;
4359 /* Load/store register (register offset) instructions. */
4360 else if ((insn_bits24_27
& 0x0b) == 0x08 && insn_bits28_29
== 0x03
4361 && insn_bits10_11
== 0x02 && insn_bit21
)
4364 debug_printf ("Process record: load/store (register offset)\n");
4365 opc
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
4372 if (size_bits
!= 0x03)
4375 return AARCH64_RECORD_UNKNOWN
;
4379 ULONGEST reg_rm_val
;
4381 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
,
4382 bits (aarch64_insn_r
->aarch64_insn
, 16, 20), ®_rm_val
);
4383 if (bit (aarch64_insn_r
->aarch64_insn
, 12))
4384 offset
= reg_rm_val
<< size_bits
;
4386 offset
= reg_rm_val
;
4387 datasize
= 8 << size_bits
;
4388 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
4390 address
= address
+ offset
;
4391 record_buf_mem
[0] = datasize
>> 3;
4392 record_buf_mem
[1] = address
;
4393 aarch64_insn_r
->mem_rec_count
= 1;
4398 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
4400 record_buf
[0] = reg_rt
;
4401 aarch64_insn_r
->reg_rec_count
= 1;
4404 /* Load/store register (immediate and unprivileged) instructions. */
4405 else if ((insn_bits24_27
& 0x0b) == 0x08 && insn_bits28_29
== 0x03
4410 debug_printf ("Process record: load/store "
4411 "(immediate and unprivileged)\n");
4413 opc
= bits (aarch64_insn_r
->aarch64_insn
, 22, 23);
4420 if (size_bits
!= 0x03)
4423 return AARCH64_RECORD_UNKNOWN
;
4428 imm9_off
= bits (aarch64_insn_r
->aarch64_insn
, 12, 20);
4429 offset
= (imm9_off
& 0x0100) ? (((~imm9_off
) & 0x01ff) + 1) : imm9_off
;
4430 datasize
= 8 << size_bits
;
4431 regcache_raw_read_unsigned (aarch64_insn_r
->regcache
, reg_rn
,
4433 if (insn_bits10_11
!= 0x01)
4435 if (imm9_off
& 0x0100)
4436 address
= address
- offset
;
4438 address
= address
+ offset
;
4440 record_buf_mem
[0] = datasize
>> 3;
4441 record_buf_mem
[1] = address
;
4442 aarch64_insn_r
->mem_rec_count
= 1;
4447 record_buf
[0] = reg_rt
+ AARCH64_V0_REGNUM
;
4449 record_buf
[0] = reg_rt
;
4450 aarch64_insn_r
->reg_rec_count
= 1;
4452 if (insn_bits10_11
== 0x01 || insn_bits10_11
== 0x03)
4453 record_buf
[aarch64_insn_r
->reg_rec_count
++] = reg_rn
;
4455 /* Advanced SIMD load/store instructions. */
4457 return aarch64_record_asimd_load_store (aarch64_insn_r
);
4459 MEM_ALLOC (aarch64_insn_r
->aarch64_mems
, aarch64_insn_r
->mem_rec_count
,
4461 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
4463 return AARCH64_RECORD_SUCCESS
;
4466 /* Record handler for data processing SIMD and floating point instructions. */
4469 aarch64_record_data_proc_simd_fp (aarch64_insn_decode_record
*aarch64_insn_r
)
4471 uint8_t insn_bit21
, opcode
, rmode
, reg_rd
;
4472 uint8_t insn_bits24_27
, insn_bits28_31
, insn_bits10_11
, insn_bits12_15
;
4473 uint8_t insn_bits11_14
;
4474 uint32_t record_buf
[2];
4476 insn_bits24_27
= bits (aarch64_insn_r
->aarch64_insn
, 24, 27);
4477 insn_bits28_31
= bits (aarch64_insn_r
->aarch64_insn
, 28, 31);
4478 insn_bits10_11
= bits (aarch64_insn_r
->aarch64_insn
, 10, 11);
4479 insn_bits12_15
= bits (aarch64_insn_r
->aarch64_insn
, 12, 15);
4480 insn_bits11_14
= bits (aarch64_insn_r
->aarch64_insn
, 11, 14);
4481 opcode
= bits (aarch64_insn_r
->aarch64_insn
, 16, 18);
4482 rmode
= bits (aarch64_insn_r
->aarch64_insn
, 19, 20);
4483 reg_rd
= bits (aarch64_insn_r
->aarch64_insn
, 0, 4);
4484 insn_bit21
= bit (aarch64_insn_r
->aarch64_insn
, 21);
4487 debug_printf ("Process record: data processing SIMD/FP: ");
4489 if ((insn_bits28_31
& 0x05) == 0x01 && insn_bits24_27
== 0x0e)
4491 /* Floating point - fixed point conversion instructions. */
4495 debug_printf ("FP - fixed point conversion");
4497 if ((opcode
>> 1) == 0x0 && rmode
== 0x03)
4498 record_buf
[0] = reg_rd
;
4500 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
4502 /* Floating point - conditional compare instructions. */
4503 else if (insn_bits10_11
== 0x01)
4506 debug_printf ("FP - conditional compare");
4508 record_buf
[0] = AARCH64_CPSR_REGNUM
;
4510 /* Floating point - data processing (2-source) and
4511 conditional select instructions. */
4512 else if (insn_bits10_11
== 0x02 || insn_bits10_11
== 0x03)
4515 debug_printf ("FP - DP (2-source)");
4517 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
4519 else if (insn_bits10_11
== 0x00)
4521 /* Floating point - immediate instructions. */
4522 if ((insn_bits12_15
& 0x01) == 0x01
4523 || (insn_bits12_15
& 0x07) == 0x04)
4526 debug_printf ("FP - immediate");
4527 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
4529 /* Floating point - compare instructions. */
4530 else if ((insn_bits12_15
& 0x03) == 0x02)
4533 debug_printf ("FP - immediate");
4534 record_buf
[0] = AARCH64_CPSR_REGNUM
;
4536 /* Floating point - integer conversions instructions. */
4537 else if (insn_bits12_15
== 0x00)
4539 /* Convert float to integer instruction. */
4540 if (!(opcode
>> 1) || ((opcode
>> 1) == 0x02 && !rmode
))
4543 debug_printf ("float to int conversion");
4545 record_buf
[0] = reg_rd
+ AARCH64_X0_REGNUM
;
4547 /* Convert integer to float instruction. */
4548 else if ((opcode
>> 1) == 0x01 && !rmode
)
4551 debug_printf ("int to float conversion");
4553 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
4555 /* Move float to integer instruction. */
4556 else if ((opcode
>> 1) == 0x03)
4559 debug_printf ("move float to int");
4561 if (!(opcode
& 0x01))
4562 record_buf
[0] = reg_rd
+ AARCH64_X0_REGNUM
;
4564 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
4567 return AARCH64_RECORD_UNKNOWN
;
4570 return AARCH64_RECORD_UNKNOWN
;
4573 return AARCH64_RECORD_UNKNOWN
;
4575 else if ((insn_bits28_31
& 0x09) == 0x00 && insn_bits24_27
== 0x0e)
4578 debug_printf ("SIMD copy");
4580 /* Advanced SIMD copy instructions. */
4581 if (!bits (aarch64_insn_r
->aarch64_insn
, 21, 23)
4582 && !bit (aarch64_insn_r
->aarch64_insn
, 15)
4583 && bit (aarch64_insn_r
->aarch64_insn
, 10))
4585 if (insn_bits11_14
== 0x05 || insn_bits11_14
== 0x07)
4586 record_buf
[0] = reg_rd
+ AARCH64_X0_REGNUM
;
4588 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
4591 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
4593 /* All remaining floating point or advanced SIMD instructions. */
4597 debug_printf ("all remain");
4599 record_buf
[0] = reg_rd
+ AARCH64_V0_REGNUM
;
4603 debug_printf ("\n");
4605 /* Record the V/X register. */
4606 aarch64_insn_r
->reg_rec_count
++;
4608 /* Some of these instructions may set bits in the FPSR, so record it
4610 record_buf
[1] = AARCH64_FPSR_REGNUM
;
4611 aarch64_insn_r
->reg_rec_count
++;
4613 gdb_assert (aarch64_insn_r
->reg_rec_count
== 2);
4614 REG_ALLOC (aarch64_insn_r
->aarch64_regs
, aarch64_insn_r
->reg_rec_count
,
4616 return AARCH64_RECORD_SUCCESS
;
4619 /* Decodes insns type and invokes its record handler. */
4622 aarch64_record_decode_insn_handler (aarch64_insn_decode_record
*aarch64_insn_r
)
4624 uint32_t ins_bit25
, ins_bit26
, ins_bit27
, ins_bit28
;
4626 ins_bit25
= bit (aarch64_insn_r
->aarch64_insn
, 25);
4627 ins_bit26
= bit (aarch64_insn_r
->aarch64_insn
, 26);
4628 ins_bit27
= bit (aarch64_insn_r
->aarch64_insn
, 27);
4629 ins_bit28
= bit (aarch64_insn_r
->aarch64_insn
, 28);
4631 /* Data processing - immediate instructions. */
4632 if (!ins_bit26
&& !ins_bit27
&& ins_bit28
)
4633 return aarch64_record_data_proc_imm (aarch64_insn_r
);
4635 /* Branch, exception generation and system instructions. */
4636 if (ins_bit26
&& !ins_bit27
&& ins_bit28
)
4637 return aarch64_record_branch_except_sys (aarch64_insn_r
);
4639 /* Load and store instructions. */
4640 if (!ins_bit25
&& ins_bit27
)
4641 return aarch64_record_load_store (aarch64_insn_r
);
4643 /* Data processing - register instructions. */
4644 if (ins_bit25
&& !ins_bit26
&& ins_bit27
)
4645 return aarch64_record_data_proc_reg (aarch64_insn_r
);
4647 /* Data processing - SIMD and floating point instructions. */
4648 if (ins_bit25
&& ins_bit26
&& ins_bit27
)
4649 return aarch64_record_data_proc_simd_fp (aarch64_insn_r
);
4651 return AARCH64_RECORD_UNSUPPORTED
;
4654 /* Cleans up local record registers and memory allocations. */
4657 deallocate_reg_mem (aarch64_insn_decode_record
*record
)
4659 xfree (record
->aarch64_regs
);
4660 xfree (record
->aarch64_mems
);
4664 namespace selftests
{
4667 aarch64_process_record_test (void)
4669 struct gdbarch_info info
;
4672 info
.bfd_arch_info
= bfd_scan_arch ("aarch64");
4674 struct gdbarch
*gdbarch
= gdbarch_find_by_info (info
);
4675 SELF_CHECK (gdbarch
!= NULL
);
4677 aarch64_insn_decode_record aarch64_record
;
4679 memset (&aarch64_record
, 0, sizeof (aarch64_insn_decode_record
));
4680 aarch64_record
.regcache
= NULL
;
4681 aarch64_record
.this_addr
= 0;
4682 aarch64_record
.gdbarch
= gdbarch
;
4684 /* 20 00 80 f9 prfm pldl1keep, [x1] */
4685 aarch64_record
.aarch64_insn
= 0xf9800020;
4686 ret
= aarch64_record_decode_insn_handler (&aarch64_record
);
4687 SELF_CHECK (ret
== AARCH64_RECORD_SUCCESS
);
4688 SELF_CHECK (aarch64_record
.reg_rec_count
== 0);
4689 SELF_CHECK (aarch64_record
.mem_rec_count
== 0);
4691 deallocate_reg_mem (&aarch64_record
);
4694 } // namespace selftests
4695 #endif /* GDB_SELF_TEST */
4697 /* Parse the current instruction and record the values of the registers and
4698 memory that will be changed in current instruction to record_arch_list
4699 return -1 if something is wrong. */
4702 aarch64_process_record (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
4703 CORE_ADDR insn_addr
)
4705 uint32_t rec_no
= 0;
4706 uint8_t insn_size
= 4;
4708 gdb_byte buf
[insn_size
];
4709 aarch64_insn_decode_record aarch64_record
;
4711 memset (&buf
[0], 0, insn_size
);
4712 memset (&aarch64_record
, 0, sizeof (aarch64_insn_decode_record
));
4713 target_read_memory (insn_addr
, &buf
[0], insn_size
);
4714 aarch64_record
.aarch64_insn
4715 = (uint32_t) extract_unsigned_integer (&buf
[0],
4717 gdbarch_byte_order (gdbarch
));
4718 aarch64_record
.regcache
= regcache
;
4719 aarch64_record
.this_addr
= insn_addr
;
4720 aarch64_record
.gdbarch
= gdbarch
;
4722 ret
= aarch64_record_decode_insn_handler (&aarch64_record
);
4723 if (ret
== AARCH64_RECORD_UNSUPPORTED
)
4725 gdb_printf (gdb_stderr
,
4726 _("Process record does not support instruction "
4727 "0x%0x at address %s.\n"),
4728 aarch64_record
.aarch64_insn
,
4729 paddress (gdbarch
, insn_addr
));
4735 /* Record registers. */
4736 record_full_arch_list_add_reg (aarch64_record
.regcache
,
4738 /* Always record register CPSR. */
4739 record_full_arch_list_add_reg (aarch64_record
.regcache
,
4740 AARCH64_CPSR_REGNUM
);
4741 if (aarch64_record
.aarch64_regs
)
4742 for (rec_no
= 0; rec_no
< aarch64_record
.reg_rec_count
; rec_no
++)
4743 if (record_full_arch_list_add_reg (aarch64_record
.regcache
,
4744 aarch64_record
.aarch64_regs
[rec_no
]))
4747 /* Record memories. */
4748 if (aarch64_record
.aarch64_mems
)
4749 for (rec_no
= 0; rec_no
< aarch64_record
.mem_rec_count
; rec_no
++)
4750 if (record_full_arch_list_add_mem
4751 ((CORE_ADDR
)aarch64_record
.aarch64_mems
[rec_no
].addr
,
4752 aarch64_record
.aarch64_mems
[rec_no
].len
))
4755 if (record_full_arch_list_add_end ())
4759 deallocate_reg_mem (&aarch64_record
);