UFLAGS   SET      1                 UH:FLG EQU'S
         SYSTEM   UTS
*
*
*M*      MBS      MULTI-BATCH RESOURCE SCHEDULER
*
*
*P*      NAME:    MBS
*P*
*P*      PURPOSE: SCHEDULES BATCH JOBS FOR EXECUTION BASED ON THEIR
*P*               RESOURCE REQUIREMENTS
*P*
*P*      DESCRIPTION:
*P*               THE MBS MODULE, PART OF THE RBBAT GHOST, CONTAINS TWO
*P*               MAIN ROUTINES, MBSOP (REPART) AND MBS.  THE FIRST OF
*P*               THESE, CALLED AS MBSOP BY RBBAT TO OPERATE ON NEWLY
*P*               SUBMITTED JOBS AND AS REPART BY MBS TO ACT ON ALL JOBS
*P*               WHEN THE PARTITION ATTRIBUTES HAVE BEEN CHANGED, IS
*P*               RESPONSIBLE FOR SETTING THE BITS IN BH:PART THAT TELL
*P*               WHETHER A GIVEN JOB IS ABLE TO RUN IN A GIVEN
*P*               PARTITION BASED ON THE MATCH OF RESOURCES.  THE MAIN
*P*               ROUTINE, OF COURSE IS MBS.  IT IS CALLED BY RBBATM
*P*               EITHER AS A RESULT OF A GHOST FUNCTION CODE IN A COMBUF
*P*               REQUESTING AN MBS FROM THE MONITOR, OR WHEN A NEW
*P*               BATCH JOB HAS BEEN ADDED TO RBBAT'S TABLES.  RBBATR
*P*               ALSO CALLS MBS TO START UP BATCH JOBS AFTER A CRASH.
*P*               MBS PERFORMS THE FOLLOWING TASKS:
*P*
*P*               1)  PL:LK - THE PARTITION ATTRIBUTE LOCK IS TESTED.
*P*               IF IT IS NON ZERO CONTROL IS CHANGING PARTITION
*P*               ATTRIBUTES AND MBS EXITS.  IF IT IS ZERO MBS SETS IT
*P*               TO PREVENT ATTRIBUTE CHANGES WHILE MBS IS RUNNING.
*P*
*P*               2)  PL:CHG - THE PARTITION ATTRIBUTE CHANGE FLAG IS
*P*               TESTED.  IF IT IS ZERO MBS CONTINUES.  IF IT IS NON-
*P*               ZERO, IT CONTAINS SET BITS FOR EACH PARTITION WHOSE
*P*               ATTRIBUTES HAVE BEEN CHANGED, AND MBS CALLS REPART TO
*P*               UPDATE THE LEGAL PARTITION BITS (BH:PART) FOR ALL
*P*               BATCH JOBS.
*P*
*P*               3)  MBS DETERMINES WHETHER A BATCH JOB COULD POSSIBLY
*P*               BE RUN NOW THIS IS DONE WITH TWO CHECKS:
*P*
*P*                   A)  IF ((S:BUAIS)-(S:BUIS))*(S:BFIS) <= 0
*P*                   EITHER NO MORE BATCH USERS ARE ALLOWED OR THERE
*P*                   ARE NONE TO RUN.
*P*
*P*                   B)  IF GI:FRE = 0 THERE ARE NO GETI TABLE SLOTS
*P*                   AVAILABLE TO MOVE RESOURCE INFORMATION INTO CORE.
*P*
*P*               IF EITHER OF THESE CHECKS FAILS MBS EXITS
*P*
*P*               4)  MBS NOW STEALS A USER SLOT FROM THE SNULL STATE.
*P*               IF A JOB IS SCHEDULED IT WILL USE THIS USER NUMBER,
*P*               AND IF NOT IT WILL BE RETURNED.  THE SLOT MUST BE
*P*               STOLEN AT THIS TIME TO BE SURE ONE IS AVAILABLE TO
*P*               RUN THE JOB.  IF THERE ARE NONE AVAILABLE, MBS EXITS
*P*
*P*               5)  A BIT MASK IS BUILT WITH A BIT ON FOR EACH PARTITION
*P*               WHICH IS NEITHER RUNNING NOR LOCKED AND WHOSE MINIMUM
*P*               RESOURCES ARE AVAILABLE.
*P*
*P*               6)  THE HIGHEST PRIORITY JOB IS SELECTED AS THE CANDIDATE
*P*               JOB (CJ).  WHENEVER A CANDIDATE JOB CANNOT BE RUN, MBS
*P*               UPS HIS PRIORITY BY THE PRIORITY INCREMENT, AND SELECTS
*P*               THE NEXT HIGHEST PRIORITY JOB AS THE NEW CJ.  AN EXCEPTION
*P*               TO THIS IS WHEN THE CJ HAS 'F' PRIORITY, IN WHICH
*P*               CASE IF THE CJ COULD EVER BE RUN MBS EXITS WITHOUT
*P*               ATTEMPTING TO SCHEDULE OTHER JOBS.  IF THE BATCH QUEUE
*P*               IS EXHAUSTED WITHOUT SELECTING ANY JOB TO RUN, MBS
*P*               EXITS.
*P*
*P*               7)  THE CJ'S BH:PART IS ANDED WITH THE MASK BUILT IN
*P*               FIVE ABOVE AND, IF THE RESULT IS ZERO, A NEW CJ IS
*P*               SELECTED.
*P*
*P*               8)  THE ACCOUNT OF THE CJ IS CHECKED AGAINST THOSE OF
*P*               ALL RUNNING JOBS TO SEE IF EITHER THE CJ OR A RUNNING
*P*               JOB SPECIFIED ACCOUNT.  IF THIS IS TRUE A NEW CJ
*P*               IS SELECTED.
*P*
*P*               9)  IF THE CJ SPECIFIED ORDER ALL RUNNING JOBS AND
*P*               THOSE IN THE QUEUE ARE CHECKED AND IF ANY WITH THE
*P*               SAME ACCOUNT HAVE A LOWER SYSID, A NEW CJ IS SELECTED
*P*
*P*               10)  THE RESOURCES REQUESTED BY THE CJ ARE CHECKED
*P*               AGAINST THOSE AVAILABLE IN THE SYSTEM AND IF ANY ARE
*P*               UNAVAILABLE A NEW CJ IS SELECTED.
*P*
*P*               11)  IF THE CJ SPECIFIED SERIAL NUMBERS FOR DISCS ON
*P*               HIS LIMIT CARD THE FOLLOWING CHECKS ARE MADE:
*P*
*P*                   A)  ANY SERIAL NUMBER THE CJ REQUESTED EXCLUSIVE
*P*                   MUST NOT BE IN USE OR REQUESTED EITHER SHARED OR
*P*                   EXCLUSIVE BY ANY OTHER RUNNING USER.
*P*
*P*                   B)  ANY SERIAL NUMBER THE CJ REQUESTED SHARED MUST
*P*                   NOT BE IN USE OR REQUESTED BY ANY RUNNING JOB AS
*P*                   EXCLUSIVE.
*P*
*P*                   C)  THERE MUST BE FREE SPINDLES (BEYOND THOSE RE-
*P*                   QUESTED BY THE CJ) TO MOUNT ANY REQUESTED SHARED
*P*                   SPINDLES NOT ALREADY MOUNTED.
*P*
*P*                   D)  THERE MUST BE ROOM IN THE IN-CORE SERIAL
*P*                   NUMBER TABLES TO HOLD THE CJ'S SERIAL NUMBERS.
*P*
*P*               IF ANY OF THESE TESTS FAIL A NEW CJ IS SELECTED
*P*
*P*               12)  THE CJ HAS NOW BEEN SELECTED TO RUN
*P*
*P*               13)  A GETI TABLE SLOT IS REMOVED FROM THE FREE CHAIN
*P*               AND THE JOBS RESOURCE INFORMATION (AND OTHER INFO) IS
*P*               MOVED FROM THE RBBAT BATCH TABLES INTO IT.
*P*
*P*               14)  AVRNOU IS INCREMENTED FOR ALL MOUNTED SHARED
*P*               SPINDLES THE JOB HAS REQUESTED AND THE DEVICE OWNERSHIP
*P*               BIT (ASPIN) IS SET FOR THESE SPINDLES.  THESE BITS
*P*               ARE TRANSFERED TO GI:ASPN AND EVENTUALLY TO J:ASPIN.
*P*
*P*               15)  THE RESOURCES THAT THE JOB REQUESTED ARE ADDED
*P*               TO THE BATCH CURRENT TOTALS
*P*
*P*               16)  THE JOB'S SERIAL NUMBERS ARE MOVED TO THE CORE
*P*               SERIAL NUMBER TABLES
*P*
*P*               17)  THE JOB IS MOVED FROM ITS PRIORITY CHAIN TO RBBATS
*P*               RUNNING CHAIN
*P*
*P*               18)  THE BATCH BIT IS SET IN THE JOB'S UH:FLG2 AND
*P*               MBS CALLS ADD1 TO START UP THE USER
*P*
*P*               19)  FINALLY MBS RETURNS TO THREE ABOVE TO TRY TO START
*P*               ANOTHER JOB.
*P*
*P*      REFERENCE:
*P*               MBS IS PART OF THE RBBAT GHOST WHICH ALSO CONTAINS
*P*               RBBATM AND RBBATR.  THE TABLES MBS USES (BATCH, GETI,
*P*               RESOURCE, AVR, PARTITION, ETC.) ARE DESCRIBED IN THE
*P*               DATA BASE TECH. MANUAL.
*P*
*
*
         PAGE
