         PCC      0
         TITLE    'SCHEDULER REFS AND DEFS'
UFLAGS   SET      1
         SYSTEM   UTS
***********************************************************************
*M*      SCHED - EXECUTION SCHEDULER
***********************************************************************
         SPACE    2
         DEF      SCHED:            PATCHING DEF
SCHED:   RES
***********************************************************************
*P*      NAME: SCHED
*P*      PURPOSE: SCHEDULES USERS FOR EXECUTION.  ALSO HANDLES
*P*               TRAP AND INTERRUPT EXITS.
*P*      ENVIRONMENT: SCHED EXECUTES MASTER MODE BOTH MAPPED
*P*               AND UNMAPPED. SCHED MUST BE LOCATED BELOW
*P*               X'8000' IN THE MONITOR ROOT.
***********************************************************************
         SPACE    2
*        ORIGINAL IMPLEMENTATION FOR UTS BY:
*                                             G. A. PERRY
*                                             H. L. SCANTLIN
*
*        SPEED-UP ENHANCEMENTS BY: T. W. MARTIN
*
*        MULTI-PRIORITY SCHEDULING FOR REAL TIME BY:
*                                             R. I. HUSTVEDT
*
         PAGE
***********************************************************************
*                 EXTERNAL DEFINITIONS
***********************************************************************
         DEF      ADD1              ADD A USER TO THE SYSTEM
         DEF      ALTERR            STACK PROBLEM FOR ALTERNATE ENTRY
         DEF      BLCKD:MASK        MASK FOR BLOCKED STATES
         DEF      CHKPROT           CHECK PROTECTION TYPE ON GIVEN ADR
         DEF      CHSE0             CHANGE STATE EXECUTABLE SUB-ENTRY FOR MPSCHE
         DEF      CLK4              ENTRY POINT FOR QUANTUM CLK=ZERO
         DEF      DASP              DECR USE CNT FOR ASP
         DEF      DDB               DECREMENT DEBUGGER
         DEF      DELTAGO           ENTER DEBUGGER(NORMAL)
         DEF      DELTAGOT          SPEC TRAP ENTRY TO DEBUGGER
         DEF      DOV               DECREMENT MON OVERLAY
         DEF      DPROCS            DECR USE CNT FOR PROCESSORS
         DEF      DRTEL1            DECR USE COUNT FOR COMMAND PROC
         DEF      DTEL              DEC USE CNT FOR COMMAND PROC
         DEF      DTORP             DECR TEL OR PROCS
         DEF      EXU:MASK          MASK REPRESENTING EXU STATES
         DEF      GETJIT            RECYCLE ENTRY TO ADD1
         DEF      IDB               INC USE CNT FOR DEBUGGER
         DEF      IOV               INCR MON OVERLAY
         DEF      IOWAIT:MASK       MASK FOR I/O WAIT STATES
         DEF      IPROCS            INC USE COUNT FOR PROCESSORS
         DEF      ISTEL1            INCR USE COUNT FOR COMMAND PROC
         DEF      ITEL              INCR COMMAND PROCESSOR
         DEF      ITORP             INCR COMMAND PROC OR PROCESSORS
         DEF      REG1              ENTRY FROM REG1PSD
         DEF      S:SET:            PATCHING SYMBOL FOR S:SET
         DEF      SB:SET:           PATCHING SYMBOL FOR SB:SET
         DEF      SB:SWP:           PATCHING SYMBOL FOR SB:SWP
         DEF      SEXU              EXECUTABLE STATE NUMBER
         DEF      SE7A              SLAVELINE BREAK; R0=LINE NUMBER
         DEF      SNSTS             HIGHEST STATE NUMBER
         DEF      SNULL             NULL STATE FOR UNUSED USER ENTRIES
         DEF      SSE0              ENTRY TO T:SSE TO AVOID SWAP SCHED
         DEF      SSE40             PATH TO PULLE FOR RTROOT
         DEF      STIOCC            IO COMPLETE TRANSITION
         DEF      T:ACCTOV          SAME AS T:SSEM
         DEF      T:CHS             CHANGE STATE(NON-EXECUTABLE)
         DEF      T:DLR1            ALTERNATE RETURN FOR DO-LIST
         DEF      T:DOLISTR         RETURN FROM DOLIST ROUTINE
         DEF      T:IOREG           ENTRY TO BLOCK FOR I/O WAIT
         DEF      T:PULLE           PULL ENVIRONMENT AND EXECUTE
         DEF      T:RCE             REPORT EVENT FOR COC LINE
         DEF      T:RE              REPORT EVENT FOR CURRENT USER
         DEF      T:REG             REPORT EVENT AND GIVEUP CONTROL
         DEF      T:RUE             REPORT EVENT FOR SPECIFIED USER
         DEF      T:SE              SCHEDULE EXECTION
         DEF      T:SSE             PULLE AFTER SCHEDULER CHECKS
         DEF      T:SSEC            SAME AS T:SSE FOR TOD CLOCK
         DEF      T:SSEM            SAME AS TRAPEXIT BUT NO PSD BUMP
         DEF      T:TOTSZ           DETERMINE USER'S PHYSICAL SIZE
         DEF      T:UTSXTS          MOVE ENVIRONMENT TO TCB TEMPSTK
         DEF      TRAPEXIT          BUMP PSD AND PULLE AFTER SCHED CHKS
         DEF      WAIT:MASK         MASK REPRESENTING WAIT STATES
         PAGE
***********************************************************************
*                 EXTERNAL REFERENCES
***********************************************************************
         REF      ACTIVATE          PM ROUTINE TO MEASURE RESPONSE
         REF      ADJSTCNT          ADJUST COUNT FOR GRAN STACK
         REF      ALLOOUT           ALLOCAT OUTSWAP REQ FLAG
         REF      ALLOQ             TELL ALLYCAT TO QUIESCE
         REF      BOTTOM            PTR TO BOTTOM OF GRAN STK
         REF      BUFLAGS           FLAGS FOR GRAN STACK
         REF      BUFMASK           CONSTANT TO RESET FLAGS
         REF      C:IDLE            COUNTER FOR PURE IDLE TIME
         REF      C:IDLES           COUNTER FOR SWAP WAIT
         REF      C:IDLESW          IDLE WITH SWAP AND I/O WAIT COUNTER
         REF      C:IDLEW           IDLE WITH I/O WAIT COUNTER
         REF      C:SCHED           COUNT OF SCHEDULES
         REF      C:TINC            CLOCK 3 COUNTER CELL
         REF      DCT14             TO SEE IF ANY I/O IS ACTIVE
         REF      CLK4PSD           PSD FOR QUAN CLK=ZERO INTERRUPT
         REF      COCOFF            COC ROUTINE TO MARK LINE OFF
         REF      DCT24             DEVICE PARTITIONED FLAG
         REF      ERO               ERO FIELD IN JIT
         REF      GOODNGT           ZAP FLAG SET BY KEYIN
         REF      DUSK              ZAP COUNTER
         REF      J:ABC             ABORT CODE IN JIT
         REF      J:ACCN            ACCOUNT FIELD IN JIT
         REF      J:CTIME           I/O COMPENSATORY TIME COUNT
         REF      J:DELTAT          NEG QUANTUM REMAINING
         REF      J:IDELTAT         INITIAL VALUE OF J:DELTAT
         REF      J:INTENT          USER BREAK ENTRY ADDRESS
         REF      J:JAC             ACCESS IMAGE IN JIT
         REF      J:JIT             BASE ADDRESS OF JIT
         REF      J:OVHTIM          SERVICE TIME IN CURRENT QUANTUM
         REF      J:RNST            RUN STATUS FLAGS
         REF      J:TCB             ADDRESS OF TASK CONTROL BLOCK
         REF      J:TELFLGS         COMMAND PROCESSOR FLAGS
         REF      J:TIMENT          STIMER ENTRY ADDRESS
         REF      J:UTIMER          TIME REMAINING FOR STIMER
         REF,1    JB:FRS            FINAL RUN STATUS
         REF      JOVVPA            VP START OF OVERLAY AREA
         REF      JTSTACKSZ         SIZE OF JIT TSTACK
         REF      M:FREE#GRAN       GRANS REMAINING ON SWAPPER
         REF      M:JITPAGE         PAGE NUMBER FOR NEXT JIT
         REF      MAXG              MAX NUMBER OF GHOSTS IN SYSTEM
         REF      MB:SPACEJIT       SPACE INCREMENT FOR JIT ALLOCATION
         REF      MB:SDI            SWAP DCT INDEX TABLE
         REF      MX:PPUT           MONITOR PHYSICAL PAGE TABLES
         REF      M21               CONSTANT X'001FFFFF'
         REF      M24               CONSTANT X'00FFFFFF'
         REF      M7                CONSTANT X'0000007F'
         REF      M8                CONSTANT X'000000FF'
         REF      NB31TO0           TABLE OF INVERTED BITS
         REF      NSCPU             NO. OF SLAVE CPUS IN SYSTEM
         REF      NSWAP             NO. OF SWAPPERS IN SYSTEM
         REF      OPNCLSUS          OPEN/CLOSE USER
         REF      PB:LCT            COUNT OF ASSOC LOCKED USERS
         REF      PB:PSZ            PROCEDURE SIZE
         REF      PB:UC             USER COUNT
         REF      PULLE1            TEMP DOUBLEWORD FOR T:PULLE
         REF      PULL11B           PULL R11; B *R11
         SREF     RAPURGE           PURGE TIMED READ-AHEAD PAGES
         REF      REGIPSD           PSD FOR IOREG(MAPPED)
         REF      REG1PSD           XPSD TARGET FOR T:REG
         REF      S:ACCW            ACCESS LOADING CONTROL WORD
         REF      S:CLOCK4          CLOCK4 COUNTER DIRECTOR
         REF      S:CUIS            CURRENT TOTAL USERS IN SYSTEM
         REF      S:CUN             CURRENT USER NUMBER
         REF      S:CUP             CURRENT USER PRIORITY
         REF      S:EVF             SCHEDULER RE-ENTRANCY COUNTER
         REF      S:HIR             COUNT OF HI-PRIO IN-CORE USERS
         REF      S:ISUNF           ISUN AT SWAP SCHED FAIL
         REF      S:MAPCW           MAP LOADING CONTROL WORD
         REF      S:OPC             OVERLAY PROTECTION COUNTER
         REF      S:OUAIS           ON-LINE USERS IN SYSTEM
         REF      S:OUIS            ON-LINE USERS IN SYSTEM
         REF      S:PNO             CPU # CELL (0 THRU 3)
         REF      S:PRIODEC         PRIORITY DECREMENT
         REF      S:RTCORE          TOTAL OF REAL TIME HOLD PAGES
         REF      S:RTIR            REAL TIME IN FLAG
         REF      S:SEVF            SWAP SET CHANGE COUNTER
         REF      S:SIP             SWAP IN PROGRESS FLAG
         REF      S:SJACCW          SPEC JIT ACCESS CONTROL WORD
         REF      SACT              SYMBIONT ACTIVATOR
         REF      SB:GJOBUN         USER NO FOR GHOST JOBS
         REF      SB:HQ             STATE QUEUE HEADS
         REF      SB:RQ             HEAD OF RESOURCE SUBQ
         REF      SB:RQT            TAIL OF RESOURCE SUBQ
         REF      SB:TQ             STATE QUEUE TAIL
         REF      SETRNST           SET J:RNST AND ABORT USER
         REF      SH:PINC           PRIORITY INCREMENT TABLE
         REF      SL:BIMF           RESTART THRESHOLD FOR MASTER FUNC CNT
         REF      SL:OIMF           SAME AS BIMF FOR ONLINE
         REF      SL:OPRIO          DEFAULT ONLINE PRIORITY
         REF      SL:QMIN           MINIMUM QUANTUM
         REF      SL:RSVP           COUNT OF PAGES RESERVED FOR STEALER
         REF      SL:SQNT           THRESHOLD AT WHICH TO EXPEDITE USER
         REF      SL:SQPB           PRIO BOOST IF INTERRUPT AFTER SQNT
         REF      SL:SQUAN          SWAP QUANTUM(CORE QUANTUM)
         REF      SNDDX             NUMBER OF SYMBIONT DEVICES
         REF      SPDBASE           SPEC PROC DATA BASE ADDRESS
         REF      SPPBASE           SPEC PROC PROCEDURE BASE ADDRESS
         REF      SSIG              SYMBIONT DEVICE SIGNAL FLAGS
         REF      SSTAT             SYMBIONT STATUS TABLE
         REF      SWAPIN            SWAP A USER IN
         REF      SWAPOUT           OUTSWAP A LIST THEN SWAPIN
         REF      SYSACT            CONSTANT ':SYS    '
         REF      T:ABORTM          ABORT A USER
         REF      T:ACCTEX          ACCOUNT FOR EXEC TIME IN CUR QUAN
         REF      T:DELUSZAP        DELETE USER (CTXT SWAP ERROR)
         REF      T:ECCP            CNTL-Y ENTRY TO COMMAND PROCESSOR
         REF      T:MASTER          CHECK FOR MASTER AND CLR MASTERO
         REF      T:MSTR            2NDARY ENTRY TO T:MASTER
         REF      T:PAC
         SREF     T:SQEND           CHECK SLAVE QUANTUM END
         REF      T:SCRATCH%USER    SCRATCH USER(SWAP ERROR)
         REF      T:SES             SCHEDULE SLAVE CPUS
         REF      T:SEXIT           SWAPPER EXIT
         REF      T:SGAJIT          ALLOCATE JIT GRANULE CLUSTER
         REF      T:SMPFLG          SET MASTER ONLY FLAG
         REF      T:SS              SWAP SCHEDULER
         REF      T:TELDELCCI       ENTER COMMAND PROC OR DEBUGGER
         REF      TEMPBOT           PTR TO TEMP BOTTOM OF GRAN STK
         REF      TQUNMAP           UNMAP BUT DONT ENABLE
         REF      U:MISC            MISC CELL FOR RESOURCE SUB-QUEUES
         SREF     U:CALC            CAL COUNT
         REF      UB:ACP            ASSOCIATED COMMAND PROCESSOR NO
         REF      UB:APO            ASSOC PROC OVERLAY NUMBER
         REF      UB:APR            ASSOCIATED PROCESSOR
         REF      UB:ASP            ASSOC SPECIAL PROCESSOR
         REF      UB:BL             STATE CHAIN BLINK
         SREF     UB:CALR           CAL RATE (TICS/CAL)
         REF      UB:DB             DEBUGGER
         REF      UB:FL             STATE CHAIN FLINK
         REF      UB:MF             MASTER FUNCTION COUNT
         REF      UB:OV             MONITOR OVERLAY NUMBER
         REF      UB:PCT            USER PAGE COUNT
         REF      UB:PRIO           USER EXECUTION PRIORITY
         REF      UB:PRIOB          BASE EXECUTION PRIORITY
         REF      UB:SWAPI          SWAPPER INDEX
         REF      UB:US             CURRENT STATE
         REF      UH:AJIT           AJIT DISC ADDRESS
         REF      UH:DL             HEAD OF DO-LIST
         REF      UH:FLG            USER FLAGS
         REF      UH:FLG2           SECOND USER FLAGS
         REF      UX:JIT            JIT PHYS PAGE NUMBER
         REF      WORDCNT           WORD COUNT IN GRAN STACK
         REF      XFFF              CONSTANT X'00000FFF'
         REF      XN2               CONSTANT X'FFFFFFFE'
         REF      X1                CONSTANT X'00000001'
         REF      X1FE00            CONSTANT X'0001FE00'
         REF      X20               CONSTANT X'00000020'
         REF      X4000             CONSTANT X'00004000'
         REF      X8                CONSTANT X'00000008'
         REF      YFF               CONSTANT X'FF000000'
         REF      Y004              CONSTANT X'00400000'
         REF      Y008              CONSTANT X'00800000'
         REF      Y4                CONSTANT X'40000000'
         REF      Y7D               EXPONENT FOR FLOATING SHIFT
         REF      Y7F               CONSTANT X'7F000000'
         REF      Y8                CONSTANT X'80000000'
         PAGE
