kuilpd created this revision.
kuilpd added a reviewer: asl.
kuilpd added a project: LLDB.
Herald added subscribers: Michael137, JDevlieghere.
Herald added a project: All.
kuilpd requested review of this revision.
Herald added a subscriber: lldb-commits.

Add MSP430 to the list of available targets, implement MSP430 ABI, add support 
for debugging targets with 16-bit address size.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146965

Files:
  lldb/include/lldb/Utility/ArchSpec.h
  lldb/include/lldb/Utility/DataExtractor.h
  lldb/source/Expression/IRMemoryMap.cpp
  lldb/source/Expression/LLVMUserExpression.cpp
  lldb/source/Host/common/NativeProcessProtocol.cpp
  lldb/source/Plugins/ABI/CMakeLists.txt
  lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp
  lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.h
  lldb/source/Plugins/ABI/MSP430/CMakeLists.txt
  lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
  lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
  lldb/source/Target/Platform.cpp
  lldb/source/Utility/ArchSpec.cpp

Index: lldb/source/Utility/ArchSpec.cpp
===================================================================
--- lldb/source/Utility/ArchSpec.cpp
+++ lldb/source/Utility/ArchSpec.cpp
@@ -154,6 +154,10 @@
     {eByteOrderLittle, 8, 2, 4, llvm::Triple::mips64el,
      ArchSpec::eCore_mips64r6el, "mips64r6el"},
 
+    // MSP430
+    {eByteOrderLittle, 2, 2, 4, llvm::Triple::msp430, ArchSpec::eCore_msp430,
+     "msp430"},
+
     {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_generic,
      "powerpc"},
     {eByteOrderBig, 4, 4, 4, llvm::Triple::ppc, ArchSpec::eCore_ppc_ppc601,
@@ -402,6 +406,8 @@
      ArchSpec::eMIPSSubType_mips64r2el, 0xFFFFFFFFu, 0xFFFFFFFFu}, // mips64r2el
     {ArchSpec::eCore_mips64r6el, llvm::ELF::EM_MIPS,
      ArchSpec::eMIPSSubType_mips64r6el, 0xFFFFFFFFu, 0xFFFFFFFFu}, // mips64r6el
+    {ArchSpec::eCore_msp430, llvm::ELF::EM_MSP430, LLDB_INVALID_CPUTYPE,
+     0xFFFFFFFFu, 0xFFFFFFFFu}, // MSP430
     {ArchSpec::eCore_hexagon_generic, llvm::ELF::EM_HEXAGON,
      LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu}, // HEXAGON
     {ArchSpec::eCore_arc, llvm::ELF::EM_ARC_COMPACT2, LLDB_INVALID_CPUTYPE,
@@ -899,6 +905,9 @@
           case llvm::ELF::ELFOSABI_SOLARIS:
             m_triple.setOS(llvm::Triple::OSType::Solaris);
             break;
+          case llvm::ELF::ELFOSABI_STANDALONE:
+            m_triple.setOS(llvm::Triple::OSType::UnknownOS);
+            break;
           }
         } else if (arch_type == eArchTypeCOFF && os == llvm::Triple::Win32) {
           m_triple.setVendor(llvm::Triple::PC);
Index: lldb/source/Target/Platform.cpp
===================================================================
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -1895,6 +1895,12 @@
     trap_opcode_size = sizeof(g_hex_opcode);
   } break;
 
+  case llvm::Triple::msp430: {
+    static const uint8_t g_msp430_opcode[] = {0x43, 0x43};
+    trap_opcode = g_msp430_opcode;
+    trap_opcode_size = sizeof(g_msp430_opcode);
+  } break;
+
   case llvm::Triple::systemz: {
     static const uint8_t g_hex_opcode[] = {0x00, 0x01};
     trap_opcode = g_hex_opcode;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -940,7 +940,8 @@
 
   bool length_OK = data.ValidOffset(header.GetNextUnitOffset() - 1);
   bool version_OK = SymbolFileDWARF::SupportedVersion(header.m_version);
-  bool addr_size_OK = (header.m_addr_size == 4) || (header.m_addr_size == 8);
+  bool addr_size_OK = (header.m_addr_size == 2) || (header.m_addr_size == 4) ||
+                      (header.m_addr_size == 8);
   bool type_offset_OK =
       !header.IsTypeUnit() || (header.m_type_offset <= header.GetLength());
 
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterFallback.cpp
@@ -19,6 +19,7 @@
   }
 #define R64(name) REG(name, 8)
 #define R32(name) REG(name, 4)
