S69PROC  SET      1
UTSPROC  SET      1
UFLAGS   SET      1
         SYSTEM   UTS
SYSGEN   SET      1
         PAGE
*M*      MM       RESIDENT MEMORY MANAGEMENT ROUTINES
*P*      NAME:    MM
*P*
*P*      PURPOSE: TO PERFORM ALLOCATION OF VIRTUAL AND
*P*               PHYSICAL MEMORY AND SWAP STORAGE. THIS
*P*               INCLUDES SETTING UP THE USERS VIRTUAL MEMORY MAP
*P*               AND ACCESS PROTECTION TABLE IN THE JIT
*P*               AND LOADING THEIR RESPECTIVE HARDWARE REGISTERS.
*P*      DESCRIPTION:  WHEN A VIRTUAL PAGE IS TO BE ALLOCATED
*P*               A PHYSICAL PAGE AND SWAP GRANULE ARE OBTAINED
*P*               AND AN I/O COMMAND ENTRY BUILT IN THE USER
*P*               SWAP COMMAND LIST IN JIT/AJIT.
*P*               ALLOCATED VIRTUAL PAGES ARE LINKED IN JB:LMAP
*P*               IN THE SAME ORDER AS THEIR COMMAND LIST
*P*               ENTRIES.  THE PHYSICAL PAGE NUMBER ASSIGNED TO
*P*               THE VIRTUAL PAGE IS PLACED IN JX:CMAP.
*P*
*P*               SWAP GRANULES ARE ALLOCATED IN GROUPS OF
*P*               FOUR, ON RAD SWAPPING SYSTEMS, AND THE SEEK
*P*               ADDRESS OF THE FIRST SECTOR OF THE
*P*               GROUP IS PLACED IN THE DISC ADDRESS
*P*               TABLE, JH:DA.  A SEEK COMMAND, ADDRESSING THE
*P*               DISC ADDRESS TABLE ENTRY, IS BUILT
*P*               IN THE COMMAND LIST PRECEDING  EACH GROUP
*P*               OF FOUR I/O COMMANDS.
*P*
*P*               UNALLOCATED VIRTUAL PAGES ARE MAPPED INTO
*P*               A MONITOR PAGE (KNOWN AS THE FPMC PAGE),
*P*               WHICH IS WRITE LOCKED AND HAS AN ACCESS
*P*               PROTECTION CODE OF 11. ALLOCATED PAGES
*P*               HAVE THEIR ACCESS PROTECTION CODES STORED IN
*P*               J:JAC BASED ON THEIR TYPE OF USAGE.
*P*
*P*               OTHER JIT TABLES DESCRIBE VIRTUAL MEMORY
*P*               BOUNDARIES FOR EACH TYPE OF MEMORY,(DATA
*P*               DCB, PROCEDURE, ETC.) AND THE NUMBER OF PAGES
*P*               ALLOCATED FOR EACH TYPE.
         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      J:RNST            CHECK IF MONITOR RUNNING
         REF      DOUBLEZERO        CONSTANT
         REF      MB:GAM1           GRANULE ALLOCATION
         REF      MB:GAM2           GRANULE ALLOCATION
         REF      MB:GAM3           GRANULE ALLOCATION
         REF      MB:GAM4           GRANULE ALLOCATION
         REF      MB:GAM5           GRANULE ALLOCATION
         REF      MB:GAM6           GRANULE ALLOCATION
         REF      MB:GAM7           GRANULE ALLOCATION
         REF      MB:DWT            GRANULE ALLOCATION
         REF      MB:GPT            GRANULE ALLOCATION
         REF      MB:SPT            GRANULE ALLOCATION
         REF      MB:SWAPS          GRANULE ALLOCATION
         REF      M:GASLIM          GRANULE ALLOCATION
         REF      M:GATLIM          GRANULE ALLOCATION
         REF      M:FREE#GRAN       GRANULE ALLOCATION
         REF      S:DP              CHECK FOR PACK SWAPPING
         REF      MINUS2            CONSTANT
         REF      M5                CONSTANT
         REF      UB:SWAPI          SWAP INDEX NR.
         REF      JOVVP             OVERLAY VIRT PAGE NR.
         REF      JCOVP             CONTEXT VIRT PAGE NR.
         REF      JH:LDCF           CHECK IF SYMB ACCESS OK
         REF      TOPROOT           MONITOR TOP
         REF      JB:FBUL           FILE BUFFER UPPER LIMIT
         REF      JB:FBUC           FILE BUFFER USE COUNT
         REF      JBFBUC            FILE BUFFER USE COUNT
         REF      JBFBFP            FREE FILE BUFFER HEAD
         REF      JB:CBUC           COOP BUFFER USE COUNT
         REF      JBCBUC            COOP BUFFER USE COUNT
         REF      JBCBLL            COOP BUFFER LOWER LIMIT
         REF      JXBUFVP           SPARE BUFFER VIRT PAGE NR.
         REF      SBUF1VPA          SPEC WINDOW BUFFER #1
         REF      JCO2VPA           2ND. COOP BUFFER PAGE ADDR
         REF      GETSBUF           FILE MANG. TRUNCATION
         REF      JSBUF2VP          SPEC WINDOW BUFFER #2
         REF      M13               CONSTANT
         REF      J:BUP             BEGIN USER PAGE
         REF      JEUPVP            END USER PAGE VIRT PAGE
         REF      JBUPVP            BEGIN USER PAGE VIRT PAGE
         REF      J:TELFLGS         EXTENDED MEMORY MODE BIT
         REF      Y002              CONSTANT
         REF      PR:MM             CONSTANT; MAX MEM PRIVILEGE
         REF      J:UPRIV           USERS PRIVILEGE BITS
         REF      JB:NRG            NR. GRANULES REMAINING
