         SYSTEM   SIG7FDP
S69PROC  SET      1
UTSPROC  SET      0
         SYSTEM   UTS
SYSGEN   SET      1
         PAGE
*************************************
*                                   *
*        MEMORY MANAGEMENT          *
*                                   *
*************************************
         PAGE
*        |-----------------------------------|
*  J:JIT |                                   |
*        |                 .                 |
*        |          USERS TEMP STACK         |
*        |                 .                 |
*        |                 .                 |
*        |                 .                 |
*        |-----------------------------------|
*        |                 .                 |
*        |             BATCH JIT             |
*        |                 .                 |
*        |                 .                 |
*        |-----------------------------------|
*        |               J:BUP               |
*        |               J:EUP               |
*        |-----------------------------------|
*        |               J:PLL               |
*        |               J:PUL               |
*        |               J:DLL               |
*        |               J:DUL               |
*        |               J:DDLL              |
*        |               J:DDUL              |
*        |               J:CLL               |
*        |               J:CUL               |
*        |-----------------------------------|
*        | JB:PCP | JB:PCD | JB:PCDD| JB:PCC |
*        |-----------------------------------|
*        | JB:TDP | JB:BCP | JB:MNPA| JB:NASP|
*        |-----------------------------------|
         PAGE
*        |-----------------------------------|
*        | JB:PPH |                          |
*        |-----------------------------------|
*        | JB:PPT |                          |
*        |-----------------------------------|
*        | JB:PPC |                          |
*        |-----------------------------------|
*        | JB:VLH |                          |
*        |-----------------------------------|
*        | JB:VLT |                          |
*        |-----------------------------------|
*        |               J:VLCS              |
*        |-----------------------------------|
*        |                J:AJ               |
*        |-----------------------------------|
*        |               J:CLPA              |
*        |-----------------------------------|
*        |                J:CLE              |
*        |-----------------------------------|
*        |                J:CLP              |
*        |-----------------------------------|
*        |                J:CLS              |
*        |-----------------------------------|
*        |J:JAC  | | | | | | | | | | | | | | |
*        |                 .                 |
*        |                 .                 |
*        | | | | | | | | | | | | | | | | | | |
*        |-----------------------------------|
         PAGE
*        |-----------------------------------|
*        |J:DAC  | | | | | | | | | | | | | | |
*        |                 .                 |
*        |                 .                 |
*        | | | | | | | | | | | | | | | | | | |
*        |-----------------------------------|
*        |JB:LMAP|         |        |        |
*        |                 .                 |
*        |                 .                 |
*        |                 .                 |
*        |                 .                 |
*        |       |         |        |        |
*        |-----------------------------------|
*         |JX:CMAP|          |         |          |
*        |                 .                 |
*        |                 .                 |
*        |                 .                 |
*        |                 .                 |
*        |       |         |        |        |
*        |-----------------------------------|
*        |      JH:DA      |                 |
*        |                 .                 |
*        |                 .                 |
*        |                 .                 |
*        |                 |                 |
*        |-----------------------------------|
         PAGE
*        |-----------------------------------|
*        |                J:CL               |
*        |                                   |
*        |                                   |
*        |                                   |
*        |-----------------------------------|
*        |                                   |
*        |                                   |
*        |                                   |
*        |                                   |
*        |-----------------------------------|
*        |                 .                 |
*        |                 .                 |
*        |                 .                 |
*        |                 .                 |
*        |-----------------------------------|
*        |                                   |
*        |                                   |
*        |                                   |
*        |                                   |
*        |-----------------------------------|
         PAGE
         REF      TSTACK
PUSH     CNAME    X'9',X'B'
PULL     CNAME    X'8',X'A'
         PROC
         DO       NUM(AF)=1
LF       GEN,1,7,4,3,17  0,NAME(1),AF(1),0,TSTACK
         ELSE
         DO       AF(1)=1
LF       GEN,1,7,4,3,17  0,NAME(1),AF(2),0,TSTACK
         ELSE
         DO       AF(1)=16
LF       LCI      0
         ELSE
LF       LCI      AF(1)
         FIN
         GEN,1,7,4,3,17  0,NAME(2),AF(2),0,TSTACK
         FIN
         FIN
         PEND
ENABLE   CNAME
         PROC
         WD,0     X'27'
         PEND
DISABLE  CNAME
         PROC
         WD,0     X'37'
         PEND
         OPEN     L
HBIT     FNAME    2
         PROC
L        SET      AF
K        SET      0
I        DO       NUM(L)
K        SET      K|(1**((NAME*8-1)-L(I)))
         FIN
         PEND     K
         CLOSE    L
SJAC     EQU      X'1000'
TIC      EQU      X'80'
BAT      EQU      X'100'
DELIC    EQU      HBIT(9)
DIC      EQU      DELIC
PPSWAP   EQU      HBIT(11)
         PAGE
         DEF      MM
         REF      J:RNST
         REF      DOUBLEZERO
         REF      MB:GAM1
         REF      MB:GAM2
         REF      MB:GAM3
         REF      MB:GAM4
         REF      MB:GAM5
         REF      MB:GAM6
         REF      MB:GAM7
         REF      MB:DWT
         REF      MB:GPT
         REF      MB:SPT
         REF      MB:SWAPS
         REF      M:GASLIM
         REF      M:GATLIM
         REF      S:DP
         REF      MINUS2
         REF      M5
         REF      UB:SWAPI
         REF      JOVVP
         REF      JCOVP
         REF      JH:LDCF,JITLOC
         REF      JB:FBUL,JB:FBUC,JBFBUC,JBFBFP
         REF      JB:CBUC,JBCBUC,JBCBLL
         REF       JXBUFVP,SBUF1VPA
         REF       JCO2VPA
         REF      GETSBUF
         REF      JSBUF2VP
         REF      M13,J:BUP
         REF      JEUPVP,JBUPVP
         REF      J:TELFLGS
         REF      Y002
         REF      JB:NRG,X4
         REF      J:ABUF
         REF      J:JIT
         REF      J:PLL
         REF      J:PUL
         REF      J:EUP
         REF      J:DLL
         REF      JB:PCP
         REF      J:DUL
         REF      JBMNPA
         REF,1    JB:PEAK
         REF      Y003E
         REF      JBNASP
         REF      J:AJ
         REF      J:AJIT
         REF      JX:PPH
         REF      JB:PPC
         REF      JB:VLH
         REF      JB:VLT
         REF      J:VLCS
         REF      JB:PRIV
         REF      J:JAC
         REF      JB:LMAP
         REF      JX:CMAP
         REF      J:CLE
         REF      J:CL
         REF      J:CLPA
         REF      JH:DA
         REF      JCCL
         REF      JJAC
         REF      JBNRG
         REF      MAP,UNMAP
         REF      UB:ASP
         REF      UB:ACP,Y4,J:BASE
         REF      UB:APR
         REF      SB:RBMX,SB:ROMX,SL:CORE
CORATX   EQU      1                 CORE RAT INDEX
         REF      S:PCORE
         REF      PB:PSZ
         REF      S:CUN
         REF      UB:PCT,UX:JIT,UH:FLG
         REF      UB:MF
         REF      UH:JIT,UH:AJIT
         REF      SPDBASE
         REF      P:SA
         DEF      T:SAD0
         DEF      T:GPP
         DEF      T:FPP
         DEF      T:SGR
         DEF      T:TOTESZ
         DEF       T:GBUF,T:RBUF,T:MBUF
         DEF       T:ZBUF,T:XBUF,T:SBUF
         DEF      T:GVGPI
         DEF      T:GVPI,T:RVPI
         DEF      T:PAC
         DEF      T:SXACM3,T:SACP1,T:SXMAPM3
         DEF      T:XMMC
         REF      M:FREE#GRAN
         DEF      T:SGAJIT
         DEF      T:SAC
         DO       SYSGEN
         REF      M:SBAND
         FIN
         REF      M:SGP
         REF      M:FPPH,M:FPPT,M:FPPC
         REF      MX:PPUT
         REF      M:ADRINCR
         REF      JCMAP
         DEF      T:IACU
         DEF      T:GNVPI
         DEF      T:GNVNPI
         DEF      T:RVSPI
         DEF      T:SNAC
         DEF      PAGEZAP
         REF      JJITVP,JAJITVP
         REF      E:NC,E:ND
         REF      E:DPA
         REF      T:RE
         REF      SB:HQ
         REF      RCVPSD
         REF      FPMC
         DEF      NPMC
         REF      PNAMEND,P:NAME
         REF      UB:DB
         REF      P:AC
         REF      XFFF800
         REF      XA
         REF      :BIG
NPMC     EQU      X'22'
J        EQU      BA(J:JIT)
         PAGE
MM       EQU      %
UACT     DATA,1   1,0,0,3,2         PROG,DATA,DYN DATA,CONTEXT,DCBS
         BOUND    8
MMUMI    :PSD     (IA,RLSP2),(WK,1),INH
WNDLIMS  DATA      SBUF1VPA,JCO2VPA
SPRLIMS  DATA      JXBUFVP,JOVVP-1
TEL      TEXTC    'TEL'
         TEXT     '    '
PXAC     DATA     J:JAC+14
         GEN,8,24 2,SPDBASE
         REF      YFF
CCS      EQU      YFF
         DO       1-SYSGEN
         DEF      M:SBAND,M:SWAPD
M:SBAND  DATA     X'1000'
M:SWAPD  DATA     X'1F0'
         FIN
         REF      X1,X10,Y8,Y08,M8,M2
MN2      DATA     X'FFFFFFFC'
XN2      DATA     -2
POSITION EQU      %
         GEN,16,16 0,1
         GEN,16,16 2,4
MASKHAF  GEN,16,16 8,16
         DATA     X'55555555'
         DATA     X'33333333'
         DATA     X'0F0F0F0F'
         DATA     X'00FF00FF'
         DATA     X'0000FFFF'
SACBP    DATA     X'C0300C03'
SACACC   DATA     X'0055AAFF'
         REF      T:REG
XPPSWAP  DATA     PPSWAP
NREADY   EQU      XN2
SPJITAC  DATA     X'55530FFF'
SPJACTRL GEN,8,7,8,9 1,0,X'40',0
         DEF      LKIMG
LKIMG    RES      8                 WL IMAGE FOR XDLT
         PAGE
*************************************
*        INTERROGRATE AC IN USER IMAGE *
*************************************
*        7  = VP #
*        CC3&4= AC
T:IACU   EQU      %
         PUSH     8,0
         DO       0                 T:ZPUP
         LI,5     2
         FIN                        T:ZPUP
         AND,7    M8
         BNEZ     %+3               NOT PAGE ZERO
         LI,6     2                 AC=2 FOR PAGE
         B        IACU6             ZERO
         CI,7     JOVVP
         BGE      IACU2
         LI,6     3
         B        IACU6
*        UNUSED ROUTINE  T:ZPUP  REMOVED  (17 WORDS RJR).
         DO       0                 T:ZPUP
T:ZPUP   PUSH     8,0
         LI,5     0
         FIN                        T:ZPUP
IACU2    EQU      %
         LI,2     0
         LW,3     7
         DW,2     X10                2= DB BIT POS    3= WD OF IMAGE
         LW,7     J:JAC,3           WD FRM AC IMAGE
         LI,6     0
         SLS,2    1                 DB BIT POS TO BIT POS
         SLD,6    2,2               APPRO AC LOW 2 BITS OF 6
         DO       0                 T:ZPUP
         BDR,5    IACU6
         CI,6     1
         BAZ      IACU6
         CI,6     2
         BANZ     IACU6
         LD,0     6
         AND,0    MN2               ZERO AC
         LCW,2    2
         SLD,0    -2,2              MOVE WD BACK TO ORIG & APPRO AC TO 0
         LI,2     1                 IMAGE ADR
         AI,3     X'800'            CNT OF 1 WHEN SHIFTED
         SLS,3    13
         LPC,2    0
         FIN                        T:ZPUP
IACU6    EQU      %
         AND,6    M2                GET APPRO AC
         SLS,6    4                 TO 3&4TH BITS OF BYTE
         STB,6    11
         PULL     8,0
IACU7    LC       11
         B        *11
         PAGE