+#define R16(name) REG(name, 2)
 
 static std::vector<DynamicRegisterInfo::Register> GetRegisters_aarch64() {
   ConstString empty_alt_name;
@@ -35,6 +36,18 @@
   return registers;
 }
 
+static std::vector<DynamicRegisterInfo::Register> GetRegisters_msp430() {
+  ConstString empty_alt_name;
+  ConstString reg_set{"general purpose registers"};
+
+  std::vector<DynamicRegisterInfo::Register> registers{
+      R16(r0),  R16(r1),  R16(r2),  R16(r3), R16(r4),  R16(r5),
+      R16(r6),  R16(r7),  R16(r8),  R16(r9), R16(r10), R16(r11),
+      R16(r12), R16(r13), R16(r14), R16(r15)};
+
+  return registers;
+}
+
 static std::vector<DynamicRegisterInfo::Register> GetRegisters_x86() {
   ConstString empty_alt_name;
   ConstString reg_set{"general purpose registers"};
@@ -71,6 +84,8 @@
   switch (arch_to_use.GetMachine()) {
   case llvm::Triple::aarch64:
     return GetRegisters_aarch64();
+  case llvm::Triple::msp430:
+    return GetRegisters_msp430();
   case llvm::Triple::x86:
     return GetRegisters_x86();
   case llvm::Triple::x86_64:
Index: lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
===================================================================
--- lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
+++ lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
@@ -124,7 +124,7 @@
         {llvm::Triple::x86_64, llvm::Triple::x86, llvm::Triple::arm,
          llvm::Triple::aarch64, llvm::Triple::mips64, llvm::Triple::mips64,
          llvm::Triple::hexagon, llvm::Triple::mips, llvm::Triple::mips64el,
-         llvm::Triple::mipsel, llvm::Triple::systemz},
+         llvm::Triple::mipsel, llvm::Triple::msp430, llvm::Triple::systemz},
         llvm::Triple::Linux);
   }
 }
Index: lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
+++ lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
@@ -71,6 +71,7 @@
       .Case("arm", Triple::arm)
       .Cases("arm64", "arm64e", Triple::aarch64)
       .Case("mips", Triple::mips)
+      .Case("msp430", Triple::msp430)
       .Case("ppc", Triple::ppc)
       .Case("ppc64", Triple::ppc64)
       .Case("s390", Triple::systemz)
