61 if (attributeName ==
"stable")
64 if (attributeName ==
"description")
65 return "A generic memory cache component.";
76 if (!ss.str().empty())
79 if (m_size >= (1 << 30))
80 ss << (m_size >> 30) <<
" GB";
81 else if (m_size >= (1 << 20))
82 ss << (m_size >> 20) <<
" MB";
83 else if (m_size >= (1 << 10))
84 ss << (m_size >> 10) <<
" KB";
86 ss << m_size <<
" bytes";
88 ss << m_size <<
" byte";
90 if (m_associativity == 0)
91 ss <<
", fully associative, ";
92 else if (m_associativity == 1)
93 ss <<
", direct-mapped, ";
95 ss <<
", " << m_associativity <<
"-way, ";
97 if (m_lineSize >= (1 << 30))
98 ss << (m_lineSize >> 30) <<
" GB";
99 else if (m_lineSize >= (1 << 20))
100 ss << (m_lineSize >> 20) <<
" MB";
101 else if (m_lineSize >= (1 << 10))
102 ss << (m_lineSize >> 10) <<
" KB";
103 else if (m_lineSize != 1)
104 ss << m_lineSize <<
" bytes";
106 ss << m_lineSize <<
" byte";
122 names.push_back(
"dump");
131 if (methodName ==
"dump")
140 const vector<string>& arguments)
142 if (methodName ==
"dump") {
143 uint64_t vaddr = m_lastDumpAddr;
145 if (arguments.size() > 1) {
150 if (arguments.size() == 1) {
156 ss.flags(std::ios::hex);
160 const int nRows = 16;
161 for (
int i=0; i<nRows; i++) {
162 const size_t len = 16;
163 unsigned char data[len];
167 ss.flags(std::ios::hex);
169 if (vaddr > 0xffffffff)
174 ss << std::setfill(
'0') << vaddr;
177 for (k=0; k<len; ++k) {
184 for (k=0; k<len; ++k) {
188 ss << std::setw(2) << std::setfill(
'0');
197 for (k=0; k<len; ++k) {
199 s[0] = data[k] >= 32 && data[k] < 127? data[k] :
'.';
215 m_lastDumpAddr = vaddr;
234 m_addressSelect = address;
236 uint64_t blockNr = address >> m_blockSizeShift;
238 if (blockNr+1 > m_memoryBlocks.size())
239 m_selectedHostMemoryBlock = NULL;
241 m_selectedHostMemoryBlock = m_memoryBlocks[blockNr];
243 m_selectedOffsetWithinBlock = address & (m_blockSize-1);
251 if (m_selectedHostMemoryBlock == NULL)
254 data = (((uint8_t*)m_selectedHostMemoryBlock)
255 [m_selectedOffsetWithinBlock]);
266 assert((m_addressSelect & 1) == 0);
268 if (m_selectedHostMemoryBlock == NULL)
271 data = (((uint16_t*)m_selectedHostMemoryBlock)
272 [m_selectedOffsetWithinBlock >> 1]);
288 assert((m_addressSelect & 3) == 0);
290 if (m_selectedHostMemoryBlock == NULL)
293 data = (((uint32_t*)m_selectedHostMemoryBlock)
294 [m_selectedOffsetWithinBlock >> 2]);
310 assert((m_addressSelect & 7) == 0);
312 if (m_selectedHostMemoryBlock == NULL)
315 data = (((uint64_t*)m_selectedHostMemoryBlock)
316 [m_selectedOffsetWithinBlock >> 3]);
332 if (m_writeProtected)
335 if (m_selectedHostMemoryBlock == NULL)
336 m_selectedHostMemoryBlock = AllocateBlock();
338 (((uint8_t*)m_selectedHostMemoryBlock)
339 [m_selectedOffsetWithinBlock]) = data;
350 assert((m_addressSelect & 1) == 0);
352 if (m_writeProtected)
355 if (m_selectedHostMemoryBlock == NULL)
356 m_selectedHostMemoryBlock = AllocateBlock();
364 (((uint16_t*)m_selectedHostMemoryBlock)
365 [m_selectedOffsetWithinBlock >> 1]) = d;
376 assert((m_addressSelect & 3) == 0);
378 if (m_writeProtected)
381 if (m_selectedHostMemoryBlock == NULL)
382 m_selectedHostMemoryBlock = AllocateBlock();
390 (((uint32_t*)m_selectedHostMemoryBlock)
391 [m_selectedOffsetWithinBlock >> 2]) = d;
402 assert((m_addressSelect & 7) == 0);
404 if (m_writeProtected)
407 if (m_selectedHostMemoryBlock == NULL)
408 m_selectedHostMemoryBlock = AllocateBlock();
416 (((uint64_t*)m_selectedHostMemoryBlock)
417 [m_selectedOffsetWithinBlock >> 3]) = d;
432 static void Test_CacheComponent_IsStable()
438 static void Test_CacheComponent_AddressDataBus()
444 "AddressDataBus interface", bus != NULL);
449 UNITTEST(Test_CacheComponent_IsStable);
450 UNITTEST(Test_CacheComponent_AddressDataBus);
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
virtual bool MethodMayBeReexecutedWithoutArgs(const string &methodName) const
Returns whether a method name may be re-executed without args.
static refcount_ptr< Component > CreateComponent(const string &componentNameAndOptionalArgs, GXemul *gxemul=NULL)
Creates a component given a short component name.
CacheComponent(const string &visibleClassName="cache")
Constructs a CacheComponent.
static refcount_ptr< Component > Create(const ComponentCreateArgs &args)
Creates a CacheComponent.
virtual void ExecuteMethod(GXemul *gxemul, const string &methodName, const vector< string > &arguments)
Executes a method on the component.
bool AddVariable(const string &name, T *variablePointer)
Adds a state variable of type T to the Component.
virtual AddressDataBus * AsAddressDataBus()
Returns the component's AddressDataBus interface.
virtual bool ReadData(uint8_t &data, Endianness endianness)
Reads 8-bit data from the currently selected address.
virtual void ExecuteMethod(GXemul *gxemul, const string &methodName, const vector< string > &arguments)
Executes a method on the component.
An interface for implementing components that read/write data via an address bus. ...
static string GetAttribute(const string &attributeName)
Creates a Component.
A memory Cache Component.
#define UNITTESTS(class)
Helper for unit test case execution.
virtual bool MethodMayBeReexecutedWithoutArgs(const string &methodName) const
Returns whether a method name may be re-executed without args.
static bool HasAttribute(const string &name, const string &attributeName)
Checks if a component has a specific attribute.
virtual void GetMethodNames(vector< string > &names) const
Retrieves a component's implemented method names.
static string GetAttribute(const string &attributeName)
Get attribute information about the CacheComponent class.
A Component is a node in the configuration tree that makes up an emulation setup. ...
string GenerateDetails() const
Generate details about the component.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
virtual ~CacheComponent()
virtual AddressDataBus * AsAddressDataBus()
Returns the component's AddressDataBus interface, if any.
virtual void AddressSelect(uint64_t address)
Place an address on the bus.
virtual string GenerateDetails() const
Generate details about the component.
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
virtual void ResetState()
Resets the state variables of this component.
virtual bool WriteData(const uint8_t &data, Endianness endianness)
Writes 8-bit data to the currently selected address.
#define UNITTEST(functionname)
Helper for unit test case execution.
virtual void GetMethodNames(vector< string > &names) const
Retrieves a component's implemented method names.