Interface MemoryContext<CellType>

Type Parameters:
CellType - memory cell type
All Superinterfaces:
Context
All Known Implementing Classes:
AbstractMemoryContext

public interface MemoryContext<CellType> extends Context
Memory context

It provides the basic memory functionality, such as reading/writing memory cells. The memory cell can be of any Java type, thus a "byte", as the lowest addressable unit, is not enforced.

The memory context must be extended in a memory plugin in order to support additional functionality.

  • Method Details

    • read

      CellType read(int location)
      Reads one memory cell at given location.
      Parameters:
      location - memory location of the memory cell
      Returns:
      cell at given location
    • peek

      default CellType peek(int location)
      Inspect a CPU-visible cell without guest timing, device effects, or access events. Pure memory uses its ordinary read; providers with execution side effects must override this operation. The provider resolves the same address mapping as read(int).
      Parameters:
      location - CPU-visible cell address
      Returns:
      currently mapped cell
    • read

      CellType[] read(int location, int count)
      Reads one or more adjacent cells from a memory.

      Implementation of return value is up to plugin programmer (e.g. ordering of cells or atomicity). If cells in memory are pure bytes, concatenation can be realized as (in small endian):

      
      result = (mem[from]&0xFF) | ((mem[from+1]<<8)&0xFF) | ...;
      
      

      and in big endian as:

      
      result = ((mem[from]<<(count *8 ))&0xFF) | (mem[from+1]<<((count-1)*8)&0xFF) | ...;
      
      

      If memory size is smaller than (location + count), then only available cells are returned - returned array size can be less than count.

      Parameters:
      location - location of the first cell
      count - number of cells to read
      Returns:
      array of cells at given location
      Throws:
      RuntimeException - if memory size is smaller than (location + count)
    • write

      void write(int location, CellType value)
      Write a value to a memory cell at given location.
      Parameters:
      location - location of the cell
      value - data to be written
    • write

      void write(int location, CellType[] values, int count)
      Write several cell values at once to a given location. The ordering of values, as well as atomicity is implementation-specific.
      Parameters:
      location - location of the first cell
      values - data to be written
      count - number of values taken from given array
      Throws:
      RuntimeException - if memory size is less than (location + count) or if (count > values.length) or if (count < 0)
    • write

      default void write(int location, CellType[] values)
      Write several cell values at once to a given location. The ordering of values, as well as atomicity is implementation-specific.
      Parameters:
      location - location of the first cell
      values - data to be written
      Throws:
      RuntimeException - if memory size is less than (location + count)
    • getCellTypeClass

      Class<CellType> getCellTypeClass()
      Get memory cell type class.
      Returns:
      Java data type of memory cells
    • clear

      void clear()
      Clears the memory content.
    • getSize

      int getSize()
      Get memory size

      A memory size is basically a number of cells.

      Its interpretation is defined by the implementing memory.

      Returns:
      memory size (number of cells)
    • addMemoryListener

      void addMemoryListener(MemoryContext.MemoryListener listener)
      Adds a memory listener
      Parameters:
      listener - the memory listener (non-null)
    • removeMemoryListener

      void removeMemoryListener(MemoryContext.MemoryListener listener)
      Removes a memory listener
      Parameters:
      listener - the memory listener to be removed (non-null)
    • setMemoryNotificationsEnabled

      void setMemoryNotificationsEnabled(boolean enabled)
      Enable/disable notifications of memory changes globally.

      Enabled by default. Usually it is disabled by CPU when in a "running" state.

      Parameters:
      enabled - - true if enabled, false if disabled.
    • areMemoryNotificationsEnabled

      boolean areMemoryNotificationsEnabled()
      Determine if notifications of memory changes are globally enabled or disabled.
      Returns:
      true if notifications are enabled, false if disabled.