1 //===-- ABISysV_loongarch.cpp----------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "ABISysV_loongarch.h"
15 #include "llvm/IR/DerivedTypes.h"
16 #include "llvm/Support/MathExtras.h"
18 #include "Utility/LoongArch_DWARF_Registers.h"
19 #include "lldb/Core/PluginManager.h"
20 #include "lldb/Core/Value.h"
21 #include "lldb/Target/RegisterContext.h"
22 #include "lldb/Target/StackFrame.h"
23 #include "lldb/Target/Thread.h"
24 #include "lldb/Utility/LLDBLog.h"
25 #include "lldb/Utility/RegisterValue.h"
26 #include "lldb/ValueObject/ValueObjectConstResult.h"
28 #define DEFINE_REG_NAME(reg_num) ConstString(#reg_num).GetCString()
29 #define DEFINE_REG_NAME_STR(reg_name) ConstString(reg_name).GetCString()
31 // The ABI is not a source of such information as size, offset, encoding, etc.
32 // of a register. Just provides correct dwarf and eh_frame numbers.
34 #define DEFINE_GENERIC_REGISTER_STUB(dwarf_num, generic_num) \
36 DEFINE_REG_NAME(dwarf_num), \
37 DEFINE_REG_NAME_STR(nullptr), \
42 {dwarf_num, dwarf_num, generic_num, LLDB_INVALID_REGNUM, dwarf_num}, \
48 #define DEFINE_REGISTER_STUB(dwarf_num) \
49 DEFINE_GENERIC_REGISTER_STUB(dwarf_num, LLDB_INVALID_REGNUM)
52 using namespace lldb_private
;
54 LLDB_PLUGIN_DEFINE_ADV(ABISysV_loongarch
, ABILoongArch
)
97 static const std::array
<RegisterInfo
, 33> g_register_infos
= {
98 {DEFINE_REGISTER_STUB(r0
),
99 DEFINE_GENERIC_REGISTER_STUB(r1
, LLDB_REGNUM_GENERIC_RA
),
100 DEFINE_REGISTER_STUB(r2
),
101 DEFINE_GENERIC_REGISTER_STUB(r3
, LLDB_REGNUM_GENERIC_SP
),
102 DEFINE_GENERIC_REGISTER_STUB(r4
, LLDB_REGNUM_GENERIC_ARG1
),
103 DEFINE_GENERIC_REGISTER_STUB(r5
, LLDB_REGNUM_GENERIC_ARG2
),
104 DEFINE_GENERIC_REGISTER_STUB(r6
, LLDB_REGNUM_GENERIC_ARG3
),
105 DEFINE_GENERIC_REGISTER_STUB(r7
, LLDB_REGNUM_GENERIC_ARG4
),
106 DEFINE_GENERIC_REGISTER_STUB(r8
, LLDB_REGNUM_GENERIC_ARG5
),
107 DEFINE_GENERIC_REGISTER_STUB(r9
, LLDB_REGNUM_GENERIC_ARG6
),
108 DEFINE_GENERIC_REGISTER_STUB(r10
, LLDB_REGNUM_GENERIC_ARG7
),
109 DEFINE_GENERIC_REGISTER_STUB(r11
, LLDB_REGNUM_GENERIC_ARG8
),
110 DEFINE_REGISTER_STUB(r12
),
111 DEFINE_REGISTER_STUB(r13
),
112 DEFINE_REGISTER_STUB(r14
),
113 DEFINE_REGISTER_STUB(r15
),
114 DEFINE_REGISTER_STUB(r16
),
115 DEFINE_REGISTER_STUB(r17
),
116 DEFINE_REGISTER_STUB(r18
),
117 DEFINE_REGISTER_STUB(r19
),
118 DEFINE_REGISTER_STUB(r20
),
119 DEFINE_REGISTER_STUB(r21
),
120 DEFINE_GENERIC_REGISTER_STUB(r22
, LLDB_REGNUM_GENERIC_FP
),
121 DEFINE_REGISTER_STUB(r23
),
122 DEFINE_REGISTER_STUB(r24
),
123 DEFINE_REGISTER_STUB(r25
),
124 DEFINE_REGISTER_STUB(r26
),
125 DEFINE_REGISTER_STUB(r27
),
126 DEFINE_REGISTER_STUB(r28
),
127 DEFINE_REGISTER_STUB(r29
),
128 DEFINE_REGISTER_STUB(r30
),
129 DEFINE_REGISTER_STUB(r31
),
130 DEFINE_GENERIC_REGISTER_STUB(pc
, LLDB_REGNUM_GENERIC_PC
)}};
134 // Number of argument registers (the base integer calling convention
135 // provides 8 argument registers, a0-a7)
136 static constexpr size_t g_regs_for_args_count
= 8U;
138 const RegisterInfo
*ABISysV_loongarch::GetRegisterInfoArray(uint32_t &count
) {
139 count
= dwarf::g_register_infos
.size();
140 return dwarf::g_register_infos
.data();
143 //------------------------------------------------------------------
145 //------------------------------------------------------------------
148 ABISysV_loongarch::CreateInstance(ProcessSP process_sp
, const ArchSpec
&arch
) {
149 llvm::Triple::ArchType machine
= arch
.GetTriple().getArch();
151 if (llvm::Triple::loongarch32
!= machine
&&
152 llvm::Triple::loongarch64
!= machine
)
155 ABISysV_loongarch
*abi
=
156 new ABISysV_loongarch(std::move(process_sp
), MakeMCRegisterInfo(arch
));
158 abi
->SetIsLA64(llvm::Triple::loongarch64
== machine
);
162 static bool UpdateRegister(RegisterContext
*reg_ctx
,
163 const lldb::RegisterKind reg_kind
,
164 const uint32_t reg_num
, const addr_t value
) {
165 Log
*log
= GetLog(LLDBLog::Expressions
);
167 const RegisterInfo
*reg_info
= reg_ctx
->GetRegisterInfo(reg_kind
, reg_num
);
169 LLDB_LOG(log
, "Writing {0}: 0x{1:x}", reg_info
->name
,
170 static_cast<uint64_t>(value
));
171 if (!reg_ctx
->WriteRegisterFromUnsigned(reg_info
, value
)) {
172 LLDB_LOG(log
, "Writing {0}: failed", reg_info
->name
);
178 static void LogInitInfo(Log
&log
, const Thread
&thread
, addr_t sp
,
179 addr_t func_addr
, addr_t return_addr
,
180 const llvm::ArrayRef
<addr_t
> args
) {
181 std::stringstream ss
;
182 ss
<< "ABISysV_loongarch::PrepareTrivialCall"
183 << " (tid = 0x" << std::hex
<< thread
.GetID() << ", sp = 0x" << sp
184 << ", func_addr = 0x" << func_addr
<< ", return_addr = 0x" << return_addr
;
186 for (auto [idx
, arg
] : enumerate(args
))
187 ss
<< ", arg" << std::dec
<< idx
<< " = 0x" << std::hex
<< arg
;
189 log
.PutString(ss
.str());
192 bool ABISysV_loongarch::PrepareTrivialCall(Thread
&thread
, addr_t sp
,
193 addr_t func_addr
, addr_t return_addr
,
194 llvm::ArrayRef
<addr_t
> args
) const {
195 Log
*log
= GetLog(LLDBLog::Expressions
);
197 LogInitInfo(*log
, thread
, sp
, func_addr
, return_addr
, args
);
199 const auto reg_ctx_sp
= thread
.GetRegisterContext();
201 LLDB_LOG(log
, "Failed to get RegisterContext");
205 if (args
.size() > g_regs_for_args_count
) {
206 LLDB_LOG(log
, "Function has {0} arguments, but only {1} are allowed!",
207 args
.size(), g_regs_for_args_count
);
211 // Write arguments to registers
212 for (auto [idx
, arg
] : enumerate(args
)) {
213 const RegisterInfo
*reg_info
= reg_ctx_sp
->GetRegisterInfo(
214 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
+ idx
);
215 LLDB_LOG(log
, "About to write arg{0} ({1:x}) into {2}", idx
, arg
,
218 if (!reg_ctx_sp
->WriteRegisterFromUnsigned(reg_info
, arg
)) {
219 LLDB_LOG(log
, "Failed to write arg{0} ({1:x}) into {2}", idx
, arg
,
225 if (!UpdateRegister(reg_ctx_sp
.get(), eRegisterKindGeneric
,
226 LLDB_REGNUM_GENERIC_PC
, func_addr
))
228 if (!UpdateRegister(reg_ctx_sp
.get(), eRegisterKindGeneric
,
229 LLDB_REGNUM_GENERIC_SP
, sp
))
231 if (!UpdateRegister(reg_ctx_sp
.get(), eRegisterKindGeneric
,
232 LLDB_REGNUM_GENERIC_RA
, return_addr
))
235 LLDB_LOG(log
, "ABISysV_loongarch::{0}() success", __FUNCTION__
);
239 bool ABISysV_loongarch::GetArgumentValues(Thread
&thread
,
240 ValueList
&values
) const {
245 Status
ABISysV_loongarch::SetReturnValueObject(StackFrameSP
&frame_sp
,
246 ValueObjectSP
&new_value_sp
) {
249 result
= Status::FromErrorString("Empty value object for return value.");
253 CompilerType compiler_type
= new_value_sp
->GetCompilerType();
254 if (!compiler_type
) {
255 result
= Status::FromErrorString("Null clang type for return value.");
259 auto ®_ctx
= *frame_sp
->GetThread()->GetRegisterContext();
261 bool is_signed
= false;
262 if (!compiler_type
.IsIntegerOrEnumerationType(is_signed
) &&
263 !compiler_type
.IsPointerType()) {
264 result
= Status::FromErrorString(
265 "We don't support returning other types at present");
270 size_t num_bytes
= new_value_sp
->GetData(data
, result
);
273 result
= Status::FromErrorStringWithFormat(
274 "Couldn't convert return value to raw data: %s", result
.AsCString());
278 size_t reg_size
= m_is_la64
? 8 : 4;
279 // Currently, we only support sizeof(data) <= 2 * reg_size.
280 // 1. If the (`size` <= reg_size), the `data` will be returned through `ARG1`.
281 // 2. If the (`size` > reg_size && `size` <= 2 * reg_size), the `data` will be
282 // returned through a pair of registers (ARG1 and ARG2), and the lower-ordered
283 // bits in the `ARG1`.
284 if (num_bytes
> 2 * reg_size
) {
285 result
= Status::FromErrorString(
286 "We don't support returning large integer values at present.");
291 uint64_t raw_value
= data
.GetMaxU64(&offset
, num_bytes
);
292 // According to psABI, i32 (no matter signed or unsigned) should be
293 // sign-extended in register.
294 if (4 == num_bytes
&& m_is_la64
)
295 raw_value
= llvm::SignExtend64
<32>(raw_value
);
297 reg_ctx
.GetRegisterInfo(eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
);
298 if (!reg_ctx
.WriteRegisterFromUnsigned(reg_info
, raw_value
)) {
299 result
= Status::FromErrorStringWithFormat(
300 "Couldn't write value to register %s", reg_info
->name
);
304 if (num_bytes
<= reg_size
)
305 return result
; // Successfully written.
307 // For loongarch32, get the upper 32 bits from raw_value and write them.
308 // For loongarch64, get the next 64 bits from data and write them.
312 raw_value
= data
.GetMaxU64(&offset
, num_bytes
- reg_size
);
315 reg_ctx
.GetRegisterInfo(eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG2
);
316 if (!reg_ctx
.WriteRegisterFromUnsigned(reg_info
, raw_value
))
317 result
= Status::FromErrorStringWithFormat(
318 "Couldn't write value to register %s", reg_info
->name
);
323 template <typename T
>
324 static void SetInteger(Scalar
&scalar
, uint64_t raw_value
, bool is_signed
) {
325 static_assert(std::is_unsigned
<T
>::value
, "T must be an unsigned type.");
326 raw_value
&= std::numeric_limits
<T
>::max();
328 scalar
= static_cast<typename
std::make_signed
<T
>::type
>(raw_value
);
330 scalar
= static_cast<T
>(raw_value
);
333 static bool SetSizedInteger(Scalar
&scalar
, uint64_t raw_value
,
334 uint8_t size_in_bytes
, bool is_signed
) {
335 switch (size_in_bytes
) {
339 case sizeof(uint64_t):
340 SetInteger
<uint64_t>(scalar
, raw_value
, is_signed
);
343 case sizeof(uint32_t):
344 SetInteger
<uint32_t>(scalar
, raw_value
, is_signed
);
347 case sizeof(uint16_t):
348 SetInteger
<uint16_t>(scalar
, raw_value
, is_signed
);
351 case sizeof(uint8_t):
352 SetInteger
<uint8_t>(scalar
, raw_value
, is_signed
);
359 static bool SetSizedFloat(Scalar
&scalar
, uint64_t raw_value
,
360 uint8_t size_in_bytes
) {
361 switch (size_in_bytes
) {
365 case sizeof(uint64_t):
366 scalar
= *reinterpret_cast<double *>(&raw_value
);
369 case sizeof(uint32_t):
370 scalar
= *reinterpret_cast<float *>(&raw_value
);
377 static ValueObjectSP
GetValObjFromIntRegs(Thread
&thread
,
378 const RegisterContextSP
®_ctx
,
379 llvm::Triple::ArchType machine
,
381 uint32_t byte_size
) {
383 ValueObjectSP return_valobj_sp
;
385 reg_ctx
->GetRegisterInfo(eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
);
387 reg_ctx
->GetRegisterInfo(eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG2
);
388 uint64_t raw_value
= 0;
391 case sizeof(uint32_t):
392 // Read a0 to get the arg
393 raw_value
= reg_ctx
->ReadRegisterAsUnsigned(reg_info_a0
, 0) & UINT32_MAX
;
395 case sizeof(uint64_t):
396 // Read a0 to get the arg on loongarch64, a0 and a1 on loongarch32
397 if (llvm::Triple::loongarch32
== machine
) {
398 raw_value
= reg_ctx
->ReadRegisterAsUnsigned(reg_info_a0
, 0) & UINT32_MAX
;
400 (reg_ctx
->ReadRegisterAsUnsigned(reg_info_a1
, 0) & UINT32_MAX
) << 32U;
402 raw_value
= reg_ctx
->ReadRegisterAsUnsigned(reg_info_a0
, 0);
406 // Read a0 and a1 to get the arg on loongarch64, not supported on
408 if (llvm::Triple::loongarch32
== machine
)
409 return return_valobj_sp
;
411 // Create the ValueObjectSP here and return
412 std::unique_ptr
<DataBufferHeap
> heap_data_up(
413 new DataBufferHeap(byte_size
, 0));
414 const ByteOrder byte_order
= thread
.GetProcess()->GetByteOrder();
415 RegisterValue reg_value_a0
, reg_value_a1
;
416 if (reg_ctx
->ReadRegister(reg_info_a0
, reg_value_a0
) &&
417 reg_ctx
->ReadRegister(reg_info_a1
, reg_value_a1
)) {
419 if (reg_value_a0
.GetAsMemoryData(*reg_info_a0
,
420 heap_data_up
->GetBytes() + 0, 8,
421 byte_order
, error
) &&
422 reg_value_a1
.GetAsMemoryData(*reg_info_a1
,
423 heap_data_up
->GetBytes() + 8, 8,
424 byte_order
, error
)) {
425 value
.SetBytes(heap_data_up
.release(), byte_size
);
426 return ValueObjectConstResult::Create(
427 thread
.GetStackFrameAtIndex(0).get(), value
, ConstString(""));
433 return return_valobj_sp
;
436 if (type_flags
& eTypeIsInteger
) {
437 if (!SetSizedInteger(value
.GetScalar(), raw_value
, byte_size
,
438 type_flags
& eTypeIsSigned
))
439 return return_valobj_sp
;
440 } else if (type_flags
& eTypeIsFloat
) {
441 if (!SetSizedFloat(value
.GetScalar(), raw_value
, byte_size
))
442 return return_valobj_sp
;
444 return return_valobj_sp
;
446 value
.SetValueType(Value::ValueType::Scalar
);
447 return_valobj_sp
= ValueObjectConstResult::Create(
448 thread
.GetStackFrameAtIndex(0).get(), value
, ConstString(""));
449 return return_valobj_sp
;
452 static ValueObjectSP
GetValObjFromFPRegs(Thread
&thread
,
453 const RegisterContextSP
®_ctx
,
454 llvm::Triple::ArchType machine
,
456 uint32_t byte_size
) {
457 auto *reg_info_fa0
= reg_ctx
->GetRegisterInfoByName("f0");
458 bool use_fp_regs
= false;
459 ValueObjectSP return_valobj_sp
;
467 raw_value
= reg_ctx
->ReadRegisterAsUnsigned(reg_info_fa0
, 0);
468 if (!SetSizedFloat(value
.GetScalar(), raw_value
, byte_size
))
469 return return_valobj_sp
;
470 value
.SetValueType(Value::ValueType::Scalar
);
471 return ValueObjectConstResult::Create(thread
.GetStackFrameAtIndex(0).get(),
472 value
, ConstString(""));
474 // we should never reach this, but if we do, use the integer registers
475 return GetValObjFromIntRegs(thread
, reg_ctx
, machine
, type_flags
, byte_size
);
478 ValueObjectSP
ABISysV_loongarch::GetReturnValueObjectSimple(
479 Thread
&thread
, CompilerType
&compiler_type
) const {
480 ValueObjectSP return_valobj_sp
;
483 return return_valobj_sp
;
485 auto reg_ctx
= thread
.GetRegisterContext();
487 return return_valobj_sp
;
490 value
.SetCompilerType(compiler_type
);
492 const uint32_t type_flags
= compiler_type
.GetTypeInfo();
493 const size_t byte_size
= compiler_type
.GetByteSize(&thread
).value_or(0);
494 const ArchSpec arch
= thread
.GetProcess()->GetTarget().GetArchitecture();
495 const llvm::Triple::ArchType machine
= arch
.GetMachine();
497 if (type_flags
& eTypeIsInteger
) {
499 GetValObjFromIntRegs(thread
, reg_ctx
, machine
, type_flags
, byte_size
);
500 return return_valobj_sp
;
502 if (type_flags
& eTypeIsPointer
) {
503 const auto *reg_info_a0
= reg_ctx
->GetRegisterInfo(
504 eRegisterKindGeneric
, LLDB_REGNUM_GENERIC_ARG1
);
505 value
.GetScalar() = reg_ctx
->ReadRegisterAsUnsigned(reg_info_a0
, 0);
506 value
.SetValueType(Value::ValueType::Scalar
);
507 return ValueObjectConstResult::Create(thread
.GetStackFrameAtIndex(0).get(),
508 value
, ConstString(""));
510 if (type_flags
& eTypeIsFloat
) {
511 uint32_t float_count
= 0;
512 bool is_complex
= false;
514 if (compiler_type
.IsFloatingPointType(float_count
, is_complex
) &&
515 float_count
== 1 && !is_complex
) {
517 GetValObjFromFPRegs(thread
, reg_ctx
, machine
, type_flags
, byte_size
);
518 return return_valobj_sp
;
521 return return_valobj_sp
;
524 ValueObjectSP
ABISysV_loongarch::GetReturnValueObjectImpl(
525 Thread
&thread
, CompilerType
&return_compiler_type
) const {
526 ValueObjectSP return_valobj_sp
;
528 if (!return_compiler_type
)
529 return return_valobj_sp
;
531 ExecutionContext
exe_ctx(thread
.shared_from_this());
532 return GetReturnValueObjectSimple(thread
, return_compiler_type
);
535 bool ABISysV_loongarch::CreateFunctionEntryUnwindPlan(UnwindPlan
&unwind_plan
) {
537 unwind_plan
.SetRegisterKind(eRegisterKindDWARF
);
539 uint32_t pc_reg_num
= loongarch_dwarf::dwarf_gpr_pc
;
540 uint32_t sp_reg_num
= loongarch_dwarf::dwarf_gpr_sp
;
541 uint32_t ra_reg_num
= loongarch_dwarf::dwarf_gpr_ra
;
543 UnwindPlan::RowSP
row(new UnwindPlan::Row
);
545 // Define CFA as the stack pointer
546 row
->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num
, 0);
548 // Previous frame's pc is in ra
550 row
->SetRegisterLocationToRegister(pc_reg_num
, ra_reg_num
, true);
551 unwind_plan
.AppendRow(row
);
552 unwind_plan
.SetSourceName("loongarch function-entry unwind plan");
553 unwind_plan
.SetSourcedFromCompiler(eLazyBoolNo
);
558 bool ABISysV_loongarch::CreateDefaultUnwindPlan(UnwindPlan
&unwind_plan
) {
560 unwind_plan
.SetRegisterKind(eRegisterKindGeneric
);
562 uint32_t pc_reg_num
= LLDB_REGNUM_GENERIC_PC
;
563 uint32_t fp_reg_num
= LLDB_REGNUM_GENERIC_FP
;
565 UnwindPlan::RowSP
row(new UnwindPlan::Row
);
567 // Define the CFA as the current frame pointer value.
568 row
->GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num
, 0);
575 // Assume the ra reg (return pc) and caller's frame pointer
576 // have been spilled to stack already.
577 row
->SetRegisterLocationToAtCFAPlusOffset(fp_reg_num
, reg_size
* -2, true);
578 row
->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num
, reg_size
* -1, true);
580 unwind_plan
.AppendRow(row
);
581 unwind_plan
.SetSourceName("loongarch default unwind plan");
582 unwind_plan
.SetSourcedFromCompiler(eLazyBoolNo
);
583 unwind_plan
.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo
);
587 bool ABISysV_loongarch::RegisterIsVolatile(const RegisterInfo
*reg_info
) {
588 return !RegisterIsCalleeSaved(reg_info
);
591 bool ABISysV_loongarch::RegisterIsCalleeSaved(const RegisterInfo
*reg_info
) {
595 const char *name
= reg_info
->name
;
596 ArchSpec arch
= GetProcessSP()->GetTarget().GetArchitecture();
597 uint32_t arch_flags
= arch
.GetFlags();
598 // Floating point registers are only callee saved when using
599 // F or D hardware floating point ABIs.
600 bool is_hw_fp
= (arch_flags
& ArchSpec::eLoongArch_abi_mask
) != 0;
602 return llvm::StringSwitch
<bool>(name
)
604 .Cases("ra", "sp", "fp", true)
605 .Cases("s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", true)
606 // integer hardware names
607 .Cases("r1", "r3", "r22", true)
608 .Cases("r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "31", true)
609 // floating point ABI names
610 .Cases("fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", is_hw_fp
)
611 // floating point hardware names
612 .Cases("f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", is_hw_fp
)
616 void ABISysV_loongarch::Initialize() {
617 PluginManager::RegisterPlugin(GetPluginNameStatic(),
618 "System V ABI for LoongArch targets",
622 void ABISysV_loongarch::Terminate() {
623 PluginManager::UnregisterPlugin(CreateInstance
);
626 static uint32_t GetGenericNum(llvm::StringRef name
) {
627 return llvm::StringSwitch
<uint32_t>(name
)
628 .Case("pc", LLDB_REGNUM_GENERIC_PC
)
629 .Cases("ra", "r1", LLDB_REGNUM_GENERIC_RA
)
630 .Cases("sp", "r3", LLDB_REGNUM_GENERIC_SP
)
631 .Cases("fp", "r22", LLDB_REGNUM_GENERIC_FP
)
632 .Cases("a0", "r4", LLDB_REGNUM_GENERIC_ARG1
)
633 .Cases("a1", "r5", LLDB_REGNUM_GENERIC_ARG2
)
634 .Cases("a2", "r6", LLDB_REGNUM_GENERIC_ARG3
)
635 .Cases("a3", "r7", LLDB_REGNUM_GENERIC_ARG4
)
636 .Cases("a4", "r8", LLDB_REGNUM_GENERIC_ARG5
)
637 .Cases("a5", "r9", LLDB_REGNUM_GENERIC_ARG6
)
638 .Cases("a6", "r10", LLDB_REGNUM_GENERIC_ARG7
)
639 .Cases("a7", "r11", LLDB_REGNUM_GENERIC_ARG8
)
640 .Default(LLDB_INVALID_REGNUM
);
643 void ABISysV_loongarch::AugmentRegisterInfo(
644 std::vector
<lldb_private::DynamicRegisterInfo::Register
> ®s
) {
645 lldb_private::RegInfoBasedABI::AugmentRegisterInfo(regs
);
647 for (auto it
: llvm::enumerate(regs
)) {
648 // Set alt name for certain registers for convenience
649 if (it
.value().name
== "r0")
650 it
.value().alt_name
.SetCString("zero");
651 else if (it
.value().name
== "r1")
652 it
.value().alt_name
.SetCString("ra");
653 else if (it
.value().name
== "r3")
654 it
.value().alt_name
.SetCString("sp");
655 else if (it
.value().name
== "r22")
656 it
.value().alt_name
.SetCString("fp");
657 else if (it
.value().name
== "r4")
658 it
.value().alt_name
.SetCString("a0");
659 else if (it
.value().name
== "r5")
660 it
.value().alt_name
.SetCString("a1");
661 else if (it
.value().name
== "r6")
662 it
.value().alt_name
.SetCString("a2");
663 else if (it
.value().name
== "r7")
664 it
.value().alt_name
.SetCString("a3");
665 else if (it
.value().name
== "r8")
666 it
.value().alt_name
.SetCString("a4");
667 else if (it
.value().name
== "r9")
668 it
.value().alt_name
.SetCString("a5");
669 else if (it
.value().name
== "r10")
670 it
.value().alt_name
.SetCString("a6");
671 else if (it
.value().name
== "r11")
672 it
.value().alt_name
.SetCString("a7");
674 // Set generic regnum so lldb knows what the PC, etc is
675 it
.value().regnum_generic
= GetGenericNum(it
.value().name
.GetStringRef());