com.cmpware.cmp
Class Memory

java.lang.Object
  extended by com.cmpware.cmp.Memory
All Implemented Interfaces:
ReadWriteInterface
Direct Known Subclasses:
Processor

public class Memory
extends java.lang.Object
implements ReadWriteInterface

This class implements the Processor's interface to memory. This class originally supplied the interface to a single main memory located at address 0. It is now responsible for managing the entire memory map. Currently this includes: local memories, memory mapped IO and shared memory. This should all be transparent; an address should be used to request a value, and a valid calue should be returned for a valid address. If the address is not valid, a Memory Access Exception should be thrown. In short, this class should make memory accesses behave in much the same way as they would in actual hardware.

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

Author:
SAG

Field Summary
static boolean BIG
          Big Endian
static java.lang.String copyright
          Copyright string
static boolean LITTLE
          Little Endian (default)
 
Constructor Summary
Memory()
          Constructor
Memory(int size)
          Constructor
 
Method Summary
 void addInput(int addr, MemoryMappedIOReader mmior)
          Deprecated. use mmio.addInput()
 void addMemory(MemoryInterface m)
          This method adds a Memory to the memory manager.
 void addOutput(int addr, MemoryMappedIOWriter mmiow)
          Deprecated. use mmio.addOutput()
 boolean getEndian()
          Deprecated. Use getLocalMemory().getEndian()
 LocalMemory getLocalMemory()
          This method returns the local memory.
 MemoryManager getMemoryManager()
          This method returns the memory manager.
 MemoryMappedIO getMmio()
          This method returns the Memory Mapped IO manager.
 int getProfile(int addr)
          This method returns the profile for a given a memory address.
 java.lang.String hexDump(int addr)
          This method returns a single text line of a hex dump starting at the specified address.
 java.lang.String hexDump(int addr, int lines)
          This method returns multiple text lines of a hex dump starting at the specified address.
 boolean isReadable(int addr)
          This method returns true if the current address is readable and false otherwise.
 boolean isValidAddress(int addr)
          This method returns true if the address is valid and false otherwise.
 boolean isWriteable(int addr)
          This method returns true if the current address is writeable and false otherwise.
 void profile(int addr)
          This method profiles a memory address.
 byte read(int addr)
          This method returns a byte from the memory at address 'addr'.
 byte[] read(int addr, int size)
          This method returns 'size' bytes from the memory at address 'addr'.
 short read16(int addr)
          This method returns a 16-bit short from the memory at address 'addr'.
 int read24(int addr)
          This method returns a 24-bit unsigned integer from the memory at address 'addr'.
 int read32(int addr)
          This method returns a 32-bit int from the memory at address 'addr'.
 long read64(int addr)
          This method returns a 64-bit long from the memory at address 'addr'.
 void removeMemory(MemoryInterface m)
          This method removes a bank of memory from the memory manager.
 void resize(int size)
          Deprecated. use getLocalMemory().resize(int)
 void setEndian(boolean e)
          Deprecated. Use getLocalMemory().setEndian(boolean)
 int size()
          Deprecated. use getLocalMemory().size()
 int toInt(byte[] b)
          This method converts a byte array to an integer.
 short toShort(byte[] b)
          This method converts a byte array to a short.
 void write(int addr, byte data)
          This method copies a byte from 'a' into the memory at address 'addr'.
 void write(int addr, byte[] buffer)
          This method copies a buffer of bytes from 'buffer' into the memory at address 'addr'.
 void write16(int addr, short data)
          This method writes the 16-bit value 'a' to the requested memory address.
 void write24(int addr, int data)
          This method writes a 24-bit value 'a' to the requested memory address.
 void write32(int addr, int data)
          This method writes the 32-bit value 'a' to the requested memory address.
 void write64(int addr, long data)
          This method writes the 64-bit value 'a' to the requested memory address.
 
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

BIG

public static final boolean BIG
Big Endian

See Also:
Constant Field Values

LITTLE

public static final boolean LITTLE
Little Endian (default)

See Also:
Constant Field Values
Constructor Detail

Memory

public Memory()
Constructor


Memory

public Memory(int size)
Constructor