*
*
         DEF      MBS               THE MULTI-BATCH SCHEDULER
         DEF      MBSOP             SET BH:PART BITS FOR A GIVEN JOB BASED
*,*                                 ON ITS RESOURCE REQUIREMENTS
*
*
         REF      M7                MASK
         REF      M8                MASK
         REF      YFF               MASK
         REF      X80               TABLE BIT
         REF      BT31TO0           TABLE BITS
         REF      NB31TO0           TABLE BITS
*
         REF      TMPSTK            RBBAT'S STACK USED TO PUSH AND PULL
         REF      DCT4              INPUT:  DEVICE TYPE USED TO CHECK
*,*                                 WHETHER A SERIAL NUMBER IS THE SAME
*,*                                 RESOURCE TYPE AS ANOTHER
         REF      UH:FLG            I/O:  BATCH BIT IS STORED HERE TO MAKE
*,*                                 NEW USER BATCH
         REF      SL:BPRIO          INPUT: BATCH DEFAULT EXECUTION
*,*                                 PRIORITY PASSED TO ADD1 WHEN JOB IS
*,*                                 STARTED
*
         REF      FIPRI             RBBAT 'F' PRIORITY JOBS PRIORITY
*,*                                 CHAIN INDEX
         REF      RUNPRI            RBBAT RUNNING JOBS PRIORITY CHAIN
