         TITLE    '**** GERM ****'
*M*      GERM     GENERALIZED RESOURCE MANAGEMENT LOGIC
         DEF      GERM:
GERM:    RES
BITS     SET      1
MONPROC  SET      1
         SYSTEM   UTS
         PCC      0
         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
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE     ROOT REFS
*        DEFS
         DEF      ASPIN             SET/RESET BIT IN J:ASPIN
         DEF      CHKCUR            INCR JB:CUR IF PERMITTED
         DEF      CHKRAT            GET RESOURCE TYPE IF ALLOCATABLE
         DEF      CLEARHI           SET J:ASPIN, CLEAR BIT0 OF JB:MAX
         DEF      DEALL             UNDO WORK OF INCGLOB
         DEF      DERES             UNDO WORK OF INCGLOB AND CHKCUR
         DEF      GETRAT            GET RESOURCE TYPE
         DEF      GETTYP            GET DEVICE TYPE FROM DCB
         DEF      HOWALO            FIND AND RESET S:XSPIN BIT
         DEF      INCGLOB           INCR SH:RXCU IF PERMITTED
         DEF      RAT:DCT4          GET RESOURCE TYPE
         DEF      RSETSPIN          RESET J:ASPIN AND S:XSPIN
         DEF      SETSPIN           SET J:ASPIN AND S:XSPIN
         DEF      SPINS             FIND ANY S:XSPIN
         DEF      USECHK2           CHKCUR PLUS INCGLOB
         PAGE
*        REFS
         REF      DCT4              GET DEVICE TYPE
         REF      ENBSR4            RETURN SUBROUTINE
         REF      J:ASPIN           BITMAP OF OWNED DEVICES
         REF      J:JIT             DETERMINE JOB TYPE
         REF      JB:CUR            COUNT USED RESOURCES
         REF      JB:MAX            LIMIT RESOURCE USE
         REF      PLX1SR4           RETURN SUBROUTINE
         REF      S:BSPIN           BITMAP OF DEVICES COUNTED IN SH:RBCU
         REF      S:GSPIN           BITMAP OF DEVICES COUNTED IN SH:RGCU
         REF      S:MBSF            KICK THE BATCH SCHEDULER
         REF      S:OSPIN           BITMAP OF DEVICES COUNTED IN SH:ROCU
         REF      SB:RTY            RESOURCE TYPE TO DEVICE TYPE
         REF      SH:RBCU           COUNT TOTAL BATCH RESOURCES IN USE
         REF      SH:RGCU           COUNT TOTAL GHOST RESOURCES IN USE
         REF      SH:RGSUM          LIMIT TOTAL GHOST RESOURCES IN USE
         REF      SH:ROCU           COUNT TOTAL ONLINE RESOURCES IN USE
         REF      SH:ROSUM          LIMIT TOTAL ONLINE RESOURCES IN USE
         REF      SH:RTOT           LIMIT TOTAL RESOURCES IN USE
         REF      SV:RSIZ           SIZE OF SB:RTY TABLE
         REF      TB:FLGS           COUNT PACK OR TAPE MOUNTS
         PAGE
*F*      NAME: SPINS
*F*      PURPOSE: Determine if a device is currently available.
SPINS    CW,0     S:BSPIN,4
         BANZ     *11               YES
         CW,0     S:OSPIN,4
         BANZ     *11
         CW,0     S:GSPIN,4
         B        *11
         PAGE
*F*      NAME: CLEARHI
*F*      PURPOSE: Attach a device to the user.
CLEARHI RES    0
         LI,14    -1                SET FOR SETTING
         LB,0     JB:MAX,1
         AND,0    M7
         STB,0    JB:MAX,1
         SPACE    3
