Skip to content

Commit 82c02b7

Browse files
committed
[lldb] Add support for MSP430 in LLDB.
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
1 parent 09b462e commit 82c02b7

File tree

18 files changed

+1078
-18
lines changed

18 files changed

+1078
-18
lines changed

lldb/include/lldb/Utility/ArchSpec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class ArchSpec {
172172
eCore_mips64r5el,
173173
eCore_mips64r6el,
174174

175+
eCore_msp430,
176+
175177
eCore_ppc_generic,
176178
eCore_ppc_ppc601,
177179
eCore_ppc_ppc602,

lldb/include/lldb/Utility/DataExtractor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,7 @@ class DataExtractor {
843843
/// \param[in] addr_size
844844
/// The size in bytes to use when extracting addresses.
845845
void SetAddressByteSize(uint32_t addr_size) {
846-
#ifdef LLDB_CONFIGURATION_DEBUG
847-
assert(addr_size == 4 || addr_size == 8);
848-
#endif
846+
assert(addr_size == 2 || addr_size == 4 || addr_size == 8);
849847
m_addr_size = addr_size;
850848
}
851849

lldb/source/Expression/IRMemoryMap.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,21 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
9696
// regions, walk forward through memory until a region is found that has
9797
// adequate space for our allocation.
9898
if (process_is_alive) {
99-
const uint64_t end_of_memory = process_sp->GetAddressByteSize() == 8
100-
? 0xffffffffffffffffull
101-
: 0xffffffffull;
102-
103-
lldbassert(process_sp->GetAddressByteSize() == 4 ||
104-
end_of_memory != 0xffffffffull);
99+
uint64_t end_of_memory;
100+
switch (process_sp->GetAddressByteSize()) {
101+
case 2:
102+
end_of_memory = 0xffffull;
103+
break;
104+
case 4:
105+
end_of_memory = 0xffffffffull;
106+
break;
107+
case 8:
108+
end_of_memory = 0xffffffffffffffffull;
109+
break;
110+
default:
111+
lldbassert(false && "Invalid address size.");
112+
return LLDB_INVALID_ADDRESS;
113+
}
105114

106115
MemoryRegionInfo region_info;
107116
Status err = process_sp->GetMemoryRegionInfo(ret, region_info);
@@ -137,26 +146,31 @@ lldb::addr_t IRMemoryMap::FindSpace(size_t size) {
137146
// We've tried our algorithm, and it didn't work. Now we have to reset back
138147
// to the end of the allocations we've already reported, or use a 'sensible'
139148
// default if this is our first allocation.
140-
141149
if (m_allocations.empty()) {
142150
uint32_t address_byte_size = GetAddressByteSize();
143151
if (address_byte_size != UINT32_MAX) {
144152
switch (address_byte_size) {
145-
case 8:
146-
ret = 0xdead0fff00000000ull;
153+
case 2:
154+
ret = 0x8000ull;
147155
break;
148156
case 4:
149157
ret = 0xee000000ull;
150158
break;
151-
default:
159+
case 8:
160+
ret = 0xdead0fff00000000ull;
152161
break;
162+
default:
163+
lldbassert(false && "Invalid address size.");
164+
return LLDB_INVALID_ADDRESS;
153165
}
154166
}
155167
} else {
156168
auto back = m_allocations.rbegin();
157169
lldb::addr_t addr = back->first;
158170
size_t alloc_size = back->second.m_size;
159-
ret = llvm::alignTo(addr + alloc_size, 4096);
171+
auto arch = target_sp->GetArchitecture().GetTriple().getArch();
172+
auto align = arch == llvm::Triple::msp430 ? 512 : 4096;
173+
ret = llvm::alignTo(addr + alloc_size, align);
160174
}
161175

162176
return ret;

lldb/source/Expression/LLVMUserExpression.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@ bool LLVMUserExpression::PrepareToExecuteJITExpression(
333333
if (m_can_interpret && m_stack_frame_bottom == LLDB_INVALID_ADDRESS) {
334334
Status alloc_error;
335335

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

338340
const bool zero_memory = false;
339341

lldb/source/Host/common/NativeProcessProtocol.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
503503
static const uint8_t g_i386_opcode[] = {0xCC};
504504
static const uint8_t g_mips64_opcode[] = {0x00, 0x00, 0x00, 0x0d};
505505
static const uint8_t g_mips64el_opcode[] = {0x0d, 0x00, 0x00, 0x00};
506+
static const uint8_t g_msp430_opcode[] = {0x43, 0x43};
506507
static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
507508
static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08}; // trap
508509
static const uint8_t g_ppcle_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
@@ -528,6 +529,9 @@ NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
528529
case llvm::Triple::mips64el:
529530
return llvm::ArrayRef(g_mips64el_opcode);
530531

532+
case llvm::Triple::msp430:
533+
return llvm::ArrayRef(g_msp430_opcode);
534+
531535
case llvm::Triple::systemz:
532536
return llvm::ArrayRef(g_s390x_opcode);
533537

lldb/source/Plugins/ABI/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
foreach(target AArch64 ARM ARC Hexagon Mips PowerPC SystemZ X86)
1+
foreach(target AArch64 ARM ARC Hexagon Mips MSP430 PowerPC SystemZ X86)
22
if (${target} IN_LIST LLVM_TARGETS_TO_BUILD)
33
add_subdirectory(${target})
44
endif()

0 commit comments

Comments
 (0)