*,*                                 INDEX
*
         REF      RRBIT             INPUT:  RERUN BIT IN BW:SDA
         REF      JEBIT             INPUT:  JOBENT SUBMITTED BIT IN BW:SDA
*
         REF      SL:PI             INPUT: AMOUNT IN 256THS TO INCREMENT
*,*                                 PRIORITY WHEN JOB IS PASSED OVER FOR
*,*                                 SCHEDULING
         REF      S:BUIS            I/O: NUMBER OF BATCH USERS RUNNING
*,*                                 USED TO DECIDE WHETHER TO SCHEDULE
*,*                                 INCREMENTED WHEN A NEW JOB IS STARTED
         REF      S:BUAIS           INPUT: NUMBER OF BATCH USERS ALLOWED
*,*                                 TO RUN USED TO DECIDE WHETHER TO
*,*                                 SCHEDULE
         REF      S:BFIS            I/O: NUMBER OF BATCH JOBS IN THE QUEUE
*,*                                 USED TO DECIDE WHETHER TO SCHEDULE.
*,*                                 DECREMENTED WHEN A NEW JOB IS RUN
         REF      S:MBSF            OUTPUT: MULTI-BATCH SCHEDULE FLAG SET
*,*                                 WHEN MBS MUST WAIT FOR A GETI TABLE
*,*                                 ENTRY - CAUSES ANOTHER MBS IN 5 SEC
*
         REF      SNULL             STATE INDEX OF UNUSED USER SLOTS
         REF      SB:HQ             I/O: STATE HEAD TABLE USED TO STEAL
*,*                                 USER NUMBER FOR NEW BATCH JOB
         REF      SB:TQ             I/O: STATE TAIL TABLE USED TO STEAL
*,*                                 USER NUMBER FOR NEW BATCH JOB
         REF      UB:FL             I/O: USER STATE FLINK USED TO STEAL
*,*                                 USER NUMBER FOR NEW BATCH JOB
         REF      UB:BL             I/O: USER STATE BLINK USED TO STEAL
*,*                                 USER NUMBER FOR NEW BATCH JOB
*
         REF      SV:RSIZ           HIGHEST INDEX INTO RESOURCE TABLES
         REF      SB:RTY            INPUT: RESOURCE TABLE USED TO CONVERT
*,*                                 RESOURCE INDEX TO DEVICE TYPE TO MOVE
*,*                                 SERIAL NUMBER INFO TO CORE AND CHECK
*,*                                 WHETHER SERIAL NUMBERS ARE SAME DEVICE
         REF      SH:RTOT           INPUT: RESOURCE TABLE TOTAL ON SYSTEM
*,*                                 USED TO CHECK HOW MANY CAN BE ALLOCATED
         REF      SH:ROCU           INPUT: RESOURCE TABLE ONLINE CURRENT USED
*,*                                      TO CHECK HOW MANY ARE IN USE
         REF      SH:RGCU           INPUT: RESOURCE TABLE GHOST CURRENT USED
*,*                                 TO CHECK HOW MANY ARE IN USE
         REF      SH:RBSUM          INPUT: RESOURCE TABLE MAX AVAILABLE TO
*,*                                 BATCH USED TO CHECK HOW MANY ARE
*,*                                 AVAILABLE
         REF      SH:RBCU           I/O: RESOURCE TABLE BATCH CURRENT USED
*,*                                 TO CHECK HOW MANY ARE AVAILABLE AND
*,*                                 INCREMENTED WHEN A NEW JOB IS SCHEDULED
*,*                                 THAT REQUESTED THEM
         REF      SB:RBDF           INPUT: RESOURCE TABLE BATCH DEFAULT
*,*                                 USED TO KEEP B4W:RES UP TO DATE
*
         REF      AVRTBLSIZ         NUMBER OF TAPE ENTRIES IN THE AVR
*,*                                 TABLES USED TO FIND PACKS
         REF      AVRTBLNE          NUMBER OF ENTRIES TOTAL IN THE AVR
*,*                                 TABLES USED TO FIND PACKS
         REF      BATAPE            FIRST DCT INDEX THAT HAS AN AVR
