OpenASIP  2.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Memory Class Referenceabstract

#include <Memory.hh>

Inheritance diagram for Memory:
Inheritance graph
Collaboration diagram for Memory:
Collaboration graph

Public Types

typedef MinimumAddressableUnit MAU
 
typedef MAUMAUTable
 

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...
 
Memoryoperator= (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...
 
RequestQueuewriteRequests_
 The uncommited write requests. More...
 
int mask_
 Mask bit pattern for unpacking IntULongWord to MAUs. More...
 

Detailed Description

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.

Definition at line 74 of file Memory.hh.

Member Typedef Documentation

◆ MAU

Definition at line 76 of file Memory.hh.

◆ MAUTable

Definition at line 77 of file Memory.hh.

Constructor & Destructor Documentation

◆ Memory() [1/2]

Memory::Memory ( ULongWord  start,
ULongWord  end,
ULongWord  MAUSize,
bool  littleEndian 
)

Initializes the memory model.

The created memory model is empty. No data is allocated for its contents.

Parameters
startFirst address of the memory.
endLast address of the memory.
MAUSizeBit width of the minimum addressable unit of the memory.

Definition at line 56 of file Memory.cc.

56  :
57  littleEndian_(littleEndian),
60 
61  const std::size_t maxMAUSize =
62  static_cast<int>(sizeof(MinimumAddressableUnit) * BYTE_BITWIDTH);
63 
64  if (MAUSize_ == maxMAUSize) {
65  mask_ = ~0;
66  } else if (MAUSize_ > maxMAUSize) {
67  std::string msg = "Maximum supported MAU width is ";
68  msg += Conversion::toString(maxMAUSize);
69  msg += " bits.";
70  throw OutOfRange(__FILE__, __LINE__, __func__, msg);
71  } else {
72  mask_ = ~0u << MAUSize_;
73  mask_ = ~mask_;
74  }
75 }

References __func__, BYTE_BITWIDTH, mask_, MAUSize_, and Conversion::toString().

Here is the call graph for this function:

◆ ~Memory()

Memory::~Memory ( )
virtual

Destructor.

Definition at line 80 of file Memory.cc.

80  {
81  delete writeRequests_;
82  writeRequests_ = NULL;
83 }

References writeRequests_.

◆ Memory() [2/2]

Memory::Memory ( const Memory )
private

Copying not allowed.

Member Function Documentation

◆ advanceClock()

void Memory::advanceClock ( )
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.

819  {
820 
821  RequestQueue::iterator iter = writeRequests_->begin();
822  while (iter != writeRequests_->end()) {
823  WriteRequest* req = (*iter);
824  for (int i = 0; i < req->size_; ++i) {
825  write(req->address_ + i, req->data_[i]);
826  }
827  delete[] (*iter)->data_;
828  (*iter)->data_ = NULL;
829  delete (*iter);
830  ++iter;
831  }
832 
833  writeRequests_->clear();
834 }

References WriteRequest::address_, WriteRequest::data_, WriteRequest::size_, write(), and writeRequests_.

Referenced by MemoryProxy::advanceClock(), CmdAdvanceClock::execute(), SimulateDialog::onAdvanceClock(), DirectAccessMemory::writeBE(), and MemoryGridTable::writeValue().

Here is the call graph for this function:

◆ checkRange()

void Memory::checkRange ( ULongWord  startAddress,
int  numberOfMAUs 
)
private

Helper for checking the legality of the memory access address range.

Does nothing in case the address range is legal, throws otherwise.

Exceptions
OutOfRangein case the range is illegal.

Definition at line 844 of file Memory.cc.

844  {
845 
846  unsigned int low = start();
847  unsigned int high = end();
848 
849  if ((startAddress < low) || (startAddress > high - numberOfMAUs + 1)) {
850  throw OutOfRange(
851  __FILE__, __LINE__, __func__,
852  (boost::format(
853  "Memory access at %d of size %d is out of the address space.")
854  % startAddress % numberOfMAUs).str());
855  }
856 }

References __func__, end(), and start().

