         DEF      MMNR
         SYSTEM   UTS
MMNR     EQU      %
*
         PAGE
         REF      FPMC
         REF      J:BASE,J:BUP,J:DCBLL,J:DDLL
         REF      J:DDUL,J:DLL,J:EUP,J:PLL,J:PUL
         REF      JX:CMAP,M17,M8,S:CUN,T:GBUF
         REF      T:RBUF,T:REG,T:RVPI,TRAPEXIT
         REF      UH:FLG,Y8
         DEF      T:GCP,T:FCP
         DEF      T:GDP,T:FDP
         DEF      T:GL
         DEF      T:GVP,T:FVP
         DEF      T:SMP
         DEF      T:SAD
J        EQU      BA(J:JIT)
         REF      CALBAD
         REF      E:NC
         REF      J:JAC
         REF      J:JIT
         REF      JB:LMAP
         REF      JB:PRIV
         REF      JB:TDP
         REF      JBBCP
         REF      JBTDP
         REF      JBUPVP
         REF      JCO2VPA,JOVVP
         REF      JSBUF1VP
         REF      JSBUF2VP
         REF      M13
         REF      PAGEZAP
         REF      RTCHK
         REF      RTERR
         REF      SBUF1VPA,SPDBASE
         REF      T:GVPI
         REF      T:SAC
         REF      T:SACP1
         REF      T:SXACM3
         REF      T:SXMAPM3
         REF      T:XMMC
         REF      YC
         PAGE
*************************************
*        GET DYNAMIC PAGES          *
*        IE GET PAGES               *
*************************************
*        GET COMMON DYNAMIC PAGES   *
*        IE GET COMMON PAGES        *
*************************************
*        GET VIRTUAL PAGE           *
*************************************
*        5  = TOP OF DYN OR BOTTOM OF COMMON
*   I    6  = # OF PAGES TO ACQUIRE
*        7  = PG # TO REQUEST
*   O    8  = # OF PAGES ACQUIRED
*   O    9  = 1ST PAGE ACQUIRED
*        10 = INCR OR DECR FOR NEXT PAGE
*        11 = LINK
*        12 = CC
*        13   CC MASK
*
T:GDP    EQU      %
*  SET UP FOR DYNAMIC
         PUSH     7,5
         LI,10    1                 REQUESTS FOR DYNAMIC PGS INCREASE
         LI,5     J+JBTDP
         LB,7     JB:TDP             PG # OF NXT DYN PG TO REQ
         B        GAP1
T:GCP    EQU      %
*  SET UP FOR COMMON DYNAMIC
         PUSH     7,5
         LI,10    -1                REQUESTS FOR COMMON DYN PGS DECREASE
         LI,5     J+JBBCP
         LB,7     0,5               PG # OF NEXT COM PG TO REQUEST
         B        GAP1
T:GVP    EQU      %
*  SET UP FOR GET A VIRTUAL PAGE
         PUSH     7,5
         LI,10    0
         LI,5     20                BA(REG 5) TO KAE UPDATE NXT PG INST
         LW,7     6                 VP ADR REQUESTED
         SLS,7    -9                VP #
         LI,6     1                 # OF PGS TO ACQUIRE
        AND,7    M8
*  SET UP TO GET ALL PAGES
GAP1     EQU      %
         BAL,1    RTCHK             CHECK IF THIS USER IS A REAL-TIME
*                                   USER WHO HAS LOCKED HIMSELF IN CORE
         BCS,4    RTCHKERR          YES, HE IS; ABORT HIM
         LI,8     0
         LW,9     7
         AND,6    M17
         BEZ      GAP4-2
*  GET VIRTUAL PG
GAP2     EQU      %
         BAL,11   T:GVPM            GET VIRTUAL PG
*  ERRORS RETURN TO BAL+1
*  BOTH NORMAL & NO PHY RETURN TO BAL+2
         B        GAP4              SOME ERROR OCCURRED - CC ALREADY SET
         BCR,15   GAP3              OBTAINED PHY PG - SKIP SETTING FLAG
         STB,7    9                 COULDN'T GET PHY - SET FLAG & CONT
*  PREPARE TO GET MORE
GAP3     EQU      %
         AW,7     10                UPDATE TO NEXT PG TO REQUEST
         AI,8     1                 UPDATE # OF PGS ACQUIRED
         BDR,6    GAP2              GET REST OF PGS
         LI,12    0                 SET CC TO OR
         B        GAP4+1
