LLDB mainline
RegisterInfoDynamic_riscv32.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
10
13#include "lldb/lldb-defines.h"
14#include "llvm/ADT/StringMap.h"
15#include "llvm/Support/Compiler.h"
16
17#include <stddef.h>
18
19#define GPR_OFFSET(idx) ((idx) * sizeof(uint32_t))
20#define FPR_OFFSET(idx) ((idx) * sizeof(uint32_t))
21
22#define DECLARE_REGISTER_INFOS_RISCV32_STRUCT
24#undef DECLARE_REGISTER_INFOS_RISCV32_STRUCT
25
30
32 return m_dyn_reg_infos.GetNumRegisters();
33}
34
36 for (uint32_t set_idx = 0; set_idx < GetRegisterSetCount(); ++set_idx) {
37 const lldb_private::RegisterSet *set =
38 m_dyn_reg_infos.GetRegisterSet(set_idx);
39 if (strcmp(set->name, "GPR") == 0)
40 return set->num_registers;
41 }
42 return 0;
43}
44
46 for (uint32_t set_idx = 0; set_idx < GetRegisterSetCount(); ++set_idx) {
47 const lldb_private::RegisterSet *set =
48 m_dyn_reg_infos.GetRegisterSet(set_idx);
49 if (strcmp(set->name, "FPR") == 0)
50 return set->num_registers;
51 }
52 return 0;
53}
54
57 return &*m_dyn_reg_infos
58 .registers<lldb_private::DynamicRegisterInfo::
59 reg_collection_const_range>()
60 .begin();
61}
62
64 return m_dyn_reg_infos.GetNumRegisterSets();
65}
66
68 uint32_t reg_index) const {
69 for (size_t set_index = 0; set_index < m_dyn_reg_infos.GetNumRegisterSets();
70 ++set_index) {
71 const lldb_private::RegisterSet *reg_set =
72 m_dyn_reg_infos.GetRegisterSet(set_index);
73 for (uint32_t idx = 0; idx < reg_set->num_registers; ++idx)
74 if (reg_set->registers[idx] == reg_index)
75 return set_index;
76 }
78}
79
82 if (set_index < GetRegisterSetCount())
83 return m_dyn_reg_infos.GetRegisterSet(set_index);
84 return nullptr;
85}
86
88 std::vector<lldb_private::DynamicRegisterInfo::Register> regs) {
89 return m_dyn_reg_infos.SetRegisterInfo(std::move(regs), m_target_arch);
90}
91
93RegisterInfoDynamic_riscv32::GetRegisterInfo(llvm::StringRef reg_name) const {
94 return m_dyn_reg_infos.GetRegisterInfo(reg_name);
95}
96
98 llvm::ArrayRef<std::string> features,
100 cs_reg_infos.clear();
101
102 // Sort and deduplicate to make the list independent of caller ordering.
103 llvm::SmallVector<llvm::StringRef> normalized_features(features.begin(),
104 features.end());
105 llvm::sort(normalized_features);
106 normalized_features.erase(llvm::unique(normalized_features),
107 normalized_features.end());
108
110 cs_reg_infos.reserve(k_num_csr_registers);
111
112 // Construct default CS register information. CS register information entries
113 // are stored in CSR-address order.
114 for (uint32_t reg = 0; reg < k_num_csr_registers; ++reg) {
116 for (auto &kind : csr.kinds)
117 kind = LLDB_INVALID_REGNUM;
118
119 lldb_private::ConstString name(llvm::formatv("csr_{0:x}", reg).str());
120 csr.name = name.GetCString();
121 csr.alt_name = csr.name;
122 csr.byte_size = 4;
123 csr.byte_offset = 0;
131 csr.value_regs = nullptr;
132 csr.invalidate_regs = nullptr;
133 csr.register_type = nullptr;
134
135 cs_reg_infos.push_back(csr);
136 }
137
138 // Patch application is order-dependent; later patches override earlier ones
139 // for the same CSR address.
140 ConfigureCSRegInfos("default", cs_reg_infos);
141
142 for (const auto &feature : normalized_features)
143 ConfigureCSRegInfos(feature, cs_reg_infos);
144}
145
147 llvm::StringRef feature,
149 // Initialized on first use so that the patch set does not depend on the
150 // initialization order of globals in other translation units.
151 static const llvm::StringMap<llvm::ArrayRef<lldb_private::RegisterInfo>>
152 g_register_infos_riscv32_csr_patches = {
153 {"default", llvm::ArrayRef(g_register_infos_riscv32_csr_patch)},
154 {"xqciint",
155 llvm::ArrayRef(g_register_infos_riscv32_csr_xqciint_patch)}};
156
157 auto it = g_register_infos_riscv32_csr_patches.find(feature);
158 if (it == g_register_infos_riscv32_csr_patches.end())
159 return;
160
161 for (const auto &csr : it->second) {
162 const uint32_t lldb_reg = csr.kinds[lldb::eRegisterKindLLDB];
163 if (lldb_reg < csr_first_riscv || lldb_reg > csr_last_riscv)
164 continue;
165 uint32_t idx = lldb_reg - csr_first_riscv;
166 if (idx < cs_reg_infos.size())
167 cs_reg_infos[idx] = csr;
168 }
169}
const size_t k_num_csr_registers
size_t SetRegisterInfo(std::vector< lldb_private::DynamicRegisterInfo::Register > regs)
const lldb_private::RegisterSet * GetRegisterSet(size_t reg_set) const override
static void BuildCSRegInfos(llvm::ArrayRef< std::string > features, llvm::SmallVectorImpl< lldb_private::RegisterInfo > &cs_reg_infos)
Builds CS register information entries for 32-bit RISC-V debug targets on the basis of the enabled IS...
static void ConfigureCSRegInfos(llvm::StringRef feature, llvm::SmallVectorImpl< lldb_private::RegisterInfo > &cs_reg_infos)
Applies the CS register information patch set for a given feature.
const lldb_private::ArchSpec m_target_arch
uint32_t GetRegisterCount() const override
lldb_private::DynamicRegisterInfo m_dyn_reg_infos
RegisterInfoDynamic_riscv32(const lldb_private::ArchSpec &target_arch)
size_t GetRegisterSetFromRegisterIndex(uint32_t reg_index) const override
const lldb_private::RegisterInfo * GetRegisterInfo() const override
An architecture specification class.
Definition ArchSpec.h:32
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
RegisterInfoAndSetInterface(const lldb_private::ArchSpec &target_arch)
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
@ eEncodingUint
unsigned integer
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindLLDB
lldb's internal register numbers
@ eRegisterKindDWARF
the register numbers seen DWARF
@ eRegisterKindEHFrame
the register numbers seen in eh_frame
@ eRegisterKindProcessPlugin
num used by the process plugin - e.g.
Every register is described in detail including its name, alternate name (optional),...
lldb::Encoding encoding
Encoding of the register bits.
const char * alt_name
Alternate name of this register, can be NULL.
uint32_t * value_regs
List of registers (terminated with LLDB_INVALID_REGNUM).
uint32_t byte_offset
The byte offset in the register context data where this register's value is found.
uint32_t byte_size
Size in bytes of the register.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
const RegisterType * register_type
If not nullptr, a type defined by XML descriptions.
const char * name
Name of this register, can't be NULL.
lldb::Format format
Default display format.
uint32_t * invalidate_regs
List of registers (terminated with LLDB_INVALID_REGNUM).
Registers are grouped into register sets.
size_t num_registers
The number of registers in REGISTERS array below.
const uint32_t * registers
An array of register indicies in this set.
const char * name
Name of this register set.