LLDB mainline
ArchitectureAArch64.cpp
Go to the documentation of this file.
1//===-- ArchitectureAArch64.cpp -------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
15
16using namespace lldb_private;
17using namespace lldb;
18
20
21void ArchitectureAArch64::Initialize() {
22 PluginManager::RegisterPlugin(GetPluginNameStatic(),
23 "AArch64-specific algorithms",
25}
26
29}
30
31std::unique_ptr<Architecture>
33 auto machine = arch.GetMachine();
34 if (machine != llvm::Triple::aarch64 && machine != llvm::Triple::aarch64_be &&
35 machine != llvm::Triple::aarch64_32) {
36 return nullptr;
37 }
38 return std::unique_ptr<Architecture>(new ArchitectureAArch64());
39}
40
41static void
43 uint64_t vg) {
44 // SVE Z register size is vg x 8 bytes.
45 uint32_t z_reg_byte_size = vg * 8;
46
47 // SVE vector length has changed, accordingly set size of Z, P and FFR
48 // registers. Also invalidate register offsets it will be recalculated
49 // after SVE register size update.
50 for (auto &reg : regs) {
51 if (reg.value_regs == nullptr) {
52 if (reg.name[0] == 'z' && isdigit(reg.name[1]))
53 reg.byte_size = z_reg_byte_size;
54 else if (reg.name[0] == 'p' && isdigit(reg.name[1]))
55 reg.byte_size = vg;
56 else if (strcmp(reg.name, "ffr") == 0)
57 reg.byte_size = vg;
58 }
59 reg.byte_offset = LLDB_INVALID_INDEX32;
60 }
61}
62
63static void
65 uint64_t svg) {
66 for (auto &reg : regs) {
67 if (strcmp(reg.name, "za") == 0) {
68 // ZA is a register with size (svg*8) * (svg*8). A square essentially.
69 reg.byte_size = (svg * 8) * (svg * 8);
70 }
71 reg.byte_offset = LLDB_INVALID_INDEX32;
72 }
73}
74
76 DataExtractor &reg_data,
77 RegisterContext &reg_context
78
79) const {
80 // Once we start to reconfigure registers, we cannot read any of them.
81 // So we must read VG and SVG up front.
82
83 const uint64_t fail_value = LLDB_INVALID_ADDRESS;
84 std::optional<uint64_t> vg_reg_value;
85 const RegisterInfo *vg_reg_info = reg_info.GetRegisterInfo("vg");
86 if (vg_reg_info) {
87 uint32_t vg_reg_num = vg_reg_info->kinds[eRegisterKindLLDB];
88 uint64_t reg_value =
89 reg_context.ReadRegisterAsUnsigned(vg_reg_num, fail_value);
90 if (reg_value != fail_value && reg_value <= 32)
91 vg_reg_value = reg_value;
92 }
93
94 std::optional<uint64_t> svg_reg_value;
95 const RegisterInfo *svg_reg_info = reg_info.GetRegisterInfo("svg");
96 if (svg_reg_info) {
97 uint32_t svg_reg_num = svg_reg_info->kinds[eRegisterKindLLDB];
98 uint64_t reg_value =
99 reg_context.ReadRegisterAsUnsigned(svg_reg_num, fail_value);
100 if (reg_value != fail_value && reg_value <= 32)
101 svg_reg_value = reg_value;
102 }
103
104 if (!vg_reg_value && !svg_reg_value)
105 return false;
106
108 if (vg_reg_value)
109 UpdateARM64SVERegistersInfos(regs, *vg_reg_value);
110 if (svg_reg_value)
111 UpdateARM64SMERegistersInfos(regs, *svg_reg_value);
112
113 // At this point if we have updated any registers, their offsets will all be
114 // invalid. If we did, we need to update them all.
115 reg_info.ConfigureOffsets();
116 // From here we are able to read registers again.
117
118 // Make a heap based buffer that is big enough to store all registers
119 reg_data.SetData(
120 std::make_shared<DataBufferHeap>(reg_info.GetRegisterDataByteSize(), 0));
121 reg_data.SetByteOrder(reg_context.GetByteOrder());
122
123 return true;
124}
static void UpdateARM64SMERegistersInfos(DynamicRegisterInfo::reg_collection_range regs, uint64_t svg)
static void UpdateARM64SVERegistersInfos(DynamicRegisterInfo::reg_collection_range regs, uint64_t vg)
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
An architecture specification class.
Definition: ArchSpec.h:31
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:683
static std::unique_ptr< Architecture > Create(const ArchSpec &arch)
bool ReconfigureRegisterInfo(DynamicRegisterInfo &reg_info, DataExtractor &reg_data, RegisterContext &reg_context) const override
An data extractor class.
Definition: DataExtractor.h:48
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
llvm::iterator_range< reg_collection::iterator > reg_collection_range
const lldb_private::RegisterInfo * GetRegisterInfo(uint32_t kind, uint32_t num) const
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value)
virtual lldb::ByteOrder GetByteOrder()
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:83
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
@ eRegisterKindLLDB
lldb's internal register numbers
Every register is described in detail including its name, alternate name (optional),...
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.