         TITLE    '**** GRSUB ****'
*M*      GRSUB    PRIVATE VOLUME SPACE ALLOCATION LOGIC
         DEF      GRSUB:            FOR PATCHING
GRSUB:   RES
*
         PCC      0
         SPACE    3
MONPROC  SET      1
BITS     SET      1
DISCBPROC SET     1
         SYSTEM   UTS
         PAGE
*        DEFS
         DEF      GNPVCYL           GET PRIVATE RANDOM FILE
         DEF      GNVAT             GET GRANULE ON NEXT VOLUME
         DEF      GPVCYL            GET PRIVATE CYLINDER
         DEF      RNPVCYL           RELEASE PRIVATE RANDOM FILE
         DEF      RNVAT             RELEASE GRANULE ON NEXT VOLUME
         DEF      RPVCYL            RELEASE PRIVATE CYLINDER
         PAGE
*        REFS
         REF      DCT22             INDEX INTO DISCLIMS
         REF      DISCLIMS          MAX SECTOR # FOR DEVICE
         PAGE
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
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
GETPAT   LI,R7    X'1FFFF'          MASK
         AND,R7   PAT,R6            EXTRACT FROM DCB
         LI,4     BAVNO             GET VNO FOR ADDRESS GENERATION
         LB,12    *6,4
         BNEZ     0,5               SOMETHING THERE, O.K.
GGERRET  LI,8     0                 SET NONE
RET      PULL     6,2               RESTORE REGISTERS
         AI,SR1   0                 SET CC
         B        *R11              RETURN
         PAGE
SETBITS  LI,R2    -1                ONE BITS
         B        %+2
SETBITSZ LI,R2    0                 ZERO BITS
         LW,R3    Y8                GET BIT ZERO
         LCW,R5   R5                INVERT BIT NUMBER
         STS,3    6,7               SET MAP UPDATED BIT FOR CLOSEPV
         SCS,3    0,5               POSITION FOR INITIAL BIT
         AI,R5    32                SET NUMBER REMAINING
SETL1    STS,R2   *R7,R4            SET A BIT
         BDR,R6   %+2               COUNT DOWN NUMBER TO SET
         B        *R12              RETURN
         SCS,3    -1                SHIFT TO NEXT BIT
         BDR,R5   SETL1             CONTINUE THIS WORD
         LI,R5    32                RESET BIT COUNT
         AI,R4    1                 NEXT WORD
         B        SETL1             CONTINUE
         PAGE
*F*      NAME: RPVCYL,RNPVCYL,RNVAT
*F*      PURPOSE: RELEASE PRIVATE CYLINDER(S) OR NVAT GRANULE.
*K*      NVAT 1 OF 29 GRANULES ALLOCATED FROM VOL#N BITMAP BUT ON VOL#N+1
RPVCYL   LI,D4    1                 SET COUNT TO ONE
RNPVCYL  PUSH     6,2               ENTRY WITH COUNT IN D4
         BAL,R5   GETPAT            GET ADDRESS OF BITMAP
         LSECTA,R5 SR1              GET SECTOR ADDRESS
         LI,R6    X'FF'             EXTRACT
         AND,R6   1,R7               NGC
         LI,R4    0
         SCS,R5   -1                CHECK FOR EVEN GRANULE
         AI,R5    0                 ADDRESS
         BLZ      GGERRET           NO
         CI,5     30                CHECK FOR RNVAT
         BL       RPV2              YES
         DW,R4    R6                CONVERT TO CYLINDER
         AI,R4    0                 CHECK FOR EVEN CYL
         BNEZ     GGERRET           NO
         INT,2    1,7               GET DCT INDEX
         LW,3     5                 MAKE SURE WE WONT GO OFF END OF PACK
         AW,3     15                LAST CYL +1
         MW,3     6                 LAST GRAN +1
         SLS,3    1                 LAST SCTOR +1
         LB,2     DCT22,2
         CW,3     DISCLIMS,2
         BG       GGERRET           NO GOOD
         SLD,R4   27                SEPARATE WORD AND
         SCS,R5   5                 BIT NUMBER
         LW,R6    R15               GET COUNT
         AI,R4    7                 START OF BITMAP
RPV1     BAL,R12  SETBITS           STORE BITS
         B        RET               DONE
RPV2     LI,R4    5                 SET TO NVAT
         LI,R6    1                 COUNT TO RELEASE
         BIR,R15  RPV1              TEST FLAG AND BRANCH
         B        GGERRET           ERROR
RNVAT    LI,D4    X'80001'          FLAG FOR RNVAT
         B        RNPVCYL
         PAGE
