         TITLE    'PWP - PHYSICAL WORK PAGE MANAGER'
         PCC      0
         SYSTEM   TP:TPO
         REF      MASKS
         REF      BT31TO0           TABLE BITS
         REF      NB31TO0           TABLE NBITS
         SYSTEM   UTS
         DEF      PWP:              GIVE XDELTA A HANDLE
         DEF      GPWP              GET A PHYSICAL WORK PAGE
         DEF      FPWP              FREE A PHYSICAL WORK PAGE
         DEF      APWP              ASSIGN A PHYSICAL WORK PAGE
         DEF      RPWP              UNASSIGN PHYSICAL WORK PAGE
         DEF      RPWPCLK
         REF      SL:PWP,S:PWP#,PWPTABLE,PWPEND
         REF      T:STLPP,T:RSPP
         REF      S:STL#,SL:RSVP,S:ACORE,SL:STLM,S:STLC
         REF      J:EUP             USER'S CURRENT VP# UPPER BOUND
         REF      J:JIT             STARTING ADDRESS OF USER'S JIT
         REF      JBBCP
         REF      JBUPVP
         REF      J:BUP
         REF      JB:VLH
         REF      JX:CMAP,JB:LMAP,J:JAC
         REF      E:NC,T:REG
         REF      ECBGBLK,UH:DL,T:DOLISTR
         REF      M2,Y8
         REF      T:GVPI,T:GVGPI,T:RVSPI,T:SAD0
         REF      FPMC,NPMC
         REF      T:IACU,T:SAC
         REF      CO:INTFL          COC INTERRUPTED FLAG
         REF      X20               X'20' MASK FOR PWPCLK CHECK
         REF      JB:PCP            BUMPED TO PASS T:TOTESZ TESTS
         PAGE
*
*        TABLE SYMBOLS FOR PWP ENTRY
*
         ADMODE   (IND)
PWPAGE   HWORD    0
PWPACNT  BYTE     2
PWPUSRN  BYTE     2
PWPACT   BIT      0,31
PWPAP    BIT      0,30
PWPGP    BIT      0,29
PWPHOLD  BIT      0,28
PWPWIND  BIT      0,27
PWPCLK   BIT      0,26
*
*        TABLE SYMBOLS FOR RPWP DO-LIST BLOCK
*
         ADMODE   (IND)
RPWPTYPE FIELD    0,(15,7)
RPWPLINK HWORD    1
RPWPEADR WORD     1
RPWPAGE  HWORD    4
RPWPTABL WORD     3
RPWPBLK  EQU      7
*
SADPAGE  EQU      1
APWPAGE  EQU      2
         PAGE
**********************************************************************
*                                                                    *
*        GPWP                                                        *
*          - GET PHYSICAL WORK PAGE                                  *
*                                                                    *
**********************************************************************
*                                                                    *
*        ENTRY POINT                                                 *
*          GPWP                                                      *
*                                                                    *
*        INPUT                                                       *
*          R11 - RETURN ADDRESS                                      *
*                                                                    *
*        OUTPUT                                                      *
*          R10 - NON-ZERO, ALLOCATED PAGE NUMBER                     *
*                ZERO,PHYSICAL PAGE NOT AVAILABLE                    *
*          CC  - INDICATE WHETHER R10 IS ZERO OR NON-ZERO            *
*                                                                    *
*        REGISTER USAGE                                              *
*          R10 ALTERED, ALL OTHERS PRESERVED                         *
*                                                                    *
**********************************************************************
*
PWP:     EQU      %                 LABEL FOR XDELTA
*
GPWP     EQU      %
         PUSH     10,R11            SAVE VOLATILE REGS INMM
         LW,R1    SL:PWP            CHECK FOR MAXIMUM
         CW,R1    S:PWP#            USAGE OF PHYSICAL WORK PAGES
         BLE      GPWP080           B, IF ALL USED AT THE MOMENT
         BAL,R0   PWPENTRY          ELSE, TRY FOR A PWPTABLE ENTRY
         BEZ      GPWP080           B, IF NONE CURRENTLY AVAILABLE
         PUSH     1,R1              SAVE ENTRY ADDRESS
         BAL,R11  T:STLPP           ATTEMPT TO STEAL A FREE PAGE
         PULL     1,R1              RETRIEVE TABLE ENTRY ADDRESS
         LW,R10   R3                SEE IF WE GOT ONE
         BLEZ     GPWP020           B, IF NOT; MUST TRY HARDER
         MTW,1    S:PWP#            ACCOUNT FO OBTAINED PAGE
         SLS,R3   -9                CONVERT TO PAGE NUMBER
         STORE,R3 *R1               AND SAVE INPWPTABLE
         SBIT,R2  PWPGP,R1          INDICATE ENTRY IS FOR GPWP
         LW,R10   R3                LOAD OUTPUT R10 WITH PAGE NUMBER
         B        GPWP100           PREPARE FOR EXIT