*F*      NAME: ASPIN
*F*      PURPOSE: Alter J:ASPIN bit for a device.
ASPIN   RES   0      14=0/1
         LW,4     2
         AND,4    M5
         LW,15    BT31TO0+1,4       GET PROPER BIT TO SET
         LW,4     2
         SLS,4    -5                AND WORD TO SET IT IN
         STS,14   J:ASPIN,4
         B        *11
         PAGE
*F*      NAME: SETSPIN
*F*      PURPOSE: Set J:ASPIN and S:XSPIN for a device.
SETSPIN  RES      0
         LI,14    -1                SET FOR SETTING
         PUSH     11
         BAL,11   ASPIN             14=1
         PULL     11
         LI,0     S:BSPIN
         LC       J:JIT
         BCR,12   SETX1             B
         LI,0     S:OSPIN
         BCS,8    SETX1             O
         LI,0     S:GSPIN
SETX1    RES      0
         STS,14   *0,4              SET  GLOB
         B        *11
         SPACE    3
*F*      NAME: RSETSPIN
*F*      PURPOSE: Reset J:ASPIN and S:XSPIN for a device.
RSETSPIN LI,14    0
         B        SETSPIN+1
         PAGE
*F*      NAME: CHKCUR
*F*      PURPOSE: Check and increment jit count for a given resource type.
CHKCUR   RES      0
         LC       JB:MAX,1
         BCS,8    *11               BEEN HERE BEFORE
         AI,11    1
         LB,0     JB:MAX,1
         CB,0     JB:CUR,1
         BLE      *11               CC2=0
         OR,0     X80
         STB,0    JB:MAX,1          SET  ALLOCATION IN PROGRESS
         MTB,1    JB:CUR,1
         B        *11
         PAGE
*F*      NAME: USECHK2
*F*      PURPOSE: Allocate resource of given device type.
USECHK2  RES      0
         BAL,11   GETTYP            GET DEVICE TYPE FROM DCB
         BAL,11   GETRAT
         BAL,11   CHKCUR
         B        2X                ALREADY ALLOCATED
         BLE      *9                JIT LIMIT EXCEEDED
*                 ON LINE   OR   GHOST
         BAL,11   INCGLOB           INCREMENT  GLOBAL
         BAL,11   OVGL              CANT, DECRENEMT JIT
2X       AI,9     2                 NO LIMIT EXCEEDED
         B        *9
         SPACE    4
OVGL     AI,9     -1
DEALJIT  LB,0     JB:MAX,1
         AI,0     -X'80'            REMOVE FLAG
         STB,0    JB:MAX,1
         MTB,-1   JB:CUR,1          DECREMENT COUNT
         B        *11
         PAGE
*F*      NAME: DERES
*F*      PURPOSE: Deallocate resource of given device type.
DERES    RES
         BAL,11   GETTYP            GET DEVICE TYPE IN 4
         BAL,11   GETRAT            GET RESOURCE TYPE IN 1
         LC       JB:MAX,1
         BCR,8    0,5               NOTHING TO UNDO
         BAL,15   DEALL1            GLOBAL
         BAL,11   DEALJIT
         B        0,5
         PAGE
*F*      NAME: INCGLOB
*F*      PURPOSE: Check and increment system counts for given resource type.
INCGLOB  LC       J:JIT
         BCR,12   PLX1SR4           BATCH
         LI,0     SH:ROCU           ASSUME ONLINE
         LH,8     SH:ROSUM,1
         BCS,8    %+3               CORRECT
         LI,0     SH:RGCU           NO, MUST BE GHOST
         LH,8     SH:RGSUM,1
         SH,8     *0,1              CHECK MAX
         BLEZ     *11               OVER
         DISABLE                    DONT LET ANYBODY DINK THE COUNTS
         LH,8     SH:RTOT,1
         SH,8     SH:RBCU,1
         SH,8     SH:ROCU,1
         SH,8     SH:RGCU,1
         BLEZ     ENBSR4            NO- OVER
         MTH,1    *0,1              ALLOCATE
         ENABLE
         B        PLX1SR4           11+1
         PAGE