*************************************
*        GET N VIRT & PHY           *
*        INTERNALLY CALLED           *
*************************************
*  I     6  = # OF PGS
*  I     7  = 1ST VP #
*        5  = -1 = INDICATION TO GVP TO GET NO PP
*           =  0 = INDICATION TO GVP TO GET PP
T:GNVPI  EQU      %
         PUSH     7,5
         LI,5     0
GNV2     EQU      %
         LI,10    -1
GNV3     EQU      %
         LI,4     0                 4 IS NOT AFFECTED BY FPMC TEST BUT
*                                   IS AFFECTED BY MAX PGS TESTS
         BAL,11   T:GVPI
         B        GNV7              REQUESTED TOO MANY PGS
         BCR,15   GNV4              GOT PG
         STW,5    10
GNV4     EQU      %
         AI,7     1
         BDR,6    GNV3
         CI,10    -1
         BE       %+3
         LI,6     E:NC
         BAL,11   T:REG
         LI,10    0                 INDICATES ALL OK
GNV5     EQU      %
         STB,10   *TSTACK
         B        SAD5             DONT CLEAN FOR GENERAL CASE
*
*        PAGE CLEANER
*
*        7=PAGE BEFORE FIRST TO CLEAN
*        10=0,1,-1 DIRECTION TO CLEAN
*        6=#PAGES TO CLEAN
*
         DEF      PAGEZAPT,PAGEZAP0
         REF      GZPRIV
PAGEZAP0 LI,10    0                 CLEAN ONE PAGE
         LI,6     1
         B        PGPZE
PAGEZAPT LI,10    -1                ALL PAGES
         AI,7     -1                R7 BELOW 1ST PAGE
PAGEZAP  LB,11    JB:PRIV           PAGEZAP0 BYPASSES
         CI,3     GZPRIV            DO WE CLEAN
         BAZ      0,5
PGPZE    SLS,7    9
         SLS,10   9
PAGEZAP1 AI,6     -1
         BLZ      0,5
         SW,7     10
         LCI      0
I        DO       32
         STM,7    I*16-16,7
         FIN
         B        PAGEZAP1
GNV7     EQU      %
         AI,4     0
         BE       GNV4
         CI,10    -1
         BE       %+3
         LI,6     E:NC
         BAL,11   T:REG
         LI,10    X'FF'             INDICATION OF ERROR
         B        GNV5
         PAGE
*************************************
*        RELEASE VP SAVE PP
*        INTERNALLY CALLED          *
*************************************
T:RVSPI  EQU      %
         PUSH     7,5
         LI,5     -1
         LI,11    7H3
         B        T:RVPI
*************************************
*        GET VP GIVEN PP             *
*        INTERNALLY CALLED          *
*************************************
*        7  = VP
*        3  = PP
*        5  = -2 = INDICATION TO GVP TO USE GIVEN PP
T:GVGPI  EQU      %
         PUSH     7,5
         LI,5     -2
         BAL,11   T:GVPI
7H3      RES      0
         NOP
SAD5     PULL     7,5
         B        IACU7
         PAGE
*        SET N AC
*  I     7  = VP #
*  I     6  = # OF PGS
T:SNAC   EQU      %
SNAC1    EQU      %
         LI,2     SNAC2+X'80000'
         CI,7     X'100'
         BL       T:SACP1
         SUA      X'21'
SNAC2    RES      0
         AI,7     1
         BDR,6    SNAC1
         B        *11
*
*************************************
*        SAD ENTRY FOR APWP         *
*************************************
*        6 = PHYSICAL PAGE NUMBER
*        7 = VIRTUAL PAGE NUMBER
*        8 = ACCESS CODE FOR PAGE
*
T:SAD0   EQU      %
         PUSH     7,5
         LI,4     2                 INDICATE PWP ENTRY AND LMAP CONSTANT
          DEF     T:SAD1
T:SAD1    EQU     %
SAD0B    EQU      %
         AND,6    M13
         AND,7    M8
         CLM,7    J:BUP             IS VP WITHIN USER PROG LIMITS
         BCS,9    SAD0R             ERROR
         LI,13    FPMC
         COMPARE,13 JX:CMAP,7
         BNE      SAD0R             ERROR
         REF      HIGH
         CW,6     HIGH
         BG       SAD0R             DON'T ALLOW MORE THAN PHYS
         STORE,6  JX:CMAP,7
         STB,4    JB:LMAP,7
         CI,4     1                 WAS ENTRY FOR SAD
         BE       SAD0D             YES
         LW,4     8                 PWP ENTRY, AC INPUT IN R8
         B        SAD1              GO SET ACCESS
SAD0D    EQU      %
*  SET AC
         LI,4     0                 AC
         AI,8     X'80'-X'B0'
         BGE      %+2
SAD1M1   AI,4     2
SAD1     BAL,2    T:SAC
*  EXECUTE AC
         BAL,11   T:SXACM3
*  EXECUTE MAP
         BAL,11   T:SXMAPM3
         LI,12    0                 SET CC AS NO ERROR
SAD0R    EQU      %
         PULL     7,5               RESTORE REGS
         LC       12                SET CC
         B        *11               RETURN
*
* ERROR RETURN FROM T:TOTESZ
*
SIZERR   PLW,3    TSTACK
         B        *11
         PAGE
T:GVPI   EQU      %
*  TEST WHETHER THE VP IS AVAILABLE
         LI,12    FPMC              FREE PG MAP CONSTANT
         COMPARE,12 JX:CMAP,7       IS REQUESTED VP FREE
         BNE      GVPO
GVP2     EQU      %
         LW,4     S:CUN             GET CURRENT USER #
         PSW,3    TSTACK
         LI,0     GVP26
*
* ROUTINE TO TOTAL UP THE USER SIZE
* BAL,0 T:TOTESZ  R4=CUN
*                 R7=VIRTUAL PAGE#
*                 R7=0 INDICATES THIS IS A TEST FOR PCORE EXCEEDED
* DESTROYS R1,R2,R3,R12,R13
*
T:TOTESZ EQU      %
         LB,12    UB:PCT,4          USER PROC + DATA + CONTEXT + DY DATA
         LB,13    JB:PCP            PAGE COUNT OF USERS PROCEDURE
         BEZ      NOOLAY            SHARED PROCESSOR RUNNING-OR NO TREE TABLE
         LI,1     1                 USER RUNNING SO FIND HIS TRUE SIZE
         LB,1     JB:PCP,1          PAGE COUNT OF DATA
         AW,13    1                 CURRENT PROCD PGS + CURRENT DATA PGS
         SW,12    13                 TAKEN OUT OF TOTAL PAGE COUNT
*                                   -NOW ADD PROCEDURE AND DATA BACK
*                                     IN BASED ON JIT LIMITS TO ALLOW
*                                     FOR POSSIBLE SEGMENT LOADING
         AW,12    J:PUL
         SW,12    J:PLL
         AW,12    J:DUL
         SW,12    J:DLL
         AI,12    2                 BECAUSE LIMITS ARE INCLUSIVE
NOOLAY   EQU      %
         LI,2     3
         LB,2     JB:PCP,2          PAGE COUNT CONTEXT
         SW,12    2
         LI,1     J+JBMNPA
         LB,13    0,1               GET JIT LIMIT
         BNEZ     GVP23             IF NOT 0, USE IT
         LI,2     CORATX            CORE RAT INDEX
         LB,13    SB:RBMX,2         SYSTEM LIMIT FOR BATCH CORE
         LC       J:JIT
         BCR,8    %+2
         LB,13    SB:ROMX,2         SYSTEM LIMIT FOR ONLINE CORE
GVP23    EQU      %
         LI,1     JBUPVP             START AT BEGINNING OF USER
         LI,2     2                 LOOKING FOR APWPAGES AND
GVP230   EQU      %
         CB,2     JB:LMAP,1         AND ADDING THEM TO USER TALLY
         BNE      %+2               SO THAT USER CANNOT
         AI,12    1                 EXCEED MEMORY LIMIT WHILE
         AI,1     1                 APWP HAS TEMPORARILY
         CW,1     J:EUP             DECREMENTED THE USER'S
         BG       %+2               PAGE COUNT
         B        GVP230            CONTINUE TILL DONE
         CW,12    13                HAS MAX BEEN ALLOC
         BL       GVP25             NO
         CI,7     JOVVP-1           TRYING TO GET A SPARE
         BLE      GVP25             YES-CONTINUE
         LW,1     Y003E
         LS,1     J:RNST
         BEZ      GVP25             IF ASP,   ALLOW EVERYTHING
         LB,2     UB:APR,4          YES, CHECK FOR SPEC PROC
         BNEZ     %+2
         LB,2     UB:ASP,4
         LW,1     Y08
         CW,1     P:SA,2            IS PROCESSOR ALLOWED MAX CORE
         BAZ      *0                NO-ABORT HIM
GVP25    EQU      %
         LI,2     JB:PEAK
         CB,12    0,2               IS THIS NEW PEAK COUNT
         BLE      %+2               NO
         MTB,1    0,2               YES-INC COUNT BY ONE
         LI,2     3
         LB,2     JB:PCP,2          COUNT OF CONTEXT
         AW,12    2
         CB,7     JB:FBUL           GETTING A FILE MGMT BUFFER
         BG       %+3               NO-CHECK FOR UNALLOCATED FM BUFFERS
         CI,7     0                 PERHAPS IT IS A TEST FOR PCORE
         BNE      GVP90             NO-REALLY A FM BUFFER
         LB,1     JB:FBUL           HOLD BACK CONTEXT NOT YET ALLOCATED
         AI,1     -JXBUFVP+1        MAX # FPOOLS
         LI,2     JBFBUC
         LB,2     J:JIT,2           # FPOOLS ALLOCATED
         SW,1     2                 # FPOOL LEFT TO ALLOCATE
         AW,12    1                 HOLD THEM IN RESERVE
         CI,7     JBUPVP            GETTING A USER PAGE
         BGE      GVP90             YES-NOW HOLD OUT UNALLOCATED CPOOLS
         CI,7     0                 PERHAPS IT IS A TEST FOR PCORE
         BNE      GVP24             NO-GETTING A CPOOL
GVP90    LI,2     X'FFFF'
         AND,2    JH:LDCF           ALLOWED SYMBIONT ACCESS
         BEZ      GVP24             NO
         LI,1     JBCBUC
         LB,1     J:JIT,1           # CPOOLS USED
         CI,1     2                 DEFAULT OR MORE
         BGE      GVP24             YES-DONT HOLD BACK ANY MORE
         AI,12    2                 HOLD BACK THOSE NOT
         SW,12    1                   NOT YET ALLOCATED
GVP24    EQU      %
         CW,12    SL:CORE           USER PAGES : MAX SWAP SIZE
         BL       GVP240            USER SIZE IS OK
         CI,7     0                 IS THIS A CHECK FOR PCORE
         BNE      *0                NO-GETTING USER PAGE-ABORT HIM
*
* USER SWAP SIZE OK-NOW CHECK FOR PCORE EXCEEDED
*                                 GET STANDARD SHARED PROC. SIZE
GVP240   LH,2     UH:FLG,4
         CI,2     TIC               IS COMMAND PROCESSOR IN CONTROL
         BAZ      GVP241            NO-SEE IF THERE IS APR
         LB,1     UB:ACP,4          GET COMMAND PROCESSOR NUMBER
         LW,3     Y4
         CW,3     P:SA,1            IS CP A SPECIAL SHARED PROCESSOR
         BANZ     GVP250            YES-GO COMPUTE SPEC. SHRD. PROC. SIZE
         B        %+3               NO-CP SIZE IS INCLUDED IN STD. SHRD. PROC. S
GVP241   LB,1     UB:APR,4          IS STD. SHRD. PROC. ASSOCIATED
         BEZ      GVP242            NO-SEE IF WE SHOULD HOLD BACK FOR TEL
         AW,12    J:PUL             SIZE OF APR OR ACP(NOT SPECIAL)
         SW,12    J:PLL             FROM JIT LIMITS (ALLOWS FOR SEG LOADING)
         AI,12    1                 BECAUSE LIMITS ARE INCLUSIVE
         CI,2     TIC               DID WE JUST ADD IN ACP
         BANZ     GVP255            YES-DONT CHECK FOR TEL
