jfrace
Class AddressSpace

java.lang.Object
  |
  +--jfrace.AddressSpace

public class AddressSpace
extends java.lang.Object

The address space is the backbone of the framework. CPU's and devices know from each other due to the address space. It is similar to the bus in a computer system. An address can be any non-negative integer below 231.

The address space is organized in non-overlapping address banks. An address bank is defined when a Device is attached (by the method addDevice) to a certain address. The size of the Device (obtained by the method Device.getNumberOfUnits()) defines the size of the address bank. For Reading and writing the invokation of the methods getValue(int, int)/getByte(int, int) and setValue(int, int, int)/setByte(int, int, byte), resp., are redirected to the corresponding methods of Device. Usually CPUs will call these methods. Reading from or writing to an address outside any address bank may lead to a BusErrorException.

Also a CPU can be added to an address (by the method addCPU(int, jfrace.CPU)). CPU's are stored in a list. Devices interested in invoking an interrupt on a CPU can get the corresponding instance with the method getCPU(int).

Devices and CPU's (i.e., any Hardware) can be removed from the AddressSpace. If a Hardware is added or removed all subscribed AddressSpaceListener will be notified.

Author:
Franz-Josef Elmer

Constructor Summary
AddressSpace()
          Default constructor.
AddressSpace(int aDefaultValue)
          Constructor defining the default value which is returned when no address bank could be found in an access due to the getValue(int, int) or getByte(int, int) method.
 
Method Summary
 void addAddressSpaceListener(AddressSpaceListener asl)
          Add an AddressSpaceListener.
 void addCPU(int anAddressOffset, CPU aCpu)
          Add a CPU.
 void addDevice(int firstAddress, int modeMask, Device device)
          Add a new device and thereby define a new address bank.
 byte getByte(int anAddress, int mode)
          Get the byte at the given address.
 CPU getCPU(int index)
          Return the CPU for the given index.
 int getCPUAddressOffset(int index)
          Return the address offset for the CPU of given index.
 Device getDevice(int index)
          Return the device of a given address bank.
 int getFirstAddress(int index)
          Return the first address of a given address bank.
 int getLastAddress(int index)
          Return the address just following the last address of a given address bank.
 int getModeMask(int index)
          Return the mode mask of a given address bank.
 int getNumberOfAddressBanks()
          Return the number of address banks.
 int getNumberOfCPUs()
          Return the number of attached CPUs.
 int getValue(int anAddress, int mode)
          Get the value of the addressable unit at the given address.
 void removeAddressSpaceListener(AddressSpaceListener asl)
          Remove an AddressSpaceListener.
 void removeCPU(CPU aCpu)
          Remove a CPU.
 void removeDevice(Device device)
          Remove a device and the associated address bank.
 void setByte(int anAddress, int mode, byte value)
          Set the byte at the given address.
 void setValue(int anAddress, int mode, int value)
          Set the value of the addressable unit at the given address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AddressSpace

public AddressSpace()
Default constructor. Identical with AddressSpace(0).

AddressSpace

public AddressSpace(int aDefaultValue)
Constructor defining the default value which is returned when no address bank could be found in an access due to the getValue(int, int) or getByte(int, int) method.
Parameters:
aDefaultValue - Default value for nonsuccessful access.
Method Detail

addAddressSpaceListener

public void addAddressSpaceListener(AddressSpaceListener asl)
Add an AddressSpaceListener. Does nothing if already in the list.
Parameters:
asl - A new AddressSpaceListener.

removeAddressSpaceListener

public void removeAddressSpaceListener(AddressSpaceListener asl)
Remove an AddressSpaceListener.
Parameters:
asl - AddressSpaceListener to be removed.

getNumberOfAddressBanks

public int getNumberOfAddressBanks()
Return the number of address banks.

getFirstAddress

public int getFirstAddress(int index)
Return the first address of a given address bank.
Parameters:
index - Index of an address bank.

getLastAddress

public int getLastAddress(int index)
Return the address just following the last address of a given address bank.
Parameters:
index - Index of address bank.

getModeMask

public int getModeMask(int index)
Return the mode mask of a given address bank.
Parameters:
index - Index of address bank.

getDevice

public Device getDevice(int index)
Return the device of a given address bank.
Parameters:
index - Index of address bank.

addDevice

public void addDevice(int firstAddress,
                      int modeMask,
                      Device device)
               throws AddressBankOverlapException,
                      java.lang.IllegalArgumentException
Add a new device and thereby define a new address bank. Inform interested AddressSpaceListeners.
Parameters:
firstAddress - First address of the added address bank.
modeMask - Mask for checking the access mode.
device - Device to be added.
Throws:
AddressBankOverlapException - if an overlap with an already existing address bank has been detected.
java.lang.IllegalArgumentException - if firstAddress < 0 or device.numberOfUnits() <= 0.

removeDevice

public void removeDevice(Device device)
Remove a device and the associated address bank. Does nothing if given device is not attached to this AddressSpace. Interested AddressSpaceListeners will be informed.
Parameters:
device - Device to be removed.

getNumberOfCPUs

public int getNumberOfCPUs()
Return the number of attached CPUs.

getCPU

public CPU getCPU(int index)
Return the CPU for the given index.

getCPUAddressOffset

public int getCPUAddressOffset(int index)
Return the address offset for the CPU of given index.

addCPU

public void addCPU(int anAddressOffset,
                   CPU aCpu)
Add a CPU. Interested AddressSpaceListeners will be informed.
Parameters:
anAddressOffset - Address offset.
aCpu - CPU which will be added.

removeCPU

public void removeCPU(CPU aCpu)
Remove a CPU. Does nothing if given CPU is not attached to this AddressSpace. Interested AddressSpaceListeners will be informed.
Parameters:
aCpu - CPU to be removed.

getValue

public final int getValue(int anAddress,
                          int mode)
                   throws BusErrorException
Get the value of the addressable unit at the given address. If the addressable unit is a byte getByte(int, int) should be be used.
Parameters:
anAddress - Address in the address space.
mode - Access mode.
Returns:
the value.
Throws:
BusErrorException - will be thrown if mode > 0 and mode masked with the modeMask attribute of the address bank yields zero.

setValue

public final void setValue(int anAddress,
                           int mode,
                           int value)
                    throws BusErrorException
Set the value of the addressable unit at the given address. If the addressable unit is a byte setByte(int, int, byte) should be be used.
Parameters:
anAddress - Address in the address space.
mode - Access mode.
value - Value.
Throws:
BusErrorException - will be thrown if mode > 0 and mode masked with the modeMask attribute of the address bank yields zero.

getByte

public final byte getByte(int anAddress,
                          int mode)
                   throws BusErrorException
Get the byte at the given address. This method is similar getValue(int, int) but has a better performance.
WARNING: This method should be used only when the addressable unit is a byte.
Parameters:
anAddress - Address in the address space.
mode - Access mode.
Returns:
the value.
Throws:
BusErrorException - will be thrown if mode > 0 and mode masked with the modeMask attribute of the address bank yields zero.

setByte

public final void setByte(int anAddress,
                          int mode,
                          byte value)
                   throws BusErrorException
Set the byte at the given address. This method is similar to setValue(int, int, int) but has a better performance.
WARNING: This method should be used only when the addressable unit is a byte.
Parameters:
anAddress - Address in the address space.
mode - Access mode.
value - Value.
Throws:
BusErrorException - will be thrown if mode > 0 and mode masked with the modeMask attribute of the address bank yields zero.