*,*                                 IN GROUP OF FOUR
         REF      X4                CONSTANT
         REF      J:ABUF            RESET TO ZERO
         REF      J:JIT             JOB INFORMATION TABLE
         REF      J:PLL             PROCEDURE LOWER LIMIT
         REF      J:PUL             PROCEDURE UPPER LIMIT
         REF      J:EUP             END USER PAGE
         REF      J:DLL             DATA LOWER LIMIT
         REF      J:DUL             DATA UPPER LIMIT
         REF      JB:PCP            PROCEDURE PAGE COUNT
         REF      JBMNPA            MAX NR. PAGES ALLOWED
         REF,1    JB:PEAK           MAX PAGES USED
         REF      Y003E             CONSTANT
         REF      JBNASP            NEXT GRAN POSITION ON RAD
         REF      J:AJ              AJIT PHYS PAGE NR.
         REF      J:AJIT            VIRT ADDRESS OF AJIT
         REF      JX:PPH            USERS PHYSICAL PAGE CHAIN HD
         REF      JB:PPC            USERS PAGE COUNT
         REF      JB:VLH            VIRT PAGE CHAIN HD
         REF      JB:VLT            VIRT PAGE CHAIN TAIL
         REF      J:VLCS            VIRT PAGE WHERE MEMORY
*,*                                 AND RAD NO LONGER COINCIDE.
         REF      JB:PRIV           USERS PRIVILEGE
         REF      J:JAC             ACCESS PROTECTION TABLE
         REF      JB:LMAP           VIRTUAL PAGE TABLE
         REF      JX:CMAP           PHYSICAL PAGE TABLE
         REF      J:CLE             CLIST LENGTH
         REF      J:CL              COMMAND LIST IN JIT
         REF      J:CLPA            CLIST PHYSICAL ADDRESS
         REF      JH:DA             DISC ADDRESS TABLE
         REF      JCCL              MAX CLIST LENGHT IN JIT
         REF      JJAC              ACCESS PROTECTION CODE TABLE
         REF      JBNRG             NR. REMAINING GRANULES
         REF      MAP               ROUTINE TO MAP USER
         REF      UNMAP             ROUTINE TO UNMAP USER
         REF      UB:ASP            USERS SPECIAL PROCESSOR
         REF      UB:ACP            USERS COMMAND PROCESSOR
         REF      UB:APR            USERS PROCESSOR
         REF      Y4                CONSTANT
         REF      SB:RBMX           CORE LIMIT
         REF      SB:ROMX           CORE LIMIT
         REF      SL:CORE           CHECK USER SIZE
         REF      S:PCORE           CHECK USER SIZE
         REF      S:RTCORE          COUNT REAL TIME PAGES
         REF      S:RTIR            REAL-TIME SCHEDULING FLAG
         REF      RTCHK             CHECK FOR REAL TIME LOCKED IN
         REF      PB:PSZ            PROCESSOR PROCEDURE SIZE
         REF      S:CUN             CURRENT USER NUMBER
         REF      UB:PCT            USERS PAGE COUNT
         REF      UX:JIT            USERS JIT PAGE NR.
         REF      UH:FLG            USERS FLAGS
         REF      UB:MF             USERS MASTER FUNCTION COUNT
         REF      UH:JIT            JIT DISC ADDRESS
         REF      UH:AJIT           AJIT DISC ADDRESS
         REF      SPDBASE           SPEC PROCESSOR DATA ADDRESS
         REF      P:SA              PROCESSOR START ADDRESS
         REF      M:SGP             SWAP GRANULE TABLE ADDRESS
         REF      M:FPPH            FREE PAGE CHAIN HEAD
         REF      M:FPPT            FREE PAGE CHAIN TAIL
         REF      M:FPPC            FREE PAGE CHAIN COUNT
         REF      MX:PPUT           RESIDENT PHYSICAL PAGE TABLE
         REF      M:ADRINCR         INC FROM END OF TRACK TO NEXT
         REF      JCMAP             PHYSICAL PAGE TABLE IN JIT
         REF      JJITVP            JIT VIRT PAGE NR.
         REF      JAJITVP           AJIT VIRT PAGE NR.
         REF      E:NC              NO CORE EVENT
         REF      E:ND              NO DISC EVENT
         REF      E:DPA             DISC AVAILABLE EVENT
         REF      T:RE              REPORT EVENTSS
         REF      SB:HQ             HEAD OF STATE QUEUES
         REF      FPMC              FREE PAGE MAP CONSTANT
         REF      TSTACK            TEMP STACK
         REF      PNAMEND           PROCESSOR NAME TBL END
         REF      P:NAME             TABLE OF PROCESSOR NAMES
         REF      UB:DB             USERS DEBUGGER
         REF      P:AC              PROCESSOR ACCES CODES
         REF      X7FF800           CONSTANT
         REF      PGCLEAN           PAGE CLEANING CONSTANT
         REF      XA                CONSTANT
         REF      :BIG              BIG MEMORY FLAG
         REF      J:ASSIGN          BIT 9=1==> CAN DO TP CALS
         REF      Y004              MASK TO CK J:ASSIGN'S BIT 9
         DEF      T:SAD0            MAP VIRT TO PHYS
         DEF      T:GPP             GET PHYS PAGE
         DEF      T:FPP             FREE PHYS PAGE
         DEF      T:SGR             RELEASE SWAP GRANULE
         DEF      T:TOTESZ          CALCULATE USERS SIZE
         DEF      T:GBUF            GET BUFFER PAGE
         DEF      T:RBUF            RELEASE BUFFER PAGE
         DEF      T:MBUF            MAP BUFFER PAGE
         DEF      T:ZBUF            RESET BUFFERS
         DEF      T:XBUF            EXCHANGE BUFFERS
         DEF      T:SBUF            SWITCH BUFFERS
         DEF      T:GVGPI           GET VIRT GIVEN PHYS PAGE
         DEF      T:GVPI            GET VIRT AND PHYS PAGE
         DEF      T:RVPI            RELEASE VIRT AND PHYS PAGE
         DEF      T:PAC             LOAD PROCESSOR ACCESS CODE
         DEF      T:SXACM3          LOAD ACCES PROTECTION
         DEF      T:SACP1           SET ACCESS CODE IN JAC
         DEF      T:SXMAPM3         LOAD MAP REGISTERS
         DEF      T:XMMC            SETUP MAP AND ACCESS REGISTERS
         DEF      T:SGAJIT          JIT GRANULE ALLOCATION
         DEF      T:SAC             SET ACCESS CODE IN JAC
         DEF      T:IACU            OBTAIN ACCESS CODE
         DEF      T:GNVPI           GET N VIRT AND PHYS PAGES
         DEF      T:GNVNPI          GET N VIRT, NO PHYS, PAGES
         DEF      T:RVSPI           RELEASE VIRT, NOT PHYS, PAGES
         DEF      T:SNAC            SET ACCESS ON N PAGES
         DEF      PAGEZAP           INITIALZE PAGES
         DEF      NPMC              UNALLOCATED PAGE MAP CONSTANT