*,*                                 TABLE ENTRY USED TO CONVERT DCTX
*,*                                 TO AVRX
         REF      AVRTBL            INPUT: AVR SERIAL NUMBER/FLAG TABLE
*,*                                 WORD 0 USED TO COMPARE REQUESTED
*,*                                 SERIAL NUMBERS WITH RUNNING - WORD1
*,*                                 BIT 2 USED TO CHECK WHETHER WORD 0 CAN
*,*                                 BE TRUSTED
         REF      AVRNOU            OUTPUT: AVR NUMBER OF USERS COUNTED UP
*,*                                 WHEN A JOB REQUESTS AN ALREADY MOUNTED
*,*                                 SHARED PACK
         REF      AVRID             INPUT: AVR USER NUMBER - IF THIS IS
*,*                                 NON-ZERO THE PACK IS EXCLUSIVE
*
         REF      BH:HPRI           I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 PRIORITY HEADS USED TO MOVE FROM JOB
*,*                                 TO JOB AND RECHAIN TO NEW PRIORITYS
         REF      BH:TPRI           I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 PRIORITY TAILS USED TO MOVE FROM JOB
*,*                                 TO JOB AND RECHAIN TO NEW PRIORITYS
         REF      BH:LINK           I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 PRIORITY LINK USED TO MOVE FROM JOB
*,*                                 TO JOB AND RECHAIN TO NEW PRIORITYS
         REF      BB:PI             I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 INCREMENTAL PRIORITY INCREASED BY
*,*                                 SL:PI WHEN JOB IS BYPASSED FOR
*,*                                 SCHEDULING
         REF      BB:RID            INPUT: BATCH QUEUE TABLE IN RBBAT
*,*                                 RBID USED TO CHECK LEGAL PARTITIONS
*,*                                 AND MOVED TO GIB:RID
         REF      BH:SID            INPUT: BATCH QUEUE TABLE IN RBBAT
*,*                                 SYSID USED TO CHECK FOR ORDER RESTRICTIONS
*,*                                 AND MOVED TO PLH:SID
         REF      BH:TIME           INPUT: BATCH QUEUE TABLE IN RBBAT
*,*                                 LIMIT CARD TIME USED TO SCHEDULE AND
*,*                                 MOVED TO GIH:TIM
         REF      BW:SDA            I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 FLAGS AND STARTING DISC ADDRESS - JEBIT
*,*                                 USED TO CHECK LEGAL PARTITIONS - SDA
*,*                                 MOVED TO GI:SDA - BW:SDA IS CLEARED
*,*                                 UNLESS RRBIT IS SET
         REF      BD:ACCT           INPUT: BATCH QUEUE TABLE IN RBBAT
*,*                                 ACCOUNT USED FOR ACCOUNT CHECK
         REF      B4W:RES           I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 RESOURCES USED FOR SCHEDULING AND
*,*                                 KEPT UP TO DATE FOR DISPLAYS - MOVED
*,*                                 TO GI:RES - BYTE 0 IS PRIORITY MOVED
*,*                                 TO GIB:PRI
         REF      BH:SLNK           I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 SHARED SERIAL NUMBER HEAD USED TO MAKE
*,*                                 SERIAL NUMBER TESTS - MBS SORTS LIST
*,*                                 FOR RECOVERY AND RERUN PURPOSES
         REF      BH:XLNK           INPUT: BATCH QUEUE TABLE IN RBBAT
*,*                                 EXCLUSIVE SERIAL NUMBER HEAD USED TO
*,*                                 MAKE SERIAL NUMBER CHECKS
         REF      BH:PART           I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 PARTITION BITS:  A BIT ON MEANS THE
*,*                                 JOB QUALIFIES FOR THE PARTITION.  SET
*,*                                 BY MBSOP WHEN THE JOB IS SUBMITTED,
*,*                                 MODIFIED BY REPART WHEN PARTITION
*,*                                 ATTRIBUTES CHANGE, AND USED BY MBS
*,*                                 TO SEE IF THERE IS A PARTITION TO RUN
*,*                                 THE JOB IN
         REF      S#W:SER           INPUT: BATCH QUEUE TABLE IN RBBAT
*,*                                 SERIAL NUMBER USED TO MAKE SERIAL
*,*                                 NUMBER CHECKS - MOVED TO TSERIAL
         REF      S#H:LNK           I/O: BATCH QUEUE TABLE IN RBBAT
*,*                                 SERIAL NUMBER LINK USED TO RUN SERIAL
*,*                                 NUMBER CHAINS AND TO SORT SERIAL
*,*                                 NUMBERS FOR RERUN AND RECOVERY
         REF      S#B:TYP           INPUT: BATCH QUEUE TABLE IN RBBAT
*,*                                 RESOURCE INDEX USED TO MAKE SERIAL
*,*                                 NUMBER CHECKS - CONVERTED TO DEVICE
*,*                                 TYPE AND MOVED TO RSERIAL
*
         REF      GI:FRE            I/O: GETI TABLE - HEAD OF FREE ENTRIES
