DASM
|
Execution system for the DCPU-16 processor. More...
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. |
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();
retval DExec::cycles | ( | scalar | self, |
scalar | cycles | ||
) | [private] |
Increment the number of cycles taken.
[in] | $self | DExec object |
[in] | $cycles | Number of cycles consumed, or undef to read |
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.
[in] | $self | DExec object |
[in] | $operand | Operand value |
retval DExec::getreg | ( | scalar | self, |
scalar | reg | ||
) | [private] |
Read a named register.
[in] | $self | Dexec object |
[in] | $reg | named register |
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.
[in] | $self | DExec object |
[in] | $addr | Address to read from |
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.
[in] | $self | DExec object |
[in] | $addr | Address to read from |
retval DExec::instructions | ( | scalar | self | ) | [private] |
Return the number of instructions executed.
[in] | $self | DExec object |
retval DExec::new | ( | scalar | proto, |
scalar | core | ||
) | [private] |
Construct a new assembler object.
[in] | $proto | This class object, or prototype to add to |
[in] | $core | The core to execute (may be a hashref of address=>value, or DASM object reference) |
retval DExec::nextword | ( | scalar | self | ) | [private] |
Read PC and increment.
[in] | $self | DExec object |
retval DExec::PEEK | ( | scalar | self | ) | [private] |
PEEK (look at the stack value) in a full descending stack.
[in] | $self | DExec object |
retval DExec::POP | ( | scalar | self | ) | [private] |
POP (unstack a value) from the full descending stack.
[in] | $self | DExec object |
retval DExec::PUSH | ( | scalar | self | ) | [private] |
PUSH (stack a value) on to the full descending stack.
[in] | $self | DExec object |
retval DExec::readref | ( | scalar | self, |
scalar | ref | ||
) | [private] |
Read a value from a reference.
[in] | $self | DExec object |
[in] | $ref | Reference to read the value of |
retval DExec::runone | ( | scalar | self | ) | [private] |
Run a single instruction.
[in] | $self | DExec 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.
[in] | $self | DExec object |
[in] | $prefix | Prefix 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.
[in] | $self | DExec object |
[in] | $pc | PC 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.
[in] | $self | DExec object |
retval DExec::writeref | ( | scalar | self, |
scalar | ref, | ||
scalar | value | ||
) | [private] |
Write a value to a reference.
[in] | $self | DExec object |
[in] | $ref | Reference to write to |
[in] | $value | Value to write |
hash DExec::basicFuncs [private] |
hash DExec::extendedFuncs [private] |
scalar DExec::O |