NPMC     EQU      X'22'
         DEF      T:SAD1            CVM  ENTRY FOR SAD
J        EQU      BA(J:JIT)
         PAGE
         DEF      MM:               PATCHING DEF
MM:      RES
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  EQU      X10
NREADY   EQU      XN2
SPJITAC  DATA     X'FFF30FFF'
         DEF      S:SJACCW
         BOUND    8
S:SJACCW DATA     SPJITAC
SPJACTRL GEN,8,7,8,9 1,0,X'40',0
         DEF      LKIMG
LKIMG    RES      8                 WL IMAGE FOR XDLT
         PAGE
*F*
*F*      NAME:    T:IACU
*F*      PURPOSE: TO OBTAIN THE ACCESS PROTECTION CODE FOR A GIVEN
*F*               VIRTUAL PAGE.
*F*      DESCRIPTION:  RETURNS ACCESS = 2 FOR PAGE ZERO, ACCESS
*F*               = 3 FOR PAGES BELOW THE FIRST OVERLAY PAGE(J0VVP)
*F*               AND THE VALUE FROM J:JAC FOR OTHERS.
*        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
*F*
*F*      NAME:    T:GNVPI
*F*      PURPOSE: TO ALLOCATE A GIVEN NUMBER OF PAGES.
*F*      DESCRIPTION:  ALLOCATES N VIRTUAL PAGES AND ASSIGNS
*F*               PHYSICAL PAGES TO THEM BY CALLING T:GVPI.
*F*               THIS ROUTINE IS CALLED BY STEP,LNKTRC AND
*F*               SEGLD.
*  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
         AI,5     0                 ARE WE GETTING PHYSICAL PAGES?
         BNEZ     GNV6              NO
         BAL,4    PARK              YES...PARK HIM FOR R/T (MAYBE)
GNV6     EQU      %
         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
*F*      NAME:    PARK
*F*      PURPOSE: TO GIVE ANY HIGH-PRIORITY REAL-TIME USERS A CHANCE
*F*               TO RUN DESPITE LENGTHY 'FETCHES' OF OTHER USERS.
*F*      DESCRIPTION:  IF S:RTIR IS ZERO, A HIGH-PRIORITY REAL-TIME
*F*               USER IS WAITING TO BE SCHEDULED AND THE CURRENT USER
*F*               IS PARKED VIA THE E:NC EVENT.
*
PARK     EQU      %
         PSW,6    TSTACK
         PSW,11   TSTACK
         LW,11    S:RTIR            ANY WAITING?
         BNEZ     NOPARK            NO
         LI,6     E:NC              YES...PARK THIS GUY
         BAL,11   T:REG
NOPARK   PLW,11   TSTACK
         PLW,6    TSTACK
         B        0,4               RETURN
         PAGE
*F*      NAME:    PAGEZAP,PAGEZAPT,PAGEZAP0
*F*      PURPOSE: TO INITIALIZE PAGES ALLOCATED BY MM ROUTINES.
*F*      DESCRIPTION:  EACH PAGE IS INITIALIZED WITH THE CONTENTS
*F*               OF THE CURRENT REGISTER SET.
*F*               PAGEZAP0 INITIALIZES ONE PAGE.
*F*               PAGEZAPT INITIALIZES N PAGES IN DESCENDING
*F*               ORDER
*F*               PAGEZAP INITIALIZES N PAGES IN EITHER ASCENDING
*F*               OR DESCENDING ORDER AS SPECIFIED.
*        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,11   GZPRIV                 IS HE SECURE
         BAZ      0,5
PGPZE    SLS,7    9
         SLS,10   9
         LCI      10
         PSM,11   TSTACK
         LW,11    PGCLEAN           GET PAGE CLEANING CONSTANT.
         STD,11   12
         STD,12   14
         LCI      5
         STM,11   0
PAGEZAP1 AI,6     -1
         BLZ      PAGEZXIT
         SW,7     10
         LCI      10
I        DO       51
         STM,11   I*10-10,7
         FIN
         STD,12   510,7
         B        PAGEZAP1
PAGEZXIT LCI      10
         PLM,11   TSTACK
         B        0,5
*
*
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
*F*      NAME:    T:RVSPI
*F*      PURPOSE: TO RELEASE A VIRTUAL PAGE WITHOUT RELEASING
*F*               ITS ASSIGNED PHYSICAL PAGE.
*F*      DESCRIPTION:  THIS ROUTINE CALLS T:RVPI TO RELEASE THE
*F*               VIRTUAL PAGE, COMMAND LIST ENTRY AND SWAP
*F*               GRANULE.  IT SETS A FLAG TO INDICATE THAT
*F*               T:RVPI IS NOT TO RETURN THE PHYSICAL PAGE TO
*F                THE MONITOR FREE PAGE LIST.  THE FPMC CONSTANT
*F*               IS PLACED IN JX:CMAP ENTRY.  THE CALLER MUST
*F*               KEEP TRACK OF THE PHYSICAL PAGE.
T:RVSPI  EQU      %
         PUSH     7,5
         LI,5     -1
         LI,11    7H3
         B        T:RVPI
         PAGE
