         PCC      0                                                             
         SYSTEM   SIG9P                                                         
         SYSTEM   OPTIONS                                                       
         SPACE    2                                                             
*                                                                               
*                                                                               
*                                                                               
         DEF      MMO2                                                          
         DEF      MMO2EXIT                                                      
         DEF      MMRP,MMDEACT,MMERASE,MMGETP,MMRELP                            
         DEF      MMTSEC,MMRELSD,MMTJOB,MMRELS                                  
OLAYFLAG EQU      'MMO2'                                                        
         PSYS     0                                                             
         SYSTEM   CPRMON                                                        
MMO2     RES      0                                                             
         TITLE    '** MMO2 - RELEASE PAGES **'                                  
*                                                                               
*        MMRP     RELEASE PAGES                                                 
*                                                                               
*                 AT ENTRY:   R6 =SD ADDRESS                                    
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                             PUSHES 8 REGISTERS                                
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R15=ERROR CODE                                    
*                             R13=DESTROYED                                     
*                             R14=DESTROYED                                     
*                             RETURN IS TO LINK+1 IF NO ERRORS                  
*                             RETURN IS TO LINK   IF ERRORS                     
*                 USES:       MMVVPN,MMRPPS,MMRSTM,MMSAC                        
*                                                                               
*                                                                               
MMRP     PUSH     8,R1                                                          
         BAL,R8   MMVVPN            VERIFY VPN                                  
         B        MM1409A                                                       
         LW,R14   SDMMCCS,R6        GET CONTROL START                           
         AND,R14  M17               MASK                                        
         SLS,R14  -9                R14=VP OF ZEROTH PAGE                       
         LW,R7    R9                VPNL                                        
         SW,R7    R14               R7=RPN OF VPNL                              
         LW,R5    R10               VPNH                                        
         SW,R5    R14               R5=RPN OF VPNH                              
         LI,R4    SDACICNT          OFFSET TO ACI COUNT                         
         LB,R4    *R6,R4            GET ACI COUNT                               
         AI,R4    SDACCIMG          OFFSET TO ACI                               
         AW,R4    R6                R4=FLAG IMAGE ADDRESS                       
         LI,R3    SDFLAGS                                                       
         LH,R0    *R6,R3            GET SEGMENT FLAGS                           
         LW,R15   R0                R0=SEG FLAGS                                
         AND,R15  XSDSTATE          R15=SEG STATE                               
         LW,R2    SDMMC,R6          R2=MAP IMAGE ADDRESS                        
         DO       #ROLL                                                         
         CI,R15   SDSTATE4          BEING ROLLED OUT                            
         BE       MM1403A               I/O LOCK OK                             
         FIN      #ROLL                                                         
MM1401   LB,R8    *R4,R7            GET FLAG BYTE                               
         CI,R8    SDRPP             CHECK RPP                                   
         BAZ      MM1411            B IF NOT SET                                
MM1402   EQU      %                                                             
         DO       #SIGMA9M                                                      
         LH,R3    *R2,R7            GET REAL PAGE #                             
         ELSE     #SIGMA9M                                                      
         LB,R3    *R2,R7            GET REAL PAGE #                             
         FIN      #SIGMA9M                                                      
         MTB,0     IOLOCK,R3        CHECK I/O LOCKS                             
         BNEZ     MM1410            B IF LOCKED                                 
MM1403   AI,R7    1                 MOVE TO NEXT PAGE                           
         CW,R7    R5                DONE ?                                      
         BLE      MM1401            B IF NO                                     
MM1403A  LW,R7    R9                R7=RPN OF VPNL                              
         SW,R7    R14                                                           
         CI,R0    SDRAC             CHECK FOR RAC                               
         BANZ     MM1409            B IF RAC                                    
         LI,R3    SDRPCNT           R3=OFFSET TO REAL PG CNT                    
         DO1      #ROLL                                                         
         LI,R1    SDNPCNT           R1=NEEDED PGS COUNT                         
MM1404   LB,R0    *R4,R7            GET PAGE FLAG                               
         CI,R0    SDRPP             CHECK RPP                                   
         BAZ      MM1406            B IF OFF                                    
         DO       #ROLL                                                         
         CI,R15   SDSTATE4          BEING ROLLED OUT                            
         BNE      MM1405            B IF NO                                     
         CI,R0    SDROL             PAGE ON RAD                                 
         BAZ      MM1406                NO, SAVE REAL PAGE                      
         FIN      #ROLL                                                         
MM1405   EOR,R0   XSDRPP            RESET RPP                                   
         DO       #SIGMA9M                                                      
         LH,R14   *R2,R7            R14= REAL PAGE #                            
         ELSE     #SIGMA9M                                                      
         LB,R14   *R2,R7            R14= REAL PAGE #                            
         FIN      #SIGMA9M                                                      
         DISABLE                                                                
         DO1      #ROLL             INCR PGS NEEDED FOR ROLLIN                  
         MTB,1    *R6,R1                                                        
         STB,R0   *R4,R7            RESTORE FLAGS                               
         MTB,-1   *R6,R3            DECR REAL PG CNT                            
         BAL,R8   MMRSTM            RELEASE A PAGE                              