***********************************************************************
*                 SECONDARY REFERENCES
***********************************************************************
         SREF     COC:BRK
         SREF     COC:BRKLTR
         SREF     COC:RDCOMP
         SREF     COCUNMAP          SETUP FOR CALLING COCOFF
         SREF     ECBFBLK           ENTRY POINT TO FREE DO LIST BLOCKS
         SREF     LB:UN             LINE TO USER NO TABLE
         SREF     MODE5             CHECK FOR SLAVE COC LINE
         SREF     LNOL              NO OF LINES
         SREF     RESCNCT           EXISTS ONLY IN 560 SYSTEMS
         SREF     RT:INTENTRY       PERFORM RT ENTRY FOR INTERRUPT
         SREF     T:ECBSTORE        STORE ECB INFO IN USER
         PAGE
M12      EQU      XFFF
XFDFF    EQU      NB31TO0+14
XFFEF    EQU      NB31TO0+5
XFFF7    EQU      NB31TO0+4
OPNCLSUSR EQU     8                 USER IS OPNCLS USER
SPECFILE EQU      4
OPNBOOST EQU      X'04'             PRIORITY BOOST FOR OPNCLSUS
SQUAN    EQU      8                 UH:FLG2 NOT HAD SWAP QUAN BIT
SWAPD    EQU      16                UH:FLG2 JUST SWAPPED IN
RTHOLD   EQU      X'800'            UH:FLG2 REAL TIME OLD
CALINT   EQU      X'200'            UH:FLG2 INTERRUPTED IN A CAL
RMAHOLD  EQU      X'2000'           UH:FLG2 RMA HOLD IN CORE
HANGUP   EQU      X'20'             UH:FLG2 COC LINE HANG UP
BYPASS   EQU      X'8000'           UH:FLG SWAP BYPASS FOR PAGE STEALING
INHIBIT  EQU      2                 UH:FLG INTENTRY INHIBIT
NREADY   EQU      XN2               UH:FLG MASK TO RESET RTR
         TITLE    'S T A T E   D E F I N I T I O N S'
*
*STATE  NOS
STATE    CNAME
         PROC
ST%      SET      ST%+1
LF       EQU      ST%
         DISP     ST%
         DEF      LF
         PEND
********************************************************************
*
*        DEFINE STATE VALUES
*
*        ORDERING OF EXECUTABLE STATES IS CRITICAL
*
*        STATES STI,STIO STOB,STOBO SQR,SQRO MUST BE PAIRED
*        THIS IS USED BY THE KICKOUT ROUTINE TO COMPUTE THE
*        OUT OF CORE STATE.
*
********************************************************************
ST%      SET      0
*
SRT      STATE                      REAL TIME EXECUTE
SC0      STATE                      BGRD X'BF'< PRIO < X'F6'
SC1      STATE                      PRIO = X'F6'
SC2      STATE                      PRIO = X'F7'
SC3      STATE                      PRIO = X'F8'
SC4      STATE                      PRIO = X'F9'
SC5      STATE                      PRIO = X'FA'
SC6      STATE                      PRIO = X'FB'
SC7      STATE                      PRIO = X'FC'
SC8      STATE                      PRIO = X'FD'
SC9      STATE                      PRIO = X'FE'
SC10     STATE                      PRIO = X'FF'
SEXU     EQU      ST%               LAST EXECUTABLE STATE
SCU      STATE                      CURRENT USER
********************************************************************
*        THESE STATES MUST BE PAIRED (STOB,STOBO)
*
STOB     STATE                      TERMINAL OUTPUT BLOCKED
STOBO    STATE                      TERMINAL OUTPUT BLOCKED - OUT
******************************************************************
*        SIOW AND SIOMF MUST BE ADJACENT STATES
*        AND SIOW MUST BE EVENLY DIVISIBLE BY 4
*
SIOW     STATE                      I/O WAIT
SIOMF    STATE                      MASTER FUNCTION COUNT TOO HIGH
******************************************************************
SW       STATE                      WAIT (ASLEEP)
SQA      STATE                      QUEUED FOR ACCESS
******************************************************************
*        THESE STATES MUST BE PAIRED (SQR,SQRO)
*
SQR      STATE                      QUEUED FOR RESOURCE
SQRO     STATE                      QUEUED FOR RESOURCE OUT OF CORE
******************************************************************
*        THESE STATES MUST BE PAIRED (STI,STIO)
*
STI      STATE                      TERMINAL INPUTTING
STIO     STATE                      TERMINAL INPUTTING - OUT
******************************************************************
SQFI     STATE                      QUEUED FOR INTERRUPT
SNULL    EQU      30                NULL STATE FOR EMPTY USER SLOTS
SNSTS    EQU      31                NUMBER OF STATES
******************************************************************
*
*        LIST OF EXECUTABLE STATES FOR STATE EVENT
*        TRANSITION TABLE FORMATION.
*
EXECUTE  EQU      SRT,SC0,SC1,SC2,SC3,SC4,SC5,SC6,SC7,SC8,SC9,SC10
******************************************************************
*
MASK     CNAME
         PROC
TEMP     SET      0
I        DO       NUM(AF)
TEMP     SET      TEMP|1**AF(I)
         FIN
LF       DATA     TEMP
         PEND
*
*
*
EXU:MASK     MASK SRT,SC0,SC1,SC2,SC3,SC4,SC5,SC6,SC7,SC8,SC9,SC10,SCU
WAIT:MASK    MASK SW,SQFI
IOWAIT:MASK  MASK STOB,STOBO,SIOW,STI,STIO
BLCKD:MASK   MASK SIOMF,SQA,SQR,SQRO
*
         PAGE
*
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
         PAGE
*
* EVENT  NOS
*
         BOUND    8
C3MP     GEN,10,22  1,CK3UM1
         DATA     X'17000000'
19SPD    DATA     TSTACK+1+19       TSTACK SPD WITH 19 WORDS IN IT.
         GEN,16,16 JTSTACKSZ-19,19   (MUST BE ON DW BOUNDARY).
SMPSD    DATA     X'00C00000'       PSD WHICH SAYS SLAVE, MAPPED,
         DATA     0                   WK=0.
TEL      RES      0
         TITLE    'EVENT DEFINING PROCEDURES'
         PAGE
*
* TRANSITION TABLES
*
SB:SET   CSECT    0                 BYTE TABLE GIVING OPERATION TO BE
SB:SET:  EQU      SB:SET
*                                   DONE GIVEN EVENT AND STATE
S:SET    CSECT    0                 WORD TABLE CORRESPONDING TO SB:SET
S:SET:   EQU      S:SET
*
*        THESE PROCS DEEFINE EVENT STATE RELATIONSHIPS
*
*        THE EVENT NUMBER IS THE STARTING POSITION IN
*        S:SET AT WHICH TO BEGIN THE SEARCH FOR A STATE MATCH
*        THE RESULT OBTAINED FROM SB:SET WILL BE EITHER A STATE
*        NUMBER IF LESS THAN X'20' OR A DISPLACEMENT FROM
*        S:TRNSVEC.  AN ERROR WILL BE FLAGGED IF THE OFFSET FROM
*        S:TRNSVEC IS TOO LARGE(>X'E0').
*
ESTS     CNAME    0                 NO CONTINUATION
ESTS1    CNAME    1                 CONTINUATION
         PROC
U        SET      %                 REMEMBER CURRENT CS POSITION
         USECT    S:SET
         DO       NAME
P        SET      X'80000000'       SET CONTINUATION BIT(BIT 0)
         ELSE
P        SET      0
         FIN
LF       EQU      %-S:SET
         DEF      LF
         DO       SCOR(AF(2),ALL)
P        SET      P|X'7FFFFFFF'
         ELSE
I        DO       NUM(AF)-1
P%       SET      AF(I+1)
I%       DO       NUM(P%)
P        SET      P|(1**P%(I%))
         FIN
         FIN
         FIN
         DATA     P                 GENERATE S:SET WORD
         USECT    SB:SET
         DO       TCOR(AF(1),S:RAD,S:SUM,S:EXT,S:FR,S:LFR)>0
P        SET      AF(1)-S:TRNSVEC+X'20'
         ERROR,7,P>X'FF' 'SPECIAL TRANSITION ROUTINE TOO FAR FROM',;
                  ' S:TRNSVEC'
         DATA,1   P
         ELSE
         DATA,1   AF(1)
         FIN
         USECT    U
         PEND
         PAGE
*
*        THIS PROC DEFINES THE EVENTS FOR BLOCKING ON
*        UNAVAILABLE RESOURCES AND RESTARTING WHEN RELEASED
*        EACH CALL DEFINES TWO EVENTS; THE BLOCK EVENT(LF(1))
*        AND THE UNBLOCK EVENT(LF(2)).
*        FLAGS MAY BE SPECIFIED FOR EACH RESOURCE DEFINING
*        WHETHER OR NOT TO CHANGE STATE UPON THE RECEIPT OF
*        AN ERR,ABRT,EC OR BRK.  ANOTHER FLAG PERMITS THE ENTIRE
*        SUB-QUEUE TO BE FLUSHED WHEN AN UNBLOCK EVENT IS REPORTED.
*        A FLAG WILL ALTER THE MEANING OF THE UNBLOCK EVENT SUCH
*        THAT THE USER TO BE UNBLOCKED IS THAT FOR WHOM THE
*        EVENT IS REPORTED.  NORMALLY THE USER NUMBER ASSOCIATED
*        WITH THE UNBLOCK REPORT IS IGNORED AND THE CORRECT USER
*        NUMBERS ARE OBTAINED FROM THE RESOURCE SUB-QUEUE.
*
*
*        OPTIONAL EXITS ARE PROVIDED AT BOTH BLOCK AND UBLOCK
*        EVENTS TO PERFORM SPECIAL CHECKING ETC.
*
*E:BLK,E:REL RESOURCE       RTBLK,RTREL,FLAGS
*
RESOURCE CNAME    0
         PROC
U%       SET      %
         USECT    SB:RBLK
CF(2)    EQU      BA(%)-BA(SB:RBLK)
         DEF      CF(2)
         DATA,1   AF(1)-T:BLKV
         USECT    SH:RFLG
         DATA,2   (AF(2)-T:RELV)+AF(3)
LF(1)    ESTS     T:RES,SCU
LF(2)    ESTS     T:RES,ALL
         USECT    U%
         PEND
*
*        BLOCK CALLS SHOULD ONLY BE MADE VIA T:REG
*        RELEASE EVENTS MAY BE REPORTED VIA T:RUE OR T:RE
*
SB:RBLK  CSECT    0
SH:RFLG  CSECT    0
*
*
         OPEN     EC,BRK,ABRT,ERR,FLUSH
ABRT     EQU      X'8000'           ABORT FLAG
ERR      EQU      X'4000'           ERR FLAG
EC       EQU      X'2000'           CONTROL-Y FLAG
BRK      EQU      X'1000'           BREAK FLAG
SPECIFIC EQU      X'100'            SPECIFIC USER ONLY
FLUSH    EQU      X'200'            FLUSH ALL
NULL     EQU      X'400'            DO RELEASE ACTION IF NULL QUEUE
*
ESTS2    CNAME
         PROC
         BOUND    4
LF       EQU      %
         DEF      LF(1)
T%T      SET      0,AF,0
I        DO       (3+NUM(T%T))/4
II       SET      1+(4*(I-1))
         GEN,8,8,8,8 T%T(II),T%T(II+1),T%T(II+2),T%T(II+3)
         FIN
         BOUND    4
         PEND
         TITLE    'STATE - EVENT TRANSITION TABLES'
*
* STATE  EVENT TRANSITIONN TABLES.   FISRT ARGUMENT  OF PROC  IS
*        ACTION TO TAKE. OTHER ARGS ARE THE STATES,
*        GIVEN THE EVENT, THAT SHOULD CAUSE THE ACTION
*******************************************************************
*
*        THESE EVENTS(E:IIP,E:QMF) MUST APPEAR FIRST AND IN THIS  ORDER
*
*
E:IIP    ESTS     STIIP,SCU
E:QMF,E:IP ESTS   STIOMF,SCU
*
*
*
*******************************************************************
*
E:CRD    ESTS     STCRD,SCU         TERMINAL READ EVENT
*
*        REPORTED BY: COC
*
*******************************************************************
*
*
E:CIC    ESTS1    STIRC,STI,STIO    TERMINAL INPUT COMPLETE
         ESTS     STIRCU,SCU        TERMINAL INPUT COMPLETE FOR CU
*
*        REPORTED BY: COC
*
*        SPECIAL CASE REQUIRED TO HANDLE COMPLETION BEFORE E:CRD
*        IS REPORTED.
*
*******************************************************************
*
*
E:CBL    ESTS     STOB,SCU          TERMINAL OUTPUT BLOCK
*
*        REPORTED BY: COC
*
*******************************************************************
*
*
E:CUB    ESTS1    STOC,STOB,STOBO   TERMINAL OUTPUT CONTINUE
         ESTS     STNOP,EXECUTE,SCU,STI,SW,SIOW,SIOMF,SQA,SQR,;
                  STIO,SQFI
*
*        REPORTED BY: COC
*
*******************************************************************
         PAGE
*******************************************************************
*
*        WARNING: THE EVENT E:CBK MUST BE AN EVEN NUMBER AND
*                 MUST BE FOLLOWED BY THE EVENTS E:CEC,E:ERR
*                 AND E:OFF IN THAT ORDER.
*
*                 THE SEQUENCE OF EVENT NUMBERS IN THIS SERIES
*                 WILL BE USED TO SELECT PROPER FLAG BITS FOR UH:DL
*
*
*******************************************************************
*
*
E:CBK    ESTS1    STBEEA,SCU,SIOW,SIOMF,SQA,SQR,SQRO,SNULL
         ESTS     STBEEAC,EXECUTE,SW,STI,STIO,STOB,STOBO,SQFI
         LIST     0
         ERROR,7,1&E:CBK         'E:CBK MUST BE AN EVEN NUMBERED EVENT'
         LIST     1
*
*        REPORTED BY: COC
*
*******************************************************************
*
*
E:CEC    ESTS1    STBEEA,SCU,SIOW,SIOMF,SQA,SQR,SQRO,SNULL
         ESTS     STBEEAC,EXECUTE,SW,STI,STIO,STOBO,SQFI,STOB
*
*        REPORTED BY: COC
*
*******************************************************************
*
*
E:ERR    ESTS1    STBEEAC,EXECUTE,SW,SQFI
         ESTS     STBEEA,SCU,SIOW,STOB,STOBO,SIOMF,;
                  SQA,SQR,SQRO,SNULL,STIO,STI
