Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## avrora.sim
Class State

    java.lang.Object
      avrora.sim.State

All Implemented Interfaces:
  IORegisterConstants

public class State
extends java.lang.Object
implements IORegisterConstants

The `State` class represents the state of the simulator, including the contents of registers and memory.

Nested Class Summary
`static interface` | `State.IOReg` The `IOReg` interface models the behavior of an IO register.
`static class` | `State.RWIOReg` The `RWIOReg` class is an implementation of an IO register that has the simple, default behavior of being able to read and write just as a general purpose register or byte in SRAM.

Field Summary
`protected boolean[]` | `flag_delta`
`protected boolean` | `pc_delta`
`protected boolean[]` | `reg_delta` Delta lists of things that have changed recently.
`static State.IOReg` | `RESERVED` The `RESERVED` field of the state class represents an instance of the `IOReg` interface that will not allow any writes to this register to occur.
`protected boolean` | `sp_delta`

Fields inherited from interface avrora.sim.IORegisterConstants
`ACSR, ADCH, ADCL, ADCSRA, ADMUX, ASSR, DDRA, DDRB, DDRC, DDRD, DDRE, DDRF, DDRG, EEARH, EEARL, EECR, EEDR, EICRA, EICRB, EIFR, EIMSK, ETIFR, ETIMSK, ICR1H, ICR1L, ICR3H, ICR3L, MCUCR, MCUCSR, NUM_REGS, OCDR, OCR0, OCR1AH, OCR1AL, OCR1BH, OCR1BL, OCR1CH, OCR1CL, OCR2, OCR3AH, OCR3AL, OCR3BH, OCR3BL, OCR3CH, OCR3CL, OSCCAL, PINA, PINB, PINC, PIND, PINE, PINF, PING, PORTA, PORTB, PORTC, PORTD, PORTE, PORTF, PORTG, RAMPZ, SFIOR, SPCR, SPDR, SPH, SPL, SPMCSR, SPSR, SREG, SREG_C, SREG_H, SREG_I, SREG_N, SREG_S, SREG_T, SREG_V, SREG_Z, TCCR0, TCCR1A, TCCR1B, TCCR1C, TCCR2, TCCR3A, TCCR3B, TCCR3C, TCNT0, TCNT1H, TCNT1L, TCNT2, TCNT3H, TCNT3L, TIFR, TIMSK, TWAR, TWBR, TWCR, TWDR, TWSR, UBRR0H, UBRR0L, UBRR1H, UBRR1L, UCSR0A, UCSR0B, UCSR0C, UCSR1A, UCSR1B, UCSR1C, UDR0, UDR1, WDTCR, XDIV, XMCRA, XMCRB`

Constructor Summary
`State(Program p, int flash_size, int ioreg_size, int sram_size)` The constructor for the `State` class builds the internal data structures needed to store the complete state of the machine, including registers, IO registers, the SRAM, and the flash.

