OpenASIP
2.0
|
#include <Memory.hh>
Public Types | |
typedef MinimumAddressableUnit | MAU |
typedef MAU * | MAUTable |
Public Member Functions | |
Memory (ULongWord start, ULongWord end, ULongWord MAUSize, bool littleEndian_) | |
virtual | ~Memory () |
virtual void | advanceClock () |
virtual void | write (ULongWord address, MAU data)=0 |
virtual Memory::MAU | read (ULongWord address)=0 |
virtual void | writeBE (ULongWord address, int size, ULongWord data) |
virtual void | writeLE (ULongWord address, int size, ULongWord data) |
void | write (ULongWord address, int size, ULongWord data) |
virtual void | writeDirectlyBE (ULongWord address, int size, ULongWord data) |
virtual void | writeDirectlyLE (ULongWord address, int size, ULongWord data) |
void | write (ULongWord address, FloatWord data) |
void | write (ULongWord address, DoubleWord data) |
void | read (ULongWord address, int size, ULongWord &data) |
void | read (ULongWord address, DoubleWord &data) |
void | read (ULongWord address, FloatWord &data) |
virtual void | writeBE (ULongWord address, FloatWord data) |
virtual void | writeBE (ULongWord address, DoubleWord data) |
virtual void | writeLE (ULongWord address, FloatWord data) |
virtual void | writeLE (ULongWord address, DoubleWord data) |
virtual void | readBE (ULongWord address, int size, ULongWord &data) |
virtual void | readLE (ULongWord address, int size, ULongWord &data) |
virtual void | readBE (ULongWord address, FloatWord &data) |
virtual void | readBE (ULongWord address, DoubleWord &data) |
virtual void | readLE (ULongWord address, FloatWord &data) |
virtual void | readLE (ULongWord address, DoubleWord &data) |
virtual void | reset () |
virtual void | fillWithZeros () |
virtual ULongWord | start () |
virtual ULongWord | end () |
virtual ULongWord | MAUSize () |
bool | isLittleEndian () |
Protected Member Functions | |
void | packBE (const Memory::MAUTable data, int size, ULongWord &value) |
void | unpackBE (const ULongWord &value, int size, Memory::MAUTable data) |
void | packLE (const Memory::MAUTable data, int size, ULongWord &value) |
void | unpackLE (const ULongWord &value, int size, Memory::MAUTable data) |
Protected Attributes | |
bool | littleEndian_ |
Private Member Functions | |
Memory (const Memory &) | |
Copying not allowed. More... | |
Memory & | operator= (const Memory &) |
Assignment not allowed. More... | |
void | checkRange (ULongWord startAddress, int numberOfMAUs) |
Private Attributes | |
ULongWord | start_ |
Starting point of the address space. More... | |
ULongWord | end_ |
End point of the address space. More... | |
ULongWord | MAUSize_ |
Size of the minimum adressable unit. More... | |
RequestQueue * | writeRequests_ |
The uncommited write requests. More... | |
int | mask_ |
Mask bit pattern for unpacking IntULongWord to MAUs. More... | |
Memory Model interface provides methods for emulating memory access.
The interface provides methods for emulating the access to data memory by operations of the target architecture such as load and store. In addition, an interface is implemented for direct access to the memory storage for the debugging user interfaces.
The abstract base class Memory implements all functionality except for the actual write() and read() methods which write and read a single unit to the memory storage as efficiently as possible. That is left for the derived classes to implement, as it depends on the storage data structure used, etc.
Memory base class implements the correct ordering of loads and stores within the same cycle: loads in the same cycle do not see the values of the writes in that cycle. That is, the writes are committed to the memory array at cycleAdvance() call. Derived classes may loosen this behavior and let the client take care of the correct ordering of the memory accesses, as is the case with the compiled simulation engine and the DirectAccessMemory implementation it uses for simulating data memory.
The Memory abstraction deals with MAUs (commonly bytes). The client can access the Memory for storing writing doubles and floats in case it implements floating point memory operations. Interface for those is out of the abstraction level of this interface.
typedef MinimumAddressableUnit Memory::MAU |
typedef MAU* Memory::MAUTable |
Initializes the memory model.
The created memory model is empty. No data is allocated for its contents.
start | First address of the memory. |
end | Last address of the memory. |
MAUSize | Bit width of the minimum addressable unit of the memory. |
Definition at line 56 of file Memory.cc.
References __func__, BYTE_BITWIDTH, mask_, MAUSize_, and Conversion::toString().
|
virtual |
|
private |
Copying not allowed.
|
virtual |
Advances clock for one cycle.
Commits all pending write requests to the memory. Cannot throw an exception, request legality is checked when request is initiated.
Reimplemented in DirectAccessMemory, and MemoryProxy.
Definition at line 819 of file Memory.cc.
References WriteRequest::address_, WriteRequest::data_, WriteRequest::size_, write(), and writeRequests_.
Referenced by MemoryProxy::advanceClock(), CmdAdvanceClock::execute(), SimulateDialog::onAdvanceClock(), DirectAccessMemory::writeBE(), and MemoryGridTable::writeValue().
|
private |
Helper for checking the legality of the memory access address range.
Does nothing in case the address range is legal, throws otherwise.
OutOfRange | in case the range is illegal. |
Definition at line 844 of file Memory.cc.
References __func__, end(), and start().
Referenced by readBE(), readLE(), writeBE(), writeDirectlyBE(), writeDirectlyLE(), and writeLE().
|
inlinevirtual |
Definition at line 117 of file Memory.hh.
References end_.
Referenced by checkRange(), MemoryGridTable::MemoryGridTable(), and MemoryControl::setMemory().
|
virtual |
Fills the whole memory with zeros.
This is needed due to some buggy simulated programs which expect uninitialized data to be zero. The default implementation is a slow for-loop which can be overridden with a faster one depending on the storage used.
Reimplemented in DirectAccessMemory, MemoryProxy, and IdealSRAM.
Definition at line 704 of file Memory.cc.
References end_, start_, and write().
Referenced by MemoryProxy::fillWithZeros().
|
inline |
|
inlinevirtual |
Definition at line 118 of file Memory.hh.
References MAUSize_.
Referenced by MemoryGridTable::MemoryGridTable(), readBE(), readLE(), MemoryControl::setMemory(), writeBE(), and writeLE().
|
protected |
|
protected |
|
pure virtual |
Reads a single memory location.
Must be implemented in the derived class. No range checking. The fastest way to read the memory.
address | The address to read. |
Implemented in DirectAccessMemory, RemoteMemory, MemoryProxy, and IdealSRAM.
Definition at line 160 of file Memory.cc.
Referenced by CmdMem::execute(), MemoryGridTable::memoryContents(), MemoryProxy::read(), readBE(), and readLE().
void Memory::read | ( | ULongWord | address, |
DoubleWord & | data | ||
) |
A convenience method for reading data from the memory and interpreting it as a DoubleWord in order set by endian bit of memory.
address | The address to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 513 of file Memory.cc.
References littleEndian_, readBE(), and readLE().
A convenience method for reading data from the memory and interpreting it as a FloatWord in order set by the memory.
address | The address to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 329 of file Memory.cc.
References littleEndian_, readBE(), and readLE().
A convenience method for reading units of data from the memory.
The data is written to an UIntWord.
address | The address to read. |
count | Number of MAUs to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 663 of file Memory.cc.
References littleEndian_, readBE(), and readLE().
|
virtual |
A convenience method for reading data from the memory and interpreting it as a DoubleWord in Big Endian.
address | The address to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 439 of file Memory.cc.
References assert, MAUSize(), and readBE().
A convenience method for reading data from the memory and interpreting it as a FloatWord in Big Endian Format
address | The address to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 247 of file Memory.cc.
References assert, checkRange(), MAUSize(), and readBE().
A convenience method for reading units of data from the memory in Big Endian
The data is written to an UIntWord.
address | The address to read. |
count | Number of MAUs to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 640 of file Memory.cc.
References checkRange(), MAUSize_, and read().
Referenced by CmdMem::execute(), read(), and readBE().
|
virtual |
A convenience method for reading data from the memory and interpreting it as a DoubleWord in Little Endian.
address | The address to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 476 of file Memory.cc.
References assert, MAUSize(), and readLE().
A convenience method for reading data from the memory and interpreting it as a FloatWord in Little Endian Format
address | The address to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 288 of file Memory.cc.
References assert, checkRange(), MAUSize(), and readLE().
A convenience method for reading units of data from the memory in Little Endian
The data is written to an UIntWord.
address | The address to read. |
count | Number of MAUs to read. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 682 of file Memory.cc.
References checkRange(), MAUSize_, and read().
Referenced by read(), and readLE().
|
virtual |
Resets the memory.
Clears any pending write requests.
Reimplemented in DirectAccessMemory, and MemoryProxy.
Definition at line 716 of file Memory.cc.
References writeRequests_.
Referenced by MemoryProxy::reset().
|
inlinevirtual |
Definition at line 116 of file Memory.hh.
References start_.
Referenced by checkRange(), MemoryGridTable::MemoryGridTable(), and MemoryControl::setMemory().
|
protected |
Unpack a given UIntWord to MAUs.
Version for static table. Table is expected to be correct size, no checking is done!
value | Value to be unpacked. |
size | The number of MAUs. |
data | The target of unpacking. |
Definition at line 778 of file Memory.cc.
References mask_, and MAUSize_.
Referenced by writeBE(), and writeDirectlyBE().
|
protected |
Unpack a given UIntWord to MAUs.
Version for static table. Table is expected to be correct size, no checking is done!
value | Value to be unpacked. |
size | The number of MAUs. |
data | The target of unpacking. |
Definition at line 800 of file Memory.cc.
References mask_, and MAUSize_.
Referenced by writeDirectlyLE(), and writeLE().
void Memory::write | ( | ULongWord | address, |
DoubleWord | data | ||
) |
A convenience method for writing a DoubleWord to the memory.
address | The address to write. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 531 of file Memory.cc.
References littleEndian_, writeBE(), and writeLE().
A convenience method for writing units of data to the memory.
The data is stored in an UIntWord.
address | The address to write. |
count | Number of MAUs to write. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 175 of file Memory.cc.
References littleEndian_, writeBE(), and writeLE().
Writes a single memory location.
Must be implemented in the derived class. No range checking. The fastest way to write to the memory.
address | The target address. |
data | The data to write. |
Implemented in DirectAccessMemory, RemoteMemory, MemoryProxy, and IdealSRAM.
Definition at line 95 of file Memory.cc.
References abortWithError.
Referenced by advanceClock(), fillWithZeros(), MemoryProxy::read(), MemoryProxy::write(), writeDirectlyBE(), writeDirectlyLE(), and MemoryGridTable::writeValue().
|
virtual |
A convenience method for writing a DoubleWord to the memory in Big Endian.
address | The address to write. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 549 of file Memory.cc.
References WriteRequest::address_, assert, checkRange(), WriteRequest::data_, MAUSize(), WriteRequest::size_, and writeRequests_.
A convenience method for writing a FloatWord to the memory in Big Endian.
address | The address to write. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 347 of file Memory.cc.
References WriteRequest::address_, assert, checkRange(), WriteRequest::data_, MAUSize(), WriteRequest::size_, and writeRequests_.
A convenience method for writing units of data to the memory.
The data is stored in an UIntWord.
address | The address to write. |
count | Number of MAUs to write. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Reimplemented in DirectAccessMemory.
Definition at line 194 of file Memory.cc.
References WriteRequest::address_, checkRange(), WriteRequest::data_, MAX_ACCESS_SIZE, WriteRequest::size_, unpackBE(), and writeRequests_.
Referenced by write(), and DirectAccessMemory::writeBE().
Writes a single memory location directly without waiting to the end of the clock.
This is used in case it's important for potential other memory operations in the same cycle to see the write. This is used (at the moment solely) to simulate Compare-and-swap (CAS).
address | The target address. |
count | Number of MAUs to write. |
data | The data to write. |
Definition at line 112 of file Memory.cc.
References checkRange(), MAX_ACCESS_SIZE, unpackBE(), and write().
Writes a single memory location directly without waiting to the end of the clock.
This is used in case it's important for potential other memory operations in the same cycle to see the write. This is used (at the moment solely) to simulate Compare-and-swap (CAS).
address | The target address. |
count | Number of MAUs to write. |
data | The data to write. |
Definition at line 137 of file Memory.cc.
References checkRange(), MAX_ACCESS_SIZE, unpackLE(), and write().
|
virtual |
A convenience method for writing a DoubleWord to the memory in Litle Endian
address | The address to write. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 594 of file Memory.cc.
References WriteRequest::address_, assert, checkRange(), WriteRequest::data_, MAUSize(), WriteRequest::size_, and writeRequests_.
A convenience method for writing a FloatWord to the memory in Little Endian.
address | The address to write. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 392 of file Memory.cc.
References WriteRequest::address_, assert, checkRange(), WriteRequest::data_, MAUSize(), WriteRequest::size_, and writeRequests_.
A convenience method for writing units of data to the memory.
The data is stored in an UIntWord.
address | The address to write. |
count | Number of MAUs to write. |
data | The data to write. |
OutOfRange | in case the address is out of range of the memory. |
Definition at line 221 of file Memory.cc.
References WriteRequest::address_, checkRange(), WriteRequest::data_, MAX_ACCESS_SIZE, WriteRequest::size_, unpackLE(), and writeRequests_.
Referenced by write().
|
private |
End point of the address space.
Definition at line 140 of file Memory.hh.
Referenced by end(), and fillWithZeros().
|
protected |
Definition at line 128 of file Memory.hh.
Referenced by isLittleEndian(), read(), and write().
|
private |
Mask bit pattern for unpacking IntULongWord to MAUs.
Definition at line 147 of file Memory.hh.
Referenced by Memory(), unpackBE(), and unpackLE().
|
private |
Size of the minimum adressable unit.
Definition at line 142 of file Memory.hh.
Referenced by MAUSize(), Memory(), packBE(), packLE(), readBE(), readLE(), unpackBE(), and unpackLE().
|
private |
Starting point of the address space.
Definition at line 138 of file Memory.hh.
Referenced by fillWithZeros(), and start().
|
private |