         PCC      0
         DEF      MPSCHED:          PATCHING DEF
MPSCHED: RES
*P*********************************************************************
*M*      MPSCHED  SLAVE CPU EXECUTION SCHEDULER                       *
*P*********************************************************************
*P*                                                                   *
*P*                     MPSCHED                                       *
*P*                                                                   *
*P*      PURPOSE: TO SCHEDULE EXECUTION FOR SLAVE CPUS IN A           *
*P*               MULTIPROCESSING SYSTEM.  MOST TWO-WAY               *
*P*               COMMUNICATION BETWEEN MASTER AND SLAVE IS           *
*P*               PERFORMED BY THIS MODULE.                           *
*P*                                                                   *
*P*      DESCRIPTION: CODE IN THIS MODULE MUST BE CONTAINED IN        *
*P*               THE MONITOR ROOT AND IS EXECUTED UNMAPPED BY        *
*P*               THE MASTER CPU ONLY.  ENTRY IS MADE BY ANY OF       *
*P*               THE SLAVE TO MASTER INTERRUPTS OR A CALL TO         *
*P*               T:SES.  IF ENTRY IS VIA AN INTERRUPT, A             *
*P*               STANDARD ENVIRONMENT IS SAVED AND T:SES IS          *
*P*               CALLED.                                             *
*P*                                                                   *
*P*               T:SES WILL PARK THE USER CURRENTLY ASSIGNED         *
*P*               TO ANY SLAVE NEEDING SERVICE AND FOLLOWING          *
*P*               THE SAME BASIC STRATEGY AS IN THE NORMAL            *
*P*               EXECUTION SCHEDULER ATTEMPT TO FIND A SLAVE         *
*P*               QUALIFIED CANDIDATE(E.G. NOT MASTER ONLY).          *
*P*               IF A FIND IS MADE THE USERS STATE IS CHANGED        *
*P*               TO CURRENT USER(SCU) AND THE USER NUMBER PASSED     *
*P*               TO THE SLAVE CPU.  EACH CALL TO T:SES WILL          *
*P*               CAUSE ALL SLAVE CPUS TO BE SERVICED.                *
*P*                                                                   *
*P*********************************************************************
         TITLE    'MULTI-PROCESSING SCHEDULER'
UFLAGS   SET      1
BITS     SET      1
MPBITS   SET      1
         SYSTEM   UTS
         PAGE
*
*        REGISTER DEFINITIONS
*
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
*
*        USER TABLES
*
         REF      UB:US             USER STATE NUMBER
         REF      UB:FL             STATE Q FORWARD LINK
         REF      UB:PRIO           USER'S CURRENT PRIORITY
         REF      UB:PRIOB          BASE PRIORITY
         REF      UB:MPFLG          MULTIPROCESSING FLAGS
         REF      UB:CALR           CPU PREFERENCE TABLE
         REF      UH:FLG            FLAGS
         REF      UH:FLG2           SECOND FLAGS
         REF      UH:DL             DO LIST
*
*        STATE TABLES
*
         REF      SB:HQ             HEAD OF QUEUE
*
*        SCHEDULER DATA
*
         REF      S:PRIODEC         PRIORITY DECREMENT
         REF      S:EVF             EVENT COUNTER/FLAG
         REF      S:ISUNF           FLAG FOR USERSOUT RUNNING
         REF      S:OPC
         REF      SL:OPC
*
*        PROCESSOR CONTROL TABLES
*
         REF      S:PCUN            CURRENT USER NUMBER
         REF      SB:MPSW           MASTER ATTENTION REQUEST
         REF      SB:PFLG           POST MASTERONLY FLAG
         REF      SB:SFLG           POST SQUAN FLAG
         REF      SB:INIT           START/STOP FLAGS
         REF      SB:RCVR           RECOVER REQUEST
         REF      SB:RCVA           RECOVER ACKNOWLEDGE
         REF      S:SSCRCH          SLAVE REQUESTED SCREECH
         REF      FB:EFLG           HARDWARE FAULT FLAG
         REF      F:EADDR           REAL ADDRESS OF ERRLOG ENTRY FOR SLAVE
