RAMComponent Class Reference

Back to the index.

Classes | Public Member Functions | Static Public Member Functions | List of all members
RAMComponent Class Reference

A Random Access Memory Component. More...

#include <RAMComponent.h>

Inheritance diagram for RAMComponent:
MemoryMappedComponent AddressDataBus UnitTestable Component ReferenceCountable

Public Member Functions

 RAMComponent (const string &visibleClassName="ram")
 Constructs a RAMComponent. More...
 
virtual ~RAMComponent ()
 
virtual void ResetState ()
 Resets the state variables of this component. More...
 
virtual void GetMethodNames (vector< string > &names) const
 Retrieves a component's implemented method names. More...
 
virtual bool MethodMayBeReexecutedWithoutArgs (const string &methodName) const
 Returns whether a method name may be re-executed without args. More...
 
virtual void ExecuteMethod (GXemul *gxemul, const string &methodName, const vector< string > &arguments)
 Executes a method on the component. More...
 
virtual AddressDataBusAsAddressDataBus ()
 Returns the component's AddressDataBus interface. More...
 
virtual void AddressSelect (uint64_t address)
 Place an address on the bus. More...
 
virtual bool ReadData (uint8_t &data, Endianness endianness)
 Reads 8-bit data from the currently selected address. More...
 
virtual bool ReadData (uint16_t &data, Endianness endianness)
 Reads 16-bit data from the currently selected address. More...
 
virtual bool ReadData (uint32_t &data, Endianness endianness)
 Reads 32-bit data from the currently selected address. More...
 
virtual bool ReadData (uint64_t &data, Endianness endianness)
 Reads 64-bit data from the currently selected address. More...
 
virtual bool WriteData (const uint8_t &data, Endianness endianness)
 Writes 8-bit data to the currently selected address. More...
 
virtual bool WriteData (const uint16_t &data, Endianness endianness)
 Writes 16-bit data to the currently selected address. More...
 
virtual bool WriteData (const uint32_t &data, Endianness endianness)
 Writes 32-bit data to the currently selected address. More...
 
virtual bool WriteData (const uint64_t &data, Endianness endianness)
 Writes 64-bit data to the currently selected address. More...
 
- Public Member Functions inherited from MemoryMappedComponent
 MemoryMappedComponent (const string &className, const string &visibleClassName)
 Constructs a MemoryMappedComponent. More...
 
string GenerateDetails () const
 Generate details about the component. More...
 
- Public Member Functions inherited from Component
virtual ~Component ()
 
string GetClassName () const
 Gets the class name of the component. More...
 
string GetVisibleClassName () const
 Gets the visible class name of the component. More...
 
refcount_ptr< ComponentClone () const
 Clones the component and all its children. More...
 
const refcount_ptr< ComponentLightClone () const
 Makes a light clone of the component and all its children. More...
 
void DetectChanges (const refcount_ptr< Component > &oldClone, ostream &changeMessages) const
 Compare an older clone to the current tree, to find changes. More...
 
string GenerateTreeDump (const string &branchTemplate, bool htmlLinksForClassNames=false, string prefixForComponentUrls="") const
 Generates an ASCII tree dump of a component tree. More...
 
void Reset ()
 Resets the state of this component and all its children. More...
 
bool PreRunCheck (GXemul *gxemul)
 Checks the state of this component and all its children, before starting execution. More...
 
void FlushCachedState ()
 Resets the cached state of this component and all its children. More...
 
virtual int Execute (GXemul *gxemul, int nrOfCycles)
 Execute one or more cycles. More...
 
virtual double GetCurrentFrequency () const
 Returns the current frequency (in Hz) that the component runs at. More...
 
virtual RootComponentAsRootComponent ()
 Returns the component's RootComponent interface. More...
 
virtual CPUComponentAsCPUComponent ()
 Returns the component's CPUComponent interface. More...
 
void SetParent (Component *parentComponent)
 Sets the parent component of this component. More...
 
ComponentGetParent ()
 Gets this component's parent component, if any. More...
 
const ComponentGetParent () const
 
string GeneratePath () const
 Generates a string representation of the path to the Component. More...
 
string GenerateShortestPossiblePath () const
 Generates a short string representation of the path to the Component. More...
 
const refcount_ptr< ComponentLookupPath (string path) const
 Looks up a path from this Component, and returns a pointer to the found Component, if any. More...
 