Referenced by readBE(), readLE(), writeBE(), writeDirectlyBE(), writeDirectlyLE(), and writeLE().

Here is the call graph for this function:

◆ end()

virtual ULongWord Memory::end ( )
inlinevirtual

Definition at line 117 of file Memory.hh.

117 { return end_; }

References end_.

Referenced by checkRange(), MemoryGridTable::MemoryGridTable(), and MemoryControl::setMemory().

◆ fillWithZeros()

void Memory::fillWithZeros ( )
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.

704  {
705  for (std::size_t addr = start_; addr <= end_; ++addr) {
706  write(addr, MAU(0));
707  }
708 }

References end_, start_, and write().

Referenced by MemoryProxy::fillWithZeros().

Here is the call graph for this function:

◆ isLittleEndian()

bool Memory::isLittleEndian ( )
inline

Definition at line 120 of file Memory.hh.

120 { return littleEndian_; }

References littleEndian_.

◆ MAUSize()

virtual ULongWord Memory::MAUSize ( )
inlinevirtual

Definition at line 118 of file Memory.hh.

118 { return MAUSize_; }

References MAUSize_.

Referenced by MemoryGridTable::MemoryGridTable(), readBE(), readLE(), MemoryControl::setMemory(), writeBE(), and writeLE().

◆ operator=()

Memory& Memory::operator= ( const Memory )
private

Assignment not allowed.

◆ packBE()

void Memory::packBE ( const Memory::MAUTable  data,
int  size,
ULongWord value 
)
protected

Packs MAUs to UIntWord.

Version for static table.

Parameters
dataData to be packed.
sizeThe number of MAUs.
valueThe target of the packing.

Definition at line 737 of file Memory.cc.

737  {
738 
739  value = 0;
740  int shiftCount = MAUSize_ * (size - 1);
741  for (int i = 0; i < size; i++) {
742  value = value | (data[i] << shiftCount);
743  shiftCount -= MAUSize_;
744  }
745 }

References MAUSize_.

◆ packLE()

void Memory::packLE ( const Memory::MAUTable  data,
int  size,
ULongWord value 
)
protected

Packs MAUs to UIntWord.

Version for static table.

Parameters
dataData to be packed.
sizeThe number of MAUs.
valueThe target of the packing.

Definition at line 757 of file Memory.cc.

757  {
758 
759  value = 0;
760  int shiftCount = 0;
761  for (int i = 0; i < size; i++) {
762  value = value | (data[i] << shiftCount);
763  shiftCount += MAUSize_;
764  }
765 }

References MAUSize_.

◆ read() [1/4]

Memory::MAU Memory::read ( ULongWord  address)
pure virtual

Reads a single memory location.

Must be implemented in the derived class. No range checking. The fastest way to read the memory.

Parameters
addressThe address to read.
Returns
The data read.

Implemented in DirectAccessMemory, RemoteMemory, MemoryProxy, and IdealSRAM.

Definition at line 160 of file Memory.cc.

160  {
161  return 0;
162 }

Referenced by CmdMem::execute(), MemoryGridTable::memoryContents(), MemoryProxy::read(), readBE(), and readLE().

◆ read() [2/4]

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.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 513 of file Memory.cc.

513  {
514  if (littleEndian_) {
515  readLE(address, data);
516  } else {
517  readBE(address, data);
518  }
519 }

References littleEndian_, readBE(), and readLE().

Here is the call graph for this function:

◆ read() [3/4]

void Memory::read ( ULongWord  address,
FloatWord data 
)

A convenience method for reading data from the memory and interpreting it as a FloatWord in order set by the memory.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 329 of file Memory.cc.

329  {
330  if (littleEndian_) {
331  readLE(address, data);
332  } else {
333  readBE(address, data);
334  }
335 }

References littleEndian_, readBE(), and readLE().

Here is the call graph for this function:

◆ read() [4/4]

void Memory::read ( ULongWord  address,
int  size,
ULongWord data 
)

A convenience method for reading units of data from the memory.

The data is written to an UIntWord.