*
*        REPORTED BY: KEYIN
*
*******************************************************************
*
*
E:OFF,E:ABRT ESTS1 STBEEAC,EXECUTE,SW,STI,STIO,SQFI,SQA
         ESTS     STBEEA,SCU,SIOMF,SIOW,STOB,STOBO,SQR,SQRO,;
                  SNULL
*
*        REPORTED BY: COC,KEYIN
         LIST     0
U%       SET      (2=(E:CEC-E:CBK))&(2=(E:ERR-E:CEC))&(2=(E:OFF-E:ERR))
         ERROR,7,0=U% 'E:CBK,E:CEC,E:ERR AND E:OFF MUST APPEAR IN ORDER'
         LIST     1
*
*******************************************************************
*
*
E:WU     ESTS1    STSC,SW,SQFI      WAKE UP
*
*        REPORTED BY: CLOCK4
*
         ESTS     STNOP,ALL         IGNORE
*******************************************************************
*
*
E:SL     ESTS     SW,SCU            SLEEP
*
*        REPORTED BY: UCAL,RBBAT,TYPR
*
*******************************************************************
*
*
E:QA     ESTS     STQA,SCU          Q FOR ACCESS
*
*        REPORTED BY: COOP
*
*******************************************************************
*
*
E:ART    ESTS1    STNOP,SCU,SIOW,SIOMF,SQR,SQRO,SQA,STI,STOB,STIO,;
                  STOBO,SNULL
         ESTS     STSCOM,SQFI,SW,EXECUTE
*
*        REPORTED BY: RTROOT
*
*******************************************************************
*
*
E:UQA    ESTS1    STUQA,SQA,SIOW,SCU,EXECUTE
         ESTS     STNOP,ALL
*
*        REPORTED BY: RBBAT
*
*******************************************************************
*
*
E:KO     ESTS1    STKO,SW,SQFI,EXECUTE,SQA,SIOMF,SIOW
         ESTS     STKOT,STOB,STI,SQR
*
*        REPORTED BY: SWAPPER
*
*******************************************************************
*
*
E:AP,E:NC ESTS    STASP,SCU         ASSOCIATE SHARED PROCESSOR
*
*        REPORTED BY: E:NC - MM
*                     E:AP - STEP,SCHED,UCAL
*
*******************************************************************
*
*
E:QE     ESTS     STSCOM,SCU
*
*        REPORTED BY: LBLT(MOVE CAL)
*
*******************************************************************
E:IC     ESTS     STIOC,ALL         I/O COMPLETE
E:QFI    ESTS     SQFI,SCU          QUEUE FOR INTERRUPT
E:REL    EQU      E:NSYMF           BASE EVENT FOR RESOURCES
E:NSYMF,E:SYMF RESOURCE,R:SYMF T:BLKV,T:RELV,FLUSH
E:NSYMD,E:SYMD RESOURCE,R:SYMD T:BLKV,T:RELV,FLUSH
E:OCR,E:NOCR   RESOURCE,R:OCR T:BLKV,OPNUNBLOCK
E:CFB,E:CBA    RESOURCE,R:CBA T:BLKV,T:RELV,FLUSH
E:ND,E:DPA     RESOURCE T:BLKV,T:RELV,FLUSH
E:QFAC,E:UQFAC RESOURCE T:BLKV,UQFAC,FLUSH+NULL
E:NQW,E:NQR RESOURCE,R:NQW  T:BLKV,T:RELV,ERR+ABRT+EC+BRK+SPECIFIC
         TITLE    'U S E R    F L A G     T A B L E S'
*
*        FIRST HALF WORD OF USER FLAGS
*
*
* UH:FLG |---------------------------------|
*        |        |       |    1 1|1 1 1 1 |
*        | 0 1 2 3|4 5 6 7|8 9 0 1|2 3 4 5 |
*        |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
*          | | | | | | | | | | | | | | | |
*          | | | | | | | | | | | | | | | > READY -READY TO RUN
*          | | | | | | | | | | | | | | > INTENTRY INHIBIT(RT)
*          | | | | | | | | | | | | | > :ACCTLG OR :USERS OPEN
*          | | | | | | | | | | | | > OPNCLS USER
*          | | | | | | | | | | | > PPSWAP-PURE PROCEDURE MUST BE SWAPPED
*          | | | | | | | | | | > INTERACTIVE USER
*          | | | | | | | | | > DELIC -DELTA IS IN CONTROL
*          | | | | | | | | > TELIC -TEL IS IN CONTROL
*          | | | | | | | > BATJOB-JOB IS A BATCH JOB
*          | | | | | | > JITIC -JIT IS IN CORE
*          | | | | | > DELASS-DELTA IS ASSOCIATED
*          | | | | > INIT -INITIALIZATION MUST BE DONE
*          | | | > SPEC. JIT ACCESS
*          | | > DCBS - INITIAL DCBS ARE BEING SWAPPED IN
*          | > STEP IN PROGRESS OR UNBLOCK RECEIVED BEFORE BLOCK EVENT
*          > BYPASS - AVAILABLE CORE IS TEMPORARILY TOO SMALL FOR USER
*
         PAGE
*
*        SECOND HALF-WORD OF USER FLAGS
*
*        FLAGS IN THIS GROUP ARE MOSTLY SWAPPER RELATED
*
*
* UH:FLG2|---------------------------------|
*        |        |       |    1 1|1 1 1 1 |
*        | 0 1 2 3|4 5 6 7|8 9 0 1|2 3 4 5 |
*        |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
*          | | | | | | | | | | | | | | | |
*          | | | | | | | | | | | | | | | > JIT SWAP ERROR
*          | | | | | | | | | | | | | | > CONTEXT SWAP ERROR
*          | | | | | | | | | | | | | > USER SWAP ERROR
*          | | | | | | | | | | | | > SWAP QUANTUM NOT SATISFIED
*          | | | | | | | | | | | > JUST SWAPPED IN
*          | | | | | | | | | | > COC LINE HANG-UP
*          | | | | | | | | | > 9
*          | | | | | | | | > 8
*          | | | | | | | > TP FUNCTION
*          | | | | | | > INTERRUPTED DURING A CAL
*          | | | | | > SYSTEM GHOST LOCKED OUT (REAL TIME LOCK IN CORE)
*          | | | | > REAL TIME LOCK IN CORE (ABSOLUTE)
*          | | | > COC EVENT FOR TRANSACTION PROCESSING
*          | | > LOCK IN CORE FOR RMA (GENTLE)
*          | > COMMAND PROCESSOR BREAK
*          > 0
         PAGE
*
*        'DO' LIST POINTER - POINTS TO THE HEAD OF A SERIES OF
*                            LINKED FOUR WORD ENTRIES DEFINING
*                            SPECIAL ACTION TO TAKE WHEN RESCHEDULING
*                            USER OR EXITING A CAL.
*
*        FLAGS FOR ERROR, ABORT, CONTROL-Y AND BREAK ARE CONTAINED IN
*        BITS 0-3.
*        BITS 1,2, AND 3 ALL ON INDICATES DATA OVERUN WHILE THIS JOB WAS
*        CURRENT USER.
*
*
* UH:DL  |---------------------------------|
*        |        |       |    1 1|1 1 1 1 |
*        | 0 1 2 3|4 5 6 7|8 9 0 1|2 3 4 5 |
*        |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
*          | | | |
*          | | | | <..... DA(DO LIST) .....>
*          | | | |
*          | | | > BRK - BREAK RECEIVED
*          | | > EC - CONTROL-Y RECEIVED
*          | > ERR - JOB IS TO BE ERRORED
*          > ABORT - JOB IS TO BE ABORTED
*          \>>>DAOV-JOB IS TO BE PUT TO SLEEP
*
         PAGE
*
* LISTS OF Q'S FOR SELECTIONS
*
* Q'S TO CHOSE EXECUTION FROM
         BOUND    4
SB:SWP   ESTS2    SW,SC10,STI,STOB,SQR,SQFI,SQA,SC9,SC8,SC7,;
                  SC6,SC5,SC4,SC3,SC2,SC1,SC0,SRT
         TITLE    'REPORT EVENT AND GIVE UP'
SB:SWP:  EQU      SB:SWP
         USECT    TEL
         BOUND    4
*
*        T:IOREG IS ENTERED VIA AN XPSD TO REGIPSD WITH
*                THE DCB ADDRESS IN R6.
*
*        ALL REGISTERS ARE PRESERVED.
*
*        DEPENDING ON CIRCUMSTANCE, THE USER MAY BE
*        SUSPENDED OR PERMITTED TO CONTINUE.
*
T:IOREG  PUSH     6,13              SAVE REGS
         LD,0     REGIPSD           GET CALLING PSD
         BAL,2    T:SAVE            SAVE ENVIRONMENT
         LI,1     X'1FFFF'          SCRUB DCB ADDRESS
         AND,1    6                 GET DCB ADDRESS
         LI,6     E:IIP             IO IN PROGRESS EVENT
         B        REG2              REPORT IT
         TITLE    'EXIT PATH CHECKS'
         SPACE    3
PULLEU   BDR,0    T:PULLE           BRANCH IF ENV IN MAPPED STACK
         LI,1     T:PULLE           SET RETURN TO PULL EXIT
         B        TQUNMAP           UNMAP BUT DONT ENABLT INTS
         SPACE    3
SSE39    LH,R15   UH:FLG,R4
         CI,R15   INHIBIT+DIC+TIC   CHECK FOR INHIBIT
         BAZ      SSE11             NONE
         B        SSE411            YES...IGNORE ITEM
         SPACE    4
SSE40    LI,R0    SSE41             SET MAPPED STACK FLAG
SSE41    DISABLE                        **** INHIBIT ****
         LH,R5    UH:DL,R4          GET DO-LIST
         AND,R5   M12               CLEAR FLAGS
         BEZ      SSE411            NOTHING TO DO
         LD,R6    0,R5              GET 1ST ITEM
         LB,R15   R6                GET PRIO
         CB,R15   UB:PRIOB,R4       IS IT IMPORTANT?
         BLE      SSE39             YES
SSE411   SW,R13   U:MISC,R4         NO...COMPUTE  TIME SINCE SCHEDULED
         CW,R13   S:RTIR            AND CHECK FOR QMIN
*                                   S:RTIR WILL BE SET ZERO IF A
*                                   REAL TIME USER IS WAITING
         BL       PULLEU            NOT HAD IT AND NO RT USER WAITING
         LW,R15   SL:QMIN           RESET FLAG TO NORMAL QMIN VALUE
         STW,R15  S:RTIR            SINCE WE MAY HAVE HAD A RT USER
SSE42    LW,15    S:HIR
         BLEZ     PULLEU            NO HIGHER PRIORITY DUDES
         BDR,0    SSE43
         LI,0     SSE43             RETURN
*
*        MOVE USER'S ENVIRONMENT FROM UNMAPPED STACK
*        TO USER'S JIT BEFORE PARKING HIM.
*
*        R0 - LINK
*        R4 - USER NUMBER (PRESERVED)
*        ALL OTHER REGISTERS VOLATILE
*
*        EXITS MAPPED
*
SSE12    UNMAP
         LOAD,2   UX:JIT,4
         SLS,2    9
         LI,3     X'1FF'            MASK FOR PAGE DISP
         AI,2     TSTACK-J:JIT
         LI,8     19
         MSP,8    *2
         LS,2     0,2
         LI,3     -17
         AI,2     -17
         AW,3     TSTACK
         LCI      10
         LM,5     *M24,3
         STM,5    *M24,2
         LCI      9
         LM,5     9,3
         STM,5    9,2
         LD,8     *3
         BUMP     -19,5
         STD,8    *2
         LW,1     0
         B        MAP
SSE43    RES      0
         DISABLE                                 ***** DISABLE *****
         LB,R3    UB:US,R4          GET CURRENT STATE
         LB,R2    UB:PRIO,R4        GET CURRENT PRIO
         CW,R4    Y4                TEST FOR BOOST FLAG
         BAZ      %+2               NO, DONT ADD PRIO BOOST
         SW,R2    SL:SQPB           ADD SWAP QUAN THRESH BOOST
         BAL,R11  CHSE0             AND PARK HIM
T:SEO    UNMAP                      SCHEDULE EXECUTION ONLY
         B        SEO               NO SWAP SCHEDULE NEEDED ON PARK
         TITLE    'TRAP AND INTERRUPT EXITS'
*************************************************
*                                               *
*            INTERRUPT EXIT POINTS              *
*                                               *
*            T:SSE - ALL INTERRUPTS BUT         *
*                    CLOCK 3                    *
*                                               *
*            T:SSEC - CLOCK 3                   *
*                                               *
*************************************************
T:SSEC   EQU      %
T:SSE    EQU      %
         LI,11    SSE0              SET RETURN FROM T:SS
         B        T:SS              SWAP SCHEDULE
         PAGE
*************************************************
*                                               *
*         CAL AND TRAP EXIT POINT               *
*                                               *
*        TRAPEXIT - BUMPS RETURN ADDRESS        *
*                   IN PSD                      *
*                                               *
*        T:SSEM - PSD IS ALREADY CORRECT        *
*                                               *
*************************************************
*                                               *
*        SSE0 - ALTERNATIVE TO T:SSE FOR        *
*               I/O INTERRUPT TO AVOID          *
*               SUPERFLUOUS SWAP SCHEDULE       *
*                                               *
*************************************************
TRAPEXIT LI,1     -17               POINT BACK TO
         AW,1     TSTACK             PSD IN ENVIRONMENT
         AND,1    XN2               SCRUB OFF TO DOUBLE WORD BOUND
         MTW,1    0,1               ADVANCE TO CAL PLUS ONE
T:ACCTOV EQU      %
         LW,R2    S:PNO             GET OUR PROCESSOR #
         MTW,1    C:SCHED,R2        COUNT CALS COMPLETED BY CPU #
         LI,R2    SSE1              RETURN LINK FROM T:MSTR
         B        T:MSTR            CHECK FOR IMMEDIATE PULLE
T:SSEM   EQU      %
SSE0     BAL,2    T:MASTER          CHECK FOR IMMEDIATE PULLE
SSE1     LAW,0    J:JIT             CHECK FOR UNMAPPED
         BNE      SSE11             MAPPED
         MAP                        GO MAPPED IF WE WERE UNMAPPED
SSE11    RES      0
         LW,4     S:CUN             GET CURRENT USER NUMBER
         LB,R1    J:RNST            GET RUN STATUS. CHECK IT AND
         CH,R1    UH:DL,R4          USER'S DO-LIST FOR THINGS TO DO.
         BCR,7    SSE5A             ---> NO ABNS OR DO-ITEMS (BOTH=0).
         LI,2     JB:FRS            GET FINAL RUN STATUS INDEX
         STB,1    0,2               SAVE RUN STATUS IN JIT FOR
*                                   ACCTSUM
         BDR,0    %+2               CHECK FOR UNMAPPED ENV
         BAL,0    SSE12             MOVE ENV FROM MTS TO UTS
         DISABLE                          ***** DISABLE *****
         LH,5     UH:DL,4           GET DO LIST
T:DOLIST EQU      %
*-----------------------------------*
         BLOCK