vector< string > FindPathByPartialMatch (const string &partialPath, bool shortestPossible=false) const
 Finds complete component paths, given a partial path. More...
 
void AddChild (refcount_ptr< Component > childComponent, size_t insertPosition=(size_t) -1)
 Adds a reference to a child component. More...
 
size_t RemoveChild (Component *childToRemove)
 Removes a reference to a child component. More...
 
ComponentsGetChildren ()
 Gets pointers to child components. More...
 
const ComponentsGetChildren () const
 Gets pointers to child components, as a const reference. More...
 
void GetVariableNames (vector< string > &names) const
 Retrieves a component's state variable names. More...
 
StateVariableGetVariable (const string &name)
 Gets a pointer to a state variable. More...
 
const StateVariableGetVariable (const string &name) const
 Gets a pointer to a state variable. More...
 
bool SetVariableValue (const string &name, const string &expression)
 Sets a variable to a new value. More...
 
void Serialize (ostream &ss, SerializationContext &context) const
 Serializes the Component into a string stream. More...
 
bool CheckConsistency () const
 Checks consistency by serializing and deserializing the component (including all its child components), and comparing the checksum of the original tree with the deserialized tree. More...
 
void AddChecksum (Checksum &checksum) const
 Adds this component's state, including children, to a checksum. More...
 
- Public Member Functions inherited from ReferenceCountable
 ReferenceCountable ()
 Default constructor, which initializes the reference count to zero. More...
 
 ~ReferenceCountable ()
 
- Public Member Functions inherited from AddressDataBus
 AddressDataBus ()
 Constructs an AddressDataBus instance. More...
 
virtual ~AddressDataBus ()
 

Static Public Member Functions

static refcount_ptr< ComponentCreate (const ComponentCreateArgs &args)
 Creates a RAMComponent. More...
 
static string GetAttribute (const string &attributeName)
 Get attribute information about the RAMComponent class. More...
 
static void RunUnitTests (int &nSucceeded, int &nFailures)
 
- Static Public Member Functions inherited from Component
static string GetAttribute (const string &attributeName)
 Creates a Component. More...
 
static refcount_ptr< ComponentDeserialize (ostream &messages, const string &str, size_t &pos)
 Deserializes a string into a component tree. More...
 
- Static Public Member Functions inherited from UnitTestable
static void RunUnitTests (int &nSucceeded, int &nFailures)
 Runs unit test cases. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Component
 Component (const string &className, const string &visibleClassName)
 Base constructor for a Component. More...
 
template<class T >
bool AddVariable (const string &name, T *variablePointer)
 Adds a state variable of type T to the Component. More...
 
bool AddCustomVariable (const string &name, CustomStateVariableHandler *variableHandler)
 Adds a custom state variable to the Component. More...
 
virtual bool CheckVariableWrite (StateVariable &var, const string &oldValue)
 Checks whether a write to a variable is OK. More...
 
virtual bool PreRunCheckForComponent (GXemul *gxemul)
 Checks the state of this component, before starting execution. More...
 
virtual void FlushCachedStateForComponent ()
 Resets the cached state of this component. More...
 
GXemulGetRunningGXemulInstance ()
 Returns a reference to the current GXemul instance. More...
 
UIGetUI ()
 Gets an UI reference for outputting debug messages during runtime. More...
 

Detailed Description

A Random Access Memory Component.

RAM is emulated by allocating large blocks of host memory (e.g. 4 MB per block), and simply forwarding all read and write requests to those memory blocks.

The host memory blocks are not allocated until they are actually written to. Reading from uninitialized/unwritten emulated memory returns zeros. This allows e.g. an emulated machine to have, say, 1 TB RAM, even if the host only has 1 GB, as long as the emulated guest OS does not touch all of the emulated memory.

In addition, host memory blocks are allocated as anonymous zero-filled memory using mmap(), so the blocks do not necessariliy use up host RAM unless they are touched.

Note 1: This class does not handle unaligned access. It is up to the caller to make sure that e.g. ReadData(uint64_t&, Endianness) is only called when the selected address is 64-bit aligned.

(The reason for this is that different emulated components want different semantics for unaligned access. For example, an x86 processor will transparently allow unaligned access, most RISC processors will cause an unaligned address exception, and some old ARM processors may even simply ignore the lowest bits of the address!)

Note 2: The RAM component's size and base offset are defined by state variables in the MemoryMappedComponent base class.

Definition at line 73 of file RAMComponent.h.

Constructor & Destructor Documentation

