103 static string GetAttribute(
const string& attributeName);
110 const string& methodName,
111 const vector<string>& arguments);
134 static void RunUnitTests(
int& nSucceeded,
int& nFailures);
137 void ReleaseAllBlocks();
139 void* AllocateBlock();
149 virtual ~RAMDataHandler()
153 virtual void Serialize(ostream& ss)
const 155 for (
size_t i=0; i<m_ram.m_memoryBlocks.size(); ++i)
156 if (m_ram.m_memoryBlocks[i] != NULL)
157 SerializeMemoryBlock(ss, i, m_ram.m_memoryBlocks[i]);
165 m_ram.ReleaseAllBlocks();
168 size_t len = value.length();
169 const char *cstr = value.c_str();
172 if (cstr[p] ==
'.') {
184 std::cerr <<
"deserialize ram: internal error\n";
185 throw std::exception();
190 memcpy(s1, cstr + p, 16);
192 memcpy(s2, cstr + p, 8);
197 ss1.flags(std::ios::hex);
202 ss2.flags(std::ios::hex);
207 if (p + 2*datalen < len) {
208 for (
size_t i=0; i<datalen; i++) {
212 if (c1 >=
'a' && c1 <=
'f')
217 if (c2 >=
'a' && c2 <=
'f')
222 uint8_t b = c1*16 + c2;
224 m_ram.AddressSelect(i + addr);
228 std::cerr <<
"deserialize ram: internal error\n";
229 throw std::exception();
232 if (cstr[p] !=
'.') {
233 std::cerr <<
"deserialize ram: internal error: no dot\n";
234 throw std::exception();
251 void SerializeMemoryBlock(ostream& ss,
size_t blockNr,
void *block)
const 253 const size_t rowSize = 1024;
254 uint64_t
addr = blockNr << m_ram.m_blockSizeShift;
255 uint64_t addrWithinBlock = 0;
257 while (addrWithinBlock < m_ram.m_blockSize) {
258 uint8_t *data = (uint8_t*)block + addrWithinBlock;
260 bool allZeroes =
true;
261 for (
size_t i=0; i<rowSize; i++)
262 if (data[i] != 0x00) {
270 SerializeRow(ss, addr, data, rowSize);
272 addrWithinBlock += rowSize;
278 void SerializeRow(ostream& ss, uint64_t
addr, uint8_t* data,
size_t rowSize)
const 280 ss.flags(std::ios::hex);
281 ss << std::setw(16) << std::setfill(
'0') << addr <<
":";
282 ss << std::setw(8) << std::setfill(
'0') << rowSize <<
":";
284 for (
size_t i=0; i<rowSize; i++)
285 ss << std::setw(2) << std::setfill(
'0') << (int)data[i];
295 const size_t m_blockSizeShift;
296 const size_t m_blockSize;
298 RAMDataHandler m_dataHandler;
301 typedef vector<void *> BlockNrToMemoryBlockVector;
302 BlockNrToMemoryBlockVector m_memoryBlocks;
303 bool m_writeProtected;
304 uint64_t m_lastDumpAddr;
307 uint64_t m_addressSelect;
308 void * m_selectedHostMemoryBlock;
309 size_t m_selectedOffsetWithinBlock;
313 #endif // RAMCOMPONENT_H static refcount_ptr< Component > Deserialize(ostream &messages, const string &str, size_t &pos)
Deserializes a string into a component tree.
RAMComponent(const string &visibleClassName="ram")
Constructs a RAMComponent.
virtual AddressDataBus * AsAddressDataBus()
Returns the component's AddressDataBus interface.
virtual bool WriteData(const uint8_t &data, Endianness endianness)
Writes 8-bit data to the currently selected address.
static void RunUnitTests(int &nSucceeded, int &nFailures)
An interface for implementing components that read/write data via an address bus. ...
static refcount_ptr< Component > Create(const ComponentCreateArgs &args)
Creates a RAMComponent.
virtual bool MethodMayBeReexecutedWithoutArgs(const string &methodName) const
Returns whether a method name may be re-executed without args.
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 RAMComponent class.
A Random Access Memory Component.
virtual void Serialize(ostream &ss) const =0
virtual bool ReadData(uint8_t &data, Endianness endianness)
Reads 8-bit data from the currently selected address.
void Serialize(ostream &ss, SerializationContext &context) const
Serializes the Component into a string stream.
virtual void ResetState()
Resets the state variables of this component.
virtual void AddressSelect(uint64_t address)
Place an address on the bus.
virtual void ExecuteMethod(GXemul *gxemul, const string &methodName, const vector< string > &arguments)
Executes a method on the component.
A base-class for memory-mapped components.
Base class for unit testable classes.