*,*                                 USED TO DECIDE WHETHER TO TRY TO SCHED-
*,*                                 ULE - GETI ENTRY TO FILL IN IS
*,*                                 REMOVED FROM HERE
         REF      GI:SDA            OUTPUT: GETI TABLE -STARTING DISC ADDRESS
*,*                                 (AND JEBIT AND RRBIT IF SET) ARE
*,*                                 MOVED HERE FROM BW:SDA
         REF      GI:RES            OUTPUT: GETI TABLE -RESOURCES FROM B4W:RES
*,*                                 ARE MOVED HERE
         REF      GI:ASPN           OUTPUT: GETI TABLE -DEVICE OWNERSHIP BITS
*,*                                 BUILT BY MBS IN BI:ASPN ARE MOVED HERE
         REF      GIB:PRT           OUTPUT: GETI TABLE -PARTITION NUMBER
*,*                                 SELECTED BY MBS IS MOVED HERE
         REF      GIH:TIM           OUTPUT: GETI TABLE -TIME FROM BH:TIME
*,*                                 IS MOVED HERE
         REF      GIB:RID           OUTPUT: GETI TABLE -RBID FROM BB:RID IS
*,*                                 MOVED HERE
         REF      GIB:UN            OUTPUT: GETI TABLE -USER NUMBER TAKEN
*,*                                 FROM SNULL IS PUT HERE - IT WILL BE
*,*                                 THE USER NUMBER OF THE NEW JOB
         REF      GIB:SLN           OUTPUT: GETI TABLE -THE SHARED SERIAL
*,*                                 NUMBER HEAD OF THE CHAIN FORMED WHEN
*,*                                 MBS MOVES SHARED SERIAL NUMBERS TO CORE
*,*                                 IS PUT HERE
         REF      GIB:XLN           OUTPUT: GETI TABLE -THE EXCLUSIVE SERIAL
*,*                                 NUMBER HEAD INTO LSERIAL IS PUT HERE
*,*                                 WHEN MBS MOVES THE SERIAL NUMBERS TO CORE
         REF      GIB:PRI           OUTPUT: GETI TABLE -THE REQUESTED RUN
*,*                                 JOB PRIORITY IS MOVED HERE FROM B4W:RES
*
         REF      LPART             NUMBER OF PARTITIONS IN THE SYSTEM
         REF      MBSOP#            LPART*SV:RSIZ USED TO THREAD THROUGH
*,*                                 PLB:MAX AND PLB:MIN
         REF      PL:LK             I/O: PARTITION CHANGE LOCK - IF SET
*,*                                 CONTROL IS MESSING WITH THE PARTITIONS
*,*                                 AND MBS CANT RUN - IF NOT MBS SETS IT
*,*                                 TO KEEP CONTROL OUT OF THE WAY
         REF      PL:CHG            I/O: PARTITION CHANGE FLAGS SET BY
*,*                                 CONTROL TO SHOW WHAT PARTITIONS HAVE
*,*                                 BEEN CHANGED - MBS STORES USER NUMBER
*,*                                 FROM SNULL INTO TOP BYTE
         REF      PLB:USR           OUTPUT: PARTITION TABLE - USER NUMBER
*,*                                 FOR NEW JOB IS STORED HERE
         REF      PLH:TOL           OUTPUT: PARTITION TABLE - TOTAL JOBS
*,*                                 RUN IN THIS PARTITION COUNTED UP BY
*,*                                 MBS WHEN A JOB IS SCHEDULED IN THIS
*,*                                 PARTITION
         REF      PLH:CUR           OUTPUT: PARTITION TABLE - TOTAL JOBS
*,*                                 RUN IN THIS PARTITION SINCE CHANGE OR
*,*                                 RECOVERY COUNTED UP BY MBS WHEN A JOB
*,*                                 IS RUN IN THIS PARTITION
         REF      PLH:TL            INPUT: PARTITION TABLE - TIME LOWER
*,*                                 LIMIT USED BY MBS TO SCHEDULE JOBS
         REF      PLH:TU            INPUT: PARTITION TABLE - TIME UPPER
*,*                                 LIMIT USED BY MBS TO SCHEDULE JOBS
         REF      PLH:SID           OUTPUT: PARTITION TABLE - SYSID STORED
*,*                                 IN BY MBS FROM BH:SID
         REF      PLD:ACT           OUTPUT: PARTITION TABLE - ACCOUNT STORED
*,*                                 IN BY MBS FROM BD:ACCT
         REF      PLH:FLG           I/O: PARTITION TABLE - FLAG BITS:
*,*                                 BIT0 = HOLD IN CORE
*,*                                 BIT1 = ACCOUNT SPECIFIED
*,*                                 BIT2 = JOB RUNNING HERE
*,*                                 BIT12 = CR JOBS LEGAL
*,*                                 BIT13 = JOBENT JOBS LEGAL
*,*                                 BIT14 = RB JOBS LEGAL
*,*                                 BIT15 = LOCKED
*,*                                 THE BITS ARE USED TO DECIDE LEGAL
*,*                                 PARTITIONS AND MAKE THE ACCOUNT CHECK
         REF      PLB:MAX           INPUT: PARTITION TABLE - RESOURCE MAX'S