GPWP020  EQU      %
         PUSH     6,R5              SAVE REGS NOT SAVED BY MM
         PUSH     1,R1              ALSO SAVE TABLE ENTRY POINTER
         LI,R5    JBBCP             ATTEMPT TO GET NEXT COMMON PAGE
         LB,R7    J:JIT,R5          GET LMAP INDEX TO BOTTOM COMMON PAGE
GPWP030  EQU      %
         LB,R11   JB:LMAP,R7        FETCH VIRTUAL LINK VALUE
         CI,R11   SADPAGE           IS PAGE A SAD PAGE(M:CVM)
         BE       %+3               B, IF SO; CAN'T USE IT FOR WINDOW
         CI,R11   APWPAGE           IS PAGE AN ASSIGNED WORK PAGE
         BNE      GPWP050           B, IF NOT; PAGE CAN BE A WINDOW
         AI,R7    -1                BACK UP TO PRECEEDING VIRTUAL PAGE
         CI,R7    JBUPVP            IS THERE ANY MORE ROOM FOR WINDOW
         BGE      GPWP030           B, IF SO; TRY FOR WINDOW HERE
GPWP040  EQU      %
         PULL     1,R1              NO, RESTORE REGISTERS AND
         LI,R11   0                 CLEAR THE ENTRY IN
         STW,R11  *R1               PWPTABLE
         PULL     6,R5              DENY THE REQUEST
         B        GPWP080           SET R10=0 AND EXIT
GPWP050  EQU      %
         MTW,1    S:PWP#            ACCOUNT FOR PAGE
         MTB,1    JB:PCP            INCREMENT PAGE COUNT OF PROCEDURE
         BAL,R11  T:GVPI            TRY TO GET THE PAGE
         B        GPWP065           NO  MORE COMMON SPACE RETURN
         BCR,15   GPWP055           WAS A PHYSICAL PAGE ALLOCATED
         LI,R6    E:NC              NO, WAIT FOR PHYSICAL PAGE
         BAL,R11  T:REG             FROM SWAP SCHEDULER
GPWP055  EQU      %
         LOAD,R8  JX:CMAP,R7        SAVE PAGE TO BE RELEASED
         MTB,-1   JB:PCP            DECREMENT PAGE COUNT OF PURE PROCEDURE
         BAL,R11  T:RVSPI           RELEASE VIRTUAL-KEEP PHYSICAL
         PULL     1,R1              RETRIEVE TABLE ENTRY POINTER
         LW,R3    R8                SAVE PAGE NUMBER FOR CALLER
         STORE,R3 *R1               SAVE PAGE NUMBER IN PWPTABLE
         SBIT,R2  PWPGP,R1          INDICSTE ENTRY FOR GPWP
GPWP060  EQU      %
         PULL     6,R5              RESTORE NON-VOLATILES FROM MM
         LW,R10   R3                LOAD OUTPUT R10 WITH PAGE NUMBER
         DISABLE                    *****INHIBIT INTERRUPTS
         MTW,1    S:STL#            BUMP STEAL COUNT
         LW,R2    S:STL#            THEN FETCH NEW COUNT
         CW,R2    SL:RSVP           HAS RESERVE LIMIT BEEN SURPASSED
         BLE      %+2               B, IF NOT; PREPARE FOR EXIT
         MTW,-1   S:ACORE           YES, TAKE PAGE AWAY FROM CURRENT USERS
         ENABLE                     *****UNINHIBIT INTERRUPTS
         B        GPWP100           AND THEN PREPARE FOR EXIT
GPWP065  MTB,-1   JB:PCP            DECREMENT PAGE COUNT OF PURE PROCEDURE
         B        GPWP040           AND GO TO CLEANUP AND EXIT
