com.cmpware.cmp.links
Class SharedRegister

java.lang.Object
  extended by com.cmpware.cmp.Link
      extended by com.cmpware.cmp.links.SharedRegister
All Implemented Interfaces:
MemoryMappedIOReader, MemoryMappedIOWriter
Direct Known Subclasses:
CellBE_SharedRegister

public class SharedRegister
extends Link

This class implements a shared register. This is a single register which has a semaphored read / write. This register may be mapped to a memory address or to a special instruction in the processor. To better support a multiprocessor communication environment, this shared registers have some specific properties. First, the register uses hardware semaphores. A write sets the the semaphore and a read clears it. Methods are provided to see if registers are currently readable / writable. This lets reliable, synchronized communication to be performed via these registers. Finally, all data written to registers is "shadowed" until a "commit" call is made. This is necessary in multiprocessor simulation environments to assure that proper clock boundaries are preserved.

Copyright (c) 2004 Cmpware, Inc. All Rights Reserved.

Author:
SAG

Field Summary
static java.lang.String copyright
          Copyright string
protected  MemoryMappedIOException mmioe
          A Shared Register Execption (so we don't have to keep re-allocating them)
protected  int readAddr
          The read address (for information only)
protected  int readCount
          The number of reads
protected  int readStallCount
          The number of read stalls
protected  long shreg
          The shared register
protected  long shregShadow
          The shared shadow registers
protected  int writeAddr
          The write address (for information only)
protected  int writeCount
          The number of writes
protected  int writeStallCount
          The number of write stalls
 
Constructor Summary
SharedRegister()
           
 
Method Summary
protected  long clear(long i)
          This method clears a semaphore in a register value.
 int getReadAddress()
          This method returns the processor address to which the read port of this Memory Mapped IO is mapped.
 int getReadCount()
          This method returns the number of times the read port has been accessed.
 int getReadStallCount()
          This method returns the number of times the read port has stalled.
 int getValue()
          This method returns the most recently written value of the Memory Mapped IO.
 int getWriteAddress()
          This method returns the processor address to which the write port of this Memory Mapped IO is mapped.
 int getWriteCount()
          This method returns the number of times the write port has been accessed.
 int getWriteStallCount()
          This method returns the number of times the write port has stalled.
 boolean isReadable()
          This method returns a true if the Memory Mapped IO is currently readable.
protected  boolean isSet(long i)
          This method tests to see if the semaphore for the register is set.
 boolean isWriteable()
          This method returns a true if the Memory Mapped IO port is currently writeable.
 int read()
          This method reads a value from the Memory Mapped IO port.
 void readCommit()
          All Memory Mapped IO reads are performed whenever data is available.
 void reset()
          This abstract class is used to reset the link.
protected  long set(long i)
          This method sets a semaphore in a register value.
 void setReadAddress(int addr)
          This method sets the read address of the Memeory Mapped IO.
 void setWriteAddress(int addr)
          This method sets the write address of the Memory Mapped IO.
 void write(int val)
          This method writes a word to the Memory Mapped IO.
 void writeCommit()
          All Memory Mapped IO writes are performed whenever data is available.
 
Methods inherited from class com.cmpware.cmp.Link
get, setBufferSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyright

public static final java.lang.String copyright
Copyright string

See Also:
Constant Field Values

shreg

protected long shreg
The shared register


shregShadow

protected long shregShadow
The shared shadow registers


readAddr

protected int readAddr
The read address (for information only)


writeAddr

protected int writeAddr
The write address (for information only)


readCount

protected int readCount
The number of reads


writeCount

protected int writeCount
The number of writes


readStallCount

protected int readStallCount
The number of read stalls


writeStallCount

protected int writeStallCount
The number of write stalls


mmioe

protected MemoryMappedIOException mmioe
A Shared Register Execption (so we don't have to keep re-allocating them)

Constructor Detail

SharedRegister

public SharedRegister()
Method Detail

reset

public void reset()
Description copied from interface: MemoryMappedIOReader
This abstract class is used to reset the link. This may be necessary in links that have state.


write

public void write(int val)
           throws MemoryMappedIOException
Description copied from interface: MemoryMappedIOWriter
This method writes a word to the Memory Mapped IO.

Parameters:
val - The value to write to the Memory Mapped IO.
Throws:
MemoryMappedIOException - - this method throws a MemoryMappedIOException if the write could not be completed on this cycle. This will typically cause a stall of the processor and a retry on the next cycle.

read

public int read()
         throws MemoryMappedIOException
Description copied from interface: MemoryMappedIOReader
This method reads a value from the Memory Mapped IO port.

Returns:
This method reads a value from the Memory mapped IO port.
Throws:
MemoryMappedIOException - - this method throws a MemoryMappedIOException if the read could not be completed on this cycle. This will typically cause a stall of the processor and a retry on the next cycle.

writeCommit

public void writeCommit()
Description copied from interface: MemoryMappedIOWriter
All Memory Mapped IO writes are performed whenever data is available. But because this is a multiprocessor simulation environment, it may not be proper to flag this communication resource as "free" until the end of the simulation cycle. This is necessary to preserve clock boundaries in multiprocessor simulation environments. This method should be called at the end of all activity in a simulation cycle and should tag the resource as free as necessary.


readCommit

public void readCommit()
Description copied from interface: MemoryMappedIOReader
All Memory Mapped IO reads are performed whenever data is available. But because this is a multiprocessor simulation environment, it may not be proper to flag this communication resource as "free" until the end of the simulation cycle. This is necessary to preserve clock boundaries in multiprocessor simulation environments. This method should be called at the end of all activity in a simulation cycle and should tag the resource as free as necessary.


setReadAddress

public void setReadAddress(int addr)
Description copied from interface: MemoryMappedIOReader
This method sets the read address of the Memeory Mapped IO. Note that is only provides the adddress value for convenience when displaying Memory Mapped IO status information. This does not effect how the Memory Mapped IO is decoded.

Parameters:
addr - The Memory Mapped IO read address.

getReadAddress

public int getReadAddress()
Description copied from interface: MemoryMappedIOReader
This method returns the processor address to which the read port of this Memory Mapped IO is mapped.

Returns:
This method returns the processor address to which the read port of this Memory Mapped IO is mapped.

getReadCount

public int getReadCount()
Description copied from interface: MemoryMappedIOReader
This method returns the number of times the read port has been accessed.

Returns:
This method returns the number of times the read port has been accessed.

getReadStallCount

public int getReadStallCount()
Description copied from interface: MemoryMappedIOReader
This method returns the number of times the read port has stalled.

Returns:
This method returns the number of times the read port has stalled.

setWriteAddress

public void setWriteAddress(int addr)
Description copied from interface: MemoryMappedIOWriter
This method sets the write address of the Memory Mapped IO. Note that is only provides the adddress value for convenience when displaying Memory Mapped IO information. This does not effect how the Memory Mapped IO port is decoded.

Parameters:
addr - The Memory Mapped IO write address.

getWriteAddress

public int getWriteAddress()
Description copied from interface: MemoryMappedIOWriter
This method returns the processor address to which the write port of this Memory Mapped IO is mapped.

Returns:
This method returns the processor address to which the write port of this Memory Mapped IO is mapped.

getWriteCount

public int getWriteCount()
Description copied from interface: MemoryMappedIOWriter
This method returns the number of times the write port has been accessed.

Returns:
This method returns the number of times the write port has been accessed.

getWriteStallCount

public int getWriteStallCount()
Description copied from interface: MemoryMappedIOWriter
This method returns the number of times the write port has stalled.

Returns:
This method returns the number of times the write port has stalled.

getValue

public int getValue()
Description copied from interface: MemoryMappedIOReader
This method returns the most recently written value of the Memory Mapped IO. Note that this value may or may not have already been read.

Returns:
This method returns the most recently written value of the Memory Mapped IO. Note that this value may or may not have already been read.

isReadable

public boolean isReadable()
Description copied from interface: MemoryMappedIOReader
This method returns a true if the Memory Mapped IO is currently readable. A false is returned otherwise.

Returns:
This method returns a true if the Memory Mapped IO is currently readable. A false is returned otherwise.

isWriteable

public boolean isWriteable()
Description copied from interface: MemoryMappedIOWriter
This method returns a true if the Memory Mapped IO port is currently writeable. A false is returned otherwise.

Returns:
This method returns a true if the Memory Mapped IO port is currently writeable. A false is returned otherwise.

isSet

protected boolean isSet(long i)
This method tests to see if the semaphore for the register is set. If it is set a true is returned, otherwise a false is returned.

Returns:
This method tests to see if the semaphore for a register is set. If it is set a true is returned, otherwise a false is returned.

set

protected long set(long i)
This method sets a semaphore in a register value.

Parameters:
i - The value on which to set the semaphore.
Returns:
The value of the input paramater i with its semaphore set.

clear

protected long clear(long i)
This method clears a semaphore in a register value.

Parameters:
i - The value on which to clear the semaphore.
Returns:
The value of the input paramater i with its semaphore cleared.