*  GOT ALL VIRTUAL PAGES - WHAT ABOUT PHY
GAP4     EQU      %
         LI,12    -1
         STB,7    0,5               UPDATE TDP OR BCP TO LAST ACQUIRED+1
         LB,11    9                 IS FLAG SET,11E VIRTUAL NO PHYSICAL
         BEZ      GAP5              NO
         LI,6     E:NC              NO CORE EVENT #
         BAL,11   T:REG
         AND,9    M17
*  PREPARE TO RETURN TO USER
GAP5     EQU      %
         LW,6     8                 GET # GOTTEN
         BAL,5    PAGEZAP           ZAPEM
         AI,10    0                 10 HAS BEEN SHIFTED NOW
         BEZ      SAD3              BUT SING IS THE SAME
         BGZ      %+3
         SW,9     8
         AI,9     1
         LW,1     TSTACK
         SLS,9    9
         STW,9    -X'D',1
         B        RAP5P1
RTCHKERR EQU      % ***************************************************
*                 THIS ROUTINE IS CALLED TO ABORT A REAL-TIME USER
*                 WHO HAS ISSUED A 'GET PAGE' TYPE OF CAL1 AFTER HAVING
*                 LOCKED HIMSELF IN CORE
*
         PULL     7,5               RESTORE STACK
         LW,14    RTERR             ABORT CODE
         B        CALBAD            ALTCP ERROR EXIT
         PAGE
***************************************
*        FELEASE DYNAMIC PAGES        *
***************************************
*        FELEASE COMMON DYNAMIC PAGES *
***************************************
*        FELEASE VIRTUAL PAGE       *
*************************************
*
*        5  = ADR OF TOP OF DYN OR BOTTOM OF COMMON
*   I    6  = # OF PGS TO RELEASE
*        7  = PG # TO RELEASE
*   O    8  = # OF PAGES RELEASED
*   O    9  = 1ST PG RELEASED
*        10 = INCR OF DECR FOR NEXT PAGE
*        11 = LINK
*        12 = CC
*        13 = CC MASK
*
T:FDP    EQU      %
*  SET UP FOR DYNAMIC
         PUSH     7,5
         LI,10     -1               DECR TO RELEASE DYN PGS
         LI,5     J+JBTDP
         LB,7     JB:TDP             PG # & 1 TO REL
         B        RAP1
T:FCP    EQU      %
*  SET UP FOR COMMON DYNAMIC
         PUSH     7,5
         LI,10    1                 INCR TO RELEASE COM PGS
         LI,5     J+JBBCP
         LB,7     0,5             PG # -1 TO REL
         B        RAP1
T:FVP    EQU      %
*  SET UP TO RELEASE A VIRTUAL PAGE
         PUSH     7,5
         LI,10    0
         LI,5     20                BA(REG 5)
         LW,7     6                 VP ADR
         SLS,7    -9                VP # TO REL
         LI,6     1                 # OF PGS TO RELEASE
*  SET UP TO RELEASE ALL PAGES
RAP1     EQU      %
         LI,12    0
         LI,8     0                 # OF PGS RELEASED
         AND,6    M17
         BEZ      RAP5
         AW,7     10                INCR OR DECR TO 1ST PG TO RELEASE
         AND,7    M8
         LW,9     7                 SAVE 1ST PG TO RELEASE
*  RELEASE VIRTUAL PG
RAP2     RES      0
         LI,12    FPMC              CHK TDP >=VP<=BCP
         COMPARE,12 JX:CMAP,7
         BE       RVP0
         CLM,7    J:BUP
         BCS,9    RVP0
         LB,4     JB:LMAP,7         FETCH VIRTUAL LINKING VALUE
         CI,4     1                 IS IT A SAD PAGE
         BE       RAP2M             YES
         CI,4     2                 IS IT APWP
         BNE      RVP0              NO
         LI,12    -1                DON'T RELEASE APWP
         B        SAD3              EXIT
RAP2M    EQU      %
         LI,4     3                 R4 MUST BE ONE FOR SAD PAGE RLS
         LI,1     128               BELOW PPUT, CHK SAD RELEASE
         CB,1     JB:PRIV
         BLE      RAP2E
         SUA      X'6A'
RAP2E    EQU      %
         STORE,12 JX:CMAP,7
         BAL,2    T:SAC
         BAL,11   T:SXACM3
         BAL,11   T:SXMAPM3
         LI,12    0
         B        SAD3
RAP2P    RES      0
         B        RAP4              SOME ERROR OCCURRED - CC ALREADY SET