*F*      NAME: GPVCYL
*F*      PURPOSE: ALLOCATE 1 PRIVATE CYLINDER FROM THE BITMAP.
GPVCYL   PUSH     6,2               SAVE REGS
         BAL,R5   GETPAT            GET ADDRESS OF BITMAP
         LI,R2    0                 SET SWITCH FOR GET CYL
         LI,R4    7                 START OF BITMAP
         LW,R6    4,R7              GET LINGTH OF BIT MAP
GPV2     LI,5     -32               BIT COUNTER
         LW,R8    *R7,R4            GET A WORD
         BEZ      L1A               NULL
L1       SLS,R8   1                 SHIFT-A-BIT
         BOD      L3                GOT ONE
         BIR,5    L1                NO, KEEP LOOKING
L1A      AI,R4    1                 NEXT WORD
         BDR,6    GPV2              CONTINUE
         B        GGERRET           EMPTY
         SPACE    2
L3       AI,R5    32                CALCULATE BIT# IN WORD
         LW,13    4                 AND CYLINDER# ON DEVICE
         AI,13    -7                ASSUME NOT NVAT
         SLS,13   5                 WORDS*32
         OR,13    5                 + BIT#
         LI,R6    X'FF'             EXTRACT
         AND,R6   1,R7              NGC
         EXU      GNV,2             *CYLSZ OR LOAD BIT# IN WORD
GPV3     LI,R8    0                 CLEAR RESULT
         SLS,R13  1                 MULTIPLY BY 2(NSG)
         STSECTA,R13,R3 SR1         STORE RELATIVE SECTOR
         LW,3     12                STORE VOL#
         STDCTX,3,S 8
         STB,R6   SR1               SET NGC
         LW,R6    R2                GET COUNT
GPV1     BAL,R12  SETBITSZ          CLER BITS
         B        RET
         PAGE
*F*      NAME: GNPVCYL
*F*      PURPOSE: ALLOCATE N PRIVATE CYLINDERS FROM THE BITMAP.
GNPVCYL  PUSH     6,2               GET N, # GRANULES IN 15
         BAL,5    GETPAT            GET ADDRESS OF BITMAP
         LI,6     X'FF'             EXTRACT CYLSZ
         AND,6    1,7
         AW,15    6                 CALCULATE # CYLNS TO GET
         AI,15    -1                ROUNDING UP
         DW,15    6
         LI,3     29                CALCULATE FIRST NON-NVAT ADDRESS
         DW,3     6                 BIT# PLUS ONE
         AI,3     1
         LW,4     4,7               SIZE OF BITMAP
         LI,5     32                SIZE OF WORD OF BITS
         LW,13    4                 COUNTING REGISTER
         AI,4     7                 DISPLACEMENT REG
         LW,2     Y8                COMPARE REG
         AI,4     -1                SEARCH FOR FIRST NONZERO WORD
         MTW,0    *7,4
         BNEZ     %+3               GOT ONE
         BDR,13   %-3               KEEP LOOKING
         B        GGERRET
         LW,8     15                SET TEMP COUNTER
GNP2     SCS,2    1                 LOOK AT NEXT BIT
         CW,2     *7,4
         BANZ     GNP3              ITS THERE
         CI,13    1                 NO, ARE WE ON THE LAST WORD
         BNE      GNP4              NO
         CW,5     3                 YES, ARE WE ON THE LAST REAL BIT
         BNE      GNP4              NO, RESTART SEARCH
         AI,5     1                 YES, RETURN WITH WHAT WEVE GOT
         B        %+2
GNP3     BDR,8    GNP5              COUNT THIS ONE
         SW,15    8                 DID WE GET ANY
         BLEZ     GGERRET
         SLS,13   5                 YES, CALCULATE CYL#
         AI,5     -33
         AW,13    5
         MW,13    6                 AND CYL#
         AI,5     32                ADJUST POINTER
         LW,R2    R15               GET CYLINDER COUNT
         B        GPV3              THEN GO GENERATE ADDR AND ZAP BITS
GNP4     LW,8     15                START  OVER, REST COUNTER
GNP5     BDR,5    GNP2              GET NXT BIT IN THIS WORD
         AI,4     -1                NONE LEFT, TRY NEXT WORD
         LI,5     32
         BDR,13   GNP2              NEVER FALLS THRU, DUE TO LAST BIT TEST
         PAGE
*F*      NAME: GNVAT
*F*      PURPOSE: ALLOCATE ONE NVAT GRANULE.
GNVAT    PUSH     6,2               SAVE REGS
         BAL,R5   GETPAT            GET HGP ADDRESS
         LI,R4    5                 ADDRESS OF NVAT IN HGP
         LI,6     1                 ONLY ONE WORD
         AI,12    1                 VOL# IS NEXT ONE
         LI,R2    1                 SET SWITCH FOR GNVAT
         B        GPV2              MERGE WITH COMMON CODE
GNV      MW,13    6                 GCYL
         LW,13    5                 GNVAT
         END

