Simple Machine

Machine
Class AbstractMainMemory

java.lang.Object
  extended by java.util.Observable
      extended by Util.AbstractDataModel
          extended by Machine.AbstractMainMemory
All Implemented Interfaces:
DataModel
Direct Known Subclasses:
MainMemory

public abstract class AbstractMainMemory
extends AbstractDataModel


Nested Class Summary
static class AbstractMainMemory.InvalidAddressException
           
 
Constructor Summary
AbstractMainMemory()
           
 
Method Summary
abstract  int bytesToInteger(UnsignedByte byteAtAddrPlus0, UnsignedByte byteAtAddrPlus1, UnsignedByte byteAtAddrPlus2, UnsignedByte byteAtAddrPlus3)
          Convert a byte array to an integer.
protected abstract  UnsignedByte[] get(int address, int length)
          Read a sequence of bytes from memory.
 java.lang.Class getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int columnIndex)
           
 int getRowCount()
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
           
abstract  UnsignedByte[] integerToBytes(int i)
          Convert an integer to a byte array.
protected abstract  boolean isAccessAligned(int address, int length)
          Determine whether specified address and length represent an ALIGNED access.
 boolean isCellEditable(int rowIndex, int columnIndex)
           
abstract  int length()
           
 UnsignedByte[] read(int address, int length)
          READ a sequence of bytes from memory starting at specified ALIGNED.
 int readInteger(int address)
          Read a four-byte integer from memory at ALIGNED address.
 int readIntegerUnaligned(int address)
          Read a four-byte Big-Endian integer from memory at possibly UNALIGNED address.
 UnsignedByte[] readUnaligned(int address, int length)
          READ a sequence of bytes from memory starting at specified possibly-UNALIGNED address.
protected abstract  void set(int address, UnsignedByte[] value)
          Write a sequence of bytes to memory.
 void setValueAt(java.lang.Object[] aValue, int rowIndex, int columnIndex)
           
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
           
 void setValueAtByUser(java.lang.Object[] aValue, int rowIndex, int columnIndex)
           
 void setValueAtByUser(java.lang.Object aValue, int rowIndex, int columnIndex)
           
 void write(int address, UnsignedByte[] value)
          WRITE a sequence of bytes to memory starting at specified ALIGNED.
 void writeInteger(int address, int value)
           
 void writeIntegerUnaligned(int address, int value)
           
 void writeUnaligned(int address, UnsignedByte[] value)
          WRITE a sequence of bytes to memory starting at specified possibly-UNALIGNED address.
 
Methods inherited from class Util.AbstractDataModel
addUndoableEditListener, canDeleteRow, canInsertRow, deleteRow, insertRow, tellObservers, tellObservers
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface Util.DataModel
addObserver
 

Constructor Detail

AbstractMainMemory

public AbstractMainMemory()
Method Detail

get

protected abstract UnsignedByte[] get(int address,
                                      int length)
                               throws AbstractMainMemory.InvalidAddressException
Read a sequence of bytes from memory. Protected method called by public read method.

Parameters:
address - byte address of first byte to read.
length - number of bytes to read.
Throws:
AbstractMainMemory.InvalidAddressException - if address is out of range.

set

protected abstract void set(int address,
                            UnsignedByte[] value)
                     throws AbstractMainMemory.InvalidAddressException
Write a sequence of bytes to memory. Protected method called by public write method.

Parameters:
address - byte address of first byte to write.
value - array of unsigned bytes to write to memory at this address.
Throws:
AbstractMainMemory.InvalidAddressException - if address is out of range.

isAccessAligned

protected abstract boolean isAccessAligned(int address,
                                           int length)
