Skip to content

Commit 93e01de

Browse files
author
Bar Soloveychik
committed
fixed comments
1 parent ee3cadc commit 93e01de

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ LLDB_PLUGIN_DEFINE_ADV(EmulateInstructionRISCV, InstructionRISCV)
3333

3434
namespace lldb_private {
3535

36+
// RISC-V General Purpose Register numbers
37+
static constexpr uint32_t RISCV_GPR_SP = 2; // x2 is the stack pointer
38+
static constexpr uint32_t RISCV_GPR_FP = 8; // x8 is the frame pointer
39+
3640
/// Returns all values wrapped in Optional, or std::nullopt if any of the values
3741
/// is std::nullopt.
3842
template <typename... Ts>
@@ -243,11 +247,10 @@ Load(EmulateInstructionRISCV &emulator, I inst, uint64_t (*extend)(E)) {
243247
return false;
244248

245249
// Set context type based on whether this is a stack-based load
246-
if (inst.rs1.rs == 2) { // x2 is the stack pointer in RISC-V
250+
if (inst.rs1.rs == RISCV_GPR_SP) // x2 is the stack pointer in RISC-V
247251
context.type = EmulateInstruction::eContextPopRegisterOffStack;
248-
} else {
252+
else
249253
context.type = EmulateInstruction::eContextRegisterLoad;
250-
}
251254

252255
// Set the context address information
253256
context.SetAddress(*addr);
@@ -284,11 +287,10 @@ Store(EmulateInstructionRISCV &emulator, I inst) {
284287
return false;
285288

286289
// Set context type based on whether this is a stack-based store
287-
if (inst.rs1.rs == 2) { // x2 is the stack pointer in RISC-V
290+
if (inst.rs1.rs == RISCV_GPR_SP) // x2 is the stack pointer in RISC-V
288291
context.type = EmulateInstruction::eContextPushRegisterOnStack;
289-
} else {
292+
else
290293
context.type = EmulateInstruction::eContextRegisterStore;
291-
}
292294

293295
// Set the context to show which register is being stored to which base
294296
// register + offset
@@ -797,29 +799,31 @@ class Executor {
797799
[&](int64_t rs1) {
798800
int64_t result = rs1 + int64_t(SignExt(inst.imm));
799801
// Check if this is a stack pointer adjustment
800-
if (inst.rd.rd == 2 && inst.rs1.rs == 2) { // rd=sp, rs1=sp
802+
if (inst.rd.rd == RISCV_GPR_SP &&
803+
inst.rs1.rs == RISCV_GPR_SP) { // rd=sp, rs1=sp
801804
EmulateInstruction::Context context;
802805
context.type =
803806
EmulateInstruction::eContextAdjustStackPointer;
804807
context.SetImmediateSigned(SignExt(inst.imm));
805-
uint32_t sp_lldb_reg = GPREncodingToLLDB(2);
808+
uint32_t sp_lldb_reg = GPREncodingToLLDB(RISCV_GPR_SP);
806809
RegisterValue registerValue;
807810
registerValue.SetUInt64(result);
808811
return m_emu.WriteRegister(context, eRegisterKindLLDB,
809812
sp_lldb_reg, registerValue);
810813
}
811814
// Check if this is setting up the frame pointer
812815
// addi fp, sp, imm -> fp = sp + imm (frame pointer setup)
813-
if (inst.rd.rd == 8 && inst.rs1.rs == 2) { // rd=fp, rs1=sp
816+
if (inst.rd.rd == RISCV_GPR_FP &&
817+
inst.rs1.rs == RISCV_GPR_SP) { // rd=fp, rs1=sp
814818
EmulateInstruction::Context context;
815819
context.type = EmulateInstruction::eContextSetFramePointer;
816820
auto sp_reg_info = m_emu.GetRegisterInfo(
817-
eRegisterKindLLDB, GPREncodingToLLDB(2));
821+
eRegisterKindLLDB, GPREncodingToLLDB(RISCV_GPR_SP));
818822
if (sp_reg_info) {
819823
context.SetRegisterPlusOffset(*sp_reg_info,
820824
SignExt(inst.imm));
821825
}
822-
uint32_t fp_lldb_reg = GPREncodingToLLDB(8);
826+
uint32_t fp_lldb_reg = GPREncodingToLLDB(RISCV_GPR_FP);
823827
RegisterValue registerValue;
824828
registerValue.SetUInt64(result);
825829
return m_emu.WriteRegister(context, eRegisterKindLLDB,

0 commit comments

Comments
 (0)