Simple Machine

machine
Class AbstractCPU

java.lang.Object
  extended by java.util.Observable
      extended by machine.AbstractCPU
Direct Known Subclasses:
AbstractSM213CPU

public abstract class AbstractCPU
extends Observable


Nested Class Summary
 class AbstractCPU.ImplementationException
          Exception indicating an internal error in CPU implementation.
static class AbstractCPU.InternalState
          AbstractCPU internal state.
 class AbstractCPU.InvalidInstructionException
          Exception indicating that an invalid instruction was just detected by the CPU.
 class AbstractCPU.MachineHaltException
          Exception indicating that the CPU just retired a halt instruction.
 
Field Summary
 AbstractCPU.InternalState is
          Internal state not accessed by concerete sub-classes.
protected  AbstractMainMemory.Port mem
          Link to CPU's main memory.
protected  RegisterSet.Ports reg
          General purpose register file.
 
Constructor Summary
AbstractCPU(String aName, AbstractMainMemory aMem)
          Create a new CPU.
 
Method Summary
protected abstract  void cycle()
          Compute one cycle of CPU.
 AbstractMainMemory getMainMemory()
          Get value of CPU's main memory.
 String getName()
          Get fully-qualified name of this implementation.
 DataModel getPC()
          Get the program-counter value.
 Vector<RegisterSet> getProcessorState()
          Get the CPU's processor state.
 RegisterSet getRegisterFile()
          Get the CPU's register file.
 boolean isInterrupt()
          Determing whether CPU has a pending interrupt.
static AbstractCPU newInstance(AbstractCPU aCPU)
          Create a new instance of the same underlying type and with the same constructor parameters as existing cpu.
 void setPC(int aPC)
          Set program-counter value
 void start()
          Start processor execution.
 void triggerInterrupt()
          Trigger an interrupt on CPU.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

is

public final AbstractCPU.InternalState is
Internal state not accessed by concerete sub-classes.


reg

protected RegisterSet.Ports reg
General purpose register file.


mem

protected AbstractMainMemory.Port mem
Link to CPU's main memory.

Constructor Detail

AbstractCPU

public AbstractCPU(String aName,
                   AbstractMainMemory aMem)
Create a new CPU.

Parameters:
aName - fully-qualified name of CPU implementation.
aMem - main memory used by CPU.
Method Detail

newInstance

public static AbstractCPU newInstance(AbstractCPU aCPU)
Create a new instance of the same underlying type and with the same constructor parameters as existing cpu.

Parameters:
aCPU - CPU object who's class and value is used as the basis of the new CPU.

getMainMemory

public AbstractMainMemory getMainMemory()
Get value of CPU's main memory.


getRegisterFile

public RegisterSet getRegisterFile()
Get the CPU's register file.


getProcessorState

public Vector<RegisterSet> getProcessorState()
Get the CPU's processor state.


getName

public String getName()
Get fully-qualified name of this implementation.


getPC

public DataModel getPC()
Get the program-counter value.


setPC

public void setPC(int aPC)
Set program-counter value


cycle

protected abstract void cycle()
                       throws AbstractCPU.InvalidInstructionException,
                              AbstractCPU.MachineHaltException,
                              AbstractMainMemory.InvalidAddressException,
                              Register.TimingException,
                              AbstractCPU.ImplementationException
Compute one cycle of CPU.

Throws:
AbstractCPU.InvalidInstructionException - attempted to execute an invalid instruction.
AbstractCPU.MachineHaltException - halt instruction executed.
AbstractMainMemory.InvalidAddressException - attempted to execute an instruction that accesses an invalid memory address.
Register.TimingException - if instruction stalls on reading register input port.
AbstractCPU.ImplementationException - wrapper for all other exception for reporting to UI.

triggerInterrupt

public void triggerInterrupt()
Trigger an interrupt on CPU. If CPU is executing in start() it stops by returning from start().


isInterrupt

public boolean isInterrupt()
Determing whether CPU has a pending interrupt.

Returns:
true iff triggerInterrupt has been called, but start() has not yet stopped as a result of that interrupt.

start

public void start()
           throws AbstractCPU.InvalidInstructionException,
                  AbstractCPU.MachineHaltException,
                  AbstractMainMemory.InvalidAddressException,
                  Register.TimingException,
                  AbstractCPU.ImplementationException
Start processor execution. Continues executing until an exception is thrown or an interrupt is triggered. If start() returns without throwing an exception then an interrupt has occured.

Throws:
AbstractCPU.InvalidInstructionException - attempted to execute an invalid instruction.
AbstractCPU.MachineHaltException - halt instruction executed.
AbstractMainMemory.InvalidAddressException - attempted to execute an instruction that accesses an invalid memory address.
Register.TimingException - if instruction stalls on reading register input port.
AbstractCPU.ImplementationException - wrapper for all other exception for reporting to UI.

Simple Machine

Copyright © 2010, 2011 Mike Feeley. All Rights Reserved.