         PCC      0                                                             
         SYSTEM   SIG9P                                                         
         SYSTEM   OPTIONS                                                       
         SPACE    2                                                             
        DO       #MAP                                                           
*                                                                               
*                                                                               
*                                                                               
         DEF      MMO3                                                          
         DEF      MMO3EXIT                                                      
         DEF      MMGPPS,MMRPPSI,MMGTRP,MMGJRP,MMRTRP,MMRJRP                    
         DEF      MMSWLK,MMTPRIM,MMRPPS                                         
OLAYFLAG EQU      'MMO3'                                                        
         PSYS     0                                                             
         SYSTEM   CPRMON                                                        
MMO3     RES      0                                                             
         TITLE    '** MMO3 **'                                                  
         TITLE    '** MMO3 - GET PREFERRED PARTITION PAGES **'                  
*                                                                               
*        MMGPPS   GET PREFERRED PARTITION PAGES                                 
*                                                                               
*                 AT ENTRY: (SECONDARY TASK)                                    
*                             R4=ADDRESS OF FLAGS IN SD                         
*                             R6=SD ADDRESS (DS SET)                            
*                             R5=RPN OF VPNL                                    
*                             R7=RPN OF VPNH                                    
*                             R8=LINK                                           
*                             R9=VPNL                                           
*                             R10=VPNH                                          
*                           (PRIMARY TASK)                                      
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R15=ERROR CODE (91,92,93,94)                      
*                             R14=DESTROYED                                     
*                             RETURN IS TO LINK+1 IF NO ERRORS                  
*                             RETURN IS TO LINK  IF ERROR                       
MMGPPS   PUSH     8,R1                                                          
         LW,R1    R7                SAVE R7                                     
         LW,R14   R9                                                            
         SLS,R14  9                 FORM WORD ADDRESS VPNL                      
         BAL,R8   MMFMP                                                         
         B        MM0313            NOT IN PARTITION                            
         LW,R3    PPT,R7            GET PPT WORD                                
         LB,R0    R3                                                            
         AND,R0   XPPTTYPE          TYPE CODE                                   
         CI,R0    PPTTYPE4          CHECK FOR PREFERRED                         
         BE       MM0302            B IF PREFFERED                              
         LI,R15   TYC91                                                         
         B        MM0311                                                        
MM0302   LW,R3    R7                SAVE PPT INDEX                              
         LW,R14   R10               SET UP TO CHECK VPNH                        
         SLS,R14  9                 FORM WORD ADDRESS                           
         BAL,R8   MMFMP                                                         
         B        MM0313            ERROR -NO PARTITION                         
         CW,R7    R3                SAME PARTITION ?                            
         BE       MM0303            B IF YES                                    
         LI,R15   TYC92             ERROR CODE                                  
         B        MM0311                                                        
MM0303   LW,R8    PPT,R7            R8=PCT ADDRESS                              
         LI,R3    PCTSP             SET R3= -RP OF VPNL WRT                     
         LB,R3    *R8,R3               PARTITION                                
         SW,R3    R9                                                            
         LW,R14   Y8                R14,R15=BIT OF NEXT                         
         LI,R15   0                     PAGE TO BE ACQUIRED                     
         SLD,R14  0,R3                                                          
         AI,R8    PCTALMP           R8=LOC OF ALLOC BITS                        
         LI,R2    PCTEXU-PCTALMP        R2=REL LOC OF EXU WORD                  
         BIFPRIM  MM0306            PRIMARY, NO SD, USE LOC TABLE               
         LW,R7    R1                RESTORE R7 TO ENTRY VALUE                   
         LI,R3    SDRPCNT           R3=OFFSET TO RP COUNT                       
         PUSH     R1                                                            
MM0304   LB,R0    *R4,R7            NEXT PAGE PRESENT ALREADY                   
         CI,R0    SDRPP                 TEST 'RPP' FLAG                         
         BANZ     MM0310                YES, ERROR                              
         DISABLE                                                                
         LD,R0    *R8                   FETCH ALLOC MAP                         
         OR,R0    R14                   AND SET ALLOC BIT                       
         OR,R1    R15                   THEN MAKE SURE IT WAS                   
         CD,R0    *R8                   NOT ALREADY SET                         
         BE       MM0310                IT WAS, QUIT                            
         STD,R0   *R8                   SAVE NEW ALLOC MAP                      
         LB,R0    *R4,R7                REFETCH FLAG BYTE                       
         OR,R0    XSDRPP                SET REAL PAGE PRESENT                   
         STB,R0   *R4,R7                                                        
         MTB,1    *R6,R3                INCR REAL PAGES PRESENT                 
         LI,R0    -1                    DECR MMTPAGES IF REQD                   
         EXU      *R8,R2                                                        
         ENABLE                                                                 
         SLD,R14  -1                GO TO NEXT PAGE                             
         AI,R7    1                                                             
         CW,R7    R5                    DONE                                    
         BLE      MM0304                NO CONTINUE                             
         PULL     R1                                                            
         B        MM0308            YES, GO SET WRITE LOCKS                     