Index: lldb/source/Plugins/ABI/MSP430/CMakeLists.txt
===================================================================
--- /dev/null
+++ lldb/source/Plugins/ABI/MSP430/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_lldb_library(lldbPluginABIMSP430 PLUGIN
+  ABISysV_msp430.cpp
+
+  LINK_LIBS
+    lldbCore
+    lldbSymbol
+    lldbTarget
+  LINK_COMPONENTS
+    Support
+    TargetParser
+  )
+
Index: lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.h
===================================================================
--- /dev/null
+++ lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.h
@@ -0,0 +1,93 @@
+//===-- ABISysV_msp430.h ----------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_PLUGINS_ABI_MSP430_ABISYSV_MSP430_H
+#define LLDB_SOURCE_PLUGINS_ABI_MSP430_ABISYSV_MSP430_H
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Target/ABI.h"
+#include "lldb/lldb-private.h"
+
+class ABISysV_msp430 : public lldb_private::RegInfoBasedABI {
+public:
+  ~ABISysV_msp430() override = default;
+
+  size_t GetRedZoneSize() const override;
+
+  bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
+                          lldb::addr_t functionAddress,
+                          lldb::addr_t returnAddress,
+                          llvm::ArrayRef<lldb::addr_t> args) const override;
+
+  bool GetArgumentValues(lldb_private::Thread &thread,
+                         lldb_private::ValueList &values) const override;
+
+  lldb_private::Status
+  SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+                       lldb::ValueObjectSP &new_value) override;
+
+  lldb::ValueObjectSP
+  GetReturnValueObjectImpl(lldb_private::Thread &thread,
+                           lldb_private::CompilerType &type) const override;
+
+  bool
+  CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+  bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
+
+  bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
+
+  bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
+    // Make sure the stack call frame addresses are 2 byte aligned
+    if (cfa & 0x01)
+      return false; // Not 2 byte aligned
+    if (cfa == 0)
+      return false; // Zero is not a valid stack address
+    return true;
+  }
+
+  bool CodeAddressIsValid(lldb::addr_t pc) override { return true; }
+
+  const lldb_private::RegisterInfo *
+  GetRegisterInfoArray(uint32_t &count) override;
+
+  //------------------------------------------------------------------
+  // Static Functions
+  //------------------------------------------------------------------
+
+  static void Initialize();
+
+  static void Terminate();
+
+  static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp,
+                                    const lldb_private::ArchSpec &arch);
+
+  static llvm::StringRef GetPluginNameStatic() { return "sysv-msp430"; }
+
+  // PluginInterface protocol
+
+  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
+
+protected:
+  void CreateRegisterMapIfNeeded();
+
+  lldb::ValueObjectSP
+  GetReturnValueObjectSimple(lldb_private::Thread &thread,
+                             lldb_private::CompilerType &ast_type) const;
+
+  bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
+
+private:
+  using lldb_private::RegInfoBasedABI::RegInfoBasedABI;
+};
+
+#endif // LLDB_SOURCE_PLUGINS_ABI_MSP430_ABISYSV_MSP430_H
Index: lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp
===================================================================
--- /dev/null
+++ lldb/source/Plugins/ABI/MSP430/ABISysV_msp430.cpp
@@ -0,0 +1,334 @@
+//===-- ABISysV_msp430.cpp --------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ABISysV_msp430.h"
+
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/Value.h"
+#include "lldb/Core/ValueObjectConstResult.h"
+#include "lldb/Core/ValueObjectMemory.h"
+#include "lldb/Core/ValueObjectRegister.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/Target/StackFrame.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/RegisterValue.h"
+
+#include "llvm/ADT/Triple.h"
+
+#include "llvm/IR/DerivedTypes.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+LLDB_PLUGIN_DEFINE_ADV(ABISysV_msp430, ABIMSP430)
+
+enum dwarf_regnums {
+  dwarf_pc = 0,
+  dwarf_sp,
+  dwarf_r2,
+  dwarf_r3,
+  dwarf_fp,
+  dwarf_r5,
+  dwarf_r6,
+  dwarf_r7,
+  dwarf_r8,
+  dwarf_r9,
+  dwarf_r10,
+  dwarf_r11,
+  dwarf_r12,
+  dwarf_r13,
+  dwarf_r14,
+  dwarf_r15,
+};
+
+static RegisterInfo g_register_infos[] = {
+    {"r0",
+     "pc",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r1",
+     "sp",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_sp, dwarf_sp, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r2",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r2, dwarf_r2, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r3",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r3, dwarf_r3, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r4",
+     "fp",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_fp, dwarf_fp, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r5",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r5, dwarf_r5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r6",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r6, dwarf_r6, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r7",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r7, dwarf_r7, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r8",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r8, dwarf_r8, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r9",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r9, dwarf_r9, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r10",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r10, dwarf_r10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r11",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r12",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r13",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r14",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr},
+    {"r15",
+     "",
+     2,
+     0,
+     eEncodingUint,
+     eFormatHex,
+     {dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
+      LLDB_INVALID_REGNUM},
+     nullptr,
+     nullptr}};
+
+static const uint32_t k_num_register_infos =
+    sizeof(g_register_infos) / sizeof(RegisterInfo);
+
+const lldb_private::RegisterInfo *
+ABISysV_msp430::GetRegisterInfoArray(uint32_t &count) {
+  // Make the C-string names and alt_names for the register infos into const
+  // C-string values by having the ConstString unique the names in the global
+  // constant C-string pool.
+  count = k_num_register_infos;
+  return g_register_infos;
+}
+
+size_t ABISysV_msp430::GetRedZoneSize() const { return 0; }
+
+//------------------------------------------------------------------
+// Static Functions
+//------------------------------------------------------------------
+
+ABISP
+ABISysV_msp430::CreateInstance(lldb::ProcessSP process_sp,
+                               const ArchSpec &arch) {
+  if (arch.GetTriple().getArch() == llvm::Triple::msp430) {
+    return ABISP(
+        new ABISysV_msp430(std::move(process_sp), MakeMCRegisterInfo(arch)));
+  }
+  return ABISP();
+}
+
+bool ABISysV_msp430::PrepareTrivialCall(Thread &thread, lldb::addr_t sp,
+                                        lldb::addr_t pc, lldb::addr_t ra,
+                                        llvm::ArrayRef<addr_t> args) const {
+  // we don't use the traditional trivial call specialized for jit
+  return false;
+}
+
+bool ABISysV_msp430::GetArgumentValues(Thread &thread,
+                                       ValueList &values) const {
+  return false;
+}
+
+Status ABISysV_msp430::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
+                                            lldb::ValueObjectSP &new_value_sp) {
+  return Status();
+}
+
+ValueObjectSP ABISysV_msp430::GetReturnValueObjectSimple(
+    Thread &thread, CompilerType &return_compiler_type) const {
+  ValueObjectSP return_valobj_sp;
+  return return_valobj_sp;
+}
+
+ValueObjectSP ABISysV_msp430::GetReturnValueObjectImpl(
+    Thread &thread, CompilerType &return_compiler_type) const {
+  ValueObjectSP return_valobj_sp;
+  return return_valobj_sp;
+}
+
+// called when we are on the first instruction of a new function
+bool ABISysV_msp430::CreateFunctionEntryUnwindPlan(UnwindPlan &unwind_plan) {
+  unwind_plan.Clear();
+  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
+
+  uint32_t sp_reg_num = dwarf_sp;
+  uint32_t pc_reg_num = dwarf_pc;
+
+  UnwindPlan::RowSP row(new UnwindPlan::Row);
+  row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 2);
+  row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, -2, true);
+  row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
+
+  unwind_plan.AppendRow(row);
+  unwind_plan.SetSourceName("msp430 at-func-entry default");
+  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+  return true;
+}
+
+bool ABISysV_msp430::CreateDefaultUnwindPlan(UnwindPlan &unwind_plan) {
+  unwind_plan.Clear();
+  unwind_plan.SetRegisterKind(eRegisterKindDWARF);
+
+  uint32_t fp_reg_num = dwarf_fp;
+  uint32_t sp_reg_num = dwarf_sp;
+  uint32_t pc_reg_num = dwarf_pc;
+
+  UnwindPlan::RowSP row(new UnwindPlan::Row);
+  row->GetCFAValue().SetIsRegisterPlusOffset(sp_reg_num, 2);
+  row->SetRegisterLocationToAtCFAPlusOffset(pc_reg_num, -2, true);
+  row->SetRegisterLocationToIsCFAPlusOffset(sp_reg_num, 0, true);
+  row->SetRegisterLocationToUnspecified(fp_reg_num, true);
+
+  unwind_plan.AppendRow(row);
+  unwind_plan.SetSourceName("msp430 default unwind plan");
+  unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
+  unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
+  return true;
+}
+
+bool ABISysV_msp430::RegisterIsVolatile(const RegisterInfo *reg_info) {
+  return !RegisterIsCalleeSaved(reg_info);
+}
+
+bool ABISysV_msp430::RegisterIsCalleeSaved(const RegisterInfo *reg_info) {
+  int reg = ((reg_info->byte_offset) / 2);
+
+  bool save = (reg >= 4) && (reg <= 10);
+  return save;
+}
+
+void ABISysV_msp430::Initialize(void) {
+  PluginManager::RegisterPlugin(
+      GetPluginNameStatic(), "System V ABI for msp430 targets", CreateInstance);
+}
+
+void ABISysV_msp430::Terminate(void) {
+  PluginManager::UnregisterPlugin(CreateInstance);
+}
Index: lldb/source/Plugins/ABI/CMakeLists.txt
===================================================================
--- lldb/source/Plugins/ABI/CMakeLists.txt
+++ lldb/source/Plugins/ABI/CMakeLists.txt
@@ -1,4 +1,4 @@
-foreach(target AArch64 ARM ARC Hexagon Mips PowerPC SystemZ X86)
+foreach(target AArch64 ARM ARC Hexagon Mips MSP430 PowerPC SystemZ X86)
   if (${target} IN_LIST LLVM_TARGETS_TO_BUILD)
     add_subdirectory(${target})
   endif()
