Short overview of the Ring-1 Service Primitives =============================================== Timer service ************* Calling sequence: CALL SLEEP OCT (a tick is 0.1 sec) The task sleeps for the specified time and is restarted after the timer is due. The timer is released then. Timers are defined in the timer table CTAB. If a task requests the timer service, a free timer is allocated and connected to the task. Device management services ************************** Attach device(s) calling sequence: CALL ATTW (blocking) DAC TTY attention handler or CALL ATTW (blocking) OCT DEV (one or more devices) or CALL ATT (non blocking) OCT DEV (one or more devices) *** *** no success return *** *** success return Release device(s), calling sequence: CALL REL OCT DEV (one or more devices) To synchronize the use of peripherals between tasks, a task has to attach a peripheral when needed and release it again when not needed anymore. Up to 8 devices can be managed this way and each device is represented by a bit in the attachment state word: bits 9-13 FREE bit 14 PTP bit 15 PTR bit 16 TTY The TTY is an exception. It can be attached two times; in the normal way (bit16) and to a so called attention handler. When attached to an attention handler, and the attention handler is activated (by pressing the ESC key), the normal attachment is overruled. The attention handler gets the TTY (e.g. for command handling) and the TTY usage of the task, to which the TTY is attached in the normal way, is stalled. A release call with octal 0, releases the TTY from an activated attention handler. With this release the attention handler becomes a 'normal' task, which can attach/release the TTY in the normal way. Input/Output services ********************* *** ASRI, read char from TTY; calling sequence: CALL ASRI switch TTY input mode *** *** returns here with the next char from the TTY in a-reg *** ASRO, print char on TTY; calling sequence: LDA CHAR a = char to print on tty CALL ASRO sets TTY in output mode *** *** returns here *** PTRI, read character from PTR (high speed papertape reader) calling sequence: CALL PTRI *** *** returns here with he next char in a-reg *** PTPO, punch character from PTP (high speed papertape puncher) calling sequence: LDA CHAR a = char to punch CALL PTPO *** *** returns here Task synchronization services ***************************** Two types of task synchronization are supported: 1) With task-linked events 2) Soft-events, operating as counting semaphores Task-linked events can be used to wait for exit of a specific task or on a signal from a specific task. When a task executes another task with the EXEW primitive, the calling task is blocked until the executed task exits, or provides a signal (SIG-0). If the task is started with the EXE primitive, the calling task is not blocked, but still can execute a wait for the earlier started task. In case the started task did not exit yet, the calling task is blocked and unblocked by the exit of the started task (or by a SIG-0 of the started task). In the same way a task can wait for exit or a SIG-0 of any other specific task. Soft-events are controlled by 3 primitives: WAIT (semaphore down), SIGNAL (semaphore up) and RSIG (reset/init the signal with an initial count). Soft-events are identified by a number, starting with number 1 (event 0 is the task-linked event; each task has its own event 0: SIG-0). Allocation of a soft-event for a specific purpose is to be done by the programmer; the soft-events are not managed as resources by the system. RSIG 1 initializes a binary semaphore which can be used to control a critical section. Maximum number of supported soft-events is octal 77; the maximum initial value of a soft-event can be octal 77. *** WAIT for an event; calling sequence: 1) Wait for task exit or on a SIG-0 of a task CALL WAIT DAC TCB (TCB address of the task to wait for) 2) Wait for a soft-event (semaphore down) CALL WAIT OCT XX (soft-event number, 1-max '77) *** SIGNAL an event; calling sequence: 1) Signal task event CALL SIGNAL OCT 0 (referring to the task-linked event) 2) Signal a soft-event CALL SIGNAL OCT XX (soft-event number 1-max '77) *** REVENT - reset soft event, set initial count Calling sequence: CALL REVENT OCT XXYY (bits 5-16) where XX = initial count YY = soft event number Task management services ************************ *** Task execution 1) Exec task and wait for exit; calling sequence: CALL EXEW DAC TCB (TCB address of the task to start) The starting task (='parent') is blocked and unblocked after exit of the started (='child') task (or by a SIG-0 of the started task). The devices attached to the starting task (='parent') are also attached to the started task (='child') and not released when the started task exits. 2) Exec task; calling sequence: CALL EXE DAC TCB (TCB address of the task to start) The calling task is not blocked (so remains ready); no attached devices of the starting task are attached to the started task. If the task to start is already started, the starting task is blocked until the task to start can be started. 3) Exit the current task; calling sequence: CALL EXIT Signals exit and releases (still) attached devices not attached to the parent task, if the task was started by EXEW. At kernel level, the TCB is not cleared, so the task can be restarted with EXE or EXEW (the task must then of course be able to reinit itself). 4) Kill another task; calling sequence: CALL KILL DAC TCB (TCB address of the task to kill) Independent of its state, the task is killed, an event the task was waiting for is cleared, exit is signaled and (still) attached devices, not attached to the parent task, if the task was started by EXEW, are released. At kernel level, the TCB is not cleared, so the task can be restarted with EXE or EXEW(the task must then of course be able to reinit itself). 5) Suspend another task, calling sequence: CALL PAUSE DAC TCB (TCB address of the task to suspend) PAUSE suspends a task and the task's devices are released for use by other tasks. An active attention handler can not be suspended (a passive attention handler, which is a task waiting for an attention event, can be suspended, but the attention event activates the attention handler). 6) Resume a suspended task, calling sequence: CALL RESUME DAC TCB (TCB address of the task to resume) *** no success return address (released devices can not be reattached) *** success return RESUME reactivates a suspended task after reattachment of the released devices with the SUSPEND. 7 Task rescheduling YIELD, leave the current task, and schedule the next ready task CALL YIELD (the current task remains ready) The task scheduler (Ring-1) =========================== The scheduler is a simple round robin scheduler and runs the tasks in Ring-2 depending on their state: - task not started (stop) 0000000000000000 - task started, not waiting for event (ready) 0000000000000001 - task started, waiting for event (blocked) 1000000000000001 A task is blocked when waiting for: - IO event (signaled by an interrupt handler) - Task event (signaled by exit or SIG-0 of the task waiting for) - Timer event (signaled by RTC interrupt handler) - Attention event (signaled by TTY interrupt handler) When a task is blocked, the PWEV entry in the task's TCB points to the event the task is waiting for. The scheduler runs at Ring-1 and has the following entry points for Ring-1 code: SKED - scheduler entry point after initialization RESH - enable interrupt and schedule the next ready task BLOK - set task waiting for an event, and schedule the next ready task BUSY - task pending for a condition, schedule next ready task SAVE - inhibit interrupt and save CPU state in TCB of current task These entry points must be entered with a JMP! Each task in Ring-2 is presented to the scheduler by a data structure: the Task Control Block (TCB). The location T always points to the TCB of the current running task. Task Control Block structure STAT EQU 0 task state LABL EQU 1 address where task must continue (P) A EQU 2 saved A B EQU 3 saved B X EQU 4 saved X KEYS EQU 5 saved keys STRT EQU 6 task start address TEVT EQU 7 task event DEV EQU 8 attached devices PWEV EQU 9 pointer to event blocked for