*F*      NAME:    T:GVGPI
*F*      PURPOSE: TO ALLOCATE A VIRTUAL PAGE AND MAP IT INTO
*F*               A GIVEN PHYSICAL PAGE.
*F*      DESCRIPTION:   THIS ROUTINE CALLS T:GVPI TO ALLOCATE
*F*               THE VIRTUAL PAGE, SWAPPER GRANULE AND COMMAND
*F*               LIST ENTRY.  IT SETS A FLAG TO INDICATE
*F*               TO T:GVPI TO USE THE SPECIFIED PHYSICAL
*F*               PAGE INSTEAD OF GETTING ONE FROM THE
*F*               MONITOR FREE PAGE LIST.
*        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
*F*      NAME:    T:SNAC
*F*      PURPOSE: TO SET ACCESS PROTECTION ON N VIRTUAL PAGES.
*F*      DESCRIPTION:  CALLS T:SNAC N TIMES.
*S*      SCREECH CODE: 21     SUA
*S*      REPORTED BY: MM
*S*      MESSAGE: ATTEMPT TO SET ACCESS CONTROLS ON NON-
*S*               EXSISTENT VIRTUAL PAGE.
*S*      REGISTERS: 6=NUMBER OF PAGES TO SET
*S*               7=VIRTUAL PAGE NUMBER.
*S*               11=LINK REGISTER.
*  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
*
         PAGE
**F*     NAME:    T:SAD0,T:SAD1
*F*      PURPOSE: TO MAP A SPECIFIED VIRTUAL PAGE ONTO
*F*               A SPECIFIED PHYSICAL PAGE.
*F*      DESCRIPTION:  THIS ROUTINE IS USED BY BOTH
*F*               APWP AND CVM CALS.  IT PLACES THE
*F*               GIVEN PHYSICAL PAGE NUMBER INTO JX:CMAP
*F*               AND SETS JB:LMAP TO EITHER 01 OR 02
*F*               DEPENDING ON THE CAL.  IT SETS THE ACCESS
*F*               PROTECTION AND LOADS THE HARDWARE MAP
*F*               AND PROTECTION REGISTERS.
*        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
T:SAD1    EQU     %
SAD0B    EQU      %
         AND,6    M13
         AND,7    M8
*  IF TEL IS DOING THE SAD, SKIP LIMIT CHECK
         LW,5     S:CUN
         LH,5     UH:FLG,5
         CI,5     TIC               IS IT TEL
         BANZ     %+3               YES, SKIP BUP/EUP CHECK
         CLM,7    J:BUP             IS VP WITHIN USER PROG LIMITS
         BCS,9    SAD0R             ERROR
         LI,13    FPMC
         COMPARE,13 JX:CMAP,7
         BE       %+3
         CB,4     JB:LMAP,7         ENABLE SAD OVER SAD....
         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   PULL     12
         PULL     3
         B        *11
         PAGE
*F:      NAME:    T:GVPI
*F*      PURPOSE: TO ALLOCATE A GIVEN VIRTUAL PAGE.
*F*      DESCRIPTION:  THIS ROUTINE CHECKS THE USERS SIZE
*F*               BY CALLING T:TOTESZ.  IT ASSIGNS A
*F*               PHYSICAL PAGE, UNLESS CALLED BY T:GNVNPI,
*F*               BUILD A COMMAND LIST ENTRY AND OBTAINS A
*F*               SWAPPER GRANULE.  IT MAINTAINS THE COUNTS
*F*               FOR EACH TYPE OF MEMORY  (DATA, PROCEDURE
*F*               DCB, ETC.) AND SETS THE APPROPRIATE ACCESS
*F*               PROTECTION CODE.  IT LOADS THE HARDWARE
*F*               MAP AND ACCESS REGISTERS BY CALLING T:SXMAPM3
*F*               AND T:SAC.
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
*
*        B        T:TOTESZ
*
         PAGE
*F*      NAME:    T:TOTESZ
*F*      PURPOSE: TO COMPUTE THE USERS SIZE AND DETERMINE
*F*               IF IT IS WITHIN VARIOUS LIMITS.
*F*      DESCRIPTION:  THERE ARE THREE SIZES COMPUTED.  THE
*F*               USERS VIRTUAL SIZE IS FOUND BY:
*F*                UB:PCT           # PAGES HE NOW OWNS
*F*               +(PUL-PLL)-PDP+1    # PROC PGS POTENTIAL
*F*               +(DUL-DLL)-PCD+1    # DATA PGS POTENTIAL
*F*               -PCC                # CONTEXT PGS
*F*               +APWP               # ASSIGN PHYS WORK PGS
*F*
*F*               THIS SIZE CANNOT EXCEED USERS AUTHORIZATION
*F*               OR SYSTEM LIMIT UNLESS IT IS A SHARED
*F*               PROCESSOR ALLOWED TO OBTAIN ALL MEMORY.
*F*
*F*               THE NUMBER OF CONTEXT PAGES, PLUS THE
*F*               NUMBER OF POTENTIAL SPARE BUFFER PAGES
*F*               ARE ADDED TO THE USERS SIZE.  THIS SIZE
*F*               CANNOT EXCEED THE MAXIMUM VIRTUAL SWAP
*F*               SPACE (SL:CORE).
*F*
*F*               THE NUMBER OF PAGES NEEDED FOR SHARED
*F*               PROCESSORS, INCLUDING SPECIAL SHARED, CORE
*F*               LIBRARY, TEL, ETC. ARE ADDED TO THE TOTAL.
*F*               THIS SUM IS TESTED AGAINST S:PCORE  TO
*F*               INSURE THE USER DOES NOT EXCEED MAXIMUM
*F*               AVAILABLE PHYSICAL MEMORY.
* 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
         CI,7     0                 PCORE CHECK
         BE       %+3               YES-HOLD BACK FOR OVERLAYS
         CB,7     JB:FBUL           GETTING A FILE MANAGEMENT BUFFER
         BLE      NOOLAY            YES-THEY HAVE BEEN HELD OUT
         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      %
         CI,7     0                 IS THIS A PCORE TEST
         BE       GVP27             YES-SKIP USER CORE CHECKS
         LI,2     3
         LB,2     JB:PCP,2          PAGE COUNT CONTEXT
         SW,12    2
         PUSH     12                SAVE CURRENT USER SIZE
         LI,1     J+JBMNPA
         LB,13    0,1               GET JIT LIMIT
         BNEZ     GVP23             IF NOT 0, USE IT