Method Summary
`void` | `clearTracingState()`
`void` | `consumeCycle()` The `consumeCycle()` method increments the cycle count of the state by one.
`void` | `consumeCycles(long num)` The `consumeCycles()` method increments the cycle count of the state by the specified number of cycles.
`void` | `dump()`
`Instr` | `getCurrentInstr()` The `getCurrentInstr()` method returns a reference to the `Instr` object representing the instruction at the address of the current value of the program counter.
`long` | `getCycles()` The `getCycles()` method returns the clock cycle count recorded so far in the simulation.
`byte` | `getDataByte(int address)` The `getDataByte()` method reads a byte value from the data memory (SRAM) at the specified address.
`boolean` | `getFlag_C()` The `getFlag_C()` method returns the current value of the C bit in the status register as a boolean.
`boolean` | `getFlag_H()` The `getFlag_H()` method returns the current value of the H bit in the status register as a boolean.
`boolean` | `getFlag_I()` The `getFlag_I()` method returns the current value of the I bit in the status register as a boolean.
`boolean` | `getFlag_N()` The `getFlag_N()` method returns the current value of the N bit in the status register as a boolean.
`boolean` | `getFlag_S()` The `getFlag_S()` method returns the current value of the S bit in the status register as a boolean.
`boolean` | `getFlag_T()` The `getFlag_T()` method returns the current value of the T bit in the status register as a boolean.
`boolean` | `getFlag_V()` The `getFlag_V()` method returns the current value of the V bit in the status register as a boolean.
`boolean` | `getFlag_Z()` The `getFlag_Z()` method returns the current value of the Z bit in the status register as a boolean.
`Instr` | `getInstr(int address)` The `getInstr()` can be used to retrieve a reference to the `Instr` object representing the instruction at the specified program address.
`State.IOReg` | `getIOReg(int ioreg)` The `getIOReg()` method is used to retrieve a reference to the actual `IOReg` instance stored internally in the state.
`byte` | `getIORegisterByte(int ioreg)` The `getIORegisterByte()` method reads the value of an IO register.
`int` | `getPC()` The `getPC()` retrieves the current program counter.
`long` | `getPostedInterrupts()` The `getPostedInterrupts()` method returns a mask that represents all interrupts that are currently pending (meaning they are ready to be fired in priority order as long as the I flag is on).
`byte` | `getProgramByte(int address)` The `getProgramByte()` method reads a byte value from the program (Flash) memory.
`byte` | `getRegisterByte(Register reg)` Read a general purpose register's current value as a byte.
`int` | `getRegisterUnsigned(Register reg)` Read a general purpose register's current value as an integer, without any sign extension.
`int` | `getRegisterWord(Register reg)` Read a general purpose register pair as an unsigned word.
`int` | `getSP()` The `getSP()` method reads the current value of the stack pointer.
`byte` | `getSREG()` The `getSREG()` method reads the value of the status register.
`byte` | `getStackByte()` The `getStackByte()` method reads a byte from the address specified by SP+1.
`protected void` | `initializeIORegs()`
`byte` | `popByte()` The `popByte()` method pops a byte from the stack by reading from the address pointed to by SP+1 and incrementing the stack pointer.
`void` | `postInterrupt(int num)` The `postInterrupt()` method is generally only used within the simulator which does pre-processing of interrupts before it posts them into the internal `State` instance.
`protected void` | `printPair(java.lang.String n, byte val, boolean modified)`
`protected void` | `printPair(java.lang.String n, int val, boolean modified)`
`protected void` | `printPair(java.lang.String n, long val, boolean modified)`
`protected void` | `printPair(java.lang.String n, java.lang.String str, boolean modified)`
`void` | `pushByte(byte val)` The `pushByte()` method pushes a byte onto the stack by writing to the memory address pointed to by the stack pointer and decrementing the stack pointer.
`void` | `setDataByte(byte val, int address)` The `setDataByte()` method writes a value to the data memory (SRAM) of the state.
`void` | `setFlag_C(boolean val)` The `setFlag_C()` method updates the value of the C bit in the status register.
`void` | `setFlag_H(boolean val)` The `setFlag_H()` method updates the value of the H bit in the status register.
`void` | `setFlag_I(boolean val)` The `setFlag_I()` method updates the value of the I bit in the status register.
`void` | `setFlag_N(boolean val)` The `setFlag_N()` method updates the value of the N bit in the status register.
`void` | `setFlag_S(boolean val)` The `setFlag_S()` method updates the value of the S bit in the status register.
`void` | `setFlag_T(boolean val)` The `setFlag_T()` method updates the value of the T bit in the status register.
`void` | `setFlag_V(boolean val)` The `setFlag_V()` method updates the value of the V bit in the status register.
`void` | `setFlag_Z(boolean val)` The `setFlag_Z()` method updates the value of the Z bit in the status register.
`void` | `setInstr(Instr i, int address)` The `setInstr()` method is used internally to update the instructions of the program by the simulator.
`void` | `setIOReg(int ioreg, State.IOReg reg)` The `setIOReg` method installs the specified `IOReg` object to the specified IO register number.
`void` | `setIORegisterByte(byte val, int ioreg)` The `setIORegisterByte()` method writes a value to the specified IO register.
`void` | `setPC(int pc)` The `setPC()` method updates the value of the program counter.
`void` | `setPostedInterrupts(long mask)` The `setPostedInterrupts()` method allows a full update to the pending list of interrupts.
`void` | `setRegisterByte(Register reg, byte val)` The `setRegisterByte()` method writes a value to a general purpose register.
`void` | `setRegisterWord(Register reg, int val)` The `setRegisterWord` method writes a word value to a general purpose register pair.
`void` | `setSP(int val)` The `setSP()` method updates the value of the stack pointer.
`void` | `setSREG_bit(int bit, boolean val)` The `setSREG_bit()` updates the value of the specified bit in the status register.
`void` | `setSREG(byte val)` The `setSREG()` method writes the value of the status register.
`void` | `unpostInterrupt(int num)` The `unpostInterrupt()` method is generally only used within the simulator which does pre-processing of interrupts before it posts them into the internal `State` instance.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### RESERVED

    public static final State.IOReg RESERVED

  The `RESERVED` field of the state class represents an instance of the `IOReg` interface that will not allow any writes to this register to occur. These reserved IO registers are specified in the hardware manuals.