GPWP070  EQU      %
         LB,R7    JB:VLH            START AT HEAD OF USER VIRT PAGES
GPWP071  EQU      %
         CLM,R7   J:BUP             MAKE SURE PAGE IS WITHIN USER
         BCR,9    GPWP073           SPACE-- IF SO, USE IT AS WINDOW
GPWP072  EQU      %
         LB,R7    JB:LMAP,R7        IF NOT, FLINK TO NEXT, TRY AGAIN
         BEZ      GPWP040           B, IF NO MORE PAGES; TIME TO QUIT
         B        GPWP071           CONTINUE
GPWP073  EQU      %
         LOAD,R8  JX:CMAP,R7        FETCH CORRESPONDING  PHYS PAGE
         CI,R8    NPMC              MAKE SURE IT IS REALLY THERE
         BE       GPWP072           NOT YET THERE, TRY ANOTHER
         BAL,R11  T:IACU            DETERMINE THE ACCESS OF THE PAGE
         STCF     *TSTACK           AND SAVE IN PUSHED R1
         BAL,R11  T:RVSPI           FORCE VIRT SPACE BUT KEEP PHYS SPACE
         PULL     1,R1              RETRIEVE TABLE POINTER
         STORE,R8 *R1               HOLD PHYSICAL PAGE IN PWPTABLE
         SBIT,R2  PWPWIND,R1        AND SIGNIFY SAME
         PUSH     1,R1              RE-SAVE POINTER
         BAL,R11  T:GVPI            GO GET VIRTUAL PAGE FOR SURE
         NOP                        CAN'T MISS THIS TIME
         BCR,15   GPWP075           WAS PHYSICAL PAGE THERE TOO
         LI,R6    E:NC              RATS--WAIT FOR PHYSICAL PAGE
         BAL,R11  T:REG             FROM SWAP SCHEDULER
GPWP075  EQU      %
         LOAD,R8  JX:CMAP,R7        SAVE THE PAGE TO BE RELEASED
         BAL,R11  T:RVSPI           CREATE VIRT SPACE+KEEP PHYS PAGE
         PULL     1,R1              RETRIEVE POINTER AGAIN
         LOAD,R3  *R1               RETRIEVE PHYSICAL PAGE (ORIGINAL)
         STORE,R8 *R1               REMEMBER PHYSICAL PAGE (PWP)
         PUSH     1,R8              SAVE THE PAGE NUMBER
         RBIT,R2  PWPWIND,R1        INDICATE WINDOW-MAKING DONE
         SBIT,R2  PWPGP,R1          INDICATE ENTRY FOR GPWP
         LB,R8    R1                FETCH ORIGINAL ACCESS CODE
         SLS,R8   -28               AND RIGHT-JUSTIFY
         BAL,R11  T:GVGPI           INSERT ORIGINAL PAGE INTO OLD SPACE
         LI,R13   0                 TELL MM CALLER IS NOT T:SMP
         LW,R4    R8                INPUT ACCESS CODE
         BAL,R2   T:SAC             RETURN PAGE TO ORIGINAL ACCESS
         PULL     1,R3              RETRIEVE THE PAGE NUMBER
         B        GPWP060           CLEAN UP
GPWP080  EQU      %
         LI,R10   0                 SET OUTPUT R10=0 TO INDICATE FAILURE
         SPACE    2
GPWP100  EQU      %
         PULL     10,R11            RESTORE REMAINING REGISTERS
         AI,R10   0                 SET CC FOR CALLER
         B        *R11              RETURN
         PAGE
**********************************************************************
*                                                                    *
*        FPWP                                                        *
*          - FREE PHYSICAL WORK PAGE                                 *
*                                                                    *
**********************************************************************
*                                                                    *
*        ENTRY POINT                                                 *
*          FPWP                                                      *
*                                                                    *
*        INPUT                                                       *
*          R11 - RETURN ADDRESS                                      *
*          R10 - PHYSICAL PAGE NUMBER TO BE FREED                    *
*                                                                    *
*        OUTPUT                                                      *
*          R10 - ZER0, PAGE FREED                                    *
*                NON-ZERO, PAGE NOT FREED (R10 SAME AS INPUT)        *
*          CC  - INDICATE WHETHER R10 IS ZERO OR NON-ZERO            *
*                                                                    *
*                                                                    *
*        REGISTER USAGE                                              *
*          R10 MAY BE ALTERED, ALL OTHERS PRESERVED                  *
*                                                                    *
*******************************************************************  *
         SPACE    3
