com.cmpware.fastmodel
Class FastModel

java.lang.Object
  extended by com.cmpware.cmp.Memory
      extended by com.cmpware.cmp.Processor
          extended by com.cmpware.fastmodel.FastModel
All Implemented Interfaces:
ReadWriteInterface
Direct Known Subclasses:
FastSimple

public abstract class FastModel
extends Processor

This abstract class is used to describe the instruction set for a processor. This is in turn used to drive other parts of the system, notably the AsmTool and DasmTool which produce a simple assembler and disassembler. This class also extends the Processor class for use in the AutoModel tool. This permits full Cmpware simulation models to be built using the instruction set data. This model supports instruction sizes of arbitrary length with maximum field sizes of 64 bits. Note: breakpoints now stop execution after the instruction has executed. Previous models stopped before the instruction executed. This should have minimal impact on functionality.

Copyright (c) 2008 Cmpware, Inc. All Rights Reserved.

Author:
SAG

Field Summary
static java.lang.String copyright
          Copyright string
protected  int[] instructionSizes
          The different instruction sizes (in bits)
 
Fields inherited from class com.cmpware.cmp.Processor
bkpt, branchAddr, branchDelay, breakpointHit, currentBranchDelay, currentInstrCode, cycleCount, elf, idlePower, iMix, instructionSize, name, noop, opcodeName, pc, prevInstr, prevInstrCode, r, regName, runningPower, sr, sregName, stall, stallCount
 
Fields inherited from class com.cmpware.cmp.Memory
BIG, LITTLE
 
Constructor Summary
FastModel()
           
 
Method Summary
 void branch(int branchAddr)
          This method should be called whenever an instruction branches.
 void branch(long branchAddr)
          This is a version of the branch() method that takes a long (64-bit) address.
 void branchNoDelay(int branchAddr)
          This method should be called whenever an instruction branches and the delay slot is not executed.
 void branchNoDelay(long branchAddr)
          This is a versi0on of the branchNoDelay() method that takes a long (64-bit) address.
 java.lang.String dasm(java.math.BigInteger instrData, Instruction instr)
          This method disassembles an instruction.
 java.lang.String dasm(byte[] instr)
          This method disassembles an instruction.
 int decode(int instr)
          A unique code identifying the instruction is returned by this method.
 void defineInstructions(Instruction[] instructions)
          This method is used to pass the instruction data tables to the AutoModel.
 void execute(int instr)
          This method is called after the fetch() and decode() and represents the execution phase of the instruction.
 Instruction fetch(Instruction instr)
          This method pre-fetches an instruction.
 int[] getBreakpoints()
          This method returns an array of Integer objects that give the addresses of all set breakpoints.
 byte[] getInstruction(int addr)
          This method fetches an instruction from memory.
 Instruction[] getInstructions()
          This method returns an array of the current instructions used by this model.
 int[] getInstructionSizes()
          This method returns an array of integers containing the different instruction sizes in the model.
 Instruction getNewInstruction(long addr)
          This method gets and caches a new instruction.
 int getPC()
          This method returns the current Program Counter.
static java.lang.String[] getSymbolNames(Symbol[] symbols)
          This method takes in a symbol table and returns an array of strings.
 Instruction instrMatch(java.math.BigInteger instr, int bits)
          This method returns the instruction object from the instruction table associated with a given instruction.
 boolean isBreakpoint(int addr)
          This method returns true if the address contains a breakpoint and a false otherwise.
 boolean isBreakpoint(long addr)
          This method returns true if the address contains a breakpoint and a false otherwise.
static void main(FastModel fm, java.lang.String[] args)
          This is the main program which is used to assemble / disassemble from the command line.
 void postLoad()
          This method it used to perform any operations that may be required after a file is loaded.
 void removeAllBreakpoints()
          This method removes all breakpoints.
 void removeBreakpoint(int addr)
          This method removes a breakpoint.
 void removeBreakpoint(long addr)
          This method removes a breakpoint.
 void reset()
          This method resets the processor.
 void setBreakpoint(int addr)
          This method sets a breakpoint.
 void setBreakpoint(long addr)
          This method sets a breakpoint.
 void setPC(int i)
          This method sets the current Program Counter.
 void statistics()
          This method keeps various statistics about the most recently exercuted instruction.
 void step(long globalCycleCount)
          This method steps the simulation one cycle.
 
Methods inherited from class com.cmpware.cmp.Processor
advancePC, defineBranchDelay, defineBreakpoint, defineInstructionSize, defineName, defineNoop, defineOpcodeNames, defineRegisterNames, defineRegisters, defineSpecialRegisterNames, defineSpecialRegisters, fetch, get, getBreakpoint, getBreakpointData, getCycleCount, getDebugRegisters, getElf, getIdlePower, getInstructionMix, getInstructionSize, getName, getNoop, getOpcodeNames, getRegister, getRegisterNames, getRegisters, getRunningPower, getSpecialRegister, getSpecialRegisterNames, getSpecialRegisters, getStallCount, isStalled, load, setIdlePower, setRegister, setRunningPower, setSpecialRegister, stall
 
