The Dispatcher looks at the list of TCB’s on the work queue and selects one to become the active task. If there are no TCB’s ready to dispatch an enabled wait will be entered.
000000 6 TXXDISP CSECT , 000000 18CF 7 LR R12,R15 ESTABLISH 00000 8 USING TXXDISP,R12 BASE REG 9 * 000002 1F11 10 SLR R1,R1 CLEAR TIME EXPIRED SWITCH 11 * 000004 58B0 0010 00010 12 L R11,16 GET CVT ADDRESS 00000 13 USING @CVT,R11 14 * 000008 5840 B004 00004 15 L R4,CVTTASKQ START AT TOP OF TASK QUEUE 16 * 00000 17 USING @TCB,R4 18 * 00000C 19 DISP010 DS 0H 00000C 91D0 4004 00004 20 TM TCBFLGS,TCBFWAIT+TCBFNDSP+TCBFETS DISPATCHABLE? 000010 4780 C05C 0005C 21 BZ DISP050 YES - GO RUN IT 22 * 000014 9110 4004 00004 23 TM TCBFLGS,TCBFETS TIME EXPIRED FOR THIS TASK? 000018 47E0 C020 00020 24 BNO DISP020 NO - BRANCH 25 * 00001C 4110 0001 00001 26 LA R1,1 SET EXPIRED SWITCH 000020 27 DISP020 DS 0H 000020 5840 4000 00000 28 L R4,TCBNEXT POINT TO NEXT TCB 000024 1244 29 LTR R4,R4 END OF CHAIN 000026 4770 C00C 0000C 30 BNZ DISP010 LOOP BACK 31 * 00002A 1211 32 LTR R1,R1 ANY TIME EXPIRED TASKS 00002C 4780 C06A 0006A 33 BZ DISP060 NO - GO INTO WAIT
The Dispatcher starts at the top of the TCB queue. It looks for a TCB that is eligible to be dispatched. If a TCB is found it becomes the current TCB and control is passed to that task. While scanning the queue a switch is set if any TCB on the queue is not dispatchable because it was interrupted by the timer task. If no any TCB’s were found that were not dispatched because of the time exceeded flag, the dispatcher will clear these bits and allows the TCB’s to be dispatched.
000030 5840 B004 00004 35 L R4,CVTTASKQ LOAD TOP OF TASK QUEUE 000034 36 DISP030 DS 0H 000034 94FE 4004 00004 37 NI TCBFLGS,X'FF'-TCBFLONG CLEAR LONG RUNNING FLAG 38 * 000038 9110 4004 00004 39 TM TCBFLGS,TCBFETS TIME EXPIRED FOR THIS TASK? 00003C 47E0 C048 00048 40 BNO DISP040 NO - BRANCH 41 * 000040 94EF 4004 00004 42 NI TCBFLGS,X'FF'-TCBFETS CLEAR FLAG 000044 9601 4004 00004 43 OI TCBFLGS,TCBFLONG SET LONG RUNNING FLAG 44 * 000048 45 DISP040 DS 0H 000048 5840 4000 00000 46 L R4,TCBNEXT NEXT TCB ON CHAIN 00004C 1244 47 LTR R4,R4 END OF CHAIN 00004E 4770 C034 00034 48 BNZ DISP030 NO - LOOP BACK 49 * 000052 5840 B004 00004 50 L R4,CVTTASKQ POINT TO TOP OF QUEUE 000056 1F11 51 SLR R1,R1 CLEAR SWITCH 000058 47F0 C020 00020 52 B DISP020 LOOK AGAIN FOR WORK
Here the Dispatcher loops through the TCB queue resetting time exceeded bit. If the TCBFETS flag is reset in a TCB, the TCBFLONG bit is set. This bit will not make the task non-dispatchable. It only indicates the TCB had previously been prohibited from dispatch. Once the entire queue has been scanned the main dispatcher loop is once again entered to select a task for dispatch.
00005C 58 DISP050 DS 0H 00005C 5040 B000 00000 59 ST R4,CVTCTCB 000060 58F0 0014 00014 60 L R15,20 MVT ADDRESS 000064 58F0 F008 00008 61 L R15,MVTLLDSP-@MVT(,R15) LLDISP ROUTINE 000068 07FF 62 BR R15
Once a TCB is selected for dispatch the address of the TCB is stored in the CVT at CVTCTCB (current TCB). Control is then passed the the Low Core Dispatch routine in low memory to restore the registers and PSW from the TCB.
00006A 68 DISP060 DS 0H 00006A 5840 B004 00004 69 L R4,CVTTASKQ WAIT TASK 00006E 5040 B000 00000 70 ST R4,CVTCTCB MAKE IT CURRENT TASK 000072 8200 C078 00078 71 LPSW DISPWPSW ENABLED WAIT 000078 75 DS 0D 000078 FF0200000000FEAD 76 DISPWPSW DC AL1(255,2,0,0),A(X'FEAD') ENABLED WAIT PSW
If no TCB is available for dispatch the dummy Wait Task TCB is made the current TCB and an enabled wait is entered. The dummy Wait Task TCB is needed so that when an interruption occurs while in the disabled wait there will be a TCB for the interrupt handler to store registers and the PSW. Although this information is saved at the interrupt, it is never used since the Wait Task is always associated with the enabled wait PSW.
[Next – TXXDINIT – Dispatcher Initialization ]