Index: lldb/source/Host/common/NativeProcessProtocol.cpp
===================================================================
--- lldb/source/Host/common/NativeProcessProtocol.cpp
+++ lldb/source/Host/common/NativeProcessProtocol.cpp
@@ -503,6 +503,7 @@
   static const uint8_t g_i386_opcode[] = {0xCC};
   static const uint8_t g_mips64_opcode[] = {0x00, 0x00, 0x00, 0x0d};
   static const uint8_t g_mips64el_opcode[] = {0x0d, 0x00, 0x00, 0x00};
+  static const uint8_t g_msp430_opcode[] = {0x43, 0x43};
   static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
   static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08};   // trap
   static const uint8_t g_ppcle_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
@@ -528,6 +529,9 @@
   case llvm::Triple::mips64el:
     return llvm::ArrayRef(g_mips64el_opcode);
 
+  case llvm::Triple::msp430:
+    return llvm::ArrayRef(g_msp430_opcode);
+
   case llvm::Triple::systemz:
     return llvm::ArrayRef(g_s390x_opcode);
 
Index: lldb/source/Expression/LLVMUserExpression.cpp
===================================================================
--- lldb/source/Expression/LLVMUserExpression.cpp
+++ lldb/source/Expression/LLVMUserExpression.cpp
@@ -333,7 +333,9 @@
     if (m_can_interpret && m_stack_frame_bottom == LLDB_INVALID_ADDRESS) {
       Status alloc_error;
 
-      const size_t stack_frame_size = 512 * 1024;
+      const size_t stack_frame_size =
+          target->GetArchitecture().GetAddressByteSize() == 2 ? 512
+                                                              : 512 * 1024;
 
       const bool zero_memory = false;
 
Index: lldb/source/Expression/IRMemoryMap.cpp
===================================================================
--- lldb/source/Expression/IRMemoryMap.cpp
+++ lldb/source/Expression/IRMemoryMap.cpp
@@ -96,9 +96,19 @@
   // regions, walk forward through memory until a region is found that has
   // adequate space for our allocation.
   if (process_is_alive) {
-    const uint64_t end_of_memory = process_sp->GetAddressByteSize() == 8
-                                       ? 0xffffffffffffffffull
-                                       : 0xffffffffull;
+    uint64_t end_of_memory;
+    uint32_t address_byte_size = process_sp->GetAddressByteSize();
+    switch (address_byte_size) {
+    case 2:
+      end_of_memory = 0xffffull;
+      break;
+    case 4:
+      end_of_memory = 0xffffffffull;
+      break;
+    default:
+      end_of_memory = 0xffffffffffffffffull;
+      break;
+    }
 
     lldbassert(process_sp->GetAddressByteSize() == 4 ||
                end_of_memory != 0xffffffffull);
@@ -137,18 +147,18 @@
   // We've tried our algorithm, and it didn't work.  Now we have to reset back
   // to the end of the allocations we've already reported, or use a 'sensible'
   // default if this is our first allocation.
-
   if (m_allocations.empty()) {
     uint32_t address_byte_size = GetAddressByteSize();
     if (address_byte_size != UINT32_MAX) {
       switch (address_byte_size) {
-      case 8:
-        ret = 0xdead0fff00000000ull;
+      case 2:
+        ret = 0x8000ull;
         break;
       case 4:
         ret = 0xee000000ull;
         break;
       default:
+        ret = 0xdead0fff00000000ull;
         break;
       }
     }
@@ -156,7 +166,8 @@
     auto back = m_allocations.rbegin();
     lldb::addr_t addr = back->first;
     size_t alloc_size = back->second.m_size;
-    ret = llvm::alignTo(addr + alloc_size, 4096);
+    auto align = GetAddressByteSize() == 2 ? 512 : 4096;
+    ret = llvm::alignTo(addr + alloc_size, align);
   }
 
   return ret;
Index: lldb/include/lldb/Utility/DataExtractor.h
===================================================================
--- lldb/include/lldb/Utility/DataExtractor.h
+++ lldb/include/lldb/Utility/DataExtractor.h
@@ -844,7 +844,7 @@
   ///     The size in bytes to use when extracting addresses.
   void SetAddressByteSize(uint32_t addr_size) {
 #ifdef LLDB_CONFIGURATION_DEBUG
-    assert(addr_size == 4 || addr_size == 8);
+    assert(addr_size == 2 || addr_size == 4 || addr_size == 8);
 #endif
     m_addr_size = addr_size;
   }
Index: lldb/include/lldb/Utility/ArchSpec.h
===================================================================
--- lldb/include/lldb/Utility/ArchSpec.h
+++ lldb/include/lldb/Utility/ArchSpec.h
@@ -172,6 +172,8 @@
     eCore_mips64r5el,
     eCore_mips64r6el,
 
+    eCore_msp430,
+
     eCore_ppc_generic,
     eCore_ppc_ppc601,
     eCore_ppc_ppc602,
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to