*-----------------------------------*
         LH,R15   UH:FLG,R4         GET USER'S FLAGS IN R15.
         STH,R5   R13               R13(0-3)= ABRT,ERR,YC,BRK FLAGS.
         AND,5    M12               CLEAR FLAGS
         STH,5    UH:DL,4           REPLACE
         LC       13                GET FLAGS TO CONDITION CODES
         BCS,8    SEABRT            ABORT
         BCS,4    SEOVRUN           CHECK FOR DATA OVERUN USER
         LB,1     J:RNST
         BEZ      SSE8
         LI,2     X'FF'
         AND,2    J:JIT+ERO
         LB,14    J:ABC
         STB,2    14
         CI,15    TIC
         BAZ      T:TELDELCCI
SSE8     LC       13                GET FLAGS AGAIN
         BCS,2    SE9               CONTROL-Y
         BCS,1    SE7               BREAK
         AI,5     0                 CHECK FOR DOLIST ITEMS
         BEZ      SSE5              NO
         LD,6     0,5               GET FIRST DW OF ENTRY
         LB,0     6                 GET PRIORITY
         CB,0     UB:PRIOB,4        CHECK IT
         BG       SSE5              NOT NOW
         LH,1     6                 GET TYPE
         AND,1    M7                SCRUB
         CI,1     INTENT            CHECK FOR INTENTRY
         BNE      DOL1              NO
*        NOTE THAT CONTENT OF UH:FLG IS IN R15
         CI,R15   INHIBIT+TIC+DIC   ARE INTERRUPT ENTRIES ALLOWED
         BANZ     SSE5              NO
*                                   ALL OK, GO DO IT
         AND,R6   M12               SCRUB TO FLINK
DOL1     STH,R6   UH:DL,R4          STORE
         B        DOLV,1            SWITCH ON TYPE
DOLV     EQU      %-1               DO LIST TYPE VECTOR
         B        T:ECBSTORE        1 => STORE ECB IN USER
INTENTL  B        RT:INTENTRY       2 =.> INTERRUPT ENTRY
INTENT   EQU      INTENTL-DOLV      INTENTRY CODE
         B        COC:BRK           3 =.> SLAVELINE BREAK.
         B        COC:RDCOMP        4 =.> SLAVELINE READ COMPLETE.
         B        COC:BRKLTR        5 =.> SLAVELINE BREAK LATER.
*
         DATA     0                 6 =*** UNUSED & ILLEGAL; SUA.***
*
         B        *R7               7 =.> SPECIAL ACTION ROUTINE.