*                                 GET SPECIAL SHARED PROCESSOR SIZE
*                                 LARGEST OF ACP/ASP/DB
GVP242   EQU      %
         LC       J:JIT             ON-LINE USER
         BCR,8    GVP255            NO
         LW,2     Y002              DOES ON-LINE USER WANT
         CW,2     J:TELFLGS          SPACE HELD IN RESERVE FOR TEL
         BANZ     GVP255            NO
         LI,1     PNAMEND           FIND TELS NUMBER
         LD,2     TEL
         CD,2     P:NAME,1
         BE       %+2
         BDR,1    %-2
GVP250   LB,2     PB:PSZ,1          FIND TELS SIZE
         B        GVP256
GVP255   EQU      %                 FIND # PGS REQUIRED FOR SHARED
         LI,2     0                 NO SP. SHARED CP
GVP256   LB,1     UB:ASP,4          SP.SHARED PROC OR CORE LIBRARY
         LB,13    PB:PSZ,1          ASP SIZE
         LB,1     UB:DB,4           DEBUGGER
         CB,13    PB:PSZ,1          ASP : DB
         BGE      %+2
         LB,13    PB:PSZ,1
         CW,13    2                 ASP/DB : SP.SHARED ACP
         BGE      %+2
         LW,13    2
         AW,12    13                GREATEST POSSIBLE SIZE
         CI,7     0                 IS THIS A PCORE TEST
         BNE      %+2               NO
         AI,12    -1                YES-ADJUST FOR BGE BELOW
         CW,12    S:PCORE           IS USER REQUIREMENT < PHY CORE
         BGE      *0
         AI,0     1
         B        *0
GVP26    B        SIZERR            T:TOTESZ TEST FAILED
         PLW,3    TSTACK
         PUSH     11
         PUSH     6
         LI,4     J+JBNRG
         LB,1     0,4
         AI,1     -1
         STB,1    0,4               STORE REMAINING GR. COUNT
         BGEZ     GVP45             BR. IF MORE GRANULES REMAIN
         LI,1     3
         STB,1    0,4               ELSE GET ANOTHER GROUP.
*          GET FOUR GRANULES.
GVP3    EQU      %
         LI,4     J+JBNASP
         LB,1     0,4               GET NEXT GRANULE POSITION
* I 1  = NEXT GRANULE POSITION
* O 15 = DISC ADR ALLOCATED
* O CC4= 0 A GRANULE WAS AVAILABLE
* O 1  = PRES GRAN POSITION
         BAL,11   T:SGA             SWAPPER GRANULE ALLOCATION
         BCR,1    GVP4              A GRAN WAS AVAILABLE
*  NO DISC GRANULE WAS AVAILABLE - REG - UPON RETURN, GET GRAN AGAIN
         LI,6     E:ND              NO DISC EVENT #
         BAL,11   T:REG
        B        GVP3              TRY FOR DISC AGAIN
GVP4     EQU      %
         AI,1     4                 FOUR GRANULES PER CLUSTER
         STB,1    0,4               SAVE IT IN JIT FOR NEXT REQUEST
         LI,4     J:CL
         LW,12    J:AJ              GET ADDRESS OF CLIST IN JIT
         BEZ      %+2
         LI,4     J:AJIT            OR AJIT, IF USED.
         AW,4     J:CLE
         LW,1     J:CLE             CLIST LENGTH
         DW,1     XA
         STH,15   JH:DA,1           ADDRESS TABLE. STORE DA
         LW,2     S:CUN
         LOAD,12  UX:JIT,2          PHYSICAL PAGE NR OF JIT
         LI,13    :BIG
         BLEZ     %+2
         LW,12    J:AJ              ON BIG9 THE DA IS IN AJIT
         SLS,12   11                BA(JIT PAGE)
         LW,13    XFFF800
         STS,12   0,4               STORE PHYS PG ADDRESS IN SEEKIOCD
         MTW,2    J:CLE             INC LENGTH OF CLIST.
*  GET PP # FROM FREE PG POOL  UNLESS THIS CAL IS GET VP, NO PP
* O 3  = PHY PG # OBTAINED
GVP45    EQU      %
         CI,5     -1
         BL       GVP51
         BE       GVP52
         BAL,2    T:GPP
GVP51    AI,3     0
         BNE      GVP5
*  RESET READY FLG IF NO PP
GVP52    RES      0
         LW,4     S:CUN
         LH,0     UH:FLG,4
         LI,3     NPMC
         AND,0    NREADY            RESET READY TO RUN BIT
         STH,0    UH:FLG,4
GVP5     EQU      %
         LI,2     BA(JB:VLH)-BA(JB:LMAP) IX TO 1ST LMAP LINK
         LI,0     0
         LI,4     J:CL
         LW,12    J:AJ
         BEZ      %+2
         LI,4     J:AJIT
         AW,4     J:CLE
         MTW,2    J:CLE             INC CLIST LENGTH FOR NEW WRITE IOCD.
         LI,13    3                 SEEK ORDER
         B        IV31
IV9      RES      0
         LOAD,12  MX:PPUT,4         WHAT ITS LINKED TO
         STORE,12 MX:PPUT,3         LINK NEW PP
         STORE,3  MX:PPUT,4         LINK PREV TO NEW PP
IV10     STORE,3  JX:CMAP,7         PUT PP# INTO CMAP
*  SET SWAP PURE PROCEDURE FLAG BIT
         LW,4     S:CUN
         MTB,1    UB:PCT,4          UPDATE USERS PG CNT TOTAL NEEDED
         LH,0     UH:FLG,4
         OR,0     XPPSWAP           SET PPSWAP BIT
         STH,0    UH:FLG,4
*  TEST WHICH AREA PG IS IN
         LI,1     -5
GVP6     CLM,7    WA(DA(J:PLL)+5),1 WHICH PAGE IS VP IN
         BCR,9    GVP7              FOUND AREA
         BIR,1    GVP6
         LI,1     -2                ASSUME CONTEXT
         CW,7     J:PUL
         BLE      GVP7
         CW,7     J:EUP
         BG       GVP7
         LI,1     -3                DYNAMIC DATA
*  UPDATE PG CNT FOR APPROPRIATE AREA
GVP7     AI,1     5                 CONVERT INDEX
         MTB,1    JB:PCP,1          INCR APPRO PG COUNT
*  SET UP FOR T:SAC
* I 13 = AC FOR JAC
* I 4  = AC FOR DAC
         CI,1     3                 IS PAGE IN CONTEXT AREA
         BE       GVP8              YES-NO CHANGE TO J:JAC
GVP75    EQU      %
         LB,4     UACT,1            AC FOR APPRO AREA
         BAL,2    T:SAC             SET UP USER & DELTA AC IN IMAGES
*  TEST WHETHER AJIT NEEDED
GVP8     EQU      %
         LW,12    J:CLE
         LI,4     J+JBNRG
         LB,4     0,4               IF THE NR OF REMAINING GRANULES
         BNEZ     %+2               IS 0
         AI,12    2                 ADD TWO FOR NEXT SEEK.
         BAL,0    T:GAJP            GET AJIT PP
         LOAD,3   JX:CMAP,7         GET PP #
         AI,3     -NPMC
         BEZ      GVP10
         CI,7     JOVVP-1           WAS A SPARE BUFFER OBTAINED
         BLE      GVP10             YES-DONT LOAD MAP NOR ACCESS
*  SET UP & EXECUTE MMC FOR MAP
* I 12 = IMAGE ADR
* I 14 = # OF PGS
* I 15 = STARTING VP #
         BAL,11   T:SXMAPM3
*  SET UP & EXECUTE MMC FOR AC
* I 12 = IMAGE ADR
* I 14 = # OF PGS
* I 15 = STARTING VP #
         LI,12    J:JAC             USER RUNNING - IMAGE ADR
         DO       1                 T:SXAC(SJAC)
         BAL,11   GVPA              *SET HIS ACCESS ON THE PAGE RIGHT
*
*        GVPA(T:SXAC)  NOW DOES SJAC STUFF  (13 WORDS,RJR)
*
         ELSE                       T:SXAC(SJAC)
         LI,11    GVP10
         LW,4     S:CUN
         LH,0     UH:FLG,4
         CI,0     SJAC
         BAZ      GVPA
         LI,14    JJITVP
         LI,15    X'F0'
         CS,14    7
         BNE      GVPA
         LI,14    SPJITAC
         LW,15    SPJACTRL          START AND COUNT CONTROL
         LPC,14   0
         LI,3     1
         FIN                        T:SXAC(SJAC)
*  T:SXAC RETURNS WITH REG 3 = 1
GVP10    EQU      %
         PULL     6
GVPB     RES      0
         PULL     11
         AI,11    1
         LCF,2    CCS,3             3=0 NO PP   3=1 NORMAL EXIT
RVP3     RES      0
GVPO     RES      0
         B        *11
         PAGE
T:RVPI   EQU      %
*  TEST WHETHER THE VP IS IN USE
         LI,12    FPMC              FREE PG MAP CONST
         COMPARE,12 JX:CMAP,7       IS VIRT PG TO RELEASE IN USE
         BE       RVP3
RVP2     EQU      %
         LB,4     JB:LMAP,7
         CB,7     JB:VLT
         BE       %+3               DON'T TEST TAIL
         CI,4     0                 DON'T RELEASE A CMAP PAGE
         BEZ      *11               NOT REPRESENTED IN LMAP
         PUSH     11
         CI,4     1
         BNE      RVP42             IF NOT A 'CVM' PAGE
         MTB,-1   JB:LMAP,7         GET RID OF 'CVM' FLAG
         STORE,12 JX:CMAP,7         ELIMINATE VIRTUAL PAGE
         B        RVP9              SET ACCESS AND GET OUT
RVP42    LW,2     S:CUN
RVP43    LB,4     UB:MF,2           IF USERS FUNCTION COUNT IS
         BEZ      RVP44             NON-ZERO PUT HIM TO SLEEP.
         REF      UH:FLG2
         LH,4     UH:FLG2,2         GET SECOND FLAGS
         OR,4     X8                SET DONT SWAP
         STH,4    UH:FLG2,2         AND REPLACE
         REF      X8
         STW,6    4
         REF      E:QMF
         LI,6     E:QMF             QUEUE FOR MASTER FUNCTION COUNT
         PUSH     11
         BAL,11   T:REG
         PULL     11
         LW,6     4
         B        RVP43
RVP44    EQU      %
*  DELETE VP & PP
         MTW,-2   J:CLE             REDUCE CLIST LENGTH BY 1 IOCD
         LI,2     3                 SETUP SEEK ORDER
         LI,4     J:CL              SETUP END CLIST
         LW,13    J:AJ
         BEZ      %+3
         LI,13    0
         LI,4     J:AJIT
         AW,4     J:CLE
         LI,1     BA(JB:VLH)-BA(JB:LMAP)          IX TO 1ST LMAP LINK
DV2      CB,7     JB:LMAP,1         IS THIS THE VP # TO RELEASE
         BE       DV4               YES
         LB,1     JB:LMAP,1         NEXT LINK
         XW,13    0,4               GET THE NEXT ADDRESS
         AI,4     -2                AND RIPPLE PREVIOUS UP.
         CB,2     *4                IS NEXT A SEEK IOCD
         BLE      %-2               YES- SKIP IT.
         B        DV2
DV4      STW,13   0,4               MOVE PREV ENTRY UP
         LOAD,2   JX:CMAP,1
         LI,3     0
         LB,4     JB:LMAP,7         NXT LINK
         STB,4    JB:LMAP,1
         STB,3    JB:LMAP,7
         BNEZ     %+4
         AI,1     0
         BLZ      %+4
         STB,1    JB:VLT
         AI,1     0
         BGEZ     %+3
         LI,2     BA(JX:PPH)-BA(MX:PPUT)
         SLS,2    -:BIG
         LOAD,3   JX:CMAP,7
         DISABLE
         CI,3     NPMC
         BNE      %+3
         LI,5     -1
         B        RVNP              RELEASE VIRTUAL, NO PHYSICAL
         LOAD,1   MX:PPUT,3
         STORE,1  MX:PPUT,2         UNLINK
         MTB,-1   JB:PPC            DECR USER PG CNT
