diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp index c6174b52..56382f05 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -556,7 +556,12 @@ void EdbgAvr8Interface::writeRegisters(const Targets::TargetRegisters& registers } } -TargetMemoryBuffer EdbgAvr8Interface::readMemory(TargetMemoryType memoryType, std::uint32_t startAddress, std::uint32_t bytes) { +TargetMemoryBuffer EdbgAvr8Interface::readMemory( + TargetMemoryType memoryType, + std::uint32_t startAddress, + std::uint32_t bytes, + const std::set& excludedAddressRanges +) { auto avr8MemoryType = Avr8MemoryType::SRAM; switch (memoryType) { @@ -579,9 +584,32 @@ TargetMemoryBuffer EdbgAvr8Interface::readMemory(TargetMemoryType memoryType, st case TargetMemoryType::EEPROM: { avr8MemoryType = Avr8MemoryType::EEPROM; } + default: { + break; + } } - return this->readMemory(avr8MemoryType, startAddress, bytes); + /* + * The internal readMemory() function accepts excluded addresses in the form of a set of addresses, as + * opposed to a set of address ranges. + * + * We will perform the conversion here. + */ + auto excludedAddresses = std::set(); + auto endAddress = startAddress + bytes - 1; + + for (const auto& addressRange : excludedAddressRanges) { + if (addressRange.startAddress > endAddress) { + // This address range is outside of the range from which we will be reading + continue; + } + + for (auto i = addressRange.startAddress; i <= addressRange.endAddress; i++) { + excludedAddresses.insert(i); + } + } + + return this->readMemory(avr8MemoryType, startAddress, bytes, excludedAddresses); } void EdbgAvr8Interface::writeMemory(TargetMemoryType memoryType, std::uint32_t startAddress, const TargetMemoryBuffer& buffer) { @@ -611,6 +639,9 @@ void EdbgAvr8Interface::writeMemory(TargetMemoryType memoryType, std::uint32_t s case TargetMemoryType::EEPROM: { avr8MemoryType = Avr8MemoryType::EEPROM; } + default: { + break; + } } return this->writeMemory(avr8MemoryType, startAddress, buffer); diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp index cca21a52..8122ee46 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.hpp @@ -218,7 +218,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr Targets::TargetMemoryBuffer readMemory( Targets::TargetMemoryType memoryType, std::uint32_t startAddress, - std::uint32_t bytes + std::uint32_t bytes, + const std::set& excludedAddressRanges = {} ) override; /** diff --git a/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8Interface.hpp b/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8Interface.hpp index 5f1870e4..fe1a48d1 100644 --- a/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8Interface.hpp +++ b/src/DebugToolDrivers/TargetInterfaces/Microchip/AVR/AVR8/Avr8Interface.hpp @@ -157,12 +157,14 @@ namespace Bloom::DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8 * @param memoryType * @param startAddress * @param bytes + * @param excludedAddressRanges * @return */ virtual Targets::TargetMemoryBuffer readMemory( Targets::TargetMemoryType memoryType, std::uint32_t startAddress, - std::uint32_t bytes + std::uint32_t bytes, + const std::set& excludedAddressRanges = {} ) = 0; /** diff --git a/src/EventManager/Events/RetrieveMemoryFromTarget.hpp b/src/EventManager/Events/RetrieveMemoryFromTarget.hpp index 611f0d97..6c45699a 100644 --- a/src/EventManager/Events/RetrieveMemoryFromTarget.hpp +++ b/src/EventManager/Events/RetrieveMemoryFromTarget.hpp @@ -19,6 +19,7 @@ namespace Bloom::Events Targets::TargetMemoryType memoryType = Targets::TargetMemoryType::RAM; std::uint32_t startAddress = 0; std::uint32_t bytes = 0; + std::set excludedAddressRanges; [[nodiscard]] EventType getType() const override { return RetrieveMemoryFromTarget::type; diff --git a/src/TargetController/TargetController.cpp b/src/TargetController/TargetController.cpp index 554cf701..07fa9448 100644 --- a/src/TargetController/TargetController.cpp +++ b/src/TargetController/TargetController.cpp @@ -601,7 +601,12 @@ void TargetController::onReadMemoryEvent(const Events::RetrieveMemoryFromTarget& try { auto memoryReadEvent = std::make_shared(); memoryReadEvent->correlationId = event.id; - memoryReadEvent->data = this->target->readMemory(event.memoryType, event.startAddress, event.bytes); + memoryReadEvent->data = this->target->readMemory( + event.memoryType, + event.startAddress, + event.bytes, + event.excludedAddressRanges + ); this->eventManager.triggerEvent(memoryReadEvent); diff --git a/src/TargetController/TargetControllerConsole.cpp b/src/TargetController/TargetControllerConsole.cpp index cf9acacf..b2cb1e95 100644 --- a/src/TargetController/TargetControllerConsole.cpp +++ b/src/TargetController/TargetControllerConsole.cpp @@ -73,12 +73,14 @@ void TargetControllerConsole::writeRegisters(const TargetRegisters& registers) { TargetMemoryBuffer TargetControllerConsole::readMemory( TargetMemoryType memoryType, std::uint32_t startAddress, - std::uint32_t bytes + std::uint32_t bytes, + const std::set& excludedAddressRanges ) { auto readMemoryEvent = std::make_shared(); readMemoryEvent->memoryType = memoryType; readMemoryEvent->startAddress = startAddress; readMemoryEvent->bytes = bytes; + readMemoryEvent->excludedAddressRanges = excludedAddressRanges; return this->triggerTargetControllerEventAndWaitForResponse(readMemoryEvent)->data; } diff --git a/src/TargetController/TargetControllerConsole.hpp b/src/TargetController/TargetControllerConsole.hpp index 70560e48..c9ab019e 100644 --- a/src/TargetController/TargetControllerConsole.hpp +++ b/src/TargetController/TargetControllerConsole.hpp @@ -97,12 +97,14 @@ namespace Bloom * @param memoryType * @param startAddress * @param bytes + * @param excludedAddressRanges * @return */ Targets::TargetMemoryBuffer readMemory( Targets::TargetMemoryType memoryType, std::uint32_t startAddress, - std::uint32_t bytes + std::uint32_t bytes, + const std::set& excludedAddressRanges = {} ); /** diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp index c097db1a..c486d771 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp @@ -223,8 +223,13 @@ TargetRegisters Avr8::readRegisters(TargetRegisterDescriptors descriptors) { return registers; } -TargetMemoryBuffer Avr8::readMemory(TargetMemoryType memoryType, std::uint32_t startAddress, std::uint32_t bytes) { - return this->avr8Interface->readMemory(memoryType, startAddress, bytes); +TargetMemoryBuffer Avr8::readMemory( + TargetMemoryType memoryType, + std::uint32_t startAddress, + std::uint32_t bytes, + const std::set& excludedAddressRanges +) { + return this->avr8Interface->readMemory(memoryType, startAddress, bytes, excludedAddressRanges); } void Avr8::writeMemory(TargetMemoryType memoryType, std::uint32_t startAddress, const TargetMemoryBuffer& buffer) { diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp index 0605c4d2..407545e7 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.hpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.hpp @@ -95,7 +95,8 @@ namespace Bloom::Targets::Microchip::Avr::Avr8Bit TargetMemoryBuffer readMemory( TargetMemoryType memoryType, std::uint32_t startAddress, - std::uint32_t bytes + std::uint32_t bytes, + const std::set& excludedAddressRanges = {} ) override; void writeMemory( TargetMemoryType memoryType, diff --git a/src/Targets/Target.hpp b/src/Targets/Target.hpp index fa7d56a1..6996c0e9 100644 --- a/src/Targets/Target.hpp +++ b/src/Targets/Target.hpp @@ -240,10 +240,16 @@ namespace Bloom::Targets * @param memoryType * @param startAddress * @param bytes + * @param excludedAddressRanges * * @return */ - virtual TargetMemoryBuffer readMemory(TargetMemoryType memoryType, std::uint32_t startAddress, std::uint32_t bytes) = 0; + virtual TargetMemoryBuffer readMemory( + TargetMemoryType memoryType, + std::uint32_t startAddress, + std::uint32_t bytes, + const std::set& excludedAddressRanges = {} + ) = 0; /** * Should write memory to the target.