Skip to content

Commit

Permalink
[lldb] Add support for MSP430 in LLDB.
Browse files Browse the repository at this point in the history
Add MSP430 to the list of available targets, implement MSP430 ABI, add support for debugging targets with 16-bit address size.

The update is intended for use with MSPDebug, a GDB server implementation for MSP430.

Reviewed By: bulbazord, DavidSpickett

Differential Revision: https://reviews.llvm.org/D146965
  • Loading branch information
asl committed Apr 17, 2023
1 parent 09b462e commit 82c02b7
Show file tree
Hide file tree
Showing 18 changed files with 1,078 additions and 18 deletions.
2 changes: 2 additions & 0 deletions lldb/include/lldb/Utility/ArchSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class ArchSpec {
eCore_mips64r5el,
eCore_mips64r6el,

eCore_msp430,

eCore_ppc_generic,
eCore_ppc_ppc601,
eCore_ppc_ppc602,
Expand Down
4 changes: 1 addition & 3 deletions lldb/include/lldb/Utility/DataExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,7 @@ class DataExtractor {
/// \param[in] addr_size
/// 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);
#endif
assert(addr_size == 2 || addr_size == 4 || addr_size == 8);
m_addr_size = addr_size;
}

Expand Down
36 changes: 25 additions & 11 deletions lldb/source/Expression/IRMemoryMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,21 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
// 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;

lldbassert(process_sp->GetAddressByteSize() == 4 ||
end_of_memory != 0xffffffffull);
uint64_t end_of_memory;
switch (process_sp->GetAddressByteSize()) {
case 2:
end_of_memory = 0xffffull;
break;
case 4:
end_of_memory = 0xffffffffull;
break;
case 8:
end_of_memory = 0xffffffffffffffffull;
break;
default:
lldbassert(false && "Invalid address size.");
return LLDB_INVALID_ADDRESS;
}

MemoryRegionInfo region_info;
Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
Expand Down Expand Up @@ -137,26 +146,31 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
// 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:
case 8:
ret = 0xdead0fff00000000ull;
break;
default:
lldbassert(false && "Invalid address size.");
return LLDB_INVALID_ADDRESS;
}
}
} else {
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 arch = target_sp->GetArchitecture().GetTriple().getArch();
auto align = arch == llvm::Triple::msp430 ? 512 : 4096;
ret = llvm::alignTo(addr + alloc_size, align);
}

return ret;
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Expression/LLVMUserExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ bool LLVMUserExpression::PrepareToExecuteJITExpression(
if (m_can_interpret && m_stack_frame_bottom == LLDB_INVALID_ADDRESS) {
Status alloc_error;

const size_t stack_frame_size = 512 * 1024;
auto arch = target->GetArchitecture().GetTriple().getArch();
const size_t stack_frame_size =
arch == llvm::Triple::msp430 ? 512 : 512 * 1024;

const bool zero_memory = false;

Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Host/common/NativeProcessProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
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
Expand All @@ -528,6 +529,9 @@ NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
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);

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/ABI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 82c02b7

Please sign in to comment.