### reg_delta

    protected final boolean[] reg_delta

  Delta lists of things that have changed recently. These things are manipulated in the subclass `TracingState`.

### flag_delta

    protected final boolean[] flag_delta

### sp_delta

    protected boolean sp_delta

### pc_delta

    protected boolean pc_delta

Constructor Detail

### State

    public State(Program p,
                 int flash_size,
                 int ioreg_size,
                 int sram_size)

  The constructor for the `State` class builds the internal data structures needed to store the complete state of the machine, including registers, IO registers, the SRAM, and the flash. All IO registers are initialized to be instances of `RWIOReg`. Reserved and special IO registers must be inserted by the `getIOReg()` and `setIOReg()` methods.

Parameters:
  `p` - the program to construct the state for
  `flash_size` - the size of the flash (program) memory in bytes
  `ioreg_size` - the number of IO registers
  `sram_size` - the size of the SRAM in bytes

Method Detail

### initializeIORegs

    protected void initializeIORegs()

### getPostedInterrupts

    public long getPostedInterrupts()

  The `getPostedInterrupts()` method returns a mask that represents all interrupts that are currently pending (meaning they are ready to be fired in priority order as long as the I flag is on).

  Returns:
    a mask representing the interrupts which are posted for processing

### postInterrupt

    public void postInterrupt(int num)

  The `postInterrupt()` method is generally only used within the simulator which does pre-processing of interrupts before it posts them into the internal `State` instance. This method causes the specified interrupt number to be added to the pending list of interrupts Clients should not use this method directly.

  Parameters:
    `num` - the interrupt number to post

### unpostInterrupt

    public void unpostInterrupt(int num)

  The `unpostInterrupt()` method is generally only used within the simulator which does pre-processing of interrupts before it posts them into the internal `State` instance. This method causes the specified interrupt number to be removed from the pending list of interrupts Clients should not use this method directly.

  Parameters:
    `num` - the interrupt number to post

### setPostedInterrupts

    public void setPostedInterrupts(long mask)

  The `setPostedInterrupts()` method allows a full update to the pending list of interrupts. This should only be used within the simulator.

  Parameters:
    `mask` - the new pending interrupt mask

### getRegisterByte

    public byte getRegisterByte(Register reg)

  Read a general purpose register's current value as a byte.

  Parameters:
    `reg` - the register to read
  Returns:
    the current value of the register

### getRegisterUnsigned

    public int getRegisterUnsigned(Register reg)

  Read a general purpose register's current value as an integer, without any sign extension.

  Parameters:
    `reg` - the register to read
  Returns:
    the current unsigned value of the register