*,*                                 USED BY MBS TO SCHEDULE JOBS
         REF      PLB:MIN           INPUT: PARTITION TABLE - RESOURCE MIN'S
*,*                                 USED BY MBS TO SCHEDULE JOBS
         REF      TSERIAL           OUTPUT: IN CORE SERIAL NUMBER TABLE
*,*                                 INTO WHICH MBS MOVES S#W:SER
         REF      LSERIAL           I/O: IN CORE SERIAL NUMBER TABLE
*,*                                 WHICH MBS USES TO LINK UP IN CORE
*,*                                 SERIAL NUMBERS TO GIB:XLN AND GIB:SLN
         REF      RSERIAL           OUTPUT: IN CORE SERIAL NUMBER TABLE
*,*                                 INTO WHICH MBS STORES THE DEVICE TYPE
*,*                                 DERIVED FROM S#B:TYP AND SB:RTY
*
         REF      BSL:CRES          I/O: RBBAT'S STATIC DATA AREA
*,*                                 8 WORD AREA USED TO BUILD RESOURCE
*,*                                 TABLE OF AVAILABLE TO BATCH
         REF      B8:CRES           I/O: RBBAT'S STATIC DATA AREA
*,*                                 4 WORD AREA USED TO BUILD DUMMY B4W:RES
*,*                                 WHICH IS INCREMENTED FOR SHARED
*,*                                 SERIAL NUMBERS NOT MOUNTED
         REF      BI:ASPN           I/O: RBBAT'S STATIC DATA AREA
*,*                                 3 WORD AREA USED TO BUILD DEVICE OWN-
*,*                                 ERSHIP BITS
         REF      BADRS             I/O: RBBAT'S STATIC DATA AREA
*,*                                 CELL USED TO HOLD WORD ADDRESS OF B4W:RES
*,*                                 FOR THE CANDIDATE JOB
         REF      RCVRFLG           INPUT: RBBAT'S STATIC DATA AREA
*,*                                 CELL THAT WHEN SET SAYS RBBATR IS RUNNING
*,*                                 AND MBS SHOULDN'T
         REF      SVZ               I/O: RBBAT'S STATIC DATA AREA
*,*                                 MBS SETS THIS CELL NON ZERO TO TURN
*,*                                 OFF THE SPECIAL SAVED ENVIRONMENT IT
*,*                                 SAVES
*
         REF      ADD1              CALLED: TO REPORT 'ON' STATE AND BEGIN IN
*,*                                 SWAP OF NEW BATCH JOBS
         REF      FIND              CALLED: TO START RUNNING BATCH QUEUE
*,*                                 PRIORITY CHAINS
         REF      FIND1             CALLED: TO CONTINUE RUNNING BATCH QUEUE
*,*                                 PRIORITY CHAINS
         REF      SVIV              CALLED: TO SAVE A SPECIAL RBBAT ENVIRONMENT
*
*
*
         PAGE
         CSECT    1