*                                                                               
MM0306   LCW,R4   R3                R4=OFFSET TO LOCATOR WORD                   
         AI,R4    PCTLOC-PCTALMP                                                
         LW,R7    R9                COUNTER                                     
         LB,R6    TCBPOINT          R6=LOC VALUE                                
         LB,R6    STILMID,R6                                                    
         OR,R6    XPCTPS                                                        
MM0307   DISABLE                                                                
         LD,R0    *R8                   FETCH ALLOC MAP                         
         OR,R0    R14                   SET BIT FOR PAGE                        
         OR,R1    R15                   SEE IF IT WAS ALREADY                   
         CD,R0    *R8                   SET,                                    
         BE       MM0312                YES, QUIT                               
         STD,R0   *R8                                                           
         STW,R6   *R8,R4            SET LOCATOR                                 
         LI,R0    -1                    DECR MMTPAGES IF REQD                   
         EXU      *R8,R2                                                        
         ENABLE                     ADVANCE TO NEXT PAGE                        
         SLD,R14  -1                                                            
         AI,R4    1                                                             
         AI,R7    1                                                             
         CW,R7    R10                   DONE                                    
         BLE      MM0307                NO, CONTINUE                            
         LW,R0    LMISDT,R6         SET PREF PAGE ACQUIRED FLAG                 
         OR,R0    XLMIPP                                                        
         STW,R0   LMISDT,R6                                                     
*                                                                               
MM0308   EQU      %                                                             
         LI,R15   TYCNORM               R15=NORMAL                              
         PULL     8,R1              EXIT                                        
         AI,R8    1                                                             
         B        OLAYEXIT                                                      
*                                                                               
MM0310   ENABLE                     ERROR, RELEASE ANY PAGES                    
         PULL     R1                                                            
         CW,R1    R7                ANY PAGES DONE                              
         BE       MM0310A               NO                                      
         LW,R5    R7                SET R5=LAST PAGE DONE                       
         AI,R5    -1                                                            
         LW,R7    R1                    R7=ORIG RPN                             
         BAL,R8   MMRPPS            RELEASE PAGES                               
         NOP                                                                    
MM0310A  LI,R15   TYC93             SET PAGE NOT AVAIL TYC                      
MM0311   PULL     8,R1                                                          
         B        OLAYEXIT                                                      
MM0312   ENABLE                     ERROR, RELEASE ANY PAGES                    
         CW,R7    R9                ANY PAGES DONE?                             
         BE       MM0310A               NO                                      
         PUSH     R10                   YES, RESET TO DO                        
         LW,R10   R7                                                            
         AI,R10   -1                    ONLY PAGES ACQ                          
         BAL,R8   MMRPPS                                                        
         NOP                                                                    
         PULL     R10                                                           
         B        MM0310A                                                       
MM0313   LI,R15   TYC90             TYC=NOT IN PREF PARTITION                   
         B        MM0311                                                        
         TITLE    '** MMO3 - RELEASE PREF PARTITION PAGES **'                   