### getRegisterWord

    public int getRegisterWord(Register reg)

  Read a general purpose register pair as an unsigned word. This method will read the value of the specified register and the value of the next register in numerical order and return the two values combined as an unsigned integer The specified register should be less than r31, because r32 (the next register) does not exist.

  Parameters:
    `reg` - the low register of the pair to read
  Returns:
    the current unsigned word value of the register pair

### setRegisterByte

    public void setRegisterByte(Register reg,
                                byte val)

  The `setRegisterByte()` method writes a value to a general purpose register. This is a destructive update and should only be called from the appropriate places in the simulator.

  Parameters:
    `reg` - the register to write the value to
    `val` - the value to write to the register

### setRegisterWord

    public void setRegisterWord(Register reg,
                                int val)

  The `setRegisterWord` method writes a word value to a general purpose register pair. This is a destructive update and should only be called from the appropriate places in the simulator. The specified register and the next register in numerical order are updated with the low-order and high-order byte of the value passed, respectively. The specified register should be less than r31, since r32 (the next register) does not exist.

  Parameters:
    `reg` - the low register of the pair to write
    `val` - the word value to write to the register pair

### getSREG

    public byte getSREG()

  The `getSREG()` method reads the value of the status register. The status register contains the I, T, H, S, V, N, Z, and C flags, in order from highest-order to lowest-order.

  Returns:
    the value of the status register as a byte.

### setSREG

    public void setSREG(byte val)

  The `setSREG()` method writes the value of the status register. This method should only be called from the appropriate places in the simulator.

  Parameters:
    `val` -

### setSREG_bit

    public void setSREG_bit(int bit,
                            boolean val)

  The `setSREG_bit()` updates the value of the specified bit in the status register. It should only be called from the appropriate places in the simulator.

  Parameters:
    `bit` - the number of the bit to update
    `val` - the new value of the bit as a boolean

### setFlag_I

    public void setFlag_I(boolean val)

  The `setFlag_I()` method updates the value of the I bit in the status register. It should only be called from within the simulator.

  Parameters:
    `val` - the new value of the flag

### setFlag_T

    public void setFlag_T(boolean val)

  The `setFlag_T()` method updates the value of the T bit in the status register. It should only be called from within the simulator.

  Parameters:
    `val` - the new value of the flag

### setFlag_H

    public void setFlag_H(boolean val)

  The `setFlag_H()` method updates the value of the H bit in the status register. It should only be called from within the simulator.

  Parameters:
    `val` - the new value of the flag

### setFlag_S

    public void setFlag_S(boolean val)

  The `setFlag_S()` method updates the value of the S bit in the status register. It should only be called from within the simulator.

  Parameters:
    `val` - the new value of the flag

### setFlag_V

    public void setFlag_V(boolean val)

  The `setFlag_V()` method updates the value of the V bit in the status register. It should only be called from within the simulator.

  Parameters:
    `val` - the new value of the flag

### setFlag_N

    public void setFlag_N(boolean val)

  The `setFlag_N()` method updates the value of the N bit in the status register. It should only be called from within the simulator.

  Parameters:
    `val` - the new value of the flag

### setFlag_Z

    public void setFlag_Z(boolean val)

  The `setFlag_Z()` method updates the value of the Z bit in the status register. It should only be called from within the simulator.

  Parameters:
    `val` - the new value of the flag

### setFlag_C

    public void setFlag_C(boolean val)

  The `setFlag_C()` method updates the value of the C bit in the status register. It should only be called from within the simulator.

  Parameters:
    `val` - the new value of the flag

### getFlag_I

    public boolean getFlag_I()

  The `getFlag_I()` method returns the current value of the I bit in the status register as a boolean.

  Returns:
    the value of the flag

### getFlag_T

    public boolean getFlag_T()

  The `getFlag_T()` method returns the current value of the T bit in the status register as a boolean.

  Returns:
    the value of the flag

### getFlag_H

    public boolean getFlag_H()

  The `getFlag_H()` method returns the current value of the H bit in the status register as a boolean.

  Returns:
    the value of the flag

