Added TargetMemoryAddress, TargetMemorySize, TargetProgramCounter and TargetStackPointer aliases

This commit is contained in:
Nav
2022-09-06 17:16:49 +01:00
parent 620e6dc06a
commit 46d8ce1854
46 changed files with 234 additions and 174 deletions

View File

@@ -74,6 +74,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
using Bloom::Targets::TargetState;
using Bloom::Targets::TargetMemoryType;
using Bloom::Targets::TargetMemoryBuffer;
using Bloom::Targets::TargetMemoryAddress;
using Bloom::Targets::TargetMemorySize;
using Bloom::Targets::TargetProgramCounter;
using Bloom::Targets::TargetRegister;
using Bloom::Targets::TargetRegisterDescriptor;
using Bloom::Targets::TargetRegisterDescriptors;
@@ -219,7 +222,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
this->targetState = TargetState::RUNNING;
}
void EdbgAvr8Interface::runTo(std::uint32_t address) {
void EdbgAvr8Interface::runTo(TargetProgramCounter address) {
this->clearEvents();
auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame(
RunTo(address)
@@ -319,7 +322,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
}
}
std::uint32_t EdbgAvr8Interface::getProgramCounter() {
TargetProgramCounter EdbgAvr8Interface::getProgramCounter() {
if (this->targetState != TargetState::STOPPED) {
this->stop();
}
@@ -335,7 +338,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
return response.extractProgramCounter();
}
void EdbgAvr8Interface::setProgramCounter(std::uint32_t programCounter) {
void EdbgAvr8Interface::setProgramCounter(TargetProgramCounter programCounter) {
if (this->targetState != TargetState::STOPPED) {
this->stop();
}
@@ -366,7 +369,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* TODO: Currently, we're assuming the signature will always only ever be three bytes in size, but we may
* want to consider pulling the size from the TDF.
*/
auto signatureMemory = this->readMemory(
const auto signatureMemory = this->readMemory(
Avr8MemoryType::SRAM,
this->targetParameters.signatureSegmentStartAddress.value(),
3
@@ -390,7 +393,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
return response.extractSignature(this->targetConfig->physicalInterface);
}
void EdbgAvr8Interface::setBreakpoint(std::uint32_t address) {
void EdbgAvr8Interface::setBreakpoint(TargetMemoryAddress address) {
auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame(
SetSoftwareBreakpoints({address})
);
@@ -400,7 +403,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
}
}
void EdbgAvr8Interface::clearBreakpoint(std::uint32_t address) {
void EdbgAvr8Interface::clearBreakpoint(TargetMemoryAddress address) {
auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame(
ClearSoftwareBreakpoints({address})
);
@@ -444,10 +447,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
auto descriptorsByType = std::map<TargetRegisterType, std::set<const TargetRegisterDescriptor*>>();
/*
* An address range is just an std::pair of integers - the first being the start address, the second being the
* end address.
* An address range is just an std::pair of addresses - the first being the start address, the second being
* the end address.
*
* TODO: Can't we just use the TargetMemoryAddressRange struct here? Review
*/
using AddressRange = std::pair<std::uint32_t, std::uint32_t>;
using AddressRange = std::pair<TargetMemoryAddress, TargetMemoryAddress>;
auto addressRangeByType = std::map<TargetRegisterType, AddressRange>();
for (const auto& descriptor : descriptors) {
@@ -519,7 +524,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
*
* See CommandFrames::Avr8Generic::ReadMemory(); and the Microchip EDBG documentation for more.
*/
auto excludedAddresses = std::set<std::uint32_t>();
auto excludedAddresses = std::set<TargetMemoryAddress>();
if (memoryType == Avr8MemoryType::SRAM && this->targetParameters.ocdDataRegister.has_value()) {
excludedAddresses.insert(
this->targetParameters.ocdDataRegister.value()
@@ -608,8 +613,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
TargetMemoryBuffer EdbgAvr8Interface::readMemory(
TargetMemoryType memoryType,
std::uint32_t startAddress,
std::uint32_t bytes,
TargetMemoryAddress startAddress,
TargetMemorySize bytes,
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges
) {
if (
@@ -667,7 +672,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
*
* We will perform the conversion here.
*/
auto excludedAddresses = std::set<std::uint32_t>();
auto excludedAddresses = std::set<TargetMemoryAddress>();
auto endAddress = startAddress + bytes - 1;
for (const auto& addressRange : excludedAddressRanges) {
@@ -686,7 +691,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
void EdbgAvr8Interface::writeMemory(
TargetMemoryType memoryType,
std::uint32_t startAddress,
TargetMemoryAddress startAddress,
const TargetMemoryBuffer& buffer
) {
auto avr8MemoryType = Avr8MemoryType::SRAM;
@@ -1459,7 +1464,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
;
}
std::uint32_t EdbgAvr8Interface::alignMemoryAddress(Avr8MemoryType memoryType, std::uint32_t address) {
TargetMemoryAddress EdbgAvr8Interface::alignMemoryAddress(
Avr8MemoryType memoryType,
TargetMemoryAddress address
) {
std::uint16_t alignTo = 1;
// We don't have to align to the page size in all cases. We may only need to align to the word size (2 bytes).
@@ -1497,7 +1505,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
}
if ((address % alignTo) != 0) {
return static_cast<std::uint32_t>(std::floor(
return static_cast<TargetMemoryAddress>(std::floor(
static_cast<float>(address) / static_cast<float>(alignTo)
) * alignTo);
}
@@ -1505,7 +1513,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
return address;
}
std::uint32_t EdbgAvr8Interface::alignMemoryBytes(Avr8MemoryType memoryType, std::uint32_t bytes) {
TargetMemorySize EdbgAvr8Interface::alignMemoryBytes(
Avr8MemoryType memoryType,
TargetMemorySize bytes
) {
std::uint16_t alignTo = 1;
// We don't have to align to the page size in all cases. We may only need to align to the word size (2 bytes).
@@ -1537,7 +1548,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
}
if ((bytes % alignTo) != 0) {
return static_cast<std::uint32_t>(std::ceil(
return static_cast<TargetMemorySize>(std::ceil(
static_cast<float>(bytes) / static_cast<float>(alignTo)
) * alignTo);
}
@@ -1547,9 +1558,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
TargetMemoryBuffer EdbgAvr8Interface::readMemory(
Avr8MemoryType type,
std::uint32_t startAddress,
std::uint32_t bytes,
const std::set<std::uint32_t>& excludedAddresses
TargetMemoryAddress startAddress,
TargetMemorySize bytes,
const std::set<TargetMemoryAddress>& excludedAddresses
) {
if (!excludedAddresses.empty() && (this->avoidMaskedMemoryRead || type != Avr8MemoryType::SRAM)) {
/*
@@ -1632,12 +1643,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
// bytes should always be a multiple of pageSize (given the code above)
assert(bytes % pageSize == 0);
int pagesRequired = static_cast<int>(bytes / pageSize);
TargetMemoryBuffer memoryBuffer;
auto memoryBuffer = Targets::TargetMemoryBuffer();
for (auto i = 0; i < pagesRequired; i++) {
auto pageBuffer = this->readMemory(
type,
startAddress + static_cast<std::uint32_t>(pageSize * i),
startAddress + static_cast<TargetMemoryAddress>(pageSize * i),
pageSize
);
std::move(pageBuffer.begin(), pageBuffer.end(), std::back_inserter(memoryBuffer));
@@ -1655,17 +1666,17 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
if (this->maximumMemoryAccessSizePerRequest.has_value() && bytes > this->maximumMemoryAccessSizePerRequest) {
auto maximumRequestSize = this->maximumMemoryAccessSizePerRequest.value();
auto totalReadsRequired = std::ceil(static_cast<float>(bytes) / static_cast<float>(maximumRequestSize));
auto output = std::vector<unsigned char>();
auto output = Targets::TargetMemoryBuffer();
output.reserve(bytes);
for (float i = 1; i <= totalReadsRequired; i++) {
const auto bytesToRead = static_cast<std::uint32_t>(
const auto bytesToRead = static_cast<TargetMemorySize>(
(bytes - output.size()) > maximumRequestSize ? maximumRequestSize : bytes - output.size()
);
auto data = this->readMemory(
type,
static_cast<std::uint32_t>(startAddress + output.size()),
static_cast<TargetMemoryAddress>(startAddress + output.size()),
bytesToRead,
excludedAddresses
);
@@ -1704,16 +1715,16 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* This call to readMemory() will result in more than two response packets, so split it into multiple
* calls that will result in no more than two response packets per call.
*/
auto output = std::vector<unsigned char>();
auto output = TargetMemoryBuffer();
for (float i = 1; i <= totalReadsRequired; i++) {
auto bytesToRead = static_cast<std::uint32_t>(
auto bytesToRead = static_cast<TargetMemorySize>(
(bytes - output.size()) > (singlePacketSize * 2) ? (singlePacketSize * 2)
: bytes - output.size()
);
auto data = this->readMemory(
type,
static_cast<std::uint32_t>(startAddress + output.size()),
static_cast<TargetMemoryAddress>(startAddress + output.size()),
bytesToRead,
excludedAddresses
);
@@ -1740,8 +1751,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
return response.getMemoryBuffer();
}
void EdbgAvr8Interface::writeMemory(Avr8MemoryType type, std::uint32_t startAddress, const TargetMemoryBuffer& buffer) {
const auto bytes = static_cast<std::uint32_t>(buffer.size());
void EdbgAvr8Interface::writeMemory(
Avr8MemoryType type,
TargetMemoryAddress startAddress,
const TargetMemoryBuffer& buffer
) {
const auto bytes = static_cast<TargetMemorySize>(buffer.size());
if (this->alignmentRequired(type)) {
const auto alignedStartAddress = this->alignMemoryAddress(type, startAddress);

View File

@@ -8,6 +8,7 @@
#include "src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8DebugInterface.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Avr8Generic.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Targets/Microchip/AVR/Target.hpp"
#include "src/Targets/Microchip/AVR/AVR8/Family.hpp"
#include "src/Targets/Microchip/AVR/AVR8/PhysicalInterface.hpp"
@@ -65,7 +66,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
*
* @param maximumSize
*/
void setMaximumMemoryAccessSizePerRequest(std::uint32_t maximumSize) {
void setMaximumMemoryAccessSizePerRequest(Targets::TargetMemorySize maximumSize) {
this->maximumMemoryAccessSizePerRequest = maximumSize;
}
@@ -122,7 +123,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address
* The (byte) address to run to.
*/
void runTo(std::uint32_t address) override;
void runTo(Targets::TargetProgramCounter address) override;
/**
* Issues the "step" command to the debug tool, stepping the execution on the target. The stepping can be
@@ -152,7 +153,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
*
* @return
*/
std::uint32_t getProgramCounter() override;
Targets::TargetProgramCounter getProgramCounter() override;
/**
* Issues the "PC Write" command to the debug tool, setting the program counter on the target.
@@ -160,7 +161,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param programCounter
* The byte address to set as the program counter.
*/
void setProgramCounter(std::uint32_t programCounter) override;
void setProgramCounter(Targets::TargetProgramCounter programCounter) override;
/**
* Issues the "Get ID" command to the debug tool, to extract the signature from the target.
@@ -176,7 +177,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address
* The byte address to position the breakpoint.
*/
void setBreakpoint(std::uint32_t address) override;
void setBreakpoint(Targets::TargetMemoryAddress address) override;
/**
* Issues the "Software Breakpoint Clear" command to the debug tool, clearing any breakpoint at the given
@@ -185,7 +186,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address
* The byte address of the breakpoint to clear.
*/
void clearBreakpoint(std::uint32_t address) override;
void clearBreakpoint(Targets::TargetMemoryAddress address) override;
/**
* Issues the "Software Breakpoint Clear All" command to the debug tool, clearing all software breakpoints
@@ -222,8 +223,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
*/
Targets::TargetMemoryBuffer readMemory(
Targets::TargetMemoryType memoryType,
std::uint32_t startAddress,
std::uint32_t bytes,
Targets::TargetMemoryAddress startAddress,
Targets::TargetMemorySize bytes,
const std::set<Targets::TargetMemoryAddressRange>& excludedAddressRanges = {}
) override;
@@ -238,7 +239,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
*/
void writeMemory(
Targets::TargetMemoryType memoryType,
std::uint32_t startAddress,
Targets::TargetMemoryAddress startAddress,
const Targets::TargetMemoryBuffer& buffer
) override;
@@ -321,7 +322,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
/**
* See the comment for EdbgAvr8Interface::setMaximumMemoryAccessSizePerRequest().
*/
std::optional<std::uint32_t> maximumMemoryAccessSizePerRequest;
std::optional<Targets::TargetMemorySize> maximumMemoryAccessSizePerRequest;
/**
* We keep record of the current target state for caching purposes. We'll only refresh the target state if the
@@ -492,7 +493,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address
* @return
*/
std::uint32_t alignMemoryAddress(Avr8MemoryType memoryType, std::uint32_t address);
Targets::TargetMemoryAddress alignMemoryAddress(Avr8MemoryType memoryType, Targets::TargetMemoryAddress address);
/**
* Aligns a number of bytes used to address memory, for a given memory type's page size.
@@ -501,7 +502,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param bytes
* @return
*/
std::uint32_t alignMemoryBytes(Avr8MemoryType memoryType, std::uint32_t bytes);
Targets::TargetMemorySize alignMemoryBytes(Avr8MemoryType memoryType, Targets::TargetMemorySize bytes);
/**
* Reads memory on the target.
@@ -527,9 +528,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
*/
Targets::TargetMemoryBuffer readMemory(
Avr8MemoryType type,
std::uint32_t startAddress,
std::uint32_t bytes,
const std::set<std::uint32_t>& excludedAddresses = {}
Targets::TargetMemoryAddress startAddress,
Targets::TargetMemorySize bytes,
const std::set<Targets::TargetMemoryAddress>& excludedAddresses = {}
);
/**
@@ -543,7 +544,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @param address
* @param buffer
*/
void writeMemory(Avr8MemoryType type, std::uint32_t address, const Targets::TargetMemoryBuffer& buffer);
void writeMemory(Avr8MemoryType type, Targets::TargetMemoryAddress address, const Targets::TargetMemoryBuffer& buffer);
/**
* Fetches the current target state.

View File

@@ -3,6 +3,9 @@
#include <cstdint>
#include "Avr8GenericResponseFrame.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/Exceptions/Exception.hpp"
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrames::Avr8Generic
@@ -13,7 +16,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
GetProgramCounter() = default;
explicit GetProgramCounter(const std::vector<AvrResponse>& avrResponses): Avr8GenericResponseFrame(avrResponses) {}
std::uint32_t extractProgramCounter() {
Targets::TargetProgramCounter extractProgramCounter() {
/*
* The payload for the PC Read command should always consist of six bytes. Thr first two being the
* command ID and version, the other four being the PC. The four PC bytes are little-endian.
@@ -24,7 +27,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
"frame - unexpected payload size.");
}
return static_cast<std::uint32_t>(payload[5] << 24 | payload[4] << 16 | payload[3] << 8 | payload[2]) * 2;
return static_cast<Targets::TargetProgramCounter>(
payload[5] << 24 | payload[4] << 16 | payload[3] << 8 | payload[2]
) * 2;
}
};
}