com.cmpware.cmp.memory
Class LittleEndianMemory

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

public class LittleEndianMemory
extends java.lang.Object
implements MemoryInterface

This class implements the Little Endian memory module.

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

Author:
SAG

Field Summary
protected  int baseAddr
          The base address
static java.lang.String copyright
          Copyright string
protected static int DEFAULT_MEMORY_SIZE
          The default memory size (in bytes)
protected  int maxProfile
          The largest value in the profile table
protected  byte[] memory
          The memory
protected  int[] profile
          The profile data
protected static int PROFILE_GRANULARITY
          The granularity of the profile (in bytes)
 
Constructor Summary
LittleEndianMemory()
          Constructor
LittleEndianMemory(byte[] b)
          Constructor
LittleEndianMemory(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 (byte order) of the memory.
 int getMaxProfile()
          This method returns the largest value currently in the profile table.
protected  int getOffset(int addr)
          This method takes an address and converts it into and offset into the array used to represent the memory.
 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 endian)
          This method sets the endian (byte order) of the memory.
 int size()
          This method returns the size of the memory.
 void write(int addr, byte data)
          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

baseAddr

protected int baseAddr
The base address


DEFAULT_MEMORY_SIZE

protected static final int DEFAULT_MEMORY_SIZE
The default memory size (in bytes)

See Also:
Constant Field Values

memory

protected byte[] memory
The memory


profile

protected int[] profile
The profile data


maxProfile

protected int maxProfile
The largest value in the profile table


PROFILE_GRANULARITY

protected static final int PROFILE_GRANULARITY
The granularity of the profile (in bytes)

See Also:
Constant Field Values
Constructor Detail

LittleEndianMemory

public LittleEndianMemory()
Constructor


LittleEndianMemory

public LittleEndianMemory(int size)
Constructor

Parameters:
size - The size of the memory in bytes

LittleEndianMemory

public LittleEndianMemory(byte[] b)
Constructor

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

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.

getEndian

public boolean getEndian()
Description copied from interface: MemoryInterface
This method returns the endian (byte order) of the memory.

Specified by:
getEndian in interface MemoryInterface
Returns:
This method returns the endian (byte order) of the memory.

setEndian

public void setEndian(boolean endian)
Description copied from interface: MemoryInterface
This method sets the endian (byte order) of the memory.

Specified by:
setEndian in interface MemoryInterface
Parameters:
endian - The endian (either Memory.BIG or Memory.LITTLE).

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.

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.

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

getOffset

protected int getOffset(int addr)
This method takes an address and converts it into and offset into the array used to represent the memory. Note that the Base Address is stored as a 64-bit long, since Java does not support unsigned integers. This keeps addresses greater than 0x80000000 from being interpreted as a negative number.

Parameters:
addr - The address.
Returns:
This method takes the address and converts it into an offset in the array representing the memory.