### getFlag_S

    public boolean getFlag_S()

  The `getFlag_S()` method returns the current value of the S bit in the status register as a boolean.

  Returns:
    the value of the flag

### getFlag_V

    public boolean getFlag_V()

  The `getFlag_V()` method returns the current value of the V bit in the status register as a boolean.

  Returns:
    the value of the flag

### getFlag_N

    public boolean getFlag_N()

  The `getFlag_N()` method returns the current value of the N bit in the status register as a boolean.

  Returns:
    the value of the flag

### getFlag_Z

    public boolean getFlag_Z()

  The `getFlag_Z()` method returns the current value of the Z bit in the status register as a boolean.

  Returns:
    the value of the flag

### getFlag_C

    public boolean getFlag_C()

  The `getFlag_C()` method returns the current value of the C bit in the status register as a boolean.

  Returns:
    the value of the flag

### getStackByte

    public byte getStackByte()

  The `getStackByte()` method reads a byte from the address specified by SP+1. This method should not be called with an empty stack, as it will cause an exception consistent with trying to read non-existent memory.

  Returns:
    the value on the top of the stack

### popByte

    public byte popByte()

  The `popByte()` method pops a byte from the stack by reading from the address pointed to by SP+1 and incrementing the stack pointer. This method, like all of the other methods that change the state, should probably only be used within the simulator. This method should not be called with an empty stack, as it will cause an exception consistent with trying to read non-existent memory.

  Returns:
    the value on the top of the stack

### pushByte

    public void pushByte(byte val)

  The `pushByte()` method pushes a byte onto the stack by writing to the memory address pointed to by the stack pointer and decrementing the stack pointer. This method, like all of the other methods that change the state, should probably only be used within the simulator.

  Parameters:
    `val` - the value to push onto the stack

### getSP

    public int getSP()

  The `getSP()` method reads the current value of the stack pointer. Since the stack pointer is stored in two IO registers, this method will cause the invocation of the `.read()` method on each of the `IOReg` objects that store these values.

  Returns:
    the value of the stack pointer as a byte address

### setSP

    public void setSP(int val)

  The `setSP()` method updates the value of the stack pointer. Generally the stack pointer is stored in two IO registers `SPL` and `SPH`. This method should generally only be used within the simulator.

  Parameters:
    `val` -
  See Also:
    `IORegisterConstants`

### getPC

    public int getPC()

  The `getPC()` retrieves the current program counter.

  Returns:
    the program counter as a byte address

### setPC

    public void setPC(int pc)

  The `setPC()` method updates the value of the program counter. It is generally used only by the simulator. In general it is a good idea to keep the program counter aligned on a 2-byte boundary. Clients of the `State` interface should generally not use this method.

  Parameters:
    `pc` - the new program counter as a byte address

### getCurrentInstr

    public Instr getCurrentInstr()

  The `getCurrentInstr()` method returns a reference to the `Instr` object representing the instruction at the address of the current value of the program counter.

  Returns:
    a reference to the `Instr` object representing the instruction at the current program counter

### getInstr

    public Instr getInstr(int address)

  The `getInstr()` can be used to retrieve a reference to the `Instr` object representing the instruction at the specified program address. Care should be taken that the address in program memory specified does not contain data. This is because Avrora does have a functioning disassembler and assumes that the `Instr` objects for each instruction in the program are known a priori.

  Parameters:
    `address` - the byte address from which to read the instruction
  Returns:
    a reference to the `Instr` object representing the instruction at that address in the program

### setInstr

    public void setInstr(Instr i,
                         int address)

  The `setInstr()` method is used internally to update the instructions of the program by the simulator. This is generally for the purpose of replacing an instruction with a `Simulator.ProbedInstr` instance that will fire probes when it is visited. It is generally not recommended for clients of the `State` interface to update instructions in the program memory.

  Parameters:
    `i` - the instruction to write
    `address` - the byte address in the program to write the instruction to