Parameters
addressThe address to read.
countNumber of MAUs to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 663 of file Memory.cc.

663  {
664  if (littleEndian_) {
665  readLE(address, size, data);
666  } else {
667  readBE(address, size, data);
668  }
669 }

References littleEndian_, readBE(), and readLE().

Here is the call graph for this function:

◆ readBE() [1/3]

void Memory::readBE ( ULongWord  address,
DoubleWord data 
)
virtual

A convenience method for reading data from the memory and interpreting it as a DoubleWord in Big Endian.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 439 of file Memory.cc.

439  {
440 
441  assert(MAUSize() == sizeof(Byte)*8 &&
442  "LDD works only with byte sized MAU at the moment.");
443 
444  const std::size_t MAUS = 8;
445  union castUnion {
446  DoubleWord d;
447  Byte maus[MAUS];
448  };
449 
450  castUnion cast;
451 
452  for (std::size_t i = 0; i < MAUS; ++i) {
453  ULongWord data;
454  readBE(address + i, 1, data);
455  // Byte order must be reversed if host is not bigendian.
456  #if WORDS_BIGENDIAN == 1
457  cast.maus[i] = data;
458  #else
459  cast.maus[MAUS - 1 - i] = data;
460  #endif
461  }
462  data = cast.d;
463 }

References assert, MAUSize(), and readBE().

Here is the call graph for this function:

◆ readBE() [2/3]

void Memory::readBE ( ULongWord  address,
FloatWord data 
)
virtual

A convenience method for reading data from the memory and interpreting it as a FloatWord in Big Endian Format

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 247 of file Memory.cc.

247  {
248 
249  assert(MAUSize() == sizeof(Byte)*8 &&
250  "Loading FloatWords works only with byte sized MAU at the moment.");
251 
252  const std::size_t MAUS = 4;
253 
254  checkRange(address, MAUS);
255 
256  union castUnion {
257  FloatWord d;
258  Byte maus[MAUS];
259  };
260 
261  castUnion cast;
262 
263  for (std::size_t i = 0; i < MAUS; ++i) {
264  ULongWord data;
265  // one byte so endian does not matter
266  readBE(address + i, 1, data);
267  // Byte order must be reversed if host is not bigendian.
268  #if WORDS_BIGENDIAN == 1
269  cast.maus[i] = data;
270  #else
271  cast.maus[MAUS - 1 - i] = data;
272  #endif
273  }
274  data = cast.d;
275 }

References assert, checkRange(), MAUSize(), and readBE().

Here is the call graph for this function:

◆ readBE() [3/3]

void Memory::readBE ( ULongWord  address,
int  size,
ULongWord data 
)
virtual

A convenience method for reading units of data from the memory in Big Endian

The data is written to an UIntWord.

Parameters
addressThe address to read.
countNumber of MAUs to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 640 of file Memory.cc.

640  {
641 
642  checkRange(address, size);
643 
644  data = 0;
645  int shiftCount = MAUSize_ * (size - 1);
646  for (int i = 0; i < size; i++) {
647  data = data | (read(address + i) << shiftCount);
648  shiftCount -= MAUSize_;
649  }
650 }

References checkRange(), MAUSize_, and read().

Referenced by CmdMem::execute(), read(), and readBE().

Here is the call graph for this function:

◆ readLE() [1/3]

void Memory::readLE ( ULongWord  address,
DoubleWord data 
)
virtual

A convenience method for reading data from the memory and interpreting it as a DoubleWord in Little Endian.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 476 of file Memory.cc.

476  {
477 
478  assert(MAUSize() == sizeof(Byte)*8 &&
479  "LDD works only with byte sized MAU at the moment.");
480 
481  const std::size_t MAUS = 8;
482  union castUnion {
483  DoubleWord d;
484  Byte maus[MAUS];
485  };
486 
487  castUnion cast;
488 
489  for (std::size_t i = 0; i < MAUS; ++i) {
490  ULongWord data;
491  readLE(address + i, 1, data);
492  // Byte order must be reversed if host is not bigendian.
493  #if WORDS_BIGENDIAN == 0
494  cast.maus[i] = data;
495  #else
496  cast.maus[MAUS - 1 - i] = data;
497  #endif
498  }
499  data = cast.d;
500 }