RVNP     EQU      %
         STORE,12 JX:CMAP,7         FREE PAGE
*  SET SWAP PURE PROCEDURE FLAG BIT
         LW,4     S:CUN
         MTB,-1   UB:PCT,4
         LH,0     UH:FLG,4
         OR,0     XPPSWAP
         STH,0    UH:FLG,4
         ENABLE
         CI,3     NPMC              DONT RELEASE IF WE DIDN'T GET
         BE       RNVP1             PAGE
         CI,11    7H3               ALSO, DONT RELEASE IF CALLED
         BE       RNVP1             BY T:RVSPI
*  RELEASE PP # TO FREE PG POOL
         BAL,2    T:FPP
RNVP1    EQU      %
*  RELEASE DISC GRANULE
         LI,4     J+JBNRG           INCR NR GRANULES REMAINING IN GROUP
         MTB,1    0,4
         LB,2     0,4
         CI,2     4
         BL       RVP5
         LI,2     0
         STB,2    0,4               CLEAR NR, REMAINING GR.
         MTW,-2   J:CLE             REMOVE SEEK FROM CLIST AND
         LW,1     J:CLE             RETURN GROUP OF FOUR GRANULES
         DW,1     XA                COMPUTE NR OF SEEKS TO GET
         LH,15    JH:DA,1           DISC SEEK ADDRESS TO RETURN.
         BAL,11   T:SGR             SWAPPER GRANULE RELEASE
         LI,4     J+JBNASP
         STB,1    0,4               SET NEXT AVAIL GRAN POSITION
*  TEST WHICH AREA PG IS IN
RVP5     EQU      %
         LI,1     -5
RVP6     CLM,7    WA(DA(J:PLL)+5),1 WHICH AREA IS VP IN
         BCR,9    RVP7
         BIR,1    RVP6
         LI,1     -2                ASSUME CONTEXT
         CW,7     J:PUL
         BLE      RVP7
         CW,7     J:EUP
         BG       %+2
         LI,1     -3                DYNAMIC DATA
*  UPDATE PG CNT FOR APPROPRIATE AREA
RVP7     EQU      %
         AI,1     5                 CONVERT INDEX
         MTB,-1   JB:PCP,1          DECR APPRO PG COUNT
         CI,7     JOVVP-1           WAS A SPARE BUFFER RELEASED
         BLE      GVPB              YES-DONT LOAD MAP NOR ACCESS
*  UPDATE PG CNT TOTAL NEEDED
*  SET UP FOR T:SAC
* I 13 = AC FOR JAC
* I 4 = AC FOR DAC
         B        RVP9
RVP8     LI,11    RVP91
T:SXMAPM3 LW,15   7                 VP #
T:SXMAPM2 LI,12   JX:CMAP           IMAGE ADDRESS
         LI,14    1                 # OF PGS
T:SXMAP  LI,3     0                 INST CODE
         LI,4     :BIG-2            SHIFT CODE
         B        MMCC
         PAGE
*************************************
*        SET VIRTUAL & PHYSICAL     *
*                                   *
*        LINK VP INTO LMAP          *
*        LINK PP INTO PPUT          *
*        SET  PP IN   CMAP          *
*        SET UP NEW CL ENTRY &      *
*        SET UP NEW DA ENTRY        *
*        RIPPLE PP MEM ADR DOWN     *
*************************************
*        1  = NEXT LINK IN LMAP
*        2  = PREV  '   '   '
*   I    3  = PP #
*        4  = INDEX ADR FOR CL & DA TABLE
*   I    7  = VP #
*        12 = ACCUM
*   I    15 = DA
*
IV4      CLM,7    J:PLL
         BCR,9    IV6               VP IS WITHIN LIMITS
IV3      EQU      %
         AI,4     -2                DECR TO NEXT CLIST ENTRY
         CB,13    *4                IS IT A SEEK
         BLE      %-2               IF SO, SKIP IT.
*  KEEP LAST PREV PP #
         LOAD,12  JX:CMAP,1
         CI,12    NPMC
         BE       %+2
         LW,0     12
*  GET A VP LINK FROM LMAP
         LB,2     JB:LMAP,2         SAVE PREV LINK
IV31     LB,1     JB:LMAP,2         GET NXT LINK
         BNEZ     IV32              MORE
         STB,7    JB:VLT            UPDATE TAIL
         B        IV8               NO MORE
IV32     RES      0
*  RIPPE MEM ADRS DOWN IN CL
         LW,12    -2,4              RIPPLE DOWN
         CB,13    12                CHECK ORDER OF PREV ENTRY
         BG       %+2               FOR SEEK
         LW,12    -4,4              SKIP SEEK, GET IOCD PRECEEDING IT
         STW,12   0,4               MOVE DOWN ONE ENTRY
*  IS VP FROM LMAP IN PURE PROCEDURE
         CLM,1    J:PLL
         BCR,9    IV4               YES THIS VP IN CHAIN IS WITHIN LIMIT
*  VP FROM LMAP WAS NOT IN PURE P
*  IS VP REQUESTED IN PURE P - YES, FINISHED - NO, TEST MORE
         CLM,7    J:PLL
         BCR,9    IV8               YES VP REQUESTED IS WITHIN LIMITS
*  BOTH VP FROM LMAP & ONE REQUESTED ARE IN PURE P
*  OR NEITHER ARE
*  IS VP REQUESTED < VP FROM LMAP - YES, FINISHED - NO, GO BACK
IV6      EQU      %
         CW,7     1
         BL       IV3               VP REQ IS > THAN VP IN CHAIN
IV8      EQU      %
*  INSERT VP INTO VIRTUAL LINK MAP
         STB,7    JB:LMAP,2         SET BACK LINK IN LMAP
         STB,1    JB:LMAP,7         LINK TO NEXT IN LMAP
         LW,12    J:VLCS
         CI,12    X'1FF'
         BE       IV88
         CLM,1    J:PLL
         BCR,9    IV82              YES 1
         CLM,12   J:PLL
         BCR,9    IV88              YES 2
IV85     CW,12    1
         BL       IV89
IV88     STW,1    J:VLCS
IV89     LW,12    3                 GET PP #
         AI,12    X'2000'           ADD IN WRITE ORDER
         SLS,12   11                GEN BA OF MEM ADR
         STW,12   0,4               STORE IN CLIST
        CI,3     NPMC
         BE       IV10
*  INSERT PP INTO PPUT CHAIN
         MTB,1    JB:PPC            INCR USER'S PG CNT IN CORE
         CI,2     BA(JB:VLH)-BA(JB:LMAP)  DOES NEW PP GO ON BEG OF CHAIN
         BE       %+3
         LW,4     0
         BNEZ     IV9
         LOAD,12  JX:PPH            YES, GET PREV 1ST PAGE
         STORE,12 MX:PPUT,3         LINK NEW PAGE TO IT
         STORE,3  JX:PPH            PUT NEW PP IN HEAD
         B        IV10
IV82     CLM,12   J:PLL
         BCR,9    IV85              YES 3
         B        IV89              NO 3
         PAGE
*************************************
*        GET PHYSICAL PAGE          *
*************************************
*        2 = LINK REGISTER
*   O    3  = NEXT FREE PHY PAGE
*        4  = FOLLOWING FPP IN CHAIN
*
T:GPP    EQU      %
         DISABLE
         LW,3     M:FPPH            GET CONTENTS OF FREE PG POOL HEAD
         BEZ      GPP1              IF 0, RETURN
         LOAD,4   MX:PPUT,3         GET NEXT PG IN CHAIN
         STW,4    M:FPPH            & PUT PG INTO HEAD
         BNEZ     %+2
         STW,4    M:FPPT            NOTHING IN CHAIN SO CLEAR TAIL
         MTW,-1   M:FPPC            DECR FPP COUNT
GPP1     EQU      %
         ENABLE
         B        0,2
*
*
*************************************
*        FELEASE PHYSICAL PAGE      *
*************************************
*        2 = LINK REGISTER
*   I    3  = PHY PAGE TO RELEASE
*        4  = PREV PG RELEASED
*
T:FPP    EQU      %
         LI,4     JITLOC            LAST MONITOR LOCATION
         SLS,4    -9                LAST MONITOR PAGE
         CW,4     3                 MON PAGE : RELEASING PAGE
         BL       1A1               NOT RELEASING MONITOR PAGE
TFPP1    SCREECH  X'01'             RELEASING MONITOR PG..
1A1      EQU      %
         LI,4     0
         STORE,4  MX:PPUT,3         0 TO END CHAIN
         DISABLE
         LW,4     M:FPPT            GET LAST PG
         BNEZ     RPP2              THERE WAS ONE
         STW,3    M:FPPH            SET HEAD OF CHAIN
         B        RPP2+1            AVOID LINKING TO ZERO
RPP2     EQU      %
         STORE,3  MX:PPUT,4         LINK TO PREV PP
         STW,3    M:FPPT            SET TAIL
         MTW,1    M:FPPC            INCR FPP COUNT
         B        GPP1
************
*THE PAGE STEALER
************
         DEF      T:STLPP,T:RSPP,T:RSPPEA,INCSTL
         REF      S:ACORE,S:STL#,S:STLC,SL:STLM,SL:RSVP
         REF      ENBSR4
************
T:STLPP  EQU      %                 STEAL A PHYSICAL PAGE
         DISABLE                    :
         LW,1     S:STL#            THIS ROUTINE IS CALLED BY THOSE MONITOR
         SW,1     SL:RSVP           FUNCTIONS THAT WISH TO 'BORROW' PHYSICAL
         BLZ      STL               PAGES FOR SHORT PERIODS OF TIME BUT WILL
         CW,1     S:STLC            RELEASE THEM WHEN THEY ARE NEEDED TO RUN
         BL       STL               USERS.  THE RELEVANT DATA CELLS ARE:
         ENABLE                     :
         LI,3     -1                SL:RSVP - THE NUMBER OF PAGES HELD BACK
         B        *11                         FOR THOSE WHO STEAL BUT CANNOT
STL      EQU      %                           RETURN THEM ON DEMAND.  THESE
         LW,3     M:FPPH                      PAGES ARE NOT INCLUDED IN SL:CORE
         BEZ      ENBSR4            :
         LOAD,4   MX:PPUT,3         SL:STLM - THE MAXIMUM NUMBER OF PAGES THAT
         STW,4    M:FPPH                      MAY BE STOLEN BEYOND SL:RSVP
         BNEZ     %+2               :
         STW,4    M:FPPT            S:STLC  - THE NUMBER OF PAGES CURRENTLY
         MTW,-1   M:FPPC                      'STEALABLE' BEYOND SL:RSVP.  THIS
         MTW,1    S:STL#                      NUMBER GOES NEGATIVE WHEN THE
         SLS,3    9                           SWAP SCHEDULER NEEDS THE STOLEN
         AI,1     0                           PAGES.
         BLZ      ENBSR4            :
         MTW,-1   S:ACORE           S:STL#  - THE NUMBER OF STOLEN PAGES
         B        ENBSR4                      (INCLUDES SL:RSVP)