MM1406   AI,R7    1                 MOVE TO NEXT PAGE                           
         CW,R7    R5                DONE ?                                      
         BLE      MM1404            B IF NO                                     
         DO       #ROLL                                                         
         CI,R15   SDSTATE4          BEING ROLLED OUT                            
         BE       MM1408                DO NOT ALTER ACCES CODES                
         FIN      #ROLL                                                         
MM1407   LI,R0    3                 ACCESS CODE = NO ACCESS                     
         BAL,R8   MMSAC             SET ACCESS CODES                            
MM1408   PULL     8,R1                                                          
         AI,R8    1                 NORMAL EXIT                                 
         B        OLAYEXIT                                                      
MM1409   BAL,R8   MMRPPS            RELEASE PREFERRED PAGES                     
         B        MM1409A           ERROR                                       
         B        MM1407                                                        
MM1409A  PULL     8,R1                                                          
         B        OLAYEXIT          ERROR EXIT                                  
MM1410   LI,R15   TYC99             NO- ERROR                                   
         B        MM1409A           RETURN                                      
MM1411   CI,R15   SDSTATE0          BEING ERASED                                
         BE       MM1403            B IF YES                                    
         LI,R15   TYC98             ERROR ON RELEASE PAGE                       
         B        MM1409A                                                       
         TITLE    '** MMO2 - DEACTIVATE A SEGMENT **'                           