References assert, MAUSize(), and readLE().

Here is the call graph for this function:

◆ readLE() [2/3]

void Memory::readLE ( ULongWord  address,
FloatWord data 
)
virtual

A convenience method for reading data from the memory and interpreting it as a FloatWord in Little Endian Format

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 288 of file Memory.cc.

288  {
289 
290  assert(MAUSize() == sizeof(Byte)*8 &&
291  "Loading FloatWords works only with byte sized MAU at the moment.");
292 
293  const std::size_t MAUS = 4;
294 
295  checkRange(address, MAUS);
296 
297  union castUnion {
298  FloatWord d;
299  Byte maus[MAUS];
300  };
301 
302  castUnion cast;
303 
304  for (std::size_t i = 0; i < MAUS; ++i) {
305  ULongWord data;
306  // one bytes so endian does not matter
307  readLE(address + i, 1, data);
308  // Byte order must be reversed if host is not little endian.
309  #if WORDS_BIGENDIAN == 0
310  cast.maus[i] = data;
311  #else
312  cast.maus[MAUS - 1 - i] = data;
313  #endif
314  }
315  data = cast.d;
316 }

References assert, checkRange(), MAUSize(), and readLE().

Here is the call graph for this function:

◆ readLE() [3/3]

void Memory::readLE ( ULongWord  address,
int  size,
ULongWord data 
)
virtual

A convenience method for reading units of data from the memory in Little Endian

The data is written to an UIntWord.

Parameters
addressThe address to read.
countNumber of MAUs to read.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 682 of file Memory.cc.

682  {
683 
684  checkRange(address, size);
685 
686  data = 0;
687  long shiftCount = 0;
688  for (int i = 0; i < size; i++) {
689  ULongWord readByte = read(address+i);
690  data = data | (readByte << shiftCount);
691  shiftCount += MAUSize_;
692  }
693 }

References checkRange(), MAUSize_, and read().

Referenced by read(), and readLE().

Here is the call graph for this function:

◆ reset()

void Memory::reset ( )
virtual

Resets the memory.

Clears any pending write requests.

Reimplemented in DirectAccessMemory, and MemoryProxy.

Definition at line 716 of file Memory.cc.

716  {
717  RequestQueue::iterator iter = writeRequests_->begin();
718  while (iter != writeRequests_->end()) {
719  delete[] (*iter)->data_;
720  (*iter)->data_ = NULL;
721  delete (*iter);
722  ++iter;
723  }
724  writeRequests_->clear();
725 }

References writeRequests_.

Referenced by MemoryProxy::reset().

◆ start()

virtual ULongWord Memory::start ( )
inlinevirtual

Definition at line 116 of file Memory.hh.

116 { return start_; }

References start_.

Referenced by checkRange(), MemoryGridTable::MemoryGridTable(), and MemoryControl::setMemory().

◆ unpackBE()

void Memory::unpackBE ( const ULongWord value,
int  size,
Memory::MAUTable  data 
)
protected

Unpack a given UIntWord to MAUs.

Version for static table. Table is expected to be correct size, no checking is done!

Parameters
valueValue to be unpacked.
sizeThe number of MAUs.
dataThe target of unpacking.

Definition at line 778 of file Memory.cc.

781  {
782  int shiftCount = MAUSize_ * (size - 1);
783  for(int i = 0; i < size; ++i) {
784  data[i] = ((value >> shiftCount) & mask_);
785  shiftCount -= MAUSize_;
786  }
787 }

References mask_, and MAUSize_.

Referenced by writeBE(), and writeDirectlyBE().

◆ unpackLE()

void Memory::unpackLE ( const ULongWord value,
int  size,
Memory::MAUTable  data 
)
protected

Unpack a given UIntWord to MAUs.

Version for static table. Table is expected to be correct size, no checking is done!