CORATX  EQU     1
         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      %
         LW,1     Y004
         AND,1    J:ASSIGN          IS USER CANDIDATE FOR ASSIGNED PGS
         BEZ      GVP236            B IF NOT; SKIP ASSIGNED PG SEARCH
         LI,1     JBUPVP             START AT BEGINNING OF USER
         LI,2     2                 LOOKING FOR APWPAGES AND
         LB,3     JB:PCP            RETAIN PROCEDURE COUNT
GVP230   EQU      %
         CB,2     JB:LMAP,1         AND ADDING THEM TO USER TALLY
         BNE      GVP235            IS IT AN APWP
         AI,3     0                 YES, HAS IT ALREADY BEEN COUNTED
         BEZ      GVP232            NO, SINCE PROCEDURE IS ZERO
         CLM,1    J:PLL             IF IN PROCEDURE OR STATIC DATA
         BCR,9    GVP235            THEN THE PAGE HAS ALREADY BEEN
         CLM,1    J:DLL             ACCOUNTED FOR, OTHERWISE
         BCR,9    GVP235            ADD IT TO USER TOTAL
GVP232   EQU      %
         AI,12    1                 INCREMENT TOTAL SIZE
GVP235   EQU      %
         AI,1     1                 MOVE TO NEXT VIRT PAGE
         CW,1     J:EUP             CONTINUE TILL DONE
         BLE      GVP230
GVP236   EQU      %
         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
         LW,1     PR:MM             IS PROCESSOR ALLOWED
         CW,1     J:UPRIV           MAX CORE?
         BAZ      *0                NO-ABORT HIM
GVP25    EQU      %
         LI,2     3
         LB,2     JB:PCP,2          COUNT OF CONTEXT
         AW,12    2
         CB,7     JB:FBUL           GETTING A FILE MGMT BUFFER
         BLE      GVP90             YES-DONT HOLD BACK FOR IT
GVP27    EQU      %
         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
         LW,13    S:PCORE
         CI,7     0                 IS THIS A PCORE TEST
         BNE      %+2               NO
         AI,13    1                 ADJUST FOR BGE BELOW
         CW,12    13                IS USER REQUIREMENT > PHY CORE
         BGE      *0
         AI,0     1
         B        *0
*
*
*
GVP26    B        SIZERR            T:TOTESZ TEST FAILED
         PULL     12                GET CURRENT SIZE
         AI,12    1                 FOR NEW PAGE
         LI,2     JB:PEAK
         CB,12    0,2               IS THIS A NEW PEAK
         BLE      %+2               NO
         MTB,1    0,2               YES-INCREMENT COUNT BY ONE
         PLW,3    TSTACK
         PUSH     11
         PUSH     6
         LI,4     J+JBNRG
         LB,1     0,4
         AI,1     -1
         BGEZ     GVP45             BR. IF MORE GRANULES REMAIN
*          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     8                 FOUR GRANULES PER CLUSTER*2
         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    X7FF800
         STS,12   0,4               STORE PHYS PG ADDRESS IN SEEKIOCD
         MTW,2    J:CLE             INC LENGTH OF CLIST.
         LI,4     J+JBNRG
         LI,1     3                 INITIALIZE NRG
*  GET PP # FROM FREE PG POOL  UNLESS THIS CAL IS GET VP, NO PP
* O 3  = PHY PG # OBTAINED
GVP45    EQU      %
         STB,1    0,4               SET NR. GRANULES REMAINING IN GROUP
         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      %
         BAL,1    RTCHK             IS THIS USER LOCKED IN CORE?
         BCR,4    GVP53             NO
         MTW,1    S:RTCORE          YES...ACCOUNT FOR NEW CONTEXT PGE
GVP53    ;
         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      CCS,3             3=0=>NO PP, =1=>NORMAL EXIT.
RVP3     RES      0
GVPO     RES      0
         B        *11
         PAGE
*F*      NAME:    T:RVPI
*F*      PURPOSE: TO RELEASE A GIVEN VIRTUAL PAGE.
*F*      DESCRIPTION:  THE VIRTUAL PAGE IS REMOVED FROM THE
*F*               JB:LMAP LIST AND THE COMMAND LIST .
*F*               IT IS REMAPPED INTO THE MONITOR FPMC PAGE
*F*               THE ACCESS PROTECTION SET NO NO ACCESS AND ITS
*F*               PHYSICAL PAGE RETURNED TO THE MONITOR FREE
*F*               PAGE LIST, UNLESS IT WAS CALLED BY T:RVSPI.
*F*               ITS SWAP GRANULE IS RELEASED.
*F*               THE COUNT FOR ITS MEMORY TYPE IS DECREMENTED,
*F*               (DATA,DCB, ETC.) AND THE ACCESS PROTECTION
*F*               AND MAP REGISTERS ARE LOADED.
T:RVPI   EQU      %
*  TEST WHETHER THE VP IS IN USE
         LB,4     JB:LMAP,7
         LI,12    FPMC              FREE PG MAP CONST
         COMPARE,12 JX:CMAP,7       IS VIRT PG TO RELEASE IN USE
         BNE      RVP2
         CI,4     1                 DOESN'T SEEM TO BE. WAS IT SAD
         BE       RVP22             PAGE. IF SO, OK TO RELEASE IT.
         B        RVP3