Determine whether specified address and length represent an ALIGNED access. Protected method called by public read and write methods. An address is aligned if and only if the address modulo value.length is 0 (i.e., the low order log 2 (length) bits are 0. Aligned memory access is faster than unaligned access and so compilers should attempt to used aligned access whenever possible. It is sometimes not possible, however, particularlly for reading instructions in architectures that support variable instruction lengths such as SM213 and Y86, for example.

Returns:
true iff access to address of length bytes is an aligned access

bytesToInteger

public abstract int bytesToInteger(UnsignedByte byteAtAddrPlus0,
                                   UnsignedByte byteAtAddrPlus1,
                                   UnsignedByte byteAtAddrPlus2,
                                   UnsignedByte byteAtAddrPlus3)
Convert a byte array to an integer.

Parameters:
byteAtAddrPlus0 - value of byte at some memory address addr
byteAtAddrPlus1 - value of byte at some memory address addr + 1
byteAtAddrPlus2 - value of byte at some memory address addr + 2
byteAtAddrPlus3 - value of byte at some memory address addr + 3
Returns:
integer comprised of this four bytes organized according to the Endianness of the target ISA

integerToBytes

public abstract UnsignedByte[] integerToBytes(int i)
Convert an integer to a byte array.

Parameters:
i - an 32-bit integer value
Returns:
an array of bytes that comprise the integer in address order according to the Endianness of the target ISA

length

public abstract int length()

read

public final UnsignedByte[] read(int address,
                                 int length)
                          throws AbstractMainMemory.InvalidAddressException
READ a sequence of bytes from memory starting at specified ALIGNED. An address is aligned if and only if the address modulo length is 0 (i.e., the low order log 2 (length) bits are 0.

Throws:
AbstractMainMemory.InvalidAddressException - if address is out of range or is not aligned.

write

public final void write(int address,
                        UnsignedByte[] value)
                 throws AbstractMainMemory.InvalidAddressException
WRITE a sequence of bytes to memory starting at specified ALIGNED. An address is aligned if and only if the address modulo value.length is 0 (i.e., the low order log 2 (value.length) bits are 0.

Throws:
AbstractMainMemory.InvalidAddressException - if address is out of range or is not aligned.

readUnaligned

public final UnsignedByte[] readUnaligned(int address,
                                          int length)
                                   throws AbstractMainMemory.InvalidAddressException
READ a sequence of bytes from memory starting at specified possibly-UNALIGNED address. An address is aligned if and only if the address modulo length is 0 (i.e., the low order log 2 (length) bits are 0. Unaligned memory access is, in real hardware, slower than aligned access and so clients should use the aligned read and write methods whenever possible.

Throws:
AbstractMainMemory.InvalidAddressException - if address is out of range.

writeUnaligned

public final void writeUnaligned(int address,
                                 UnsignedByte[] value)
                          throws AbstractMainMemory.InvalidAddressException
WRITE a sequence of bytes to memory starting at specified possibly-UNALIGNED address. An address is aligned if and only if the address modulo value.length is 0 (i.e., the low order log 2 (value.length) bits are 0. Unaligned memory access is, in real hardware, slower than aligned access and so clients should use the aligned read and write methods whenever possible.

Throws:
AbstractMainMemory.InvalidAddressException - if address is out of range.

readInteger

public int readInteger(int address)
                throws AbstractMainMemory.InvalidAddressException
Read a four-byte integer from memory at ALIGNED address.

Throws:
AbstractMainMemory.InvalidAddressException

writeInteger

public void writeInteger(int address,
                         int value)
                  throws AbstractMainMemory.InvalidAddressException
Throws:
AbstractMainMemory.InvalidAddressException

readIntegerUnaligned

public int readIntegerUnaligned(int address)
                         throws AbstractMainMemory.InvalidAddressException
Read a four-byte Big-Endian integer from memory at possibly UNALIGNED address. Unaligned memory access is, in real hardware, slower than aligned access and so clients should use the aligned read and write methods whenever possible.

Throws:
AbstractMainMemory.InvalidAddressException

writeIntegerUnaligned

public void writeIntegerUnaligned(int address,
                                  int value)
                           throws AbstractMainMemory.InvalidAddressException
Throws:
AbstractMainMemory.InvalidAddressException

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface DataModel
Overrides:
getColumnClass in class AbstractDataModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface DataModel
Overrides:
getColumnCount in class AbstractDataModel

getColumnName

public java.lang.String getColumnName(int columnIndex)
Specified by:
getColumnName in interface DataModel
Overrides:
getColumnName in class AbstractDataModel

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface DataModel
Overrides:
getRowCount in class AbstractDataModel

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Specified by:
getValueAt in interface DataModel
Overrides:
getValueAt in class AbstractDataModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface DataModel
Overrides:
isCellEditable in class AbstractDataModel

setValueAt

public void setValueAt(java.lang.Object[] aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface DataModel
Overrides:
setValueAt in class AbstractDataModel

setValueAtByUser

public void setValueAtByUser(java.lang.Object[] aValue,
                             int rowIndex,
                             int columnIndex)
Specified by:
setValueAtByUser in interface DataModel
Overrides:
setValueAtByUser in class AbstractDataModel

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface DataModel
Overrides:
setValueAt in class AbstractDataModel

setValueAtByUser

public void setValueAtByUser(java.lang.Object aValue,
                             int rowIndex,
                             int columnIndex)
Specified by:
setValueAtByUser in interface DataModel
Overrides:
setValueAtByUser in class AbstractDataModel

Simple Machine