*
*        JIT CELLS
*
         REF      J:RNST            RUN STATUS FOR USER
         PAGE
*
*        CONTROL PARAMETERS
*
*
*        STATE NUMBERS
*
         REF      SCU               STATE NUMBER  - CURRENT USER
         REF      SEXU              NUMBER OF HIGHEST EXECUTABLE STATE
*
*        CENTRAL SUBROUTINES
*
         REF      T:CHS             CHANGE STATE
         REF      STIOCC            CHANGE TO EXECUTABLE WITH I/0 BOOST
         REF      T:SSE             CENTRAL INTERRUPT EXIT
         REF      T:SAVE            SAVE STANDARD ENVIRONMENT
         REF      T:GJOBSTRT        START UP MOOSE GHOST
         REF      ERRLOG            LOG ERROR FOR SCREECHING SLAVE
*
*        FLAGS AND MASKS
*
         REF      Y7D               CONSTANT FOR NORMALIZING SHIFT
*
*        SLAVE TO MASTER INTERRUPT PSDS
*
         REF      SIPSD1            SLAVE ONE INTERRUPT PSD
*
*        SLAVE INTERRUPT ENTRY POINTS
*
         DEF      T:SLAVE           INTERPROCESSOR INTERRUPT HANDLER
*        ENTRY TO SCHEDULE SLAVE PROCESSORS
*
         DEF      T:SES             SCHEDULE EXECUTION FOR SLAVES
         PAGE
*
*        VALUE DEFINITIONS
*
MASTERONLY EQU    X80               TEMPORARY MASTER ONLY FLAG
*
NSQUAN   EQU      NB31TO0+4         MASK TO RESET SQUAN FLAG
*
*
         PAGE
***********************************************************
*               SLAVE TO MASTER INTERRUPT                 *
*                      RECEIVERS                          *
***********************************************************
TSSEPSD  :PSD     (IA,T:SSE),(WK,1)
TXMOOSE  TEXTC    'MOOSE'
T:SLAVE  EQU      %
         PUSH     6,R13             SAVE REGS TO PICK UP PSD
         LD,R0    SIPSD1            GET PSD
SLAVEI1  BAL,R2   T:SAVE            SAVE STANDARD ENVIRONMENT
         LW,R15   S:SSCRCH          CHECK FOR SLAVE REQUESTED SCREECH
         BEZ      SLAVEI2           NO, ALL OK
SC78     LW,R2    FB:EFLG           ANY HARDWARE FAULTS
         BEZ      DO78              NO,GO SCREECH
         LI,R1    NSCPU             YEP,FIND WHICH ONE
AG78     LB,R2    FB:EFLG,R1        THIS ONE ?
         BEZ      NX78              NOPE
         LW,R6    F:EADDR,R1        YEP,ANY ERRLOG MSG
         BEZ      NX78              NOPE
         BAL,R5   ERRLOG
NX78     BDR,R1   AG78
DO78     SCREECH  X'78'             SOFTWARE CHECK 78
*S*********************************************************************
*S*      SCREECH CODE: 78           CALLED FROM MPSCHED               *
*S*      MESSAGE: SLAVE CPU INITIATED RECOVERY                        *
*S*      SIGNIFICANT REGISTERS:                                       *
*S*               R15 = CONTENT OF S:SSCRCH                           *
*S*                     GIVING CAUSE OF SCREECH IN SLAVE              *
*S*      REMARKS: SOME SIGNIFICANT PROBLEM WAS DETECTED               *
*S*               BY A SLAVE CPU WHICH CAN BE CORRECTED ONLY BY A     *
*S*               FULL SYSTEM RECOVERY.  FOR EXAMPLE A TRAP WITH      *
*S*               NO ASSIGNED CURRENT USER.                           *
*S*********************************************************************
SLAVEI2  EQU      %
         ENABLE                     ALLOW INTERRUPTS
         BAL,R11  T:SES             DRIVE ALL SLAVES
         LPSD,11  TSSEPSD           CLEAR INTERRUPT AND T:SSE
*
         PAGE