Methods inherited from class com.cmpware.cmp.Memory
addInput, addMemory, addOutput, getEndian, getLocalMemory, getMemoryManager, getMmio, getProfile, hexDump, hexDump, isReadable, isValidAddress, isWriteable, profile, read, read, read16, read24, read32, read64, removeMemory, resize, setEndian, size, toInt, toShort, write, write, write16, write24, write32, write64
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyright

public static final java.lang.String copyright
Copyright string

See Also:
Constant Field Values

instructionSizes

protected int[] instructionSizes
The different instruction sizes (in bits)

Constructor Detail

FastModel

public FastModel()
Method Detail

main

public static void main(FastModel fm,
                        java.lang.String[] args)
This is the main program which is used to assemble / disassemble from the command line.

Parameters:
args - The command line args. Should be a flag ("-asm" of "-dasm") followed by an input filename and an output filename (three strings).

defineInstructions

public void defineInstructions(Instruction[] instructions)
This method is used to pass the instruction data tables to the AutoModel. It is not called as a constructor but should probably be called early in the subclass constructor.

Parameters:
instructions - the instruction data tables.

step

public void step(long globalCycleCount)
          throws MemoryAccessException,
                 IllegalOpcodeException,
                 IllegalRegisterException,
                 BreakpointException
Description copied from class: Processor
This method steps the simulation one cycle.

Overrides:
step in class Processor
Parameters:
globalCycleCount - This is the clock cycle as maintained by the multiprocessor. If the processor itself has gotten ahead of this value this method simply returns. The local cycle count should never be less than the global cycle count.
Throws:
MemoryAccessException - A Memory Access Exception is thrown is an illegal memory access is attempted.
IllegalOpcodeException - if an attempt is made to execute an illegal opcode.
IllegalRegisterException - if an attempt is made to access a register illegally.
BreakpointException - if a breakpoint is encountered on this cycle.

decode

public int decode(int instr)
           throws IllegalOpcodeException,
                  MemoryAccessException
Description copied from class: Processor
A unique code identifying the instruction is returned by this method. In some processors with simple fixed-field opcodes this may be a very simple method to define. Other architectures with more complex decoding will require a more complex implementation.

Specified by:
decode in class Processor
Parameters:
instr - The instruction to be decoded.
Returns:
A unique code identifying the instruction is returned by this method.
Throws:
IllegalOpcodeException - if an illegal opcode is encountered.
MemoryAccessException - A Memory Access Exception is thrown is an illegal memory access is attempted.

execute

public void execute(int instr)
             throws MemoryAccessException,
                    IllegalRegisterException,
                    IllegalOpcodeException
Description copied from class: Processor
This method is called after the fetch() and decode() and represents the execution phase of the instruction. All update of processor state occurs in this method. This is where most of the processor definition will occur. See examples for suggestions on implementation of this method.

Specified by:
execute in class Processor
Parameters:
instr - The instruction to be executed.
Throws:
MemoryAccessException - A Memory Access Exception is thrown is an illegal memory access is attempted.
IllegalRegisterException - if an attempt is made to access a register illegally.
IllegalOpcodeException - is added for models which may combine decode and execute in the same method (such as AutoModel).

branch

public void branch(int branchAddr)
Description copied from class: Processor
This method should be called whenever an instruction branches. Use of this method will ensure that proper delay slotting is performed.

Overrides:
branch in class Processor
Parameters:
branchAddr - The branch address.

branch

public void branch(long branchAddr)
This is a version of the branch() method that takes a long (64-bit) address.

Parameters:
branchAddr - the branch address

branchNoDelay

public void branchNoDelay(int branchAddr)
Description copied from class: Processor
This method should be called whenever an instruction branches and the delay slot is not executed.

Overrides:
branchNoDelay in class Processor
Parameters:
branchAddr - The branch address.

branchNoDelay

public void branchNoDelay(long branchAddr)
This is a versi0on of the branchNoDelay() method that takes a long (64-bit) address.

Parameters:
branchAddr - the branch address

dasm

public java.lang.String dasm(byte[] instr)
Description copied from class: Processor
This method disassembles an instruction. Note that a byte array is provided as the interface. This is to make this method as generic as possible.

Specified by:
dasm in class Processor
Parameters:
instr - The instruction to be disassembled.
Returns:
This method returns the disassembled instruction.

setPC

public void setPC(int i)
Description copied from class: Processor
This method sets the current Program Counter.

Specified by:
setPC in class Processor

getPC

public int getPC()
Description copied from class: Processor
This method returns the current Program Counter.

Specified by:
getPC in class Processor
Returns:
This method returns the current Program Counter.

reset

public void reset()
Description copied from class: Processor
This method resets the processor. Classes which inherit from Processor may want to define their own processor-specifif reset() method, but it should call this methos first via super.reset().

Overrides:
reset in class Processor

statistics

public void statistics()
Description copied from class: Processor
This method keeps various statistics about the most recently exercuted instruction. This includes cycle counts, memory access profiling and instruction mix profiling.

Overrides:
statistics in class Processor

postLoad