RVP2     EQU      %
         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
RVP22    PUSH     11
         CI,4     1
         BNE      RVP42             IF NOT A 'CVM' PAGE
RVP21    EQU      %
         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      %
         BAL,4    PARK              GO CHECK REAL-TIME ENVIRONMENT
*  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
         BAL,1    RTCHK             IS THIS USER LOCKED IN CORE?
         BCR,4    RNVP1             NO
         MTW,-1   S:RTCORE          YES...COUNT IT DOWN
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
*F*      NAME:    T:SXMAPM3
*F*      PURPOSE: TO LOAD THE MAP REGISTERS FOR A SINGLE PAGE.
T:SXMAPM3 LW,15   7                 VP #
T:SXMAPM2 LI,12   JX:CMAP           IMAGE ADDRESS
         LI,14    1                 # OF PGS
*F*      NAME:    T:SXMAP
*F*      PURPOSE: TO LOAD THE MAP REGISTERS FROM THE USERS
*F*               IMAGE IN JX:CMAP STARTING AT A SPECIFIED
*F*               PAGE FOR A SPECIFIED NUMBER OF PAGES.
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
*F*      NAME:    T:GPP
*F*      PURPOSE: TO OBTAIN A PAGE FROM THE MONITOR FREE
*F*               PAGE LIST (M:FPPH)
*F*      DESCRIPTION: THE PAGE IS OBTAINED FROM THE HEAD OF THE
*F*               LIST (M:FPPH).
*        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
*
*
         PAGE
*F*      NAME:    T:FPP
*F*      PURPOSE: TO RETURN A PHYSICAL PAGE TO THE MONITOR
*F*               FREE PAGE LIST.
*F*      DESCRIPTION:  THE PAGE IS ADDED TO THE TAIL OF
*F*               THE LIST (M:FPPT).
*        2 = LINK REGISTER
*   I    3  = PHY PAGE TO RELEASE
*        4  = PREV PG RELEASED
*
T:FPP    EQU      %
         LI,4     TOPROOT-1         LAST MONITOR LOCATION
         SLS,4    -9                LAST MONITOR PAGE
         CW,4     3                 MON PAGE : RELEASING PAGE
         BL       1A1               NOT RELEASING MONITOR PAGE
*S*      SCREECH CODE: 01-01
*S*      REPORTED BY: MM
*S*      MESSAGE: ATTEMPT TO RELEASE MONITOR PAGE.
*S*      REGISTERS: 3=PHYSICAL PAGE TO BE RELEASED.
*S*                 7=VIRTUAL PAGE
*S*      REMARKS:   MAY BE CALLED  TO RELEASE A PAGE FROM
*S*                 THE USERS PAGE CHAIN, OR, TO RELEASE A
*S*                 STOLEN PAGE.
TFPP1    SCREECH  1,1
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
         PAGE
*F*      NAME:    T:STLPP
*F*      PURPOSE: TO STEAL A PHYSICAL PAGE FROM THE MONITOR
*F*               FREE PAGE LIST WITHOUT ASSIGNING IT TO A
*F*               USER.
*F*      DESCRIPTION:  THIS IS A CAREFULLY CONTROLLED METHOD OF
*F*               OBTAINING PHYSICAL MEMORY FOR USE BY MONITOR
*F*               FUNCTIONS FOR SHORT PERIODS OF TIME.  IT KEEPS
*F*               TRACK OF THE NUMBER OF STOLEN PAGES TO ENSURE
*F*               AGAINST DEADLOCKS.
         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)
         PAGE
*F*      NAME:    T:RSPP,T:RSPPEA
*F*      PURPOSE: TO RETURN STOLEN PAGES TO THE MONITOR.
*F*      DESCRIPTION:  THIS ROUTINE ADDS A SPECIFIED PAGE
*F*               TO THE MONITOR FREE PAGE LIST AND UPDATES THE
*F*               STOLEN PAGE CONTROL COUNTERS.
*                                   :
*                                   --------------------------------------------
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     TOPROOT-1         LAST MONITOR LOCATION
         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
*F*      NAME:    T:SGA,T:SGAJIT
*F*      PURPOSE: TO ALLOCATE SWAPPER GRANULES.
*F*      DESCRIPTION:  THIS ROUTINE LOCATES AN AVAILABLE
*F*               SWAPPER GRANULE BY SEARCHING THE SGP TABLE AND
*F*               RETURNS THE SEEK ADDRESS.
*F*               ONLY EVERY FOURTH GRANULE IS MARKED AVAILABLE.
*F*               THE T:SGAJIT ENTRY ALLOWS PHE CALLER TO SPECIFY A
*F*               SWAPPER INSTEAD OF USING THE CURRENT USERS.
*F*               A CONSTANT SEEK ADDRESS (02) IS RETURNED FOR
*F*               PACK SWAPPING SYSTEMS.
*
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,14    MB:SPT,2          *
         CW,1     M:GASLIM,2        *COMPARE REQUEST AGAINST
         BLE      %+4               *SECTOR/TRACK.
         LI,0     0                 *GET SECTOR NR. MOD TRACK SIZE
         DW,0     14                *
         STW,0    1                 *
         LI,0     -1                *BUILD MASK FOR SEARCH
         MTB,0    MB:GAM7,2         *
         BEZ      %+5               *
         LW,0     =X'55555555'      *3214 (NSRAD) MASK
         CI,1     1                 *IF REQUEST IS FOR AN ODD
         BAZ      %+2               *SECTOR MAKE THE MASK ODD.
         SCS,0    1                 *
         STW,0    6                 *SAVE FOR LOOP LATER
         SLS,1    -1                *MAKE IT A GRANULE NR.
*****************************************************************
*INITIALIZE FOR TABLE SEARCH
*****************************************************************
SGA1     EQU      %
         LB,14    M:SWAPS,2         *GET SHIFT VALUE
         SLS,1    *14               *GIVES DBLWD INDEX OF GRAN REQUESTED