◆ RAMComponent()

RAMComponent::RAMComponent ( const string &  visibleClassName = "ram")

Constructs a RAMComponent.

Parameters
visibleClassNameThe visible class name. Defaults to "ram". Useful alternatives may be "rom" or "vram" for video ram.

Definition at line 36 of file RAMComponent.cc.

References Component::AddCustomVariable(), and Component::AddVariable().

Referenced by Create().

◆ ~RAMComponent()

RAMComponent::~RAMComponent ( )
virtual

Definition at line 53 of file RAMComponent.cc.

Member Function Documentation

◆ AddressSelect()

void RAMComponent::AddressSelect ( uint64_t  address)
virtual

Place an address on the bus.

Parameters
addressThe address to select.

Implements AddressDataBus.

Definition at line 206 of file RAMComponent.cc.

Referenced by ExecuteMethod().

◆ AsAddressDataBus()

AddressDataBus * RAMComponent::AsAddressDataBus ( )
virtual

Returns the component's AddressDataBus interface.

Returns
A pointer to an AddressDataBus.

Reimplemented from Component.

Definition at line 200 of file RAMComponent.cc.

◆ Create()

refcount_ptr< Component > RAMComponent::Create ( const ComponentCreateArgs args)
static

Creates a RAMComponent.

Definition at line 70 of file RAMComponent.cc.

References RAMComponent().

◆ ExecuteMethod()

void RAMComponent::ExecuteMethod ( GXemul gxemul,
const string &  methodName,
const vector< string > &  arguments 
)
virtual

Executes a method on the component.

Note 1: The method name must be one of those returned by GetMethodNames(vector<string>&), either in the class itself or by one of the base implementations.

Note 2: The base class' member function should only be called if this class does not handle the method.

Parameters
gxemulA reference to the GXemul instance.
methodNameThe name of the method.
argumentsA vector of arguments to the method.

Reimplemented from Component.

Definition at line 114 of file RAMComponent.cc.

References AddressSelect(), BigEndian, data, Component::ExecuteMethod(), GXemul::GetUI(), ReadData(), and UI::ShowDebugMessage().

◆ GetAttribute()

string RAMComponent::GetAttribute ( const string &  attributeName)
static

Get attribute information about the RAMComponent class.

Parameters
attributeNameThe attribute name.
Returns
A string representing the attribute value.

Definition at line 76 of file RAMComponent.cc.

References Component::GetAttribute().

◆ GetMethodNames()

void RAMComponent::GetMethodNames ( vector< string > &  names) const
virtual

Retrieves a component's implemented method names.

Note that a component's implementation should call its base class' GetMethodNames(vector<string>&) too. However, when methods are executed, the most specific implementation (i.e. not the base class) will get a chance first to execute the method.

Parameters
namesA vector of strings, where method names should be added.

Reimplemented from Component.

Definition at line 94 of file RAMComponent.cc.

References Component::GetMethodNames().

◆ MethodMayBeReexecutedWithoutArgs()

bool RAMComponent::MethodMayBeReexecutedWithoutArgs ( const string &  methodName) const
virtual

Returns whether a method name may be re-executed without args.

Typical examples may be a RAMComponent which has a "dump" method, or a CPUComponent which has "dump" and "unassemble" methods.

Note that a component's implementation should call its base class' MethodMayBeReexecutedWithoutArgs(cosnt string&) too.

Parameters
methodNameThe name of the method.
Returns
true if the method may be re-executed without arguments, false otherwise.

Reimplemented from Component.

Definition at line 104 of file RAMComponent.cc.

References Component::MethodMayBeReexecutedWithoutArgs().

◆ ReadData() [1/4]

bool RAMComponent::ReadData ( uint8_t &  data,
Endianness  endianness 
)
virtual

Reads 8-bit data from the currently selected address.

Parameters
dataA reference to a variable which will receive the data.
endiannessSelects the endianness of the operation. Ignored for 8-bit reads and writes.
Returns
True if the access was successful, false otherwise (e.g. because of a timeout).

Implements AddressDataBus.

Definition at line 243 of file RAMComponent.cc.

Referenced by ExecuteMethod().

◆ ReadData() [2/4]

bool RAMComponent::ReadData ( uint16_t &  data,
Endianness  endianness 
)
virtual

Reads 16-bit data from the currently selected address.

Parameters
dataA reference to a variable which will receive the data.
endiannessSelects the endianness of the operation.
Returns
True if the access was successful, false otherwise (e.g. because of a timeout).