Parameters
valueValue to be unpacked.
sizeThe number of MAUs.
dataThe target of unpacking.

Definition at line 800 of file Memory.cc.

803  {
804  int shiftCount = 0;
805  for(int i = 0; i < size; ++i) {
806  data[i] = ((value >> shiftCount) & mask_);
807  shiftCount += MAUSize_;
808  }
809 }

References mask_, and MAUSize_.

Referenced by writeDirectlyLE(), and writeLE().

◆ write() [1/4]

void Memory::write ( ULongWord  address,
DoubleWord  data 
)

A convenience method for writing a DoubleWord to the memory.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 531 of file Memory.cc.

531  {
532  if (littleEndian_) {
533  writeLE(address, data);
534  } else {
535  writeBE(address, data);
536  }
537 }

References littleEndian_, writeBE(), and writeLE().

Here is the call graph for this function:

◆ write() [2/4]

void Memory::write ( ULongWord  address,
FloatWord  data 
)

◆ write() [3/4]

void Memory::write ( ULongWord  address,
int  count,
ULongWord  data 
)

A convenience method for writing units of data to the memory.

The data is stored in an UIntWord.

Parameters
addressThe address to write.
countNumber of MAUs to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 175 of file Memory.cc.

175  {
176  if (littleEndian_) {
177  writeLE(address, count, data);
178  } else {
179  writeBE(address, count, data);
180  }
181 }

References littleEndian_, writeBE(), and writeLE().

Here is the call graph for this function:

◆ write() [4/4]

void Memory::write ( ULongWord  address,
MAU  data 
)
pure virtual

Writes a single memory location.

Must be implemented in the derived class. No range checking. The fastest way to write to the memory.

Parameters
addressThe target address.
dataThe data to write.

Implemented in DirectAccessMemory, RemoteMemory, MemoryProxy, and IdealSRAM.

Definition at line 95 of file Memory.cc.

95  {
96  abortWithError("Must be implemented in the derived class.");
97 }

References abortWithError.

Referenced by advanceClock(), fillWithZeros(), MemoryProxy::read(), MemoryProxy::write(), writeDirectlyBE(), writeDirectlyLE(), and MemoryGridTable::writeValue().

◆ writeBE() [1/3]

void Memory::writeBE ( ULongWord  address,
DoubleWord  data 
)
virtual

A convenience method for writing a DoubleWord to the memory in Big Endian.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 549 of file Memory.cc.

549  {
550 
551  assert(MAUSize() == sizeof(Byte)*8 &&
552  "LDD works only with byte sized MAU at the moment.");
553 
554  const std::size_t MAUS = 8;
555 
556  checkRange(address, MAUS);
557 
558  union castUnion {
559  DoubleWord d;
560  Byte maus[MAUS];
561  };
562 
563  castUnion cast;
564  cast.d = data;
565 
566  WriteRequest* request = new WriteRequest();
567  request->data_ = new MAU[MAUS];
568  request->size_ = MAUS;
569  request->address_ = address;
570 
571  for (std::size_t i = 0; i < MAUS; ++i) {
572  UIntWord data;
573  // Byte order must be reversed if host is not bigendian.
574  #if WORDS_BIGENDIAN == 1
575  data = cast.maus[i];
576  #else
577  data = cast.maus[MAUS - 1 - i];
578  #endif
579  request->data_[i] = data;
580  }
581  writeRequests_->push_back(request);
582 }

References WriteRequest::address_, assert, checkRange(), WriteRequest::data_, MAUSize(), WriteRequest::size_, and writeRequests_.

Here is the call graph for this function:

◆ writeBE() [2/3]

void Memory::writeBE ( ULongWord  address,
FloatWord  data 
)
virtual

A convenience method for writing a FloatWord to the memory in Big Endian.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 347 of file Memory.cc.