SGA12    EQU      %
         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      %
         LD,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
         SCS,0    1                 *CHECK FOR ANOTHER PASS
         CW,0     6                 *
         BNE      SGA12             *YES, DO IT
         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    0                 *DOES THE FIRST HALF HAVE A FREE TRK
         BANZ     SGA5              *IF YES, SKIP
         AI,1     1                 *NO, INCREMENT THE WORD INDEX
         CW,13    0                 *HOW ABOUT THE SECOND HALF
         BANZ     SGA5              *
         SLS,1    -1                *TRACK IS GONE, RESTORE THE DBLWD
         B        SGA2+2            *INDEX AND CONTINUE LOOPING
SGA7     STS,13   *15,1             *RESTORE TABLE AND CONTINUE
         B        %-3               *SEARCHING
SGA5     LW,12    0                 *GET MASK
         LI,13    0                 *
         XW,13    *15,1             *GET TABLE WORD AND BLOCK IT
         AND,12   13                *FROM REENTRANCE.
         BEZ      SGA7              *OUR BIT WAS GONE.
         EOR,13   12                *RESET ANYTHING WE CAN USE AND
         STS,13   *15,1             *PUT THE REST BACK.
************************************************************************
*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
         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
         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
         LB,1     MB:GAM6,2         *
         AND,1    15                *RETURN SECTOR ADDRESS
SGA10    EQU      %
         MTW,-4   M:FREE#GRAN,2
         B        SGR1              NORMAL EXIT
         PAGE
*F*      NAME:    T:SGR,T:SGRNU
*F*      PURPOSE: TO RELEASE SWAPPER GRANULE.
*F*      DESCRIPTION:  THIS ROUTINE RELEASES A SWAP GRANULE BY
*F*               CONVERTING ITS SEEK ADDRESS TO A BIT ADDRESS
*F*               AND SETTING THE SGP TABLE.
*F*               ONLY GRANULES WHICH ARE A MULTIPLE OF FOUR MAY
*F*               BE RELEASED.
*F*               T:SGRNU USES A SPECIFIED SWAPPER SGP INSTEAD
*F*               OF THE CURRENT USERS.
*F*               ON PACK SWAPPER SYSTEMS NO ACTION IS PERFORMED.
************************************************************************
* 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.*
************************************************************************
         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.
         STB,12   2                 SAVE SECTOR #
         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,1     2                 RETREIVE SECTOR ADDRESS
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
*F*      NAME:    T:SAC,T:SACP1
*F*      PURPOSE: TO SET AN ACCESS PROTECTION CODE IN J:JAC F
*F*               FOR A SPECIFIED VIRTUAL PAGE.
*
*  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
*F*      NAME:    T:SXACM3
*F*      PURPOSE: TO LOAD THE ACCESS PROTECTION CODE FOR A
*F*               PAGE.
T:SXACM3 LI,12    J:JAC
         LI,14    1
         LW,15    7
*F*      NAME:    T:SXAC
*F*      PURPOSE: TO LOAD THE ACCESS PROTECTION REGISTERS FROM
*F*               THE USERS IMAGE IN J:JAC, STARTING AT A
*F*               SPECIFIED PAGE FOR A SPECIFIED NUMBER OF
*F*               PAGES.
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
*F*      NAME     T:XMMC,T:XMMC1
*F*      PURPOSE: TO SETUP THE MAP AND ACCESS PROTECTION REGISTERS
*F*               BEFORE EXECUTING THE USER.
*F*               T:XMMC1 IS ENTERED MAPPED.
*
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
*F*      NAME:    T:PAC
*F*      PURPOSE: TO LOAD THE ACCESS PROTECTION REGITERS FOR
*F*               SPECIAL SHARED PROCESSOR.
*F*      DESCRIPTION:  THE ACCESS IS NOT SET IF THE USER
*F*               HAS EXTENDED MEMORY MODE.  OTHERWISE, THE
*F*               ACCESS CODES ARE OBTAINED FROM P:AC AND
*F*               STORED INTO J:JAC.  AN LPC IS EXECUTED TO
*F*               LOAD THE REGISTERS.
*        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
*F*      NAME:    T:GNVNPI
*F*      PURPOSE: TO OBTAIN VIRTUAL PAGES WITHOUT ALLOCATING
*F*               PHYSICAL.
*F*      DESCRIPTION:  THIS ROUTINE CALLS T:GNVPI WITH A
*F*               FLAG SET TO ALLOCATE VIRTUAL PAGES, BUILD
*F*               COMMAND LIST ENTRY AND GET A SWAP GRANULE
*F*               WITHOUT ASSIGNING A PHYSICAL PAGE.  INSTEAD,
*F*               A SPECIAL MONITOR PAGE (NPMC) IS USED FOR
*F*               THE JX:CMAP AND COMMAND LIST ENTRIES.
*F*               THIS ROUTINE IS USED BY STEP TO OBTAIN
*F*               PAGES WHICH ARE TO BE INITIALIZED WITH
*F*               PROCESSOR DATA OR DCB DURING THE INSWAP
*F*               PROCESS.
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
*F*      NAME:    T:GAJP
*F*      PURPOSE: TO DETERMINE IF AN AJIT IS REQUIRED AND
*F*               TO ALLOCATE ONE IF SO.
*F*      DESCRIPTION:  IF THE USER COMMAND LIST CANNOT FIT
*F*               INTO THE SPACE IN JIT AN AJIT PAGE IS
*F*               OBTAINED AND THE COMMAND LIST IS MOVED INTO
*F*               IT.  THE JIT DISC ADDRESS IS NOW USED FOR
*F*               THE AJIT AND THE SECOND GRANULE'S
*F*               SEEK ADDRESS USED FOR THE JIT.(WHEN THE
*F*               JIT WAS ALLOCATED IT GOT A GROUP OF
*F*               FOUR GRANULES)
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
         AI,14    2
         LB,15    MB:GAM6,4
         CS,14    M:GASLIM,4
         BLE      %+2
         AW,14    M:ADRINCR,4
         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
