fi.hu.cs.titokone
Class Processor

java.lang.Object
  extended byfi.hu.cs.titokone.Processor
All Implemented Interfaces:
TTK91Cpu

public class Processor
extends java.lang.Object
implements TTK91Cpu

This class represents the processor. It can be told to run for one command cycle at a time.


Field Summary
private static java.lang.String ADDRESS_OUT_OF_BOUNDS_MESSAGE
           
private static java.lang.String BAD_ACCESS_MODE_MESSAGE
           
private static java.lang.String BRANCH_BAD_ACCESS_MODE_MESSAGE
           
static int CRT
          CRT-device
private static java.lang.String DIVISION_BY_ZERO_MESSAGE
           
private static java.lang.String INTEGER_OVERFLOW_MESSAGE
           
private static java.lang.String INVALID_DEVICE_MESSAGE
           
private static java.lang.String INVALID_OPCODE_MESSAGE
           
static int KBD
          KBD-device
private  java.lang.Integer kbdData
          The stdinData and kbdData fields stores buffer data to be read with the IN operation.
private static java.lang.String NO_KDB_DATA_MESSAGE
           
private static java.lang.String NO_STDIN_DATA_MESSAGE
           
static int OS_CODE_AREA
          When SVC call is made PC points to this place.
private  RandomAccessMemory ram
          This field represents the memory of computer.
private  Registers regs
          This field represents the registers of computer.
private  RunDebugger runDebugger
          Rundebugger
private  boolean[] sr
          state register array.
private  int status
          Is program running.
static int STDIN
          STDIN-device
private  java.lang.Integer stdinData
          The stdinData and kbdData fields stores buffer data to be read with the IN operation.
static int STDOUT
          STDOUT-device
private static java.lang.String STORE_BAD_ACCESS_MODE_MESSAGE
           
 
Fields inherited from interface fi.hu.cs.ttk91.TTK91Cpu
CU_IR, CU_PC, CU_PC_CURRENT, CU_SR, CU_TR, REG_FP, REG_R0, REG_R1, REG_R2, REG_R3, REG_R4, REG_R5, REG_R6, REG_R7, REG_SP, STATUS_ABNORMAL_EXIT, STATUS_STILL_RUNNING, STATUS_SVC_SD
 
Constructor Summary
Processor(int memsize)
          Creates new processor, memory and registers.
 
Method Summary
private  void alu(int opcode, int Rj, int param)
          ALU-operations.
private  void branch(int opcode, int Rj, int M, int ADDR, int param)
          Branching.
private  void comp(int Rj, int param)
          Compare-method manipulates status register.
 void eraseMemory()
          Method erases memorylines from memory.
 TTK91Memory getMemory()
          Returns the memory attached to the processor.
 MemoryLine getMemoryLine(int row)
          Returns queried memory line.
 int getStatus()
          Method returns the current value of Processor.
 int getValueOf(int registerID)
          Returns the value of given registerID.
private  boolean isOverflow(long value)
          Tests if given long value is acceptable int value.
 void keyboardInput(int kbdInput)
          This method adds a line of keyboard data to a buffer the Processor can read it from during its next command cycle (or previous cycle repeated).
 void memoryInput(int rowNumber, MemoryLine inputLine)
          Method for loading MemoryLines to Processor, Loader classes uses this for loading application to processor.
private  void nop()
           
 void runInit(int initSP, int initFP)
          Initializes processor with new program set FP and SP, PC = 0 and return RunInfo
 RunInfo runLine()
          Process next instruction.
private  void setNewPC(int newPC)
           
private  void stack(int opcode, int Rj, int Ri, int param)
          Stack.
 void stdinInput(int stdinInput)
          This method adds a line of stdin data to a buffer the Processor can read it from during its next command cycle (or previous cycle repeated).
private  void subr(int opcode, int Rj, int ADDR, int param)
          Subroutine.
private  void svc(int Rj, int param)
          Supervisor call.
private  void transfer(int opcode, int Rj, int M, int ADDR, int param)
          Transfer-operations.
