Fixed alignment bug in EDBG and RISC-V drivers
This commit is contained in:
@@ -605,6 +605,10 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
|||||||
TargetMemorySize bytes,
|
TargetMemorySize bytes,
|
||||||
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges
|
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges
|
||||||
) {
|
) {
|
||||||
|
if (bytes == 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
if (this->programmingModeEnabled && memorySegmentDescriptor.type == TargetMemorySegmentType::RAM) {
|
if (this->programmingModeEnabled && memorySegmentDescriptor.type == TargetMemorySegmentType::RAM) {
|
||||||
throw Exception{"Cannot access RAM when programming mode is enabled"};
|
throw Exception{"Cannot access RAM when programming mode is enabled"};
|
||||||
}
|
}
|
||||||
@@ -742,6 +746,10 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
|||||||
TargetMemoryAddress startAddress,
|
TargetMemoryAddress startAddress,
|
||||||
Targets::TargetMemoryBufferSpan buffer
|
Targets::TargetMemoryBufferSpan buffer
|
||||||
) {
|
) {
|
||||||
|
if (buffer.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (memorySegmentDescriptor.type == TargetMemorySegmentType::FLASH) {
|
if (memorySegmentDescriptor.type == TargetMemorySegmentType::FLASH) {
|
||||||
if (this->session.configVariant == Avr8ConfigVariant::XMEGA) {
|
if (this->session.configVariant == Avr8ConfigVariant::XMEGA) {
|
||||||
const auto bootSectionStartAddress = this->session.programBootSection.value().get().startAddress;
|
const auto bootSectionStartAddress = this->session.programBootSection.value().get().startAddress;
|
||||||
@@ -1614,6 +1622,8 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
|||||||
TargetMemorySize bytes,
|
TargetMemorySize bytes,
|
||||||
const std::set<TargetMemoryAddress>& excludedAddresses
|
const std::set<TargetMemoryAddress>& excludedAddresses
|
||||||
) {
|
) {
|
||||||
|
assert(bytes > 0);
|
||||||
|
|
||||||
if (type == Avr8MemoryType::FUSES && this->session.configVariant == Avr8ConfigVariant::DEBUG_WIRE) {
|
if (type == Avr8MemoryType::FUSES && this->session.configVariant == Avr8ConfigVariant::DEBUG_WIRE) {
|
||||||
throw Exception{"Cannot access AVR fuses via the debugWIRE interface"};
|
throw Exception{"Cannot access AVR fuses via the debugWIRE interface"};
|
||||||
}
|
}
|
||||||
@@ -1732,6 +1742,8 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
|||||||
TargetMemoryAddress startAddress,
|
TargetMemoryAddress startAddress,
|
||||||
Targets::TargetMemoryBufferSpan buffer
|
Targets::TargetMemoryBufferSpan buffer
|
||||||
) {
|
) {
|
||||||
|
assert(!buffer.empty());
|
||||||
|
|
||||||
if (type == Avr8MemoryType::FUSES && this->session.configVariant == Avr8ConfigVariant::DEBUG_WIRE) {
|
if (type == Avr8MemoryType::FUSES && this->session.configVariant == Avr8ConfigVariant::DEBUG_WIRE) {
|
||||||
throw Exception{"Cannot access AVR fuses via the debugWIRE interface"};
|
throw Exception{"Cannot access AVR fuses via the debugWIRE interface"};
|
||||||
}
|
}
|
||||||
@@ -1770,10 +1782,12 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
|||||||
alignedBuffer.begin() + (startAddress - alignedStartAddress)
|
alignedBuffer.begin() + (startAddress - alignedStartAddress)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const auto backAlignmentBytes = alignedBytes - bytes - (startAddress - alignedStartAddress);
|
||||||
|
if (backAlignmentBytes > 0) {
|
||||||
const auto dataBack = this->readMemory(
|
const auto dataBack = this->readMemory(
|
||||||
readMemType,
|
readMemType,
|
||||||
startAddress + bytes,
|
startAddress + bytes,
|
||||||
alignedBytes - bytes - (startAddress - alignedStartAddress),
|
backAlignmentBytes,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
std::copy(
|
std::copy(
|
||||||
@@ -1781,6 +1795,7 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
|||||||
dataBack.end(),
|
dataBack.end(),
|
||||||
alignedBuffer.begin() + (startAddress - alignedStartAddress) + bytes
|
alignedBuffer.begin() + (startAddress - alignedStartAddress) + bytes
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return this->writeMemory(type, alignedStartAddress, alignedBuffer);
|
return this->writeMemory(type, alignedStartAddress, alignedBuffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -529,11 +529,13 @@ namespace DebugToolDrivers::Protocols::RiscVDebug
|
|||||||
alignedBuffer.begin() + (startAddress - alignedStartAddress)
|
alignedBuffer.begin() + (startAddress - alignedStartAddress)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const auto backAlignmentBytes = alignedBytes - bytes - (startAddress - alignedStartAddress);
|
||||||
|
if (backAlignmentBytes > 0) {
|
||||||
const auto dataBack = this->readMemory(
|
const auto dataBack = this->readMemory(
|
||||||
addressSpaceDescriptor,
|
addressSpaceDescriptor,
|
||||||
memorySegmentDescriptor,
|
memorySegmentDescriptor,
|
||||||
startAddress + bytes,
|
startAddress + bytes,
|
||||||
alignedBytes - bytes - (startAddress - alignedStartAddress),
|
backAlignmentBytes,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
std::copy(
|
std::copy(
|
||||||
@@ -541,6 +543,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebug
|
|||||||
dataBack.end(),
|
dataBack.end(),
|
||||||
alignedBuffer.begin() + (startAddress - alignedStartAddress) + bytes
|
alignedBuffer.begin() + (startAddress - alignedStartAddress) + bytes
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return this->writeMemory(
|
return this->writeMemory(
|
||||||
addressSpaceDescriptor,
|
addressSpaceDescriptor,
|
||||||
@@ -958,6 +961,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebug
|
|||||||
Targets::TargetMemoryAddress startAddress,
|
Targets::TargetMemoryAddress startAddress,
|
||||||
Targets::TargetMemorySize bytes
|
Targets::TargetMemorySize bytes
|
||||||
) {
|
) {
|
||||||
|
assert(bytes > 0);
|
||||||
assert(startAddress % DebugTranslator::WORD_BYTE_SIZE == 0);
|
assert(startAddress % DebugTranslator::WORD_BYTE_SIZE == 0);
|
||||||
assert(bytes % DebugTranslator::WORD_BYTE_SIZE == 0);
|
assert(bytes % DebugTranslator::WORD_BYTE_SIZE == 0);
|
||||||
|
|
||||||
@@ -1006,6 +1010,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebug
|
|||||||
Targets::TargetMemoryBufferSpan buffer
|
Targets::TargetMemoryBufferSpan buffer
|
||||||
) {
|
) {
|
||||||
using DebugModule::Registers::MemoryAccessControlField;
|
using DebugModule::Registers::MemoryAccessControlField;
|
||||||
|
assert(!buffer.empty());
|
||||||
assert(startAddress % DebugTranslator::WORD_BYTE_SIZE == 0);
|
assert(startAddress % DebugTranslator::WORD_BYTE_SIZE == 0);
|
||||||
assert(buffer.size() % DebugTranslator::WORD_BYTE_SIZE == 0);
|
assert(buffer.size() % DebugTranslator::WORD_BYTE_SIZE == 0);
|
||||||
|
|
||||||
@@ -1049,6 +1054,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebug
|
|||||||
Targets::TargetMemoryAddress startAddress,
|
Targets::TargetMemoryAddress startAddress,
|
||||||
Targets::TargetMemorySize bytes
|
Targets::TargetMemorySize bytes
|
||||||
) {
|
) {
|
||||||
|
assert(bytes > 0);
|
||||||
assert(startAddress % DebugTranslator::WORD_BYTE_SIZE == 0);
|
assert(startAddress % DebugTranslator::WORD_BYTE_SIZE == 0);
|
||||||
assert(bytes % DebugTranslator::WORD_BYTE_SIZE == 0);
|
assert(bytes % DebugTranslator::WORD_BYTE_SIZE == 0);
|
||||||
|
|
||||||
@@ -1186,6 +1192,7 @@ namespace DebugToolDrivers::Protocols::RiscVDebug
|
|||||||
Targets::TargetMemoryAddress startAddress,
|
Targets::TargetMemoryAddress startAddress,
|
||||||
Targets::TargetMemoryBufferSpan buffer
|
Targets::TargetMemoryBufferSpan buffer
|
||||||
) {
|
) {
|
||||||
|
assert(!buffer.empty());
|
||||||
assert(startAddress % DebugTranslator::WORD_BYTE_SIZE == 0);
|
assert(startAddress % DebugTranslator::WORD_BYTE_SIZE == 0);
|
||||||
assert(buffer.size() % DebugTranslator::WORD_BYTE_SIZE == 0);
|
assert(buffer.size() % DebugTranslator::WORD_BYTE_SIZE == 0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user