*D*********************************************************************
*D*                                                                   *
*D*      NAME:           T:SES                                        *
*D*                                                                   *
*D*            SCHEDULE EXECUTION FOR ALL                             *
*D*                 SLAVE PROCESSORS                                  *
*D*                                                                   *
*D*      PURPOSE: T:SES WILL SERVICE ALL SLAVE CPUS                   *
*D*               WITH SB:MPSW SET.  THE CURRENT USER                 *
*D*               PF A SLAVE, IF ANY, WILL BE PARKED                  *
*D*               AND ANY REQUIRED FLAGS POSTED.  A                   *
*D*               NEW USER SUITABLE FOR SLAVE CPU                     *
*D*               EXECUTION WILL BE FOUND IF POSSIBLE                 *
*D*               AND ASSIGNED TO THE SLAVE CPU.                      *
*D*                                                                   *
*D*      DESCRIPTION: A QUICK CHECK AT THE TOP IS MADE FOR            *
*D*               EITHER SLAVE REQUESTED SCREECH OR NO                *
*D*               SERVICE REQUIRED.  IF ANY SLAVE REQU-               *
*D*               ESTED SERVICE, ALL SLAVE PROCESSOR                  *
*D*               TABLE ENTRIES ARE SCANNED STARTING                  *
*D*               WITH THE HIGHEST NUMBERED SLAVE.                    *
*D*               FOR EACH SLAVE CPU WITH SB:MPSW                     *
*D*               SET, THE CURRENT USER IN S:PCUN                     *
*D*               WILL HAVE HIS FLAGS UPDATED ACCORDING               *
*D*               TO SB:PFLG(MASTER ONLY) AND SB:SFLG                 *
*D*               (SQUAN REACHED) AND THEN BE PARKED.                 *
*D*               IF THE USER WAS MARKED MASTER ONLY,                 *
*D*               HE WILL BE QUEUED TO THE HEAD OF HIS                *
*D*               PRIORITY GROUP.  IN ANY CASE, THE USER              *
*D*               WILL BE GIVEN AN I/O COMPLETE PRIORITY              *
*D*               BOOST AS HE IS PARKED.                              *
*D*               A SWAP SCHEDULE(T:SS) WILL BE PERFORMED             *
*D*               BEFORE ATTEMPTING TO SCHEDULE THE                   *
*D*               SLAVE A NEW EXECUTABLE USER IF THERE                *
*D*               HAD BEEN A SWAP SCHEDULING DIFFICULTY               *
*D*               AND THE USER JUST PARKED HAD PASSED                 *
*D*               HIS SQUAN.                                          *
*D*               IF THE START FLAG IS STILL SET FOR                  *
*D*               THIS CPU AN ATTEMPT WILL BE MADE TO                 *
*D*               SCHEDULE A NEW CURRENT USER SUITABLE                *
*D*               FOR EXECUTION BY SLAVE PROCESSORS.                  *
*D*               THIS WILL BE THE HIGHEST PRIORITY                   *
*D*               IN-CORE USER NOT FLAGGED AS MASTER                  *
*D*               ONLY WHOSE RECENT INTER-CAL COMPUTE                 *
*D*               INTERVAL IS GREATER THAN THE THRES-                 *
*D*               HOLD(SL:MPCALR).  SUCH A USER WILL BE               *
*D*               PASSED TO THE SLAVE CPU VIA S:PCUN                  *
*D*               AND THE SERVICE REQUEST SWITCH(SB:MPSW)             *
*D*               RESET TO SIGNAL THE SLAVE CPU.  THE                 *
*D*               USERS STATE WILL THEN BE CHANGED TO                 *
*D*               SCU AND THE SCAN OF THE PROCESSOR                   *
*D*               TABLES RESUMED.                                     *
*D*               THE SERVICE REQUEST FLAG(SB:MPSW)                   *
*D*               BE CLEARED FOR ANY PROCESSOR THAT IS                *
*D*               TO BE STOPPED AFTER PARKING ITS USER                *
*D*               IF ANY.                                             *
*D*                                                                   *
*D*      REGISTERS: R11 - LINK                                        *
*D*                 ALL OTHERS VOLATILE                               *
*D*                                                                   *
*D*      INTERFACE:                                                   *
*D*               T:CHS - CHANGE STATE                                *
*D*               STIOCC - EXECUTABLE STATE CHANGE AT                 *
*D*                        I/O COMPLETE PRIORITY OFFSET               *
*D*                                                                   *
*D*      INPUT:   SLAVE PROCESSOR TABLES                              *
*D*               SB:MPSW - SERVICE REQUEST FLAG                      *
*D*               SB:PFLG - POST MASTER ONLY FLAG                     *
*D*               SB:INIT - CPU START STOP FLAGS                      *
*D*               S:PCUN - SLAVE CPU CURRENT USER TO                  *
*D*                        BE DROPPED OR ZERO IF NONE                 *
*D*               SB:SFLG - POST SQUAN REACHED FLAG                   *
*D*               S:SSCRCH - SLAVE REQUESTED SCREECH FLAG             *
*D*               USER TABLES                                         *
*D*               UB:US - USER STATE                                  *
*D*               UB:FL - STATE CHAIN FORWARD LINK                    *
*D*               UB:PRIO - CURRENT PRIORITY                          *
*D*               UB:PRIOB - BASE PRIORITY                            *
*D*               UB:MPFLG - MULTIPROCESSING FLAGS                    *
*D*               UB:CALR - RECENT AVG INTERCAL INTERVAL              *
*D*               UH:FLG - USER FLAGS                                 *
*D*               UH:FLG2 - SECOND USER FLAGS(SQUAN)                  *
*D*               STATE CHAINS                                        *
*D*               SB:HQ - HEADS OF STATE QUEUES                       *
*D*               CONTROL PARAMETERS                                  *
*D*               SL:MPCALR - INTERCAL INTERVAL SELECTION THRESHOLD   *
*D*               S:PRIODEC - PRIORITY DECREMENT WHEN SCHEDULED       *
*D*      OUTPUT:                                                      *
*D*               SB:MPSW - 0 IF USER ASSIGNED                        *
*D*               SB:PFLG - 0                                         *
*D*               SB:SFLG - 0                                         *
*D*               S:PCUN - ASSIGNED USER NUMBER OR 0                  *
*D*               UB:MPFLG - MASTER ONLY FLAG SET                     *
*D*                          ACCORDING TO SB:PFLG                     *
*D*               UH:FLG2 - SQUAN RESET IF SB:SFLG                    *
*D*               UB:PRIO - DECREMENT TOWARDS BASE FOR                *
*D*                         FOR NEW USER SCHEDULED                    *
*D*               STATE CHAIN UPDATED VIA T:CHS AND                   *
*D*               STIOCC                                              *
*D*                                                                   *
*D*      ERROR EXIT:    SOFTWARE CHECK 78 IF S:SSCRCH                 *
*D*                     NON-ZERO.                                     *
*D*                                                                   *
*D*********************************************************************
         SPACE    2
T:SES    EQU      %
         LW,R15   S:SSCRCH          CHECK FOR SLAVE REQUESTED SCREECH
         BNEZ     SC78              YES
         LW,R0    SB:MPSW           CHECK FOR ANY REQUESTS
         BEZ      *R11              NONE, EXIT QUICKLY
         PUSH     R11               SAVE RETURN
         LI,R1    NSCPU             INITIALIZE PROCESSOR INDEX
SES1     LB,R0    SB:MPSW,R1        IS REQUEST SWITCH SET?
         BNE      SES3              YES, TRY TO HELP HIM
SES2     BDR,R1   SES1              SCAN ALL SLAVES
SES21    PULL     R11               RESTORE RETURN
         B        *R11              RETURN, ALL DONE
*
*        WE HAVE A SLAVE WHO NEEDS SERVICE
*
SES3     DISABLE                    BLOCK OTHER INTERRUPTS IN MASTER
         LB,R0    SB:MPSW,R1        CHECK TO SEE HE STILL NEEDS SERVICE
         BEZ      SES2E             ENABLE AND CONTINUE SCAN
         LI,R4    0                 ZAPPER FOR USER NUMBER
         XW,R4    S:PCUN,R1         GET AND ZAP
         BEZ      SES15             NO USER NOW
         LI,R0    0                 FLAG ZAPPER
         LB,R8    UB:MPFLG,R4       GET MULTIPROCESSING FLAGS
         LB,R2    SB:PFLG,R1        SHOULD WE POST MASTER ONLY FLAG
         BEZ      SES32             NO
         OR,R8    MASTERONLY        SET MASTER ONLY FLAG
         STB,R8   UB:MPFLG,R4       REPLACE FLAGS
         STB,R0   SB:PFLG,R1        ZAP FLAG REQUEST
SES32    LB,R2    SB:SFLG,R1        SHOULD WE POST SQUAN
         BEZ      SES34             NO
         LH,R14   UH:FLG2,R4        GET SECOND FLAGS
         AND,R14  NSQUAN            RESET SQUAN FLAG BIT
         STH,R14  UH:FLG2,R4        AND RESTORE SECOND FLAGS
         STB,R0   SB:SFLG,R1        CLEAR POSTING REQUEST
         PAGE
         SPACE    2
SES34    LB,R3    UB:US,R4          GET CURRENT STATE FOR USER
         LB,R2    J:RNST            GET RUN STATUS
         BEZ      SES345
         LH,R2    UH:DL,R4          GET DO LIST
         OR,R2    X1000             SET BREAK BIT
         STH,R2   UH:DL,R4          RESTORE DO LIST
SES345   EQU      %
         LH,R15   UH:FLG,R4         GET USER FLAGS
         PUSH     R1                SAVE PROCESSOR INDEX
         CW,R8    MASTERONLY        CHECK FOR MASTER ONLY
         BAZ      %+2               NO, QUEUE AT TAIL
         OR,R4    Y8                SET FLAG TO QUEUE AT HEAD OF Q
         BAL,R11  STIOCC            CHANGE TO EXECUTABLE WITH
*                                   I/O PRIORITY BOOST
         PULL     R1                AND PROCESSOR INDEX
SES15    LB,R2    FB:EFLG,R1        ANY HARDWARE FAULTS
         BEZ      SES18             NOPE
         PUSH     R1                SAVE INDEX
         LD,R0    TXMOOSE           START UP MOOSE
         BAL,R10  T:GJOBSTRT        GHOST FOR PROCESSING
         PULL     R1                RESTORE INDEX
SES18    LW,R14   S:EVF             GET CURRENT EVENT COUNTER
         LB,R2    SB:INIT,R1        CHECK FOR RUNNING
         AND,R2   M2                ISOLATE FLAGS
         CI,R2    STARTBIT          START BUT NOT STOP
         BNE      SES5              HE IS STOPPED
         LW,15    S:OPC             DON'T SCHEDULE SLAVES IF SWAPPER
         AW,15    SL:OPC            IS FAILING.
         BGEZ     %+3
         ENABLE
         B        SES21
         PAGE
*
*        NOW SCHEDULE A SUITABLE USER FOR THIS SLAVE
*
*        THE BASIC SELECTION PROCESS IS THE SAME AS FOR THE
*        MASTER CPU - THE HIGHEST PRIORITY, EXECUTABLE USER
*        WITH THE READY TO RUN BIT SET IS FOUND.  ADDITIONAL
*        QUALIFYING CHECKS ARE THEN MADE BEFORE PASSING HIM TO A
*        SLAVE PROCESSOR.
*
         LI,R15   RTR               FLAG TO CHECK FOR READY TO RUN
         LD,R2    SB:HQ             GET HEADS OF FIRST SEVEN STATES
         BEZ      SCHEDS1           NONE GO TO START AT STATE#8
         OR,R2    Y7D               SET EXPONENT FOR FLOATING SHIFT
         SFL,R2   16                DO NORMALIZE TO FIND FULL STATE
         SCS,R2   7                 COUNT=COUNT/2
         AND,R2   M6                SCRUB TO SIGNIFICANT BITS
         EOR,R2   M6                INVERT TO FORM INDEX
         B        %+2
SCHEDS1  LI,R2    8                 START AT EIGHTH STATE
SCHEDS2  LB,R4    SB:HQ,R2          GET HEAD OF QUEUE
         BEZ      SCHEDS4           NONE IN THIS QUEUE
SCHEDS3  CH,R15   UH:FLG,R4         HE MUST BE COMPLETELY IN CORE
         BANZ     SCHEDS5           YES, CONTINUE CHECKS
SCHEDS35 LB,R4    UB:FL,R4          FLINK ONWARD IN THIS STATE
         BNEZ     SCHEDS3           AND TRY THE NEXT USER
SCHEDS4  AI,R2    1                 NEXT STATE
         CI,R2    SEXU              ONLY LOOK AT EXU STATES
         BLE      SCHEDS2           CONTINUE
SES2E    ENABLE                     RELEASE INTERRUPT INHIBITS
         B        SES2              AND LOOK AT NEXT SLAVE
         PAGE
*
*        WE HAVE A GOOD CANDIDATE BUT NOW MAKE SURE
*        HE IS SUITABLE FOR A SLAVE CPU
*
SCHEDS5  LC       UB:MPFLG,R4       GET MP FLAGS
         BCS,8+4  SCHEDS35          EITHER PERM OR TEMPORARY
*
*        CHECK TO SEE IF USER DESIRES TO RUN ON CERTAIN CPU #
*
         LB,R0    UB:CALR,R4        CHK PREFERENCE
         BEZ      SCHEDS5A          DEALER'S CHOICE
         CB,R1    UB:CALR,R4        IS PROPER CPU # NOW
         BNE      SCHEDS35          NO-> DEFER TILL WE DO IT LATER
SCHEDS5A EQU      %
*
*        NOW OUR CHOICE HAS BEEN PROPERLY QUALIFIED AS
*        WORTHWHILE FOR SLAVE DISPATCHING
*
         DISABLE                    RE-INHIBIT MASTER INTERRUPTS
         CW,R14   S:EVF             CHECK FOR ANY EVENTS
         BNE      SES6              YES
         LC       S:ISUNF           CHECK FOR USERSOUT RUNNING
         BCS,8    SES21             YES GET OUT
         LB,R0    SB:MPSW,R1        TEST FLAG TO SEE IF HE STILL
*                                   NEEDS SERVICE
         BEZ      SES2E             NO, WE WERE INTERRUPTED
         LW,R8    S:PCUN,R1         DOES HE STILL NEED A USER
         BNEZ     SES3              YES, BUT WE MUST DROP ONE
*                                   FIRST. WE WERE INTERRUPTED AND
*                                   SCHEDULED  A USER FOR HIM WHO
*                                   BLOCKED IMMEDIATELY.
         LH,R15   UH:FLG,R4         GET USER FLAGS
         STW,R4   S:PCUN,R1         SET HIS NUMBER INTO SLAVE TABLE
         LI,R0    0                 ZAPPER
         STB,R0   SB:MPSW,R1        RELEASE SLAVE TO WORK ON
*                                   THIS USER
         PUSH     R1                SAVE PROCESSOR INDEX
         LI,R2    SCU               NEW STATE IS CURRENT USER
         LB,R5    UB:PRIO,R4        GET CURRENT PRIORITY
         CB,R5    UB:PRIOB,R4       AND COMPARE AGAINST
         BGE      %+3               BASE, AT BASE NOW
         AW,R5    S:PRIODEC         DECREMENT PRIO ONE STEP
         STB,R5   UB:PRIO,R4        AND REMEMBER NEW VALUE
         LB,R3    UB:US,R4          GET USER'S CURRENT STATE
         BAL,R11  T:CHS             CHANGE STATE TO SCU
*                                   ***** ENABLES *****
         PULL     R1                RESTORE CPU INDEX
         B        SES2              AND CONTINUE TO NEXT
         PAGE
*        SLAVE HAS STOP FLAG SET
*
SES5     LI,R0    0
         STB,R0   SB:MPSW,R1        CLEAR MASTER FLAG
         B        SES2E             AND CONTINUE
*
*        RE-CYCLED BECAUSE EVENTS OCCURRED DURING SCHEDULE ATTEMPT
*
SES6     ENABLE
         B        SES18             AND TRY AGAIN
*
         END