FPWP     EQU      %
         PUSH     10,R11            SAVE MM VOLATILES
         BAL,R0   PWPMATCH          FIND ENTRY IN PWPTABLE
         BEZ      FPWP100           NO MATCH - NOT A PWP
         TBIT,R2  PWPGP,R1          WAS IT ACQUIRED BY GPWP
         BEZ      FPWP100           NO, NOT VALID FOR FPWP
         TBIT,R2  PWPAP,R1          IS IT ALSO AN ASSIGNED WORK PAGE
         BEZ      FPWP050           NO
         RBIT,R2  PWPGP,R1          YES, FREE GPWPASSIGNMENT ONLY
         B        FPWP095           EXIT
FPWP050  EQU      %
         LW,R3    R10               SET UP INPUT TO T:RSPP
         SLS,R3   9                 GENERATE WORD ADDRESS
         LW,R10   R1                SAVE TABLE POINTER
         BAL,R11  T:RSPP            RETURN PHYSICAL PAGE TO FREE CHAIN
         LI,R3    0                 RELEASE TABLE ENTRY
         STW,R3   *R10              CLEAR AND RELEASE
FPWP090  EQU      %
         MTW,-1   S:PWP#            DECREMENT PWP COUNT
FPWP095  EQU      %
         LI,R10   0                 INDICATE GOOD RETURN
FPWP100  EQU      %
         PULL     10,R11            RESTORE REGS
         AI,R10   0                 SET CC FOR CALLER
         B        *R11              RETURN
         PAGE
******************************************************************** *
*                                                                    *
*        APWP                                                        *
*          - ASSIGN PHYSICAL WORK PAGE                               *
*                                                                    *
******************************************************************** *
*                                                                    *
*        ENTRY POINT                                                 *
*          APWP                                                      *
*                                                                    *
*        INPUT                                                       *
*          R11 - RETURN ADDRESS                                      *
*          R10 - BIT 0,ZER0; BITS 1-31,PHYSICAL PAGE TO BE ASSIGNED  *
*                BIT 0,ONE; BITS 1-31, VIRTUAL ADDRESS OF A WORD     *
*                                      IN THE PAGE TO BE ASSIGNED    *
*                                                                    *
*        OUTPUT                                                      *
*          R10 - ZERO, PAGE ASSIGNED                                 *
*                NON-ZERO, REQUEST NOT SATISIFIED                    *
*                          BIT 0 - ZERO, PHYSICAL WORK PAGE          *
*                                        LIMIT REACHED               *
*                                  ONE, PAGE/ADDRESS NOT OWNED       *
*                                       BY USER                      *
*                          BITS 1-31 - PRESERVED FROM INPUT R10      *
*          CC  - INDICATE WHETHER R10 IS ZERO OR NON-ZERO            *
*                                                                    *
*        REGISTER USAGE                                              *
*          R10 ALTERED, ALL OTHERS PRESERVED                         *
*                                                                    *
*******************************************************************  *
         SPACE    3
APWP     EQU      %
         PUSH     10,R11            SAVE MM VOLATILES
         PUSH     1,R8              MUST SAVE R8 ALSO
         PUSH     1,R10             SAVE INPUT REGISTER
         LW,R1    S:PWP#            CHECK AGAINST PWP LIMIT
         CW,R1    SL:PWP
         BGE      APWP090           ALLOW NO MORE
         LI,R8    APWP005           SET EXIT TO SEARCH FOR PAGE
         AI,R10   0                 IS INPUT PAGE NUMBER OR ADDRESS
         BGEZ     APWP003           BRANCH IF INPUT IS PAGE NUMBER
         LI,R8    APWP020           SET BRANCH TO AVOID MAP SEARCH
         AND,R10  MASKS+17          REMOVE EXTRANEOUS BITS
         SLS,R10  -9                GENERATE VIRTUAL PAGE NUMBER
         CLM,R10  J:BUP             IS VIRT PAGE WITHIN USER
         BCS,9    APWP085           NO, ERROR
         LW,R2    R10               USE INDEX REGISTER
         LOAD,R10 JX:CMAP,R2        TRANSLATE VIRTUAL PAGE TO PHYSICAL