Parameters:
size - The size of the memory in bytes
Method Detail

getLocalMemory

public LocalMemory getLocalMemory()
This method returns the local memory.

Returns:
This method returns the local memory.

getMmio

public MemoryMappedIO getMmio()
This method returns the Memory Mapped IO manager.

Returns:
This method returns the Memory Mapped IO manager.

getMemoryManager

public MemoryManager getMemoryManager()
This method returns the memory manager.

Returns:
This method returns the memory manager.

setEndian

public void setEndian(boolean e)
Deprecated. Use getLocalMemory().setEndian(boolean)

This method sets the endian of the local memory only. A value of 'LITTLE' indicates the default Little Endian and a value of 'BIG' indicates Big Endian.

Parameters:
e - The endian value. Should be "BIG" or "LITTLE".

getEndian

public boolean getEndian()
Deprecated. Use getLocalMemory().getEndian()

This method returns the endian of the memory accesses. A value of 'LITTLE' indicates the default Little Endian and a value of 'BIG' indicates Big Endian.

Returns:
This method returns the endian value. Should be "BIG" or "LITTLE".

resize

public void resize(int size)
Deprecated. use getLocalMemory().resize(int)

This method resizes the local memory. Any data in the old memory is lost.

Parameters:
size - The size of the new memory in bytes.

size

public int size()
Deprecated. use getLocalMemory().size()

This method returns the size of the local memory in bytes.

Returns:
This method returns the size of the local memory in bytes.

isValidAddress

public boolean isValidAddress(int addr)
This method returns true if the address is valid and false otherwise.

Parameters:
addr - The address.
Returns:
This method returns true if the address is valid and false otherwise.

profile

public void profile(int addr)
This method profiles a memory address. This address should be a valid memory address. If it is not, this method returns silently.

Parameters:
addr - The address.

getProfile

public int getProfile(int addr)
This method returns the profile for a given a memory address. This is the number of times the Program Counter has fetched an instruction from this address. Note that profiling is done by address blocks and not by individual addresses. This address should be a valid memory address. If it is not, this method returns zero.

Parameters:
addr - The address.
Returns:
the number of times this address range has been visited by the program is returned.

read

public byte[] read(int addr,
                   int size)
            throws MemoryAccessException
This method returns 'size' bytes from the memory at address 'addr'.

Parameters:
addr - The memory address.
size - The number of bytes to be read from memory.
Returns:
The requested data is returned.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

isReadable

public boolean isReadable(int addr)
Description copied from interface: ReadWriteInterface
This method returns true if the current address is readable and false otherwise.

Specified by:
isReadable in interface ReadWriteInterface
Parameters:
addr - the address
Returns:
This method returns true if the current address is readable and false otherwise.

isWriteable

public boolean isWriteable(int addr)
Description copied from interface: ReadWriteInterface
This method returns true if the current address is writeable and false otherwise.

Specified by:
isWriteable in interface ReadWriteInterface
Parameters:
addr - the address
Returns:
This method returns true if the current address is writeable and false otherwise.

read

public byte read(int addr)
          throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a byte from the memory at address 'addr'.

Specified by:
read in interface ReadWriteInterface
Parameters:
addr - The memory address.
Returns:
The requested data is returned.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

read16

public short read16(int addr)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a 16-bit short from the memory at address 'addr'.

Specified by:
read16 in interface ReadWriteInterface
Parameters:
addr - The memory address.
Returns:
The requested data is returned from the memory.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

read24

public int read24(int addr)
           throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a 24-bit unsigned integer from the memory at address 'addr'. The value is returned as a 32-bit int, with the upper 8 bits always zero.

Specified by:
read24 in interface ReadWriteInterface
Parameters:
addr - The memory address.
Returns:
The requested data is returned from the memory.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

read32

public int read32(int addr)
           throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a 32-bit int from the memory at address 'addr'. Note that this method also attempts a Memory Mapped IO if an illegal memory address is encountered.

Specified by:
read32 in interface ReadWriteInterface
Parameters:
addr - The memory address.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

read64

public long read64(int addr)
            throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method returns a 64-bit long from the memory at address 'addr'.

Specified by:
read64 in interface ReadWriteInterface
Parameters:
addr - The memory address.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write