*  PREPARE TO RELEASE MORE
         AW,7     10                UPDATE TO NEXT PG TO REL
         AI,8     1                 # OF PG REL
         BDR,6    RAP2              REL REST
         LI,12    0                 SET CC TO 0
         B        RAP4+1
*  PREPARE TO RETURN TO USER
RAP4     EQU      %
         LI,12    -1
         SW,7     10                UPDATE TO NEXT PG TO ACQ
         STB,7    0,5               UPDATE TDP OR DCP TO LAST REL
RAP5     EQU      %
         LW,1     TSTACK
RAP5P1   RES      0
         STW,8    -X'E',1
         B        SAD3
         PAGE
*        GET LIMITS ON COMMON
*  O     8  = ADR OF 1ST WD ALLOC
*  O     9  = ADR OF LAST WD ALLOC (WITHOUT MORE GET PG CALS
T:GL     EQU      %
         LI,1     J+JBBCP
         LB,8     0,1               NXT PG #
         AI,8     1                 LAST PG OBTAINED
         LW,9     J:DDUL            UPPER LIMIT - 1ST PG EVER OBTAINED
         SLD,8    9
         AI,9     X'1FF'
         AI,8     -1
         CW,8     9                 TOP & BOTTOM LIMITS =
         BE       %+2               YES
         AI,8     1                 NO - RESTORE BOTTOM TO 1ST WD OF PG
         LW,1     TSTACK
         STW,8    -7,1
         STW,9    -6,1
         B        TRAPEXIT
         PAGE
*************************************
*        SET MEMORY PROTECT         *
*************************************
*        6  = ADR OF 1ST PG
*        7  = POINTS TO FPT+1
*             (VALUE & ADR OF LAST PG)
T:SMP    EQU      %
         PUSH     7,5
         BAL,11   GETARG2           GET USER'S SECOND ARGUMENT INTO R7
         SLS,6    -9
         AND,6    M8
         XW,6     7                 7 = 1ST VP #
         LB,4     6                 AC
         SLS,6    -9
         AND,6    M8                6 = LAST VP #
         LI,10    0
         LI,13    -2                SET FLG FOR SMP CAL
         LI,14    FPMC
SMP4     EQU      %
         LI,2     SMP4P
         CLM,7    J:BUP
         BCS,9    SMP7
         COMPARE,14 JX:CMAP,7       DOES USER HAVE PAGE
         BE       SMP7
         LB,1     JB:LMAP,7         IS THIS A SAD PAGE
         CI,1     1
         BNE      T:SACP1           NO,SET MPRT
SMP7     RES      0
         OR,10    X80
SMP4P    RES      0
         AI,7     1
SMP6     RES      0
         CW,7     6                 MORE PGS TO DO
         BLE      SMP4              YES
         LW,4     S:CUN
         REF      T:XMMC1
         BAL,1    T:XMMC1
         LW,13    YC
         STB,10   12                SET UP CC IN REG 12
         B        SAD4
         PAGE
*************************************
*        GET VIRTUAL PAGE           *
*        MASTER                     *
*************************************
*   I    7  = VP # REQUESTED
*        3  = PP #
*        15 = DA
*        0  = UH:FLG
*        1  = INDEXING
*        2  = FOR SUBR
*        4  = INDEX ADR
*        6  = EVENT # (PUSHED)
*        11 = EXIT & INTERNAL SUBR LINK (PUSHED)
*        12 = ACCUM
*        13 = FOR SUBR
*        14 = FOR SUBR
*        5  = NEG IF NO PHY PGS DESIRED
*
T:GVPM   EQU      %
*  TEST WHETHER REQUESTED VP IS WITHIN PROGRAM LIMITS
         CI,5     20                GVP REQ
         BNE      GVP1              NO
         LB,12    JB:TDP
         LI,4     J+JBBCP
         LB,13    0,4
         CLR,12   7
         BCR,6    T:GVPI
         CW,7     J:PUL             ABOVE PURE P
         BLE      %+3               NO
         CW,7     J:EUP             LESS THAN END OF PROG
         BLE      T:GVPI            YES - OK
         CLM,7    J:DLL             IS IT IN DATA
         BCS,9    GVP9              NO, CHECK IF WINDOW PAGE AND SPEC
         B        T:GVPI            PROC WITH SJAC
GVP1     EQU      %
         CLM,7    J:DDLL            IN DATA
         BCS,9    GAP4
         B        T:GVPI
         PAGE
*
*        GET SPECIAL BUFFER PAGE FOR GVP CAL BY PROCESSOR
*
GVP9     LW,4     S:CUN
         LH,12    UH:FLG,4
         CI,12    SJAC              IF NO JIT ACCESS IT IS A BAD CAL
         BAZ      GAP4
         CI,7     JSBUF1VP
         BE       GVP9A             SPECIAL BUFFER #1
         CI,7     JSBUF2VP
         BE       GVP9A             SPECIAL BUFFER #2
         CLM,7    J:BUP             ALLOW TEL TO GET ANY USER PAGE
         BCS,9    GAP4              NOT A USER PAGE
         B        T:GVPI            GET IT..
*
GVP9A    EQU      %
         LW,14    7
         SLS,14   9                 CONVERT TO PAGE ADDRESS
         BAL,2    T:GBUF            GET BUFFER PAGE
         LI,12    0                 ASSUME NO ERROR
         LW,4     10                SAVE BUFFER INDEX
         BNEZ     SAD3              GOOD RETURN IF NON-ZERO
         LI,12    -1                SET CC IF NO BUFFER AVAILABLE
         B        SAD3
         PAGE
*************************************
*        FELEASE VIRTUAL PAGE       *
*        MASTER                     *
*************************************
RVP0     EQU      %
         CI,5     20                IS THIS A FVP REQUEST
         BNE      RVP1              NO
         CLM,7    J:BUP             IS IT A USER PAGE.
         BCS,9    RAP9              NO...
         CLM,7    J:PLL             IS IT PROCEDURE
         BCR,9    RAP4              YES. DON'T RELEASE IT.
         CLM,7    J:DCBLL           IS IT A DCB PAGE
         BCR,9    RAP4              YES.
         B        T:RVPIM           IT'S COOL.
RVP1     EQU      %
         CLM,7    J:DDLL            IN DATA AREA
         BCS,9    RAP4
T:RVPIM  LI,11    RAP2P
         B        T:RVPI
         PAGE
*
*        RELEASE SPECIAL BUFFER PAGE FOR M:FVP CAL BY PROCESSOR
*
RAP9     LW,4     S:CUN
         LH,12    UH:FLG,4
         CI,12    SJAC
         BAZ      RAP4              MUST HAVE SJAC AND PROPER VIRTUAL
         CI,7     JSBUF1VP          PAGE NUMBERS
         BE       %+3
         CI,7     JSBUF2VP
         BNE      RAP4
         LW,14    7                 SET UP VP# ARG
         SLS,14   9                 CONVERT TO PAGE ADDRESS
         PUSH     7,5
         LI,5     0                 RELEASE EVERYTHING
         BAL,2    T:RBUF
         PULL     7,5
         B        RAP2P+1           EXIT
         PAGE
*************************************
*        SEARCH AND DISPLAY         *
*************************************
*        6  = PP ADR TO BE PLACED IN SPECIFIED VP
*        7  = FPT+1 ADR
*        FPT+1 = VP ADR INTO WHICH PP IS TO BE MAPP
*
T:SAD    EQU      %
         PUSH     11
         LI,11    SAD2              BUILD RETURN FROM RESIDENT
         PUSH     7,5
         BAL,11   GETARG2           GET USER'S SECOND ARGUMENT INTO R7
         LI,12    -1                FOR ERRORS
         LB,8     JB:PRIV
         AI,8     -X'80'
         LI,4     1                 INDICATE SAD ENTRY AND LMAP CONSTANT
         SLD,6    -9                ADRS TO +S
         B        T:SAD1            DO RESIDENT PORTION OF SAD
SAD2     PULL     11                RETRIEVE RETURN
         PUSH     7,5               BALANCE STACK
         REF      T:SAD1
SAD3     LW,13    Y8
SAD4     LI,1     X'FFFFE'
         AND,1    TSTACK
         STS,12   -24,1             SET CC
SAD5     PULL     7,5
IACU7    LC       11                FOR IACU & GNVPI
         B        *11
*
*  LOAD USER'S SECOND ARGUMENT INTO R7
*
GETARG2  LW,7     0,7               L/WD 1 OF FPT
         BGEZ     *11               BGEZ; NOT INDIRECT, RETURN
         CI,7     X'1FFF0'          C/ADR W/X'1FFF0'
         BANZ     %+2               BANZ; ARG NOT IN REGISTER
         AW,7     J:BASE            +J:BASE; ARG IN REG, LOAD FROM TSTACK
         LW,7     0,7               L/ARG
         B        *11               RETURN
         END

