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 CodeSegment

    java.lang.Object
      avrora.sim.Segment
          avrora.sim.CodeSegment

Direct Known Subclasses:
  ReprogrammableCodeSegment

public class CodeSegment
extends Segment

The `CodeSegment` class represents a segment of memory that stores executable code. The program memory on the AVR chips, for example, is a flash segment.

Nested Class Summary
`static interface` | `CodeSegment.CodeSharer` The `CodeSharer` interface is used to allow sharing of the underlying array representing the code.
`static class` | `CodeSegment.DefaultFactory` The `DefaultFactory` class represents a factory capable of creating a simple code segment that is not reprogrammable.
`static interface` | `CodeSegment.Factory` The `CodeSegment.Factory` class is used to create a new code segment for a new interpreter.
`protected class` | `CodeSegment.ProbedInstr` The ProbedInstr class represents a wrapper around an instruction in the program that executes the probes before executing the instruction and after the instruction.

Nested classes inherited from class avrora.sim.Segment
`Segment.AddressOutOfBoundsException, Segment.ErrorReporter, Segment.Sharer`

Field Summary
`protected CodeSegment.CodeSharer` | `codeSharer`
`static byte` | `DEFAULT_VALUE` The `DEFAULT_VALUE` field stores the default value that is used to initialize the flash memory.
`protected avrora.sim.CodeSegment.MisalignedInstr` | `MISALIGNED_INSTR`
`protected avrora.sim.CodeSegment.NoInstr` | `NO_INSTR`
`protected Instr[]` | `segment_instr` The `segment_instr` field stores a reference to an array that contains the disassembled instructions that correspond to the machine code.

Fields inherited from class avrora.sim.Segment
`errorReporter, interpreter, name, segment_data, segment_watches, sharer, size, value`

Constructor Summary
`CodeSegment(java.lang.String name, int size, BaseInterpreter bi, Segment.ErrorReporter er)` The constructor for the `CodeSegment` class creates a new code segment, complete with binary and instruction representations.

Method Summary
`Instr` | `getInstr(int address)` The `getInstr()` method reads an Instr from the specified address in the flash.
`void` | `insertProbe(int address, Simulator.Probe p)` The `insertProbe()` method inserts a probe on an instruction at the specified address.
`void` | `load(Program p)` The `load()` method loads a program into the flash memory, writing the binary machine code and the disassembled instructions.
`Instr` | `readInstr(int address)` The `readInstr()` method reads an Instr from the specified address in the flash.
`void` | `removeProbe(int address, Simulator.Probe p)` The `removeProbe()` method removes a probe from a particular instruction in the program.
`protected void` | `replaceInstr(int address, Instr i)` The `replaceInstr()` method is used internally to update an instruction in the flash segment without losing all of its attached instrumentation (i.e. probes and watches).
`Instr[]` | `shareCode(CodeSegment.CodeSharer s)`
`void` | `update()` The `update()` method is called when the program attempts an update to the flash memory through the SPM instruction.
`protected void` | `writeInstr(int address, Instr i)`

Methods inherited from class avrora.sim.Segment
`get, insertWatch, read, removeWatch, set, share, write`

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

Field Detail

### DEFAULT_VALUE

    public static final byte DEFAULT_VALUE

  The `DEFAULT_VALUE` field stores the default value that is used to initialize the flash memory.

  See Also:
    Constant Field Values

### segment_instr

    protected Instr[] segment_instr

  The `segment_instr` field stores a reference to an array that contains the disassembled instructions that correspond to the machine code.

### NO_INSTR

    protected final avrora.sim.CodeSegment.NoInstr NO_INSTR

### MISALIGNED_INSTR

    protected final avrora.sim.CodeSegment.MisalignedInstr MISALIGNED_INSTR

### codeSharer

    protected CodeSegment.CodeSharer codeSharer

Constructor Detail

### CodeSegment

    public CodeSegment(java.lang.String name,
                       int size,
                       BaseInterpreter bi,
                       Segment.ErrorReporter er)

  The constructor for the `CodeSegment` class creates a new code segment, complete with binary and instruction representations.

Parameters:
  `name` - the name of the segment as a string
  `size` - the size of the segment in bytes
  `bi` - the interpreter that will use this segment
  `er` - the error reporter consulted on accesses out of bounds

Method Detail

### replaceInstr

    protected void replaceInstr(int address,
                                Instr i)

  The `replaceInstr()` method is used internally to update an instruction in the flash segment without losing all of its attached instrumentation (i.e. probes and watches).

  Parameters:
    `address` - the address in the code segment of the instruction
    `i` - the new instruction to place at this location in the flash

### update

    public void update()

  The `update()` method is called when the program attempts an update to the flash memory through the SPM instruction. This is only supported on some flash memory types.

### shareCode

    public Instr[] shareCode(CodeSegment.CodeSharer s)

### load

    public void load(Program p)

  The `load()` method loads a program into the flash memory, writing the binary machine code and the disassembled instructions. This should only be done once for a `FlashMemory` object, before any instrumentation is added.

  Parameters:
    `p` - the program to be loaded into the flash memory

### readInstr

    public Instr readInstr(int address)

  The `readInstr()` method reads an Instr from the specified address in the flash. For misaligned accesses and accesses to places in the flash where there are no valid instructions, this method returns `null`. This method does not return `ProbedInstr` or `DisassembleInstr` objects which are used internally to accomplish probing and dynamically updated code.

  Parameters:
    `address` - the address in the flash from which to read the instruction
  Returns:
    a reference to the `Instr` object at this address in the flash; `null` if there is no instruction at this address.

### getInstr

    public Instr getInstr(int address)

  The `getInstr()` method reads an Instr from the specified address in the flash. For misaligned accesses and accesses to places in the flash where there are no valid instructions, this method may return instances of `MisalignedInstr` or `DisassembleInstr` objects which are used internally to check for errors and support dynamically updated code. Additionally, this method may return instances of `ProbedInstr` that are used internally to support probing of instructions.

  Parameters:
    `address` - the address in the flash from which to read the instruction
  Returns:
    a reference to the `Instr` object at this address in the flash; `null` if there is no instruction at this address.

### insertProbe

    public void insertProbe(int address,
                            Simulator.Probe p)

  The `insertProbe()` method inserts a probe on an instruction at the specified address. No equality testing is done; i.e. inserting the same probe on the same address more than once will result in it being triggered more than once when the instruction executes.

  Parameters:
    `address` - the address of the instruction on which to insert the probe
    `p` - the probe to insert on this instruction

### removeProbe

    public void removeProbe(int address,
                            Simulator.Probe p)

  The `removeProbe()` method removes a probe from a particular instruction in the program. The probe will no longer be triggered for subsequent executions of this instruction. Reference equality is used for testing whether the probe should be removed; i.e. the `Object.equals()` method is not consulted.

  Parameters:
    `address` - the address of the instructiobn on which to insert the probe
    `p` - the probe to isnert on this instruction

### writeInstr

    protected void writeInstr(int address,
                              Instr i)

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