APWP003  EQU      %
         CI,R10   FPMC              IS IT AFREE PAGE
         BE       APWP085           YES, DON'T ALLOW APWP
         CI,R10   NPMC              IS PAGE PHYSICALLY THERE
         BE       APWP085           NO, DON'T ALLOW APWP
*        CHECK DPMC
         B        *R8               BRANCH TO APPROPRIATELY CONTINUE
APWP005  EQU      %
         LI,R2    JBUPVP            SEARCH FOR PAGE IN
APWP010  EQU      %
         COMPARE,R10 JX:CMAP,R2     USER AREA OF MAP
         BE       APWP020           FOUND IT
         CW,R2    J:EUP             IS THERE STILL A CHANCE FOR MATCH ?
         BG       APWP085           NO WAY -- QUIT
         AI,R2    1                 STEP TO NEXT PAGE
         B        APWP010           AND CONTINUE SEARCH
APWP020  EQU      %
         LB,R8    JB:LMAP,R2        FETCH LINK VALUE
         LW,R11   R2                SAVE LMAP INDEX FOR LATER
         CI,R8    SADPAGE           CHECK FOR SAD (CVM) PAGE
         BE       APWP085           SAD PAGE CANNOT BE ASSIGNED
         DISABLE
         BAL,R0   PWPMATCH          SEARCH FOR EXISTENCE OF PAGE AS PWP
         BEZ      APWP025           NO MATCH
         CI,R8    APWPAGE           ALREADY APWP FOR THIS USER
         BNE      APWP030
         LW,R0    0,R1              GET ENTRY
         CW,R0    X20               CHECK FOR PWPCLK SET
         BAZ      %+3               B, IF NOT; JUST BUMP COUNT
         AND,R0   =X'FFFF00DF'      ELSE, CLEAR PWPCLK & USRN/ACT FIELDS
         STW,R0   0,R1              AND RESTORE ENTRY
         MTBYTE,1,R2 PWPACNT,*R1    YES, JUST INCREASE COUNT
         ENABLE
         B        APWP040           AND EXIT GRACEFULLY
APWP025  EQU      %
         ENABLE
         BAL,R0   PWPENTRY          NO MATCH, OBTAIN A NEW ENTRY
         BEZ      APWP100           NO ENTRY, QUIT
         STORE,R10 *R1              SAVE PAGE NUMBER IN PWPTABLE
APWP030  EQU      %
         SBIT,R2  PWPAP,R1          SIGNIFY PAGE IS APWP
         MTBYTE,1,R2 PWPACNT,*R1    INCREMENT ASSIGN COUNT
         ENABLE
         LW,R3    R11               RETRIEVE VIRTUAL PAGE INDEX
         LI,R2    0                 SAVE
         SCD,R2   -4                 ACCESS
         SCS,R2   5                   PROTECTION
         LW,R3    J:JAC,R3
         SLD,R2   2,R2
         AND,R2   M2
         PUSH     6,R5              SAVE REGS USED BY MM
         PUSH     1,R1              SAVE PWP POINTER
         PUSH     1,R2              SAVE AC
         LW,R7    R11               RETRIEVE VIRTUAL PAGE INDEX
         LOAD,R8  JX:CMAP,R7        RETAIN PHYSICAL PAGE NUMBER
         BAL,R11  T:RVSPI           RELEASE VIRT - KEEP PHYSICAL
         LW,R6    R8                INPUT PAGE NUMBER TO T:SAD0
         PULL     1,R8              RETRIEVE ACCESS PROTECTION
         BAL,R11  T:SAD0            INSERT APWP
         PULL     1,R1              RETRIEVE PWP POINTER
         PULL     6,R5              RESTORE REGS
         MTW,1    S:PWP#            INCREMENT PWP COUNT
         LBYTE,R2,R3 PWPACNT,*R1    IF ASSIGN COUNT >1 OR PAGE
         CI,R2    1                 IS ALREADY GPWP THEN PAGE
         BG       APWP040           NEED NOT BE ACCOUNTED FOR
         TBIT,R3  PWPGP,R1          AGAIN IN PAGE STEALING TABLES
         BNEZ     APWP040
         MTW,1    S:STL#            ACCOUNT FOR THIS PAGE
         LW,R1    S:STL#            FETCH CURRENT STOLEN PAGE COUNT
         CW,R1    SL:RSVP           HAS RESERVED COUNT BEEN EXCEEDED
         BLE      APWP040           NO
         MTW,-1   S:ACORE           TAKE PHYS PAGE AWAY FROM ALL USERS