BACCT    EQU      BT31TO0+31
BORDR    EQU      BT31TO0+32
AVRD     EQU      BT31TO0+30
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
*
*
*F*      NAME:    MBSOP
*F*
*F*      PURPOSE: SET BIT IN BH:PART FOR EACH PARTITION THE GIVEN JOB
*F*               CAN RUN IN BASED ON RESOURCES REQUESTED AND JOB ORIGON
*F*
*
*
*F*      NAME:    REPART
*F*
*F*      PURPOSE: REEVALUATE LEGAL PARTITION BITS IN BH:PART FOR ALL JOBS
*F*               IN THE BATCH QUEUE FOR THOSE PARTITIONS WHOSE ATTRIBUTES
*F*               HAVE BEEN CHANGED BY CONTROL
*F*
*
*
*        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
*
*
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
*
*
*F*      NAME:    BATQT
*F*
*F*      PURPOSE: LINKS JOB ENTRY TO THE TAIL OF A PRIORITY CHAIN FOR MBS
*F*
*
*
*        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
*
*
*F*      NAME:    BATUNQ
*F*
*F*      PURPOSE: UNCHAINS A JOB ENTRY FROM A PRIORITY CHAIN FOR MBS
*F*
*
*
*        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
*
*
*F*      NAME:    QHO
*F*
*F*      PURPOSE: RETURNS A USER SLOT STOLEN BY MBS TO THE SNULL QUEUE
*F*
*
*
*        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
*
*
*F*      NAME:    MBS1
*F*
*F*      PURPOSE: DETERMINES WHETHER IT IS POSSIBLE TO RUN A JOB AT THIS
*F*               TIME BY LOOKING AT S:BUAIS, S:BUIS, S:BFIS, AND GI:FRE
*F*               STEALS A USER SLOT FROM THE SNULL QUEUE FOR POSSIBLE
*F*               USE BY THE BATCH JOB ABOUT TO BE RUN.
*F*
*
*
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
*
*
*F*      NAME:    MBS3
*F*
*F*      PURPOSE: BUILDS A BIT MASK WITH A BIT ON FOR EACH PARTITION WHICH
*F*               IS NEITHER RUNNING NOR LOCKED AND WHOSE MINIMUM RESOURCES
*F*               CAN BE ALLOCATED.
*F*
*
*
*        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
*
*
*F*      NAME:    MBSJ (MBSJ0)
*F*
*F*      PURPOSE: RUNS THE BATCH QUEUE PRIORITY CHAINS FROM 'F' TO '1'
*F*               PRIORITY SELECTING EACH JOB AS THE NEW CANDIDATE JOB
*F*               IF THE AND OF ITS BH:PART BITS AND THE POSSIBLE PARTITIONS
*F*               MASK BUILT BY MBS3 IS NON-ZERO
*F*
*
*
*        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
*
*
*F*      NAME:    MBSA
*F*
*F*      PURPOSE: CALCULATES THE WORD ADDRESS OF THE CANDIDATE JOB'S B4W:RES
*F*               AND STORES IT IN BADRS.  CHECKS TO SEE WHETHER ACCOUNT
*F*               OR ORDER RESTRICTIONS PREVENT RUNNING THE CANDIDATE JOB
*F*
*
*
*        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)
*
*
*F*      NAME:    MBSR (MBSR0)
*F*
*F*      PURPOSE: CHECKS WHETHER SUFICIENT RESOURCES ARE AVAILABLE TO RUN
*F*               THE CANDIDATE JOB
*F*
*
*
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
*
*
*F*      NAME:    MBSCS#
*F*
*F*      PURPOSE: PROCESSES THE SERIAL NUMBER LISTS FROM THE CANDIDATE
*F*               JOB'S MOUNT OPTION.  DETERMINES WHETHER SERIAL NUMBER
*F*               CONFLICTS PREVENT RUNNING THE CANDIDATE JOB
*F*
*F*      DESCRIPTION:
*F*               THE CANDIDATE JOB'S (CJ) EXCLUSIVE SERIAL NUMBERS ARE
*F*               COMPARED AGAINST BOTH THE SHARED AND EXCLUSIVE LISTS OF
*F*               ALL RUNNING JOBS.  IF ANY MATCHES ARE FOUND THE CJ CANNOT
*F*               BE RUN.  THE CJ'S SHARED LIST IS COMPARED AGAINST THE
*F*               EXCLUSIVE LISTS OF ALL RUNNING JOBS AND MATCHES PREVENT
*F*               RUNNING HIM.  IF ANY SERIAL NUMBER THE CJ REQUESTED
*F*               EXCLUSIVE IS PRESENTLY MOUNTED AND IN USE HE CANNOT RUN
*F*               IF ANY SERIAL NUMBER THE CJ REQUESTED SHARED IS NOT
*F*               MOUNTED HIS REQUIREMENT FOR THAT TYPE OF RESOURCE IS
*F*               INCREMENTED.  IF ANY OF THE CJ'S SHARED SERIAL NUMBERS
*F*               ARE IN USE EXCLUSIVE HE CANNOT RUN.
*F*
*F*               IF ANY OF THE CJ'S SHARED SERIAL NUMBERS ARE PRESENTLY
*F*               MOUNTED AND IN USE SHARED,  HIS DEVICE OWNERSHIP BIT FOR
*F*               THE DEVICE ON WHICH THE PACK IS MOUNTED IS SET IN BI:ASPN
*F*               (A TEMP AREA LATER MOVED TO GI:ASPIN AND ON TO HIS JIT).
*F*               THEN HIS SHARED SERIAL NUMBER CHAIN IS SORTED SO THAT
*F*               THESE SERIAL NUMBERS ARE AT THE FRONT AND A SEPARATE
*F*               HEAD IS MAINTAINED FOR THOSE SHARED SERIAL NUMBERS WHICH
*F*               WERE NOT MOUNTED (AND THUS WILL BE MOVED TO CORE).  THIS
*F*               PRESERVES THE CJ'S SHARED CHAIN IN CASE OF A RECOVERY
*F*               OR RERUN.
*F*
*
*
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      %
         LD,12    AVRTBL,6
         AND,13   AVRD
         BNEZ     %+2
         BDR,11   RUNMNT0
         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
*
*
*F*      NAME:    MBSSP3
*F*
*F*      PURPOSE: CHECKS WHETHER RESOURCES INCREMENTED BECAUSE REQUESTED
*F*               SHARED SERIAL NUMBERS WERE NOT MOUNTED ARE AVAILABLE.
*F*               CHECKS WHETHER THERE IS ROOM IN THE IN-CORE SERIAL NUMBER
*F*               TABLES TO MOVE DOWN THE CJ'S SERIAL NUMBERS.
*F*
*
*
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
*
*
*F*      NAME:    MBSRJ
*F*
*F*      PURPOSE: THE CANDIDATE JOB HAS BEEN SELECTED TO BE RUN.  A GETI
*F*               TABLE SLOT IS TAKEN AND GIB:PRI, GIB:RID, AND GIH:TIM
*F*               ARE FILLED IN FROM B4W:RES(BYTE0),BB:RID, AND BH:TIME.
*F*
*
*
*        RESOURCES ARE AVAILABLE - RUN THE JOB
MBSRJ    EQU      %
         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