*F*      NAME: GETTYP
*F*      PURPOSE: Determine device type from dcb.
GETTYP   RES      0
         AI,6     0                 IF NO DCB, IS ALREADY IN 4
         BEZ      *11
         LI,4     2                 IF DCB IS TAPE (2,3,A) IS IN DEVTP
         CW,4     ASN,6
         LI,4     BARNDEV           OTHERWISE IS IN RNDEV
         BAZ      %+2
         LI,4     BADEVTP
         LB,4     *6,4
         AND,4    M6
         B        *11
         PAGE
*F*      NAME: DEALL
*F*      PURPOSE: Decrement system count (undo INCGLOB).
DEALL    RES
         BAL,11   GETTYP            LOAD 4
         BAL,11   GETRAT            LOAD 1
*        HAVE TYPE AND RATX
DEALL1   RES      0
         LC       J:JIT
         BCR,12   *15               BATCH   DONE
         LI,0     SH:RGCU
         BCR,8    %+2
         LI,0     SH:ROCU
         MTH,-1   *0,1              GLOBAL
         STW,15   S:MBSF    SET MBS FLAG
         B        *15
         PAGE
*F*      NAME: HOWALO
*F*      PURPOSE: Find S:XSPIN bit for a device.
HOWALO   LI,0     SH:RBCU
         CW,15    S:BSPIN,4
         BANZ     B1                B
         LI,0     SH:ROCU
         CW,15    S:OSPIN,4
         BANZ     O1                OL
         LI,0     SH:RGCU
         CW,15    S:GSPIN,4
         BAZ      *11               NOBODY????
         STS,14   S:GSPIN,4
O1       STS,14   S:OSPIN,4
B1       STS,14   S:BSPIN,4
         B        *11               0=WHO HAS IT
*
         PAGE
*F*      NAME: GETRAT,RAT:DCT4,CHKRAT
*F*      PURPOSE: Convert device type to resource type.
*D*      NAME:    GETRAT
*D*      ENTRY:   RAT:DCT4
*D*      ENTRY:   CHKRAT
*D*      CALL:    BAL,11   (BNE NOT A RESOURCE FOR CHKRAT ONLY)
*D*      INPUT:   R2=DCT INDEX (CHKRAT AND RAT:DCT4)
*D*               R4=DEVICE TYPE (GETRAT)
*D*               SB:RTY CONTAINS DEVICE TYPES INDEXED BU RESOURCE TYPE
*D*      OUTPUT:  R1=RESOURCE TYPE
*D*               R4=DEVICE TYPE (CHKRAT AND RAT:DCT4)
*D*               CONDITION CODES SET TO 'NOT EQUAL' IF CALLED AT CHKRAT
*D*               AND DEVICE IS NOT ALLOCATABLE.
*D*      DESCRIPTION: SB:RTY IS SEARCHED FOR A MATCH WITH DEVICE TYPE.
*D*               IF NO MATCH AND CALL WASNT CHKRAT, SUA 31-00 OCCURS.
         SPACE    2
CHKRAT   OR,11    Y8                SET CHKRAT FLAG
RAT:DCT4 LB,4     DCT4,2            GET DEVICE TYPE
GETRAT   LI,1     SV:RSIZ           SEARCH TABLE
         CB,4     SB:RTY,1
         BE       *11
         BDR,1    %-2
         AI,11    0                 IF CALLED AT CHKRAT, RETURN
         BLZ      *11
*        B        SC31              ELSE SCREECH
         PAGE
*S*      SCREECH CODE: 31-00
*S*      REPORTED BY:  GERM
*S*      MESSAGE: INVALID RESOURCE TYPE IN OPEN DCB
*S*      TYPE:    SUA
*S*      REGISTERS: R11 IS CALLER OF GETRAT'S ADDRESS
*S*                 R4 IS DEVICE TYPE
SC31     SUA      X'31'
         END

