It is now time to start deveoloping a dispatcher to control the excution of Units Of Work or executable tasks.  Each dispatchable unit of work will be defined by a control block we will call TCB.  It will contain status information about the unit of work and will be used to manage interrupts.  When an interrupt occurs the dispatcher will save the current environment (registers and PSW) into the active TCB.  A new unit of work can be dispatched by restoring the environment frrom a TCB.

A second control block will be used along side the TCB to manage unit of work execution.  It will function as a stack to manage levels of interirupts for a TCB.  This block will be the RB.  It will contain the PSW and Registers for a level of interruption under a TCB.

The RB is pretty simple containing the following data:

RBNEXT   DS    A     - Next RB for this TCB
RBWTCNT  DS    X     - Wait Count
RBPSW    DS    D     - PSW Contents
RBREGS   DS    16F   - Register Contents

The TCB is a little more complex and will contain the following data:

TCBNEXT  DS    A     - Next TCB in the dispatcher chain
*
TCBFLGS  DS    X     - Flags
TCBFWAIT EQU   X'80' - TCB waiting on ECB
TCBFNDSP EQU   X'40' - Do not dispatch
TCBFETS  EQU   X'20' - Exceeded Time Slice
TCBFLONG EQU   X'01' - Long Running Task
*
TCBFLGS2 DS    X     - Flags 2
*
TCBPRI   DS    X     - Execution Priority
TCBKEY   DS    X     - Execution Key
TCBECB   DS    A     - ECB to be Posted on Termination
TCBERC   DS    F     - Error/Return Code
TCBPSW   DS    D     - PSW
TCBREGS  DS    16F   - Registers

The TCB blocks will be maintained in a chain with each TCB pointing to the next ont he chain.  The end of the chain will be indicated with a null pointer.  The TCB on the chain is the Wait TCB.  It does not represent any actual work but becomes the active TCB when the CPU is in a wait state waiting on work to be performed.  The Wait TCB provides a place for the system status to be stored when an interrupt occurs and the CPU is waiting.

The flags indicate the dispatchability of the TCB.  If the TCB is waiting on an ECB the wait count field will be non-zero indicating the nubmer of events it is waiting on.  The Exceded Time Slice flag indicates the TCB did not give up control of the CPU unitl it was forced as a result of the timer expiring.  This flag indicates this TCB should not be dispatched again until no other work is waiting to be dispatched.

[Next – Nucleus Low Core]