Simple Machine

arch.sm213.machine
Class AbstractSM213CPU

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

public abstract class AbstractSM213CPU
extends AbstractCPU

Infrastructure for executing an SM213 CPU implementation.


Nested Class Summary
 
Nested classes/interfaces inherited from class machine.AbstractCPU
AbstractCPU.ImplementationException, AbstractCPU.InternalState, AbstractCPU.InvalidInstructionException, AbstractCPU.MachineHaltException
 
Field Summary
protected  Register.Port insOp0
          Operand 0.
protected  Register.Port insOp1
          Operand 1.
protected  Register.Port insOp2
          Operand 2.
protected  Register.Port insOpCode
          Opcode.
protected  Register.Port insOpExt
          Extended operand (extra 4 bytes).
protected  Register.Port insOpImm
          Immediate-value operand.
protected  Register.Port instruction
          Value of current instruction (in its entirety).
protected  Register.Port pc
          Program counter (address of next instruction).
protected  AbstractMainMemory.Port physMem
          Physical memory (in case mem, is virtual memory)
protected  RegisterSet ps
          Internal machine registers.
protected  Register.Port ptbr
           
 
Fields inherited from class machine.AbstractCPU
is, mem, reg
 
Constructor Summary
AbstractSM213CPU(String name, AbstractMainMemory memory)
          Create a new CPU.
 
Method Summary
protected  void cycle()
          Compute one cycle of the SM213 CPU
 void enableVirtualMemory()
          Enable Virtual Memory address translation.
protected abstract  void execute()
          Execute instruction currently loaded in processorState registers.
protected abstract  void fetch()
          Fetch next instruction from memory into CPU processorState registers.
 void setPC(int aPC)
          Set PC.
 int translateAddress(int va)
          Translate address from virtual to physical.
 
Methods inherited from class machine.AbstractCPU
getMainMemory, getName, getPC, getProcessorState, getRegisterFile, isInterrupt, newInstance, start, triggerInterrupt
 
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

ps

protected RegisterSet ps
Internal machine registers.


ptbr

protected Register.Port ptbr

pc

protected Register.Port pc
Program counter (address of next instruction).


instruction

protected Register.Port instruction
Value of current instruction (in its entirety).


insOpCode

protected Register.Port insOpCode
Opcode.


insOp0

protected Register.Port insOp0
Operand 0.


insOp1

protected Register.Port insOp1
Operand 1.


insOp2

protected Register.Port insOp2
Operand 2.


insOpImm

protected Register.Port insOpImm
Immediate-value operand.


insOpExt

protected Register.Port insOpExt
Extended operand (extra 4 bytes).


physMem

protected AbstractMainMemory.Port physMem
Physical memory (in case mem, is virtual memory)

Constructor Detail

AbstractSM213CPU

public AbstractSM213CPU(String name,
                        AbstractMainMemory memory)
Create a new CPU.

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

enableVirtualMemory

public void enableVirtualMemory()
Enable Virtual Memory address translation.


translateAddress

public int translateAddress(int va)
                     throws AbstractMainMemory.InvalidAddressException
Translate address from virtual to physical. By default there is no translation. Subclasses extend to implement virtual memory.

Parameters:
va - virtual address
Returns:
physical address
Throws:
AbstractMainMemory.InvalidAddressException - if address is not valid

cycle

protected void cycle()
              throws AbstractCPU.InvalidInstructionException,
                     AbstractCPU.MachineHaltException,
                     AbstractMainMemory.InvalidAddressException
Compute one cycle of the SM213 CPU

Specified by:
cycle in class AbstractCPU
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.

setPC

public void setPC(int aPC)
Set PC.

Overrides:
setPC in class AbstractCPU
Parameters:
aPC - New memory address for PC.

fetch

protected abstract void fetch()
                       throws AbstractMainMemory.InvalidAddressException
Fetch next instruction from memory into CPU processorState registers.

Throws:
AbstractMainMemory.InvalidAddressException - Program counter stores an invalid memory address for fetching a new instruction.

execute

protected abstract void execute()
                         throws AbstractCPU.InvalidInstructionException,
                                AbstractCPU.MachineHaltException,
                                RegisterSet.InvalidRegisterNumberException,
                                AbstractMainMemory.InvalidAddressException
Execute instruction currently loaded in processorState registers.

Throws:
AbstractCPU.InvalidInstructionException - instruction is invalid.
AbstractCPU.MachineHaltException - instruction is the halt instruction.
RegisterSet.InvalidRegisterNumberException - instruction encodes an invalid register number.
AbstractMainMemory.InvalidAddressException - instruction encodes an invalid memory address.

Simple Machine

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