347  {
348 
349  assert(MAUSize() == sizeof(Byte)*8 &&
350  "Writing FloatWords works only with byte sized MAU at the moment.");
351 
352  const std::size_t MAUS = 4;
353 
354  checkRange(address, MAUS);
355 
356  union castUnion {
357  FloatWord d;
358  Byte maus[MAUS];
359  };
360 
361  castUnion cast;
362  cast.d = data;
363 
364  WriteRequest* request = new WriteRequest();
365  request->data_ = new MAU[MAUS];
366  request->size_ = MAUS;
367  request->address_ = address;
368 
369  for (std::size_t i = 0; i < MAUS; ++i) {
370  UIntWord data;
371  // Byte order must be reversed if host is not bigendian.
372  #if WORDS_BIGENDIAN == 1
373  data = cast.maus[i];
374  #else
375  data = cast.maus[MAUS - 1 - i];
376  #endif
377  request->data_[i] = data;
378  }
379  writeRequests_->push_back(request);
380 }

References WriteRequest::address_, assert, checkRange(), WriteRequest::data_, MAUSize(), WriteRequest::size_, and writeRequests_.

Here is the call graph for this function:

◆ writeBE() [3/3]

void Memory::writeBE ( ULongWord  address,
int  count,
ULongWord  data 
)
virtual

A convenience method for writing units of data to the memory.

The data is stored in an UIntWord.

Parameters
addressThe address to write.
countNumber of MAUs to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Reimplemented in DirectAccessMemory.

Definition at line 194 of file Memory.cc.

194  {
195 
196  checkRange(address, count);
197 
198  Memory::MAU MAUData[MAX_ACCESS_SIZE];
199  unpackBE(data, count, MAUData);
200 
201  WriteRequest* request = new WriteRequest();
202  request->data_ = new MAU[count];
203  std::memcpy(request->data_, MAUData, count*sizeof(MAU));
204  request->size_ = count;
205  request->address_ = address;
206  writeRequests_->push_back(request);
207 }

References WriteRequest::address_, checkRange(), WriteRequest::data_, MAX_ACCESS_SIZE, WriteRequest::size_, unpackBE(), and writeRequests_.

Referenced by write(), and DirectAccessMemory::writeBE().

Here is the call graph for this function:

◆ writeDirectlyBE()

void Memory::writeDirectlyBE ( ULongWord  address,
int  count,
ULongWord  data 
)
virtual

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).

Parameters
addressThe target address.
countNumber of MAUs to write.
dataThe data to write.

Definition at line 112 of file Memory.cc.

112  {
113 
114  checkRange(address, count);
115 
116  Memory::MAU MAUData[MAX_ACCESS_SIZE];
117  unpackBE(data, count, MAUData);
118 
119  for (int i = 0; i < count; ++i) {
120  write(address + i, MAUData[i]);
121  }
122 }

References checkRange(), MAX_ACCESS_SIZE, unpackBE(), and write().

Here is the call graph for this function:

◆ writeDirectlyLE()

void Memory::writeDirectlyLE ( ULongWord  address,
int  count,
ULongWord  data 
)
virtual

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).

Parameters
addressThe target address.
countNumber of MAUs to write.
dataThe data to write.

Definition at line 137 of file Memory.cc.

137  {
138 
139  checkRange(address, count);
140 
141  Memory::MAU MAUData[MAX_ACCESS_SIZE];
142  unpackLE(data, count, MAUData);
143 
144  for (int i = 0; i < count; ++i) {
145  write(address + i, MAUData[i]);
146  }
147 }

References checkRange(), MAX_ACCESS_SIZE, unpackLE(), and write().

Here is the call graph for this function:

◆ writeLE() [1/3]

void Memory::writeLE ( ULongWord  address,
DoubleWord  data 
)
virtual

A convenience method for writing a DoubleWord to the memory in Litle Endian

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 594 of file Memory.cc.

