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->target->isProgramMemory(addressSpaceDescriptor, memorySegmentDescriptor, startAddress, bytes)
|
||||
) {
|
||||
auto& cache = this->getProgramMemoryCache(addressSpaceDescriptor);
|
||||
auto& cache = this->getProgramMemoryCache(memorySegmentDescriptor);
|
||||
|
||||
if (!cache.contains(startAddress, bytes)) {
|
||||
Logger::debug(
|
||||
@@ -749,7 +749,7 @@ namespace TargetController
|
||||
this->target->writeMemory(addressSpaceDescriptor, memorySegmentDescriptor, startAddress, buffer);
|
||||
|
||||
if (isProgramMemory && this->environmentConfig.targetConfig.programMemoryCache) {
|
||||
this->getProgramMemoryCache(addressSpaceDescriptor).insert(startAddress, buffer);
|
||||
this->getProgramMemoryCache(memorySegmentDescriptor).insert(startAddress, buffer);
|
||||
}
|
||||
|
||||
EventManager::triggerEvent(
|
||||
@@ -778,7 +778,7 @@ namespace TargetController
|
||||
|
||||
if (this->environmentConfig.targetConfig.programMemoryCache) {
|
||||
Logger::debug("Clearing program memory cache");
|
||||
this->getProgramMemoryCache(addressSpaceDescriptor).clear();
|
||||
this->getProgramMemoryCache(memorySegmentDescriptor).clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -854,14 +854,14 @@ namespace TargetController
|
||||
}
|
||||
|
||||
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()) {
|
||||
cacheIt = this->programMemoryCachesByAddressSpaceKey.emplace(
|
||||
addressSpaceDescriptor.key,
|
||||
TargetMemoryCache{addressSpaceDescriptor}
|
||||
if (cacheIt == this->programMemoryCachesBySegmentId.end()) {
|
||||
cacheIt = this->programMemoryCachesBySegmentId.emplace(
|
||||
memorySegmentDescriptor.id,
|
||||
TargetMemoryCache{memorySegmentDescriptor}
|
||||
).first;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,8 @@
|
||||
#include "src/Targets/Targets.hpp"
|
||||
#include "src/Targets/TargetRegisterDescriptor.hpp"
|
||||
#include "src/Targets/TargetMemory.hpp"
|
||||
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
|
||||
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
|
||||
#include "src/Targets/TargetMemoryCache.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.
|
||||
*
|
||||
* Most targets only have a single program memory, which resides on a single address space. But some may have
|
||||
* multiple program memories, residing on multiple address spaces. We have a single cache (TargetMemoryCache
|
||||
* object) for each address space.
|
||||
* Most targets only have a single memory segment for program memory, but some may have multiple program
|
||||
* memories, across multiple address spaces. We have a single cache (TargetMemoryCache object) for each
|
||||
* 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.
|
||||
@@ -324,14 +326,14 @@ namespace TargetController
|
||||
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.
|
||||
*
|
||||
* @param addressSpaceDescriptor
|
||||
* @param memorySegmentDescriptor
|
||||
* @return
|
||||
*/
|
||||
Targets::TargetMemoryCache& getProgramMemoryCache(
|
||||
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor
|
||||
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
|
||||
namespace Targets
|
||||
{
|
||||
TargetMemoryCache::TargetMemoryCache(const TargetAddressSpaceDescriptor& addressSpaceDescriptor)
|
||||
: addressSpaceDescriptor(addressSpaceDescriptor)
|
||||
, data(TargetMemoryBuffer(addressSpaceDescriptor.size(), 0x00))
|
||||
TargetMemoryCache::TargetMemoryCache(const TargetMemorySegmentDescriptor& memorySegmentDescriptor)
|
||||
: memorySegmentDescriptor(memorySegmentDescriptor)
|
||||
, data(TargetMemoryBuffer(memorySegmentDescriptor.size(), 0x00))
|
||||
{}
|
||||
|
||||
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 (
|
||||
startAddress < this->addressSpaceDescriptor.addressRange.startAddress
|
||||
startAddress < this->memorySegmentDescriptor.addressRange.startAddress
|
||||
|| (startIndex + bytes) > this->data.size()
|
||||
) {
|
||||
throw Exceptions::Exception{"Invalid cache access"};
|
||||
@@ -34,7 +34,7 @@ namespace Targets
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
#include "TargetAddressSpaceDescriptor.hpp"
|
||||
#include "TargetMemorySegmentDescriptor.hpp"
|
||||
#include "TargetMemory.hpp"
|
||||
|
||||
namespace Targets
|
||||
@@ -11,7 +11,7 @@ namespace Targets
|
||||
class TargetMemoryCache
|
||||
{
|
||||
public:
|
||||
TargetMemoryCache(const TargetAddressSpaceDescriptor& addressSpaceDescriptor);
|
||||
TargetMemoryCache(const TargetMemorySegmentDescriptor& memorySegmentDescriptor);
|
||||
|
||||
/**
|
||||
* Fetches data from the cache.
|
||||
@@ -47,7 +47,7 @@ namespace Targets
|
||||
void clear();
|
||||
|
||||
private:
|
||||
const TargetAddressSpaceDescriptor& addressSpaceDescriptor;
|
||||
const TargetMemorySegmentDescriptor& memorySegmentDescriptor;
|
||||
TargetMemoryBuffer data;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user