*                                                                               
*        MMDEACT  DEACTIVATE A SEGMENT                                          
*                                                                               
*                 AT ENTRY:   R2 =CAL ADDRESS                                   
*                             R3 =FPT ADDRESS                                   
*                             R8 =LINK                                          
*                             R11=SEGMENT NUMBER                                
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R5 =DESTROYED                                     
*                             R6 =SD ADDRESS                                    
*                             R7 =DESTROYED                                     
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                             R11=SEGMENT NUMBER                                
*                             R12=AST ADDRESS                                   
*                             R14=DESTROYED                                     
*                             R15=ERRORCODE                                     
*                             RETURN IS TO LINK IF ERROR                        
*                             RETURN IS TO LINK+1 IF NO ERROR                   
*                             NOTE NO ERROR CODE IF PRIMARY                     
MMDEACT  BIFPRIM  MM1905                                                        
         PUSH     R8                SAVE LINK                                   
         BAL,R8   MMSEGCK           SET R6=SD,R12=AST AS F(SEG#)                
         B        MM1907            ERROR SEG NUM BAD                           
         B        MM1906            INACTIVE SEGMENT (ERROR X'9B')              
         LW,R9    SDMMCCS,R6        GET START VIRTUAL PAGE                      
         SLS,R9   15                PUT IN HIGH ORDER BYTE                      
         LB,R9    R9                GET VPNL (REG.IS CLEAN IN HIGH BITS         
         LI,R5    SDVPCNT                                                       
         LB,R10   *R6,R5            GET VIRTUAL PAGE COUNT                      
         AI,R10   -1                ADJUST FOR COUNT                            
         AW,R10   R9                YEILDS VPNH                                 
         BAL,R8   MMSDS             ACTIVE SEGMENT-KEEP OTHER TASKS OUT         
         DISABLE                                                                
         EOR,R6   XASTACT           RESET ACTIVE BIT                            
         STW,R6   *R12              R12 HAS AST ENTRY ADDRESS                   
         LI,R5    SDTACT                                                        
         MTB,-1   *R6,R5            DECREMENT ACTIVITY COUNT                    
         BNEZ     MM1903            B IF SOMEBODY STILL USING SEG               
         LI,R5    SDFLAGS                                                       
         LH,R7    *R6,R5            GET SEGMENT FLAGS                           
         LI,R15   SDSTATE           MASK                                        
         LI,R14   SDSTATE2          INACTIVE                                    
         STS,R14  R7                MAKE STATE INACTIVE                         
         STH,R7   *R6,R5            RESTORE FLAGS                               
MM1903   ENABLE                                                                 
         BAL,R8   MMRDS             RELEASE SD                                  
         BAL,R8   LOADACI           LOAD ACCESS CODES INTO                      
         DO       #ROLL                                                         
         MTW,1    ROLL99            INCR RE-ENT FOR ROLL OUT SCAN               
         BAL,R8   MMSTART           START MEM EXEC                              
         FIN      #ROLL                                                         
         PULL     R8                RESTORE LINK                                
         LI,R15   TYCNORM           TYC                                         
         AI,R8    1                 NORMAL EXIT                                 
         B        OLAYEXIT                                                      
MM1905   LI,R15   TYC6A             INVALID CAL TO CALLER                       
         B        OLAYEXIT          ERROR EXIT                                  
MM1906   LI,R15   TYC9B             ERROR CODE                                  
MM1907   PULL     R8                ERROR EXIT                                  
         B        OLAYEXIT                                                      
         TITLE    '** MMO2 - ERASE A SEGMENT **'                                
*                                                                               
*        MMERASE  ERASE A SEGMENT                                               
*                                                                               
*                 AT ENTRY:   R2 =CAL ADDRESS                                   
*                             R3 =ADDRESS OF FPT                                
*                             R8 =LINK                                          
*                             R11=SEGMENT NUMBER                                
*                                                                               
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R2 =DESTROYED                                     
*                             R3 =ADDRESS OF FPT                                
*                             R5 =DESTROYED                                     
*                             R6 =SD ADDRESS                                    
*                             R7 =DESTROYED                                     
*                             R8 =LINK                                          
*                             R9 =UPNL                                          
*                             R10=VPNH                                          
*                             R11=SEGMENT NUMBER                                
*                             R12=AST ADDRESS                                   
*                             R14=DESTROYED                                     
*                             R15=ERROR CODE                                    
*                                                                               
*                             RETURNS TO LINK IF ERROR                          
*                             RETURNS TO LINK+1 IF NO ERROR                     
*                                                                               
MMERASE  BIFPRIM  MM2012            NO PRIMARYS                                 
         PUSH     R8                SAVE LINK                                   
         BAL,R8   MMSEGCK           SET R6=SD,R12=AST AS F(SEG#)                
         B        MM2002            ERROR                                       
         B        MM2001            INACTIVE                                    
*                                   ACTIVE                                      
MM2001   LW,R9    SDMMCCS,R6        GET START VIRTUAL PAGE                      
         AND,R9   M17               MASK -R9 NOW HAS START WORD ADDRESS         
         LI,R5    SDVPCNT                                                       
         LB,R10   *R6,R5            GET NUMBER OF PAGES IN SEGMENT              
         SLS,R10  9                 NUMBER OF  WORDS                            
         AW,R10   R9                PLUS STARTING BASE                          
         AI,R10   -1                MINUS 1 YEILDS LAST WORD ADDRESS            
         XW,R9    R10                                                           
         XW,R9    R11               GET THEM INTO  DOUBLE WORD REG.             
         CLM,R2   R10               CHECK CAL ADDRESS                           
         BCR,9    MM2011            B IF OUT OF LIMITS                          
         CLM,R3   R10               CHECK FPT ADDRESS                           
         BCR,9    MM2011            B IF OUT OF LIMITS                          
         XW,R9    R11                                                           
         XW,R9    R10               RESTORE REGISTERS                           
         SLS,R9   -9                YEILDS VPNL                                 
         SLS,R10  -9                YEILDS VPNH                                 
         CW,R6    XASTFA            IS FIRST ACTIVATE FLAG SET                  
         BANZ     MM2003            B IF YES                                    
         LB,R5    TCBPOINT          IS TASK IN TERMINATION                      
         LB,R5    STILMID,R4        TEST FOR TASK IN TERMINATION                
         LH,R0    LMISTAT,R5        TRY TO STRAIGHTED OUT IF SO                 
         CI,R0    LMIT                                                          
         BANZ     MM2013                YES, TRY TO STRAIGHTEN                  
         LI,R15   TYC9D             ERROR CODE                                  
MM2002   PULL     R8                GET LINK                                    
         B        OLAYEXIT          ERROR EXIT                                  
MM2003   BAL,R8   MMSDS             ACQUIRE EXCL USE OF SD                      
         LI,R5    SDFLAGS               R5=OFFSET TO FLAGS HW                   
         LI,R7    SDTERASE                                                      
         LB,R0    *R6,R7            GET NUMBER OF TASKS ERASED                  
         CI,R0    1                 =1, RELEASE PAGES                           
         BNE      MM2005            B IF NOT ONE                                
MM2004   LH,R0    *R6,R5            SET STATE TO 'BEING ERASED'                 
         AND,R0   XSDSTMSK              SDSTATE0 OR 0                           
         STH,R0   *R6,R5                                                        
         BAL,R8   MMRP              RELEASE REAL PAGES                          
         B        MM2010                ERROR (INCL IO ACTIVE)                  
MM2005   LH,R7    *R6,R5            GET SEGMENT FLAGS                           
         CW,R6    XASTACT           SEGMENT ACTIVE TO THIS TASK                 
         BAZ      MM2006            B IF NO                                     
         EOR,R6   XASTACT           RESET ACTIVE BIT                            
         LI,R2    SDTACT                                                        
         DISABLE                                                                
         MTB,-1   *R6,R2            DECREMENT TASKS ACTIVE                      
         BNEZ     MM2006            B IF SDTACT NOT ZERO                        
         LI,R15   SDSTATE           MASK                                        
         LI,R14   SDSTATE2          STATE = INCACTIVE                           
         STS,R14  R7                SET STATE INACTIVE                          
         STH,R7   *R6,R5            REPLACE IN SD                               
MM2006   EOR,R6   XASTFA            RESET FIRST ACTIVATE                        
         DISABLE                                                                
         STW,R6   *R12              STORE INTO AST                              
         LI,R2    SDTERASE                                                      
         MTB,-1   *R6,R2            DECREMENT TASKS ERASED                      
         BNEZ     MM2007            B IF TERASED DID NOT GO TO ZERO             
         LI,R15   SDSTATE           MASK                                        
         LI,R14   SDSTATE1          STATE ERASED                                
         STS,R14  R7                SET STATE                                   
         STH,R7   *R6,R5            RESTORE IN SD                               
MM2007   ENABLE                                                                 
         BAL,R8   MMRDS             RELEASE EXCL USE OF SEG                     
         DO       #ROLL                                                         
         MTW,1    ROLL99            INCR ROLL OUT REENT                         
         BAL,R8   MMSTART           START MEM  EXEC                             
         FIN      #ROLL                                                         
         BAL,R8   LOADACI           LOAD ACCESS CODES INTO HARDWARE             
MM2008   PULL     R8                                                            
         AI,R8    1                 NORMAL EXIT                                 
         LI,R15   TYCNORM           NORMAL COMPLETION                           
         B        OLAYEXIT                                                      
MM2009   LI,R15   TYC99             ERROR CODE                                  
MM2010   BAL,R8   MMRDS             RELEASE SD                                  
         B        MM2002            EXIT                                        
MM2011   LI,R15   TYC9F             ERROR CODE                                  
         B        MM2002            EXIT                                        
MM2012   LI,R15   TYC6A             ILLEGAL CAL FOR CALLER                      
         B        OLAYEXIT          ERROR EXIT                                  
MM2013   CW,R6    XASTDS            IN PROCESS AT TERM                          
         BANZ     MM2014                YES                                     
         BAL,R8   MMSDS                 NO, ACQUIRE USE OF SEG                  
MM2014   LI,R5    SDTERASE          IS SEG IS USE                               
         LB,R0    *R6,R5                BY ANY OTHER TASKS                      
         BNEZ     MM2007                YES, EXIT NORMALLY                      
         MTB,1    *R6,R5            INCR 'ERASE' COUNT AND                      
         B        MM2004               REDO ERASE                               
         TITLE    '** MMO2 - GET PAGE **'                                       
*                                                                               
*        MMGETP   PROCESSES GETPAGE CAL REQUESTS                                
*                                                                               
*                 AT ENTRY:   R2 =CAL ADDRESS                                   
*                             R3 =FPT ADDRESS                                   
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                             R11=SEGMENT NUMBER                                
*                                                                               
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R1 =DESTROYED                                     
*                             R2 =DESTROYED                                     
*                             R5 =DESTROYED                                     
*                             R6 =SD ADDRESS                                    
*                             R7 =DESTROYED                                     
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                             R11=SEGMENT NUMBER                                
*                             R12=AST ADDRESS                                   
*                             R14=DESTROYED                                     
*                             R15=ERROR CODE                                    
*                                                                               
*                             RETURN IS TO LINK IF ERROR                        
*                             RETURN IS TO LINK+1 IF NO ERROR                   
*                                                                               
MMGETP   PUSH     R8                SAVE LINK                                   
         BIFSEC   MM2103                                                        
         BAL,R8   MMGPPS            GET PREFERRED PAGES                         
         B        MM2102            ERROR                                       
         B        MM2107A           GO SET UP VPNL,VPNH                         
MM2101   LI,R15   TYCNORM           NORMAL COMPLETION                           
         PULL     R8                                                            
         AI,R8    1                 NORMAL EXIT                                 
         B        OLAYEXIT                                                      
MM2102   PULL     R8                                                            
         B        OLAYEXIT          ERROR EXIT                                  
MM2103   BAL,R8   MMSEGCK           SET R6=SD,R12=AST AS F(SEG#)                
         B        MM2102            ERROR                                       
         B        MM2103A           INACTIVE                                    
         B        MM2105            ACTIVE                                      
MM2103A  BAL,R8   MMFOV             FIND OVLOAD ENTRY                           
         B        MM2102            ERROR-NO ENTRY                              
         LI,R5    OVLMBL            OFFSET TO LOAD MODULE BYTE LENGTH           
         LW,R0    *R14,R5           GET BYTE LENGTH                             
         AND,R0   M24               MASK                                        
         CI,R0    0                 IS SEGMENT EMPTY                            
         BEZ      MM2103B           B IF EMPTY                                  
         LI,R15   TYC9A             ERROR CODE                                  
         B        MM2102                                                        
         DO       #ROLL                                                         
MM2103B  BAL,R8   MMSDS             ACQUIRE USE OF SEG                          
         LI,R5    SDFLAGS           IS SEGMENT ROLLED OUT                       
         LH,R8    *R6,R5                                                        
         AND,R8   XSDSTATE                                                      
         CI,R8    SDSTATE5                                                      
         BNE      MM2105A               NO, AOK                                 
         BAL,R8   MMRISEG           CALL SUBR TO ROLL IN SEG                    
         B        MM2108                ERROR EXIT                              
         B        MM2105A               AND CONTINUE                            
         ELSE                                                                   
MM2103B  EQU      %                                                             
         FIN      #ROLL                                                         
MM2105   BAL,R8   MMSDS             ACQUIRE EXCL USE OF SD                      
MM2105A  BAL,R8   MMGP              GET REAL PAGES                              
         B        MM2108            ERROR                                       
         CW,R6    XASTFA            FROM ERASED STATE IN TASK                   
         BANZ     MM2106                NO                                      
         OR,R6    XASTFA                YES, SET FIRST ACTIVATE                 
         LI,R5    SDTERASE              INCR 'ERASE' COUNT                      
         DISABLE                                                                
         MTB,1    *R6,R5                                                        
MM2106   CW,R6    XASTACT           FROM INACTIVE STATE                         
         BANZ     MM2107                NO, FROM ACTIVE                         
         OR,R6    XASTACT               YES, SET ACTIVE                         
         DISABLE                                                                
         STW,R6   *R12              SET INTO AST                                
         LI,R5    SDTACT                                                        
         MTB,1    *R6,R5            INCREMENT TASKS ACTIVE                      
         LI,R5    SDFLAGS           SET SEGMENT STATE TO ACTIVE                 
         LH,R8    *R6,R5                                                        
         AND,R8   XSDSTMSK                                                      
         AI,R8    SDSTATE3                                                      
         STH,R8   *R6,R5                                                        
MM2107   ENABLE                                                                 
         BAL,R8   MMRDS             RELEASE EXCL USE OF SD                      
         BAL,R8   LOADMAP                                                       
MM2107A  EQU      %                                                             
         AI,R10   1                 MOVE VPNH FOR NEXT REQUEST                  
         STW,R10  R9                SET BPNL = VPNH                             
         B        MM2101                                                        
MM2108   BAL,R8   MMRDS             RELEASE SD                                  
         B        MM2102            ERROR EXIT                                  
         TITLE    '** MMO2 - RELEASE PAGE **'                                   
*                                                                               
*        MMRELP   PROCESSES  RELPAGES  CAL'S                                    
*                                                                               
*                 AT ENTRY:   R2 =CAL ADDRESS                                   
*                             R3 =FPT ADDRESS                                   
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                             R11=SEGMENT NUMBER                                
*                                                                               
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R1 =DESTROYED                                     
*                             R2 =DESTROYED                                     
*                             R5 =DESTROYED                                     
*                             R6 =SD ADDRESS                                    
*                             R7 =DESTROYED                                     
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                             R11=SEGMENT NUMBER                                
*                             R12=AST ADDRESS                                   
*                             R14=DESTROYED                                     
*                             R15=ERROR CODE                                    
*                                                                               
*                             RETURN IS TO LINK IF ERROR                        
*                             RETURN IS TO LINK+1 IF NO ERROR                   
*                                                                               
MMRELP   AI,R10   -1                REDUCE VPNH                                 
         AI,R9    -1                REDUCE VPNL                                 
         PUSH     R8                SAVE LINK                                   
         BIFSEC   MM2203            B IF SECONDARY                              
         BAL,R8   MMRPPS            RELEASE PREFERRED PARTITION  PAGES          
         B        MM2202            ERROR                                       
         B        MM2205            GO SET UP VPNL,VPNH                         
MM2201   LI,R15   TYCNORM           NORMAL COMPLETION                           
         PULL     R8                                                            
         AI,R8    1                 NORMAL EXIT                                 
         B        OLAYEXIT                                                      
MM2202   PULL     R8                                                            
         B        OLAYEXIT          ERROR EXIT                                  
MM2203   BAL,R8   MMSEGCK           SET R6=SD,R12=AST AS F(SEG#)                
         B        MM2202            ERROR                                       
         B        MM2206            INACTIVE (ERROR X'9B')                      
         BAL,R8   MMSDS             ACTIVE -LOCK OUT OTHER TASKS                
         BAL,R8   MMRP              RELEASE PAGES                               
         B        MM2207            ERROR                                       
         LI,R5    SDRPCNT                                                       
         LB,R5    *R6,R5            GET REAL PAGE COUNT                         
         BNEZ     MM2204            B IF PAGES  STILL IN SEGMENT                
         BAL,R8   MMFOV             FIND OVLOAD TABLE ENTRY                     
         B        MM2207            ERROR NO OVLOAD ENTRY                       
         LI,R5    OVLMBL                                                        
         LW,R5    *R14,R5           GET LOAD MODULE BYTE LENGTH                 
         AND,R5   M24               MASK                                        
         CI,R5    0                 IS IT AN EMPTY SEGMENT                      
         BNEZ     MM2204            B IF NOT EMPTY                              
         LW,R1    XASTACT           ACTIVE FLAG                                 
         OR,R1    XASTFA            FIRST ACTIVATION FLAG                       
         LI,R0    0                 SET TO STORE ZEROES                         
         STS,R0   R6                RESET FLAGS                                 
         LI,R7    SDFLAGS           R7=OFFSET TO SEG STATE                      
         LI,R1    SDSTATE           R1=STATE MASK FOR STS                       
         DISABLE                                                                
         STW,R6   *R12              STORE BACK IN AST                           
         LH,R0    *R6,R7            R0=CURRENT STATE                            
         LI,R5    SDTACT                                                        
         MTB,-1   *R6,R5            DECREMENT TASKS ACTIVE                      
         BNEZ     MM2203A           B IF SEGMENT STILL ACTIVE                   
         LI,R0    SDSTATE2          INACTIVE STATE                              
MM2203A  LI,R5    SDTERASE                                                      
         MTB,-1   *R6,R5            DECREMENT TASKS ERASED                      
         BNEZ     MM2204            B IF SEGMENT NOT ERASED                     
         LI,R0    SDSTATE1          ERASED STATE                                
MM2204   LH,R5    *R6,R7            R5=STATE AND FLAGS                          
         STS,R0   R5                SET SEGMENT STATE                           
         STH,R5   *R6,R7            RESTORE IN SD                               
         ENABLE                                                                 
         BAL,R8   MMRDS                                                         
         DO       #ROLL                                                         
         MTW,1    ROLL99            INCR ROLL SCAN RETRY                        
         BAL,R8   MMSTART           START MEM EXEC                              
         FIN      #ROLL                                                         
         BAL,R8   LOADACI                                                       
MM2205   STW,R9   R10               SET VPNH = VPHL                             
         B        MM2201                                                        
MM2206   LI,R15   TYC9B             ERROR CODE                                  
         B        MM2202                                                        
MM2207   BAL,R8   MMRDS             RELEASE SD                                  
         B        MM2202            ERROR EXIT                                  
         TITLE    '** MMO2 - SUBROUTINE TO CLEAN UP MAPPED TASK **'             
*******************                                                             
*    MMTSEC       *    SUBR TO CLEAN UP MAPPED TASK AT TERMINATION              
*******************                                                             
*                                                                               
* ENTRY  R4       TASK ID                                                       
*        R5       LMID                                                          
*        BAL,R8   MMTSEC                                                        
* EXIT   +1                                                                     
*                                                                               
* REGISTERS USED: R0-R3,R9-R15                                                  
*          SAVED: R4-R8                                                         
* STACK WORDS:    1                                                             
* SUBROUTINES:    RELTEMP,MMRELSD,MMERASE,MMRRFILE,MMSTART                      
*                                                                               
MMTSEC   PUSH     5,R4              SAVE EXIT                                   
*                                                                               
*                                   ***** DO SEGMENT DESCRIPTORS *****          
*                                                                               
         LW,R6    STITCB,R4         FIND THE STCB                               
         LW,R12   STCBAST,R6        DETATCH THE TASK FROM                       
         BEZ      MM5336                THE SEGMENTS IF AST                     
         B        MM5330            SKIP OVSD                                   
*                                       IS ZERO, THERE ARE NO                   
*                                       SEGMENTS.                               
MM5302   LI,R15   0                     R12=AST ENTRY, R15=0                    
         LW,R6    *R12                  R6=SD (SEG DESCRIPTOR)                  
         BLEZ     MM5330                AST ENTRY NOT USED                      
         CW,R6    XASTDS            TASK TERMINATED WITH 'DS'                   
         BANZ     MM5304                SET ON THIS SEGMENT                     
         CW,R6    XASTFA                CURRENTLY ERASED?                       
         BAZ      MM5306                YES                                     
MM5304   LW,R11   2,R6                  ERASE THE SEGMENT                       
         AND,R11  M16                   R11= SEGMENT NUMBER                     
         LI,R3    0                     SET R3=NOT IN SEG                       
         BAL,R8   MMERASE           CALL THE ERASE SUBR                         
         B        MM5340                ERROR EXIT                              
*                                       R6=SD ADDRESS                           
         DO       #ROLL             DO IF ROLLOUT                               
MM5306   LW,R0    STITCB,R4         TASK LOCKED                                 
         CW,R0    XSTILOCK                                                      
         BAZ      MM5308                NO                                      
         LI,R2    SDTLOCK               YES, DECR LOCKED TASKS                  
         MTB,-1   *R6,R2                COUNT                                   
MM5308   LI,R2    SDTUSING          DECREMENT THE USING TASK                    
         ELSE                           COUNT                                   
MM5306   LI,R2    SDTUSING                                                      
         FIN      #ROLL                                                         
         LW,R3    M24                   R3=ADDRESS  MASK                        
         LI,R1    SDFLAGS               R1=OFFSET TO SD TYPE                    
         LB,R4    TCBPOINT          LOCATE THE HEAD OF THE                      
         LB,R5    STIJID,R4             SEGMENT DESCRIPTOR                      
         LW,R5    SJI1,R5               CHAIN IN THE JCB                        
         DISABLE                                                                
         LH,R1    *R6,R1                FETCH SEGMENT TYPE                      
         AND,R1   XSDTYPE               ISOLATE IT                              
         MTB,-1   *R6,R2                USING TASKS COUNT-1                     
         BNEZ     MM5328                NON-ZERO, DO NEXT SD                    
         SLS,R1   -7                                                            
         EXU      %+1,R1                BRANCH ON TYPE                          
         B        MM5330                00-TASK LEVEL                           
         B        MM5310                01-JOB LEVEL                            
         B        MM5318                02-SYSTEM LEVEL                         
         B        MM5316                03-PUBLIB                               
         B        MM5330                04-NOT USED                             
         B        MM5330                05-TASK RESERVED PAGES                  
         B        MM5340                06-JOB RESERVED PAGES                   
         B        MM5330                07-SYSTEM OVERLAY                       
*                                   RELEASE ALL TASK RESERVED                   
*                                       SD AT END OF LOOP                       
MM5310   LW,R2    JCBSDT,R5             R2=SD POINTER                           
MM5312   CW,R2    M24               END OF CHAIN?                               
         BAZ      MM5340                ERROR, SD NOT IN PROPER                 
*                                       CHAIN                                   
         CS,R2    R6                    NEXT SD=ONE WITH 0 COUNT?               
         BNE      MM5314                NO                                      
         LW,R9    SDFLINK,R6            CHAIN FLINK FROM SD BEING               
         CS,R2    JCBSDT,R5             HEAD OF CHAIN BEING REMOVED?            
         BNE      MM5322                NO                                      
         LW,R0    JCBSDT,R5             PRESERVE BYTE 1 IN                      
         LB,R0    R0                    CASE IT IS EVER USED                    
         STB,R0   R9                                                            
         STW,R9   JCBSDT,R5             DELETED TO JCB                          
         B        MM5326                GO FREE SD SPACE                        
MM5314   LW,R7    R2                MOVE THROUGH SD CHAIN                       
         LW,R2    SDFLINK,R2            SEARCHING FOR ONE TO BE                 
         B        MM5312                DELETED.                                
*                                                                               
MM5316   LI,R2    SDLMID            FREE PUBLIB LMI                             
         LB,R2    *R6,R2                GET INDEX FROM SD                       
         CB,R2    STILMID,R5        DO NOT BELEASE LMI IF TH BELONGS            
         BE       MM5318            TO TERMINING TASK (WINDOW IN INIT)          
         LI,R0    0                                                             
         LI,R1    0                                                             
         STH,R0   LMISTAT,R2                                                    
         STD,R0   LMINAME,R2                                                    
         MTW,1    RUN99                                                         
*                                                                               
MM5318   LW,R2    S:SD                  R2=HEAD OF SYSTEM CHAIN                 
MM5320   CW,R2    M24                   END OF CHAIN?                           
         BAZ      MM5340                ERROR,SD NOT IN CHAIN                   
         CS,R2    R6                    MEMBER FOUND?                           
         BNE      MM5324                NO                                      
         LW,R9    SDFLINK,R6            SET R1= FLINK TO                        
         CS,R2    S:SD                  REMOVING CHAIN HEAS?                    
         BNE      MM5322                NO                                      
         LW,R0    S:SD                  YES, PRESERVE BYTE                      
         LB,R0    R0                    ZERO                                    
         STB,R0   R9                                                            
         STW,R9   S:SD                                                          
         B        MM5326                RELEASE THE SD                          
*                                                                               
MM5322   LW,R0    SDFLINK,R7            REMOVE SD FROM CHAIN BUT                
         LB,R0    R0                    PRESERVE LMI IN PREV                    
         STB,R0   R9                    MEMBER                                  
         STW,R9   SDFLINK,R7                                                    
         B        MM5326                RELEASE SD                              
*                                                                               
MM5324   LW,R7    R2                SET R7=PREVIOUS MEMBER                      
         LW,R2    SDFLINK,R2            R2=NEXT                                 
         B        MM5320                                                        
*                                                                               
MM5326   ENABLE                     SD NOW OUT OF CHAIN AND                     
*                                   UNREG TO OTHER TASKS                        
         DO1      #ROLL                                                         
         BAL,R8   MMRRFILE          RELEASE RAD SPACE                           
         BAL,R8   MMRELSD           RELEASE THE SD SPACE                        
         B        MM5330                DONE                                    
*                                                                               
MM5328   CI,R1    SDTYPE6           JOB RESERVED PAGES                          
         BNE      MM5330                NO                                      
         OR,R6    XASTAFA                YES, SET ACTIVE                        
         B        MM5332                FOR JOB CLEANUP IF REQD                 
*                                                                               
MM5330   LI,R6    0                 SD DONE, ZERO OR RESTORE AST                
MM5332   STW,R6   *R12                                                          
         ENABLE                                                                 
         AI,R12   1                     ADVANCE TO THE NEXT AST                 
         MTB,-1   R12                   DONE?                                   
         BNEZ     MM5302                NO                                      
*                                                                               
*        RELEASE ALL THE TASK LEVEL                                             
         LB,R5    STILMID,R4            SEGMENT DESCRIPTORS                     
         LW,R6    LMISDT,R5             AT ONCE                                 
MM5334   AND,R6   M24                   DONE?                                   
         BEZ      MM5336                YES                                     
         LW,R2    SDFLINK,R6            SAVE NEXT CHAIN MEMBER                  
         DO1      #ROLL                                                         
         BAL,R8   MMRRFILE          RELEASE RAD SPACE                           
         BAL,R8   MMRELSD               RELEASE SD                              
         LW,R6    R2                    SWAP TO NEXT MEMBER                     
         B        MM5334                                                        
*                                                                               
         DO       #ROLL             DO IF ROLLOUT                               
MM5336   LW,R0    LMIRECB+MMLMID    MEM REQ QUEUED                              
         BEZ      MM5338                NO                                      
         MTW,1    ROLL99                YES                                     
         BAL,R8   MMSTART               START MEM EXEC                          
MM5338   PULL     5,R4              EXIT                                        
         ELSE                                                                   
MM5336   PULL     5,R4              EXIT                                        
         FIN      #ROLL                                                         
         B        OLAYEXIT                                                      
*                                                                               
MM5340   CRASH    'MM53-ERROR'                                                  
         TITLE    '** MMO2 - SUBROUTINE TO RELEASE SD SPACE **'                 
*******************                                                             
*    MMRELSD      *    SUBR TO FREE SD SPACE TO TSPACE MANAGER                  
*******************                                                             
*                                                                               
* ENTRY  R6       SD ADDRESS                                                    
*        BAL,R8   MMRELSD                                                       
* EXIT   +1       RETURNS TO LINK+1                                             
* REGISTERS USED: R0,R9-R11                                                     
*          SAVED: R1-R7,R12-R15                                                 
* SUBROUTINES:    RELTEMP                                                       
* STACK WORDS:    2                                                             
*                                                                               
MMRELSD  PUSH     2,R7              SAVE REGISTERS                              
         LW,R0    SDMMC,R6          BUILD RELTEMP ARGUMENT                      
         LI,R7    SDMMCCNT             START OF MAP+MAP LGTH-BASE               
         LB,R7    *R6,R7                                                        
         AW,R0    R7                                                            
         SW,R0    R6                                                            
         LW,R7    R6                                                            
         STB,R0   R7                                                            
         BAL,R8   RELTEMP           FREE SPACE                                  
         PULL     2,R7              RESTORE REGISTERS                           
         B        OLAYEXIT                                                      
         TITLE    '** MMO2 - SUBROUTINE TO CLEANUP JOB SEGMENTS **'             
*******************                                                             
*    MMTJOB       *    SUBR TO DO JOB LEVEL CLEANUP, ESP JRP                    
*******************                                                             
*                                                                               
* ENTRY  R1       JCB ADDRESS                                                   
*        R6       JOB ID                                                        
*        BAL,R8   MMTJOB                                                        
* EXIT   +1                                                                     
* REGISTERS USED: R0,R9-R11                                                     
*          SAVED: R1-R7,R12-R15                                                 
* STACK WORDS:    5                                                             
* SUBROUTINES:    MMRELSD,MMRP,MMRRFILE,MMSETVPN                                
*                                                                               
MMTJOB   PUSH     5,R4              SAVE REGISTERS                              
         LW,R6    JCBSDT,R1         RELEASE JOB SD'S                            
MM5502   AND,R6   M17                   RELEASE SD'S FROM                       
         BEZ      MM5506                JOB                                     
         LI,R4    SDRPCNT               DOES SEG HAVE REAL PAGES                
         LB,R0    *R6,R4                LEFT                                    
         BEZ      MM5504                NO, ONLY RELEASE SD,FILE                
         BAL,R8   MMSETVPN              YES, SET VPNL,VPNH                      
         LI,R5    SDFLAGS           SET STATE TO BEING ERASED                   
         LH,R0    *R6,R5                (ZERO)                                  
         AND,R0   XSDSTMSK                                                      
         STH,R0   *R6,R5                                                        
         BAL,R8   MMRP                  AND RELEASE REAL PAGES                  
         B        MM5508                ERROR, CRASH FOR NOW                    
MM5504   EQU      %                                                             
         DO1      #ROLL                                                         
         BAL,R8   MMRRFILE              ASSIGNED TO SEG IF ROLL                 
         LW,R5    SDFLINK,R6            R5=FORWARD 'SD' LINK                    
         BAL,R8   MMRELSD           RELEASE SD                                  
         LW,R6    R5                    R6=NEXT 'SD' IF ONE                     
         B        MM5502            GO TEST FOR AND RELEASE                     
MM5506   PULL     5,R4              RESTORE RREGISTERS                          
         B        OLAYEXIT                                                      
MM5508   CRASH    'MM55-ERROR'                                                  
         TITLE    '** MMO2 - SUBROUTINE TO RELEASE AST,ACI **'                  
*******************                                                             
*    MMRELS       *    SUBR TO RELEASE ACI AND AST                              
*******************                                                             
*                                                                               
* ENTRY  R4       TASK ID                                                       
*        BAL,R8   MMRELS                                                        
* EXIT   +1                                                                     
* REGISTERS USED: R0,R1,R7                                                      
*          SAVED: R2-R6,R9-R15                                                  
* STACK WORDS:    1                                                             
*                                                                               
MMRELS   PUSH     R8                SAVE EXIT                                   
         LW,R1    STITCB,R4         FETCH TCB ADDRESS                           
         LI,R7    0                 ZERO AND FETCH                              
         XW,R7    STCBACI,R1        ACI ADDRESS                                 
         BEZ      MM5602                NOT PRESENT                             
         BAL,R8   RELTEMP                                                       
MM5602   LI,R7    0                 ZERO AND FETCH                              
         XW,R7    STCBAST,R1        AST ADDRESS                                 
         BEZ      MM5604                NOT PRESENT                             
         BAL,R8   RELTEMP               RELEASE AST                             
MM5604   PULL     R8                EXIT                                        
         B        OLAYEXIT                                                      
OLAYEXIT EQU      %                                                             
MMO2EXIT B        *R8               COMMON EXIT                                 
         OLAYEND                                                                
         END                                                                    