public void postLoad()
Description copied from class: Processor
This method it used to perform any operations that may be required after a file is loaded. In the PowerPC, for instance, this method sets the TOC address for ELF files which use a TOC section. This method currently does nothing and must be overloaded by specific architectures.

Overrides:
postLoad in class Processor

instrMatch

public Instruction instrMatch(java.math.BigInteger instr,
                              int bits)
This method returns the instruction object from the instruction table associated with a given instruction.

Parameters:
instr - the instruction data.
bits - the number of bits in the instruction.
Returns:
This method returns the instruction object from the instruction table associated with a given instruction.

getNewInstruction

public Instruction getNewInstruction(long addr)
                              throws MemoryAccessException
This method gets and caches a new instruction.

Parameters:
addr - the address of the instruction.
Returns:
this method returns a nwly fetched instruction.
Throws:
MemoryAccessException - if an illegal memory acces is attempted.

getInstructionSizes

public int[] getInstructionSizes()
This method returns an array of integers containing the different instruction sizes in the model. The values are in bits.

Returns:
This method returns an array of integers containing the different instruction sizes in the model. The values are in bits.

dasm

public java.lang.String dasm(java.math.BigInteger instrData,
                             Instruction instr)
This method disassembles an instruction.

Parameters:
instrData - The instruction to be disassembled.
instr - The description of the instruction to be diassembled.
Returns:
This method returns a string representing the current instruction.

setBreakpoint

public void setBreakpoint(long addr)
                   throws MemoryAccessException
This method sets a breakpoint. Note that this is a 64-bit version of the legacy 32-bit breakpoint implementation.

Parameters:
addr - The address at which to set the breakpoint.
Throws:
MemoryAccessException - if an attempt is bade to set a breakpoint at an illegal memory address.

setBreakpoint

public void setBreakpoint(int addr)
                   throws MemoryAccessException
Description copied from class: Processor
This method sets a breakpoint.

Overrides:
setBreakpoint in class Processor
Parameters:
addr - The address at which to set the breakpoint.
Throws:
MemoryAccessException - if an attempt is bade to set a breakpoint at an illegal memory address.

removeBreakpoint

public void removeBreakpoint(long addr)
This method removes a breakpoint. If the breakpoint does not exist this method returns silently. Note that this is a 64-bit version of the legacy 32-bit breakpoint implementation.

Parameters:
addr - The address of the breakpoint.

removeBreakpoint

public void removeBreakpoint(int addr)
Description copied from class: Processor
This method removes a breakpoint. If the breakpoint does not exist this method returns silently.

Overrides:
removeBreakpoint in class Processor
Parameters:
addr - The address of the breakpoint.

getBreakpoints

public int[] getBreakpoints()
Description copied from class: Processor
This method returns an array of Integer objects that give the addresses of all set breakpoints.

Overrides:
getBreakpoints in class Processor
Returns:
This method returns an array of Integer objects that give the addresses of all set breakpoints.

removeAllBreakpoints

public void removeAllBreakpoints()
This method removes all breakpoints. Note that this is a 64-bit version of the legacy 32-bit breakpoint implementation.

Overrides:
removeAllBreakpoints in class Processor

isBreakpoint

public boolean isBreakpoint(long addr)
This method returns true if the address contains a breakpoint and a false otherwise. Note that this is a 64-bit version of the legacy 32-bit breakpoint implementation.

Parameters:
addr - The address of the breakpoint.
Returns:
This method returns true if the address contains a breakpoint and a false otherwise.

isBreakpoint

public boolean isBreakpoint(int addr)
Description copied from class: Processor
This method returns true if the address contains a breakpoint and a false otherwise.

Overrides:
isBreakpoint in class Processor
Parameters:
addr - The address of the breakpoint.
Returns:
This method returns true if the address contains a breakpoint and a false otherwise.

getInstruction

public byte[] getInstruction(int addr)
                      throws MemoryAccessException
Description copied from class: Processor
This method fetches an instruction from memory. Note that breakpoints are taken into account. If the instruction is a breakpoint, the actual instruction is fetched from the saved value in the breakpoint table. Note that this is generally for off-line use and not a replacement for the fetch() method.

Overrides:
getInstruction in class Processor
Parameters:
addr - The address at which to fetch the instruction.
Throws:
MemoryAccessException

getSymbolNames

public static java.lang.String[] getSymbolNames(Symbol[] symbols)
This method takes in a symbol table and returns an array of strings. Note that for symbols which may map to two or more values, the last entry in the table for that value is the string returned. This is useful for getting an array of strings used in defineRegisterNames().

Parameters:
symbols - An array of Symbols.
Returns:
this method returns an array of strings representing the symbols.

fetch

public Instruction fetch(Instruction instr)
                  throws MemoryAccessException
This method pre-fetches an instruction.

Parameters:
instr - The current instruction. May be null on start-up.
Returns:
The next instruction in sequence or the instruction pointed to by the current program counter is returned.
Throws:
MemoryAccessException - if an attempt is bade to set a breakpoint at an illegal memory address.

getInstructions

public Instruction[] getInstructions()
This method returns an array of the current instructions used by this model.

Returns:
This method returns an array of the current instructions used by this model.