Made TargetMemoryCache use TargetMemorySegmentDescriptor, as the base memory descriptor (instead of TargetMemoryAddressSpaceDescriptor).
Basing the memory cache on address spaces will result in large amounts of memory being unnecessarily reserved for large address spaces.
This commit is contained in:
@@ -690,7 +690,7 @@ namespace TargetController
|
|||||||
&& this->environmentConfig.targetConfig.programMemoryCache
|
&& this->environmentConfig.targetConfig.programMemoryCache
|
||||||
&& this->target->isProgramMemory(addressSpaceDescriptor, memorySegmentDescriptor, startAddress, bytes)
|
&& this->target->isProgramMemory(addressSpaceDescriptor, memorySegmentDescriptor, startAddress, bytes)
|
||||||
) {
|
) {
|
||||||
auto& cache = this->getProgramMemoryCache(addressSpaceDescriptor);
|
auto& cache = this->getProgramMemoryCache(memorySegmentDescriptor);
|
||||||
|
|
||||||
if (!cache.contains(startAddress, bytes)) {
|
if (!cache.contains(startAddress, bytes)) {
|
||||||
Logger::debug(
|
Logger::debug(
|
||||||
@@ -749,7 +749,7 @@ namespace TargetController
|
|||||||
this->target->writeMemory(addressSpaceDescriptor, memorySegmentDescriptor, startAddress, buffer);
|
this->target->writeMemory(addressSpaceDescriptor, memorySegmentDescriptor, startAddress, buffer);
|
||||||
|
|
||||||
if (isProgramMemory && this->environmentConfig.targetConfig.programMemoryCache) {
|
if (isProgramMemory && this->environmentConfig.targetConfig.programMemoryCache) {
|
||||||
this->getProgramMemoryCache(addressSpaceDescriptor).insert(startAddress, buffer);
|
this->getProgramMemoryCache(memorySegmentDescriptor).insert(startAddress, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
EventManager::triggerEvent(
|
EventManager::triggerEvent(
|
||||||
@@ -778,7 +778,7 @@ namespace TargetController
|
|||||||
|
|
||||||
if (this->environmentConfig.targetConfig.programMemoryCache) {
|
if (this->environmentConfig.targetConfig.programMemoryCache) {
|
||||||
Logger::debug("Clearing program memory cache");
|
Logger::debug("Clearing program memory cache");
|
||||||
this->getProgramMemoryCache(addressSpaceDescriptor).clear();
|
this->getProgramMemoryCache(memorySegmentDescriptor).clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -854,14 +854,14 @@ namespace TargetController
|
|||||||
}
|
}
|
||||||
|
|
||||||
TargetMemoryCache& TargetControllerComponent::getProgramMemoryCache(
|
TargetMemoryCache& TargetControllerComponent::getProgramMemoryCache(
|
||||||
const TargetAddressSpaceDescriptor& addressSpaceDescriptor
|
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor
|
||||||
) {
|
) {
|
||||||
auto cacheIt = this->programMemoryCachesByAddressSpaceKey.find(addressSpaceDescriptor.key);
|
auto cacheIt = this->programMemoryCachesBySegmentId.find(memorySegmentDescriptor.id);
|
||||||
|
|
||||||
if (cacheIt == this->programMemoryCachesByAddressSpaceKey.end()) {
|
if (cacheIt == this->programMemoryCachesBySegmentId.end()) {
|
||||||
cacheIt = this->programMemoryCachesByAddressSpaceKey.emplace(
|
cacheIt = this->programMemoryCachesBySegmentId.emplace(
|
||||||
addressSpaceDescriptor.key,
|
memorySegmentDescriptor.id,
|
||||||
TargetMemoryCache{addressSpaceDescriptor}
|
TargetMemoryCache{memorySegmentDescriptor}
|
||||||
).first;
|
).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,8 @@
|
|||||||
#include "src/Targets/Targets.hpp"
|
#include "src/Targets/Targets.hpp"
|
||||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||||
#include "src/Targets/TargetMemory.hpp"
|
#include "src/Targets/TargetMemory.hpp"
|
||||||
|
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
|
||||||
|
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
|
||||||
#include "src/Targets/TargetMemoryCache.hpp"
|
#include "src/Targets/TargetMemoryCache.hpp"
|
||||||
|
|
||||||
#include "src/EventManager/EventManager.hpp"
|
#include "src/EventManager/EventManager.hpp"
|
||||||
@@ -165,11 +167,11 @@ namespace TargetController
|
|||||||
*
|
*
|
||||||
* If program caching is enabled, all program memory reads will be serviced by the cache, if we have the data.
|
* If program caching is enabled, all program memory reads will be serviced by the cache, if we have the data.
|
||||||
*
|
*
|
||||||
* Most targets only have a single program memory, which resides on a single address space. But some may have
|
* Most targets only have a single memory segment for program memory, but some may have multiple program
|
||||||
* multiple program memories, residing on multiple address spaces. We have a single cache (TargetMemoryCache
|
* memories, across multiple address spaces. We have a single cache (TargetMemoryCache object) for each
|
||||||
* object) for each address space.
|
* memory segment.
|
||||||
*/
|
*/
|
||||||
std::map<std::string, Targets::TargetMemoryCache> programMemoryCachesByAddressSpaceKey;
|
std::map<Targets::TargetMemorySegmentId, Targets::TargetMemoryCache> programMemoryCachesBySegmentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a handler function for a particular command type.
|
* Registers a handler function for a particular command type.
|
||||||
@@ -324,14 +326,14 @@ namespace TargetController
|
|||||||
void disableProgrammingMode();
|
void disableProgrammingMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the program memory cache object for the given address space. If the address space has no associated
|
* Fetches the program memory cache object for the given memory segment. If the segment has no associated
|
||||||
* cache object, one will be created.
|
* cache object, one will be created.
|
||||||
*
|
*
|
||||||
* @param addressSpaceDescriptor
|
* @param memorySegmentDescriptor
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Targets::TargetMemoryCache& getProgramMemoryCache(
|
Targets::TargetMemoryCache& getProgramMemoryCache(
|
||||||
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor
|
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,16 +6,16 @@
|
|||||||
|
|
||||||
namespace Targets
|
namespace Targets
|
||||||
{
|
{
|
||||||
TargetMemoryCache::TargetMemoryCache(const TargetAddressSpaceDescriptor& addressSpaceDescriptor)
|
TargetMemoryCache::TargetMemoryCache(const TargetMemorySegmentDescriptor& memorySegmentDescriptor)
|
||||||
: addressSpaceDescriptor(addressSpaceDescriptor)
|
: memorySegmentDescriptor(memorySegmentDescriptor)
|
||||||
, data(TargetMemoryBuffer(addressSpaceDescriptor.size(), 0x00))
|
, data(TargetMemoryBuffer(memorySegmentDescriptor.size(), 0x00))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
TargetMemoryBuffer TargetMemoryCache::fetch(TargetMemoryAddress startAddress, TargetMemorySize bytes) const {
|
TargetMemoryBuffer TargetMemoryCache::fetch(TargetMemoryAddress startAddress, TargetMemorySize bytes) const {
|
||||||
const auto startIndex = startAddress - this->addressSpaceDescriptor.addressRange.startAddress;
|
const auto startIndex = startAddress - this->memorySegmentDescriptor.addressRange.startAddress;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
startAddress < this->addressSpaceDescriptor.addressRange.startAddress
|
startAddress < this->memorySegmentDescriptor.addressRange.startAddress
|
||||||
|| (startIndex + bytes) > this->data.size()
|
|| (startIndex + bytes) > this->data.size()
|
||||||
) {
|
) {
|
||||||
throw Exceptions::Exception{"Invalid cache access"};
|
throw Exceptions::Exception{"Invalid cache access"};
|
||||||
@@ -34,7 +34,7 @@ namespace Targets
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TargetMemoryCache::insert(TargetMemoryAddress startAddress, const TargetMemoryBuffer& data) {
|
void TargetMemoryCache::insert(TargetMemoryAddress startAddress, const TargetMemoryBuffer& data) {
|
||||||
const auto startIndex = startAddress - this->addressSpaceDescriptor.addressRange.startAddress;
|
const auto startIndex = startAddress - this->memorySegmentDescriptor.addressRange.startAddress;
|
||||||
|
|
||||||
std::copy(data.begin(), data.end(), this->data.begin() + startIndex);
|
std::copy(data.begin(), data.end(), this->data.begin() + startIndex);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "TargetAddressSpaceDescriptor.hpp"
|
#include "TargetMemorySegmentDescriptor.hpp"
|
||||||
#include "TargetMemory.hpp"
|
#include "TargetMemory.hpp"
|
||||||
|
|
||||||
namespace Targets
|
namespace Targets
|
||||||
@@ -11,7 +11,7 @@ namespace Targets
|
|||||||
class TargetMemoryCache
|
class TargetMemoryCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TargetMemoryCache(const TargetAddressSpaceDescriptor& addressSpaceDescriptor);
|
TargetMemoryCache(const TargetMemorySegmentDescriptor& memorySegmentDescriptor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches data from the cache.
|
* Fetches data from the cache.
|
||||||
@@ -47,7 +47,7 @@ namespace Targets
|
|||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const TargetAddressSpaceDescriptor& addressSpaceDescriptor;
|
const TargetMemorySegmentDescriptor& memorySegmentDescriptor;
|
||||||
TargetMemoryBuffer data;
|
TargetMemoryBuffer data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user