public void write(int addr,
                  byte[] buffer)
           throws MemoryAccessException
This method copies a buffer of bytes from 'buffer' into the memory at address 'addr'.

Parameters:
addr - The memory address.
buffer - The data to be written to the memory.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write

public void write(int addr,
                  byte data)
           throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method copies a byte from 'a' into the memory at address 'addr'.

Specified by:
write in interface ReadWriteInterface
Parameters:
addr - The memory address.
data - The data to be written to the memory.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write16

public void write16(int addr,
                    short data)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method writes the 16-bit value 'a' to the requested memory address.

Specified by:
write16 in interface ReadWriteInterface
Parameters:
addr - The memory address.
data - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write24

public void write24(int addr,
                    int data)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method writes a 24-bit value 'a' to the requested memory address. The upper 8 bits of the value of 'a' are always ignored.

Specified by:
write24 in interface ReadWriteInterface
Parameters:
addr - The memory address.
data - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write32

public void write32(int addr,
                    int data)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method writes the 32-bit value 'a' to the requested memory address.

Specified by:
write32 in interface ReadWriteInterface
Parameters:
addr - The memory address.
data - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write64

public void write64(int addr,
                    long data)
             throws MemoryAccessException
Description copied from interface: ReadWriteInterface
This method writes the 64-bit value 'a' to the requested memory address.

Specified by:
write64 in interface ReadWriteInterface
Parameters:
addr - The memory address.
data - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

hexDump

public java.lang.String hexDump(int addr)
This method returns a single text line of a hex dump starting at the specified address. If the address is out of range, an empty string is returned.

Parameters:
addr - The address of the memory to be dumped. Will be aligned to a 16 byte boundary.
Returns:
This method returns a single text line of a hex dump starting at the specified address. If the address is out of range, an empty string is returned.

hexDump

public java.lang.String hexDump(int addr,
                                int lines)
This method returns multiple text lines of a hex dump starting at the specified address. If the address goes out of range, the partial dump of the legal addresses is returned.

Parameters:
addr - The address of the memory to be dumped. Will be aligned to a 16 byte boundary.
lines - The number of lines of hex dump to return.
Returns:
This method returns multiple text lines of a hex dump starting at the specified address. If the address goes out of range, the partial dump of the legal addresses is returned.

toInt

public int toInt(byte[] b)
This method converts a byte array to an integer. The array should have no more than four items, or the result is undefined.

Parameters:
b - The byte array.
Returns:
This method returns the byte array b converted into an integer.

toShort

public short toShort(byte[] b)
This method converts a byte array to a short. The array should have exactly two items, or the result is undefined.

Parameters:
b - The byte array.
Returns:
This method returns the byte array b converted into a short.

addInput

public void addInput(int addr,
                     MemoryMappedIOReader mmior)
Deprecated. use mmio.addInput()

This method adds a Memory Mapped IO Reader interface to the memory mapped IO. If a Memory Mapped IO Reader already exists at this address, it is replaced.

Parameters:
addr - the address of the Memory Mapped IO Input port.
mmior - The Memory Mapped IO reader.

addOutput

public void addOutput(int addr,
                      MemoryMappedIOWriter mmiow)
Deprecated. use mmio.addOutput()

This method adds a Memory Mapped IO Writer interface to the memory mapped IO. If a Memory Mapped IO Writer already exists at this address, it is replaced.

Parameters:
addr - the address of the Memory Mapped IO Output port.
mmiow - The Memroy Mapped IO writer.

addMemory

public void addMemory(MemoryInterface m)
This method adds a Memory to the memory manager. These are typically Local Memories for use within a single processing node or Shared Memories which are added to more than one (but usually just two) processing nodes. Note that Local Memories may be mapped to multiple processing nodes, but proper synchronization is not provided and correct operating is not guaranteed. Also note that no checking of consistency of the memory map is performed. Results from overlapping memory objects is undefined. Also note that this is the same as getMemoryManager().add(m).

Parameters:
m - The memory being added.

removeMemory

public void removeMemory(MemoryInterface m)
This method removes a bank of memory from the memory manager.

Parameters:
m - The memory being removed.