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