*
*
*F*      NAME:    MBSSCH
*F*
*F*      PURPOSE: INCREMENTS AVRNOU FOR EACH PACK WHOSE DEVICE OWNERSHIP
*F*               BIT HAS BEEN SET IN BI:ASPN BY MBSCS#
*F*
*
*
         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
*
*
*F*      NAME:    MBSSCH1
*F*
*F*      PURPOSE: MOVES RESOURCES FROM B4W:RES TO GI:RES AND DEVICE
*F*               OWNERSHIP BITS FROM BI:ASPN TO GI:ASPN
*F*
*
*
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
*
*
*F*      NAME:    MBSGR
*F*
*F*      PURPOSE: ADDS THE NEW JOB'S RESOURCE REQUIREMENTS TO SH:RBCU.
*F*               SELECTS A PARTITION TO RUN HIM IN, TAKING THE HIGHEST
*F*               NUMBERED ONE HE FITS IN.  MOVES THE REST OF THE JOB
*F*               INFORMATION FROM THE BATCH QUEUE TABLES TO THE GETI
*F*               TABLES.  CHAINS THE JOB ENTRY TO THE RUNNING CHAIN.
*F*               INCREMENTS S:BUIS, DECREMENTS S:BFIS, SETS THE BATCH
*F*               BIT IN UH:FLG2, AND CALLS ADD1 TO START THE NEW USER.
*F*
*
*
*  SWIPE RESOURCES
MBSGR    EQU      %
         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
*
*
*F*      NAME:    CNTSER
*F*
*F*      PURPOSE: COUNTS THE NUMBER OF SERIAL NUMBERS IN A JOB'S SHARED
*F*               OR EXCLUSIVE CHAIN
*F*
*
*
CNTSER   EQU      %
         AW,6     3
         AI,12    1
         LH,6     S#H:LNK,6
         BNEZ     %-2
         B        *11
*
*
*F*      NAME:    MOVSERS
*F*
*F*      PURPOSE: MOVES SERIAL NUMBERS FROM THE CHAINS IN RBBAT (S#W:SER)
*F*               TO THE IN-CORE CHAINS (TSERIAL)
*F*
*
*
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
*
*
*F*      NAME:    RUNSER
*F*
*F*      PURPOSE: COMPARES EACH SERIAL NUMBER IN A CANDIDATE JOB'S CHAIN
*F*               WITH ALL SERIAL NUMBERS IN THE SHARED OR EXCLUSIVE CHAINS
*F*               OF ALL RUNNING JOBS AND REJECTS THE CJ IF A MATCH IS FOUND
*F*
*
*
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
         BE       MBSJ0
RUNSER3  EQU      %
         LH,6     S#H:LNK,6
         BNEZ     RUNSER2
         LH,5     S#H:LNK,5
         BNEZ     RUNSER1
         B        *11
*
*
*F*      NAME:    RUNMNT
*F*
*F*      PURPOSE: GETS THE NEXT SERIAL NUMBER FROM THE CJ'S CHAIN AND
*F*               INFORMS THE CALLER WHETHER OR NOT IT IS MOUNTED AND IN USE.
*F*
*
*
RUNMNT   EQU      %
         LW,5     1
         LH,1     S#H:LNK,5
         BEZ      *11
         LI,6     AVRTBLNE
RUNMNT0  EQU      %
         LW,12    S#W:SER,1
         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      MBSJ0
         LH,12    AVRNOU,6
         BNEZ     RUNMNT18
         B        RUNMNT0
         PAGE
*
*
*F*      NAME:    MBSNR (MBSI)
*F*
*F*      PURPOSE: INCREMENTS THE PRIORITY INCREMENT OF JOBS WHICH HAVE
*F*               BEEN REJECTED BY SL:PI.  IF THE NEW PRIORITY INCREMENT
*F*               EXCEEDS 256 THE JOB IS MOVED UP ONE PRIORITY.  PRIORITY
*F*               'F' JOBS ARE HANDED TO MBSF TO HANDLE.
*F*
*
*
*        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
*
*
*F*      NAME:    MBSF
*F*
*F*      PURPOSE: HANDLES PRIORITY 'F' JOBS WHICH CANNOT BE PRESENTLY
*F*               SCHEDULED.  IF THE JOB COULD BE RUN IF ALL PRESENTLY
*F*               ALLOCATED RESOURCES WERE FREE, NO JOB IS SCHEDULED.
*F*               OTHERWISE SCHEDULING CONTINUES.
*F*
*
*
*        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
*
*
*F*      NAME:    MBSX (MBSX1)
*F*
*F*      PURPOSE: CLEARS PARTITION LOCK AND RETURNS STOLEN USER NUMBER
*F*               TO THE SNULL QUEUE - THEN EXITS.  MBSX1 JUST EXITS.
*F*
*
*
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