Implements AddressDataBus.

Definition at line 255 of file RAMComponent.cc.

References BE16_TO_HOST, BigEndian, and LE16_TO_HOST.

◆ ReadData() [3/4]

bool RAMComponent::ReadData ( uint32_t &  data,
Endianness  endianness 
)
virtual

Reads 32-bit data from the currently selected address.

Parameters
dataA reference to a variable which will receive the data.
endiannessSelects the endianness of the operation.
Returns
True if the access was successful, false otherwise (e.g. because of a timeout).

Implements AddressDataBus.

Definition at line 274 of file RAMComponent.cc.

References BE32_TO_HOST, BigEndian, and LE32_TO_HOST.

◆ ReadData() [4/4]

bool RAMComponent::ReadData ( uint64_t &  data,
Endianness  endianness 
)
virtual

Reads 64-bit data from the currently selected address.

Parameters
dataA reference to a variable which will receive the data.
endiannessSelects the endianness of the operation.
Returns
True if the access was successful, false otherwise (e.g. because of a timeout).

Implements AddressDataBus.

Definition at line 293 of file RAMComponent.cc.

References BE64_TO_HOST, BigEndian, and LE64_TO_HOST.

◆ ResetState()

void RAMComponent::ResetState ( )
virtual

Resets the state variables of this component.

Note 1: This function is not recursive, so children should not be traversed.

Note 2: After a component's state variables have been reset, the base class' ResetState() function should also be called.

The implementation of this function ususally takes the form of a number of assignment of values to member variables, and then the call to the base class' ResetState() function.

Reimplemented from Component.

Definition at line 88 of file RAMComponent.cc.

◆ RunUnitTests()

static void RAMComponent::RunUnitTests ( int &  nSucceeded,
int &  nFailures 
)
static

◆ WriteData() [1/4]

bool RAMComponent::WriteData ( const uint8_t &  data,
Endianness  endianness 
)
virtual

Writes 8-bit data to the currently selected address.

Parameters
dataA reference to a variable which contains the data.
endiannessSelects the endianness of the operation. Ignored for 8-bit reads and writes.
Returns
True if the access was successful, false otherwise (e.g. because of a timeout).

Implements AddressDataBus.

Definition at line 312 of file RAMComponent.cc.

◆ WriteData() [2/4]

bool RAMComponent::WriteData ( const uint16_t &  data,
Endianness  endianness 
)
virtual

Writes 16-bit data to the currently selected address.

Parameters
dataA reference to a variable which contains the data.
endiannessSelects the endianness of the operation.
Returns
True if the access was successful, false otherwise (e.g. because of a timeout).

Implements AddressDataBus.

Definition at line 327 of file RAMComponent.cc.

References BE16_TO_HOST, BigEndian, and LE16_TO_HOST.

◆ WriteData() [3/4]

bool RAMComponent::WriteData ( const uint32_t &  data,
Endianness  endianness 
)
virtual

Writes 32-bit data to the currently selected address.

Parameters
dataA reference to a variable which contains the data.
endiannessSelects the endianness of the operation.
Returns
True if the access was successful, false otherwise (e.g. because of a timeout).

Implements AddressDataBus.

Definition at line 350 of file RAMComponent.cc.

References BE32_TO_HOST, BigEndian, and LE32_TO_HOST.

◆ WriteData() [4/4]

bool RAMComponent::WriteData ( const uint64_t &  data,
Endianness  endianness 
)
virtual

Writes 64-bit data to the currently selected address.

Parameters
dataA reference to a variable which contains the data.
endiannessSelects the endianness of the operation.
Returns
True if the access was successful, false otherwise (e.g. because of a timeout).

Implements AddressDataBus.

Definition at line 373 of file RAMComponent.cc.

References AddressDataBus::AddressSelect(), Component::AsAddressDataBus(), UnitTest::Assert(), BE64_TO_HOST, BigEndian, Component::CheckConsistency(), Component::Clone(), ComponentFactory::CreateComponent(), Component::Deserialize(), ComponentFactory::HasAttribute(), LE64_TO_HOST, LittleEndian, Component::MethodMayBeReexecutedWithoutArgs(), AddressDataBus::ReadData(), Component::Reset(), Component::Serialize(), Component::SetVariableValue(), UNITTEST, UNITTESTS, and AddressDataBus::WriteData().


The documentation for this class was generated from the following files:

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13