*M*      PPS      PHYSICAL PAGE STEALER GHOST JOB
*P*
*P*      NAME:    PPS
*P*
*P*      PURPOSE: TO PROVIDE FOR DYNAMIC ALLOCATION AND DEALLOCATION
*P*               OF REAL-TIME MEMORY PAGES.
*P*
*P*      DESCRIPTION:  PHYSICAL PAGES ARE MADE AVAILABLE FOR REAL-TIME
*P*               PROCESSING IN EITHER OF TWO WAYS:
*P*
*P*               1)  DEDICATION OF PHYSICAL CORE PAGES AT BOOT TIME.
*P*                   THESE PAGES ARE KNOWN AS THE RESIDENT FOREGROUND
*P*                   PAGES (RESDF).  SYSGEN PARAMETERS DEFINE THE
*P*                   PHYSICAL PAGES THAT ARE TO BE REMOVED FROM THE
*P*                   SYSTEM AND DEDICATED TO REAL-TIME.  THESE PAGES
*P*                   REMAIN DEDICATED UNTIL RETURNED TO THE SYSTEM
*P*                   BY PPS.
*P*
*P*               2)  DYNAMIC ACQUISITION AND RELEASE OF PHYSICAL CORE
*P*                   PAGES DURING NORMAL OPERATIONS.  THESE PAGES ARE
*P*                   KNOWN AS THE DYNAMIC RESIDENT FOREGROUND PAGES
*P*                   (DYNRESDF).  THE OPERATOR CAN ACQUIRE OR RELEASE
*P*                   DYNRESDF PAGES VIA COMMUNICATION WITH PPS.
*P*
*P*               IN BOTH CASES, FOREGROUND MEMORY IS ALLOCATED IN MEMORY
*P*               SEGMENTS.  A MEMORY SEGMENT IN THIS CONTEXT IS SIMPLY
*P*               A SET OF CONTIGUOUS PHYSICAL PAGES.  THERE IS ONLY
*P*               ONE RESDF MEMORY SEGMENT, THAT WHICH IS ALLOCATED
*P*               AT BOOT TIME.  THERE MAY BE SEVERAL DYNRESDF SEGMENTS,
*P*               THE MAXIMUM NUMBER OF WHICH IS SPECIFIED AT SYSGEN
*P*               TIME.  ALL MEMORY SEGMENTS MUST BE ALLOCATED IN THE
*P*               AREA BETWEEN 64K AND THE END OF PHYSICAL CORE.
*P*
*P*               THE OPERATOR, BY COMMUNICATION WITH PPS, HAS CONTROL
*P*               OVER THE ALLOCATION OF BOTH RESDF AND DYNRESDF PAGES.
*P*               HE ALSO HAS THE ABILITY TO RESET THE SYSGEN DEFINED
*P*               RESDF SIZE AND MAXIMUM DYNRESDF SIZE THUS AFFECTING
*P*               THE SYSTEM'S MAXIMUM USER SIZE.  INCREASES TO RESDF
*P*               SIZE OR TO MAXIMUM DYNRESDF SIZE WILL CAUSE A DECREASE
*P*               TO MAXIMUM USER SIZE; DECREASES WILL CAUSE THE MAXIMUM
*P*               USER SIZE TO INCREASE.  BY SETTING THE MAXIMUM NUMBER
*P*               OF REAL-TIME PAGES THAT MAY BE ALLOCATED TO A MINIMUM
*P*               HE WILL ALLOW LARGE JOBS TO BE SCHEDUALED.  DECREASES
*P*               TO THE MAXIMUM REAL-TIME PAGE VALUES MAY BE EFFECTED
*P*               AT ANY TIME.  INCREASES THAT WOULD CAUSE THE USER
*P*               PAGES TO FALL BELOW 186 PAGES (MAXIMUM USER SIZE
*P*               IN ANY SYSTEM) ARE LIMITED TO THE TIMES WHEN THERE
*P*               ARE NO USERS ON THE SYSTEM OTHER THAN SYSTEM GHOSTS.
*P*               THAT IS, THE SYSTEM MUST BE QUIESCENT EXCEPT FOR
*P*               ALLOCAT, RBBAT, FILL AND THE PPS GHOST.  NEITHER
*P*               RESDF OR DYNRESDF MAXIMUM MAY BE INCREASED TO THE
*P*               POINT WHERE THE MAXIMUM USER SIZE IS TOO SMALL TO
*P*               ALLOW THE SYSTEM GHOSTS TO RUN.
*P*
*P*               THE SYSTEM PARAMETERS THAT DEFINE THE PAGES TO BE
*P*               ALLOCATED AT BOOT TIME, THE MAXIMUM NUMBER OF PAGES
*P*               THAT MAY BE ALLOCATED FOR REAL-TIME USE, AND THE MAXIMUM
*P*               NUMBER OF MEMORY SEGMENTS THAT MAY BE ALLOCATED ARE
*P*               SPECIFIED VIA OPTIONS OF THE :FRGD PASS2 COMMAND
*P*               AS FOLLOWS:
*P*
*P*                  (RESDF,SIZE,ADDRESS)
*P*                  (DYNRESDF, MAX # PGS., MAX # SEGMENTS)
*P*
*P*               WHEN A REAL TIME SYSTEM IS BOOTED THE OPERATOR
*P*               MAY REDEFINE THE RESDF OPTION.  THIS SIMPLY RESETS THE
*P*               VALUES OF RESDF AND RESDFP.  AFTER THE BOOT PROCESS
*P*               IS COMPLETE THE MEMORY MANAGEMENT SYSTEM PARAMETERS
*P*               ARE COMPUTED AS FOLLOWS:
*P*
*P*               S:ACORE = HIGH-LOW+1-1(FOR MONJIT)-DELTA SIZE-
*P*                            SIZE OF THE UNMAPPED MON. OVERLAY
*P*
*P*               S:PCORE = S:ACORE-7 (FOR USER AJIT AND OVERLAYS)
*P*
*P*               THE RESDF PAGES, IF ANY, ARE THEN REMOVED FROM THE
*P*               THE SYSTEM AND PUT INTO THE REAL-TIME PAGE CHAIN.  THE
*P*               FOLLOWING ADJUSTMENTS ARE THEN MADE:
*P*
*P*               S:ACORE = S:ACORE-RESDF PGS.
*P*
*P*               S:PCORE = S:PCORE-RESDF PGS.-MAX. DYNRESDF PGS.
*P*
*P*               THUS BY SETTING S:PCORE TO A VALUE ASSUMING THAT NOT
*P*               ONLY RESDF PAGES, BUT ALSO ALL DYNRESDF PAGES HAVE
*P*               BEEN ALLOCATED, NO SINGLE USER WILL BE ALLOWED TO GET
*P*               SO BIG THAT HE WOULD BE BLOCKED AS DYNRESDF PAGES
*P*               ARE ACTUALLY ACQUIRED.
*P*
*P*               S:ACORE REFLECTS ONLY THOSE PAGES THAT HAVE ACTUALLY
*P*               BEEN ALLOCATED FOR USE AS REAL-TIME PAGES.  THIS ALLOWS
*P*               THE SYSTEM TO USE THE PAGES UNTIL ACTUALLY ALLOCATED
*P*               TO REAL-TIME.  S:ACORE IS DECREMENTED WHENEVER
*P*               A REAL-TIME PAGE IS STOLEN; INCREMENTED WHENEVER A
*P*               REAL-TIME PAGE IS RETURNED.
*P*
         PAGE
         SYSTEM   UTS
TXTC     CNAME
         PROC
         LOCAL    I,VEC
LF       EQU      %
VEC      SET      NUM(S:UT(AF)),S:UT(AF)
I        DO       (NUM(VEC)+3)/4
         GEN,8,8,8,8  VEC(I*4-3),VEC(I*4-2),VEC(I*4-1),VEC(I*4)
         FIN
         PEND
*
*
*        MODULE DEFS
*
         DEF      PPS               PPS START ADDRESS
         DEF      PPSDATA           PPS CSECT0
         DEF      PPSPATCH          PPS PATCH AREA
*
*        MODULE REFS
*
         REF      S:CUN             CURRENT USER #
         REF      S:PCORE           MAX CORE FOR ANY USER
         REF      S:ACORE           MAX CORE FOR ALL USERS
         REF      S:RTCORE          R/T PAGES LOCKED IN CORE
         REF      MX:PPUT           MONITOR'S PAGE CHAIN
         REF      MP:UPPH           HEAD OF PAGES IN UMOV
         REF      PWPTABLE          TP PHYSICAL WORK PAGE TABLE
         REF      PWPEND            END OF PWPTABLE
         REF      S:STLC            COUNT OF STOLEN PHYSICAL PAGES
         REF      HIGH              LAST PHYSICAL PAGE IN THE SYSTEM
         REF      JX:CMAP           USER'S PAGE CHAIN
         REF      JB:PPC            COUNT OF USER'S PAGES
         REF      S:BUIS            # BATCH USERS IN THE SYSTEM
         REF      S:OUIS            # ON-LINE USERS IN THE SYSTEM
         REF      MAXG              MAX GHOST JOBS ALLOWED ON THE SYSTEMM
         REF      MING              LAST SYSTEM GHOST #
         REF      SB:GJOBUN         GHOST JOB USER NUMBER
         REF      T:TOTESZ          COMPUTE USER'S MAX SIZE (MM)
         REF      T:TOTSZ           COMPUTE USER'S CURRENT SIZE (SCHED)
         REF      INCSTL            INCREMENT S:STLC
         REF      T:GPP             GET A PHYSICAL PAGE
         REF      T:FPP             FREE A PHYSICAL PAGE
         REF      T:RVSPI           RELEASE VIRTUAL/SAVE PHYSICAL PAGE
         REF      FPMC              FREE PAGE
*
*        MODULE SREFS
*
         SREF     CRESDF            DEFAULT RESDF MEMORY SEGMENT
         SREF     DYNRESDF          CURRENT # OD DYNRESDF PAGES
         SREF     MDYNRESDF         MAX # OF DYNAMIC RESDF PAGES
         SREF     PP:UPPC           COUNT OF R/T PAGES
         SREF     PP:UPPH           HEAD OF R/T PAGE CHAIN
         SREF     PP:UPPT           TAIL OF R/T PAGE CHAIN
         SREF     PPTABLE           DEFINES THE R/T MEMORY SEGMENTS
         SREF     PPTABLSZ          SIZE OF PPTABLE
         SREF     RESDF             # OF RESDF PAGES CURRENTLY ALLOCATED
         SREF     RESDFP            PAGE # OF 1ST RESDF PAGE
         PAGE
*
PPSDATA  EQU      %
         BOUND    8
DDPGS    DATA     0,0               DYNAMIC DATA  1ST PG / # OF PGS
CPAGES   DATA     0,0               FIRST/LAST PAGE OF CURRENT SEGMENT
PGCNT    DATA     0                 # OF PAGES LEFT IN THIS SEGMENT
PGCNT2   DATA     0                 ORIGINAL # OF PAGES IN THIS SEGMENT
ENTRY    DATA     0                 PPTABLE FORMAT
CENTRY   DATA     0                 INDEX INTO PPTABLE
WAITCT   DATA     0
PP:RPPH  DATA     0                 HEAD OF UNUSED STOLEN PAGES
PP:RPPT  DATA     0                 TAIL OF UNUSED STOLEN PAGES
PP:RPPC  DATA     0                 COUNT OF UNUSED STOLEN PAGES
*
MSG0     TXTC     'PPS:   NOT A REAL-TIME SYSTEM'
DM1      TXTC     '     MAXIMUM DYNRESDF = YYY',X'15'
DM2      TXTC     '     CURRENT DYNRESDF = YYY',X'15'
DM3      TXTC     '     DYNRESDF SEGMENT   YYY  XXXXX',X'15'
DM4      TXTC     '     RESDF SEGMENT      YYY  XXXXX',X'15'
DM5      TXTC     '     MAXIMUM USER CORE = YYY',X'15'
DYM1     TXTC      'PPS:       CURRENT DYNRESDF PAGES > NEW MAXIMUM'
GMSG1    TXTC      'PPS:      EXCEEDS MAXIMUM DYNRESDF '
GMSG2    TXTC      'PPS:       PAGES ARE REAL-TIME PAGES'
GMSG3    TXTC      'PPS:       MAXIMUM DYNRESDF SEGMENTS ALLOCATED'
GMSG4    TXTC      'PPS:       UNABLE TO OBTAIN PAGES'
GMSG5    TXTC      'PPS:       PAGES IN USE BY MONITOR'
RSMSG1   TXTC      'PPS:       NO RESDF PAGES ALLOCATED'
RSMSG2   TXTC      'PPS:       RESDF PAGES ALREADY ALLOCATED'
FMSG1    TXTC      'PPS:       NOT A DYNRESDF MEMORY SEGMENT'
QUEST    TXTC     'PPS:  ?? ',X'15'
MSG1     TXTC      'PPS:      MUST BE EXECUTED AS A GHOST JOB'
MSG2     TXTC      'PPS:       ENTER COMMAND: '
MSG3     TXTC      'PPS:       EXPRESS # OF PAGES IN DECIMAL  0-999'
MSG4     TXTC     'PPS:   EXPRESS PG ADDR IN HEX  10000-XXXXX'
MSG5     TXTC      'PPS:       INSUFFICIENT PRIVILEGE'
MSG6     TXTC      'PPS:       SYSTEM IS ACTIVE'
MSG7     TXTC      'PPS:      DONT LOCK OUT SYSTEM GHOSTS'
ERRMSG   TXTC      'PPS:       PPS DETECTED ERROR'
*
XCONFPT  GEN,12,20 X'198',XCON
*
TRAPFPT  DATA     X'14000000'       IGNORE ARITHMETIC TRAP
         DATA     X'00000003'        WHEN IN MASTER MODE
*
TYPFPT   DATA     X'02000000'       M:TYPE
         DATA     X'80000000'       PLIST
         DATA     X'8000000F'       MSG ADDRESS IN R15
*
CMDFPT   DATA     X'04000000'       M:KEYIN
         DATA     X'F0000000'       PLIST
         DATA     MSG2              'ENTER COMMAND'
         DATA     REPLY             BUFFER FOR REPLY
         DATA     19                SIZE OF REPLY
         DATA     ECB               ECB
*
WAITFPT  DATA     X'0F000001'
*
VPFPT    DATA     X'04000000'
GPFPT    DATA     X'88000007'       # OF PAGES IN R7
FPFPT    DATA     X'090000FF'
*
PSTACK   DATA     0                 TEMP STACK ADDRESS
REPLY    DATA     0,0,0,0,0         BUFFER FOR KEYIN COMMAND
ECB      DATA     0
BUFPTR   DATA     0                 INDEX INTO REPLY
*
*
LOCK     DATA     X'04000000',X'800'
UNLOCK   DATA     X'04000000',0
TEN      DATA     10
YFFFF    DATA     X'FFFF0000'
M8       DATA     X'0F'
M16      DATA     X'FFFF'
M17      DATA     X'1FFFF'
         BOUND    8
ALFA     DATA     C'A',C'F'         FOR VALIDATING INPUT HEX
NUMR     DATA     C'0',C'9'           CHARACTERS
*
COMMANDS DATA,2   0,C'DI',C'GE',C'FR',C'DY',C'RE',C'EN'
         BOUND    4
#CMMDS   EQU      6
*
* DATA FROM ERROR CONDITIONS
*
SAVE15   DATA     0                 BAL,15 GSTERR
SAVEREGS RES      19
XCONC    DATA     0                 FOR RE-ENTRY
*
SYSFPT   DATA     X'08000000'
*
SNAPFPT  DATA     0
         DATA     X'80000000'
         DATA     X'80000001'
         TEXT     'SNAP1   '
         NOP
         B        SNAPIT+1
PPSPATCH RES      50
         PAGE
*F*
*F*      NAME:    PPS
*F*
*F*      PURPOSE: TO DRIVE TO THE CORRECT PPS ROUTINE TO PERFORM THE
*F*               THE REQUIRED FUNCTION.
*F*
*F*
*F*      DESCRIPTION:  PPS WILL ATTEMPT TO PERFORM THE REQUESTED
*F*               FUNCTION, TYPE AN ERROR MESSAGE IF THE FUNCTION CANNOT
*F*               BE PERFoRMED, AnD REPROMPT THE OPERATOR TO GET THE
*F*               NEXT COMMAND.
*F*
         PAGE
*D*
*D*      NAME:    PPS
*D*
*D*      CALL:    PPS IS LOADED FOR EXECUTION VIA THE OPERATOR
*D*               KEY-IN '!GJOB PPS'.
*D*
*D*      ENVIRONMENT:  PPS MUST BE EXECUTED AS A GHOST JOB.  THIS
*D*               DISALLOWS ANYONE BUT THE OPERATOR TO HAVE CONTROL
*D*               OVER REAL-TIME MEMORY ALLOCATION.
*D*
*D*               PPS MUST HAVE C0 PRIVILEGE OR GREATER AS PPS
*D*               ISSUES AN M:SYS CAL TO ENTER THE MASTER MODE IN
*D*               ORDER THAT MONITOR REAL-TIME PAGE PARAMETERS MAY
*D*               BE UPDATED.
*D*
*D*      DATA:    THE FOLLOWING WORDS ARE GENERATED BY PASS2 AND RESIDE
*D*               IN THE MONITOR ROOT.  THEY ARE USED IN CONJUNCTION
*D*               WITH THE ALLOCATION OF REAL-TIME PAGES:
*D*
*D*               CRESDF     DEFAULT SIZE OF THE RESDF MEMORY SEGMENT
*D*
*D*               DYNRESDF   COUNT OF PHYSICAL PAGES CURRENTLY
*D*                          ALLOCATED AS DYNRESDF MEMORY SEGMENTS
*D*
*D*               RESDF      COUNT OF PHYSICAL PAGES CURRENTLY
*D*                          ALLOCATED AS RESDF MEMORY SEGMENT.
*D*
*D*               RESDFP     WORD ADDRESS OF THE 1ST PAGE OF THE
*D*                          RESDF MEMORY SEGMENT
*D*
*D*               PP:UPPH    HEAD OF THE CHAIN OF PAGES CURRENTLY
*D*                          ALLOCATED FOR REAL-TIME.  THE PAGES ARE
*D*                          LINKED IN MX:PPUT.
*D*
*D*               PP:UPPT    TAIL OF THE CHAIN OF PAGES CURRENTLY
*D*                          ALLOCATED FOR REAL-TIME.
*D*
*D*               PP:UPPC    COUNT OF THE  NUMBER OF PAGES CURRENTLY
*D*                          ALLOCATED FOR REAL-TIME.
*D*
*D*               PPTABLE    A TABLE OF ONE WORD ENTRIES, EACH WORD
*D*                          DEFINING A CURRENTLY ALLOCATED REAL-TIME
*D*                          MEMORY SEGMENT.  THE FORMAT OF EACH TABLE
*D*                          ENTRY IS AS FOLLOWS:
*D*
*D*                             1ST HALF WORD - PAGE # OF 1ST PG. IN SEG.
*D*                             2ND HALF WORD - # OF PGS. IN SEG.
*D*
*D*                          THE 1ST WORD OF THE TABLE IS RESERVED
*D*                          FOR THE RESDF MEMORY SEGMENT.  ALL OTHER
*D*                          ENTRIES ARE USED FOR DYNRESDF MEMORY SEG-
*D*                          MENTS.  UNUSED ENTRIES CONTAIN ALL ZEROS.
*D*                          THE SIZE OF THE TABLE IS DEFINED BY THE
*D*                          VALUE 'PPTABLSZ'.
*D*
*D*               THE FOLLOWING WORDS IN THE MONITOR ROOT ARE ALSO
*D*               ALTERED BY REAL-TIME MEMORY ALLOCATION:
*D*
*D*               S:PCORE    THE MAXIMUM NUMBER OF PAGES THAT MAY BE
*D*                          ASSOCIATED WITH ANY ONE USER.
*D*
*D*               S:ACORE    THE TOTAL NUMBER OF PAGES AVAILABLE TO THE
*D*                          SYSTEM FOR ALLOCATION TO ALL USERS.
*D*
*D*      INPUT:   THE OPERATOR MAY ENTER ANY OF THE FOLLOWING COMMANDS:
*D*
*D*               DISPLAY       DISPLAY CURRENT REAL-TIME ALLOCATION
*D*               GET YYY,XXXXX   GET DYNRESDF MEMORY SEGMENT
*D*               FREE YYY,XXXXX  RELEASE DYNRESDF MEMORY SEGMENT
*D*               DYNRESDF YYY    RESET MAX. NUMBER OF DYNRESDF PAGES
*D*               RESDF YYY,XXXXX  REDEFINE THE RESDF MEMORY SEGMENT
*D*               END             EXIT PPS GHOST JOB
*D*
*D*                 WHERE XXXXX = HEXIDECIMAL WORD ADDR. OF THE 1ST
*D*                               PAGE IN THE MEMORY SEGMENT.
*D*                       YYY = DECIMAL NUMBER OF PAGES.
*D*
*D*      DESCRIPTION:  PPS WILL ATTEMPT TO PERFORM THE REQUESTED
*D*               FUNCTION, TYPE AN ERROR MESSAGE IF THE FUNCTION CANNOT
*D*               BE PERFoRMED, AnD REPROMPT THE OPERATOR TO GET THE
*D*               NEXT COMMAND.
*D*
         CSECT    1
PPS      EQU      %
         STW,0    PSTACK
*
* VERIFY THAT THIS A REAL-TIME SYSTEM
*
         LI,15    MSG0
         LI,1     RESDF
         BEZ      PPSABT
*
* PPS MUST BE RUN AS A GHOST JOB
*
         LI,15    MSG1
         LC       X'8C00'
         BCR,4    PPSABT
*
* GO MASTER MODE
*
         CAL1,6   SYSFPT            GO MASTER MODE
         BCR,8    %+4
         LI,15    MSG5              = INSUFFICIENT PRIV
PPSABT   CAL1,2   TYPFPT
         CAL1,9   1
*
* SET UP HIGH IN ERR MSG
*
         LW,1     HIGH
         SLS,1    21                WORD ADDR OF LAST PG(LEFT JUSTIFIED)
         LI,2     38                INDEX INTO MSG
         LI,3     5                 # OF CHARACTERS
         LI,15    MSG4              ADDR OF MSG
         BAL,4    CVTBCD            CONVERT AND STORE IN MSG
*
* SET UP TRAP CONTROL, EXIT CONTROL
*
         CAL1,8   TRAPFPT           IGNORE ARITHMETIC TRAPS
         CAL1,8   XCONFPT           GET XIT CONTROL
         PAGE
*F*
*F*      NAME:    GST1
*F*
*F*      PURPOSE: TO GET A COMMAND FROM THE OPERATOR AND TRANSFER
*F*               CONTROL TO THE PROPER ROUTINE TO PROCESS IT.
*F*
*F*      DESCRIPTION:  GST1 WILL ISSUE AN M:KEYIN CAL ASKING THE
*F*               OPERATOR FOR A COMMAND AND WAIT FOR A REPLY.
*F*               CONTROL THEN TRANSFERS TO ONE OF THE FOLLOWING
*F*               ROUTINES BASED ON THE 1ST TWO CHARACTERS OF THE
*F*               OPERATOR COMMAND:
*F*
*F*                  DISPLAY
*F*                  GET
*F*                  FREE
*F*                  DYNRESDFX
*F*                  RESDFX
*F*
*F*               AN 'END' COMMAND WILL CAUSE PPS TO EXIT.
*F*
GST1     EQU      %
         LI,1     0
         STW,1    WAITCT
         CAL1,2   CMDFPT            M:KEYIN
         CAL1,8   WAITFPT           M:WAIT
         MTW,0    ECB               WAIT FOR ANSWER
         BLZ      %-2
         LI,0     0                 TO ZAP EOM
         LB,1     REPLY             FIND WHERE IT IS
         STB,0    REPLY,1           ZAP IT
         LI,4     1                 SET INITIAL INDEX INTO REPLY
         STW,4    BUFPTR
         LI,14    0                 INDICATE CHARACTER INPUT
         BAL,1    CVTHEX            BUMP POINTER PAST COMMAND KEY WORD
         NOP
GST2     LW,1     REPLY             PICK FIRST WORD
         SLS,1    -8                JUST LOOK AT 1ST 2 CHARACTER
         OR,1     YFFFF             FOR CH SIGN EXTENSION
         LI,2     #CMMDS
         CH,1     COMMANDS,2        LOOK FOR MATCH
         BE       GST3,2            GOT IT
         BDR,2    %-2               KEEP LOOKING
TYPQUEST LI,15    QUEST             M:TYPE QUESTION MARKS
TRYAGAIN CAL1,2   TYPFPT
         B        GST1
GST3     B        %                 NO 'ZERO' ENTRY
         B        DISPLAY
         B        GET
         B        FREE
         B        DYNRESDFX
         B        RESDFX
         CAL1,9   1                 END
         PAGE
*F*
*F*      NAME:    DISPLAY
*F*
*F*      PURPOSE: TO PROCESS THE DISPLAY COMMAND.
*F*
*F*      DESCRIPTION:  THE FOLLOWING INFORMATION IS TYPED ON  THE
*F*               OC DEVICE VIA M:TYPE:
*F*
*F*               MAX DYNRESDF = YYY
*F*               CURRENT DYNRESDF = YYY
*F*               DYRESDF SEGMENT YYY XXXXX *
*F*               RESDF SEGMENT YYY XXXXX
*F*               MAXIMUM USER SIZE = YYY
*F*
*F*               WHERE    XXXXX = HEXIDECIMAL WORD ADDRESS OF THE 1ST
*F*                                PAGE IN THE REAL-TIME MEMORY SEGMENT
*F*                        YYY = DECIMAL NUMBER OF PAGES
*F*
*F*               *  THIS MESSAGE IS REPEATED FOR EACH CURRENTLY
*F*                    ALLOCATED DYNRESDF MEMORY SEGMENT.
*F*
*F*
*F*               CONTROL THEN RETURNS TO GST1 TO GET THE NEXT COMMAND.
*F*
DISPLAY  EQU      %
*
*   MAXIMUM DYNRESDF = YYY
*
         LI,15    DM1               ADDR OF MESSAGE
         LW,1     MDYNRESDF         VALUE TO CONVERT
         BAL,5    DSPLY
*
*  CURRENT DYNRESDF = YYY
*
         LI,15    DM2
         LW,1     DYNRESDF
         BAL,5    DSPLY
*
*  DYNRESDF/RESDF SEGMENT  YYY  XXXXX
*
         LI,7     PPTABLSZ          FOR BDR LOOP
         LI,15    DM3               ADDR OF DYNRESDF MSG
DISPLAY1 LW,1     PPTABLE-1,7       GET ENTRY
         CI,7     1                 IS IT THE RESDF ENTRY
         BNE      DISPLAY2          NO
         LI,15    DM4               ADDR OF RESDF MSG
         B        DISPLAY3          DISPLAY EVEN IF = 0
DISPLAY2 LW,1     1                 IS DYNRESDF ENTRY NULL
         BEZ      DISPLAY4          YES-DONT PRINT
DISPLAY3 AND,1    YFFFF
         SLS,1    5                 LEFT JUSTIFY WA(1ST PAGE)
         LI,2     30                INDEX INTO MSG
         LI,3     5                 # OF CHARACTERS TO CONVERT
         BAL,4    CVTBCD            CONVERT/STORE IN MSG
         LW,1     PPTABLE-1,7       GET # OF PAGES
         AND,1    M16
         BAL,5    DSPLY             CONVERT/STORE/PRINT MSG
DISPLAY4 BDR,7    DISPLAY1          OUTPUT REST OF PPTABLE
*
*  MAXIMUM USER CORE = YYY
*
         LI,15    DM5               ADDR OF MSG
         LW,1     S:PCORE
         LI,2     28                INDEX INTO MSSG
         BAL,5    DSPLY2            CONVERT/STORE/PRINT MSG
         B        GST1              GET NEXT COMMAND
*
DSPLY    LI,2     27                INDEX INTO DYNRESDF LIMIT MSGS
DSPLY2   EQU      %
         LI,3     3                 # OF CHARACTERS TO CONVERT
         BAL,4    CVTDBCD           CONVERT AND STORE IN MSG
         CAL1,2   TYPFPT            TYPE MESSAGE
         B        0,5
         PAGE
*F*
*F*      NAME:    DYNRESDFX
*F*
*F*      PURPOSE: TO PROCESS THE DYNRESDF COMMAND
*F*
*F*      DESCRIPTION:  THE DYNRESDF COMMAND IS USED TO REDEFINE THE
*F*               MAXIMUM NUMBER OF PAGES THAT MAY BE REMOVED FROM
*F*               THE SYSTEM TO BE USED AS DYNRESDF PAGES.  NO PAGES
*F*               ARE OBTAINED OR RELEASED AS A RESULT OF THIS COMMAND.
*F*               THIS COMMAND WILL ALTER THE MAXIMUM USER SIZE.
*F*
*F*               THE VALUE SPECIFIED IS COMPARED WITH THE CURRENT SETTING
*F*               OF THE MAXIMUM NUMBER OF DYNRESDF PAGES.  IF ATTEMPTING
*F*               TO INCREASE THE MAXIMUM SIZE, AND THE USER SIZE WOULD
*F*               FALL TO A VALUE OF LESS THAN 186 PAGES, THE SYSTEM MUST
*F*               HAVE NO USERS OTHER THAN SYSTEM GHOSTS.  THE DECREASED
*F*               MAXIMUM USER SIZE MUST BE LARGE ENOUGH TO ALLOW THESE
*F*               GHOSTS TO RUN.  IF THESE CONDITIONS ARE MET, THE MAXIMUM
*F*               DYNRESDF SIZE (MDYNRESDF) AND MAXIMUM USER SIZE (S:PCORE)
*F*               ARE RESET TO REFLECT THE INCREASED DYNRESF MAX. VALUE.
*F*
*F*               IF ATTEMPTING TO DECREASE THE MAXIMUM NUMBER OF
*F*               DYNRESDF PAGES THAT MAY BE ALLOCATED, THE VALUE
*F*               SPECIFIED MUST BE EQUAL TO OR GREATER THAN THE NUMBER
*F*               OF DYNRESDF PAGES CURRENTLY ALLOCATED.  THEN THE
*F*               MAXIMUM DYNRESDF PAGES IS DECREASED AND THE
*F*               MAXIMUM USER SIZE IS INCREASED AS SPECIFIED.
*F*
DYNRESDFX EQU     %
         LI,14    -1                INDICATE DECIMAL VALUE
         LI,15    MSG3              FOR ERROR RETURN
         BAL,1    CVTHEX            GET # OF PAGES
         B        TRYAGAIN          TYPE MSG-GET COMMAND
         CI,6     0                 WAS THERE ANY INPUT
         BE       TYPQUEST          BAD FORMAT
         CI,3     0                 OR TOO MUCH INPUT
         BNE      TYPQUEST          YES
         CI,2     999               TRYING TO GET GREATER THAN MAX
         BG       TRYAGAIN          YES
         CW,2     MDYNRESDF         INCREASE OR DECREASE
         BG       DYN3              INCREASE
*
* DECREASING MDYNRESDF
*
         LI,15    DYM1              > ALLOC. ERROR MSG
         CW,2     DYNRESDF          IS DECREASE BELOW CURRENT ALLOCATIONN
         BL       TRYAGAIN          YES-DONT RESET MDYNRESDF
         LW,3     MDYNRESDF         FIND AMOUNT OF DECREASE
         SW,3     2
         AWM,3    S:PCORE           INCREASE USER SIZE
         STW,2    MDYNRESDF         SET NEW MAXIMUM
         B        GST1              GET NEXT COMMAND
*
* INCREASING MDYNRESDF
*
DYN3     EQU      %
         LW,3     S:PCORE           FIND NEW PCIRE SIZE
         AW,3     MDYNRESDF
         SW,3     2
         BAL,11   CHKUSRS           IS NEW PCORE SIZE OK
         B        TRYAGAIN
         STW,3    S:PCORE           YES-USE IT
         STW,2    MDYNRESDF         AND RESET MAXIMUM DYNRESDF
         B        GST1
         PAGE
*F*
*F*      NAME:    RESDFX
*F*
*F*      PURPOSE: TO PROCESS THE RESDF COMMAND
*F*
*F*      DESCRIPTION:  THE RESDF COMMAND IS USED TO RELEASE RESDF PAGES
*F*               OR TO RE-ESTABLISH THE RESDF MEMORY SEGMENT.
*F*
*F*               TO RELEASE THE RESDF MEMORY SEGMENT THE FOLLOWING
*F*               FORMAT OF THE RESDF KEY-IN IS USED:
*F*
*F*                        RESDF 0
*F*
*F*               THE RESDF PAGES ARE RETURNED TO THE SYSTEM AND THE
*F*               MAXIMUM USER SIZE IS INCREASED BY THE NUMBER OF
*F*               PAGES RELEASED.
*F*
*F*               TO RE-ESTABLISH THE RESDF SEGMENT THE FOLLOWING
*F*               KEY-IN IS USED:
*F*
*F*                        RESDF (YYY)(,XXXXX)
*F*
*F*               IF EITHER THE NUMBER OF PAGES OR THE WORD ADDRESS OF
*F*               THE 1ST PAGE IS NOT SPECIFIED, THE PREVIOUS VALUE OF
*F*               THE PARAMETER IS USED.  THE MAXIMUM USER SIZE WILL
*F*               BE DECREASED BY AN AMOUNT EQUAL TO THE SIZE OF THE
*F*               RESDF SEGMENT TO BE ALLOCATED.  THEREFORE, IF THE
*F*               USER SIZE WOULD BE DECREASED TO A VALUE LESS THAN
*F*               186 PAGES THERE MUST BE NO USERS ON THE SYSTEM OTHER
*F*               THAN SYSTEM GHOSTS AND THE SYSTEM GHOSTS MUST BE ABLE
*F*               TO TOLERATE THE DECREASED USER SIZE.  THE PAGES
*F*               SPECIFIED ARE REMOVED FROM THE SYSTEM AND THE MAXIMUM
*F*               USER SIZE IS RESET.
*F*
*D*      NAME:    RESDFX
*D*
*D*      DESCRIPTION:  IF THE COMMAND IS USED TO RELEASE THE RESDF
*D*               MEMORY SEGMENT, AND THERE IS NO RESDF SEGMENT CURRENTLY
*D*               ALLOCATED AN ERROR MESSAGE IS TYPED.
*D*
RESDFX   EQU      %
         BAL,11   GETFREE           SET UP REGISTERS
         LW,7     PGCNT             IS THIS RELEASE
         BNEZ     RSDF2             NO-RESTORE RESDF
         LI,15    RSMSG1            =NO RESDF PAGES ALLOCATED
         LW,0     PPTABLE           IS RESDF ALLOCATED
         BEZ      TRYAGAIN          NO-NOTHING TO RELEASE
*D*               OTHERWISE, THE RELPG ROUTINE IS CALLED TO RETURN THE
*D*               PAGES TO THE MONITOR.
*D*
         SLD,0    -16               SET UP R0-R1
         SLS,1    -16
         STW,1    PGCNT
         STW,1    PGCNT2
         AW,1     0
         AI,1     -1
         STD,0    CPAGES
         BAL,5    RELPG             GO RELEASE THEM
         BAL,15   GSTERR
*D*
*D*               THE NUMBER OF PAGES RELEASED IS ADDED TO THE MAXIMUM
*D*               USER SIZE (S:PCORE), THE ENTRY FOR RESDF IN PPTABLE
*D*               IS ZEROED, THE DEFAULT # OF RESDF PAGES IS SAVED
*D*               (CRESDF) AND THE CURRENT NUMBER OF RESDF PAGES
*D*               IS SET TO ZERO (RESDF).
*D*
         LW,0     PGCNT2
         AWM,0    S:PCORE           INCREASE USER SIZE
         LI,0     0
         STW,0    PPTABLE           ZAP PPTABLE RESDF ENTRY
         XW,0     RESDF
         STW,0    CRESDF
         B        GST1
*D*
*D*               IF THE COMMAND WAS TO RESTORE THE RESDF SEGMENT, THE
*D*               RESDF SEGMENT MUST NOT CURRENTLY EXISTS.
*D*
RSDF2    LI,15    RSMSG2            =RESDF ALREADY ALLOCATED
         LW,5     PPTABLE           IS IT ALREADY ALLOCATED
         BNEZ     TRYAGAIN          YES
*D*
*D*               THE FIRST PAGE (CRESDF) AND NUMBER OF PAGES (RESDF)
*D*               ARE SET AS SPECIFIED.  THE CHKUSRS ROUTINE IS CALLED
*D*               TO VERIFY THAT THE DECREASE TO MAXIMUM USER SIZE CAN
*D*               BE TOLERATED.  IF SO THE MAXIMUM USER SIZE (S:PCORE)
*D*               IS RESET.
*D*
         STW,2    RESDFP            RESET 1ST PAGE
         LW,5     PGCNT              AND # OF RESDF PAGES
         STW,5    RESDF
         LW,3     S:PCORE           FIND NEW PCORE SIZE
         SW,3     5
         BAL,11   CHKUSRS           IS NEW PCORE OK
         B        RESDF4            NO
         STW,3    S:PCORE
*D*
*D*               THE GETPGS ROUTINE IS CALLED TO REMOVE THE PAGES
*D*               FROM THE SYSTEM.  IF THE PAGES CANNOT BE OBTAINED
*D*               RESDF IS RESET TO ZERO, S:PCORE IS SET TO ITS
*D*               ORIGINAL VALUE AND AN ERROR MESSAGE IS TYPED.
*D*
         LI,7     0                 INDEX TO RESDF IN PPTABLE
         BAL,11   GETPGS            GO GET THEM
         B        RSDF3             DIDNT GET THEM
         B        GST1              GOT THEM-ALL OK
RSDF3    LI,1     0
         XW,1     RESDF             INDICATE NONE ALLOCATED
         AWM,1    S:PCORE
         B        TRYAGAIN
*
*
RESDF4   LI,0     0
         STW,0    RESDF
         B        TRYAGAIN
         PAGE
*F*
*F*      NAME:    CHKUSRS
*F*
*F*      PUPROSE: TO DETERMINE IF DECREASES TO THE MAXIMUM USER SIZE
*F*               CAN BE TOLERATED.
*F*
*F*      DESCRIPTION:  CHKUSRS DETERMINES IF THERE ARE ANY USERS ON
*F*               THE SYSTEM OTHER THAN SYSTEM GHOSTS AND IF THE SYSTEM
*F*               GHOSTS WOULD BE ABLE TO RUN IN THE DECREMENTED USER
*F*               SIZE.
*F*
*D*      NAME:    CHKUSRS
*D*
*D*      CALL:    ENTERED FROM DYNRESDFX WHEN THE MAXIMUM NUMBER OF
*D*               DYNRESDF PAGES IS TO BE DECREASED.
*D*
*D*               ENTERED FROM RESDFX WHEN THE RESDF SEGMENT IS TO
*D*               BE RE-ESTABLISHED.
*D*
*D*               BAL,11    CHKUSRS
*D*               ERROR RETURN
*D*               NORMAL RETURN
*D*
*D*      INPUT:   R3 = NEW S:PCORE SIZE
*D*
*D*      DESCRIPTION:  IF THE MAXIMUM USER SIZE IS NOT TO BE SET TO LESS
*D*               THAN 186 PAGES, S:PCORE MAY BE RESET.  THE LARGEST
*D*               USER SIZE, INCLUDING SHARED PROCESSOR PROCEDURE, IS
*D*               186 PAGES.  IF THERE ARE USERS ON THE SYSTEM OTHER
*D*               THAN SYSTEM GHOSTS S:PCORE MAY NOT BE DECREASED AS
*D*               CURRENTLY THERE IS NO WAY TO DETERMINE THE LARGEST
*D*               USER ON THE SYSTEM FROM THE RESIDENT MONITOR TABLES.
*D*
CHKUSRS  EQU      %
         CI,3     186               MAX USERS PAGES
         BGE      CKUS3+1           OK TO REDUCE PCORE
         LI,15    MSG6              = SYSTEM IS ACTIVE
         DISABLE
         LW,6     S:BUIS            ANY BATCH USERS
         BNEZ     CKUS4             YES
         LW,6     S:OUIS            ANY ON-LINE USERS
         BNEZ     CKUS4             YES
         LI,6     MAXG              TO CHECK FOR GHOST USERS
CKUS2    LB,4     SB:GJOBUN,6       GET GHOST JOB USER #
         BNEZ     CKUS5             AND GO CHECK IT
CKUS3    BDR,6    CKUS2             CHECK ALL GHOSTS
         AI,11    1                 ALL OK
CKUS4    EQU      %
         ENABLE
         LD,0     CPAGES            RESTORE 1ST-LAST PAGE
         B        *11
*D*
*D*               THE T:TOTSZ ROUTINE IS CALLED TO COMPUTE THE CURRENT
*D*               SIZE OF ALL SYSTEMS GHOSTS AND THE PPS GHOST ITSELF.
*D*               IF ANY GHOST IS LARGER THAN THE NEW S:PCORE SIZE,
*D*               S:PCORE MAY NOT BE RESET.
*D*
CKUS5    CI,4     MING              IS THIS A SYSTEM GHOST
         BLE      CKUS6             YES
         CW,4     S:CUN             OR PPS
         BNE      CKUS4             NO
CKUS6    LCI      2
         PSM,2    *PSTACK
         BAL,7    T:TOTSZ           RETURN WITH R2=USER SIZE
         LW,5     2
         AI,5     -6                ADJUST FOR OVERLAYS
         LCI      2
         PLM,2    *PSTACK
         CW,4     S:CUN             IS THIS PPS
         BNE      %+2               NO
         AI,5     2
         LI,15    MSG7              = LOCKS OUT SYSTEM GHOSTS
         CW,5     3                 SIZE : NEW PCORE
         BG       CKUS4             WONT FIT
         LI,15    MSG6              = SYSTEM ACTIVE
         B        CKUS3
         PAGE
*F*
*F*      NAME:    GET
*F*
*F*      PURPOSE:  TO PROCESS THE GET COMMAND
*F*
*F*      DESCRIPTION:  THE GET COMMAND IS USED TO OBTAIN DYNRESDF PAGES.
*F*               THIS COMMAND HAS NO EFFECT ON MAXIMUM USER SIZE.
*F*               THE MAXIMUM NUMBER OF DYNRESDF SEGMENTS ALLOWED
*F*               MAY NOT BE EXCEEDED NOR MAY THE MAXIMUM NUMBER
*F*               OF DYNRESDF PAGES.  THE PAGES ARE THEN REMOVED FROM
*F*               THE SYSTEM.
*F*
*D*      NAME:    GET
*D*
*D*      DESCRIPTION:  IF THE MAXIMUM NUMBER OF DYNRESDF PAGES WOULD
*D*               BE EXCEEDED BY ALLOCATION OF THIS MEMORY SEGMENT AN
*D*               ERROR MESSAGE IS TYPED.
*D*
GET      EQU      %
         BAL,11   GETFREE
         LI,15    GMSG1             =MAX DYNRESDF ALLOCATED
*D*
*D*               THE PPTABLE IS SEARCHED FOR AN AVAILABLE ENTRY AND IF
*D*               NONE IS FOUND, THE MAXIMUM NUMBER OF DYNRESDF MEMORY
*D*               SEGMENTS HAS BEEN ALLOCATED AND AN ERROR MESSAGE
*D*               IS TYPED.
*D*
         LW,2     PGCNT
         AW,2     DYNRESDF          FIND WHAT TOTAL WOULD BE
         CW,2     MDYNRESDF         WOULD IT BE > MAX
         BG       TRYAGAIN          YES
         LI,15    GMSG3             =ALL DYNAMIC SEGS ALLOCATED
         LI,7     PPTABLSZ-1        # OF DYNRESDF SEGS
         MTW,0    PPTABLE,7         IS THIS A FREE ENTRY
         BEZ      %+3               YES-USE IT
         BDR,7    %-2               NO-KEEPLOOKING
         B        TRYAGAIN          TYPE MSG-GET COMMAND
*D*
*D*               OTHERWISE, THE GETPGS ROUTINE IS CALLED TO REMOVE
*D*               THE PAGES FROM THE SYSTEM.  IF THE PAGES CANNOT BE
*D*               OBTAINED, AN ERROR MESSAGE IS TYPED.  IF OBTAINED, THE
*D*               NUMBER OF PAGES IN THE SEGMENT IS ADDED TO THE CURRENTT
*D*               COUNT OF DYNRESDF PAGES.
*D*
         BAL,11   GETPGS            GO GET THEM
         B        TRYAGAIN          DIDNT GET THEM
         LW,0     PGCNT2
         AWM,0    DYNRESDF          BUMP COUNT
         B        GST1
         PAGE
*F*
*F*      NAME:    GETPGS
*F*
*F*      PURPOSE:  TO STEAL THE PAGES FROM THE SYSTEM.
*F*
*F*      DESCRIPTION:  GETPGS FIRST TRIES TO ACQUIRE AND STEAL THE
*F*               PAGES THROUGH DYNAMIC DATA ACQUISITION.  THIS WILL
*F*               NOT AFFECT OTHER USERS ON THE SYSTEM.
*F*
*F*               HOWEVER, IF THE PAGES CANNOT BE OBTAINED IN THIS
*F*               MANNER, GETPGS WILL BEGIN STEALING PAGES FROM THE
*F*               MONITOR FREE PAGE CHAIN.  THIS WILL CAUSE OTHER
*F*               USERS TO BE SWAPPED OUT AND SHARED PROCESSOR
*F*               PROCEDURE PAGES TO BE RELEASED IN ORDER TO GET PAGES
*F*               FOR PPS.  AFTER THE REQUESTED REAL-TIME PAGES HAVE
*F*               BEEN STOLEN, UNUSED PAGES STOLEN FROM THE MONITOR
*F*               FREE PAGE CHAIN ARE RETURNED.
*F*
*D*      NAME:    GETPGS
*D*
*D*      CALL:    ENTERED FROM RESDFX TO RE-ESTABLISH THE RESDF SEGMENT
*D*               ENTERED FROM GET TO ALLOCATE A DYNRESDF SEGMENT
*D*
*D*               BAL,11 GETPGS
*D*               ERROR RETURN  (PAGES COULD NOT BE OBTAINED)
*D*               NORMAL RETURN (PAGES OBTAINED)
*D*
*D*      INPUT:   R0/R1 = 1ST PAGE/LAST PAGE
*D*               R7 = AVAILABLE ENTRY IN PPTABLE
*D*
*D*      OUTPUT:  R15 = ADDR OF ERR MESSAGE (IF PAGES NOT OBTAINED)
*D*
*D*      DESCRIPTION:  THE CHKRTPG ROUTINE IS CALLED TO DETERMINE IF THE
*D*               PAGES ARE AVAILABLE
*D*
GETPGS   EQU      %
         BAL,4    CHKRTPG           SEE IF THEY ARE ALREADY STOLEN
         B        *11               YES
         PSW,11   *PSTACK           SAVE RETURN
         STW,7    CENTRY
*D*
*D*               AS MUCH DYNAMIC DATA AS POSSIBLE IS OBTAINED AND THE
*D*               STEALPGS ROUTINE IS CALLED TO REMOVE THE PAGES FROM
*D*               THE DYNAMIC DATA AREA.
*D*
*
*        TRY TO GET THEM WITHOUT INTERRUPTING SERVICE
*
GET1     EQU      %
         BAL,6    GETDD
         B        GET3              CANT GET DYNAMIC DATA
         BAL,6    STEALPGS
         B        GET2              DIDNT GET THEM ALL
*D*
*D*               IF THE PAGES ARE OBTAINED, THE PPTABLE ENTRY IS
*D*               ESTABLISHED, DYNAMIC DATA PAGES ARE FREED, AND GETPGS
*D*               EXITS.
*D*
GET15    EQU      %
         LW,7     CENTRY
         LW,0     ENTRY             GET PPTABLE ENTRY
         STW,0    PPTABLE,7         STORE IT
         LW,1     *PSTACK
         MTW,1    *1                BUMP RETURN
         B        GET6              FREE DYNAMIC DATA
*D*
*D*               IF NOT ALL THE PAGES WERE OBTAINED FROM THE CURRENT
*D*               SET OF DYNAMIC DATA, AN M:WAIT CAL IS ISSUED TO
*D*               FORCE A SWAP AND GET NEW PHYSICAL PAGES ASSIGNED TO
*D*               THE DYNAMIC DATA.  THIS PROCESS WILL CONTINUE UNTIL
*D*               ALL THE PAGES IN THE MEMORY SEGMENT HAVE BEEN OBTAINED
*D*               OR THE SWAP FOR NEW PAGES HAS BEEN ATTEMPTED FIVE
*D*               TIMES.
*D*
GET2     EQU      %
         MTW,1    WAITCT
         LW,10    WAITCT
         CI,10    5                 HAVE WE TRIED LONG ENOUGH
         BG       GET3              YES
         CAL1,8   WAITFPT           SWAP-GET NEW PAGES
         B        GET1
*D*
*D*               IF THE PAGES CANNOT BE OBTAINED BY THE METHOD
*D*               DESCRIBED ABOVE, THE DYNAMIC DATA PGS. AR RELEASED.
*D*
GET3     EQU      %
         CAL1,8   WAITFPT
         BAL,10   FREEDD            GET RID OF DYNAMIC DATA
*D*
*D*               THE STEALFP ROUTINE IS CALLED TO REMOVE PAGES
*D*               FROM THE MONITOR'S FREE PAGE CHAIN.
*D*
GET4     BAL,11   STEALFP
         MTW,0    PGCNT             GET THEM
         BEZ      GET15             YES
*D*
*D*               IF THE PAGES ARE NOT OBTAINED BY STEALFP, AS MUCH
*D*               DYNAMIC DATA AS POSSIBLE IS AGAIN OBTAINED AND THE
*D*               STEALPGS ROUTINE IS CALLED TO REMOVE THE PAGES FROM
*D*               DYNAMIC DATA.
*D*
*D*               IF ALL THE PAGES HAVE STILL NOT BEEN FOUND, THE
*D*               PROCESS OF RELEASING DYNAMIC DATA, STEALING FROM
*D*               THE MONITOR FREE PAGE CHAIN, OBTAINING DYNAMIC DATA
*D*               AND STEALING FROM DYNAMIC DATA IS REPEATED UNTIL EITHER
*D*               ALL PAGES ARE FOUND OR THE MONITOR FREE PAGE CHAIN HAS
*D*               BEEN DEPLETED TO THE POINT WERE PPS WOULD NO LONGER
*D*               BE ABLE TO RUN.
*D*
         BAL,6    GETDD             NO-CAUSE SOME ONE TO BE OUTSWAPPED
         B        GET5              CANT FORCE AN OUTSWAP
         BAL,6    STEALPGS          TRY TO GET THEM
         B        GET3              DIDNT GET THEM ALL YET
         B        GET15             GOT THEM ALL
*D*
*D*               IN THIS CASE, PPS MUST GIVE UP.  ANY PAGES THAT WERE
*D*               STOLEN FOR THIS MEMORY SEGMENT ARE RETURNED.
*D*
GET5     EQU      %
         LW,6     PGCNT2
         SW,6     PGCNT             RESTORE PGCNT
         STW,6    PGCNT
         BEZ      %+3
         BAL,5    RELPG             GIVE BACK ANY WE DID GET
         BAL,15   GSTERR
         LI,15    GMSG4             = UNABLE TO OBTAIN PGS
*D*
*D*               ALL PAGES THAT HAVE BEEN STOLEN FROM THE MONITOR FREE
*D*               PAGES ARE RETURNED, DYNAMIC DATA IS RELEASED, AND
*D*               GETPGS EXITS.
*D*
GET6     BAL,10   FREERPP           GET RID OF UNUSED STOLEN PAGES
         BAL,10   FREEDD
         PLW,11   *PSTACK
         B        *11
*
*
*
FREEDD   BAL,6    GETDD             FILL UP HOLES
         NOP
         CAL1,8   FPFPT             GET RID OF DYNAMIC DATA
         LI,1     0
         STW,1    DDPGS             INDICATE NO DYNAMIC DATA
         B        *10
         PAGE
*F*
*F*      NAME:    STEALPGS
*F*
*F*      PURPOSE: TO SEARCH FOR REQUESTED PAGES IN THE PPS DYNAMIC
*F*               DATA AREA AND STEAL THEM FROM THE SYSTEM.
*F*
*F*      DESCRIPTION:  STEALPGS OBTAINS AS MUCH DYNAMIC DATA AS
*F*               POSSIBLE, SEARCHES FOR THE REQUESTED PHYSICAL PAGES
*F*               IN THE DYNAMIC DATA AREA, AND WHEN FOUND REMOVES
*F*               THE PAGE FROM THE SYSTEM AND ALLOCATES IT FOR
*F*               REAL-TIME USE.
*F*
*D*      NAME:    STEALPGS
*D*
*D*      CALL:    ENTERED FROM THE GETPGS ROUTINE.
*D*
*D*               BAL,6   STEALPGS
*D*               RETURN IF PAGES NOT IN DYNAMIC DATA
*D*               RETURN IF ALL PAGES WERE STOLEN
*D*
*D*      DESCRIPTION:  THE STEALPGS ROUTINE CAUSES PPS TO BE LOCKED IN
*D*               CORE SO THAT THE PHYSICAL PAGES WILL NOT BE CHANGED
*D*               BY A SWAP.  STEALPGS RUNS THROUGH JX:CMAP LOOKING
*D*               AT EACH PHYSICAL PAGE ASSIGNED TO THE DYNAMIC DATA
*D*               PAGES.
*D*
STEALPGS EQU      %
         PSW,6    *PSTACK           SAVE RETURN
         CAL1,6   LOCK
         LD,0     CPAGES
STLPGS2  LCI      2
         LM,7     DDPGS             RESTORE LL AND SIZE OF DYNAMIC DATA
         LW,8     8                 DO I HAVE ANY PAGES
         BEZ      STLPGS7           NO
STLPGS3  LOAD,3   JX:CMAP,7         GET THE PP NUMBER
         CLR,0    3                 IS THIS A PAGE WE WANT
         BCR,6    STLPGS5           YES
STLPGS4  AI,7     1                 SET TO LOOK AT NEXT PAGE
         BDR,8    STLPGS3
STLPGS7  CAL1,6   UNLOCK
         PLW,6    *PSTACK           DIDNT GET THEM THIS PASS
         B        0,6
*D*
*D*               WHEN A REQUESTED PAGE IS FOUND THE PAGE IS REMOVED
*D*               FROM PPS VIA T:RVSPI IN MM (RELEASE VIRTUAL/SAVE
*D*               PHYSICAL).  THE PHYSICAL PAGE IS THEN ADDED TO THE
*D*               REAL-TIME PAGE CHAIN WHICH IS LINKED THROUGH MX:PPUT
*D*               THROUGH PP:UPPH (PPS USED PHYSICAL PAGE HEAD). THE
*D*               COUNT OF THE NUMBER OF PAGES AVAILABLE TO THE SYSTEM
*D*               (S:ACORE) IS DECREMENTED.
*D*
STLPGS5  EQU      %
         PSW,8    *PSTACK           SAVE # OF PAGES LEFT
         LCI      4
         PSM,0    *PSTACK
         BAL,11   T:RVSPI           VP IS IN R7
         LCI      4
         PLM,0    *PSTACK
         PLW,8    *PSTACK
         BAL,11   PUTCHAIN          ADD TO RT PAGE CHAIN
*D*
*D*               THE SEARCH OF DYNAMIC DATA CONTINES UNTIL ALL PAGES
*D*               IN THE REQUESTED MEMORY SEGMENT HAVE BEEN FOUND OR
*D*               ALL PAGES IN THE DYNAMIC DATA AREA HAVE BEEN CHECKED.
*D*               PPS IS THEN UNLOCKED IN CORE TO ALLOW SWAPS AND THE
*D*               STEALPGS ROUTINE EXITS.
*D*
         MTW,0    PGCNT             GOT THEM ALL
         BNEZ     STLPGS4
         CAL1,6   UNLOCK
         PLW,6    *PSTACK
         B        1,6               GOT ALL REQUIRED PAGES
*
* ROUTINE TO ADD PAGE TO REAL-TIME PAGE CHAIN
*
PUTCHAIN EQU      %
         LI,4     0
         STORE,4  MX:PPUT,3         SET END OF CHAIN IN PPUT
         LW,4     PP:UPPT           USED TAIL
         BNEZ     STLPGS6           THIS IS NOT 1ST STOLEN PAGE
         STW,3    PP:UPPH           BUT IF SO, IS ALSO THE HEAD
         B        %+2
STLPGS6  STORE,3  MX:PPUT,4         LINK UP CHAIN
         STW,3    PP:UPPT           AND SET NEW TAIL
         MTW,1    PP:UPPC           COUNT OF STOLEN PAGES
         MTW,-1   S:ACORE
         MTW,-1   PGCNT             SEE IF WE HAVE THEM ALL
         B        *11
         PAGE
*F*
*F*      NAME:    STEALFP
*F*
*F*      PURPOSE:  TO REMOVE PAGES FROM THE MONITOR'S FREE PAGE CHAIN
*F*
*F*      DESCRIPTION:  PAGES ARE REMOVED FROM THE MONITOR'S FREE PAGE
*F*               CHAIN.  IF THE PAGE IS A REQUESTED PAGE IT IS ADDED
*F*               TO THE REAL-TIME PAGE CHAIN.  OTHERWISE IT IS PUT
*F*               INTO A CHAIN OF UNUSED STOLEN PAGES.
*F*
*D*      NAME:    STEALFP
*D*
*D*      CALL:    ENTERED FROM GETPGS WHEN THE REQUESTED PAGES
*D*               CANNOT BE FOUND IN PPS DYNAMIC DATA.
*D*
*D*               BAL,11   STEALFP
*D*
*D*      DESCRIPTION:  PAGES ARE REMOVED FROM THE MONITOR'S FREE PAGE
*D*               CHAIN BY CALLING T:GPP IN MM.  WHEN THERE ARE NO
*D*               MORE PAGES IN THE FREE CHAIN, THE STEALFP ROUTINE
*D*               EXITS.
*D*
STEALFP  EQU      %
         PSW,11   *PSTACK           SAVE RETURN
         LD,0     CPAGES
SFP10    BAL,2    T:GPP             STEAL FROM FREE CHAIN
         CI,3     0                 END OF CHAIN
         BE       SFP31             YES
*D*
*D*               WHENEVER A PAGE IS STOLEN FROM THE FREE CHAIN, S:ACORE
*D*               IS DECREMENTED, WHICH DISALLOWS LARGE USERS FROM BEING
*D*               SWAPPED IN UNTIL THESE PAGES ARE RETURNED.
*D*
         MTW,-1   S:ACORE           FOR SCHED
         CLR,0    3                 IS THIS A PAGE I WANT
         BCR,6    SFP20             YES
*D*
*D*               IF THE PAGE STOLEN FROM THE MONITOR FREE PAGE CHAIN
*D*               IS NOT WITHIN THE REQUESTED MEMORY SEGMENT, IT IS
*D*               PUT INTO THE CHAIN OF UNUSED STOLEN MONITOR PAGES
*D*               THAT IS LINKED THROUGH MX:PPUT BEGINNING WITH
*D*               PP:RPPH (RETURNABLE PHYSICAL PAGE HEAD).
*D*
         LI,4     0
         STORE,4  MX:PPUT,3         SET END OF CHAIN IN PPUT
         LW,4     PP:RPPT           GET CURRENT TAIL
         BNEZ     %+3               NOT FIRST IN CHAIN
         STW,3    PP:RPPH           BUT IF SO IT IS ALSO THE HEAD
         B        %+2
         STORE,3  MX:PPUT,4         LINK UP CHAIN
         STW,3    PP:RPPT           SET NEW TAIL
         MTW,1    PP:RPPC           COUNT OF UNUSED STOLEN PAGES
         B        SFP10             GO GET NEXT PAGE IN FREE PG CHAIN
*D*
*D*               IF THE STOLEN PAGE IS ONE THAT WAS REQUESTED IT IS
*D*               PUT IN THE CHAIN OF REAL-TIME PAGES.
*D*
SFP20    BAL,11   PUTCHAIN          DO IT
         MTW,0    PGCNT             GOT THEM ALL
         BNEZ     SFP10             NO-KEEP LOOKING
SFP31    PLW,11   *PSTACK
         B        *11
         PAGE
*F*
*F*      NAME:    FREERPP
*F*
*F*      PURPOSE: TO RETURN PAGES STOLEN FROM THE MONITOR FREE PAGE
*F*               CHAIN.
*F*
*F*      DESCRIPTION:  ALL PAGES IN THE CHAIN OF STOLEN PAGES ARE
*F*               RETURNED TO THE SYSTEM.
*F*
*D*      NAME:    FREERPP
*D*
*D*      CALL:    ENTERED FROM GETPGS AFTER ALL PAGES HAVE BEEN
*D*               OBTAINED OR IT HAS BEEN DETERMINED THAT PPS MUST GIVE  UP.
*D*
*D*               ENTER FROM GSTERR ON AN ERROR CONDITION TO BE SURE
*D*               PPS DOES NOT EXIT WITHOUT RETURNING UNUSED STOLEN PAGES.
*D*
*D*               BAL,10   FREERPP
*D*
*D*      DESCRIPTION:  ALL PAGES IN THE UNUSED STOLEN PAGE CHAIN ARE
*D*               RETURNED TO THE SYSTEM VIA THE T:FPP ROUTINE IN MM.
*D*               S:ACORE IS INCREMENTED SO THAT THESE PAGES MAY BE
*D*               ALLOCATED.
*D*
FREERPP  EQU      %
         LW,3     PP:RPPH           ANY STOLEN
         BEZ      *10               NO
FRPP2    LOAD,5   MX:PPUT,3         GET FORWARD LINK
         BAL,2    T:FPP             GIVE IT PACK
         MTW,1    S:ACORE
         MTW,-1   PP:RPPC
*D*
*D*               THE INCSTL ROUTINE IN MM IS CALLED TO BUMP  THE
*D*               COUNT OF CURRENTLY STEALABLE PAGES AS THE SWAPPER
*D*               HAS SET IT WAY LOW NOT KNOWING THAT S:ACORE WAS
*D*               GETTING SMALLER BECAUSE OF 'ILLEGAL' PAGE STEALING.
*D*
         DISABLE                    BUMP UP THE NUMBER OF PAGES
         LW,3     S:STLC             THAT MAY BE STOLEN BY THE PAGE
         BAL,11   INCSTL              STEALERS AS SWAPPER HAS SET IT LOWW
         LW,3     5                 ANY MORE TO RETURN
         BNEZ     FRPP2             YES
         MTW,0    PP:RPPC           CONSISTENCY CHECK
         BEZ      %+2
         BAL,15   GSTERR
         LI,0     0
         STW,0    PP:RPPH           ZAP HEAD
         STW,0    PP:RPPT            AND TAIL
         B        *10               EXIT
         PAGE
*F*
*F*      NAME:    CHKRTPG
*F*
*F*      PURPOSE: TO SEE IF THE REQUESTED PAGES ARE STEALABLE
*F*
*F*      DESCRIPTION:  CHKRTPGS DETERMINES IF THE REQUESTED PAGES ARE
*F*               CURRENTLY ALLOCATED REAL-TIME PAGES, MONITOR UNMAPPED
*F*               ROUTINE PAGES, OR TP WORK PAGES.
*F*
*D*
*D*      NAME:    CHKRTPG
*D*
*D*      CALL:    ENTERED FROM THE GETPGS ROUTINE
*D*
*D*               BAL,4   CHKRTPG
*D*               RETURN IF PAGES ARE NOT STEALABLE
*D*               RETURN IF PAGES ARE STEALABLE
*D*
*D*      INPUT:   R0 = 1ST PAGE
*D*               R1 = LAST PAGE
*D*
*D*      DESCRIPTION:  THE REAL-TIME PAGE CHAIN (HEAD = PP:UPPH) IN
*D*               MX:PPUT IS CHECKED TO DETERMINE IF THE PAGES SPECIFIED
*D*               ARE ALREADY STOLEN REAL-TIME PAGES.
*D*
CHKRTPG  EQU      %
         LI,15    GMSG2             = PGS ARE RT PGS
         LW,3     PP:UPPH           GET HEAD OF RT PAGE CHAIN
         BEZ      CHKMON            NONE IN CHAIN
CHKRTPG2 CLR,0    3                 IS RT PAGE ONE WE WANT
         BCR,6    0,4               YES-PG IN CHAIN
         LOAD,3   MX:PPUT,3         GET NEXT IN CHAIN
         BNEZ     CHKRTPG2          KEEP LOOKING
*D*
*D*               THE UNMAPPED MONITOR ROUTINE PAGES, INCLUDING
*D*               EXEC DELTA PAGES (HEAD = MP:UPPH), IS CHECKED TO
*D*               DETERMINE IF THE PAGES SPECIFIED ARE IN USE BY THE
*D*               MONITOR.
*D*
CHKMON   EQU      %
         LI,15    GMSG5             = PGS IN USE BY MON
         LW,3     MP:UPPH           HEAD OF MONITOR UNMAPPED PGS
         BEZ      CHKMON3           NONE IN CHAIN
CHKMON2  CLR,0    3                 ARE WE AFTER A MONITOR PG
         BCR,6    0,4               YES
         LOAD,3   MX:PPUT,3         NEXT IN CHAIN
         BNEZ     CHKMON2           AND CHECK IT
*                                   NOT USED BY MON UNMAPPED ROUTINES
*D*
*D*               THE PWPTABLE, IF ANY, IS CHECKED TO DETERMINE IF
*D*               THE PAGES SPECIFIED ARE BEING USED FOR TP WORK PAGES.
*D*
CHKMON3  LI,5     PWPTABLE-1
         CI,5     PWPEND
         BE       1,4               NONE
CHKMON4  LOAD,3   *5                GET PG #--IF ANY
         CLR,0    3                 IS IT ONE WE WANT
         BCR,6    0,4               YES
         AI,5     1
         CI,5     PWPEND            MORE IN THE TABLE
         BG       1,4               NO-OK TO GET THE PAGE
         B        CHKMON4           YES-KEEP CHECKING
*D*
*D*               NOTE:  IF REAL-TIME LOCKED IN CORE PAGES ARE EVER
*D*                      PUT IN A CHAIN, THAT CHAIN WILL BE CHECKED TOO.
         PAGE
*F*
*F*      NAME:    FREE
*F*
*F*      PURPOSE:  TO PROCESS THE FREE COMMAND
*F*
*F*      DESCRIPTION:  THE FREE COMMAND IS USED TO RETURN CURRENTLY
*F*               ALLOCATED DYNRESDF PAGES TO THE SYSTEM.  THIS
*F*               COMMAND HAS NO EFFECT OF MAXIMUM USER SIZE.
*F*
*F*               DYNRESDF SEGMENTS CANNOT BE PARTIALLY RELEASED.  THAT
*F*               IS, ALL PAGES WITHIN THE MEMORY SEGMENT MUST BE RELEASED
*F*               WITH ONE FREE COMMAND.  IF THE SEGMENT SPECIFIED IS
*F*               VALID, THE PAGES ARE RETURNED TO THE SYSTEM.
*F*
FREE     EQU      %
         BAL,11   GETFREE
         LI,7     PPTABLSZ-1        # OF DYNRESDF SEGMENTS
         LW,11    PPTABLE,7         GET TABLE ENTRY
         CW,11    ENTRY             IS IT A MATCH
         BE       FREE2             YES
         BDR,7    %-3               NO-KEEP LOOKING
         LI,15    FMSG1             =NOT DYNRESDF SEGMENT
         B        TRYAGAIN
FREE2    BAL,5    RELPG             GO RELEASE THEM
         BAL,15   GSTERR            ERROR
         LI,2     0
         XW,2     PPTABLE,7         ZAP PPTABLE ENTRY
         AND,2    M16               # OF PAGES
         LCW,2    2
         AWM,2    DYNRESDF          ADJUST CURRENT COUNT
         B        GST1
         PAGE
*F*
*F*      NAME:    RELPG
*F*
*F*      PURPOSE: TO RETURN STOLEN REAL-TIME PAGES TO THE SYSTEM
*F*
*D*      NAME:    RELPG
*D*
*D*      CALL:    ENTERED FROM RESDFX TO RELEASE THE RESDF SEGMENT.
*D*
*D*               ENTERED FROM GETPGS TO RETURN PARTLY STOLEN SEGMENTS
*D*               WHEN IT HAS BEEN DETERMINED PPS MUST GIVE UP.
*D*
*D*               ENTERED FROM FREE TO RELEASE A DYNRESDF SEGMENT.
*D*
*D*               BAL,5   RELPG
*D*               RETURN IF NOT ALL RELEASED
*D*               RETURN IF ALL RELEASED
*D*
*D*      DESCRIPTION:  THE PAGE IS REMOVED FROM THE REAL-TIME PAGE CHAIN
*D*               IN MX:PPUT AND RETURNED TO THE MONITOR FREE PAGE CHAIN
*D*               VIA T:FPP IN MM.  S:ACORE IS INCREMENTED TO MAKE THE PAGES
*D*               AVAILABLE TO THE SYSTEM.
*D*
RELPG    LW,3     PP:UPPH           GET FIRST STOLEN PAGE
         BEZ      0,5               ERROR
         LD,0     CPAGES
RELP3    CLR,0    3                 IS THIS PAGE TO BE RELEASED
         BCR,6    RELP4             YES
         LW,4     3                 SAVE BACKWARD LINK
         LOAD,3   MX:PPUT,3         GET FORWARD LINK
         BNEZ     RELP3              AND SEE IF WE SHOULD RELEASE IT
         B        0,5               ERROR
*
RELP4    CW,3     PP:UPPH           ARE WE RELEASING THE HEAD
         BNE      RELP7             NO
         LOAD,4   MX:PPUT,3         YES-GET FORWARD LINK
         STW,4    PP:UPPH           AND SET NEW HEAD
         BNEZ     %+2               THERE ARE MORE PGS IN THE CHAIN
RELP5    STW,4    PP:UPPT           RELEASING ONLY PAGE IN THE CHAIN
RELP6    BAL,2    T:FPP             RELEASE THE PAGE
         MTW,1    S:ACORE
         MTW,-1   PP:UPPC           # OF STOLEN PAGES
         MTW,-1   PGCNT             # OF PAGES THIS REQUEST
         BNEZ     RELPG             MORE TO RELEASE
         B        1,5               ALL RELEASED
*
RELP7    LOAD,6   MX:PPUT,3         FORWARD LINK
         STORE,6  MX:PPUT,4         LINKED TO BACKWARD LINK
         BNEZ     RELP6             NOT RELEASING TAIL
         B        RELP5             WE ARE RELEASING TAIL
         PAGE
*F*
*F*      NAME:    GETDD
*F*
*F*      PURPOSE: TO GET AS MUCH DYNAMIC DATA AS POSSIBLE
*F*
*F*      DESCRIPTION:  THE GETDD ROUTINE COMPUTES THE MAXIMUM NUMBER
*F*               OF PAGES THAT MAY BE ACQUIRED BASED ON THE CURRENT
*F*               NUMBER OF PAGES AVAILABLE ON THE SYSTEM (S:ACORE).
*F*               THESE PAGES ARE OBTAINED WITH AN M:GP CAL.
*F*
*F*               IF PPS ALREADY HAS DYNAMIC DATA WHEN GETDD IS ENTERED,
*F*               IT IS A CALL TO REPLACE PAGES WITHIN THE DYNAMIC
*F*               DATA AREA THAT HAVE BEEN RELEASED BY THE CALL TO
*F*               T:RVSPI IN THE GETPGS ROUTINE.
*F*
*D*      NAME:    GETDD
*D*
*D*      CALL:    ENTERED FROM GETPGS
*D*
*D*               BAL,6  GETDD
*D*               RETURN IF NO DYNAMIC DATA CAN BE OBTAINED
*D*               RETURN IF DYNAMIC DATA IS OBTAINED
*D*
*D*      OUTPUT:  R7 = LOWEST VP IN DYNAMIC DATA AREA
*D*               R8 = NUMBER OF PAGES ACQUIRED
*D*
*D*      DESCRIPTION:  UNLESS THERE ARE NO DYNAMIC DATA PAGES CURRENTLY
*D*               ALLOCATED, CONTROL TRANSFERS TO FILLDD.
*D*
*        RETURN IF NO DYNAMIC DATA CAN BE OBTAINED
*        RETURN IF DYNAMIC DATA IS OBTAINED
*
GETDD    EQU      %
         LCI      2
         LM,7     DDPGS
         LW,7     7                 DO I ALREADY HAVE DYNAMIC DATA
         BNEZ     FILLDD            YES-REPLACE ANY RELEASED PGS
*D*
*D*               GETDD MUST DETERMINE THE NUMBER OF DYNAMIC DATA PAGES
*D*               THAT SHOULD BE REQUESTED.  THE GETPGS ROUTINE REPEATEDLY
*D*               STEALS PAGES FROM THE MONITOR FREE PAGE CHAIN AND THEN
*D*               MAKES CALLS TO GETDD.  PRECAUTIONS MUST BE TAKEN TO
*D*               INSURE THAT THE NUMBER OF PAGES REQUESTED DOES NOT
*D*               EXCEED THE NUMBER AVAILABLE (S:ACORE) AS THIS WOULD
*D*               CAUSE PPS TO BE OUTSWAPPED BECAUSE OF NO CORE.  THE
*D*               NUMBER OF DYNAMIC DATA PAGES TO BE REQUESTED IS
*D*               COMPUTED AS FOLLOWS:
*D*
*D*                 S:ACORE - S:RTCORE(REAL TIME LOCKED IN CORE PAGES)-
*D*                    PPS SIZE - 6(FOR OVERLAYS)
*D*
*D*               THE PAGES ARE THEN OBTAINED VIA AN M:GP CAL.
*D*
*
* FIND MAX # OF PAGES TO ASK FOR--AVOID GETTING BYPASS BIT SET IF POSSIBLE
*
         LW,4     S:CUN
         BAL,0    T:TOTESZ          R12 = USER SIZE-1
         NOP
         AI,12    6                 FOR OVERLAYS
         LW,7     S:ACORE           # OF FLUID PAGES
         SW,7     S:RTCORE           - RT LOCKED IN CORE PAGES
         SW,7     12                  - PAGES NOW IN USE BY PPS
         BLEZ     0,6               CANT GET DD WITH OUT GETTING LOCKED OUT
         CAL1,8   GPFPT             M:GP *R7
         SLS,9    -9                LOWEST DD PAGE
         LW,7     9                 GET IT IN AN INDEX REGISTER
         LCI      2
         STM,7    DDPGS             REMEMBER HOW BIG WE ARE
         B        1,6
*D*
*D*               FILLDD INSURES FULL DYNAMIC DATA ALLOCATION.  THIS
*D*               IS NECESSARY BECAUSE HOLES IN THE DYNAMIC DATA AREA
*D*               WILL EXIST WHEN PAGES HAVE BEEN RELEASED (IN THE
*D*               STEALPGS ROUTINE) VIA T:RVSPI, RELEASE VIRTUAL/
*D*               SAVE PHYSICAL.
*D*
*D*               A SEARCH IS MADE OF JX:CMAP LOOKING FOR THE FPMC.
*D*               WHEN FOUND THE PAGE IS REPLACED BY ISSUING AN
*D*               M:GVP CAL.
*D*
FILLDD   EQU      %
         LOAD,2   JX:CMAP,7
         CI,2     FPMC              DID WE STEAL THIS PAGE
         BE       FILLDD3
FILLDD2  AI,7     1                 LOOK AT NEXT PAGE
         BDR,8    %-4
         LCI      2
         LM,7     DDPGS
         B        1,6
FILLDD3  LW,4     7                 PAGE TO GET
         SLS,4    9                 WORD ADDRESS
         LW,5     M17
         STS,4    VPFPT             SET UP THE FPT
         CAL1,8   VPFPT             REPLACE THE PAGE
         CI,8     0                 DID I GET THE PAGE
         BNE      FILLDD2           YES
         BAL,15   GSTERR            NO
         PAGE
*
* BAL,1 CVTHEX      TO GET DATA FROM OPERATOR AND CONVERT IT TO HEX
* ERROR RETURN
* NORMAL RETURN
*
* INPUT  R14 =0 CHARACTER INPUT
*            >0 HEX VALUE
*            <0 DECIMAL VALUE
*
*OUTPUT  R6 = # OF CHARACTERS
*        R2 = VALUE
*
CVTHEX   LI,2     0                 BUILD ANSWER IN R2
         LI,5     0                 BUILD DECIMAL ANSWER IN R5
         LI,6     0                 INITIALIZE # CHAR. COUNT
         LW,4     BUFPTR            CURRENT INDEX INTO REPLY
CVTHEX2  LB,3     REPLY,4           GET CHARACTER
         BEZ      CVTHEX4           NORMAL EXIT ON EOM
         AI,4     1                 BUMP INDEX INTO REPLY
         CI,3     C','              CHECK FOR DELIMITERS
         BE       CVTHEX4
         CI,3     C' '
         BE       CVTHEX4
         LW,14    14                WHAT TYPE OF INPUT
         BEZ      CVTHEX3           CHARACTER-DONT VALIDATE
         BLZ      %+3               DECIMAL  A-F IS ILLEGAL
         CLM,3    ALFA              VALIDATE HEX CHARACTER
         BCR,9    %+3               ITS A-F
         CLM,3    NUMR               OR 0-9
         BCS,9    0,1               ERROR
         AI,3     -X'F0'            CONVERT TO HEX
         LW,14    14                WHAT TYPE OF INPUT
         BLZ      CVTHEX5           DECIMAL
         CI,3     0
         BGE      %+2               0-9
         AI,3     X'39'             A-F
         SLS,3    28                TO BITS 0-2
         SLD,2    4                 BUILD ANSWER IN R2
CVTHEX3  AI,6     1                 COUNT # OF CHARACTERS
         B        CVTHEX2           GET NEXT CHARACTER
*
CVTHEX4  STW,4    BUFPTR            REMEMBER WHERE WE ARE
         B        1,1               NORMAL EXIT
*
CVTHEX5  MI,5     10                SHIFT PREVIOUS ANSWER
         AW,5     3                 SUM UP ANSWER
         LW,2     5                 ANSWER IN R2
         B        CVTHEX3           CONTINUE
         PAGE
*
* R1 = CHARACTERS TO CONVERT (LEFT JUSTIFIED)
* R2 = INDEX INTO MESSAGE
* R3 = # OF CHARACTERS TO CONVERT
* R4 = RETURN
* R15 = ADDRESS OF MESSAGE
*
CVTBCD   LI,0     0
         SLD,0    4                 GET CHARACTER
         AI,0     X'F0'             CONVERT
         CI,0     X'F9'
         BLE      %+2               0-9
         AI,0     -X'39'            A-F
         STB,0    *15,2             STORE IN MESSAGE
         AI,2     1                 BUMP INDEX INTO MESSAGE
         BDR,3    CVTBCD            GET NEXT CHARACTER
         B        0,4               EXIT
*
* R1 = VALUE TO CONVERT
* R2 = INDEX TO LAST CHARACTER OF MSG FIELD
* R3 = # OF CHARACTERS TO CONVERT
* R4 = RETURN
* R15 = ADDRESS OF MESSAGE
*
CVTDBCD  LI,0     0                 CLEAR ANSWER
         DW,0     TEN               R0=REMAINDER
         AI,0     X'F0'             CONVERT TO EBCDIC
         STB,0    *15,2             STORE IN MESSAGE
         AI,2     -1                BUMP INDEX
         BDR,3    CVTDBCD           GET NEXT DIGIT
         B        0,4               EXIT
         PAGE
*
* ROUTINE TO GET INPUT IN GET/FREE COMMAND
*
* OUTPUT          R0 = 1ST PAGE
*                 R1 = LAST PAGE
*                 R2 = WA(1ST PAGE)
*                 ENTRY = PPTABLE FORMAT
*                 PGCNT = # OF PAGES
*
GETFREE  EQU      %
         LI,14    -1                INDICATE DECIMAL VALUE
         LI,15    MSG3              = PGS IN DECIMAL 0-999
         BAL,1    CVTHEX            GET #PGS IN R2/R5
         B        TRYAGAIN          INPUT NOT DECIMAL
         CI,6     0                 ANY INPUT
         BNE      GF2               YES
         CI,11    RESDFX+1          IS THIS RESDF COMMAND
         BNE      TYPQUEST          NO-MUST SPECIFY # OF PAGES
         LW,2     CRESDF            YES-USE LATEST VALUE
GF2      CI,2     999               REASONABLE INPUT
         BG       TRYAGAIN          NO
         STW,2    PGCNT             SAVE # OF PAGES
         STW,2    PGCNT2
         LI,14    1                 INDICATE HEX INPUT
         LI,15    MSG4              =ADDR IN HEX 10000-XXXXX
         BAL,1    CVTHEX            GET 1ST PAGE ADDR
         B        TRYAGAIN          INVALID HEX ADDRESS
         CI,6     0                 ANY INPUT
         BNE      GF3               YES
         CI,11    RESDFX+1          IS THIS RESDF COMMAND
         BNE      TYPQUEST          NO-MUST SPECIFY FIRST PAGE
         LW,2     RESDFP            YES-USE LATEST VALUE
GF3      CI,2     X'1FF'            VALID PAGE ADDR
         BANZ     TRYAGAIN          NO
         LW,0     2
         SLS,0    -9                GET 1ST PAGE #
         CI,0     X'80'             VALID RT PAGE
         BL       TRYAGAIN          NO
         LW,1     PGCNT             LAST PAGE TO R1
         AW,1     0
         AI,1     -1
         CW,1     HIGH              VALID RT PAGE
         BG       TRYAGAIN          NO
         STD,0    CPAGES
         LW,7     0                 FISRT PAGE
         SLS,7    16
         OR,7     PGCNT             BUILD PPTABLE ENTRY
         STW,7    ENTRY             SAVE IT
         B        *11
*
         PAGE
*F*
*F*      NAME:    GSTERR
*F*
*F*      PURPOSE: TO HANDLE ERROR CONDITIONS
*F*
*F*      DESCRIPTION:  WHEN AN ERROR IS DETECTED, PPS SNAPS THE PPS
*F*               DATA AREA, THE :FRGD AREA OF THE MONITOR ROOT,
*F*               MX:PPUT AND PPS JIT.  AN ERROR MESSAGE IS TYPED
*F*               ON THE OC DEVICE AND PPS EXITS.
*F*
GSTERR   EQU      %
         STW,15   SAVE15
         B        XCON2
XCON     MTW,0    XCONC             RE-ENTERED XIT CONTROL
         BNEZ     XCONR             YES
         MTW,1    XCONC
         AND,8    M8
         BEZ      XCONR             EXECUTING NORMALLY
XCON2    LCI      0
         STM,0    SAVEREGS
         LCI      3
         LM,0     PP:RPPH
         STM,0    SAVEREGS+16
         CAL1,6   SYSFPT            GO MASTER MODE
         BAL,10   FREERPP
         LI,0     X'A000'
         LI,1     X'A1FF'
         BAL,14   SNAPIT            SNAP1=DATA
         LI,2     RESDF-1
         BAL,14   MVSNAP            SNAP2 = :FRGD
         LI,2     MX:PPUT-1
         BAL,14   MVSNAP            SNAP 3 = MX:PPUT
         LI,0     X'8C00'
         LI,1     X'8DFF'
         BAL,14   SNAPIT            SNAP4=JIT
         LI,15    ERRMSG            =GST DETECTED ERR
         CAL1,2   TYPFPT
XCONR    CAL1,9   1
MVSNAP   LI,3     128               CANT SNAP MON ROOT
         LW,4     *2,3
         STW,4    PPSDATA-1,3
         BDR,3    %-2
SNAPIT   CAL1,3   SNAPFPT
         MTB,1    SNAPFPT+4
         B        *14
         END      PPS
		 