594  {
595 
596  assert(MAUSize() == sizeof(Byte)*8 &&
597  "LDD works only with byte sized MAU at the moment.");
598 
599  const std::size_t MAUS = 8;
600 
601  checkRange(address, MAUS);
602 
603  union castUnion {
604  DoubleWord d;
605  Byte maus[MAUS];
606  };
607 
608  castUnion cast;
609  cast.d = data;
610 
611  WriteRequest* request = new WriteRequest();
612  request->data_ = new MAU[MAUS];
613  request->size_ = MAUS;
614  request->address_ = address;
615 
616  for (std::size_t i = 0; i < MAUS; ++i) {
617  UIntWord data;
618  // Byte order must be reversed if host is not bigendian.
619  #if WORDS_BIGENDIAN == 0
620  data = cast.maus[i];
621  #else
622  data = cast.maus[MAUS - 1 - i];
623  #endif
624  request->data_[i] = data;
625  }
626  writeRequests_->push_back(request);
627 }

References WriteRequest::address_, assert, checkRange(), WriteRequest::data_, MAUSize(), WriteRequest::size_, and writeRequests_.

Here is the call graph for this function:

◆ writeLE() [2/3]

void Memory::writeLE ( ULongWord  address,
FloatWord  data 
)
virtual

A convenience method for writing a FloatWord to the memory in Little Endian.

Note
Currently works only if MAU == 8 bits. asserts otherwise.
Parameters
addressThe address to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 392 of file Memory.cc.

392  {
393 
394  assert(MAUSize() == sizeof(Byte)*8 &&
395  "Writing FloatWords works only with byte sized MAU at the moment.");
396 
397  const std::size_t MAUS = 4;
398 
399  checkRange(address, MAUS);
400 
401  union castUnion {
402  FloatWord d;
403  Byte maus[MAUS];
404  };
405 
406  castUnion cast;
407  cast.d = data;
408 
409  WriteRequest* request = new WriteRequest();
410  request->data_ = new MAU[MAUS];
411  request->size_ = MAUS;
412  request->address_ = address;
413 
414  for (std::size_t i = 0; i < MAUS; ++i) {
415  UIntWord data;
416  // Byte order must be reversed if host is not bigendian.
417  #if WORDS_BIGENDIAN == 0
418  data = cast.maus[i];
419  #else
420  data = cast.maus[MAUS - 1 - i];
421  #endif
422  request->data_[i] = data;
423  }
424  writeRequests_->push_back(request);
425 }

References WriteRequest::address_, assert, checkRange(), WriteRequest::data_, MAUSize(), WriteRequest::size_, and writeRequests_.

Here is the call graph for this function:

◆ writeLE() [3/3]

void Memory::writeLE ( ULongWord  address,
int  count,
ULongWord  data 
)
virtual

A convenience method for writing units of data to the memory.

The data is stored in an UIntWord.

Parameters
addressThe address to write.
countNumber of MAUs to write.
dataThe data to write.
Exceptions
OutOfRangein case the address is out of range of the memory.

Definition at line 221 of file Memory.cc.

221  {
222 
223  checkRange(address, count);
224 
225  Memory::MAU MAUData[MAX_ACCESS_SIZE];
226  unpackLE(data, count, MAUData);
227 
228  WriteRequest* request = new WriteRequest();
229  request->data_ = new MAU[count];
230  std::memcpy(request->data_, MAUData, count*sizeof(MAU));
231  request->size_ = count;
232  request->address_ = address;
233  writeRequests_->push_back(request);
234 }

References WriteRequest::address_, checkRange(), WriteRequest::data_, MAX_ACCESS_SIZE, WriteRequest::size_, unpackLE(), and writeRequests_.

Referenced by write().

Here is the call graph for this function:

Member Data Documentation

◆ end_

ULongWord Memory::end_
private

End point of the address space.

Definition at line 140 of file Memory.hh.

Referenced by end(), and fillWithZeros().

◆ littleEndian_

bool Memory::littleEndian_
protected

Definition at line 128 of file Memory.hh.

Referenced by isLittleEndian(), read(), and write().

◆ mask_

int Memory::mask_
private

Mask bit pattern for unpacking IntULongWord to MAUs.

Definition at line 147 of file Memory.hh.

Referenced by Memory(), unpackBE(), and unpackLE().

◆ MAUSize_

ULongWord Memory::MAUSize_
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().

◆ start_

ULongWord Memory::start_
private