APWP040  EQU      %
         PULL     1,R10             RETRIEVE ORIGINAL INPUT
         LI,R10   0                 INDICATE GOOD RETURN
         B        APWP100           EXIT
APWP085  EQU      %
         PULL     1,R10             RETRIEVE ORIGINAL INPUT
         OR,R10   Y8                INDICATE ERROR RETURN
         B        APWP100
APWP090  EQU      %
         PULL     1,R10             RETRIEVE ORIGINAL INPUT
         AND,R10  NB31TO0+32        RESET BIT ZERO
APWP100  EQU      %
         PULL     1,R8              RETURN R8 TO INPUT STATE
         PULL     10,R11            RESTORE REMAINING REGS
         AI,R10   0                 SET CC FOR CALLER
         B        *R11              RETURN
         PAGE
*******************************************************************  *
*                                                                    *
*        RPWP                                                        *
*          - RELEASE PHYSICAL WORK PAGE                              *
*                                                                    *
*******************************************************************  *
*                                                                    *
*        INPUT                                                       *
*          R11 - RETURN ADDRESS                                      *
*          R10 - BIT 0, ZER0; BITS 1-31, PHYSICAL PAGE NUMBER        *
*                                        TO BE RELEASED              *
*                BIT 0, ONE; BITS 1-31, PHYSICAL ADDRESS OF A        *
*                                       WORD IN THE PAGE TO BE       *
*                                       RELEASED                     *
*          R9  - USER NUMBER                                         *
*                                                                    *
*        OUTPUT                                                      *
*          R10 - ZERO,ASSIGNMENT RELEASE ACCEPTED                    *
*                NON-ZERO, PAGE NOT REFERENCED BY APWP               *
*          CC  - INDICATE WHETHER R10 IS ZERO OR NON-ZERO            *
*                                                                    *
*        REGISTER USAGE                                              *
*          R10 ALTERED, ALL OTHERS PRESERVED                         *
*                                                                    *
*******************************************************************  *
         SPACE    3
RPWP     EQU      %
         PUSH     4,R0              SAVE REGS
         AI,R10   0                 DETERMINE TYPE OF INPUT
         BGEZ     RPWP005           PAGE NUMBER
         AND,R10  NB31TO0+32        WORD ADDRESS, REMOVE BIT
         SLS,R10  -9                AND CREATE PAGE NUMBER
RPWP005  EQU      %
         BAL,R0   PWPMATCH          FIND ENTRY INPWPTABLE
         BEZ      RPWP100           NOT THERE, CAN'T BE APWP
         TBIT,R2  PWPAP,R1          WAS IT ASSIGN WORK PAGE BLOCK
         BEZ      RPWP100           NO, QUIT
         MTBYTE,-1,R2 PWPACNT,*R1   DECREMENT ASSIGN COUNT FOR THIS PAGE
         BNEZ     RPWP090           STILL IN USE, DON'T RELEASE PAGE YET
         TBIT,R2  PWPGP,R1          IS IT A GPWP ALSO
         BEZ      RPWP020           NO
         RBIT,R2  PWPAP,R1          YES, REMOVE ASSIGN WP STATUS
         B        RPWP090           BUT DON'T FREE PAGE
RPWP020  EQU      %
         LW,R3    R1                SAVE TABLE ENTRY POINTER
         MTH,0    CO:INTFL          SEE IF WE'VE INTERRUPTED COC CODE
         BNEZ     %+3               B, IF SO; DEFER REQUEST
         BAL,R1   ECBGBLK           GET A DO-LIST BLOCK
         BNEZ     RPWP040           WAS A BLOCK AVAILABLE
         SBIT,R2  PWPCLK,R3         LET CLOCK4 DO THE RELEASE
         SBYTE,R9,R2 PWPUSRN,*R3    STORE USER NUMBER IN TABLE ENTRY
         B        RPWP090           QUIT