*                                                                               
*        MMRPPS   RELEASE PREFERRED PARTITION PAGES                             
*                                                                               
*                 AT ENTRY (SEC TASK)                                           
*                                   R4=ADDRESS OF FLAGS                         
*                                   R5=RPN OF VPNH                              
*                                   R6=SD ADDRESS (DS SET)                      
*                                   R7=RPN OF VNPL                              
*                                   R8=LINK                                     
*                         (PRIM TASK)                                           
*                                   R9=VNPL                                     
*                                   R10=VNPH                                    
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R14=DESTROYED                                     
*                             R15=ERROR CODES  (91,92,93,94,95                  
*                             RETURN IS TO LINK +1 IF NO ERRORS                 
*                             RETURN IS TO LINK IF ERROR                        
*                                                                               
MMRPPSI  PUSH     11,R1             SAVE REGISTERS                              
         B        MM0403                INTERNAL ENTRY, R7=RMPT INDEX           
*                                       R1=RPN ON VPNL                          
*                                       R5=RPN OF VPNH                          
*                                       R9,R10=VPNL,VPNH                        
*                                       R4=FLAGS ADDR                           
MMRPPS   PUSH     11,R1                                                         
         LW,R1    R7                SAVE R7                                     
         LW,R14   R9                VPHL                                        
         SLS,R14  9                 FORM WORD ADDRESS                           
         BAL,R8   MMFMP                                                         
         B        MM0412            NOT IN PARTITION                            
         LW,R3    PPT,R7            GET PPT WORD                                
         LB,R0    R3                GET FLAGS                                   
         AND,R0   XPPTTYPE          TYPE FIELD                                  
         CI,R0    PPTTYPE4          CHECK FOR PREFERRED                         
         BE       MM0402            B IF PREFERRED                              
         LI,R15   TYC91             ERROR CODE                                  
MM0401   PULL     11,R1                                                         
         B        OLAYEXIT          ERROR EXIT                                  
MM0402   LW,R3    R7                SAVE PPT INDEX                              
         LW,R14   R10               VPNH                                        
         SLS,R14  9                 WORD ADDRESS                                
         BAL,R8   MMFMP                                                         
         B        MM0412            ERROR -NO PARTITION                         
         CW,R7    R3                SAME PARTITION ?                            
         BE       MM0403            B IF YES                                    
         LI,R15   TYC92             ERROR CODE                                  
         B        MM0401            ERROR EXIT                                  
MM0403   LW,R8    PPT,R7            R8=PCT ADDRESS                              
         LI,R3    PCTSP             SET R3=-RP OF VPNL WRT                      
         LB,R3    *R8,R3               PARTITION                                
         SW,R3    R9                                                            
         LW,R14   Y8                R14-R15=BIT ALLOCATION                      
         LI,R15   0                                                             
         SLD,R14  0,R3                                                          
         LCW,R3   R3                    R3=REL PAGE BEING RELSD                 
         LW,R11   R8                    R11=BASE ADDR OF LOC                    
         AI,R11   PCTLOC                WORDS                                   
         AI,R8    PCTALMP           R8=LOC OF BIT MAP                           
         LW,R2    R9                R2=REAL PAGE #                              
         BIFPRIM  MM0405            PRIMARY LOGIC                               
         LW,R7    R1                R7=RPN OF VPNL                              
MM0404   LB,R0    *R4,R7            PAGE  PRESENT                               
         CI,R0    SDRPP                                                         
         BAZ      MM0411                NO                                      
         DISABLE                                                                
         MTB,0    IOLOCK,R2             CHECK FOR                               
         BEZ      %+3                   IO IN PROGRESS                          
         ENABLE                                                                 
         B        %-4                   WAIT FOR COMPLETION                     
         EOR,R0   XSDRPP                REVERSE RPP                             
         STB,R0   *R4,R7                                                        
         LD,R0    *R8                   RESET ALLOC BIT FOR PAGE                
         EOR,R0   R14                                                           
         EOR,R1   R15                                                           
         STD,R0   *R8                                                           
         LI,R1    SDRPCNT               R1=OFFSET TO RP CNT                     
         MTB,-1   *R6,R1                DECR RPP                                
         LI,R0    1                     INCR MMTPAGES IF REQD                   
         LI,R1    PCTEXU-PCTALMP                                                
         EXU      *R8,R1                                                        
         LI,R0    0                     ZERO LOCATOR                            
         STW,R0   *R11,R3                                                       
         ENABLE                     DO NEXT PAGE                                
MM0404A  SLD,R14  -1                                                            
         AI,R2    1                                                             
         AI,R3    1                                                             
         AI,R7    1                                                             
         CW,R7    R5                DONE                                        
         BLE      MM0404            NO                                          
         B        MM0409            GO SET WRITE LOCKS                          
*                                                                               
MM0405   LI,R4    PCTEXU-PCTALMP        R4=REL LOC OF EXU                       
         LB,R6    TCBPOINT          R6=LOCATOR VALUE                            
         LB,R6    STILMID,R6                                                    
         OR,R6    XPCTPS                                                        
         LI,R1    MMIOWAIT/6            APPROX WAIT TIME                        
MM0406   DISABLE                                                                
         MTB,0    IOLOCK,R2         LOCKED BY IO                                
         BEZ      MM0407                NO                                      
         ENABLE                                                                 
         BDR,R1   MM0406                WAIT                                    
         LI,R15   TYC99                 SET TYC                                 
         B        MM0401                ERROR EXIT                              
MM0407   CW,R6    *R11,R3           ALLOCATED TO THIS LOAD MOD                  
         BNE      MM0411                NO, ERROR                               
MM0408   LI,R0    0                                                             
         STW,R0   *R11,R3               ZERO LOCATOR                            
         LD,R0    *R8                   RESET ALLOC BIT FOR PAGE                
         EOR,R0   R14                                                           
         EOR,R1   R15                                                           
         STD,R0   *R8                                                           
         LI,R0    1                     INCR MMTPAGES IF REQD                   
         EXU      *R8,R4                                                        
         ENABLE                                                                 
         SLD,R14  -1                ADVANCE TO NEXT PAGE                        
         AI,R2    1                                                             
         AI,R3    1                                                             
         AI,R9    1                     INCR VNP TO VNPH                        
         CW,R9    R10                   DONE                                    
         BLE      MM0408                NO, CONTINUE                            
*                                                                               
MM0409   EQU      %                                                             
         LI,R15   TYCNORM               R15=NORMAL                              
         PULL     11,R1                                                         
         AI,R8    1                                                             
         B        OLAYEXIT          EXIT                                        
*                                                                               
MM0411   LI,R1    SDFLAGS           SEGMENT BEING ERASED                        
         LH,R0    *R6,R1                                                        
         AND,R0   XSDSTATE          MASK FOR SEG STATE FLAGS                    
         BEZ      MM0404A               PAGE NOT PRESENT OK                     
         LI,R15   TYC95             NOT ALLOC TO CALLER                         
         B        MM0401                                                        
MM0412   LI,R15   TYC90             TYC=NOT IN PREF PARTITION                   
         B        MM0401                ERROR EXIT                              
         TITLE    '** MMO3 - GET TASK/JOB RESERVED PAGE **'                     
*                                                                               
*        MMGTRP   GET TASK RESERVED PAGES                                       
*        MMGJRP   GET JOB  RESERVED PAGES                                       
*                                                                               
*                 RETURNS ONE RESERVED PAGE FOR EACH CALL                       
*                 CALLER SUPPLIES ACCESS CODE                                   
*                 ROUTINE EXITS WITH ACCESS CODES AND MAP LOADED                
*                 ERROR IF NO SPACE IS AVAILABLE                                
*                 AT ENTRY:   R0 =ACCESS CODES (2BIT) RT. JUSTIFIED             
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R14=VIRTUAL PAGE NUMBER OF ACQUIRED PAGE          
*                             RETURN IS TO LINK+1 IF NO ERRORS                  
*                             RETURN  IS TO LINK  IF ERROR                      
MMGTRP   AND,R0   M2                SAVE ACCESS CODES                           
         OR,R0    Y8                SET TASK RESERVED FLAG                      
         B        MM0701                                                        
MMGJRP   AND,R0   M2                SAVE ACCESS CODES                           
MM0701   PUSH     8,R5              SAVE REGS                                   
         LW,R9    R0                R9=ACCESS CODE FOR PAGE                     
         LI,R5    STCBAST           OFFSET TO AST POINTER                       
         LW,R12   *TCBPOINT,R5      R12= AST POINTER                            
         BEZ      MM0703A           B IF NO AST ?                               
MM0702   LI,R7    SDFLAGS           OFFSET TO FLAGS                             
         LW,R6    *R12              R6=SD ADDRESS AND FLAGS                     
         CW,R6    XASTACT           IS THIS SEGMENT ACTIVE                      
         BAZ      MM0703            B IF NO                                     
         LH,R7    *R6,R7            GET FLAGS                                   
         AND,R7   XSDTYPE                                                       
         MTW,0    R0                CHECK REQUEST TYPE                          
         BLZ      MM0705            B IF FOR TASK PAGES                         
         CI,R7    SDTYPE6           IS THIS SEGMENT JOB RESERVED PAGES          
         BE       MM0706            B IF YES                                    
MM0703   AI,R12   1                 DO NEXT AST UNTIL DONE                      
         MTB,-1   R12                                                           
         BNEZ     MM0702                                                        
MM0703A  LI,R15   TYCAF             TYC-MEM MGMT CONTROL GOOF                   
MM0704   PULL     8,R5              RESTORE REGS                                
         B        OLAYEXIT          ERROR EXIT                                  
MM0705   CI,R7    SDTYPE5           IS IT TASK RESERVED PAGES                   
         BNE      MM0703            B IF NO                                     
MM0706   BAL,R8   MMSDS             ACQUIRE EXCLUSIVE USE OF SD                 
         MTW,1    MMTPREQ           INCR PAGES REQUESTED                        
         DO       #ROLL                                                         
         LW,R5    LMIRECB+MMLMID        MEMORY REQUESTS QUEUED                  
         BEZ      MM0706A               NO                                      
         LW,R7    ECBPC,R5              YES, IT THE REQUESTOR                   
         LW,R8    XECBPR                HIGHER PRIORITY                         
         LB,R5    TCBPOINT              THAN FIRST QUEUE ENTRY                  
         CS,R7    STIPRIO,R5                                                    
         BGE      MM0711                NO, QUEUE REQUEST                       
         FIN      #ROLL                                                         
MM0706A  LI,R5    SDACICNT          OFFSET TO ACCESS IMAGE COUNT                
         LB,R5    *R6,R5            GET COUNT                                   
         AI,R5    SDACCIMG          OFFSET TO ACCESS IMAGE                      
         AW,R5    R6                YEILDS ADDRESS OF FLAG IMAGE                
         LI,R7    SDVPCNT                                                       
         LB,R7    *R6,R7            GET VIRTUAL PAGE COUNT                      
         AI,R7    -1                ADJUST COUNT FOR INDEX                      
MM0707   LB,R8    *R5,R7            GET PAGE FLAG                               
         CI,R8    SDRPP             IS PAGE PRESENT                             
         BAZ      MM0710            B IF NO                                     
MM0708   AI,R7    -1                                                            
         BGEZ     MM0707            B IF NOT DONE                               
         B        MM0712                ERROR, NO SPACE                         
MM0710   BAL,R8   MMGSTM            GET A REAL PAGE                             
         B        MM0711                                                        
         LB,R8    *R5,R7            GET FLAG BYTE                               
         OR,R8    XSDRPP            SET RPP                                     
         AND,R8   XFC                             (NOT PARAMETRIC CODE)         
         AND,R9   XSDAPCRP                                                      
         OR,R8    R9                SET ACCESS PROTECTION CODE IN FLAGS         
         STB,R8   *R5,R7            STORE INTO FLAG IMAGE                       
         LW,R5    0,R6              R5=MAP IMAGE ADDR                           
         DO       #SIGMA9M                                                      
         STH,R14  *R5,R7            SET REAL PAGE INTO MAP IMAGE (9)            
         ELSE     #SIGMA9M                                                      
         STB,R14  *R5,R7            SET REAL PAGE INTO MAP IMAGE (7)            
         FIN      #SIGMA9M                                                      
         LI,R5    SDRPCNT                                                       
         MTB,1    *R6,R5            INCREMENT REAL PAGE COUNT                   
         ENABLE                                                                 
         MTW,-1   MMTPREQ           DECREMENT TOTAL PAGES REQUESTED             
         LW,R0    R9                R0=ACCESS CODE FOR MMSAC                    
         LW,R9    SDMMCCS,R6        GET START VIRTUAL PAGE                      
         AND,R9   M17               MASK                                        
         SLS,R9   -9                JUSTIFY                                     
         AW,R9    R7                GIVES START PAGE  VPNL                      
         STW,R9   R10               GIVES END  PAGE  VPNH                       
         BAL,R8   MMSAC             SET THE ACCESS CODES                        
         BAL,R8   MMRDS             RELEASE EXCLUSIVE USE OF SD                 
         BAL,R8   LOADMAP           LOAD THE MAP                                
         LW,R14   R9                R14=VPN ACQUIRED                            
         PULL     8,R5                                                          
         AI,R8    1                 NORMAL EXIT                                 
         B        OLAYEXIT                                                      
         DO       #ROLL                                                         
MM0711   LW,R5    R3                SAVE R3 AND SET PAGES NEEDED                
         LI,R3    1                     TO 1                                    
         BAL,R8   MMROLL            WAIT FOR MEMORY                             
         B        MM0713                ERROR                                   
         LW,R3    R5                    RESTORE R3                              
         B        MM0706A                                                       
         ELSE                                                                   
MM0711   LI,R15   TYCA4             SET TYC=NO REAL PAGES                       
         B        MM0713                                                        
         FIN      #ROLL                                                         
MM0712   LI,R15   TYC98             PAGE ALLOCATION CONFLICT                    
MM0713   BAL,R8   MMRDS             RELEASE EXCL USE OF SEG                     
         B        MM0704            ERROR EXIT                                  
         TITLE    '** MMO3 - REL TASK/JOB RESERVED PAGE **'                     
*                                                                               
*        MMRTRP   RELEASE TASK RESERVED PAGE                                    
*        MMRJRP   RELEASE JOB RESERVED PAGE                                     
*                                                                               
*                 RELEASES ONE RESERVED PAGE FOR EACH CALL                      
*                 ROUTINE EXITS WITH RELEASED VIRTUAL PAGE MARKED               
*                 NO ACCESS.                                                    
*                 ERROR IF NO SD CAN BE FOUND.                                  
*                 ERROR IF RELEASING  PAGE ALREADY RELEASED                     
*                 ERROR IF PAGE HAS ONGOING IO                                  
*                 ERROR IF PAGE NUMBER  OUT OF  RANGE                           
*                 AT ENTRY:   R8 =LINK                                          
*                             R14=VIRTUAL PAGE TO BE RELEASED                   
*                                                                               
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R14=DESTROYED                                     
*                             RETURNS TO LINK+1 IF NO ERROR                     
*                             RETURNS TO LINK   IF ERROR                        
*                                                                               
MMRTRP   LW,R0    Y8                SET TASK FLAG                               
         CI,R14   MMTRPLL                                                       
         BL       MM0911            B IF TASK PAGE OUT OF RANGE                 
         CI,R14   MMTRPUL                                                       
         BG       MM0911            B IF TASK PAGE OUT OF RANGE                 
         B        MM0901                                                        
MMRJRP   LI,R0    0                 SET JOB FLAG                                
         CI,R14   MMJRPLL                                                       
         BL       MM0911            B IF JOB PAGE OUT OF RANGE                  
         CI,R14   MMJRPUL                                                       
         BG       MM0911            B IF PAGE OUT OF RANGE                      
MM0901   PUSH     9,R4                                                          
         LI,R5    STCBAST           OFFSET TO AST POINTER                       
         LW,R12   *TCBPOINT,R5      R12= AST POINTER                            
         BEZ      MM0903A           B IF NO AST                                 
MM0902   LI,R7    SDFLAGS           OFFSET TO FLAGS                             
         LW,R6    *R12              R6=SD ADDRESS AND FLAGS                     
         CW,R6    XASTACT           IS IT ACTIVE                                
         BAZ      MM0903            B IF NO                                     
         LH,R7    *R6,R7            GET FLAGS                                   
         AND,R7   XSDTYPE                                                       
         MTW,0    R0                CHECK TYPE REQUEST                          
         BLZ      MM0905            B IF TASK PAGES                             
         CI,R7    SDTYPE6           IS IT JOB SEGMENT                           
         BE       MM0906            B IF YES                                    
MM0903   AI,R12   1                 DO NEXT AST UNTIL DONE                      
         MTB,-1   R12                                                           
         BNEZ     MM0902                                                        
MM0903A  LI,R15   TYCAF             TYC=MEM MGMT GOOF                           
MM0904   PULL     9,R4                                                          
         B        OLAYEXIT          ERROR EXIT                                  
MM0905   CI,R7    SDTYPE5           IS IT TASK RESERVED PAGES                   
         BNE      MM0903            B IF NO                                     
MM0906   LI,R5    SDACICNT          OFFSET TO ACCESS IMAGE COUNT                
         LB,R5    *R6,R5            GET COUNT                                   
         AI,R5    SDACCIMG          OFFSET TO ACCESS IMAGE                      
         AW,R5    R6                R5=FLAG IMAGE ADDRESS                       
         LW,R7    SDMMCCS,R6        GET START VIRTUAL PAGE                      
         AND,R7   M17               MASK                                        
         SLS,R7   -9                JUSTIFY                                     
         SW,R7    R14               FORMS NEG INDEX                             
         LCW,R7   R7                R7=PAGE INDEX                               
         BAL,R8   MMSDS             ACQUIRE EXCL USE OF SD                      
         LB,R8    *R5,R7            GET FLAG BYTE                               
         CI,R8    SDRPP             REAL PAGE PRESENT                           
         BAZ      MM0908            B IF NO                                     
         LW,R10   R14               SAVE VP BEING RELEASED                      
         LW,R9    SDMMC,R6          R9=MAP POINTER                              
         DO       #SIGMA9M                                                      
         LH,R14   *R9,R7            R14= REAL PAGE#                             
         ELSE     #SIGMA9M                                                      
         LB,R14   *R9,R7            R14= REAL PAGE #                            
         FIN      #SIGMA9M                                                      
         LW,R4    R14               PUT IN INDEX REG                            
         MTB,0    IOLOCK,R4         TEST FOR IO LOCK                            
         BNEZ     MM0910            B IF LOCKED                                 
         EOR,R8   XSDRPP            RESET RPP                                   
         AND,R8   XSDAPRMK          RESET ACCESS CODES                          
         DISABLE                    DISABLE WHILE RELEASING REAL                
*                                       PAGE                                    
         STB,R8   *R5,R7            RESTORE  IN FLAG IMAGE                      
         LI,R5    SDRPCNT           OFFSET TO REAL PAGE COOUNT                  
         MTB,-1   *R6,R5            REDUCE COUNT                                
         BAL,R8   MMRSTM            RELEASE PAGE                                
*                                   RETURNS ENABLED                             
         LW,R9    R10               VPNL & VPNH  SAME                           
         LI,R0    3                 ACCESS PROT = NO ACCESS                     
         BAL,R8   MMSAC             SET ACCESS CODE                             
         BAL,R8   MMRDS             RELEASE SD                                  
         DO       #ROLL                                                         
         MTW,1    ROLL99            SET MEM EXEC RETRY                          
         BAL,R8   MMSTART           AND START IT                                
         FIN      #ROLL                                                         
         BAL,R8   LOADACI           LOAD THE ACI                                
MM0907   PULL     9,R4                                                          
         AI,R8    1                                                             
         B        OLAYEXIT          NORMAL EXIT                                 
MM0908   LI,R15   TYC98             PAGE ALLOC CONFLICT                         
MM0909   ENABLE                                                                 
         BAL,R8   MMRDS             RELEASE SD                                  
         B        MM0904            ERROR EXIT                                  
MM0910   LI,R15   TYC99             I/O IN PROGRESS                             
         B        MM0909                                                        
MM0911   LI,R15   TYC97             VIRTUAL PAGE # ERROR                        
         B        OLAYEXIT              ERROR EXIT                              
         TITLE    '** MMO3 - SET WRITE LOCKS **'                                
*                                                                               
*        MMSWLK   SET WRITE LOCKS                                               
*                                                                               
*                 AT ENTRY:                                                     
*                             R0 =LOCK CODE RIGHT JUSTIFIED                     
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                                                                               
*                 AT EXIT:    R0 =DESTROYED                                     
*                             RETURN TO LINK                                    
*                                                                               
*                                                                               
*                                                                               
MMSWLK   EQU      %                                                             
         PUSH     5,R1                                                          
         LI,R1    3                 MASK                                        
         LI,R2    0                 CLEAR                                       
         LI,R3    16                LOOP COUNT                                  
MM2801   SLS,R2   2                 FORM REGISTER FULL OF CODES                 
         STS,R0   R2                                                            
         BDR,R3   MM2801            LOOP                                        
         LW,R0    R2                R0 CONTAINS CODES                           
         LW,R2    R9                VPNL                                        
         LI,R3    0                 CLEAR                                       
         SCD,R2   -2                2 LOW ORDER BITS GIVE STARTING              
         SLS,R3   -30               FIELD WITHIN BYTE IN WLOCK                  
         LI,R4    4                                                             
         SW,R4    R3                                                            
         LW,R1    C0C0C0C0          MASK                                        
         LCW,R3   R3                RIGHT SHIFT                                 
         SCS,R1   0,R3              SHIFT TO STARTING POSITION                  
         SCS,R1   0,R3              ONCE MORE FOR TWO BITS                      
         LW,R3    R10               VPNH                                        
         SW,R3    R9                VPNH-VPNL                                   
         AI,R3    1                 SET LOOP COUNT                              
*                                   R0 HAS FULL SET OF CODES                    
*                                   R1 HAS MASK                                 
*                                   R2 HAS BYTE INDEX INTO WLOCK                
*                                   R3 HAS TOTAL LOOP COUNT                     
*                                   R4 HAS SUB LOOP COUNT                       
MM2802   LB,R5    WLOCK+1,R2        GET BYTE                                    
MM2803   STS,R0   R5                SET CODE                                    
         SCS,R1   -2                SHIFT MASK                                  
         BDR,R3   MM2805            B IF NOT DONE                               
         STB,R5   WLOCK+1,R2        STORE LAST CODES                            
         LD,R0    MM2801D                                                       
         MMC,0    1                 LOAD THE LOCKS                              
MM2804   PULL     5,R1              RESTORE                                     
         B        OLAYEXIT          RETURN                                      
MM2805   BDR,R4   MM2803            B FOR MORE IN THIS BYTE                     
         STB,R5   WLOCK+1,R2                                                    
         AI,R2    1                 MOVE TO NEXT BYTE                           
         LI,R4    4                 BACK FOR MORE                               
         B        MM2802                                                        
         BOUND    8                                                             
MM2801D  DATA     WLOCK+1                                                       
         GEN,8,7,6,11    16,0,0,0                                               
         TITLE    '** MMO3 - SUBR TO FREE PRIM PREF PAGES **'                   
*******************                                                             
*    MMTPRIM      *    SUBR TO FREE PREFERRED PAGES ACQUIRED BY                 
*******************        A PRIMARY TASK AT TERMINATION                        
*                                                                               
* ENTRY  R5       LMI OF PRIMARY TASK                                           
*        BAL,R8   MMTPRIM                                                       
* EXIT   +1                                                                     
* REGISTERS USED: R0,R14,R15                                                    
*          SAVED: R1-R13                                                        
* STACK WORDS:    8                                                             
* SUBROUTINES:    NONE                                                          
*                                                                               
MMTPRIM  PUSH     8,R1                                                          
         LB,R7    K:RMPT            R7=RMPT INDEX                               
         BEZ      MM5216                NONE, ERROR                             
MM5202   LW,R8    PPT,R7            R8=PPT ADDRESS                              
         LB,R0    R8                R0=PART TYPE                                
         CI,R0    PPTTYPE4              PREFERRED                               
         BNE      MM5214                NO, BYPASS IT                           
MM5204   LB,R4    *R8               R4=PAGES IN PREF PART                       
         LI,R2    PCTSP             R2=VPN OF FIRST PAGE                        
         LB,R2    *R8,R2                (ALSO RPN)                              
         LW,R14   Y8                R14,R15=ALLOC BIT                           
         LI,R15   0                                                             
         AI,R8    PCTALMP           R8=LOC OF ALLOC DOUBLEWORD                  
         LI,R6    PCTLOC-PCTALMP    R6=OFFSET FROM ALLOC TO LOC WORDS           
         OR,R5    XPCTPS            R5=LMID AND PRIM FLAG                       
         LI,R3    PCTEXU-PCTALMP    R3=OFFSET TO NOP OR AWM                     
MM5206   CW,R5    *R8,R6            PAGE ALLOCATED TO PRIM                      
         BNE      MM5212                NO, BYPASS                              
         LI,R1    MMIOWAIT/6            APPROX WAIT TIME IN LOOPS               
MM5208   DISABLE                                                                
         MTB,0    IOLOCK,R2             LOCKED?                                 
         BEZ      MM5210                NO, RELEASE IT                          
         ENABLE                                                                 
         BDR,R1   MM5208                WAIT                                    
         CRASH    'MMTPRIM ERROR'                                               
MM5210   STW,R0   *R8,R6                ZERO LOC WORD                           
         LD,R0    *R8                   ZERO ALLOC BIT                          
         EOR,R0   R14                                                           
         EOR,R1   R15                                                           
         STD,R0   *R8                                                           
         LI,R0    1                 INCR FREE PAGE COUNT IF                     
         EXU      *R8,R3                IN STM MODE                             
         ENABLE                                                                 
MM5212   AI,R2    1                 ADVANCE TO NEXT PAGE                        
         AI,R6    1                                                             
         SLD,R14  -1                                                            
         BDR,R4   MM5206                                                        
MM5214   BDR,R7   MM5202                                                        
MM5216   PULL     8,R1                                                          
         B        OLAYEXIT          EXIT                                        
OLAYEXIT EQU      %                                                             
MMO3EXIT B        *R8               COMMON EXIT                                 
         OLAYEND                                                                
        FIN      #MAP                                                           
         END                                                                    
