Refactored page alignment code in EDBG and RISC-V debug translator driver
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
#include "src/Services/PathService.hpp"
|
||||
#include "src/Services/StringService.hpp"
|
||||
@@ -1505,15 +1506,30 @@ namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
|
||||
* We can't just forward the memory type to readMemory(), because some memory types (such as
|
||||
* EEPROM_ATOMIC) can only be used for writing.
|
||||
*/
|
||||
auto alignedBuffer = this->readMemory(
|
||||
type == Avr8MemoryType::EEPROM_ATOMIC ? Avr8MemoryType::EEPROM : type,
|
||||
alignedStartAddress,
|
||||
alignedBytes
|
||||
);
|
||||
assert(alignedBuffer.size() >= buffer.size());
|
||||
const auto readMemType = type == Avr8MemoryType::EEPROM_ATOMIC ? Avr8MemoryType::EEPROM : type;
|
||||
auto alignedBuffer = (alignedStartAddress < startAddress)
|
||||
? this->readMemory(readMemType, alignedStartAddress, startAddress - alignedStartAddress)
|
||||
: TargetMemoryBuffer{};
|
||||
|
||||
const auto offset = alignedBuffer.begin() + (startAddress - alignedStartAddress);
|
||||
std::copy(buffer.begin(), buffer.end(), offset);
|
||||
alignedBuffer.resize(alignedBytes);
|
||||
|
||||
std::copy(
|
||||
buffer.begin(),
|
||||
buffer.end(),
|
||||
alignedBuffer.begin() + (startAddress - alignedStartAddress)
|
||||
);
|
||||
|
||||
const auto dataBack = this->readMemory(
|
||||
readMemType,
|
||||
startAddress + bytes,
|
||||
alignedBytes - bytes - (startAddress - alignedStartAddress),
|
||||
{}
|
||||
);
|
||||
std::copy(
|
||||
dataBack.begin(),
|
||||
dataBack.end(),
|
||||
alignedBuffer.begin() + (startAddress - alignedStartAddress) + bytes
|
||||
);
|
||||
|
||||
return this->writeMemory(type, alignedStartAddress, alignedBuffer);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Registers/CpuRegisterNumbers.hpp"
|
||||
#include "DebugModule/Registers/RegisterAddresses.hpp"
|
||||
@@ -411,19 +412,31 @@ namespace DebugToolDrivers::Protocols::RiscVDebugSpec
|
||||
addressSpaceDescriptor,
|
||||
memorySegmentDescriptor,
|
||||
alignedStartAddress,
|
||||
(startAddress - alignedStartAddress)
|
||||
(startAddress - alignedStartAddress),
|
||||
{}
|
||||
)
|
||||
: TargetMemoryBuffer{};
|
||||
alignedBuffer.reserve(alignedBytes);
|
||||
|
||||
// Read the offset bytes required to align the buffer size
|
||||
alignedBuffer.resize(alignedBytes);
|
||||
|
||||
std::copy(
|
||||
buffer.begin(),
|
||||
buffer.end(),
|
||||
alignedBuffer.begin() + (startAddress - alignedStartAddress)
|
||||
);
|
||||
|
||||
const auto dataBack = this->readMemory(
|
||||
addressSpaceDescriptor,
|
||||
memorySegmentDescriptor,
|
||||
startAddress + bytes,
|
||||
alignedBytes - bytes - (startAddress - alignedStartAddress)
|
||||
alignedBytes - bytes - (startAddress - alignedStartAddress),
|
||||
{}
|
||||
);
|
||||
std::copy(
|
||||
dataBack.begin(),
|
||||
dataBack.end(),
|
||||
alignedBuffer.begin() + (startAddress - alignedStartAddress) + bytes
|
||||
);
|
||||
alignedBuffer.insert(alignedBuffer.end(), dataBack.begin(), dataBack.end());
|
||||
|
||||
return this->writeMemory(
|
||||
addressSpaceDescriptor,
|
||||
|
||||
Reference in New Issue
Block a user