RPWP040  EQU      %
         LI,R0    RPWPBLK           SET UP DO-LIST BLOCK
         SFIELD,R0 RPWPTYPE,R2      EXIT ADDRESS TYPE
         LI,R1    RPWPEA            EXIT ADDRESS
         STW,R1   RPWPEADR(I),R2    INTO BLOCK
         SHW,R10,R1 RPWPAGE,*R2     PAGE NUMBER INTO BLOCK
         STW,R3   RPWPTABL(I),R2    STORE TABLE ENTRY POINTER
         LW,R1    R9                USER NUMBER INTO XR
         DISABLE
         LH,R0    UH:DL,R1          FETCH HEAD OF DO-LIST
*        WATCH FOR FLAGS IN B00
         SHW,R0,R3 RPWPLINK,*R2     CHAIN BLOCK ONTO
         SLS,R2   -1                DO-LIST FOR THIS USER
         STH,R2   UH:DL,R1          FOR ENTRY INTO RPWPEA BY SSS
         ENABLE
RPWP090  EQU      %
         LI,R10   0                 INDICATE GOOD RETURN
RPWP100  EQU      %
         PULL     4,R0              RESTORE REGS
         AI,R10   0                 SET CC FOR CALLER
         B        *R11              RETURN
         SPACE    3
RPWPEA   EQU      %
         PUSH     4,R1
         LD,R2    2,R5              FETCH DATA WORDS IN DO-LIST BLOCK
         SLS,R2   -16               RIGHT JUSTIFY PAGE NUMBER
         LI,R1    JBUPVP            START AT BEGINNING OF USER AREA
RPWPE03  EQU      %
         COMPARE,R2 JX:CMAP,R1      AND SEARCH MAP FOR THIS PHYSIACL
         BE       RPWPE05           PAGE, IF FOUND GO FREE IT
         CW,R1    J:EUP             CK IF END OF USER'S VP#S
         BGE      RPWPE80           PAGE NOT IN JX:CMAP ANY MORE
         AI,R1    1                 STEP TO NEXT MAP PAGE
         B        RPWPE03           AND COMTINUE SEARCH
RPWPE05  EQU      %
         PUSH     12,R5             NO REGISTERS VOLATILE
         LW,R7    R1                SET INPUT TO MM
         LB,R1    JB:LMAP,R7        CHECK FOR APWP
         CI,R1    2                 FLAG IN LMAP
         BNE      RPWPE10           NOT APWP
         DISABLE
         MTBYTE,0,R1 PWPACNT,*R3    TEST FOR APWP IN INTERIM
         BEZ      RPWPE07           IF NO APWP LET PAGE GO
         ENABLE
         B        RPWPE08           CONCURRENT APWP HAS OCCURRED
RPWPE07  EQU      %
         LI,R8    FPMC              FREE
         STORE,R8 JX:CMAP,R7        THE
         LI,R8    0                 VIRTUAL
         STB,R8   JB:LMAP,R7        PAGE
         STW,R8   *R3               CLEAR PWPTABLE ENTRY
         ENABLE
         LW,R8    R3                SAVE PWPTABLE POINTER
         LW,R3    R2                INPUT PHYSICAL PAGE NUMBER TO MM
         MTB,1    JB:PCP            **ALLOW RPWP TO PASS T:TOTESZ TESTS
         BAL,R11  T:GVGPI           INSERT PHYSICAL PAGE BACK INTO USER
         MTB,-1   JB:PCP            **COME BACK DOWN TO REALITY
RPWPE08  EQU      %
         BAL,R3   PWPCLNUP          CLEAN UP FOR PAGE STEALING
RPWPE10  EQU      %
         PULL     12,R5             RESTORE REGS
         B        RPWPE90           CONTINUE EXIT
RPWPE80  EQU      %
         XW,R2    R3                SET UP INPUT
         SLS,R3   9                 TO
         LW,R1    R11               FREE THE PAGE
         BAL,R11  T:RSPP            LET THE PAGE GO
         LW,R11   R1                RESTORE LINK REGISTER
         MTW,-1   S:PWP#            DECREMENT PWP COUNT
         LI,R1    0                 CLEAR PWPTABLE ENTRY
         STW,R1   *R2
RPWPE90  EQU      %
         PULL     4,R1
         B        T:DOLISTR         RETURN TO SCHEDULER
         SPACE    3
RPWPCLK  EQU      %                 ENTRY POINT FOR CLOCK RELEASE
         MTH,0    CO:INTFL          SEE IF WE'VE INTERRUPTED COC CODE
         BNEZ     *R11              B, IF SO; TRY AGAIN NEXT TIME
         PUSH     3,R9              SAVE RETURN
         LI,R8    PWPEND-PWPTABLE+2 LENGTH OF PWPTABLE PLUS ONE
         LW,R3    R8                START AT END OF
         AI,R3    PWPTABLE-1        PHYSICAL WORK PAGE TABLE