Starting point of the address space.

Definition at line 138 of file Memory.hh.

Referenced by fillWithZeros(), and start().

◆ writeRequests_

RequestQueue* Memory::writeRequests_
private

The uncommited write requests.

Definition at line 145 of file Memory.hh.

Referenced by advanceClock(), reset(), writeBE(), writeLE(), and ~Memory().


The documentation for this class was generated from the following files:
UIntWord
Word UIntWord
Definition: BaseType.hh:144
Memory::littleEndian_
bool littleEndian_
Definition: Memory.hh:128
WriteRequest::address_
Word address_
Address to be written to.
Definition: WriteRequest.hh:49
Memory::unpackLE
void unpackLE(const ULongWord &value, int size, Memory::MAUTable data)
Definition: Memory.cc:800
OutOfRange
Definition: Exception.hh:320
Memory::MAUSize
virtual ULongWord MAUSize()
Definition: Memory.hh:118
Memory::readBE
virtual void readBE(ULongWord address, int size, ULongWord &data)
Definition: Memory.cc:640
Byte
unsigned char Byte
Definition: BaseType.hh:116
Conversion::toString
static std::string toString(const T &source)
RequestQueue
Definition: WriteRequest.hh:57
Memory::MAUSize_
ULongWord MAUSize_
Size of the minimum adressable unit.
Definition: Memory.hh:142
assert
#define assert(condition)
Definition: Application.hh:86
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
Memory::start_
ULongWord start_
Starting point of the address space.
Definition: Memory.hh:138
Memory::readLE
virtual void readLE(ULongWord address, int size, ULongWord &data)
Definition: Memory.cc:682
MinimumAddressableUnit
Word MinimumAddressableUnit
Type for storing a MAU (must be unsigned type!). This limits the maximum size of the simulated minimu...
Definition: BaseType.hh:184
MAX_ACCESS_SIZE
#define MAX_ACCESS_SIZE
Maximum number of MAUs in a single request supported by the interface.
Definition: Memory.hh:152
FloatWord
float FloatWord
Definition: BaseType.hh:160
WriteRequest::data_
Memory::MAUTable data_
Data to be written.
Definition: WriteRequest.hh:45
__func__
#define __func__
Definition: Application.hh:67
Memory::mask_
int mask_
Mask bit pattern for unpacking IntULongWord to MAUs.
Definition: Memory.hh:147
DoubleWord
double DoubleWord
Definition: BaseType.hh:166
WriteRequest::size_
int size_
Size of the data to be read/written.
Definition: WriteRequest.hh:51
Memory::read
virtual Memory::MAU read(ULongWord address)=0
Definition: Memory.cc:160
MAU
MinimumAddressableUnit MAU
Definition: CustomDBGController.cc:44
Memory::MAU
MinimumAddressableUnit MAU
Definition: Memory.hh:76
Memory::checkRange
void checkRange(ULongWord startAddress, int numberOfMAUs)
Definition: Memory.cc:844
Memory::end_
ULongWord end_
End point of the address space.
Definition: Memory.hh:140
Memory::unpackBE
void unpackBE(const ULongWord &value, int size, Memory::MAUTable data)
Definition: Memory.cc:778
Memory::write
virtual void write(ULongWord address, MAU data)=0
Definition: Memory.cc:95
BYTE_BITWIDTH
const Byte BYTE_BITWIDTH
Definition: BaseType.hh:136
Memory::end
virtual ULongWord end()
Definition: Memory.hh:117
Memory::writeBE
virtual void writeBE(ULongWord address, int size, ULongWord data)
Definition: Memory.cc:194
Memory::writeLE
virtual void writeLE(ULongWord address, int size, ULongWord data)
Definition: Memory.cc:221
Memory::writeRequests_
RequestQueue * writeRequests_
The uncommited write requests.
Definition: Memory.hh:145
ULongWord
unsigned long ULongWord
Definition: BaseType.hh:51
WriteRequest
Definition: WriteRequest.hh:42
Memory::start
virtual ULongWord start()
Definition: Memory.hh:116