private  void writeToMemory(int row, int value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OS_CODE_AREA

public static final int OS_CODE_AREA
When SVC call is made PC points to this place.

See Also:
Constant Field Values

INVALID_OPCODE_MESSAGE

private static final java.lang.String INVALID_OPCODE_MESSAGE
See Also:
Constant Field Values

ADDRESS_OUT_OF_BOUNDS_MESSAGE

private static final java.lang.String ADDRESS_OUT_OF_BOUNDS_MESSAGE
See Also:
Constant Field Values

BAD_ACCESS_MODE_MESSAGE

private static final java.lang.String BAD_ACCESS_MODE_MESSAGE
See Also:
Constant Field Values

BRANCH_BAD_ACCESS_MODE_MESSAGE

private static final java.lang.String BRANCH_BAD_ACCESS_MODE_MESSAGE
See Also:
Constant Field Values

STORE_BAD_ACCESS_MODE_MESSAGE

private static final java.lang.String STORE_BAD_ACCESS_MODE_MESSAGE
See Also:
Constant Field Values

NO_KDB_DATA_MESSAGE

private static final java.lang.String NO_KDB_DATA_MESSAGE
See Also:
Constant Field Values

NO_STDIN_DATA_MESSAGE

private static final java.lang.String NO_STDIN_DATA_MESSAGE
See Also:
Constant Field Values

INVALID_DEVICE_MESSAGE

private static final java.lang.String INVALID_DEVICE_MESSAGE
See Also:
Constant Field Values

INTEGER_OVERFLOW_MESSAGE

private static final java.lang.String INTEGER_OVERFLOW_MESSAGE
See Also:
Constant Field Values

DIVISION_BY_ZERO_MESSAGE

private static final java.lang.String DIVISION_BY_ZERO_MESSAGE
See Also:
Constant Field Values

CRT

public static final int CRT
CRT-device

See Also:
Constant Field Values

KBD

public static final int KBD
KBD-device

See Also:
Constant Field Values

STDIN

public static final int STDIN
STDIN-device

See Also:
Constant Field Values

STDOUT

public static final int STDOUT
STDOUT-device

See Also:
Constant Field Values

ram

private RandomAccessMemory ram
This field represents the memory of computer.


regs

private Registers regs
This field represents the registers of computer.


status

private int status
Is program running.


runDebugger

private RunDebugger runDebugger
Rundebugger


sr

private boolean[] sr
state register array. index: 0 - greater 1 - equal 2 - less 3 - arithmetic overflow 4 - divide by zero 5 - unknown instruction 6 - forbidden memory access 7 - device interrupt 8 - supervisor call 9 - priviledged mode 10 - interrupts disabled


stdinData

private java.lang.Integer stdinData
The stdinData and kbdData fields stores buffer data to be read with the IN operation. When the data has been read, the field should be set to be null.


kbdData

private java.lang.Integer kbdData
The stdinData and kbdData fields stores buffer data to be read with the IN operation. When the data has been read, the field should be set to be null.

Constructor Detail

Processor

public Processor(int memsize)
Creates new processor, memory and registers. Processor state, program counter get initial values

Parameters:
memsize - creates new computer with given size of memory. Proper values are power of two (from 512 to 64k).
Method Detail

getMemory

public TTK91Memory getMemory()
Returns the memory attached to the processor.


getValueOf

public int getValueOf(int registerID)
Returns the value of given registerID. The index numbers are available from the TTK91CPU interface.

Specified by:
getValueOf in interface TTK91Cpu
Parameters:
registerID - Identifying number of the register.
Returns:
Value of given register. Inproper value returns -1.

getMemoryLine

public MemoryLine getMemoryLine(int row)
Returns queried memory line.

Parameters:
row - Number of the row in processor's memory.
Returns:
Queried memory line.

getStatus

public int getStatus()
Method returns the current value of Processor. Status values are available from the TTK91CPU interface.

Specified by:
getStatus in interface TTK91Cpu
Returns:
Current status of the Processor.

eraseMemory

public void eraseMemory()
Method erases memorylines from memory. Memory will be filled with 0-lines.


memoryInput

public void memoryInput(int rowNumber,
                        MemoryLine inputLine)
                 throws TTK91AddressOutOfBounds
Method for loading MemoryLines to Processor, Loader classes uses this for loading application to processor.

Throws:
java.lang.IllegalArgumentException - If inputLine is null.
TTK91AddressOutOfBounds - If the rownumber is either below 0 or beyond the memory size.

keyboardInput

public void keyboardInput(int kbdInput)
This method adds a line of keyboard data to a buffer the Processor can read it from during its next command cycle (or previous cycle repeated).

Parameters:
kbdInput - An int to be "read from the keyboard".

stdinInput

public void stdinInput(int stdinInput)
This method adds a line of stdin data to a buffer the Processor can read it from during its next command cycle (or previous cycle repeated).

Parameters:
stdinInput - An int to be "read from STDIN (file)".

runInit

public void runInit(int initSP,
                    int initFP)
Initializes processor with new program set FP and SP, PC = 0 and return RunInfo

Returns:
RunInfo created by RunDebugger.

runLine

public RunInfo runLine()
                throws TTK91RuntimeException
Process next instruction.

Returns:
RunInfo created by RunDebugger.
Throws:
TTK91RuntimeException

transfer

private void transfer(int opcode,
                      int Rj,
                      int M,
                      int ADDR,
                      int param)
               throws TTK91BadAccessMode,
                      TTK91AddressOutOfBounds,
                      TTK91NoKbdData,
                      TTK91NoStdInData,
                      TTK91InvalidDevice
Transfer-operations.

Throws:
TTK91BadAccessMode
TTK91AddressOutOfBounds
TTK91NoKbdData
TTK91NoStdInData
TTK91InvalidDevice

alu

private void alu(int opcode,
                 int Rj,
                 int param)
          throws TTK91IntegerOverflow,
                 TTK91DivisionByZero
ALU-operations.

Returns:
Result of the ALU-operation.
Throws:
TTK91IntegerOverflow
TTK91DivisionByZero

comp

private void comp(int Rj,
                  int param)
Compare-method manipulates status register.

Parameters:
Rj - First value to compare (register index).
param - Second value.

branch

private void branch(int opcode,
                    int Rj,
                    int M,
                    int ADDR,
                    int param)
             throws TTK91BadAccessMode
Branching.

Throws:
TTK91BadAccessMode

stack

private void stack(int opcode,
                   int Rj,
                   int Ri,
                   int param)
            throws TTK91AddressOutOfBounds
Stack.

Throws:
TTK91AddressOutOfBounds

subr

private void subr(int opcode,
                  int Rj,
                  int ADDR,
                  int param)
           throws TTK91AddressOutOfBounds
Subroutine.

Throws:
TTK91AddressOutOfBounds

svc

private void svc(int Rj,
                 int param)
          throws TTK91AddressOutOfBounds,
                 TTK91NoKbdData
Supervisor call.

Throws:
TTK91AddressOutOfBounds
TTK91NoKbdData

nop

private void nop()

writeToMemory

private void writeToMemory(int row,
                           int value)
                    throws TTK91AddressOutOfBounds
Throws:
TTK91AddressOutOfBounds

setNewPC

private void setNewPC(int newPC)

isOverflow

private boolean isOverflow(long value)
Tests if given long value is acceptable int value.