RPWPC10  EQU      %
         BDR,R8   %+2               GO TO NEXT ENTRY, IF ANY
         B        RPWPC90           NO MORE ENTRIES, ALL DONE
         AI,R3    -1                MOVE TO NEXT PWP ENTRY
         TBIT,R11 PWPCLK,R3         ENTRY WAITING FOR CLOCK RELEASE
         BEZ      RPWPC10           NO, GO TO NEXT ENTRY
         PUSH     4,R0              SAVE REGS USED IN RPWP
         BAL,R1   ECBGBLK           TRY FOR WORK BLOCK NOW
         BNEZ     RPWPC20           IF BLOCK AVAILABLE, CONTINUE
         PULL     4,R0              ELSE, CLEANUP AND
         B        RPWPC10           GO TO NEXT ENTRY
RPWPC20  EQU      %
         RBIT,R11 PWPCLK,R3         REMOVE NEED FOR CLOCK RELEASE
         LBYTE,R9,R1 PWPUSRN,*R3    FETCH USER NUMBER
         LI,R11   0
         STB,R11  *R3,R1            CLEAR USRN/ACT FIELD
         LOAD,R10 *R3               FETCH PAGE NUMBER
         BAL,R11  RPWP040           QUEUE THE PAGE FOR RELEASE
         B        RPWPC10           CONTINUE TO NEXT ENTRY
RPWPC90  EQU      %
         PULL     3,R9              RETURN ADDRESS
         B        *R11              GO BACK
         PAGE
PWPCLNUP EQU      %
         MTW,-1   S:PWP#            DECREMENT PWP COUNT
         MTW,-1   S:STL#            DECREMENT STOLEN PAGES
         LW,R1    S:STL#            FETCH CURRENT STOLEN PAGE TALLY
         CW,R1    SL:RSVP           CHECK STOLEN PAGES AGAINST RESERVED PAGES
         BL       *R3               BELOW LIMIT, ALL DONE
         MTW,1    S:ACORE           CAN NOW ALLOW ONE PAGE FOR USERS
         LW,R1    S:STLC            COMPARE CURRENT STEAL LIMIT
         CW,R1    SL:STLM           AGAINST MAXIMUM
         BGE      *R3               IF THERE, ALL DONE
         MTW,1    S:STLC            OTHERWISE ALLOW ANOTHER PAGE FOR STEALING
         B        *R3               RETURN
         SPACE    3
PWPENTRY EQU      %
         LI,R1    PWPTABLE          START AT ORIGIN OF PWPTABLE
         DISABLE
PWPE005  EQU      %
         TBIT,R2  PWPACT,R1         IS ENTRY IN USE
         BNEZ     PWPE010           YES
         LW,R2    PWPACT(M)         CLEAR ENTRY AND
         STW,R2   *R1               SET ACTIVE FLAG
         ENABLE
         AI,R1    0                 SET CC FOR EXIT
         B        *R0               RETURN
PWPE010  EQU      %
         CI,R1    PWPEND            END OF TABLE AREA
         BGE      PWPE020           YES
         AI,R1    1                 NO, STEP TO NEXT ENTRY
         B        PWPE005           AND CONTINUE SEARCH
PWPE020  EQU      %
         ENABLE
         LI,R1    0                 INDICATE NO ENTRY AVAILABLE
         B        *R0               AND EXIT
         SPACE    3
PWPMATCH EQU      %
         LI,R1    PWPTABLE          START AT ORIGIN OF TABLE
PWPM005  EQU      %
         COMPARE,R10 *R1            DOES ENTRY PAGE MATCH INPUT PAGE
         BE       PWPM010           YES
         CI,R1    PWPEND            END OF TABLE
         BL       PWPM020           NO
         LI,R1    0                 YES, SIGNIFY NO MATCH
PWPM010  EQU      %
         AI,R1    0                 SET CC FOR CALLER
         B        *R0               RETURN
PWPM020  EQU      %
         AI,R1    1                 STEP TO NEXT ENTRY
         B        PWPM005           AND CONTINUE SEARCH
         SPACE    2
         END

