com.cmpware.cmp.memory
Class LocalMemory

java.lang.Object
  extended by com.cmpware.cmp.memory.LocalMemory
All Implemented Interfaces:
MemoryInterface, ReadWriteInterface
Direct Known Subclasses:
SharedMemory

public class LocalMemory
extends java.lang.Object
implements MemoryInterface

This class implements the Local Memory. It implements the standard Memory Interface, but permits the Endian to be changed.

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
LocalMemory()
          Constructor
LocalMemory(byte[] b)
          Constructor
LocalMemory(int size)
          Constructor
 
Method Summary
 void clearProfile()
          This method clears the profile table.
 byte[] get()
          This method returns the byte array used to represent the memory.
 int getBaseAddress()
          This method returns the current base address of the memory.
 boolean getEndian()
          This method returns the endian of the memory accesses.
 int getMaxProfile()
          This method returns the largest value currently in the profile table.
 int[] getProfile()
          This method returns the current memory access profile data as an array of integers.
 int getProfile(int addr)
          This method returns the number of times an address has been visited by the Program Counter.
 int getProfileGranularity()
          This method returns the profile granularity.
 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 increments the profile count for a particular address.
 byte read(int addr)
          This method returns a byte 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 resize(int size)
          This method resizes the memory array.
 void setBaseAddress(int baseAddr)
          This method sets the base address of the memory.
 void setEndian(boolean e)
          This method sets the endian of the memory accesses.
 int size()
          This method returns the size of the memory.
 void write(int addr, byte a)
          This method copies a byte from 'a' into the memory at address 'addr'.
 void write16(int addr, short a)
          This method writes the 16-bit value 'a' to the requested memory address.
 void write24(int addr, int a)
          This method writes a 24-bit value 'a' to the requested memory address.
 void write32(int addr, int a)
          This method writes the 32-bit value 'a' to the requested memory address.
 void write64(int addr, long a)
          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

LocalMemory

public LocalMemory()
Constructor


LocalMemory

public LocalMemory(int size)
Constructor

Parameters:
size - The size of the memory in bytes

LocalMemory

public LocalMemory(byte[] b)
Constructor

Parameters:
b - The byte array used as the memory store.
Method Detail

setEndian

public void setEndian(boolean e)
This method sets the endian of the memory accesses. A value of 'LITTLE' indicates the default Little Endian and a value of 'BIG' indicates Big Endian.

Specified by:
setEndian in interface MemoryInterface
Parameters:
e - The endian value. Should be "BIG" or "LITTLE".

getEndian

public boolean 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.

Specified by:
getEndian in interface MemoryInterface
Returns:
This method returns the endian value. Should be "BIG" or "LITTLE".

setBaseAddress

public void setBaseAddress(int baseAddr)
Description copied from interface: MemoryInterface
This method sets the base address of the memory. The default base address is zero.

Specified by:
setBaseAddress in interface MemoryInterface
Parameters:
baseAddr - The base address.

getBaseAddress

public int getBaseAddress()
Description copied from interface: MemoryInterface
This method returns the current base address of the memory.

Specified by:
getBaseAddress in interface MemoryInterface
Returns:
This method returns the current base address of the memory.

get

public byte[] get()
Description copied from interface: MemoryInterface
This method returns the byte array used to represent the memory.

Specified by:
get in interface MemoryInterface
Returns:
This method returns the byte array used to represent the memory.

resize

public void resize(int size)
Description copied from interface: MemoryInterface
This method resizes the memory array. Any data in the old memory array is lost.

Specified by:
resize in interface MemoryInterface
Parameters:
size - The size of the new memory array in bytes.

size

public int size()
Description copied from interface: MemoryInterface
This method returns the size of the memory.

Specified by:
size in interface MemoryInterface
Returns:
This method returns the size of the memory.

isValidAddress

public boolean isValidAddress(int addr)
Description copied from interface: MemoryInterface
This method returns true if the address is valid and false otherwise.

Specified by:
isValidAddress in interface MemoryInterface
Parameters:
addr - The address.
Returns:
This method returns true if the address is valid and false otherwise.

getProfile

public int[] getProfile()
Description copied from interface: MemoryInterface
This method returns the current memory access profile data as an array of integers. Each integer in the array represents the number of accesses in a fixed, aligned range of addresses of size getProfileGranularity().

Specified by:
getProfile in interface MemoryInterface
Returns:
This method returns the current memory access profile data as an array of integers.

profile

public void profile(int addr)
Description copied from interface: MemoryInterface
This method increments the profile count for a particular address.

Specified by:
profile in interface MemoryInterface
Parameters:
addr - The address.

getProfile

public int getProfile(int addr)
Description copied from interface: MemoryInterface
This method returns the number of times an address has been visited by the Program Counter.

Specified by:
getProfile in interface MemoryInterface
Parameters:
addr - The address.
Returns:
This method returns the number of times an address has been visited by the Program Counter.

getProfileGranularity

public int getProfileGranularity()
Description copied from interface: MemoryInterface
This method returns the profile granularity. This is the size, in bytes, of the fixed, aligned address range tracked. The size of the profile data array is the size of the memory array in bytes divided by the profile granularity.

Specified by:
getProfileGranularity in interface MemoryInterface
Returns:
This method returns the profile granularity.

clearProfile

public void clearProfile()
Description copied from interface: MemoryInterface
This method clears the profile table.

Specified by:
clearProfile in interface MemoryInterface

getMaxProfile

public int getMaxProfile()
Description copied from interface: MemoryInterface
This method returns the largest value currently in the profile table.

Specified by:
getMaxProfile in interface MemoryInterface
Returns:
This method returns the largest value currently in the profile table.

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 a)
           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.
a - The data to be written to the memory.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write16

public void write16(int addr,
                    short a)
             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.
a - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write24

public void write24(int addr,
                    int a)
             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.
a - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write32

public void write32(int addr,
                    int a)
             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.
a - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.

write64

public void write64(int addr,
                    long a)
             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.
a - The value to be written.
Throws:
MemoryAccessException - if an illegal memory address is encountered.