DASM
Public Attributes | Private Attributes
DExec Class Reference

Execution system for the DCPU-16 processor. More...

List of all members.

Public Attributes

scalar O
 The indices of the registers in our 'registers' array.

Private Member Functions

Public Functions
retval new (scalar proto, scalar core)
 Construct a new assembler object.
retval DESTROY (scalar self)
 Destroy the object, implicitly ending all the hardware that wasn't stopped previously.
retval cycles (scalar self, scalar cycles)
 Increment the number of cycles taken.
retval instructions (scalar self)
 Return the number of instructions executed.
retval getword (scalar self, scalar addr)
 Get a word from the core.
retval getwordref (scalar self, scalar addr)
 Get a reference to a word from the core.
retval nextword (scalar self)
 Read PC and increment.
retval getoperand (scalar self, scalar operand)
 Get the value of an operand, given the operand value.
retval readref (scalar self, scalar ref)
 Read a value from a reference.
retval writeref (scalar self, scalar ref, scalar value)
 Write a value to a reference.
retval POP (scalar self)
 POP (unstack a value) from the full descending stack.
retval PUSH (scalar self)
 PUSH (stack a value) on to the full descending stack.
retval PEEK (scalar self)
 PEEK (look at the stack value) in a full descending stack.
retval start (scalar self, scalar pc)
 Start execution in the CPU.
retval stop (scalar self, scalar pc)
 Stop execution on a CPU.
retval runone (scalar self)
 Run a single instruction.
retval showregs (scalar self, scalar prefix)
 Show the current registers state.
retval getreg (scalar self, scalar reg)
 Read a named register.

Private Attributes

hash basicFuncs
 The functions to apply for every basic opcode.
hash extendedFuncs
 The functions to apply for every extended opcode.

Detailed Description

Execution system for the DCPU-16 processor.

This is a pretty simple interpreter for the core data.

We work on the principle that all operands are references. If an operand is read, we use the 'readref', and if the operand is written to we use the 'writeref'. The references may be to registers, or to core memory locations. They may also be objects which implement hardware, in which case their 'read' or 'write' functions are called.

Consequently some of the opcodes are implemented oddly. Where possible we try to keep to the same semantics such that any memory accesses will obey hardware mappings that might be present.

Actual hardware regions will be implemented by separate objects, and will be registered as part of hardware profiles. However, the hardware devices registered with the core will be copied from the DASM object if it is used to initialise the execution object. These hardware devices may provide poll() methods in order to provide regular updates of the devices, if necessary.

Typical use of this class might be:

   $dasm->readfile($infile);  # Assemble some code (or load a dump)

   # Resolve all the relocations
   die "Unresolved relocations" if (!$dasm->resolve($infile));

   $dexec = new DExec($dasm);
   $dexec->start(1);
   while (1)
   {
       $dexec->runone();
   }
   $dexec->stop();

Definition at line 90 of file DExec.pm.


Member Function Documentation

retval DExec::cycles ( scalar  self,
scalar  cycles 
) [private]

Increment the number of cycles taken.

Parameters:
[in]$selfDExec object
[in]$cyclesNumber of cycles consumed, or undef to read
Returns:
Total number of cycles.
retval DExec::DESTROY ( scalar  self) [private]

Destroy the object, implicitly ending all the hardware that wasn't stopped previously.

retval DExec::getoperand ( scalar  self,
scalar  operand 
) [private]

Get the value of an operand, given the operand value.

Parameters:
[in]$selfDExec object
[in]$operandOperand value
Returns:
$valref reference to the operand value, or an object to access value
Note:
Constants will still be returned as a reference (to a value that goes nowhere)
retval DExec::getreg ( scalar  self,
scalar  reg 
) [private]

Read a named register.

Parameters:
[in]$selfDexec object
[in]$regnamed register
Returns:
register value
retval DExec::getword ( scalar  self,
scalar  addr 
) [private]

Get a word from the core.

Any core values that haven't been assigned will return 0.

Parameters:
[in]$selfDExec object
[in]$addrAddress to read from
Returns:
value from the core
retval DExec::getwordref ( scalar  self,
scalar  addr 
) [private]

Get a reference to a word from the core.

Any core values that haven't been assigned will be assigned 0.

Parameters:
[in]$selfDExec object
[in]$addrAddress to read from
Returns:
reference to a value from the core
retval DExec::instructions ( scalar  self) [private]

Return the number of instructions executed.

Parameters:
[in]$selfDExec object
Returns:
Total number of instructions
retval DExec::new ( scalar  proto,
scalar  core 
) [private]

Construct a new assembler object.

Parameters:
[in]$protoThis class object, or prototype to add to
[in]$coreThe core to execute (may be a hashref of address=>value, or DASM object reference)
Returns:
Assembler object
retval DExec::nextword ( scalar  self) [private]

Read PC and increment.

Parameters:
[in]$selfDExec object
Returns:
value from the core and increment PC
retval DExec::PEEK ( scalar  self) [private]

PEEK (look at the stack value) in a full descending stack.

Parameters:
[in]$selfDExec object
Returns:
reference to the value popped
retval DExec::POP ( scalar  self) [private]

POP (unstack a value) from the full descending stack.

Parameters:
[in]$selfDExec object
Returns:
reference to the value popped
retval DExec::PUSH ( scalar  self) [private]

PUSH (stack a value) on to the full descending stack.

Parameters:
[in]$selfDExec object
Returns:
reference to the value popped
retval DExec::readref ( scalar  self,
scalar  ref 
) [private]

Read a value from a reference.

Parameters:
[in]$selfDExec object
[in]$refReference to read the value of
Returns:
value
retval DExec::runone ( scalar  self) [private]

Run a single instruction.

Parameters:
[in]$selfDExec object
retval DExec::showregs ( scalar  self,
scalar  prefix 
) [private]

Show the current registers state.

The registers will be listed, followed by value of the instruction at PC, and 'NX' if the 'no execute' flag has been set for the next instruction. Following the registers, the stack will be printed, ascending from SP to the top of memory.

Parameters:
[in]$selfDExec object
[in]$prefixPrefix for each line
retval DExec::start ( scalar  self,
scalar  pc 
) [private]

Start execution in the CPU.

Calls the hardware initialisation entry points, sets the PC to the requested value, and clears registers to their initial value. IF the CPU has already been started, the end() execution will be called for all the CPUs.

Parameters:
[in]$selfDExec object
[in]$pcPC to start at (defaults to 0)
retval DExec::stop ( scalar  self,
scalar  pc 
) [private]

Stop execution on a CPU.

Calls all the 'stop' entry points to stop the devices from running. Mostly this is intended to clear up their terminal controls, sync any buffered data and otherwise tidy up cleanly.

Parameters:
[in]$selfDExec object
retval DExec::writeref ( scalar  self,
scalar  ref,
scalar  value 
) [private]

Write a value to a reference.

Parameters:
[in]$selfDExec object
[in]$refReference to write to
[in]$valueValue to write

Member Data Documentation

hash DExec::basicFuncs [private]

The functions to apply for every basic opcode.

Each function is passed the DExec object, operand a and operand b.

Definition at line 100 of file DExec.pm.

hash DExec::extendedFuncs [private]

The functions to apply for every extended opcode.

Each function is passed the DExec object, and operand a.

Definition at line 106 of file DExec.pm.

scalar DExec::O

The indices of the registers in our 'registers' array.

Definition at line 94 of file DExec.pm.


The documentation for this class was generated from the following file: