         SYSTEM   UTS
         DEF      MBS
         REF      FIPRI,RUNPRI,FIND,FIND1,SB:RTY
         DEF      MBSOP
         REF      UB:FL,UB:BL,SB:TQ,SB:HQ,ADD1
         REF      SNULL
         REF      UH:FLG
         REF      SL:PI
         REF      S:BUIS,S:BUAIS,S:BFIS,S:MBSF
         REF      AVRTBL,AVRNOU,AVRID,AVRTBLSIZ,AVRTBLNE
         REF      BH:HPRI,BH:TPRI,BH:LINK
         REF      BH:XLNK,BH:SLNK,BB:PI,BB:RID
         REF      GI:FRE,GI:SDA,GI:RES,GI:ASPN,GIB:PRT
         REF      GIH:TIM,GIB:RID,GIB:UN,GIB:XLN,GIB:SLN
         REF      GIB:PRI
         REF      BH:PART,BH:SID,BH:TIME,S#H:LNK
         REF      BW:SDA,S#W:SER,MBSOP#,TMPSTK,DCT4,MBSMSK
         REF      BD:ACCT
         REF      LSERIAL,TSERIAL
         REF      LPART,PL:LK,PL:CHG
         REF      PLB:USR
         REF      PLH:TL,PLH:TU,PLH:FLG,PLH:SID
         REF      PLH:CUR,PLH:TOL
         REF      PLD:ACT
         REF      YC,M8
         REF      BSL:CRES,SV:RSIZ,SH:RTOT,SH:ROCU,SH:RGCU,SH:RBSUM
         REF      SH:RBCU,PLB:MIN,PLB:MAX,B4W:RES,SB:RBDF
         REF      B8:CRES,S#B:TYP,OB:BTX,RSERIAL,M7
         REF      BADRS
         REF      DCTSIZ
         REF      BI:ASPN
         REF      BATAPE
         REF      SVZ,SVIV,YFF,RCVRFLG
         REF      SL:BPRIO
         REF      RRBIT,JEBIT
         PAGE
         CSECT    1
BACCT    EQU      BT31TO0+31
BORDR    EQU      BT31TO0+32
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
PLK      EQU      1
PHOLD    EQU      X'8000'
PRUN     EQU      X'2000'
PACCT    EQU      X'4000'
RBLGL    EQU      2
LCLGL    EQU      8
JELGL    EQU      4
         PAGE
*        MBSOP,REPART
*        SET OR RESET BITS IN BH:PART
*        BAL,11   MBSOP
*          2 = BH:PART INDEX
*          ALL BITS ARE SET IF JOB FITS IN PARTITION
*          AND RESET IF JOB DOESN'T FIT
*        BAL,11   REPART
*          15= BH:PART BITS TO BE REEXAMINED
*          THOSE BITS IN 10 ARE SET OR RESET APPROPRIATELY
*          IN BH:PART FOR ALL JOBS IN THE QUEUE
*
*
*MBSOP#  EQU      SV:RSIZ*LPART     (DEFINED BY SYSGEN)
*
MBSOP#1  EQU      MBSOP#+LPART-1
*
*MBSOP#1 CAN BE ADDED TO THE PLB:MIN/MAX INDEX
*OF RESOURCE N IN PARTITION 0 (WHICH OF COURSE ISNT
*REALLY THERE) TO OBTAIN THE INDEX OF RESOURCE N-1
* IN PARTITION LPART
*
MBSOP#2  EQU      MBSOP#1+1+SV:RSIZ
*
*MBSOP#2 IS THE PLB:MIN/MAX INDEX OF THE HIGHEST
*NUMBERED (SV:RSIZ+1) RESOURCE IN THE HIGHEST
*NUMBERED (LPART) PARTITION
*
*MBSMSK MASKS OFF LEGAL PARTITION BITS FOR BH:PART AND
* IS EQUAL TO (1**LPART)-1
*
MBSOP    EQU      %
         LCI      3
         PSM,5    TMPSTK
         LW,12    BADRS
         LI,15    -1
         B        REPART1
REPART   EQU      %
         LI,1     FIPRI
         BAL,0    FIND
         B        *11
         LW,12    2
         SLS,12   2
         AI,12    B4W:RES
REPART1  EQU      %
         LI,R14   0
         LI,R7    RBLGL
         LB,R3    BB:RID,R2
         BNEZ     CKORG
         LW,R3    JEBIT
         CW,R3    BW:SDA,R2
         BANZ     %+2
         AI,R7    LCLGL-JELGL
         AI,R7    JELGL-RBLGL
CKORG    EQU      %
         LI,R3    LPART
         CH,R7    PLH:FLG,R3
         BAZ      %+2
         OR,R14   BT31TO0,R3
         BDR,R3   %-3
         AND,14   15
         BEZ      MBSOP4
         BAL,7    CKRS
         B        MBSOP3
         BAL,8    SETRS
         BAL,10   CKRS1
MBSOP1   EQU      %
         CB,13    PLB:MAX,5
         BG       CKRSB
         CB,13    PLB:MIN,5
MBSOP2   BL       CKRSB
         B        CKRSG
MBSOP3   EQU      %
         LH,13    BH:TIME,2
         LI,7     MBSOP4
         BAL,10   CKRS1
         CH,13    PLH:TU,3
         BG       CKRSB
         CH,13    PLH:TL,3
         B        MBSOP2
MBSOP4   EQU      %
         LH,13    BH:PART,2
         STS,14   13
         STH,13   BH:PART,2
         CI,15    -1
         BNE      FIND1
         LCI      3
         PLM,5    TMPSTK
         B        *11
CKRS     EQU      %
         LI,6     SV:RSIZ
         LI,5     MBSOP#2
         B        1,7
CKRS1    EQU      %
         LI,3     LPART
CKRS2    CW,14    BT31TO0,3
         BANZ     *10
         B        CKRSG
CKRSB    EQU      %
         AND,14   NB31TO0,3
CKRSG    EQU      %
         AI,5     -(SV:RSIZ+1)
         BDR,3    CKRS2
         AI,5     MBSOP#1
         BDR,6    1,7
         B        0,7
SETRS    EQU      %
         LB,13    *12,6
         CI,13    X'80'
         BAZ      *8
         LB,13    SB:RBDF,6
         OR,13    X80
         STB,13   *12,6
         AND,13   M7
         B        *8
         PAGE
*        LINK JOB ENTRY TO TAIL OF PRIORITY QUEUE
*        BAL,11   BATQT
*  3=ENTRY INDEX;          4=PRIORITY
*        6 CLOBBERED
BATQT    LH,6     BH:TPRI,4         QUEUE AT TAIL
         BNEZ     %+2
         STH,3    BH:HPRI,4
         STH,3    BH:TPRI,4
         STH,3    BH:LINK,6
         LI,6     0
         STH,6    BH:LINK,3
         STH,6    BH:LINK
         B        *11
         PAGE
*        REMOVE JOB ENTRY FROM PRIORITY QUEUE
*        BAL,11   BATUNQ
*  3=ENTRY INDEX;          4=PRIORITY
*  7=INDEX OF PREVIOUS ENTRY IN QUEUE.
* IF UNQUEUEING HEAD OF CHAIN, 7 IS EITHER 0 OR
* HA(BH:HPRI)-HA(BH:LINK)+PRIORITY (WHICH IS NEGATIVE)
BATUNQ   LH,6     BH:LINK,3         UNQUEUE
         STH,6    BH:LINK,7                            4=PRIORITY
         BNEZ     %+5
         STH,7    BH:TPRI,4
         CI,7     0
         BG       *11
         STH,6    BH:TPRI,4
         CI,7     0
         BNEZ     *11
         STH,6    BH:HPRI,4
         B        *11
         PAGE
*        PUT USER NUMBER BACK IN SNULL QUEUE
*        USER # IN 2, LINK IN 3, 4 AND 6  CLOBBERED
*        DISABLE ASSUMED
QH0      EQU      %
         LI,4     SNULL
         LB,6     SB:HQ,4           CURRENT HEAD
         STB,6    UB:FL,2           IS NOW 2ND
         STB,2    SB:HQ,4           2 IS NOW HEAD
         STB,2    UB:BL,6
         BNEZ     %+2               CC SET BY LB SB:HQ
         STB,2    SB:TQ,4           EMPTY QUEUE, 2 IS ALSO TAIL
         B        0,3
         PAGE
*        PREPARE TO SELECT A JOB, SWIPE A USER SLOT
MBS      EQU      %
         LCI      7
         PSM,5    TMPSTK
         BAL,11   SVIV
         LW,3     RCVRFLG
         BNEZ     MBSX1
         LI,15    1
         XW,15    PL:LK
         BNEZ     MBSX1
         XW,15    PL:CHG
         BEZ      %+2               NO MODS
         BAL,11   REPART            REPARTITION
MBS1     LI,1     0
         STW,1    PL:CHG            ZAP ANY USER #, CANT HAVE ONE HERE
         LW,3     S:BUAIS
         SW,3     S:BUIS
         MW,3     S:BFIS
         BLEZ     MBSX              NOTHING TO DO
         LW,6     GI:FRE
         BNEZ     %+3
         STW,11   S:MBSF
         B        MBSX
         DISABLE                    GET A USER #
         LI,4     SNULL             NULL STATE INDEX FOR FREE USER SLOTS
         LB,2     SB:HQ,4           TRY TO GET ONE
         BEZ      MBSX
         LB,6     UB:FL,2           NEXT IN QUEUE
         STB,6    SB:HQ,4           SET NEW HEAD
         BNEZ     %+2
         STB,6    SB:TQ,4           NO HEAD => NO TAIL
         STB,1    UB:BL,6           BL OF HEAD IS 0
         STW,2    PL:CHG
         ENABLE
         PAGE
*        SET BIT IN R15 FOR EACH PARTITION
*        WHICH IS NOT RUNNING OR LOCKED OUT
*        AND WHOSE MINIMUM RESOURCES CAN BE ALLOCATED.
MBS3     EQU      %
         LI,14    X'FFFF'
         LI,13    PRUN|PLK
         BAL,7    CKRS
         B        MBSP2
         LH,8     SH:RTOT,6
         SH,8     SH:ROCU,6
         SH,8     SH:RGCU,6
         CH,8     SH:RBSUM,6
         BLE      %+2
         LH,8     SH:RBSUM,6
         SH,8     SH:RBCU,6
         BGEZ     %+2
         LI,8     0
         STH,8    BSL:CRES,6
         BAL,10   CKRS1
         CH,13    PLH:FLG,3
         BANZ     CKRSB
         LB,8     PLB:MIN,5
         CH,8     BSL:CRES,6
         BLE      CKRSG
         B        CKRSB
MBSP2    EQU      %
         LW,15    14
         BEZ      MBSX
         LI,4     FIPRI+1
         LI,7     0
         STH,7    BH:LINK
         B        MBSJ
         PAGE
*        RUN      THE PRIORITY CHAINS UNTIL A JOB
*        FITS IN ANY OF THE RUNNABLE PARTITIONS.
MBSJ0    LW,7     3                 SAVE PREV INDEX
MBSJ     LH,3     BH:LINK,7         NEXT IN CHAIN
         BNEZ     MBSJ2
         LI,7     HA(BH:HPRI)-HA(BH:LINK)-1 TAIL, GET HEAD
         AW,7     4                 OF NEXT PRIORITY
         BDR,4    MBSJ
         B        MBSX              NONE
MBSJ2    CH,15    BH:PART,3         PART AVAILABLE
         BAZ      MBSI              NO, INCR PRIORITY
         PAGE
*        DETERMINE IF ACCOUNT OR ORDER RESTRICTIONS
*        PREVENT RUNNING CANDIDATE JOB.
*        REGISTERS:
*   3     = CANDIDATE JOB INDEX
*   4     = CANDIDATE JOB PRIORITY
*   1,2,5-6 = TEMP INDEXES
*   7     = PREVIOUS PRIORITY CHAIN ENTRY INDEX
*   8-9,12= TEMP
*   10-11 = ACCOUNT
*   13    = FLAGS (BW:SDA)
*   14    = SYSID (BH:SID)
*   15    = RUNNABLE PARTITION BIT MASK
         LW,12    3
         SLS,12   2
         AI,12    B4W:RES
         STW,12   BADRS
         LH,14    BH:SID,3          SYSID
         LW,13    BW:SDA,3          GET FLAGS
         LI,12    PACCT             ACCT FLAG (PART)
         LD,10    BD:ACCT,3         ACCT
         LI,2     LPART
MBSA     CD,10    PLD:ACT,2
         BNE      MBSA1
         CH,12    PLH:FLG,2         RUNNING JOB ACCT DEP
         BANZ     MBSF              CHECK IF F PRIORITY
         CW,13    BACCT
         BANZ     MBSF              NEW ACCT DEPENDENT
         CW,13    BORDR             NEW ORDER FLAG
         BAZ      MBSA1             NO
         CH,14    PLH:SID,2         ORDER
         BG       MBSJ0             WRONG WAY
MBSA1    BDR,2    MBSA
         CW,13    BORDR
         BAZ      MBSR              NO ORDER, CHECK RESOURCES
         LI,1     FIPRI
         BAL,0    FIND
         B        MBSR
         CD,10    BD:ACCT,2
         BNE      FIND1
         CH,14    BH:SID,2
         BG       MBSJ0
         B        FIND1
         PAGE
*        DETERMINE IF ADEQUATE RESOURCES ARE AVAILABLE
*        SAME REGISTERS AS ACCT/ORDER CHECK EXCEPT:
*   2     = 0 ON ENTRY; BECOMES J:SPIN
*   8     = RESOURCE REQUIREMENTS (4 BYTES)
*   9     = HEAD OF FOUND SERIAL NUMBERS CHAIN
*        (SHARED SERIAL NUMBERS FOUND IN AVRTBL
*        ARE UNLINKED FROM THE BB:SLNK CHAIN)
MBSR     EQU      %
         LI,1     3                 CLEAR BI:ASPN
         LI,2     0
         STB,2    B8:CRES
         STW,2    BI:ASPN-1,1
         BDR,1    %-1
         LI,6     SV:RSIZ
         LW,12    BADRS
MBSR0    EQU      %
         BAL,8    SETRS
         CH,13    BSL:CRES,6
         BG       MBSNR
         STB,13   B8:CRES,6
         BDR,6    MBSR0
MBSCS#   EQU      %
         LH,9     BH:SLNK,3
         AH,9     BH:XLNK,3
         BEZ      MBSSP3
         LI,2     RUNPRI+HA(BH:HPRI)-HA(BH:LINK)
MBSCS#0  EQU      %
         LH,2     BH:LINK,2
         BEZ      MBSCM
         LI,13    BH:XLNK
         LI,12    BH:SLNK
         BAL,11   RUNSER
         LI,12    BH:XLNK
         BAL,11   RUNSER
         LI,13    BH:SLNK
         LI,11    MBSCS#0
         B        RUNSER
MBSCM    EQU      %
         LI,1     HA(BH:XLNK)-HA(S#H:LNK)
         AW,1     3
         BAL,11   RUNMNT
         B        MBSCM1
         B        MBSJ0
         B        %-3
MBSCM1   EQU      %
         LH,9     BH:SLNK,3
         LI,1     HA(BH:SLNK)-HA(S#H:LNK)
         AW,1     3
MBSCM2   BAL,11   RUNMNT
         B        MBSSP3
         B        MBSIS
         MTB,1    B8:CRES,2
         B        MBSCM2
MBSIS    EQU      %
         LH,8     AVRID,6
         BNEZ     MBSJ0
         MTB,1    B8:CRES
         SCS,2    -5
         LB,6     2
         SLS,6    -3
         LW,8     BI:ASPN,2
         OR,8     BT31TO0+1,6
         STW,8    BI:ASPN,2
         DISABLE
         LH,6     S#H:LNK,1
         STH,6    S#H:LNK,5
         LH,13    BH:SLNK,3
         STH,13   S#H:LNK,1
         STH,1    BH:SLNK,3
         ENABLE
         CW,1     9
         BNE      %+2
         LW,9     6
         CW,6     13
         BE       MBSCM2
         BDR,11   RUNMNT+1
MBSSP3   EQU      %
         LI,1     SV:RSIZ
         LB,8     B8:CRES,1
         CH,8     BSL:CRES,1
         BG       MBSNR
         BDR,1    %-3
         LI,12    0
         LW,6     9
         BEZ      %+2
         BAL,11   CNTSER+2
         LI,6     HA(BH:XLNK)-HA(S#H:LNK)
         BAL,11   CNTSER
         B        %+3
         LB,6     LSERIAL,6
         BEZ      MBSNR
         BDR,12   %-2
         PAGE
*        RESOURCES ARE AVAILABLE - RUN THE JOB
         DISABLE
         LW,1     GI:FRE            GET GI TABLE SLOT
         SLS,1    -8
         XW,1     GI:FRE
         AND,1    M8
         ENABLE
         LB,6     *BADRS            GET PRIO
         STB,R6   GIB:PRI,1         AND SAVE IN CORE
         LB,6     BB:RID,3
         STB,6    GIB:RID,1
         LH,6     BH:TIME,3
         STH,6    GIH:TIM,1
         LB,2     B8:CRES
         BEZ      MBSSCH1
         LI,5     AVRTBLNE-1        INCREMENT SHARED SER#S
         LI,6     AVRTBLNE+BATAPE-1+X'20'
         SCS,6    -5
         LB,2     6
         AND,6    M8
         SLS,2    -3
         AI,2     1
MBSSCH   EQU      %
         LW,10    BI:ASPN-1,6
MBSSCH0  EQU      %
         CW,10    BT31TO0,2
         BAZ      %+2
         MTH,1    AVRNOU,5
         AI,5     -1
         CI,5     AVRTBLSIZ
         BL       MBSSCH1
         BDR,2    MBSSCH0
         LI,2     32
         BDR,6    MBSSCH
MBSSCH1  EQU      %
         LI,2     4
         LW,10    BADRS
         AI,10    -1
         LW,11    1
         SLS,11   2
         AI,11    GI:RES-1
         LW,12    *10,2
         STW,12   *11,2
         BDR,2    %-2
         AI,11    GI:ASPN-GI:RES
         SW,11    1
         LI,2     3
         LW,12    BI:ASPN-1,2
         STW,12   *11,2
         BDR,2    %-2
*  SWIPE RESOURCES
         LI,6     SV:RSIZ
         LB,12    B8:CRES,6
         AH,12    SH:RBCU,6
         STH,12   SH:RBCU,6
         BDR,6    %-3
         LI,6     LPART
         LH,5     BH:PART,3         FIND PARTITION TO RUN
         AND,5    15
         CW,5     BT31TO0,6
         BANZ     %+2
         BDR,6    %-2
         STB,6    GIB:PRT,1
         MTH,1    PLH:CUR,6
         MTH,1    PLH:TOL,6
         LD,10    BD:ACCT,3
         STD,10   PLD:ACT,6
         LW,2     PL:CHG            GET USER #
         STH,14   PLH:SID,6         PUT USER ID
         LW,13    BW:SDA,3
         AND,13   BACCT             MOVE ONLY ACCT FLAG TO PLH:FLG
         LH,13    13
         AH,13    PLH:FLG,6         ADD IN PHOLD
         AI,13    PRUN              AND PRUN
         STH,13   PLH:FLG,6
         STB,2    PLB:USR,6
         LI,8     0
         STB,8    GIB:SLN,1
         STB,8    GIB:XLN,1
         LB,15    LSERIAL           MOVE SER#S TO CORE
         LW,10    9
         BEZ      %+3
         STB,15   GIB:SLN,1
         BAL,11   MOVSERS
         LH,10    BH:XLNK,3
         BEZ      %+3
         STB,15   GIB:XLN,1
         BAL,11   MOVSERS
         STB,15   LSERIAL
         LW,6     BW:SDA,3
         CW,R6    RRBIT
         BANZ     %+2
         AND,6    YFF
         LW,2     PL:CHG
         DISABLE
         XW,6     BW:SDA,3
         STW,6    GI:SDA,1
         STB,2    GIB:UN,1
         STB,2    BB:PI,3
         BAL,11   BATUNQ            UNQUEUE SYMB ENTRY
         LI,4     RUNPRI            ADD TO SCHED QUEUE
         BAL,11   BATQT
         BAL,3    QH0               PUT SLOT BACK IN QUEUE
         LI,15    BAT
         STH,15   UH:FLG,2          SET BAT BIT
         MTW,1    S:BUIS
         MTW,-1   S:BFIS
         LW,4     2                 ADD1 NEEDS UN IN 4
         LW,15    SL:BPRIO          DEFAULT BATCH PRIORITY
         BAL,11   ADD1
         B        MBS1
CNTSER   EQU      %
         AW,6     3
         AI,12    1
         LH,6     S#H:LNK,6
         BNEZ     %-2
         B        *11
MOVSERS  EQU      %
         LW,5     15
         LW,6     10
         LW,9     S#W:SER,6
         STW,9    TSERIAL,5
         LB,2     S#B:TYP,6
         LB,9     SB:RTY,2
         STB,9    RSERIAL,5
         LB,15    LSERIAL,5
         LH,10    S#H:LNK,6
         BNEZ     MOVSERS
         STB,10   LSERIAL,5
         B        *11
*
*
RUNSER   EQU      %
         LH,5     *13,2
         BEZ      *11
RUNSER1  EQU      %
         LH,6     *12,3
         BEZ      *11
         LW,8     S#W:SER,5
RUNSER2  EQU      %
         CW,8     S#W:SER,6
         BNE      RUNSER3
         LB,9     S#B:TYP,5
         CB,9     S#B:TYP,6
         BE       MBSJ0
RUNSER3  EQU      %
         LH,6     S#H:LNK,6
         BNEZ     RUNSER2
         LH,5     S#H:LNK,5
         BNEZ     RUNSER1
         B        *11
*
*
RUNMNT   EQU      %
         LW,5     1
         LH,1     S#H:LNK,5
         BEZ      *11
         LI,6     AVRTBLNE
         LW,12    S#W:SER,1
RUNMNT0  EQU      %
         LB,2     S#B:TYP,1
         B        RUNMNT15
RUNMNT1  EQU      %
         CLM,12   AVRTBL,6
         BCR,3    RUNMNT2
RUNMNT15 EQU      %
         AI,6     -1
         CI,6     AVRTBLSIZ
         BGE      RUNMNT1
         AI,11    1
RUNMNT18 AI,11    1
         B        *11
RUNMNT2  EQU      %
         LB,8     SB:RTY,2
         LW,2     6
         AI,2     BATAPE
         CB,8     DCT4,2
         BNE      RUNMNT0
         LH,12    AVRNOU,6
         BNEZ     RUNMNT18
         B        RUNMNT0
         PAGE
*        NOT ENOUGH RESOURCES - INCREMENT PRIORITY,
*        TRY NEXT JOB
MBSNR    EQU      %
*        INCREMENT PRIORITY BY SL:PI UNLESS JOB FITS IN
*        NO PARTITIONS OR EXIT IF JOB IS F PRIORITY.
*        THEN TRY NEXT JOB IN PRIORITY CHAINS
MBSI     MTH,0    BH:PART,3         DONT INCR IF NOT RUNNABLE
         BEZ      MBSJ0             ANYWHERE
         CI,4     FIPRI
         BGE      MBSF1
         LB,9     BB:PI,3
         AW,9     SL:PI
         STB,9    BB:PI,3
         CI,9     255
         BLE      MBSJ0
         DISABLE
         BAL,11   BATUNQ            MOVE UP
         AI,4     1                 ONE
         BAL,11   BATQT             PRIORITY
         ENABLE
         BDR,4    MBSJ
         PAGE
*        TRY NEXT JOB IN PRIORITY CHAINS OR EXIT IF
*        CURRENT CANDIDATE IS F PRIORITY
MBSF     CI,4     FIPRI
         BL       MBSJ0
MBSF1    LW,5     BADRS
         LI,6     SV:RSIZ
MBSCKF   LB,8     *5,6
         AND,8    M7
         CH,8     SH:RTOT,6
         BG       MBSJ0             CANT RUN,KEEP GOING
         BDR,6    MBSCKF
MBSX     LI,2     0
         DISABLE
         STW,2    PL:LK             UNLOCK TABLES
         XW,2     PL:CHG            RELEASE USER # IF ANY
         BEZ      MBSX1
         BAL,3    QH0               PUT BACK IN QUEUE
MBSX1    ENABLE
         LI,11    1
         STW,11   SVZ
         LCI      7
         PLM,5    TMPSTK
         B        *11               RETURN
         END