*F*      NAME:    T:XPGVI
*F*      PURPOSE: TO PLACE A SPECIFIED PHYSICAL PAGE INTO
*F*               A PREVIOUSLY ALLOCATED VIRTUAL PAGE.
*F*      DESCRIPTION:  TH E PHYSICAL PAGE IS PLACED IN
*F*               JX:CMAP,INSERTED INTO THE USERS PHYSICAL
*F*               PAGE CHAIN AND ITS BYTE ADDRESS PLACED INTO
*F*               THE COMMAND LIST ENTRY.
*F*               THE PREVIOUS PHYSICAL PAGE IS NOT
*F*               RETAINED BY THIS ROUTINE.
         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
*S*      SCREECH CODE: 01-02
*S*      REPORTED BY: MM
*S*      MESSAGE: USERS VIRTUAL PAGE CHAIN (JB:LMAP) INCONSISTANT
*S*      REGISTERS: 7=VIRTUAL PAGE NUMBER SOUGHT IN JB:LMAP.
*S*      REMARKS:   SCREECH OCCURS IN T:XPGVI, CALLED ONLY BY
*S*                 T:XBUF.
         SCREECH  1,2
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
*
*F*      NAME:    T:GBUF
*F*      PURPOSE: TO OBTAIN A SPARE BUFFER PAGE AND MAP
*F*               IT INTO A SPECIFIED WINDOW PAGE.
*F*      DESCRIPTION:  AN AVAILABLE VIRTUAL PAGE IS LOCATED
*F*               IN THE SPARE BUFFER AREA AND A PHYSICAL PAGE,
*F*               COMMAND LIST ENTRY AND SWAP GRANULE ALLOCATED
*F*               TO IT BY CALLING T:GVPI.
*F*               THE PHYSICAL PAGE THUS OBTAINED IS THEN
*F*               MAPPED INTO THE SPECIFIED WINDOW PAGEBY
*F*               PLACING ITS PAGE ADDRESS INTO JX:CMAP
*F*               AND CALLING T:SXMAPM3.
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
*F*      NAME:    T:ZBUF
*F*      PURPOSE: TO RELEASE ALL FPOOL BUFFERS.
*F*      DESCRIPTION:  CALLS RUNDRLS TO UNMAP THE WINDOW
*F*               PAGE AND RELEASE THE SPARE BUFFER PAGES.
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
*
         PAGE
*F*      NAME:    T:RBUF
*F*      PURPOSE: TO RELEASE A SPARE BUFFER TO THE FREE BUFFER
*F*               POOL OR TO RETURN IT TO THE MONITOR.
*F*      DESCRIPTION:  IF THE SPECIFIED BUFFER IS MAPPED
*F*               INTO A WINDOW PAGE IT SI REMOVED BY
*F*               PLACING AN FPMC CONSTANT IN JX:CMAP AND
*F*               AND RELOADING THE MEMORY MAP.  IF THE
*F*               BUFFER IS TO BE PLACED IN THE FREE BUFFER
*F*               POOL IT IS ADDED TO THE HEAD (JB:FBUL).
*F*               IF IT IS TO BE RELEASED, T:RVPI IS CALLED
*F*               TO RELEASE IT.  IF THE PHYSICAL PAGE
*F*               IS NOT TO BE RETURNED TO THE MONITOR A
*F*               FLAG IS SET AND T:RVPI DOES NOT RETURN IT.
*
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    20                # OF 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
*F*      NAME:    T:MBUF
*F*      PURPOSE: TO REMAP  A PREVIOUSLY ACQUIRED SPARE
*F*               BUFFER INTO A SPECIFIED WINDOW PAGE.
*F*      DESCRIPTION:  IF THE PAGE IS ALREADY MAPPED
*F*               NOTHING IS DONE.  IF NOT, ITS PHYSICAL
*F*               PAGE ADDRESS IS PLACED IN JX:CMAP AT
*F*               THE SPECIFIED WINDOW PAGE AND A CALL
*F*               MADE TO T:SXMAPM3 TO REMAP IT.
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
*F*      NAME:    T:SBUF
*F*      PURPOSE: TO MAP A SPARE BUFFER, CURRENTLY MAPPED
*F*               INTO A DIFFERENT WINDOW PAGE, INTO A
*F*               SPECIFIED WINDOW PAGE.
*F*      DESCRIPTION:  THE PAGES ARE SWITCHED BY SETTING
*F*               JX:CMAP AND CALLING T:SXMAPM3. THE PREVIOUS
*F*               JX:CMAP ENTRY IS DELETED BY PLACING FPMC
*F*               IN IT.
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
*F*      NAME:    T:XBUF
*F*      PURPOSE: TO EXCHANGE A STOLEN PHYSICAL PAGE FOR
*F*               A SPARE BUFFER PAGE ACQUIRED BY T:GBUF.
*F*      DESCRIPTION:  THIS ROUTINE LOCATES THE SPARE BUFFER
*F*               PAGE TO BE EXCHANGED AND SAVES THE
*F*               PREVIOUS PHYSICAL PAGE ASSIGNED TO IT
*F*               FOR RETURN TO TH CALLER.  IT THEN CALLS
*F*               T:XPGVI TO SETUP THE PHYSICAL PAGE CHAINS
*F*               AND COMMAND LIST.
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
*S*      SCREECH CODE: 6B-00
*S*      REPORTED BY: MM
*S*      MESSAGE: ERROR IN SPARE BUFFER TABLES
*S*      REGISTERS: 11=ADDRESS IN BUFFER SUBROUTINE WITHIN MM
*S*                    (T:GBUF,T:RBUF, ETC.) WHICH DETECTED THE
*S*                    ERROR.
*S*      REMARKS:   USUALLY BAD INPUT FROM CALLING ROUTINE.
BSCREECH EQU      %
         SCREECH  X'6B'
         END

