avrora.core
Class Program.Impression

java.lang.Object
  extended byavrora.core.Program.Impression
Enclosing class:
Program

public class Program.Impression
extends java.lang.Object

The Impression class represents a copy of the program that is suitable for reading and writing during execution without changing the underlying program. This is used in the Simulator class to make a private copy of the program so that multiple instances of the program do not interfere with each other. It basically amounts to a deep copy of the instructions and data in the program segment.

This class is meant as a point to do smart code sharing between multiple instances of the program so that better scalability can be achieved.

See Also:
Simulator

Method Summary
 Instr readInstr(int address)
          The readInstr() method reads the instruction at the given byte address.
 byte readProgramByte(int address)
          The readProgramByte() method reads a single byte value from the program (code) segment.
 void writeInstr(Instr i, int address)
          The writeInstr() method is used to update an instruction at a particular address in memory.
 void writeProgramByte(byte val, int address)
          The writeProgramByte() method writes a single byte value to the program (code) segment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readProgramByte

public byte readProgramByte(int address)
The readProgramByte() method reads a single byte value from the program (code) segment.

Parameters:
address - the byte address to read the value from
Returns:
the current value of that program location if that program location is within the valid memory space; 0 otherwise

writeProgramByte

public void writeProgramByte(byte val,
                             int address)
The writeProgramByte() method writes a single byte value to the program (code) segment. This write may overwrite instructions within the program. NO EFFORT IS MADE BY THIS CLASS TO ENSURE CONSISTENCY OF THE INSTRUCTIONS. THEREFORE SELF MODIFYING CODE DOES NOT BEHAVE CORRECTLY.

Parameters:
val - the value to write to the location
address - the byte address in the program segment to write the value to

readInstr

public Instr readInstr(int address)
The readInstr() method reads the instruction at the given byte address. No attempt to disassemble raw data into usable instructions is made, and unaligned accesses will return null. SELF MODIFYING CODE DOES NOT BEHAVE CORRECTLY NOR DOES ATTEMPTING TO EXECUTE DATA AS CODE.

Parameters:
address - the byte address in the program segment to read from
Returns:
the Instr instance at that address if that address is valid code from creation of the Program instance; an instance of Instr.NOP if the address is beyond valid memory; null if the instruction is misaligned or only raw data is present at that location.

writeInstr

public void writeInstr(Instr i,
                       int address)
The writeInstr() method is used to update an instruction at a particular address in memory. The address is given as a byte address but is expected to be aligned on a 2-byte boundary. This is generally used by the Simulator to insert probes on instructions, but could be used to achieve self-modifying code.

Parameters:
i - the instruction to write
address - the byte address to write the instruction that must be aligned on a 2-byte boundary.