*
*        DO-LIST PROCESSING ROUTINES ARE CALLED WITH:
*                 R4 = S:CUN (CURRENT USER NUMBER).
*                 R5 = DA(DO-LIST BLOCK).
*                 R6/7 = FIRST DW OF DO-LIST BLOCK.
*                         (EXCEPT FOR R/T INTENTRY ROUTINE)
*                 R15 = UH:FLG (USER'S FLAGS).
*        REGISTERS 4 AND 5 MUST BE PRESERVED BY PROCESSING ROUTINE.
*        PROCESSING ROUTINE SHOULD RETURN TO T:DOLISTR.
*
T:DOLISTR EQU     %                 RETURN FROM DO LIST PROCESSOR
         LD,6     0,5               GET FIRST DW AGAIN
         CW,6     Y008              TEST INHIBIT RELEASE BIT
         BANZ     T:DLR1            SET, DONT RELEASE
         LW,2     5                 POINT TO BLOCK
         SLS,2    1                 WORD ADDRESS
         BAL,1    ECBFBLK           RETURN BLOCK TO POOL
T:DLR1   RES      0
         DISABLE                           ***** DISABLE *****
         LH,5     UH:DL,4           GET DO LIST AGAIN
         BNE      T:DOLIST          DO IT
SSE5     LI,0     4                 SET DONT-COPY-CONTEXT FLAG AGAIN.
SSE5A    EQU      %
         LW,R13   S:PNO             WHAT CPU # ARE WE NOW
         BNEZ     T:SQEND           CHECK FOR QUANTUM END ON SLAVE
         ENABLE                     WE'RE A MASTER- CHECK TIMES
         LW,13    J:DELTAT
         AW,13    J:OVHTIM
         AW,13    J:CTIME
         SW,13    J:IDELTAT
         DISABLE                              ***** INHIBIT *****
         LH,R14   UH:FLG2,R4        GET SECOND USER FLAGS
         CI,R14   SQUAN             CHECK FOR ALREADY PAST SQUAN
         BAZ      SSE6              YES, SKIP
         CW,R13   SL:SQNT           ARE WE NEARING THE END OF SQUAN?
         BL       SSE6              NO
         OR,R4    Y4                SET FLAG TO TRIGGER PRIO BOOST
         CW,13    SL:SQUAN
         BL       SSE6              NOT HAD SQUAN YET
         MTW,+1   S:SEVF            SWAP SET CHANGED
         AND,R14  XFFF7             RESET SQUAN FLAG
         STH,R14  UH:FLG2,R4        AND SAVE NEW FLAGS
         AND,R4   M8                RESET BOOST FLAG
SSE6     ENABLE                               ***** ENABLE *****
         AW,R13   J:IDELTAT         NOW CHECK FOR QUANTUM END
         BLZ      SSE41             NOT YET
         BDR,R0   %+2               CHECK FOR ENV IN UNMAPPED JIT
         BAL,R0   SSE12             YES, MOVE TO USER JIT
         BAL,R3   T:ACCTEX          GIVE NEW QUAN
         LW,4     S:CUN             RESTORE CURRENT USER NUMBER
         DISABLE                                 ***** DISABLE ****
         LB,3     UB:US,4           GET UUSERS CURRENT STATE
         LH,15    UH:FLG,4          GET USER FLAGS.
         LW,R11   S:OPC             CHECK FOR SWAP PROBLEM
         BGEZ     SSE7              NONE, JUST NORMAL PARK
         LW,R2    S:ISUNF           GET FAILING INSWAP USER
         LW,R11   S:CUP             GET CURRENT USER PRIO
         CB,R11   UB:PRIO,R2        AND COMPARE WITH INSWAP CANDIDATE
         BLE      SSE7              WE ARE EQUAL OR BETTER
*
*        IN ORDER TO PERMIT THE SWAP SCHEDULER TO PROPERLY
*        OBSERVE PRIORITIES, WE WILL MARK THE CURRENT USER
*        WHO HAS JUST QUANTUM-ENDED AS NOT READY-TO-RUN
*        WHICH WILL FORCE HIM THROUGH AN I/O-LESS INSWAP.
*
         AND,R15  NREADY            RESET READY-TO-RUN FLAG
         LH,R14   UH:FLG2,R4
         CI,R14   RTHOLD            IS HE R/T LOCKED-IN-CORE?
         BANZ     %+2               YES
         STH,R15  UH:FLG,R4         NO...SAVE UPDATED FLAGS
SSE7     RES      0
         MTW,+1   S:SEVF            BUMP SWAP SET CHANGE CTR
         BAL,11   T:CHSE0           TAIL OF HIS COMPUTE Q
*        B        T:SE              FALL THROUGH TO SCHEDULE
*
*
*        USER HAS QUANTUM ENDED AND BEEN DROPPED BACK TO HIS
*        BASE EXECUTION PRIORITY.
*
         TITLE    'E X E C U T I O N    S C H E D U L E R'
T:SE     EQU      %
         SPACE    1
***************************************************
*                                                 *
*             SCHEDULE FOR EXECUTION              *
*                                                 *
*        BOTH A SWAP SCHEDULE ATTEMPT AND         *
*        A CALL TO SACT ARE MADE BEFORE           *
*        SCHEDULING ANOTHER USER.                 *
*                                                 *
***************************************************
         SPACE    1
         UNMAP
         BAL,11   T:SS
         BAL,11   SACT              GOOSE THE SYMBIONTS
SEO      BAL,R11  T:SES             SCHEDULE EXECUTION FOR SLAVES
         LI,15    1
         LW,R14   S:EVF             GET EVENT FLAG COUNTER
         REF      M6
         LD,2     SB:HQ             GET FIRST SEVEN STATES
         BEZ      SEF1              NONE, SKIP FIRST SEVEN
         OR,2     Y7D               SET EXPONENT FOR FLOATING SHIFT
         SFL,2    16                DO NORMALIZE TO FIND FIRST FULL STATE
         SCS,2    7                 COUNT=COUNT/2
         AND,2    M6                SCRUB
         EOR,2    M6                INVERT TO FORM INDEX
         B        %+2
SEF1     LI,2     8                 START WITH EIGHTH STATE
SIC1     RES      0
         LB,4     SB:HQ,2           GET HEAD OF STATE QUEUE
         BEZ      SIC3
SIC2     CH,15    UH:FLG,4          IN CORE?
         BANZ     SE1               IF SO LETS RUN HIM
         LB,R4    UB:FL,R4          NEXT USER IN QUEUE
         BNEZ     SIC2
SIC3     AI,2     1                 NEXT STATE
         CI,2     SEXU              ONLY LOOK AT EXU STATES
         BLE      SIC1              CONTINUE
         LI,1     X'FF'             CLEAR CURRENT PRIORITY
         STW,1    S:CUP             FOR S:HIR TESTS
         LI,0     %+3               SET RETURN
         LI,2     RAPURGE
         BNEZ     0,2               GO RELEASE READ-AHEAD PAGES IF POSSIBLE
         LW,1     S:CUIS
         AW,1     GOODNGT
         BG       IDL1
         MTB,0    DCT14             ANY DEVICES ACTIVE?
         BNEZ     IDL1              IF SO DON'T TERMINATE YET
         LI,1     3                 USER # OF RBBAT
SLEEPY   LB,3     UB:US,1           GET USER'S STATE
         CI,3     SNULL             IS SYSTEM GHOST NONEXISTANT?
         BE       %+3               IF SO, OK TO SHUT DOWN
         CI,3     SW                IS SYSTEM GHOST SLEEPING?
         BNE      IDL1              IF NOT, DON'T GO COMATOSE
         BDR,1    SLEEPY            CHECK NEXT GHOST
         LB,5     SNDDX
         AI,5     -2
IDL0     EQU      %
         LB,7     SSTAT,5
         BEZ      %+3
         CI,7     1
         BE       IDL1
         LB,7     SSIG,5
         CI,7     'I'
         BE       IDL1
         BDR,5    IDL0
         LD,0     WORDCNT           IF ALLYCAT HASNT EMPTIED THE STACKS
         BEZ      %+4               TELL HIM TO DO SO
         LI,14    X'50000'
         BAL,4    ALLOQ
         B        T:SE
         MTW,-1   DUSK              COUNT DOWN TIMER (10 SEC FOR COC
         BGZ      IDL1              OUTPUT) AND IDLE IF NOT DONE.
*                                   TO PERMIT COC OUTPUT
         SCREECH  X'404'
IDL1     EQU      %
         ENABLE
         LW,1     S:SIP             CHECK FOR SWAP IN PROGRESS
         LH,2     SB:HQ+(SIOW/4)    CHECK FOR BOTH KINDS OF I/O WAIT
         BEZ      %+2               NO I/O WAIT
         AI,1     2                 SET I/O BIT
         LH,0     C:IDL,1           GET COUNTER ADDRESS
         LF       F:IDL,1           SET FLOATING MODE BITS
         STW,R0   S:CLOCK4          SET CLOCK TO ACCOUNT IDLE
         LW,0     C:TINC            CHECK TIME OF DAY CLOCK
         BG       %+3               -POSITIVE,YUP AOK
         LI,5     X'80'             -NEG,BAD  SO
         WD,5     X'1700'           ... TRIGGER HIM
*                                   FALL THROUGH TO IDLE LOOP
         PAGE
***********************************************************************
*                                                                     *
*                    I D L E     L O O P                              *
*                                                                     *
*              THE REASON FOR BEING IDLE IS DISPLAYED                 *
*              IN THE FLOATING MODE CONTROL BITS OF                   *
*              THE PROGRAM STATUS DOUBLEWORD:                         *
*                                                                     *
*                  F  F  F                                            *
*                  S  Z  N                                            *
*                  -  -  -                                            *
*                  1  0  0     =>    PURE IDLE, NOTHING TO DO
*                  0  0  1     =>    IDLE WITH SWAP IN PROGRESS       *
*                  0  1  1     =>    IDLE WITH I/O AND SWAP IN PROGRESS
*                  1  1  0     =>    IDLE WITH I/O IN PROGRESS        *
*                                                                     *
***********************************************************************
         SPACE    2
         WAIT,0   0                 *** IDLE LOOP ***
         SPACE    2
*                                   DRIVEN OUT OF WAIT BY INTERRUPTS
*                                   AT LEAST EVERY 2 MILLISECONDS
*                                   FALLING THROUGH TO SCHEDULE FOR
*                                   BOTH SWAPS AND EXECUTION
         B        T:SE              GO SCHEDULE AGAIN
         SPACE    1
C:IDL    DATA,2   C:IDLE,C:IDLES,C:IDLEW,C:IDLESW
F:IDL    DATA,1   4,1,6,3
         TITLE    'PLACE USER IN EXECUTION'
SE1      EQU      %                RETURN HERE FROM SIC WITH A USER
*
**************************************************
*                                                *
*             LOAD MAP AND ACCESS                *
*                                                *
**************************************************
         SPACE    2
         STW,R4   S:CUN             DECLARE CURRENT USER NUMBER
         LOAD,11  UX:JIT,4          GET JIT PAGE NUMBER
         SLS,11   9                 AND MAKE IT WORD ADDRESS
         LD,8     S:ACCW            GET SKELETON CW FOR ACCES
         OR,8     11                MERGE IN PHYS PAGE
         LPC,8    0                 LOAD ACCESS LOCKS
         LD,8     S:MAPCW           GET SKELETON FOR LOADING MAP
         OR,8     11                MERGE PAGE OF JIT
         LDMAP,8  0                 LOAD ENTIRE MAP
         DISABLE
         LH,R15   UH:FLG,R4         GET FLAGS
         CW,R14   S:EVF             CHECK FOR EVENTS
         BNE      T:SE              YES, RECYCLE AND TRYA AGAIN
         CI,15    SJAC              CHECK FOR SPECIAL JIT ACCESS
         BAZ      %+3               NONE
         LD,8     S:SJACCW          GET CONTROL WORD
         LPC,8    0                 AND LOAD JIT ACCESS
         LB,3     UB:US,4           GET CURRENT STATE
         LI,2     SCU
         LB,5     UB:PRIO,4         GET USERS PRIORITY
         CB,R5    UB:PRIOB,R4       IS HE AT BASE
         BGE      %+3               YES, DONT DECREMENT
         AW,R5    S:PRIODEC         DECREMENT CURRENT PRIO
         STB,R5   UB:PRIO,R4        SAVE NEW PRIO
         STW,5    S:CUP             ANNOUNCE IT
         MTW,-1   S:HIR             ONE LES HIR
         BAL,11   RCE4              CHANGE STATE TO SCU  ***** ENABLE *****
         MAP
         LH,14    UH:FLG2,4         GET SECOND FLAGS
         CI,14    7                 CHECK FOR SWAP ERRORS
         BAZ      SE4D              NONE
         SLD,14   -3                ERROR FLAGS TO R15
         SLS,14   3                 CLEAR FLAGS
         STH,14   UH:FLG2,4         SAVE NEW FLAGS
         LC       15                GET SWAP ERROR FLAGS
         BCS,4    T:DELUSZAP        OFF THIS USER - CONTEXT ERROR
         BCR,2    SE4D1             USER AREA ERROR
         LW,5     S:CUN             USER NUMBER
         B        T:SCRATCH%USER
SE4D1    DISABLE                            ***** DISABLE *****
         LH,15    UH:FLG,4          RELOAD USER FLAGS.
         LH,R6    UH:DL,R4          GET DO LIST
         OR,6     X4000             SET ERROR FLAG
         STH,6    UH:DL,4           SAVE
         ENABLE                             ***** ENABLE *****
SE4D     EQU      %
         BAL,R6   ACTIVATE          MEASURE RESPONSE TIME
         CI,R14   SWAPD             CHECK FOR JUST SWAPPED IN
         BAZ      SE4F              NO
         AND,R14  XFFEF             CLEAR THE JUST SWAPPED IN FLAG
         BAL,3    T:ACCTEX          ACCOUNT EXEC TIME UP TO NOW
         LW,4     S:CUN
         STH,14   UH:FLG2,4         SAVE SECOND FLAGS
SE4F     LI,R0    J:OVHTIM          SET CLOCK TO OVERHEAD
         STW,R0   S:CLOCK4          AND SET IN CLOCK POINTER
         LW,R13   J:DELTAT          COMPUTE
         AW,R13   J:OVHTIM           EFFECTIVE
         AW,R13   J:CTIME             QUANTUM
         STW,R13  U:MISC,R4         SAVE IN MISC
         BAL,2    T:MASTER
         LB,R5    J:RNST            CHECK RUN STATUS AND
         CH,R5    UH:DL,R4          USER'S DO-LIST FOR
         BCS,7    SSE1              THINGS TO DO...GO DECODE
         LW,10    J:TIMENT          GET STIMER ENTRY ADDRESS.
         BEZ      SSE40             NONE
         LW,2     J:UTIMER          CHECK TIMER
         BGZ      SSE40             NOT UP YET
         LI,0     0
         STW,0    J:TIMENT          ONLY ONE ENTRY PER CAL.
         B        ALTENT            GO TO STIMER ENTRY ADDRESS
         PAGE
SEABRT   RES      0
T:OFF    LW,1     J:ACCN
         BNEZ     OFF10
         LW,1     SYSACT+1          GET BLANKS
         STW,1    J:ACCN
OFF10    RES      0
         LW,4     S:CUN             CHECK IF THIS IS
         LH,1     UH:FLG2,4         A LINE-HANGUP USER
         CI,R1    HANGUP            CHECK FOR HANGUP FLAG
         LI,R1    X'10'             ASSUME NOT (CC2 UNCHANGED)
         BAZ      NOTLNF            NOT HANGUP, RNST = X'10'
         LI,R1    8                 LINE HANGUP, RNST = X'08'
NOTLNF   RES      0
         STB,1    J:RNST
         LI,R13   TIC+BAT           TEL IN CONTROL AND BATCH FLAGS
         CS,R13   R15               CHECK FOR PRE CCI ABORT
         BNE      T:TELDELCCI       NO, EXIT.
         B        SSE5              YES, IGNORE FOR NOW
SEERR    RES      0
         ENABLE
         LI,R14   X'B403'           CODE FOR ERRORED BY OPERATOR
         SCS,R14  -8                ALIGN
         LI,1     X'20'
         B        SETRNST
SEOVRUN  BCR,2    SEERR             MUST HAVE ALL THREE BITS SET
         BCR,1    SEERR
         LI,R1    3                 SLEEP FOR 3 TICKS
         STW,R1   U:MISC,4
         LI,R6    E:SL              SLEEP EVENT
         BAL,11   T:REG
         B        SSE0              START OVER
         PAGE
DELTAGO  RES      0
*                 GO TO DELTA.  BRING DELTA INTO CORE IF NECESSARY.
*                 ASSUMES DELTA ASSOCIATED, NOT TEL-IN-CONTROL.
*                 REGISTERS MUST BE SET AS FOLLOWS:
*                 R10 = DELTA ENTRY ADDRESS.
*                 R4  = USER NUMBER. (CURRENT USER).
*                 R15 = USER'S FLAGS (UH:FLG).  DELA SET, TIC RESET.
*                 R0 CONTENTS GO INTO TOP WORD OF DELTA'S STACK AFTER
*                       COPYING TSTACK CONTEXT TO DELTA'S STACK.
         LD,R12   19SPD
         STD,R12  TSTACK            CRANK STACK DOWN TO 1 ENVIRONMENT.
DELTAGOT RES      0                 (DONT CRANK STACK ON TRAPS)
         CI,15    DIC               DIC = DELTA IN CORE & ACCESSIBLE.
         BANZ     DELTAIN           ---> SO JUST DO THE STACK COPY.
         SETST    DIC               IF NOT DIC, WE'LL MAKE IT SO.
         LB,2     UB:ASP,4          ASP NONZERO = DELTA NOT AROUND.
         BEZ      DELNOASP          ---> NO ASP; DELTA'S IN CORE NOW.
         RSETST   RTR               HAVE ASP, SO MUST FETCH DELTA.
         MTB,-1   PB:UC,2           DECREMENT ASP (LIBRARY) USE COUNT.
         LH,14    UH:FLG2,4
         CI,14    X'800'            LOCKED IN CORE
         BAZ      NOLCT             NO
         MTB,-1   PB:LCT,2          STILL LOCKED
         BG       NOLCT             YES
         LB,2     PB:PSZ,2          NO, GET PSZ
         LCW,2    2                 AND TAKE IT
         AWM,2    S:RTCORE          FROM RTCORE
NOLCT    BAL,2    IDB
         LI,6     E:AP
         BAL,11   T:REG             READ DELTA INTO CORE.
         CI,14    X'800'            LOCKED IN CORE
         BAZ      DELNOASP          NO
         MTB,0    PB:LCT,1          ALREADY LOCKED
         BG       %+3               YES
         LB,14    PB:PSZ,1          NO, GET PSZ
         AWM,14   S:RTCORE          AND ADD IT IN
         MTB,1    PB:LCT,1
DELNOASP LW,6     0                   (SAVE R0 ACROSS T:PAC)
         BAL,11   T:PAC             LOAD DELTA'S ACCESS-PROTECTION.
         LW,0     6                   (RESTORE R0)
DELTAIN  LI,1     SPDBASE           R1 => DELTA'S STACK.
         LW,6     10                SAVE ENTRY ADDR ACROSS T:UTSXTS.
         BAL,4    T:UTSXTS          COPY TSTACK TO DELTA STACK.
         BAL,R4   DELSTBAD           (BAD-STACK RETURN; GO TIDY IT UP).
         OR,6     SMPSD             BUILD A   R E L I A B L E   PSD
         LW,7     SMPSD+1           AROUND DELTA'S ENTRY ADDRESS
         STD,6    *3                AND INSTALL IN TSTACK.
         LB,R8    J:RNST
         STW,R8   R8+2,3            PUT RNST INTO R8 IN TSTACK.
         LI,R8    0
         STB,R8   J:RNST            ZERO OUT RNST.
         B        T:SSEM          -----> RESCHEDULE, THEN GOTO DELTA.
DELSTBAD LW,R3    TSTACK            ** DELTA'S STACK IS BAD. FIX R3
         AI,R3    -17               ** TO POINT TO PSD IN TSTACK.
         B        0,R4
*
SE7      LI,0     -1                BREAK. R0= CODE FOR BREAK (-1).
         CI,15    TIC               TIC = COMMAND PROCESSOR IN CONTROL
         BANZ     SE6               ---> GO IF C.P. IN CONTROL.
         CI,15    DELA              DELA = DELTA ASSOCIATED.
         BAZ      SE6A              ---> GO IF USERCONTROL, NODELTA.
         LI,10    SPPBASE+X'D'      R10= DELTA BREAK ENTRY ADDRESS.
         B        DELTAGO         -----> GO TO DELTA.
SE7A     CI,15    TIC               TIC = COMMAND PROCESSOR IN CONTROL.
         BAZ      SE6A              ---> GO IF USER IN CONTROL.
SE6      LH,2     UH:FLG2,4         SEE IF CP
         CI,2     X'4000'           HAS BREAK CONTROL
         BAZ      T:SSEM            ---> NO, IGNORE BREAK
SE6A     LW,10    J:INTENT          R10= USER/C.P. BREAK ADDRESS.
         BNEZ     ALTENT            ---> IF M:INT, GO TO USER/C.P.
*
SE9      CI,R15   TIC+BAT           CTL-Y OR BRK WITH NO M:INT
         BANZ     T:SSEM            --> IGNORE IF C.P. IN CONTROL.
         LH,2     UH:FLG2,4
         CI,2     RTHOLD            IS USER 'LOCKED-IN-CORE'?
         BANZ     T:SSEM            YES...IGNORE 'YC'/'BREAK'
         LI,1     2                 TELL C.P. THAT
         STS,1    J:TELFLGS           BRK/YC RECEIVED.
         B        T:ECCP
*
ALTENT   RES      0     (R0=USERSTACK FLAGWORD, R10=USERROUTINE ADDR)
         LW,1     J:TCB             BREAK/TIMEOUT WITH USER CONTROL.
         LI,11    X'1FFFF'          COPY ADDR ONLY INTO TSTACK PSD.
         BAL,4    T:UTSXTS          COPY TSTACK TO USER TCB STACK.
         B        ALTERR            ---> ERROR IN USER STACK.
         B        T:SSEM            GO TO USER AFTER NORMAL CHECKS
*
ALTERR   LI,14    X'A3'             *** ERROR IN BREAK/STIMER.
         B        T:ABORTM          ***
         TITLE    'REPORT USER EVENT'
*
*D*      NAME:    T:RUE
*D*      PURPOSE: TO REPORT AN EVENT ON A SPECIFIED USER.
*D*      DESCRIPTION: T:RUE MOVES THE USER NUMBER TO R4
*D*                  AND MERGES WITH RCE0.
*D*      CALL:      BAL,R11 T:RUE      WITH USER NUMBER IN R5
*D*                 <NORMAL RETURN>
*D*      ENVIRONMENT: T:RUE IS CALLED BOTH MAPPED AND UNMAPPED
*D*               AND EXECUTES IN THE MODE OF THE CALLER.
*D*               INTERRUPTS ARE ENABLED ON EXIT.
*D*      REGISTERS:   R0-R4 - VOLATILE
*D*                      R5 - USER NUMBER (INPUT)
*D*                      R6 - EVENT NUMBER (INPUT) MODIFIED
*D*                   R7-R10 - VOLATILE
*D*                     R11 - LINK
*D*                  R12-R15 - VOLATILE
*
*
T:RUE    LW,R4    R5                MOVE USER NUMBER TO PROPER REG
         B        RCE0              AND MERGE WITH COMMON PATH
         TITLE    'REPORT EVENT AND GIVE UP CONTROL'
*
*        T:REG    REPORT EVENT AND GIVE UP
*
*        R6 - EVENT NUMBER
*        R11 - LINK
*        ALL REGISTERS PRESERVED
*
*        T:REG MUST BE CALLED MAPPED AS IT ASSUMES THAT
*        WE MAY BLOCK THE CURRENT USER FOR SOME UNSATISFIED
*        CONDITION.  THE ENVIRIONMENT EXISTING AT THE TIME
*        T:REG IS CALLED IS SAVE IN THE CURRENT USER'S JIT
*        AND THEN THE EVENT IS REPORTED.  SOME EVENT-
*        CIRCUMSTANCE COMBINATIONS WILL CAUSE AN IMMEDIATE
*        T:PULLE.  NORMALLY, HOWEVER THE USER WILL BE SUSPENDED
*        AND A NEW USER SCHEDULED AT T:SE.
*
T:REG    XPSD,0   REG1PSD           GET CURRENT PSD AND GO MAPPED
REG1     PUSH     6,13              SAVE 13,14,15,0,1,2
         LW,R0    R11               RETURN
         LI,R1    X'E0000'          MASK IT INTO
         LS,R0    REG1PSD           PSD
         LW,R1    REG1PSD+1         GET SECOND HALF
         BAL,R2   T:SAVE            SAVE ENVIRIONMENT
REG2     BAL,R2   T:SMPFLG          SET MASTER ONLY FLAG
         LI,R11   T:SE              SET RETURN TO SCHEDULE
*                                   RE-SCHEDULE
*
*        T:RE  REPORT EVENT FOR CURRENT USER
*
*        R11 - LINK
*        R6 - EVENT (MODIFIED)
*        ALL OTHER REGISTERS VOLATILE
*
*
*        IF WE'RE RUNNING ON THE SLAVE CPU - MUST PARK
*        OURSELF HERE.
*
T:RE     EQU      %
         LW,R4    R1                PRESERVE R1
         BLOCK                      PARK IF SLAVE CPU MONITOR MODE
         LW,R1    R4                RESTORE R1
         LW,R4    S:CUN             GET CURRENT USER #
*        B        RCE0              WADE INTO EVENT REPORTING
         TITLE    'E V E N T    R E P O R T I N G '
*                                   T:RCE - REPORT COC EVENT
*                                   T:RE - REPORT EVENT FOR CURRENT
*                                            USER
*                                   T:RUE - REPORT EVENT FOR SPECIFIED
*                                            USER
*                                   7 = LINE# (RCE ONLY)
*                                   6 = EVENT#
*                                   5 = USER# (RUE ONLY)
RCE0     DISABLE                    EVENT REPORTING MUST BE DONE
         MTW,+1   S:EVF             SET EVENT FLAG-COUNTER
*                                   DISABLED
         LB,3     UB:US,4           GET CURRENT STATE
         LW,12    X1,3              GET BIT CORRESPONDING TO IT
RCE1     CW,12    S:SET,6           ARE WE AT THE RIGHT PLACE
         BANZ     RCE3              YES
         LW,15    S:SET,6           CHECK FOR CONTINUATION
         BLZ      RCE2              YES
         SCREECH  X'02'             BAD STATE EVENT COMBINATION
*S*********************************************************************
*S*                                                                   *
*S*      SCREECH CODE: 02                                             *
*S*      REPORTED BY: SCHED                                           *
*S*      MESSAGE: USER'S STATE AND EVENT ARE INCONSISTENT             *
*S*      SIGNIFICANT REGISTERS:                                       *
*S*               R3 - USER'S CURRENT STATE                           *
*S*               R4 - USER NUMBER                                    *
*S*               R6 - EVENT NUMBER (MAY HAVE BEEN INCREMENTED)       *
*S*              R11 - RETURN ADDRESS FOR EVENT REPORTING             *
*S*              R12 - BIT CORRESPONDING TO CURRENT STATE             *
*S*              R15 - REGISTER USED FOR CONTINUATION CHECK           *
*S*                    BIT 0 WILL BE EQUAL TO ZERO                    *
*S*      REMARKS: USUALLY A SOFTWARE CHECK 02 INDICATES THAT SOME     *
*S*               PIECE OF THE SYSTEM PASSED BAD ARGUMENTS TO T:RE,   *
*S*               T:REG OR T:RUE.  THE SOLUTION TO THE PROBLEM WILL   *
*S*               GENERALLY COME FROM DETERMINING WHO CALLED THE      *
*S*               EVENT REPORTING LOGIC AND WHY.                      *
*S*********************************************************************
RCE2     AI,6     1                 NEXT ENTRY
         B        RCE1              CONTINUE
RCE3     LB,2     SB:SET,6          GET ACTION CODE
         LH,15    UH:FLG,4          GET FLAGS FOR MANY ST EVENTS
         CI,2     SNSTS             CHECK FOR SPECIAL ACTION
         BG       S:TRNSVEC-X'20',2 YES GO TO IT
*
*        STATE CHANGE FOR NON-EXECUTABLE STATES
*
RCE4     LB,5     UB:BL,4           GET BACK LINK
         LB,1     UB:FL,4           AND FORWARD LINK
         BNEZ     %+2               NOT TAIL
         STB,5    SB:TQ,3           SET NEW TAIL
         AI,5     0                 CHECK FOR HEAD
         BNEZ     %+2               NO
         STB,1    SB:HQ,3           SET NEW HEAD
         STB,5    UB:BL,1           CROSS LINK
         STB,1    UB:FL,5           REMAINING QUEUE MEMBERS
         LI,1     0                 ZAPPER
         AI,4     0                 CHECK FOR QUEUE TO HEAD
         BLZ      T:QH              YES
T:QT     STB,1    UB:FL,4           ZAP FLINK SINCE WE ARE AT TAIL
         LB,1     SB:TQ,2           GET PREVIOUS TAIL
         BEZ      CHSE25            EMPTY QUEUE
         STB,4    SB:TQ,2           SET NEW TAIL
         STB,1    UB:BL,4           BACK LINK TO PREVIOUS TAIL
         STB,4    UB:FL,1           AND MAKE HIM POINT TO NEW GUY
         B        CHS1              DONE
T:QH     STB,1    UB:BL,4           SET BACK LINK TO ZERO
         LB,1     SB:HQ,2           GET CURRENT HEAD
         BEZ      CHSE25            EMPTY QUEUE
         STB,4    SB:HQ,2           AND SET NEW HEAD
         STB,4    UB:BL,1           SET BLINK TO PREVIOUS HEAD
         STB,1    UB:FL,4           SET FLINK TO PREVIOUS  HEAD
         B        CHS1              DONE
         TITLE    'EXECUTABLE STATE CHANGE'
*
*        CHANGE STATE FOR EXECUTABLE STATES
*
*        R1 - PRIORITY INCREMENT INDEX, DESTROYED
*                 0 => NONE (OLD SCOM)
*                 1 => SPECIAL COMPUTE (OLD SC)
*                 2 => I/O COMPLETE (OLD SIOC)
*                 3 => INTERACTIVE (OLD SIR,SEC,SBK,SON,SOFF)
*                 4 => TERMINAL OUTPUT CONTINUE (OLD STOC)
*                 5 => RESOURCE UNBLOCK (OLD SC)
*        R2 - TEMP, NEW STATE
*        R3 - OLD STATE
*        R4 - USER NUMBER
*                 QUEUE TO HEAD IF BIT 0 IS SET
*        R5 - TEMP, USER PRIORITY
*        R11 - LINK  EXIT WILL ENABLE
*        R15 - USER FLAGS (UH:FLG)
*        THESE ROUTINES MUST BE CALLED DISABLED
*
T:CHSE0  LI,1     STSC              SET INDEX TO ZERO (BASE COMPUTE)
T:CHSE   LB,2     UB:PRIOB,4        GET CURRENT PRIORITY
         CI,R15   OPNCLSUSR+SPECFILE   CHECK FOR EXTRA BOOST
         BAZ      %+2               NO, NOTHING SPECIAL FOR HIM
         AI,2     -OPNBOOST         YES, GIVE HIM AN EXTRA SHOT
         AI,1     -STSC             SUBTRACT BASE ADDRESS
         SH,2     SH:PINC,1         ADD PROPER PRIORITY INCREMENT
CHSE0    STB,2    UB:PRIO,4         REMEMBER NEW VALUE
         CW,2     S:CUP             GREATER THAN CURRENT USER
         BGE      CHSE1             NO, DONT SET S:HIR
         CI,15    1                 IF HE IS IN CORE
         BAZ      CHSE1             NO
         MTW,1    S:HIR             GOT A HIGH PRIO GUY
         BG       CHSE1             POSITIVE IS OK
         LI,1     1                 ELSE FORCE TO ONE
         STW,1    S:HIR             IF 0 OR NEGATIVE
CHSE1    AI,2     -X'F5'            PRIO FOR STATE SC0
         BG       CHSE6             CHANGE STATE TO SC1 - SC10
         AI,2     X'F5'-X'C0'       CHECK FOR REAL TIME
         BL       CHSRT             YES
         LI,2     SC0               QUEUE INTO SC0 FOR HIGH PRIO BGRD
CHSE2    LB,5     UB:BL,4           GET BLINK *
         LB,1     UB:FL,4           AND FLINK  *
         BNEZ     %+2               NOT AT TAIL * UNLINK
         STB,5    SB:TQ,3           SET NEW TAIL *
         AI,5     0                 CHECK FOR AT HEAD
         BNEZ     %+2               NO
         STB,1    SB:HQ,3           YES, SET NEW HEAD
         STB,1    UB:FL,5           CROSS LINK REMAINING MEMBERS
         STB,5    UB:BL,1           IN OLD STATE QUEUE
         LB,5     UB:PRIO,4         GET PRIORITY
         AI,4     0                 CHECK FOR QUEUE TO HEAD
         BLZ      CHSEH             YES
         LB,1     SB:TQ,2           GET TAIL OF NEW QUEUE
         BNE      CHSE3             NOT EMPTY
CHSE25   STB,1    UB:BL,4           NULL QUEUE
         STB,1    UB:FL,4           ZAP LINKS
         STB,4    SB:TQ,2           SET HEAD AND
         STB,4    SB:HQ,2           TAIL POINTERS
         B        CHS1              EXIT
CHSE3    CB,5     UB:PRIO,1         COMPARE PRIORITIES
         BGE      CHSE4             THIS IS THE PLACE
         LB,1     UB:BL,1           BLINK BACK
         BNE      CHSE3             AND TRY AGAIN
         B        T:QH              AT THE HEAD OF THIS Q
CHSE4    STB,1    UB:BL,4           SET BACK LINK
         LB,5     UB:FL,1           GET FORWARD
         BNEZ     CHSE5             NOT AT TAIL
         STB,4    SB:TQ,2           SET NEW TAIL
         STB,5    UB:FL,4           ZAP FORWARD LINK
         STB,4    UB:FL,1           LINK TO PREVIOUS TAIL
         B        CHS1              EXIT
CHSE5    STB,4    UB:BL,5           SET BLINK FOR NEXT GUY
         STB,5    UB:FL,4           AND POINT TO HIM
         STB,4    UB:FL,1           LINK TO PREVIOUS GUY
         B        CHS1
CHSRT    RES      0                 GOT  A REAL TIME GUY
         LI,2     SRT               STATE REAL TIME
         LB,5     UB:PRIOB,4        GET BASE PRIORITY
         STB,5    UB:PRIO,4         AND MAKE IT CURRENT - DONT FLOAT RT
         B        CHSE2             CHAIN HIM IN
CHSEH    LB,1     SB:HQ,2           GET CURRENT HEAD
         BEZ      CHSE25            NULL QUEUE
CHSEH1   CB,5     UB:PRIO,1         COMPARE PRIORITIES
         BL       CHSEH2            AT THE RIGHT SPOT NOW
         LB,1     UB:FL,1           FLINK ON
         BNE      CHSEH1            AND COMPARE AGAIN
         B        T:QT              WE GO ON THE TAIL
CHSEH2   STB,1    UB:FL,4           SET NEW FORWARD LINK
         LB,5     UB:BL,1           GET HIS OLD BACK LINK
         BNEZ     CHSEH3            NOT AT HEAD
         STB,4    SB:HQ,2           SET NEW HEAD
         STB,5    UB:BL,4           ZAP BLINK
         STB,4    UB:BL,1           MAKE HIM POINT BACK
         B        CHS1              EXIT
CHSEH3   STB,4    UB:FL,5           MAKE PREVIOUS GUY POINT TO US
         STB,5    UB:BL,4           POINT BACK AT HIM
         STB,4    UB:BL,1           SET NEXT GUYS BLINK TO US
         B        CHS1              EXIT
*
T:CHS    DISABLE
         B        RCE4
CHSE6    AI,R2    SC0               ADD IN BASE STATE NUMBER
         B        RCE4              AND DO SIMPLE STATE CHANGE
         TITLE    'S P E C I A L     T R A N S I T I O N S'
***********************************************************************
*                 SPECIAL ACTION ROUTINES FOR EVENT REPORTING
*
*        ALL SPECIAL TRANSITION ROUTINES ARE ENTERED DISABLED BUT ARE
*        GENERALLY VERY SHORT.  SPECIAL TRANSITION ROUTINES ARE
*        REQUIRED WHEN EITHER MORE THAN A SIMPLE STATE CHANGE MUST
*        OCCUR OR WHEN MORE INFORMATION THAN AN EVENT AND CURRENT
*        STATE IS NECESSARY TO MAKE A DECISION.
*
*        STANDARD REGISTER CONTENTS:
*        R3 - OLD STATE
*        R4 - USER NUMBER
*        R6 - MODIFIED EVENT NUMBER (INDEX INTO S:SET)
*        R11 - RETURN
*        R12 - BIT CORRESPONDING TO OLD STATE
*
*        STRICTLY SPEAKING ALL OTHER REGISTERS ARE VOLATILE
*        EXCEPT THAT R7 IS EXPECTED TO CONTAIN THE LINE
*        NUMBER FOR COC EVENTS WHEN RETURNING.
**********************************************************************
S:TRNSVEC EQU     %
STSCOM   BAL,1    T:CHSE            COMPUTE
STSC     BAL,1    T:CHSE            SPECIAL COMPUTE
STIOCC   BAL,1    T:CHSE            I/O COMPLETE
STIRC    BAL,1    INTERACTIVE       INTERACTIVE
STOC     BAL,R1   T:CHSE            TERMINAL OUTPUT CONTINUE
STRUB    BAL,R1   T:CHSE            RESOURCE UNBLOCK
INTERACTIVE EQU   %
         OR,15    X20               SET INTERACTIVE BIT
         STH,15   UH:FLG,4          IN FLAGS
         B        T:CHSE            AND CHANGE STATE
         PAGE
*
*        BLOCK FOR I/O IN PROGRESS OR MF TOO HIGH
*
*        ENTERED VIA T:REG FOR THE EVENTS E:IIP AND E:QMF.
*        A CHECK IS MADE FOR COMPLETETION OF ALL OUTSTANDING I/O
*        BEFORE ACTUALLY BLOCKING THE USER.  IF A DCB IS ASSOCIATED
*        WITH THE I/O REQUEST AND THE EVENT IS E:IIP, A CHECK IS
*        ALSO MADE FOR DCB:FCN=ZERO.  THE HIGH ORDER BIT OF THE
*        FUNCTION COUNT WILL BE SET TO MARK THE DCB WE ARE WAITING FOR.
*
*        R1 - DCB ADDRESS, VIRTUAL  (0 => NONE - NEWQ)
*
STIOMF   LI,R1    0                 ZERO DCB TO FORCE BLOCK
STIIP    EQU      %                 I/O IN PROGRESS
         LB,2     UB:MF,4
         BEZ      GRANT             I/O IS ALLREADY DONE
         LI,R11   T:SEO             CHANGE RETURN TO AVOID T:SS
         AI,6     SIOW-E:IIP        FORM PROPER STATE NUMBER
         LW,2     6                 MOVE TO PROPER REGISTER
         AI,1     0                 CHECK FOR NEWQ (DCBADDR =0)
         BEZ      RCE4              NEWQ
FCN      EQU      7
         LW,8     FCN,1             GET FUNCTION COUNT WORD
         CW,8     YFF               TEST FOR ZERO FUNCTIO COUNT
         BAZ      GRANT             YES, LET HIM GO
         OR,8     Y8                SET MARKER BIT IN FCN WORD OF DCB
         STW,8    FCN,1             AND REPLACE IT
         B        RCE4              PARK HIM
         PAGE
*
*        I/O COMPLETE REPORT HANDLING
*
*        ENTERED VIA T:RUE FOR EVENT E:IC.  (UNMAPPED)
*
*        THE USER'S MASTER FUNCTION COUNT (UB:MF) IS DECREMENTED AND
*        A CHECK IS MADE TO DETERMINE IF THE USER IS IN AN I/O
*        WAIT STATE.  IF THE USER IS BLOCKED IN I/O WAIT, HE WILL BE
*        RELEASED IF THIS IS THE REQUEST WE ARE WAITING FOR.
*        A FAIL-SAFE OPERATION OCCURS IF ALL I/O HAS COMPLETED
*        AS INDICATED BY UB:MF AND THE DCB:FCN IS STILL NON-ZERO.
*        IN THIS CASE THE DCB:FCN WILL BE FORCED TO ZERO AND THE
*        USER WILL BE UNBLOCKED.
*
*        R1 - DCB ADDRESS, PHYSICAL (0 => NONE - NEWQ)
*
STIOC    EQU      %                 I/O COMPLETE
         MTB,-1   UB:MF,4           DECREMENT MASTER FUNCTION COUNT
         CW,12    =(1**SIOW)+(1**SIOMF)
         BAZ      ENBISR4           NOT WAITING, GET OUT
         LB,R0    UB:MF,R4          CHECK FOR ALL I/O COMPLETE
         BEZ      IOCOM3            YES
         CI,3     SIOMF             CHECK FO MASTER FUNCTION COUNT BLOCK
         BE       IOCOM2            YES, WITH I/O GOING
IOCOM1   AND,R1   M21               SCRUB DCB PHYSICAL ADDRESS
         BEZ      STIOCC            NO DCB, NEWQ
         LW,R2    FCN,R1            GET FUNCTION COUNT WORD
         BGEZ     IOCOM4            NOT WAITING ON THIS ONE
         CW,R2    Y7F               CHECK FOR ZERO FCN
         BANZ     IOCOM4            NO, DONT UNBLOCK YET
IOCOM5   AND,R2   M24               SCRUB FLAG OFF
         STW,R2   FCN,R1            REPLACE FCN WORD WITH FLAG OFF
         B        STIOCC            AND UNBLOCK
IOCOM2   LW,2     SL:OIMF           GET ONLINE UNBLOCK
         CI,15    BAT               CHECK FOR BATCH
         BAZ      %+2               NO
         LW,2     SL:BIMF           YES, USE BATCH LIMIT
         CB,2     UB:MF,4           SHOULD WE RESTART HIM
         BL       ENBISR4           NO
IOCOM3   MTW,+1   S:SEVF            SWAP SET CHANGED
         CI,R3    SIOMF             BLOCKED FOR MASTER FUNCTION COUNT?
         BNE      IOCOM1            NO
         B        STIOCC            TURN HIM LOOSE
IOCOM4   LB,R0    UB:MF,R4          GET MF AGAIN
         BNE      ENBISR4           STILL GOT I/O GOING
         B        IOCOM5            AND REPLACE IN DCB
CHS1     STB,2    UB:US,4           REMEMBER NEW STATE
         MTW,+1   S:EVF             SET EVENT FLAG COUNTER
STNOP    RES      0
         PAGE
*
*        COMMON EXIT FOR T:RUE...ETC...
*
*        NOTE:    IF R6 HAS A Y4 IN IT - IT SPECIFIES TO NOT
*                 ENABLE ON THE WAY BACK.
*
ENBISR4  EQU      %
         LC       R6                TEST FOR NO ENABLE
         BCS,4    *R11              YUP->
         ENABLE                     IF OK
BISR4    RES      0
         B        *11
         PAGE
*        ABORT OR OFF EVENT HANDLER
         SPACE    1
STABRT   CI,15    BAT               CHECK FOR BATCH
         BANZ     SETDL             SET DO LIST
         LI,3     MAXG              CHECK FOR GHOST
         ENABLE                     ALLOW INTERRUPTS   ** ENABLE **
         CB,4     SB:GJOBUN,3       IS HIS USER NUMBER A GHOST
         BE       STABRT1           YES, NO COC LINE
         BDR,3    %-2               CONTINUE
         LI,7     LNOL-1            MUST BE ONLINE, FIND HIS LINE #
STABRT0G ;
         CB,4     LB:UN,7           HIS USER NUMBER
         BNE      STABRT0L          B/NOT OUR LINE
         LC       MODE5,R7
         BCR,8    COCABRT           B/MASTER LINE
STABRT0L AI,R7    -1                DEC LINE #
         BGEZ     STABRT0G          B/MORE LINES TO CHECK
STABRT1  DISABLE                    BLOCK INTERRUPTS   ** DISABLE**
         LB,3     UB:US,4           GET USERS STATE
SETDL    CW,12    =(1**SQR)+(1**SQRO)  CHECK FOR SQR OR SQRO
         BAZ      SETDL1            NEITHER
         LW,1     U:MISC,4          GET RESOURCE
         LB,1     1                 INDEX
         CH,14    SH:RFLG,1         SHOULD WE CHANGE STATE?
         BAZ      SETDL1            NO
         BAL,0    T:UQR             UNQ FROM RESOURCE CHAIN
         OR,6     Y8                SET STATE CHANGE FLAG
SETDL1   RES      0
         CH,14    UH:DL,4           IS THIS FLAG ALREADY SET
         BANZ     ENBISR4           YES, GET OUT
         AH,14    UH:DL,4           MERGE IN NEW FLAG
         STH,14   UH:DL,4           AND PUT AWAY
         LH,R15   UH:FLG,R4         GET CORRECT FLAGS BEFORE STIRC
         BIR,6    STIRC             TEST FLAG FOR STATE CHANGE
         B        ENBISR4           NO STATE CHANGE
         PAGE
*        COMMON PROCESSING FOR E:OFF,E:ERR,E:CBK,E:CEC
*        ONLY E:OFF REQUIRES SPECIAL ADDITIONAL ACTION
         SPACE    1
STBEEAC  OR,6     Y8                SET STATE CHANGE FLAG
STBEEA   OR,6     X1                SELECT RIGHT HALFWORD
         LH,14    X1+(12-E:CBK/2),6 PICK PROPER FLAG
*                                   E:CBK => X1000
*                                   E:CEC => X2000
*                                   E:ERR => X4000
*                                   E:OFF => X8000 (NEGATIVE HALFWORD)
*
         BLZ      STABRT            SPECIAL ABORT PROCESSING
         B        SETDL             SET DOLIST
COCABRT  PUSH     11                SAVE RETURN
         BAL,11   STABRT1           SET FLAGS AND MAYBE CHANGE STATE
         LW,R2    R7                PUT LINE # IN CORRECT REG FOR COC
         XPSD,0   COCUNMAP          GO UNMAPPED, INHIBITED, NO EA/MA
         BAL,R11  COCOFF            BAL/COCOFF; RETURN WITH MAP IN
*                                   .. SAME MODE AS BEFORE XPSD ABOVE
         B        PULL11B           PULL R11; B *R11
*
*        ASSOCIATE PROCESSOR
*
*        QUEUES USER TO HEAD OF SPECIAL COMPUTE QUEUE
*
STASP    OR,4     Y8                SET HEAD OF Q FLAG
         B        STSC              AND MAKE HIM SPECIAL COMPUTE
STCRD    CI,15    X'4000'           TEST FOR UNBLOCK BEFORE BLOCK
         BANZ     QFORA2            YES
         LI,2     STI               STATE TERMINAL INPUTTING
         OR,R4    Y8                SET HEAD OF QUEUE FLAG
         B        RCE4              GO CHANGE STATE
STQA     EQU      %
         LH,15    UH:FLG,4
         CI,15    X'4000'
         BAZ      QFORA1
QFORA2   AI,15    -X'4000'          TURN OFF FLAG
         STH,15   UH:FLG,4
         B        T:PULLE
QFORA1   LI,2     SQA
         B        RCE4
STUQA    CI,3     SQA               IS HE QUEUED FOR ACCES
         BE       STSC              YES SPECIAL COMPUTE
STIRCU   RES      0
         OR,15    X4000
         STH,R15  UH:FLG,R4         SAVE NEW FLAGS
         B        ENBISR4           ENABLE AND EXIT
*
*        KICKOUT USER SPECIAL TRANSITION
*
STKOT    LB,2     UB:US,4           FORM NEW STATE
         AI,2     STOBO-STOB        FOR TERMINAL I/O OUT OF CORE
         AND,15   =~(RTR+JIC)       RESET JIC AND RTR
         STH,R15  UH:FLG,R4         SAVE NEW FLAGS
         B        RCE4              AND CHANGE STATE
STKO     AND,15   =~(RTR+JIC)       RESET JIC AND RTR
         STH,15   UH:FLG,4          SAVE FLAGS
         CI,3     SEXU              CHECK FOR EXECUTABLE
         BG       ENBISR4           NO, SKIP STATE CHANGE
         LB,2     UB:PRIO,4         GET PRIORITY
         B        CHSE1             WADE INTO STATE CHANGE
         PCC      0
         PAGE
*  UNQUEUE FOR ALLYCAT... RESIDENT PORTION OF ALLYCAT
         SPACE
STUQFAC  EQU      %
         LI,R1    4                 INDEX FOR BUFFERS
UNQNEXT  AI,R1    -1                DECREMENT INDEX
         BLZ      UNQXIT            EXIT IF NO MORE
         DISABLE
         LH,R2    BUFLAGS,R1        GET FLAGS
         SLS,R2   16                POSITION
         LC       R2                GET MSG
         BCS,4    UNQEMPTY          JUST EMPTIED
         BCS,2    UNQFILL           JUST FILLED
         B        UNQSETFL          DO ARITHMETIC ON EMPTH HGP
UNQEMPTY LH,R2    BOTTOM,R1         UPDATE THE POINTERS
         STH,R2   TEMPBOT,R1
         B        UNQSETFL          RESET THE FLAGS
         SPACE
UNQFILL  LH,R2    TEMPBOT,R1        UPDATE THE POINTERS
         STH,R2   BOTTOM,R1
UNQSETFL LH,R2    BUFLAGS,R1        RESET THE FLAGS
         AND,R2   X9FFF
         STH,R2   BUFLAGS,R1
         SPACE
         LH,R2    WORDCNT,R1        ADJUST WORD COUNT
         AH,R2    ADJSTCNT,R1       TO NEW VALUE
         STH,R2   WORDCNT,R1
         AI,R2    -1                DECREMENT COUNT
         CW,R2    BUFMASK,R1        COMPARE TO MAX POSSIBLE
         BLE      UNQNEXT1          OKAY
         SCREECH  X'88'             BUMMER
UNQNEXT1 LI,R2    0                 NOW ZAP
         STH,R2   ADJSTCNT,R1       ADJUSTED COUNTER
         ENABLE                     LET EM RIP
         SPACE
         B        UNQNEXT
         SPACE
X9FFF    DATA     X'9FFE'
         SPACE
         TITLE    'RESOURCE BLOCK/UNBLOCK'
*
*        BLOCK AND RELEASE FOR RESOURCES
*
*        SB:RQ CONTAINS THE RESOURCE SUB QUEUE HEADS
*        SB:RQ IS INDEXED BY RESOURCE NUMBER(E:XXX-E:REL)
*
*        ODD NUMBERED RESOURCE EVENT DIFFERENCES MEAN RELEASE
*
*        USERS WILL BE ADDED AT THE HEAD OF THE PROPER
*        SUB-QUEUE AND REMOVED FROM THE TAIL IN ORDER TO
*        FAIRLY DISTRIBUTE ANY DELAYS.
*
T:RES    AI,6     -E:REL            TAKE OFF BASE
         SCS,6    -1                HALVE AND POSITION FLAG
         AI,6     0                 TEST FOR RELEASE
         BLZ      T:REL             YES
         LB,2     SB:RBLK,6         GET BLOCK TRANSFER INDEX
         BNEZ     T:BLKV,2          GO TO IT
         LB,2     SB:RQ,6           GET HEAD OF RESOURCE Q
         STB,6    2                 SAVE RESOURCE INDEX
         STW,2    U:MISC,4          SET FLINK
         STB,R4   UB:PRIO,R2        AND BLINK TO CURRENT HEAD
         BNEZ     %+2               NOT AN EMPTY SUB-QUEUE
         STB,R4   SB:RQT,R6         NULL Q, SET TAIL ALSO
         LI,2     0                 ZAP
         STB,2    UB:PRIO,4          BLINK
         STB,4    SB:RQ,6           SET NEW HEAD
         LI,2     SQR               NEW STATE
         B        RCE4
*
*
T:REL    LH,2     SH:RFLG,6         GET FLAGS AND INDEX
         CI,2     SPECIFIC          SPECIFIED USER ONLY?
         BANZ     RELB              YES
         CI,2     NULL              CHECK FOR ACTION ON NULL Q
         LB,R4    SB:RQT,R6         GET TAIL OF SUB-QUEUE
         BCR,7    ENBISR4           NONE IN Q AND NO NULL FLAG
RELA     AND,2    M8                SCRUB TO INDEX
         BNE      T:RELV,2          GO TO SPECIAL ROUTINE
UNQXIT   EQU      %
T:REL1   DISABLE                    MERGE POIN FOR SPECIAL UNBLOCK ROUTINES
         AI,4     0                 CHECK FOR NULL Q
         BEZ      ENBISR4           YES, GET OUT
         BAL,0    T:UQR             UNQUEUE FOR RESOURCE
         PUSH     11                SAVE RETURN
         LB,3     UB:US,4           GET CURRENT STATE
         BAL,R11  STRUB             RESOURCE UNBLOCK BOOST
         PULL     11                RESTORE RETURN
         LH,2     SH:RFLG,6         GET FLAGS
         CI,2     FLUSH             FLUSH ALL>
         BAZ      ENBISR4           NO
         DISABLE                             ***** DISABLE *****
         B        T:REL             CONTINUE FLUSHING
RELB     CW,R12   =(1**SQR)+(1**SQRO)  CHECK THAT HE IS SQR OR SQRO
         BANZ     RELA              YES, OK
         LI,R4    0                 OTHER WISE ZAP USER NO
         B        RELA              TO SKIP UNQ
         PAGE
*
*
*        UNQUEUE FOR RESOURCE
*
*                 CALLED DISABLED
*
*        R0 = LINK
*        R1 = TEMP
*        R4 = USER NUMBER
*        R5 = TEMP
*        R6 = FORCED TO RESOURCE INDEX FOR USER(R4)
*
*        UB:PRIO IS USED AS A BACK LINK
*        BYTE(3) OF U:MISC IS FORWARD LINK
*        BYTE(0) OF U:MISC IS RESOURCE INDEX
*        SB:RQ(R6) CONTAINS HEAD OF SUB-QUEUE
*
T:UQR    LW,5     U:MISC,4          GET FORWARD LINK
         LB,6     5                 RESOURCE INDEX
         LB,1     UB:PRIO,4         GET BLINK
         BNEZ     %+2
         STB,5    SB:RQ,6           SET NEW HEAD
         STB,1    UB:PRIO,5         CROSS LINK REMAINING
         STW,5    U:MISC,1          ENTRIES
         CI,R5    X'FF'             CHECK FOR TAIL
         BANZ     *R0               NO, RETURN
         STB,R1   SB:RQT,R6         YES, SET NEW TAIL
         B        *0                RETURN
         PAGE
*
*        SPECIAL ACTION VECTOR FOR RESOURCE BLOCK
*
T:BLKV   EQU      %-1               BASE
*
*
*
*
*
*
*        SPECIAL ACTION VECTOR FOR RESOURCE UNBLOCK
*
T:RELV   EQU      %-1               BASE
UQFAC    B        STUQFAC           UNQUEUE FOR ALLOCAT
OPNUNBLOCK RES    0
         LW,R15   OPNCLSUS          DID ANY GET THERE BEFORE US
         BNEZ     ENBISR4           YES GET OUT
         LH,R15   UH:FLG,R4         GET HIS FLAGS
         OR,R15   X8                SET OPNCLSUSR FLAG
         STH,R15  UH:FLG,R4         AND SAVE NEW FLAGS
         STW,R4   OPNCLSUS          CLEAR, MAKE HIM OPNCLS USER
         B        T:REL1            AND UNBLOCK HIM
*
*
         TITLE    'L O G O N     N E W     U S E R S'
*D*********************************************************************
*D*      NAME:    T:RCE
*D*      PURPOSE: REPORT COC EVENT GIVEN LINE NUMBER
*D*      DESCRIPTION: THE LINE NUMBER IS CONVERTED TO A USER NUMBER
*D*               AND THE COMMON EVENT REPORTING LOGIC IS CALLED
*D*      REGISTERS: R6 - EVENT  (MAY BE ALTERED)
*D*                 R2 - LINE NUMBER
*D*                R11 - LINK
*D*               ALL OTHER REGISTERS ARE VOLATILE
*D*      ENVIRONMENT: T:RCE EXECUTES MASTER MODE AND MAY BE CALLED
*D*               EITHER MAPPED OR UNMAPPED.  ALL INTERRUPTS WILL
*D*               BE INHIBITED DURING T:RCE BUT WILL BE ENABLED ON EXIT
*D*********************************************************************
T:RCE    LI,R10   X'BAD'            MAKE SURE BYTE 0, R10 IS ZERO
         LB,R4    LB:UN,R2          L/USER # FOR THIS LINE
         BNE      RCE0              B/USER ASSOCIATED
*
*        A COC EVENT HAS JUST BEEN REPORTED ON A LINE WHICH HAS
*        NO ASSIGNED USER.  THIS IS THE SIGNAL TO LOGON A NEW
*        TIMESHARING USER AND ASSIGN THIS LINE TO HIM.
*
         DISABLE
         LI,1     SNULL             GET HEAD OF
         LB,4     SB:HQ,1           NULL STATE
         BEZ      LOGNO             CAN'T LOGON - NO AVAIL USERS
         LW,1     S:OUIS
         CW,1     S:OUAIS
         BGE      LOGNO
         MTW,1    S:OUIS
         STB,R4   LB:UN,R2          S/USER # IN COC LINE TABLE
         LW,15    SL:OPRIO          GET DEFAULT ONLINE PRIO
         TITLE    'ADD A NEW USER'
*D*********************************************************************
*D*      NAME:    ADD1
*D*      PURPOSE: TO ADD A USER TO THE SYSTEM
*D*      DESCRIPTION: ADD1 IS CALLED BY MBS,T:GJOBSTRT AND LOGON
*D*               TO START A NEW USER INTO THE SYSTEM.  ADD1 IS
*D*               SUPPLIED WITH THE USER TABLE SLOT BY THE CALLER
*D*               AND ALLOCATES A GRANULE CLUSTER FOR THE JIT AND
*D*               SETS UP THE USER TABLE ENTRIES.  THE NEW USER WILL
*D*               BE PLACED IN AN EXECUTABLE STATE IF A DISC PAGE IS
*D*               AVAILABLE FOR HIS JIT.  OTHERWISE, HE WILL BE PLACED
*D*               IN SQR AND QUEUED FOR A DISC PAGE.  WHEN A DISC PAGE
*D*               BECOMES AVAILABLE AND THE USER IS SCHEDULED FOR INSWAP
*D*               THE SWAPPER WILL RE-ENTER ADD1 AT GETJIT WHICH WILL
*D*               AGAIN TRY TO ALLOCATE A JIT GRANULE CLUSTER BEFORE HIS
*D*               INITIAL INSWAP.
*D*      REGISTERS: R4 - USER NUMBER (INPUT)
*D*                R11 - LINK
*D*                R15 - BASE PRIORITY (INPUT)
*D*               ALL OTHER REGISTERS ARE VOLATILE
*D*      ENVIRONMENT- ADD1 EXECUTES UNMAPPED MASTER WITH ALL INTERRUPTS
*D*               INHIBITED.  INTERRUPTS ARE ENABLED ON EXIT FROM ADD1
*D*      INTERFACE: T:SGAJIT - ALLOCATE DISC GRANULE
*D*                 STIRC - EXECUTABLE STATE CHANGE
*D*                 T:RES - QUEUE FOR SWAPPER PAGE
*D*********************************************************************
         SPACE    1
ADD1     EQU      %
         MTW,1    S:CUIS            INCREMENT NO. OF USERS IN SYSTEM
         STB,R15  UB:PRIOB,R4       PUT AWAY USER PRIORITY
*  GET GRAN FOR JIT AFTER DECIDING WHICH RAD AND GRAN POS ON THAT RAD
GETJIT   PUSH     11
         DISABLE
         LW,R1    NSWAP
         LI,15    -1
GJG1     EQU      %
         CW,15    M:FREE#GRAN-1,1   IS # IN HAND GREATER THAN BUSH
         BGE      GJG2              SURE IS, KEEP IT AND TRY NEXT
         LW,3     1                 NAA, IF DEVICE WASN'T REMOVED
         AI,3     -1                HEAD FOR THE BUSHES
         LB,3     MB:SDI,3
         LB,11    DCT24,3
         CI,11    X'80'
         BANZ     GJG2
         LW,15    M:FREE#GRAN-1,1   NAA, HEAD FOR THE BUSHES
         LW,2     1                 AND POINT TO NEW ONE
GJG2     EQU      %
         BDR,1    GJG1            TRY NEXT
         AI,2     -1
*  2 POINTS TO THE MOST AVAILABLE RAD  GET NXT GRAN POS
         STB,2    UB:SWAPI,4        ALLOCATE USER TO RAD
         LW,1     M:JITPAGE,2       NEXT GRAN POS
         BAL,11   T:SGAJIT
         BCS,1    GJG4              NONE AVAEIL
         LB,1     MB:SPACEJIT,2     INCR VALUE TO SPACE AROUND THIS RAD
         AWM,1    M:JITPAGE,2       UPDATA FOR NXT
         LI,2     STIRC             MAKE HIM INTERACTIVELY EXECUTABLE
GJG3     RES      0
         PULL     11                RESTORE RETURN
         STH,15   UH:AJIT,4         ESTABLISH USERS JIT DISC ADDR.
         LH,R15   UH:FLG,R4         GET USER FLAGS
         OR,R15   =TIC+PPSWP        SET TEL IN CONTROL AND PPSWAP
         STH,R15  UH:FLG,R4         STORE FLAGS
         LI,R3    SQUAN+SWAPD       SET SQUAN AND JUST SWAPPED BIT
         STH,R3   UH:FLG2,R4        IN SECOND FLAGS
         LI,R3    1+:BIG            INITIAL PAGE COUNT
         STB,3    UB:PCT,4          USER NEEDS 1 PAGE FOR HIS JIT
         LB,3     UB:US,4           GET CURRENT STATE
         LI,1     0
         STH,1    UH:DL,4           MAKE SURE DOLIST EMPTY.
         CI,1     NSCPU             NO. OF SLAVE CPUS
         BE       %+3               NONE
         STB,1    UB:CALR,4         CLEAR CAL RATE
         STW,1    U:CALC,4          AND CAL COUNT
         MTB,0    R10               WAS RESOURCE PASSED
         BEZ      0,R2              NO - EXIT
         LI,R1    RESCNCT           DOES RAS HANDLER EXIST
         BEZ      0,R2              NO - IGNORE THIS
         B        0,R1              DISPATCH RAS HANDLER - RETURN VIA R2
GJG4     RES      0
         LI,6     E:ND              RESOURCE INDEX
         LI,2     T:RES             SET TO BLOCK FOR DISC PAGE
         LI,15    -1                SET FLAG FOR SWAPPER
         B        GJG3              MERGE WITH COMMON
LOGNO    EQU      ENBISR4
*
*
*
*
         PAGE
         TITLE    'P U L L   E X I T'
T:UTSXTS EQU      %
*                 COPY ENVIRONMENT FROM TSTACK TO USER STACK.
*                 MAPPED.  INTERRUPT INHIBITS UNCHANGED.
*                 R1 = ADDRESS OF USER STACK POINTER DOUBLEWORD.
*                 R0 CONTENTS WILL BE ON TOP OF USER STACK AFTER COPY.
*                 R10/R11 ARE CONTENTS/MASK TO REPLACE PSW0 IN TSTACK
*                         AFTER COPY.
*                 R4 = LINK.  RETURNS 1,R4 IF COPY IS SUCCESSFUL.
*                                   R0,R1,R4,R6 PRESERVED.
*                                   R2 = ADDRESS OF PSW0 IN USERSTACK.
*                                   R3 = MID-ADDRESS OF PSD IN TSTACK.
*                                   R5 = J:TCB.
*                                   R0 IN TSTACK = J:TCB.
*                                   R1 IN TSTACK => PSW0 IN USERSTACK.
*                                   PSW0 IN TSTACK MODIF. PER R10/R11.
*                             RETURNS 0,R4 IF USER STACK IS BAD.
*                                   R0,R1,R4,R6 PRESERVED.
*                                   R10,R11,R14 PRESERVED.
*
         LW,3     1
         BAL,7    CHKPROT-1         CHECK SPD IN 00 SPACE.
         LD,12    *1                12/13 ARE SPD.
         LW,3     12
         AI,3     1
         BAL,7    CHKPROT           CHECK STACK BOTTOM IN 00 SPACE.
         CI,12    1
         BAZ      %+4               IF STACKBOTTOM IS EVEN,
         LI,3     21                  PUSH 21 WORDS
         LI,5     -1                  STARTING WITH A -1.
         B        %+3               IF STACKBOTTOM IS ODD,
         LI,3     20                  PUSH 20 WORDS
         LI,5     0                   STARTING WITH A 0.
         LW,9     L(X'80008000')
         LS,8     13                REMEMBER SPD TRAP BITS.
         OR,13    L(X'80008000')
         MSP,3    12                MODIFY SPD IN 12/13.
         BCS,10   0,4               ----->  EVIL STACK....
         STS,8    13                RESTORE SPD TRAP BITS.
         LW,3     12
         BAL,7    CHKPROT           CHECK STACK TOP IN 00 SPACE.
         STD,12   *1                STORE UPDATED SPD.
         LW,2     12
         AI,2     -18               2 => PLACE FOR PSD.
         LW,3     TSTACK
         AI,3     -17               3 => PSD IN TSTACK.
         LD,14    *3
         STD,14   *2                STORE PSD IN OTHER STACK.
         STS,10   14                  FIX UP PSW0
         STD,14   *3                  IN TSTACK.
         STW,5    -1,2              STORE -1 OR 0 IN OTHER STACK.
         LCI      8
         LM,8     2,3
         STM,8    2,2               STORE REGS 0-7 IN OTHER STACK.
         LM,8     10,3
         LCI      9
         STM,8    10,2              STORE REGS 8-15 IN OTHER STACK.
         LW,5     J:TCB
         STW,5    2,3               STORE TCBADDR IN R0 IN TSTACK.
         STW,2    3,3               STORE => PSD  IN R1 IN TSTACK.
         B        1,4               -----> OKAY RETURN...
*
*
         LI,15    -1                GARBAGE PAGE # FOR FIRST CALL.
CHKPROT  EQU      %
*                 CHECK STOREABILITY IN *R3. USES R2,R3,R15.
*                 RETURN 0,R7 IF OKAY,  0,R4 IF BAD.
         AND,3    X1FE00            CONVERT ARG TO PAGE ADDRESS.
         CW,3     15                SAME PAGE...
         BE       0,7               ---> YES. MUST STILL BE OKAY.
         CI,3     JOVVPA            OUTSIDE THE MONITOR ROOT...
         BGE      %+2               ---> YES.
         B        0,4               ---> NO. MUST BE BAD.
         LW,15    3                 REMEMBER PAGE ADDRESS.
         SLD,2    21                R2= PAGE#/4.
         SCS,3    2                 R3= PAGE# MOD 4.
         LB,2     J:JAC,2           GET BYTE OF ACCESS CODES.
         CB,2     L(X'C0300C03'),3  COMPARE THE PROPER TWO BITS.
         BAZ      0,7               ---> STOREABLE. RETURN OKAY.
         B        0,4               ---> NOT STOREABLE. RETURN BAD.
         PAGE
T:PULLE  EQU      %
         DISABLE
         BUMP     -19,2
         BCR,1    T:PULLE1          B/STACK NOT EMPTY
         LW,2     J:JIT             L/WD 0 OF JIT
         BEZ      T:PULLE1          BEZ; MONITOR JIT, DON'T TOUCH TSTACK SIZE
         LI,2     JTSTACKSZ         L/USER JIT'S TSTACK SIZE
         STH,2    TSTACK+1          PURGE OSTACK; RESET SPACE COUNT
T:PULLE1 EQU      %
GRANT    EQU      T:PULLE
         LI,2     2
         AW,2     TSTACK
         STW,2    PULLE1+1
         LCI      0
         LM,0     2,2
         LPSD,8   *PULLE1+1
         PAGE
*
*        CLOCK4 INTERRUPT ROUTINE
*
CLK4     EQU      %
         PUSH     9
         LW,9     CLK4PSD
         CW,9     Y008
         BAZ      CK3EX
         PULL     9
         LPSD,11  C3MP              CLEAR INT,PUSHE AND SSE1
CK3UM1   T:PUSHE  CLK4PSD
         B        SSE1
CK3EX    PULL     9
         LPSD,11  CLK4PSD           CLEAR INT AND RETURN
         TITLE    'S U B R O U T I N E S'
*
*        SUM TOTAL USER SIZE
*
*        R0 - TOTAL USER SIZE (OUTPUT) LESS LOCKED PROCS
*        R1 - TEMP            (VOL)
*        R2 - TOTAL USER SIZE (OUTPUT) INCLUSIVE
*        R3 - TEMP            (VOL)
*        R4 - USER NUMBER     (INPUT)
*        R5 - TEMP            (VOL)
*        R7 - LINK
*        R15 - TEMP - FLAGS   (VOL)
*
T:TOTSZ  EQU      %
T:TOTESZ EQU      %
         LH,15    UH:FLG,4          GET USER FLAGS
         LB,0     UB:PCT,4          DATA PAGE COUNT
         LB,R2    UB:PCT,R4         AND AGAIN
         CI,15    TIC               CHECK FOR TEL
         BANZ     TOTE1             YES
         CI,15    DIC               CHECK FOR DELTA
         BANZ     TOTE2             YES
         LB,1     UB:APR,4          PROCESSOR ROOT
         BAL,5    TOTE              ADD PSZ
         LB,1     UB:APO,4          PROCESSOR OVERLAY
         BAL,5    TOTE              ADD ITS PAGES
         LB,1     UB:ASP,4          GET SPECIAL SHARED PROC
         BEZ      TOTE2             ---> (OR DEBUGGER IF NO ASP)
TOTE3    BAL,5    TOTE              ADD
         LB,1     UB:OV,4           MONITOR OVERLAY
         BAL,5    TOTE              ADD
         B        0,7               RETURN
TOTE1    LB,1     UB:ACP,4          COMMAND PROCESSOR
         B        TOTE3
TOTE2    LB,1     UB:DB,4           DEBUGGER
         B        TOTE3
TOTE     BEZ      0,5               RETURN IF NO
         LB,R3    PB:PSZ,R1         GET PROCEDURE SIZE
         AW,R2    R3                ADD TO INCLUSIVE TOTAL
         MTB,0    PB:LCT,R1         TEST FOR LOCK
         BNEZ     0,R5              YES, DONT ADD TO NET TOTAL
         AW,R0    R3                ADD SIZE TO NET TOTAL
         B        0,5               RETURN
         PAGE
*
* MISC ROUTINES
*
*
*  INCREMENT ASSOCIATED PROCESSOR COUNTS  (DECREMENT)
*  BAL ON 2, USER IS 4
*
DRTEL1   RSETST   TIC               DECR/RESET TEL
DTEL     EQU      %
         LB,1     UB:ACP,4          GET COMMAND PROC #
DECR     MTB,-1   PB:UC,1
         B        0,2
ISTEL    LSETRST  TIC               INCR/SET TEL
ISTEL1   EQU      ISTEL+1           ENTRY IF GLAGS IN 15
ITEL     EQU      %
         LB,1     UB:ACP,4          GET COMMAND PROC #
INCR     MTB,1    PB:UC,1
         B        0,2
DTORP    CI,R15   TIC               CHECK FOR TEL IN CONTROL
         BANZ     DTEL              YES
DPROCS   LB,1     UB:APR,4
         MTB,-1   PB:UC,1
         LB,1     UB:APO,4
         MTB,-1   PB:UC,1
         LH,15    UH:FLG,4
         CI,15    DIC
         BANZ     DDB
DASP     LB,1     UB:ASP,4          DECR ASP
         BNEZ     DECR
DDB      LB,1     UB:DB,4
         B        DECR
DOV      LB,1     UB:OV,4
         B        DECR
ITORP    LH,15    UH:FLG,4
         CI,15    TIC
          BANZ    ITEL
IPROCS   LB,1     UB:APR,4          INCCR PROCS
         MTB,1    PB:UC,1
         LB,1     UB:APO,4
         MTB,1    PB:UC,1
         LH,15    UH:FLG,4
         CI,15    DIC
         BANZ     IDB
         LB,1     UB:ASP,4          INC ASP
         BNEZ     INCR
IDB      LB,1     UB:DB,4
         B        INCR
IOV      LB,1     UB:OV,4
         B        INCR
         PAGE
         END

