Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ABI/LoongArch/ABISysV_loongarch.cpp
213845 views
//===-- ABISysV_loongarch.cpp----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "ABISysV_loongarch.h"910#include <array>11#include <limits>12#include <sstream>1314#include "llvm/ADT/StringRef.h"15#include "llvm/IR/DerivedTypes.h"16#include "llvm/Support/MathExtras.h"1718#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"2728#define DEFINE_REG_NAME(reg_num) ConstString(#reg_num).GetCString()29#define DEFINE_REG_NAME_STR(reg_name) ConstString(reg_name).GetCString()3031// 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.3334#define DEFINE_GENERIC_REGISTER_STUB(dwarf_num, generic_num) \35{ \36DEFINE_REG_NAME(dwarf_num), \37DEFINE_REG_NAME_STR(nullptr), \380, \390, \40eEncodingInvalid, \41eFormatDefault, \42{dwarf_num, dwarf_num, generic_num, LLDB_INVALID_REGNUM, dwarf_num}, \43nullptr, \44nullptr, \45nullptr, \46}4748#define DEFINE_REGISTER_STUB(dwarf_num) \49DEFINE_GENERIC_REGISTER_STUB(dwarf_num, LLDB_INVALID_REGNUM)5051using namespace lldb;52using namespace lldb_private;5354LLDB_PLUGIN_DEFINE_ADV(ABISysV_loongarch, ABILoongArch)5556namespace {57namespace dwarf {58enum regnums {59r0,60r1,61ra = r1,62r2,63r3,64sp = r3,65r4,66r5,67r6,68r7,69r8,70r9,71r10,72r11,73r12,74r13,75r14,76r15,77r16,78r17,79r18,80r19,81r20,82r21,83r22,84fp = r22,85r23,86r24,87r25,88r26,89r27,90r28,91r29,92r30,93r31,94pc95};9697static const std::array<RegisterInfo, 33> g_register_infos = {98{DEFINE_REGISTER_STUB(r0),99DEFINE_GENERIC_REGISTER_STUB(r1, LLDB_REGNUM_GENERIC_RA),100DEFINE_REGISTER_STUB(r2),101DEFINE_GENERIC_REGISTER_STUB(r3, LLDB_REGNUM_GENERIC_SP),102DEFINE_GENERIC_REGISTER_STUB(r4, LLDB_REGNUM_GENERIC_ARG1),103DEFINE_GENERIC_REGISTER_STUB(r5, LLDB_REGNUM_GENERIC_ARG2),104DEFINE_GENERIC_REGISTER_STUB(r6, LLDB_REGNUM_GENERIC_ARG3),105DEFINE_GENERIC_REGISTER_STUB(r7, LLDB_REGNUM_GENERIC_ARG4),106DEFINE_GENERIC_REGISTER_STUB(r8, LLDB_REGNUM_GENERIC_ARG5),107DEFINE_GENERIC_REGISTER_STUB(r9, LLDB_REGNUM_GENERIC_ARG6),108DEFINE_GENERIC_REGISTER_STUB(r10, LLDB_REGNUM_GENERIC_ARG7),109DEFINE_GENERIC_REGISTER_STUB(r11, LLDB_REGNUM_GENERIC_ARG8),110DEFINE_REGISTER_STUB(r12),111DEFINE_REGISTER_STUB(r13),112DEFINE_REGISTER_STUB(r14),113DEFINE_REGISTER_STUB(r15),114DEFINE_REGISTER_STUB(r16),115DEFINE_REGISTER_STUB(r17),116DEFINE_REGISTER_STUB(r18),117DEFINE_REGISTER_STUB(r19),118DEFINE_REGISTER_STUB(r20),119DEFINE_REGISTER_STUB(r21),120DEFINE_GENERIC_REGISTER_STUB(r22, LLDB_REGNUM_GENERIC_FP),121DEFINE_REGISTER_STUB(r23),122DEFINE_REGISTER_STUB(r24),123DEFINE_REGISTER_STUB(r25),124DEFINE_REGISTER_STUB(r26),125DEFINE_REGISTER_STUB(r27),126DEFINE_REGISTER_STUB(r28),127DEFINE_REGISTER_STUB(r29),128DEFINE_REGISTER_STUB(r30),129DEFINE_REGISTER_STUB(r31),130DEFINE_GENERIC_REGISTER_STUB(pc, LLDB_REGNUM_GENERIC_PC)}};131} // namespace dwarf132} // namespace133134// Number of argument registers (the base integer calling convention135// provides 8 argument registers, a0-a7)136static constexpr size_t g_regs_for_args_count = 8U;137138const RegisterInfo *ABISysV_loongarch::GetRegisterInfoArray(uint32_t &count) {139count = dwarf::g_register_infos.size();140return dwarf::g_register_infos.data();141}142143//------------------------------------------------------------------144// Static Functions145//------------------------------------------------------------------146147ABISP148ABISysV_loongarch::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {149llvm::Triple::ArchType machine = arch.GetTriple().getArch();150151if (llvm::Triple::loongarch32 != machine &&152llvm::Triple::loongarch64 != machine)153return ABISP();154155ABISysV_loongarch *abi =156new ABISysV_loongarch(std::move(process_sp), MakeMCRegisterInfo(arch));157if (abi)158abi->SetIsLA64(llvm::Triple::loongarch64 == machine);159return ABISP(abi);160}161162static bool UpdateRegister(RegisterContext *reg_ctx,163const lldb::RegisterKind reg_kind,164const uint32_t reg_num, const addr_t value) {165Log *log = GetLog(LLDBLog::Expressions);166167const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(reg_kind, reg_num);168169LLDB_LOG(log, "Writing {0}: 0x{1:x}", reg_info->name,170static_cast<uint64_t>(value));171if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, value)) {172LLDB_LOG(log, "Writing {0}: failed", reg_info->name);173return false;174}175return true;176}177178static void LogInitInfo(Log &log, const Thread &thread, addr_t sp,179addr_t func_addr, addr_t return_addr,180const llvm::ArrayRef<addr_t> args) {181std::stringstream ss;182ss << "ABISysV_loongarch::PrepareTrivialCall"183<< " (tid = 0x" << std::hex << thread.GetID() << ", sp = 0x" << sp184<< ", func_addr = 0x" << func_addr << ", return_addr = 0x" << return_addr;185186for (auto [idx, arg] : enumerate(args))187ss << ", arg" << std::dec << idx << " = 0x" << std::hex << arg;188ss << ")";189log.PutString(ss.str());190}191192bool ABISysV_loongarch::PrepareTrivialCall(Thread &thread, addr_t sp,193addr_t func_addr, addr_t return_addr,194llvm::ArrayRef<addr_t> args) const {195Log *log = GetLog(LLDBLog::Expressions);196if (log)197LogInitInfo(*log, thread, sp, func_addr, return_addr, args);198199const auto reg_ctx_sp = thread.GetRegisterContext();200if (!reg_ctx_sp) {201LLDB_LOG(log, "Failed to get RegisterContext");202return false;203}204205if (args.size() > g_regs_for_args_count) {206LLDB_LOG(log, "Function has {0} arguments, but only {1} are allowed!",207args.size(), g_regs_for_args_count);208return false;209}210211// Write arguments to registers212for (auto [idx, arg] : enumerate(args)) {213const RegisterInfo *reg_info = reg_ctx_sp->GetRegisterInfo(214eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + idx);215LLDB_LOG(log, "About to write arg{0} ({1:x}) into {2}", idx, arg,216reg_info->name);217218if (!reg_ctx_sp->WriteRegisterFromUnsigned(reg_info, arg)) {219LLDB_LOG(log, "Failed to write arg{0} ({1:x}) into {2}", idx, arg,220reg_info->name);221return false;222}223}224225if (!UpdateRegister(reg_ctx_sp.get(), eRegisterKindGeneric,226LLDB_REGNUM_GENERIC_PC, func_addr))227return false;228if (!UpdateRegister(reg_ctx_sp.get(), eRegisterKindGeneric,229LLDB_REGNUM_GENERIC_SP, sp))230return false;231if (!UpdateRegister(reg_ctx_sp.get(), eRegisterKindGeneric,232LLDB_REGNUM_GENERIC_RA, return_addr))233return false;234235LLDB_LOG(log, "ABISysV_loongarch::{0}() success", __FUNCTION__);236return true;237}238239bool ABISysV_loongarch::GetArgumentValues(Thread &thread,240ValueList &values) const {241// TODO: Implement242return false;243}244245Status ABISysV_loongarch::SetReturnValueObject(StackFrameSP &frame_sp,246ValueObjectSP &new_value_sp) {247Status result;248if (!new_value_sp) {249result = Status::FromErrorString("Empty value object for return value.");250return result;251}252253CompilerType compiler_type = new_value_sp->GetCompilerType();254if (!compiler_type) {255result = Status::FromErrorString("Null clang type for return value.");256return result;257}258259auto ®_ctx = *frame_sp->GetThread()->GetRegisterContext();260261bool is_signed = false;262if (!compiler_type.IsIntegerOrEnumerationType(is_signed) &&263!compiler_type.IsPointerType()) {264result = Status::FromErrorString(265"We don't support returning other types at present");266return result;267}268269DataExtractor data;270size_t num_bytes = new_value_sp->GetData(data, result);271272if (result.Fail()) {273result = Status::FromErrorStringWithFormat(274"Couldn't convert return value to raw data: %s", result.AsCString());275return result;276}277278size_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 be282// returned through a pair of registers (ARG1 and ARG2), and the lower-ordered283// bits in the `ARG1`.284if (num_bytes > 2 * reg_size) {285result = Status::FromErrorString(286"We don't support returning large integer values at present.");287return result;288}289290offset_t offset = 0;291uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);292// According to psABI, i32 (no matter signed or unsigned) should be293// sign-extended in register.294if (4 == num_bytes && m_is_la64)295raw_value = llvm::SignExtend64<32>(raw_value);296auto reg_info =297reg_ctx.GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);298if (!reg_ctx.WriteRegisterFromUnsigned(reg_info, raw_value)) {299result = Status::FromErrorStringWithFormat(300"Couldn't write value to register %s", reg_info->name);301return result;302}303304if (num_bytes <= reg_size)305return result; // Successfully written.306307// 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.309if (4 == reg_size)310raw_value >>= 32;311else312raw_value = data.GetMaxU64(&offset, num_bytes - reg_size);313314reg_info =315reg_ctx.GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2);316if (!reg_ctx.WriteRegisterFromUnsigned(reg_info, raw_value))317result = Status::FromErrorStringWithFormat(318"Couldn't write value to register %s", reg_info->name);319320return result;321}322323template <typename T>324static void SetInteger(Scalar &scalar, uint64_t raw_value, bool is_signed) {325static_assert(std::is_unsigned<T>::value, "T must be an unsigned type.");326raw_value &= std::numeric_limits<T>::max();327if (is_signed)328scalar = static_cast<typename std::make_signed<T>::type>(raw_value);329else330scalar = static_cast<T>(raw_value);331}332333static bool SetSizedInteger(Scalar &scalar, uint64_t raw_value,334uint8_t size_in_bytes, bool is_signed) {335switch (size_in_bytes) {336default:337return false;338339case sizeof(uint64_t):340SetInteger<uint64_t>(scalar, raw_value, is_signed);341break;342343case sizeof(uint32_t):344SetInteger<uint32_t>(scalar, raw_value, is_signed);345break;346347case sizeof(uint16_t):348SetInteger<uint16_t>(scalar, raw_value, is_signed);349break;350351case sizeof(uint8_t):352SetInteger<uint8_t>(scalar, raw_value, is_signed);353break;354}355356return true;357}358359static bool SetSizedFloat(Scalar &scalar, uint64_t raw_value,360uint8_t size_in_bytes) {361switch (size_in_bytes) {362default:363return false;364365case sizeof(uint64_t):366scalar = *reinterpret_cast<double *>(&raw_value);367break;368369case sizeof(uint32_t):370scalar = *reinterpret_cast<float *>(&raw_value);371break;372}373374return true;375}376377static ValueObjectSP GetValObjFromIntRegs(Thread &thread,378const RegisterContextSP ®_ctx,379llvm::Triple::ArchType machine,380uint32_t type_flags,381uint32_t byte_size) {382Value value;383ValueObjectSP return_valobj_sp;384auto *reg_info_a0 =385reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);386auto *reg_info_a1 =387reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG2);388uint64_t raw_value = 0;389390switch (byte_size) {391case sizeof(uint32_t):392// Read a0 to get the arg393raw_value = reg_ctx->ReadRegisterAsUnsigned(reg_info_a0, 0) & UINT32_MAX;394break;395case sizeof(uint64_t):396// Read a0 to get the arg on loongarch64, a0 and a1 on loongarch32397if (llvm::Triple::loongarch32 == machine) {398raw_value = reg_ctx->ReadRegisterAsUnsigned(reg_info_a0, 0) & UINT32_MAX;399raw_value |=400(reg_ctx->ReadRegisterAsUnsigned(reg_info_a1, 0) & UINT32_MAX) << 32U;401} else {402raw_value = reg_ctx->ReadRegisterAsUnsigned(reg_info_a0, 0);403}404break;405case 16: {406// Read a0 and a1 to get the arg on loongarch64, not supported on407// loongarch32408if (llvm::Triple::loongarch32 == machine)409return return_valobj_sp;410411// Create the ValueObjectSP here and return412std::unique_ptr<DataBufferHeap> heap_data_up(413new DataBufferHeap(byte_size, 0));414const ByteOrder byte_order = thread.GetProcess()->GetByteOrder();415RegisterValue reg_value_a0, reg_value_a1;416if (reg_ctx->ReadRegister(reg_info_a0, reg_value_a0) &&417reg_ctx->ReadRegister(reg_info_a1, reg_value_a1)) {418Status error;419if (reg_value_a0.GetAsMemoryData(*reg_info_a0,420heap_data_up->GetBytes() + 0, 8,421byte_order, error) &&422reg_value_a1.GetAsMemoryData(*reg_info_a1,423heap_data_up->GetBytes() + 8, 8,424byte_order, error)) {425value.SetBytes(heap_data_up.release(), byte_size);426return ValueObjectConstResult::Create(427thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));428}429}430break;431}432default:433return return_valobj_sp;434}435436if (type_flags & eTypeIsInteger) {437if (!SetSizedInteger(value.GetScalar(), raw_value, byte_size,438type_flags & eTypeIsSigned))439return return_valobj_sp;440} else if (type_flags & eTypeIsFloat) {441if (!SetSizedFloat(value.GetScalar(), raw_value, byte_size))442return return_valobj_sp;443} else444return return_valobj_sp;445446value.SetValueType(Value::ValueType::Scalar);447return_valobj_sp = ValueObjectConstResult::Create(448thread.GetStackFrameAtIndex(0).get(), value, ConstString(""));449return return_valobj_sp;450}451452static ValueObjectSP GetValObjFromFPRegs(Thread &thread,453const RegisterContextSP ®_ctx,454llvm::Triple::ArchType machine,455uint32_t type_flags,456uint32_t byte_size) {457auto *reg_info_fa0 = reg_ctx->GetRegisterInfoByName("f0");458bool use_fp_regs = false;459ValueObjectSP return_valobj_sp;460461if (byte_size <= 8)462use_fp_regs = true;463464if (use_fp_regs) {465uint64_t raw_value;466Value value;467raw_value = reg_ctx->ReadRegisterAsUnsigned(reg_info_fa0, 0);468if (!SetSizedFloat(value.GetScalar(), raw_value, byte_size))469return return_valobj_sp;470value.SetValueType(Value::ValueType::Scalar);471return ValueObjectConstResult::Create(thread.GetStackFrameAtIndex(0).get(),472value, ConstString(""));473}474// we should never reach this, but if we do, use the integer registers475return GetValObjFromIntRegs(thread, reg_ctx, machine, type_flags, byte_size);476}477478ValueObjectSP ABISysV_loongarch::GetReturnValueObjectSimple(479Thread &thread, CompilerType &compiler_type) const {480ValueObjectSP return_valobj_sp;481482if (!compiler_type)483return return_valobj_sp;484485auto reg_ctx = thread.GetRegisterContext();486if (!reg_ctx)487return return_valobj_sp;488489Value value;490value.SetCompilerType(compiler_type);491492const uint32_t type_flags = compiler_type.GetTypeInfo();493const size_t byte_size =494llvm::expectedToOptional(compiler_type.GetByteSize(&thread)).value_or(0);495const ArchSpec arch = thread.GetProcess()->GetTarget().GetArchitecture();496const llvm::Triple::ArchType machine = arch.GetMachine();497498if (type_flags & eTypeIsInteger) {499return_valobj_sp =500GetValObjFromIntRegs(thread, reg_ctx, machine, type_flags, byte_size);501return return_valobj_sp;502}503if (type_flags & eTypeIsPointer) {504const auto *reg_info_a0 = reg_ctx->GetRegisterInfo(505eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1);506value.GetScalar() = reg_ctx->ReadRegisterAsUnsigned(reg_info_a0, 0);507value.SetValueType(Value::ValueType::Scalar);508return ValueObjectConstResult::Create(thread.GetStackFrameAtIndex(0).get(),509value, ConstString(""));510}511if (type_flags & eTypeIsFloat) {512uint32_t float_count = 0;513bool is_complex = false;514515if (compiler_type.IsFloatingPointType(float_count, is_complex) &&516float_count == 1 && !is_complex) {517return_valobj_sp =518GetValObjFromFPRegs(thread, reg_ctx, machine, type_flags, byte_size);519return return_valobj_sp;520}521}522return return_valobj_sp;523}524525ValueObjectSP ABISysV_loongarch::GetReturnValueObjectImpl(526Thread &thread, CompilerType &return_compiler_type) const {527ValueObjectSP return_valobj_sp;528529if (!return_compiler_type)530return return_valobj_sp;531532ExecutionContext exe_ctx(thread.shared_from_this());533return GetReturnValueObjectSimple(thread, return_compiler_type);534}535536UnwindPlanSP ABISysV_loongarch::CreateFunctionEntryUnwindPlan() {537uint32_t pc_reg_num = loongarch_dwarf::dwarf_gpr_pc;538uint32_t sp_reg_num = loongarch_dwarf::dwarf_gpr_sp;539uint32_t ra_reg_num = loongarch_dwarf::dwarf_gpr_ra;540541UnwindPlan::Row row;542543// Define CFA as the stack pointer544row.GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 0);545546// Previous frame's pc is in ra547row.SetRegisterLocationToRegister(pc_reg_num, ra_reg_num, true);548549auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF);550plan_sp->AppendRow(std::move(row));551plan_sp->SetSourceName("loongarch function-entry unwind plan");552plan_sp->SetSourcedFromCompiler(eLazyBoolNo);553return plan_sp;554}555556UnwindPlanSP ABISysV_loongarch::CreateDefaultUnwindPlan() {557uint32_t pc_reg_num = LLDB_REGNUM_GENERIC_PC;558uint32_t fp_reg_num = LLDB_REGNUM_GENERIC_FP;559560UnwindPlan::Row row;561562// Define the CFA as the current frame pointer value.563row.GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 0);564565int reg_size = 4;566if (m_is_la64)567reg_size = 8;568569// Assume the ra reg (return pc) and caller's frame pointer570// have been spilled to stack already.571row.SetRegisterLocationToAtCFAPlusOffset(fp_reg_num, reg_size * -2, true);572row.SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, reg_size * -1, true);573574auto plan_sp = std::make_shared<UnwindPlan>(eRegisterKindGeneric);575plan_sp->AppendRow(std::move(row));576plan_sp->SetSourceName("loongarch default unwind plan");577plan_sp->SetSourcedFromCompiler(eLazyBoolNo);578plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);579return plan_sp;580}581582bool ABISysV_loongarch::RegisterIsVolatile(const RegisterInfo *reg_info) {583return !RegisterIsCalleeSaved(reg_info);584}585586bool ABISysV_loongarch::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {587if (!reg_info)588return false;589590const char *name = reg_info->name;591ArchSpec arch = GetProcessSP()->GetTarget().GetArchitecture();592uint32_t arch_flags = arch.GetFlags();593// Floating point registers are only callee saved when using594// F or D hardware floating point ABIs.595bool is_hw_fp = (arch_flags & ArchSpec::eLoongArch_abi_mask) != 0;596597return llvm::StringSwitch<bool>(name)598// integer ABI names599.Cases("ra", "sp", "fp", true)600.Cases("s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", true)601// integer hardware names602.Cases("r1", "r3", "r22", true)603.Cases("r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30", "31", true)604// floating point ABI names605.Cases("fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", is_hw_fp)606// floating point hardware names607.Cases("f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", is_hw_fp)608.Default(false);609}610611void ABISysV_loongarch::Initialize() {612PluginManager::RegisterPlugin(GetPluginNameStatic(),613"System V ABI for LoongArch targets",614CreateInstance);615}616617void ABISysV_loongarch::Terminate() {618PluginManager::UnregisterPlugin(CreateInstance);619}620621static uint32_t GetGenericNum(llvm::StringRef name) {622return llvm::StringSwitch<uint32_t>(name)623.Case("pc", LLDB_REGNUM_GENERIC_PC)624.Cases("ra", "r1", LLDB_REGNUM_GENERIC_RA)625.Cases("sp", "r3", LLDB_REGNUM_GENERIC_SP)626.Cases("fp", "r22", LLDB_REGNUM_GENERIC_FP)627.Cases("a0", "r4", LLDB_REGNUM_GENERIC_ARG1)628.Cases("a1", "r5", LLDB_REGNUM_GENERIC_ARG2)629.Cases("a2", "r6", LLDB_REGNUM_GENERIC_ARG3)630.Cases("a3", "r7", LLDB_REGNUM_GENERIC_ARG4)631.Cases("a4", "r8", LLDB_REGNUM_GENERIC_ARG5)632.Cases("a5", "r9", LLDB_REGNUM_GENERIC_ARG6)633.Cases("a6", "r10", LLDB_REGNUM_GENERIC_ARG7)634.Cases("a7", "r11", LLDB_REGNUM_GENERIC_ARG8)635.Default(LLDB_INVALID_REGNUM);636}637638void ABISysV_loongarch::AugmentRegisterInfo(639std::vector<lldb_private::DynamicRegisterInfo::Register> ®s) {640lldb_private::RegInfoBasedABI::AugmentRegisterInfo(regs);641642static const llvm::StringMap<llvm::StringRef> isa_to_abi_alias_map = {643{"r0", "zero"}, {"r1", "ra"}, {"r2", "tp"}, {"r3", "sp"},644{"r4", "a0"}, {"r5", "a1"}, {"r6", "a2"}, {"r7", "a3"},645{"r8", "a4"}, {"r9", "a5"}, {"r10", "a6"}, {"r11", "a7"},646{"r12", "t0"}, {"r13", "t1"}, {"r14", "t2"}, {"r15", "t3"},647{"r16", "t4"}, {"r17", "t5"}, {"r18", "t6"}, {"r19", "t7"},648{"r20", "t8"}, {"r22", "fp"}, {"r23", "s0"}, {"r24", "s1"},649{"r25", "s2"}, {"r26", "s3"}, {"r27", "s4"}, {"r28", "s5"},650{"r29", "s6"}, {"r30", "s7"}, {"r31", "s8"}};651652for (auto it : llvm::enumerate(regs)) {653llvm::StringRef reg_name = it.value().name.GetStringRef();654655// Set alt name for certain registers for convenience656llvm::StringRef alias_name = isa_to_abi_alias_map.lookup(reg_name);657if (!alias_name.empty())658it.value().alt_name.SetString(alias_name);659660// Set generic regnum so lldb knows what the PC, etc is661it.value().regnum_generic = GetGenericNum(reg_name);662}663}664665666