444 changes: 444 additions & 0 deletions lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.cpp

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions lldb/source/Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
//===-- EmulateInstructionMIPS64.h ------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef EmulateInstructionMIPS64_h_
#define EmulateInstructionMIPS64_h_

#include "lldb/Core/EmulateInstruction.h"
#include "lldb/Core/Error.h"
#include "lldb/Interpreter/OptionValue.h"

class EmulateInstructionMIPS64 : public lldb_private::EmulateInstruction
{
public:
static void
Initialize ();

static void
Terminate ();

static lldb_private::ConstString
GetPluginNameStatic ();

static const char *
GetPluginDescriptionStatic ();

static lldb_private::EmulateInstruction *
CreateInstance (const lldb_private::ArchSpec &arch,
lldb_private::InstructionType inst_type);

static bool
SupportsEmulatingInstructionsOfTypeStatic (lldb_private::InstructionType inst_type)
{
switch (inst_type)
{
case lldb_private::eInstructionTypeAny:
case lldb_private::eInstructionTypePrologueEpilogue:
return true;

case lldb_private::eInstructionTypePCModifying:
case lldb_private::eInstructionTypeAll:
return false;
}
return false;
}

virtual lldb_private::ConstString
GetPluginName();

virtual lldb_private::ConstString
GetShortPluginName()
{
return GetPluginNameStatic();
}

virtual uint32_t
GetPluginVersion()
{
return 1;
}

bool
SetTargetTriple (const lldb_private::ArchSpec &arch);

EmulateInstructionMIPS64 (const lldb_private::ArchSpec &arch) :
EmulateInstruction (arch)
{
}

virtual bool
SupportsEmulatingInstructionsOfType (lldb_private::InstructionType inst_type)
{
return SupportsEmulatingInstructionsOfTypeStatic (inst_type);
}

virtual bool
ReadInstruction ();

virtual bool
EvaluateInstruction (uint32_t evaluate_options);

virtual bool
TestEmulation (lldb_private::Stream *out_stream,
lldb_private::ArchSpec &arch,
lldb_private::OptionValueDictionary *test_data)
{
return false;
}

virtual bool
GetRegisterInfo (lldb::RegisterKind reg_kind,
uint32_t reg_num,
lldb_private::RegisterInfo &reg_info);

virtual bool
CreateFunctionEntryUnwind (lldb_private::UnwindPlan &unwind_plan);


protected:

typedef struct
{
uint32_t mask;
uint32_t value;
bool (EmulateInstructionMIPS64::*callback) (const uint32_t opcode);
const char *name;
} Opcode;

static Opcode*
GetOpcodeForInstruction (const uint32_t opcode);

bool
Emulate_addsp_imm (const uint32_t opcode);

bool
Emulate_store (const uint32_t opcode);

bool
Emulate_load (const uint32_t opcode);

bool
nonvolatile_reg_p (uint64_t regnum);

const char *
GetRegisterName (unsigned reg_num, bool altnernate_name);

};

#endif // EmulateInstructionMIPS64_h_
14 changes: 14 additions & 0 deletions lldb/source/Plugins/Instruction/MIPS64/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
##===- source/Plugins/Instruction/MIPS64/Makefile -------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##

LLDB_LEVEL := ../../../..
LIBRARYNAME := lldbPluginEmulateInstructionMIPS64
BUILD_ARCHIVE = 1

include $(LLDB_LEVEL)/Makefile
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PARALLEL_DIRS := ABI/MacOSX-arm ABI/MacOSX-arm64 ABI/MacOSX-i386 ABI/SysV-x86_64
ObjectContainer/Universal-Mach-O ObjectFile/Mach-O \
ObjectFile/JIT SymbolFile/DWARF SymbolFile/Symtab Process/Utility \
DynamicLoader/Static Platform Process/gdb-remote \
Instruction/ARM Instruction/ARM64 \
Instruction/ARM Instruction/ARM64 Instruction/MIPS64 \
UnwindAssembly/InstEmulation UnwindAssembly/x86 \
LanguageRuntime/CPlusPlus/ItaniumABI \
LanguageRuntime/ObjC/AppleObjCRuntime \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,6 @@ UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction,
case EmulateInstruction::eContextRegisterPlusOffset:
case EmulateInstruction::eContextAdjustPC:
case EmulateInstruction::eContextRegisterStore:
case EmulateInstruction::eContextRegisterLoad:
case EmulateInstruction::eContextAbsoluteBranchRegister:
case EmulateInstruction::eContextSupervisorCall:
case EmulateInstruction::eContextTableBranchReadMemory:
Expand All @@ -634,6 +633,35 @@ UnwindAssemblyInstEmulation::WriteRegister (EmulateInstruction *instruction,
// }
break;

case EmulateInstruction::eContextRegisterLoad:
{
const uint32_t unwind_reg_kind = m_unwind_plan_ptr->GetRegisterKind();
const uint32_t reg_num = reg_info->kinds[unwind_reg_kind];
if (reg_num != LLDB_INVALID_REGNUM)
{
m_curr_row->SetRegisterLocationToRegister (reg_num, reg_num, must_replace);
m_curr_row_modified = true;
m_curr_insn_restored_a_register = true;

if (reg_info->kinds[eRegisterKindGeneric] == LLDB_REGNUM_GENERIC_RA)
{
// This load was restoring the return address register,
// so this is also how we will unwind the PC...
RegisterInfo pc_reg_info;
if (instruction->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, pc_reg_info))
{
uint32_t pc_reg_num = pc_reg_info.kinds[unwind_reg_kind];
if (pc_reg_num != LLDB_INVALID_REGNUM)
{
m_curr_row->SetRegisterLocationToRegister (pc_reg_num, reg_num, must_replace);
m_curr_row_modified = true;
}
}
}
}
}
break;

case EmulateInstruction::eContextRelativeBranchImmediate:
{

Expand Down
3 changes: 3 additions & 0 deletions lldb/source/lldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
#include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
#include "Plugins/JITLoader/GDB/JITLoaderGDB.h"
#include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h"
#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
Expand Down Expand Up @@ -224,6 +225,7 @@ lldb_private::Initialize ()
UnwindAssembly_x86::Initialize();
EmulateInstructionARM::Initialize();
EmulateInstructionARM64::Initialize();
EmulateInstructionMIPS64::Initialize();
SymbolFileDWARFDebugMap::Initialize();
ItaniumABILanguageRuntime::Initialize();
AppleObjCRuntimeV2::Initialize();
Expand Down Expand Up @@ -339,6 +341,7 @@ lldb_private::Terminate ()
UnwindAssemblyInstEmulation::Terminate();
EmulateInstructionARM::Terminate();
EmulateInstructionARM64::Terminate();
EmulateInstructionMIPS64::Terminate();
SymbolFileDWARFDebugMap::Terminate();
ItaniumABILanguageRuntime::Terminate();
AppleObjCRuntimeV2::Terminate();
Expand Down