*                                   :
*                                   --------------------------------------------
T:RSPPEA LW,3     14                RETURN A STOLEN PP (ADDR IN R14 FOR END ACTI
T:RSPP   EQU      %                 RETURN A STOLEN PP (ADDR IN R3)
         CI,3     JITLOC
         BLE      TFPP1
         SLS,3    -9                ============================================
         LI,4     0                 S:ACORE - IS THE CURRENT AVAILABLE SWAPPING
         STORE,4  MX:PPUT,3                   CORE. IT IS LESS THAN SL:CORE BY
         DISABLE                              THE NUMBER OF PAGES STOLEN BEYOND
         LW,4     M:FPPT                      SL:RSVP.
         BNEZ     %+3               :
         STW,3    M:FPPH            :
         B        %+2               ONLY ROUTINES ABLE TO GIVE BACK THEIR
         STORE,3  MX:PPUT,4         STOLEN PAGES SHOULD CALL T:STLPP UNLESS
         STW,3    M:FPPT            THEIR PAGES HAVE BEEN RESERVED IN SL:RSVP
         MTW,1    M:FPPC            :
         LW,3     S:STL#            :
         AI,3     -1                UPON RETURN FROM T:STLPP
         STW,3    S:STL#            :
         SW,3     SL:RSVP           R3 = -1  -> NO PAGES MAY BE STOLEN AT THIS
         BLZ      ENBSR4                        TIME. (THE SWAPPER IS SHORT)
         MTW,1    S:ACORE           :
         LW,3     S:STLC            R3 = 0   -> THERE ARE CURRENTLY NO FREE
INCSTL   EQU      %                             MONITOR PAGES - TRY AGAIN
         CW,3     SL:STLM                       LATER.
         BGE      ENBSR4            :
         MTW,1    S:STLC            R3 > 0   -> HERE'S THE WA OF YOUR PAGE.
         B        ENBSR4            :
*********                           (INCSTL IS CALLED BY CLOCK4)
**********                          :
         PAGE
*
M:GAM1   EQU      MB:GAM1
M:GAM2   EQU      MB:GAM2
M:GAM3   EQU      MB:GAM3
M:GAM4   EQU      MB:GAM4
M:GAM5   EQU      MB:GAM5
M:GAM6   EQU      MB:GAM6
M:DWT    EQU      MB:DWT
M:GPT    EQU      MB:GPT
M:SWAPS  EQU      MB:SWAPS
*
************************************************************************
* INPUT: DESIRED GRANULE NO. (0-40 FOR 7212, 0-5 FOR 7232) IN REG 1    *
* OUTPUT: TRACK/SECTOR RIGHT ADJUSTED TO P31 IN REG 15                 *
* REGISTERS USED: 2, 12, 13, 14, 15                                    *
*         CC3 SET TO 0 IF ALLOCATION MADE, 1 IF NOT MADE               *
*                                                                      *
* THE FOLLOWING TABLE SHOWS THE VALUES OF CERTAIN SYSGEN DATA ACCORDING*
* TO THE TYPE OF RAD USED FOR SWAPPING.                                *
*                                                                      *
*                                                                      *
*                FULL    1/4    1/2   FULL                             *
*                7212   7232   7232   7232                             *
*                                                                      *
*      M:GAM1     63      7      7      7                              *
*      M:GAM2      1      3      7     15                              *
*      M:GAM3     -1     -2     -3     -4                              *
*      M:GAM4      6      3      3      3                              *
*      M:GPT      41      6      6      6                              *
*      M:SWAPS     0      1      2      3                              *
*      M:DWT      41     12     24     48                              *
*                    *THE ABOVE ARE ALL BYTE VALUES                    *
*                                                                      *
*                                                                      *
* M:SGP CONTAINS THE ADDRESS OF THE GRANULE ALLOCATION TABLE.          *
* M:SBAND CONTAINS THE TRACK/SECTOR ORIGIN OF THE SWAP AREA ON DISC    *
************************************************************************
************************************************************************
T:SGA    EQU      %
         LW,2     S:CUN
         LB,2     UB:SWAPI,2
*  THIS ENTRY FOR GETTING JIT FIRST TIME
T:SGAJIT EQU      %
         LI,15    2                 GET DUMMY ADDRESS, THEN
         MTW,0    S:DP              TEST FOR DISK PACK SWAPPING
         BNEZ     SGA10             IF YES DON'T ALLOCATE
************************************************************************
*MAKE GRANULE POSITION MODULAR (SECTORS/TRACK)                         *
************************************************************************
         LB,12    M:GAM1,2          *GET EXTRACT MASK
         LB,14    M:GPT,2           *GET GRANULE SIZE
         AND,1    12                *MAKE GRANULE POSITION LESS THAN 64
*                                     FOR 7212, LESS THAN 8 FOR 7232
         CW,1     14                *COMPARE AGAINST GRANULES PER TRACK
         BL       SGA1              *SKIP IF OK
         SW,1     14                *FORCE TO A LEGAL VALUE IF TOO BIG
************************************************************************
*INITIALIZE FOR TABLE SEARCH                                           *
************************************************************************
SGA1     EQU      %
         LD,12    DOUBLEZERO        *ZERO 12 AND 13
         LB,14    M:SWAPS,2         *GET SHIFT VALUE
         SLS,1    *14               *GIVES DBLWD INDEX OF GRAN REQUESTED
         LB,14    M:DWT,2           *GET NO. OF DBLWDS IN GRANULE TABLE
         LW,15    M:SGP,2           *GET ADDRESS OF GRANULE TABLE
************************************************************************
* SEARCH TABLE FOR AVAILABLE TRACK (0 BIT MEANS NOT AVAILABLE, 1 BIT   *
* MEANS AVAILABLE).  START WITH THE GRANULE REQUESTED.                 *
************************************************************************
SGA2     EQU      %
         CD,12    *15,1             *IS THERE A TRACK AVAILABLE IN DBLWD
         BNE      SGA4              *IF YES, SKIP
         AI,1     1                 *NO.  INCREMENT DBLWD INDEX.
         CB,1     M:DWT,2           *ARE WE AT THE END OF THE TABLE
         BL       SGA3              *IF NOT, SKIP
         LI,1     0                 *YES.  RESET DBLWD INDEX.
SGA3     EQU      %
         BDR,14   SGA2              *LOOP IF ENTIRE TABLE NOT EXAMINED
         B        SGRBAD            TABLE FULL
************************************************************************
*EXAMINE THE DOUBLEWORD TABLE ENTRY TO GET THE NON-ZERO WORD           *
************************************************************************
SGA4     EQU      %
         SLS,1    1                 *MAKE A WORD INDEX OF THE DBLWD INDX
         CW,12    *15,1             *DOES THE FIRST HALF HAVE A FREE TRK
         BNE      SGA5              *IF YES, SKIP
         AI,1     1                 *NO, INCREMENT THE WORD INDEX
SGA5     EQU      %
         XW,12    *15,1             *BRING ENTRY.  SET TABLE TO ZERO TO
*                                    PREVENT REENTRANCE FROM USING DATA
*                                    TO GET A GRANULE.
         BNEZ     SGA6              *SKIP IF WE STILL HAVE A TRACK.
*                                    REENTRANCE COULD HAVE RESET THE BIT
         SLS,1    -1                *TRACK IS GONE, RESTORE DBLWD INDEX
         B        SGA2              *LOOP TO CONTINUE SEARCH
************************************************************************
*COMPUTE THE BIT POSITION OF THE LEAST SIGNIFICANT 1-BIT IN THE TABLE  *
*                                                                 ENTRY*
************************************************************************
SGA6     EQU      %
         STW,2    14                *SAVE SWAP INDEX
         LI,2     5                 *SET LOOP INDEX
         LI,15    0                 *CLEAR BIT POSITION VALUE
         LCW,13   12                *SET ALL BITS OF GRANULE ALLOCATION
         AND,13   12                 WORD TO ZERO EXCEPT LEAST SIG BIT
SGA8     EQU      %
         CW,13    MASKHAF,2         *IS BIT IN BOTTOM HALF OF DIVISION?
         BCS,4    SGA9              *IF YES, SKIP
         AH,15    POSITION,2        *NO, ADD NO. OF BITS IN DIVISION
SGA9     EQU      %
         BDR,2    SGA8              *LOOP UNTIL CONVERSION COMPLETE
         EOR,13   12                *RESET FOUND BIT
         LW,2     14                *BRING BACK SWAP INDEX
         LW,14    M:SGP,2           *GET GRANULE TABLE ADDRESS
         STS,13   *14,1             *MERGE RESULT BACK INTO GRANULE
*                                    ALLOCATION TABLE.  MERGING PRESERVS
*                                    ANY TRACK BITS SET BY REENTRANCE.
************************************************************************
*COMPUTE THE TRACK/SECTOR ADDRESS OF THE ALLOCATED GRANULE             *
************************************************************************
         LB,14    M:GAM2,2          *GET MASK
         LB,12    M:GAM3,2          *GET SHIFT VALUE
         AND,14   1                 *EXTRACT HIGH ORDER TRACK BITS
         SLS,1    *12               *SHIFT GRANULE NO. TO P31
         LW,12    M:SBAND,2         *GET DISC ADDRESS OF SWAPPING AREA
         SLS,14   5                 *SHIFT HIGH ORDER TRACK BITS UP
         PUSH     2
         LB,2     M:GAM4,2          *GET SHIFT VALUE
         SLD,14   0,2               *POSITION ALL TRACK BITS FOR IO
         PULL     2
         AW,15    14                *COMBINE HIGH AND LOW ORDER TRACKS
         AW,15    1                 *ADD GRANULE NO.
         SLS,15   1                 *SHIFT UP TO GIVE TRACK/SECTOR ADDR
         AW,15    12                *ADD SWAPPING AREA ORIGIN
         CB,15    MB:GAM7,2         *CHECK FOR ODD TRACK ON
         BAZ      %+2               *DEVICE WITH ODD SECTOR/TRACK
         AI,15    1                 *AND MAKE SECTOR ADDRESS ODD
SGA10    EQU      %
         MTW,-4   M:FREE#GRAN,2
         B        SGR1              NORMAL EXIT
         PAGE
************************************************************************
* INPUT: TRACK/SECTOR ADDRESS OF GRANULE TO BE RELEASED IN REGISTER 15 *
* OUTPUT: RELEASED GRANULE NO. IN REGISTER 1                           *
* REGISTERS USED: 2, 12, 13                                            *
*         CC3 SET TO 0 IF GRANULE RELEASED                             *
*         CC3 SET TO 1 IF GRANULE ALREADY RELEASED OR IF TRACK/SECTOR  *
*              INPUT LOOKS BAS                                         *
* THE FOLLOWING TABLE SHOWS THE VALUES OF CERTAIN SYSGEN DATA ACCORDING*
*      TO THE TYPE OF RAD USED FOR SWAQQING.                           *
*                                                                      *
*                                                                      *
*                FULL    1/4    1/2   FULL                             *
*                7212   7232   7232   7232                             *
*                                                                      *
*      M:GAM3      -1     -2     -3     -4                             *
*      M:GAM5      -7     -4     -4     -4                             *
*      M:GAM6     127     15     15     15                             *
*      M:GATLIM    63    127    255    511                             *
*            *M:GAM3,M:GAM5, M:GAM6 AND M:SWAPS ARE BYTE VALUES        *
*                                                                      *
* M:SGP CONTAINS THE ADDRESS OF THE GRANULE ALLOCATION TABLE           *
* M:SBAND CONTAINS THE TRACK/SECTOR ORIGIN OF THE SWAP AREA ON DISC    *
************************************************************************
************************************************************************
T:SGR    EQU      %                 *
         LW,2     S:CUN
         LB,2     UB:SWAPI,2
T:SGRNU  EQU      %
         DEF      T:SGRNU
         MTW,0    S:DP              TEST FOR DISK PACK SWAPPING
         BNEZ     SGR0              IF YES DON'T RELEASE
************************************************************************
* POSITION A BIT P0 THROUGH P31 CORRESPONDING TO THE LOW ORDER TRACKS  *
* 31 THROUGH 0 DERIVED FROM THE FULL TRACK/SECTOR ADDRESS.  THIS BIT   *
* WILL BE MERGED INTO THE PROPER ENTRY IN THE GRANULE ALLOCATION TABLE.*
************************************************************************
         SW,15    M:SBAND,2         *SUBTRACT SWAP AREA DISC ADDRESS
         BLZ      SGRBAD            *EXIT IF DISC ADDRESS BELOW ORIGIN
         AND,15   MINUS2            *FORCE EVEN SECTOR NUMBER
         LB,12    M:GAM5,2          *GET SHIFT VALUE
         LW,1     15                *
         SLS,1    *12               *SHIFT TRACK TO P31
         CW,1     M:GATLIM,2        *COMPARE TRACK AGAINST UPPER LIMIT
         BG       SGRBAD            *EXIT IF OVER UPPER LIMIT
         LB,13    MB:SPT,2          *#SECTORS/TRACK
         MW,13    1                 *  X TRACK NR.
         AI,13    1
         LB,12    M:GAM6,2          *
         AND,12   15                *SECTOR NUMBER
         AW,13    12
         CB,15    MB:GAM7,2         *
         BAZ      %+2               *
         AI,12    1                 *INC SECTOR NR. IF ODD TRK
         CW,12    M:GASLIM,2        *COMPARE SECTOR AGAINST UPPER LIMIT.
         BG       SGRBAD            *EXIT IF OVER UPPER LIMIT.
         SLS,13   -1                *GRANULE NR RELATIVE BEGIN RAD
         CI,13    3                 *
         BANZ     SGR1+1            *EXIT IF NOT A MULTIPLE OF FOUR.
         LB,12    M:GAM5,2          *GET SHIFT VALUE.
         AND,1    M5                *EXTRACT TRACK NO. MODULO 32
         LI,13    1                 *POSITION A 1 BIT CORRESPONDING
         SLS,13   0,1               *     TO THE LOW ORDER TRACK NO.
************************************************************************
* COMPUTE THE GRANULE TABLE INDEX AND SET THE GRANULE BIT              *
************************************************************************
         AI,12    -5                *INCREASE THE SHIFT VALUE
         LW,1     15                *
         SLS,1    *12               *SHIFT THE HIGH ORDER TRACKS TO P31
         XW,1     15                *
         LB,12    M:GAM6,2          *GET EXTRACT MASK
         AND,1    12                *EXTRACT THE SECTOR NO.
         LB,12    M:SWAPS,2         *GET SHIFT VALUE
         SLS,1    *12               *CONVERT SECTOR NO. TO GRANULE INDEX
         AW,1     15                *ADD TRACK GROUP NO.  THE RESULT IS
*                                    THE GRANULE TABLE WORD INDEX
         LW,12    M:SGP,2           *GET THE GRANULE TABLE ADDRESS
         CW,13    *12,1             *IS THE GRANULE ALREADY FREE?
         BAZ      SGR0              *SKIP IF GRANULE STILL IN USE
SGRBAD   LCI      1                 *SET CC4
         B       *11                *EXIT
SGR0     EQU      %                 *
         MTW,4    M:FREE#GRAN,2
         MTW,0    S:DP              TEST FOR DISK PACK SWAPPINT
         BNEZ     SGR0A               YES
         STS,13   *12,1             *MERGE BIT INTO GRANULE TABLE
         LB,12    M:GAM3,2          *GET SHIFT CONSTANT
         SLS,1    *12               *SHIFT TABLE INDEX TO GET GRAN NO.
SGR0A    EQU      %
         PUSH     16,0
         LI,6     E:DPA
         BAL,11   T:RE
         PULL     16,0
SGR1     EQU      %                 *
         LCI      0                 *RESET CC3
         B       *11                *EXIT
         PAGE
RVP9     LI,4     3                 JAV AC
         LI,2     RVP8
*  SET AC  -  ACCESS CONTROL
*
*  THE VP# IS DIVIDED BY 4 TO OBTAIN A DISPLACEMENT OF THE APPRO
*  BYTE IN THE IMAGE AND THE POSITION OF THE DOUBLE BIT TO BE SET
*  WITHIN THAT BYTE.  THE POS OF THE DBL BIT IS USED AS AN INDEX
*  TO GET THE APPRO MASK (1) CONTAINING ONES IN THAT DBL BIT POS.
*  THE AC TO SET IS USED AS AN INDEX TO GET A BYTE (2) CONTAINING
*  THE AC IN ALL DBL BIT POS.  THE BYTE IS PULLED FROM THE IMAGE (3).
*  THE AC IS SET INTO THE BYTE BY A SELECTIVE STORE (4) AND THE
*  UPDATED BYTE IS STORED BACK INTO THE IMAGE (5).
*
*        FOLLOWING EXAMPLE SHOWS RESULTS OF SETTING 01 AC IN VP#10 MOD16
*
*                                   ---------------
*                             REG8  | 01 01 01 01 |  (2)
*                                   ---------------
*                                   ---------------
*                             REG9  | 00 00 11 00 |  (1)
*                                   ---------------
*                                           ||
*                                     STORE VV SELECTIVE (4)
*                                   ---------------
*                        |--> REG15 | XX XX 01 XX |
*                        |          ---------------
*                        |(3)        STORE |  (5)
*                        |---------------| |
*                                        | V
*        --------------------------------------------------------
*        |            |             | XX XX 01 XX |             |
*        --------------------------------------------------------
*                  WORD IN IMAGE CONTAINING AC TO CHANGE
         PAGE
*        2 = LINK REGISTER WHICH IS ALTERED BY BIR AT SAC2-2
*  I     7   = VP#
*        12 = JAC ADR (IMAGE)
*  I     4  = AC FOR JAC  (IN LOW 2 BITS)
*        3  - ADR INDEXING
*        15 = AC IMAGE BYTE
T:SAC    EQU      %
         AI,2     X'80000'          NOT SMP CALL
T:SACP1  RES      0                 T:SMP ENTRY POINT
         AND,4    M2
         LI,3     3
         AND,3    7                 DBL BIT POSN IN BYTE
         LB,13    SACBP,3           MASK FOR DBL BIT POS IN BYTE
         LW,3     7
         SLS,3    -2                BYTE DISP
         LB,15    J:JAC,3           APPROPRIATE BYTE FROM IMAGE
         BIR,2    SAC4              BRANCH IF NOT SMP
         LI,3     -4
SAC2     LB,12    SACACC+1,3        GET AN AC IN ALL BITS OF BYTE TIL
         CS,12    15                ONE COMPARES WITH AC IN USERIMAGE
         BE       %+2
         BIR,3    SAC2
         CB,12    SACACC,4          COMP CANDIDATE WITH EXISTING
         BLE      SAC4M             GO SET IT
         LI,3     -5
         CLM,7    WA(DA(J:PLL)+5),3 DETERMINE WHICH AREA VP IS IN
         BCR,9    SAC3
         BIR,3    %-2
         LI,3     -2
         CW,7     J:PUL
         BLE      SAC3
         CW,7     J:EUP
         BG       SAC3
         LI,3     -3
SAC3     AI,3     5                 CONVERT INDEX
         LB,3     UACT,3
         LB,3     SACACC,3          GET AREA AC INTO ALL OF BYTE
         CB,3     SACACC,4          COMP CAND WITH MIN FOR AREA
         BG       SAC6              DON'T SET
SAC4M    LW,3     7
         SLS,3    -2                BYTE DISP
SAC4     LB,12    SACACC,4          NEW AC
         STS,12   15                STORE AC INTO BYTE
         STB,15   J:JAC,3           PUT BYTE INTO IMAGE
SAC6     B        -1,2              RETURN - BIR HAS INCREMENTED
         PAGE
*  SET UP AND EXECUTE MMC FOR MAP & AC
*
*  ENTER T:SXMAP OR T:SXAC
*  EACH USES T:SMMC TO SET UP REGS FOR MMC INST
*  THEN EXECUTES APPROP MMC INST
*        12 = IMAGE ADR       A
*        14 = # OF PGS        N
*        15 = STARTING VP #   P
*        11 = EXIT
*        11 = EXIT
*        13 - SUBRT LINK
*        3  - INST CODE
*        4  - SHIFT CODE
*
*  14=                                               A+(P/X)
*        0                             15                             31
*                                                IMAGE ADDRESS
*
*  15=    ((N-1+P)/X)-(P/X)+1             (&/X)*X
*        0                   7         15         22                  31
*                COUNT                 START CONTROL
*
*
*        REGISTERS 4,12,14,15 GET (SOMEWHAT PREDICTABLY) CLOBBERED.
*
RVP91    LI,11    GVPB
T:SXACM3 LI,12    J:JAC
         LI,14    1
         LW,15    7
T:SXAC   EQU      %
         LI,3     1                 INST CODE
         LI,4     -4                SHIFT CODE
MMCC     EQU      %
GVPA     EQU      T:SXAC-2
T:SMMC   EQU      %
         AI,14    -1     14= N-1
         AW,14    15            +P
         SLD,14   0,4             /X             15= P/X
         SW,14    15                -(P/X)
         AI,14    1                       +1
         AW,12    15     12= A+(P/X)
         LCW,4    4
         SLS,15   9,4                            15= (P/X)*X  SHIFTED 9
         STB,14   15     15= ((N-1+P)/X)-(P/X)+1     (P/X)*X
         LW,14    M22
         REF      M22
         AND,14   12
         EXU      MMCI,3
*        DOES SPECIAL PROCESSOR WANT SJAC
         LW,4     S:CUN
         LH,15    UH:FLG,4
         CI,15    SJAC
         BAZ      *11               NOPE, EXIT
*        LOAD CANNED AC FOR SPECIAL...
*                 PROCESSOR JIT AC(AND BUFFER CONTEXT AC).
         LI,14    SPJITAC           'CANNED IMAGE' ADDR.
         LW,15    SPJACTRL          COUNT AND START STUFF
         LPC,14   0                 ACCESS TO MACHINE INTERNALS
*
*        NOTE:
*        ASSUME 'SJAC PEOPLE' ARE SIGNIFICANTLY RARER THAN 'NOT
*        SJAC PEOPLE'.  IT IS THEN CHEAPER BOTH BY CODE SIZE AND SPEED
*        TO CHECK FOR EM AND ALWAYS RELOAD THAN TO CHECK THE AFFECTED
*        PAGE AND NOT.  SJAC PAGES HAVE AS HI IF NOT HIGHER MM FREQ-
*        UENCY THAN NON-SJAC PAGES, TYPICALLY.
*
*        ALSO NOTE:  J:JAC DOESN'T REFLECT SJAC, THIS IS CHEAP THOUGH
*        MAYBE NOT EASY TO TROUBLE-SHOOT(I.E. THE TRACKS LEFT ARE NOT
*        'ANLZ'-ABLE).
*
         B        *11
MMCI     EQU      %
         LDMAP,14 0
         LPC,14   0
*
T:XMMC   EQU      %
*        EXECUTE MMC - FOR MAP & AC BEFORE RUNNING USER
*  SET UP % EXECUTE MAP
         LW,2     4
         LOAD,12  UX:JIT,2
         SLS,12   9
         PUSH     11
         LW,13    12
         AI,12    JCMAP
         LI,14    256-JOVVP
         LI,15    JOVVP
         BAL,11   T:SXMAP
*  SET UP & EXECUTE APROPOS AC - JAC OR DAC
         LW,12    13
         AI,12    JJAC
         LH,0     UH:FLG,2
         LI,14    256-JOVVP
         LI,15    JOVVP
         BAL,11   T:SXAC
*        T:SXAC NOW DOES SJAC STUFF (7 FOR 5 GROSS +2 WORDS,
*                   NET THIS UPDATE -13-17+2=-18 WORDS,RJR).
         DO       0                 T:SXAC(SJAC)
*  TEST WHETHER SPECIAL PROCESSOR NEEDS JIT ACCESS
         CI,0     SJAC
         BAZ      XMMC5
*  LOAD UP CANNED AC WD FOR SPECIAL PROCESSOR JIT AC
         LI,14    SPJITAC           IMAGE ADR - CANNED IMAGE
         LW,15    SPJACTRL          COUNT AND START CONTROL
         LPC,14   0
         FIN                        T:SXAC(SJAC)
XMMC5    EQU      %
         PULL     11
         B        *11
         SPACE    5
         PAGE
         DEF      T:XMMC1
T:XMMC1  PUSH     1
         BAL,1    UNMAP
         BAL,11   T:XMMC
         BAL,1    MAP
         PULL     1
         B        0,1
         PAGE
*************************************
*        PROCESSOR ACCESS CONTROL   *
*************************************
*        OR PERRY'S ACCESS CODE
*        0  = USERS FLAGS
*        1  = CURRENT USER #
*        2  = AC WORD FOR APPRO PROC
*        4  = APPRO PROC #
*
T:PAC    EQU      %
         LW,1     J:EUP             DONT SET AC IF USER HAS ALL
         CI,1     JEUPVP              OF CORE
         BNE      *11
         LW,1     S:CUN
         LH,0     UH:FLG,1
         LB,4     UB:ACP,1          GET COMMAND PROC #
         CI,0     TIC
         BANZ     PAC4
         LB,4     UB:ASP,1
         CI,0     DIC
         BAZ      PAC4
         LB,4     UB:DB,1
PAC4     EQU      %
         LD,2     P:AC,4            PROC AC DBWD
         LCI      2
         STM,2    J:JAC+14
         LD,14    PXAC              14=I4AGE 15=# OF 2 & START CONTROL
         LPC,14   0
         B        *11
         PAGE
T:GNVNPI PUSH     7,5
         LI,5     -1
         LW,12    6
         PUSH     2,6               SAVE # PAGES AND PAGE#
         STW,12   9                 #DCB AND DATA PAGES
         LI,1     BA(JB:NRG)
         LB,1     0,1
         LCW,1    1
         AW,1    12                 #PAGES-#REMAINING GRANS
         AI,1     3
         DW,1     X4                #SEEKS REQ'D
         AW,12    1
         SLS,12   1
         AW,12    J:CLE             NEW CLIST LENGTH
         BAL,0    T:GAJP
         LW,4     S:CUN
         LB,2     UB:SWAPI,4
         CW,9     M:FREE#GRAN,2
         BL       %+4
         LI,6     E:ND
         BAL,11   T:REG
         B        %-4
         PULL     2,6               RESTORE # OF PAGES AND PAGE #
         B        GNV2
         PAGE
T:GAJP   EQU      %
*  TEST WHETHER AJIT NEEDED
         CI,12    JCCL
         BL       AJPO
*  AJIT PRESENT OR NEEDED
         LW,13    J:AJ
         BNEZ     AJPO
         LW,1     S:CUN             AJIT NEEDED
         MTB,1    UB:PCT,1          UPDATE USERS TOTAL PGS NEEDED CNT
         BAL,2    T:GPP
         LI,2     JAJITVP
         AI,3     0
         BE       GAJ6              NO PP AVAIL
*  PP AVAIL - PUT IN CMAP AND LINK INTO PPUT
         STORE,3  JX:CMAP,2
*  LINK INTO PPUT
         LI,4     JJITVP
         LOAD,12  JX:CMAP,4         JIT PP
         COMPARE,12 JX:PPH          HEAD OF PP CHAIN
         BNE      AJP5-1
         STORE,3  JX:PPH            YES, PUT AJIT AS HEAD
         B        AJP6              AND GO TO LINK AJIT TO JIT
         LOAD,4   JX:PPH
AJP5     EQU      %
         COMPARE,12 MX:PPUT,4
         BE       %+3               FOUND PP END
         LOAD,4   MX:PPUT,4
         B        AJP5
         STORE,3  MX:PPUT,4         LINK LAST PP TO AJIT PP
AJP6     EQU      %
         STORE,12 MX:PPUT,3         LINK AJIT PP TO JIT PP
         MTB,1    JB:PPC            UPDATE PP CNT
*  DO MMC ON MAP IN ORDER TO ACCESS AJIT PG
         LW,15    2                 AJIT VP #
         LI,11    GAJ8
         B        T:SXMAPM2
*  NO PP AVAIL -  DO T:REG WHICH RESULTS IN EXECUTING SWAP LOGIC,
*  WHICH GETS PP, LINKS TO PPUT & PUTS PP IN CMAP - WHEN PP AVAIL.
GAJ6     EQU      %
         LI,12    NPMC
         STORE,12 JX:CMAP,2
         LH,12    UH:FLG,1
         AND,12   NREADY
         STH,12   UH:FLG,1
         LI,6     E:NC
         BAL,11   T:REG             REPORT NO CORE AND GIVE UP
         OR,12    X1
         STH,12   UH:FLG,1
*  FOLLOWING IS COMMON TO BOTH - PP & NO PP
GAJ8     EQU      %
*  INCR CONTEXT AREA CNT
         LI,4     3                 CONTEXT
         MTB,1    JB:PCP,4
*  SET IN JIT - J:AJ (AJIT PP #) & J:CLPA (PHY ADR OF CL)
         LOAD,3   JX:CMAP,2
         STW,3    J:AJ
         SLS,3    9
         STW,3    J:CLPA
*   PUT JIT ON 2ND GRANULE AND AJIT ON 1ST OF GROUP.
         LH,14    UH:JIT,1
         STH,14   UH:AJIT,1
         LB,4     UB:SWAPI,1
         LB,15    MB:GAM6,4
         CS,14    M:GASLIM,4
         BNE      %+2
         AW,14    M:ADRINCR,4
         AI,14    2
         STH,14   UH:JIT,1
*        FILL UP AJIT WITH CLIST
         LCI      4
         LM,12    J:CL
         AND,14   YFF
         LI,4     -255
AJP9     STD,12   J:AJIT+510,4      STORE SEEK IOCD
         LI,3     4
         AI,4     1
         STD,14   J:AJIT+510,4      FOLLOWED BY FOUR WRITE IOCDS.
         BDR,3    %-2
         AI,12    2                 INC PTR TO JH:DA
         BIR,4    AJP9
*        MOVE OLD CLIST FROM JIT TO AJIT
         LW,4     J:CLE
         SLS,4    2
         LI,1     BA(J:AJIT)
         STB,4    1                 NR. BYTES IN CLIST
         MBS,1    BA(J:CL)-BA(J:AJIT)
         CI,4     X'FF'
         BLE      %+3
         AW,1     YFF
         MBS,1    BA(J:CL)-BA(J:AJIT)
AJPO     RES      0
         B        *0                RETURN
         PAGE
         DO       0
         DEF      T:SPGVI
T:SPGVI  BAL,2    T:GPP
         CI,3     0
         BNE      T:XPGVI
         PUSH     6
         PUSH     11
         LI,3     NPMC
         MTB,-1   JB:PPC
         CW,7     J:VLCS
         BG       %+3
         STW,7    J:VLCS
         MTW,-1   J:VLCS
         BAL,11   T:XPGVI
SPGV1    LW,6     S:CUN
         LH,11    UH:FLG,6
         OR,11    XPPSWAP
         AND,11   NREADY
         STH,11   UH:FLG,6
         LI,6     E:NC
         BAL,11   T:REG
         PULL     11
         PULL     6
*
         FIN
*
T:XPGVI  LI,4     J:AJIT
         LW,1     J:AJ              DO WE HAVE AJIT
         BNEZ     %+2
         LI,4     J:CL              NO
         AW,4     J:CLE
         LI,2     3                 CODE FOR SEEK
         LI,1     BA(JB:VLH)-BA(JB:LMAP)
XPGV1    AI,4     -2
         CB,2     *4                CHECK FOR SEEK
         BLE      %-2               YES, SKIP IT
         CB,7     JB:LMAP,1
         BE       XPGV2
         LB,1     JB:LMAP,1
         BNEZ     XPGV1
         SCREECH  X'01'
XPGV2    STORE,3  JX:CMAP,7
         LW,14    3                 GET PAGE NUMBER
         LI,15    X'1FFF'           13 BIT MASK FOR PAGE
         SLD,14   11                POSITION
         STS,14   0,4               AND STORE IN CLIST
         CI,3     NPMC
         BNE      %+3
         LB,3     JB:LMAP,7         SKIP CUR PAGE IN CHAIN
         LOAD,3   JX:CMAP,3         IF WE DON'T HAVE ANOTHER.
         CI,1     BA(JB:VLH)-BA(JB:LMAP)
         BNE      %+3
         STORE,3  JX:PPH            NEW HEAD
         B        %+3
         LOAD,1   JX:CMAP,1         PREV PP IN CHAIN
         STORE,3  MX:PPUT,1
         DO       0
         CI,11    SPGV1
         BE       SPGV1             DONE FOR NOW IF NO PAGE AVAIL
         FIN
         LB,1     JB:LMAP,7         VP OF NEXT PP IN CHAIN
         BEZ      XPGV4             * NONE- MUST BE LAST
         LOAD,1   JX:CMAP,1         PP OF NEXT PP IN CHAIN.
XPGV3    EQU      %                 * GAURENTEED NEXT PP # IN 1
         STORE,1 MX:PPUT,3          LINK TO NEW PAGE.
         B         *11
*
XPGV4    EQU      %                 * NEXT PPUT IS AJIT OR JIT
         LW,1     J:AJ              * IS AJIT THERE
         BNEZ     XPGV3             *  YEP-USE IT
         LW,1     S:CUN             * NO GO TO USER TABLE
         LOAD,1   UX:JIT,1          * FOR JIT VP #
         B        XPGV3             *  FOR PPUT FLINK
*
         PAGE
*
* SPARE BUFFER MEMORY MANGEMENT ROUTINES
*
T:GBUF   EQU      %
         PUSH     2                 SAVE RETURN
         PUSH     6                 SAVE DCB ADDRESS
         LB,1     JB:FBUL
         AI,1     -JXBUFVP+1        MAX # OF FPOOLS
         SLS,14   -9                PAGE # IN WINDOW
         CI,14    JCOVP             FPOOL OR CPOOL WINDOW
         BL       GETFPOOL          FPOOL
GETCPOOL LCW,1    1
         AI,1     JOVVP-JXBUFVP     MAX # OF CPOOLS
         CI,1     9                 9 IS MOST EVER NEEDED
         BLE      %+2
         LI,1     9                 SO SET MAX# = 9
         LI,7     JOVVP-1           CPOOL SPARE UL
* GET A FREE PAGE FROM THE SPARE BUF AREA: R7=UL OF SPARES TO SEARCH
*                                          R1=# FPOOLS/CPOOLS ALLOWED
GETSPARE LI,12    FPMC              LOOK FOR ONE NEVER USED
         COMPARE,12 JX:CMAP,7          IN SPARE BUFFER AREA
         BE       GOTSPARE          FOUND ONE
         AI,7     -1                LOOK AT NEXT LOWER VIRTUAL PAGE
         BDR,1    %-3                  UP TO MAX ALLOWED
NOBUF    EQU      %
         CI,14    JSBUF2VP          ATTEMPTING TO GET SPEC BUFFER
         BG       NOBUF2            NO-INDICATE NONE AVAILABLE
         PUSH     14                SAVE WINDOW VP
         LI,6     0                 CAUSE SPECIAL TRUNCATION
         BAL,0    GETSBUF           GETSBUF WILL SAVE R1
         PULL     14                RESTORE WINDOW VP
         B        GETFPOOL          ONE WILL BE AVAILABLE
NOBUF3   PULL     14
NOBUF2   LI,10    0                 NO BUFFER
         SLS,14   9                 RESTORE R14
BUFFEXIT EQU      %
         ENABLE
         PULL     6                 RESTORE DCB ADDR
BUFFXIT2 PULL     2                 RESTORE RETURN ADDR
         B        0,2               EXIT
* GET THE SPARE VIRTUAL PAGE: R7=PAGE # IN SPARES
GOTSPARE EQU      %
         LI,5     0                 INDICATE GET PHYSICAL PAGE
         PUSH     14
         BAL,11   GVP2              ENTRY POINT TO T:GVPI
         B        NOBUF3            USER MAX PAGES AND WANTS A CPOOL
         PULL     14
         CI,3     0                 GOT A PAGE
         BNE      %+3               YES
         LI,6     E:NC              NO CORE EVENT #
         BAL,11   T:REG
         CI,14    JCOVP             WAS IT A CPOOL
         BL       GOTFPOOL          NO-FPOOL OR SPECIAL
GOTCPOOL MTW,1    JB:CBUC           INCREMENT # CPOOLS USED
         LI,3     JBCBLL
         LB,10    J:JIT,3           GET CURRENT CPOOL LL
         CW,7     10                IS THIS A NEW CPOOL LL
         BG       MAPSPARE          NO
         STB,7    J:JIT,3           YES-RESET IT
         B        MAPSPARE
GOTFPOOL MTW,1    JB:FBUC           INCREMENT # FPOOLS USED
MAPSPARE EQU      %
         LW,10    7                 CONVERT SPARE BUFFER VP
         AI,10    -JXBUFVP+1          TO INDEX FOR CALLING ROUTINE
         LOAD,3   JX:CMAP,7         PHYS PAGE ASSIGNED TO SPARE BUFF
         LW,7     14                WINDOW VP TO R7
         STORE,3  JX:CMAP,7         PP TO MAP FOR WINDOW VP
         PUSH     14
         BAL,11   T:SXMAPM3         LOAD THE MAP FOR THE WINDOW
         PULL     14
         SLS,14   9                 RESTORE WORD ADDR/TEST POOL FLAG
         BCR,4    BUFFEXIT          BUFFER NOT OBTAINED VIA FREE POOL
         LB,3     *14               GET NEW FREE POOL HEAD (OR ZERO)
         LI,1     JBFBFP
         STB,3    J:JIT,1           SET NEW HEAD
         B        BUFFEXIT          EXIT
GETFPOOL EQU      %
         LI,7     JBFBFP
         DISABLE
         LB,7     J:JIT,7           HEAD OF FREE FPOOLS (SPARE BUF VP)
         BEZ      NONEFREE          NONE IN POOL
         LW,3     Y8                SET FLAG TO INDICATE BUFF HEAD MUST
         STS,3    14                  BE UPDATED AFTER PAGE IS MAPPED
         B        MAPSPARE
NONEFREE EQU      %
         ENABLE
         LB,7     JB:FBUL           FPOOL SPARE UPPER LIMIT
         B        GETSPARE
         PAGE
T:ZBUF   EQU      %                 TOTAL RELEASE OF ALL FPOOLS
         LI,5     0                 INDICATE TO RELEASE PP
ZBUF2    LB,1     JB:FBUL           UL OF FPOOLS
         CI,1     JXBUFVP
         BGE      ZBUF3             MORE TO RELEASE
         LI,1     0                 INDICATE NO BUFFERS
         STH,1    JB:FBUL
         STW,1    J:ABUF
         B        0,6
ZBUF3    LOAD,3   JX:CMAP,1         PP ASSIGNED TO SPARE
         CI,3     FPMC              IS SPARE ALLOCATED
         BE       ZBUF4             NO-CHECK REST OF SPARE FPOOL AREA
         LI,2     ZBUF4
         PUSH     2
         PUSH     5,6
         BAL,2    RUNDRLS           YES-UNMAP WINDOW,RELEASE BUFFER
ZBUF4    MTB,-1   JB:FBUL           RESET FPOOL UL
         B        ZBUF2
*
*
T:RBUF   EQU      %
         PUSH     2                 SAVE RETURN
         PUSH     5,6               SAVE DCB ADDRESS ETC.
         LW,1     14
         CLM,1    WNDLIMS           WINDOW ADDR GIVEN
         BCR,9    RWINDOW           YES
         AI,1     JXBUFVP-1         CONVERT INDEX TO VP
RSPARE   EQU      %                 RELEASE BUFFER GIVEN INDEX
         BAL,11   TESTREL           ERROR IF THIS VP IS ALREADY IN POOL
RUNDRLS  LI,12    8                 # OF WINDOW PAGES
         LI,7     JCOVP+1           WINDOW UPPER LIMIT
         BAL,11   SEARCH            SEE IF IT IS NOW MAPPED
         B        RLSBUF            NO-GO RELEASE
UNMAPBUF EQU      %
         LI,11    FPMC              GET BUFFER OUT OF WINDOW
         STORE,11 JX:CMAP,7          WITH FPMC
         BAL,11   T:SXMAPM3         RELOAD MAP FOR THAT PAGE
RLSBUF   LW,5     5                 RELEASE BUFFER AS DICTATED BY R5
         BGZ      RLSPOOL           GREATER THAN ZERO-RELEASE TO POOL
         BLZ      BUFFXIT3          LESS THAN ZERO-JUST RELEASE WINDOW
         CB,1     JB:FBUL           RELEASING FPOOL
         BLE      RLSBUF2           YES
         MTW,-1   JB:CBUC           NO-DECREMENT # CPOOLS
         LI,3     JBCBLL
         CB,1     J:JIT,3           SPARE VP : CURRENT LL
         BNE      RLSBUF3           ABOVE CURRENT LL-DONT CHANGE LL
         LW,2     1
RBUF2    AI,2     1                 LOOK AT NEXT CPOOL SPARE
         CI,2     JOVVP             ARE ALL RELEASED
         BE       RBUF3             YES
         LOAD,7   JX:CMAP,2         IS NEXT HIGHER A FREE CPOOL SPARE
         CI,7     FPMC
         BE       RBUF2             YES-LOOK FOR USED CPOOL SPARE
RBUF3    STB,2    J:JIT,3
         B        RLSBUF3
RLSBUF2  MTW,-1   JB:FBUC           RELEASING FPOOL VP AND PP
RLSBUF3  LW,7     1                 SPARE VP TO R7
         BAL,11   T:RVPI            T:RVPI WILL REACT TO R5 CORRECTLY
         NOP
         B        BUFFXIT3          EXIT
RLSPOOL  EQU      %                 RELEASE BUFFER TO FREE POOL
         LI,5     JBFBFP            GET CURRENT HEAD OF FREE
         DISABLE
         LB,7     J:JIT,5             BUFFER IN POOL (SPARE VP)
         STB,1    J:JIT,5           RELEASED SPARE TO HEAD (SPARE VP)
         LOAD,3   JX:CMAP,1         PP OF NEW POOL HEAD
         LPSD,0   MMUMI             DISABLE AND GO UNMAPPED
RLSP2    SLS,3    9                 GET REAL WORD ADDR OF RELEASED BUFFER
         STB,7    *3                SET PREV HEAD AS LINK IN NEW HEAD
         BAL,1    MAP
BUFFXIT3 PULL     5,6
         B        BUFFXIT2
*
RWINDOW  EQU      %                 RELEASE BUFFER GIVEN WINDOW
         SLS,1    -9                GET WINDOW VP
         LW,5     5                 IS THIS A CALL TO UNMAP
         BGEZ     %+3               NO
         LW,7     1                 R7 = WINDOW VP
         B        UNMAPBUF          GO RELEASE IT
         LI,7     JOVVP-1           SPARE BUFFER UPPER LIMIT
         LI,12    31                # OF SPARE PAGES
         BAL,11   SEARCH            FIND MATCH IN SPARES
         BAL,11   BSCREECH          BUF MAPPED IN WINDOW BUT NOT IN SPR
         XW,1     7                 R1=SPARE VP   R7=WINDOW VP
         BAL,11   TESTREL           ERROR IF BUFFER IS ALREADY IN POOL
         B        UNMAPBUF          REMAP WINDOW PAGE-RELEASE BUFFER
         PAGE
* ROUTINE TO FIND A PHYSICAL PAGE MATCH IN WINDOW AND SPARES
*  GIVEN SPARE FIND MATCH IN WINDOW - GIVEN WINDOW FIND MATCH IN SPARE
*  INPUT    R1=SPARE VP                  R1=WINDOW VP
*           R7=WINDOW UL                 R7=SPARE BUF UL
*          R12=# OF WINDOWS TO SEARCH   R12=# OF SPARES TO SEARCH
*
* OUTPUT   R3= PHYS PAGE #               R3= PHYS PAGE #
*           R7= VP IN WINDOW             R7= VP IN SPARE
*
*  CALLING SEQUENCE :BAL,11  SEARCH
*                    NO MATCH
*                    MATCH
SEARCH   EQU      %
         LOAD,3   JX:CMAP,1         GET PP #
         CI,3     FPMC              DOES ANYONE HAVE IT
         BNE      SEARCH2           YES
         B        BSCREECH          NO-TRYING TO RELEASE UNALLOC BUFFER
SEARCH2  COMPARE,3 JX:CMAP,7        IS THIS A MATCH
         BNE      SEARCH3           NO
         AI,11    1
         B        *11               MATCH FOUND-EXIT
SEARCH3  AI,7     -1                LOOK AT NEXT LOWER PAGE
         BDR,12   SEARCH2             UNTILL ALL HAVE BEEN CHECKED
         B        *11               NO MATCH-EXIT
         PAGE
*  ROUTINE TO DETERMINE IF BUFFER MAY BE RELEASED
*  IF ERRORS FOUND GO TO RECOVERY
*  CALLING SEQUENCE: BAL,11 TESTREL    R1=VP OF SPARE TO BE RELEASED
*
TESTREL  EQU      %
         LI,4     JBFBFP
         LB,4     J:JIT,4           CURRENT HEAD OF POOL
         BEZ      *11               NONE IN POOL
         LI,15    0                 INITIALIZE COUNT OF BUFFERS IN FREE POOL
TESTREL3 AI,15    1                 ADD UP # OF BUFFERS IN FREE POOL
         CW,4     1                 RELEASED:REQUESTED RELEASE
         BNE      %+2
         B        BSCREECH          BUFFER IS ALREADY IN POOL
         LOAD,3   JX:CMAP,4         PP OF RELEASED BUFFER
         PUSH     1
         BAL,1    UNMAP
         SLS,3    9                 WA OF RELEASED BUFFER
         LB,4     *3                GET LINK TO NEXT IN POOL (SPARE VP)
         BAL,1    MAP
         PULL     1
         CI,4     0                 END OF CHAIN
         BNE      TESTREL3          NO-CONTINUE CHECKING
         LW,5     5                 RELEASING TO POOL
         BLEZ     *11               NO
         CI,15    3                 HAS FREE POOL THRESHOLD BEEN REACHED
         BL       *11               NO-RELEASE IT TO POOL
         LI,5     0                 YES-SET TO RELEASE EVERYTHING
         B        *11
         PAGE
T:MBUF   EQU      %
         LW,1     10                INDEX TO SPARE
         AI,1     JXBUFVP-1         SPARE VP
         LW,7     14                WINDOW ADDR
         SLS,7    -9                WINDOW VP
         LOAD,12  JX:CMAP,1         PP ASSIGNED TO SPARE
         CI,12    FPMC              IS THERE A PP
         BE       BSCREECH          NO-GO TO RECOVERY
         COMPARE,12 JX:CMAP,7       IS SPARE CURRENTLY MAPPED INTO WINDO
         BE       0,2               YES-EXIT
         STORE,12 JX:CMAP,7         PUT PP IN WINDOW VP
         BAL,11   T:SXMAPM3         LOAD MAP FOR THAT PAGE
         B        0,2               EXIT
         PAGE
T:SBUF   EQU      %
         LW,1     10                SPARE BUFFER INDEX
         AI,1     JXBUFVP-1         SPARE BUFFER VP
         LI,7     JCOVP-1           FPOOL WINDOW UL
         LI,12    6                 # OF WINDOWS TO SEARCH
         BAL,11   SEARCH            FIND WHERE IT IS NOW
         BAL,11   BSCREECH          NOT IN FPOOL WINDOW
         LW,1     14                NEW WINDOW TO R1
         SLS,1    -9                NEW WINDOW VP
         STORE,3  JX:CMAP,1         PP TO WINDOW CMAP
         LI,3     FPMC
         STORE,3  JX:CMAP,7         FPMC TO OLD WINDOW PAGE
         BAL,11   T:SXMAPM3         LOAD MAP FOR OLD WINDOW PAGE
         LW,7     1                 NEW WINDOW VP
         BAL,11   T:SXMAPM3         LOAD MAP FOR NEW WINDOW PAGE
         B        0,2
         PAGE
T:XBUF   PUSH     2,2               SAVE RETURN AND PP ADDRESS
         LW,1     14                WINDOW ADR TO R1
         SLS,1    -9                WINDOW VP
         LB,7     JB:FBUL           FPOOL SPARE UL
         LW,12    7
         AI,12    -JXBUFVP+1        # OF SPARES TO SEARCH
         BAL,11   SEARCH            FIND MATCH
         BAL,11   BSCREECH          BUF MAPPED IN WINDOW-NOT IN SPARES
         PULL     3                 PP ADDRESS
         SLS,3    -9                PP PAGE
         LOAD,10  JX:CMAP,7         PP NOW IN SPARE
         SLS,10   9                 CONVERT TO WINDOW ADDRESS
         STORE,3  JX:CMAP,1         NEW PP TO WINDOW
         PUSH     1                 SAVE WINDOW VP
         BAL,11   T:XPGVI           FIX MAP AND PP LINKS
         PULL     7                 LOAD MAP FOR WINDOW
         BAL,11    T:SXMAPM3           LOAD MAP FOR WINDOW
         PULL     2
         B        0,2
BSCREECH EQU      %
         SCREECH  X'6B'
MMSZ     EQU      %-MM
         END