### getDataByte

    public byte getDataByte(int address)

  The `getDataByte()` method reads a byte value from the data memory (SRAM) at the specified address.

  Parameters:
    `address` - the byte address to read
  Returns:
    the value of the data memory at the specified address
  Throws:
    `java.lang.ArrayIndexOutOfBoundsException` - if the specified address is not the valid memory range

### getProgramByte

    public byte getProgramByte(int address)

  The `getProgramByte()` method reads a byte value from the program (Flash) memory. The flash memory generally stores read-only values and the instructions of the program. Care should be taken that the program memory at the specified address does not contain an instruction. This is because, in general, programs should not read instructions as data, and secondly, because no assembler is present in Avrora and therefore the actual byte value of an instruction may not be known.

  Parameters:
    `address` - the byte address at which to read
  Returns:
    the byte value of the program memory at the specified address
  Throws:
    `java.lang.ArrayIndexOutOfBoundsException` - if the specified address is not the valid program memory range

### setDataByte

    public void setDataByte(byte val,
                            int address)

  The `setDataByte()` method writes a value to the data memory (SRAM) of the state. This is generally meant for the simulator, related classes, and device implementations to use, but could also be used by debuggers and other tools.

  Parameters:
    `val` - the value to write
    `address` - the byte address at which to write the value

### getIORegisterByte

    public byte getIORegisterByte(int ioreg)

  The `getIORegisterByte()` method reads the value of an IO register. Invocation of this method causes an invocatiobn of the `.read()` method on the corresponding internal `IOReg` object, and its value returned.

  Parameters:
    `ioreg` - the IO register number
  Returns:
    the value of the IO register

### setIOReg

    public void setIOReg(int ioreg,
                         State.IOReg reg)

  The `setIOReg` method installs the specified `IOReg` object to the specified IO register number. This method is generally only used in the simulator and in device implementations to set up the state correctly during initialization.

  Parameters:
    `ioreg` - the IO register number
    `reg` - the `IOReg`object to install``

### getIOReg

    public State.IOReg getIOReg(int ioreg)

  The `getIOReg()` method is used to retrieve a reference to the actual `IOReg` instance stored internally in the state. This is generally only used in the simulator and device implementations, and clients should probably not call this memory directly.

  Parameters:
    `ioreg` - the IO register number to retrieve
  Returns:
    a reference to the `IOReg` instance of the specified IO register

### setIORegisterByte

    public void setIORegisterByte(byte val,
                                  int ioreg)

  The `setIORegisterByte()` method writes a value to the specified IO register. This is generally only used internally to the simulator and device implementations, and client interfaces should probably not call this method.

  Parameters:
    `val` - the value to write to the IO register
    `ioreg` - the IO register number to which to write the value

### getCycles

    public long getCycles()

  The `getCycles()` method returns the clock cycle count recorded so far in the simulation.

  Returns:
    the number of clock cycles elapsed in the simulation

### consumeCycle

    public void consumeCycle()

  The `consumeCycle()` method increments the cycle count of the state by one. This is generally only used internally to the simulator and tightly coupled classes, so clients of the state interface should not call this method unless they are implementing careful timings (e.g. an external RAM).

### consumeCycles

    public void consumeCycles(long num)

  The `consumeCycles()` method increments the cycle count of the state by the specified number of cycles. This is generally only used internally to the simulator and tightly coupled classes, so clients of the state interface should not call this method unless they are implementing careful timings (e.g. an external RAM).

  Parameters:
    `num` - the number of cycles to advance the cycle counter

### dump

    public void dump()

### printPair

    protected final void printPair(java.lang.String n,
                                   java.lang.String str,
                                   boolean modified)

### printPair

    protected final void printPair(java.lang.String n,
                                   byte val,
                                   boolean modified)

### printPair

    protected final void printPair(java.lang.String n,
                                   int val,
                                   boolean modified)

### printPair

    protected final void printPair(java.lang.String n,
                                   long val,
                                   boolean modified)

### clearTracingState

    public void clearTracingState()

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD