Refactored page alignment code in EDBG and RISC-V debug translator driver

This commit is contained in:
Nav
2024-11-16 19:54:40 +00:00
parent 8f61c5a839
commit a7ee6cbae2
2 changed files with 42 additions and 13 deletions

View File

@@ -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,