         PCC      0                                                             
         SYSTEM   SIG9P                                                         
         SYSTEM   OPTIONS                                                       
         SPACE    2                                                             
*                                                                               
*                                                                               
*                                                                               
         DEF      MMO1                                                          
         DEF      MMCALX                                                        
         DEF      MMO1EXIT                                                      
         DEF      MMSAC,MMGP,MMFOV,MMACT,MMVVPN,MMSTART                         
         DEF      MMSEGCK,MMSDS,MMRDS,MMSETVPN,MMCAL                            
OLAYFLAG EQU      'MMO1'                                                        
         PSYS     0                                                             
         SYSTEM   CPRMON                                                        
MMO1     RES      0                                                             
         TITLE    '** MMO1 - SET ACCESS CODES **'                               
*                                                                               
*        MMSAC    SET ACCESS CODES                                              
*                                                                               
*                 AT ENTRY:   R0 =ACCESS CODE RIGHT JUSTIFIED                   
*                             R6 =SD ADDRESS                                    
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                 AT EXIT:    R0 =DESTROYED                                     
*                             RETURN IS TO LINK                                 
*                                                                               
MMSAC    EQU      %                                                             
         PUSH     8,R1                                                          
         LI,R1    3                 MASK                                        
         LI,R2    0                 CLEAR                                       
         LI,R3    16                LOOP COUNT                                  
MM1101   SLS,R2   2                 MOVE TO NEXT TWO BIT POSITION               
         STS,R0   R2                SET CODE                                    
         BDR,R3   MM1101            LOOP                                        
         LW,R0    R2                R0 CONTAINS CODES                           
         LW,R1    SDMMCCS,R6        GET CONTROL START                           
         AND,R1   M17               MASK                                        
         SLS,R1   -9                JUSTIFY                                     
         LW,R2    R9                VPNL                                        
         SW,R2    R1                START INDEX (# OF 2 BIT FIELDS)             
         LB,R3    *R6               GET ACCESS PROTECTION OFFSET                
         AND,R3   XSDAPM            MASK                                        
         AW,R2    R3                ADD OFF-SET                                 
         LI,R3    0                 CLEAR                                       
         SCD,R2   -2                FORM BYTE INDEX IN R2                       
         SLS,R3   -30               R3 HAS FIRST SUB LOOP COUNT                 
         LW,R4    R10               VPNH                                        
         SW,R4    R9                VPNH-VPNL                                   
         AI,R4    1                 SET LOOP COUNT                              
         LW,R1    C0C0C0C0          MASK CONSTANT                               
         LCW,R3   R3                MAKE IT NEGATIVE FOR SHIFT                  
         SCS,R1   0,R3                                                          
         SCS,R1   0,R3              JUSTIFY  MASK (2BIT FIELDS)                 
         AI,R3    4                 GIVES NUMBER OF 2 BIT CODES IN FIRS         
         LW,R8    SDMMCCS,R6        COMPUTE FIRST FLAG BYTE                     
         AND,R8   M17                   AS VNPL-V START PAGE                    
         SLS,R8   -9                                                            
         SW,R8    R9                    R8=NEG OFFSET TO FIRST FLAG             
         LI,R7    SDACICNT              GET LENGTH OF ACI                       
         LB,R7    *R6,R7                IN WORDS                                
         AI,R7    SDACCIMG              PLUS LOC OF ACI                         
         AW,R7    R6                    PLUS SD LOC                             
         SLS,R7   2                     CONVERT TO BA                           
         SW,R7    R8                    OFFSET TO FIRST BYTE                    
*                                   R0 HAS ACCESS CODES                         
*                                   R1 HAS MASK                                 
*                                   R2 HAS STARTING BYTE INDEX                  
*                                   R3 HAS SUB LOOP COUNT                       
*                                   R4 HAS LOOP COUNT                           
         LI,R5    SDACCIMG          ACCESS IMAGE OFFSET                         
         AW,R5    R6                R5 HAS ADDRESS OF ACCESS IMAGE              
*                                   R7 HAS BA OF FLAG LOC IN SD                 
MM1102   LB,R6    *R5,R2            GET BYTE OF ACCESS IMAGE                    
MM1103   LB,R8    0,R7              IS REAL PAGE PRESENT                        
         CI,R8    SDRPP                                                         
         BANZ     MM1103B               YES, SET PER INPUT CODES                
         STS,R1   R6                    NO, SET TO NO ACCESS                    
         B        MM1103C                                                       
MM1103B  STS,R0   R6                SET CODE                                    
MM1103C  AI,R7    1                                                             
         SCS,R1   -2                    SHIFT MASK                              
         BDR,R4   MM1104            B IF NOT DONE                               
         STB,R6   *R5,R2            SET LAST BYTE                               
         PULL     8,R1              RESTORE                                     
         B        OLAYEXIT          RETURN                                      
MM1104   BDR,R3   MM1103            B FOR MORE IN THIS BYTE                     
         STB,R6   *R5,R2            SET CODES                                   
         AI,R2    1                 MOVE TO NEXT BYTE                           
         LI,R3    4                 SET NEXT SUB LOOP COUNT                     
         B        MM1102                                                        
*                                                                               
         TITLE    '** MMO1 - GET PAGES **'                                      
*                                                                               
*        MMGP     GET PAGES                                                     
*                                                                               
*                 AT ENTRY:                                                     
*                             R6 =SD ADDRESS                                    
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                 AT EXIT:                                                      
*                             R0 =DESTROYED                                     
*                             R14=DESTROYED                                     
*                             R15=ERROR CODE  (98)                              
*                             RETURN IS TO LINK+1 IF NO ERRORS                  
*                             RETURN IS TO LINK   IF ERROR                      
*                                                                               
*                 USES:       MMVVPN,MMGPPS,MMROLL,MMSAC,MMSRPP                 
*                                                                               
MMGP     PUSH     8,R1              SAVE REGS                                   
         BAL,R8   MMVVPN            CHECK VPN LIMITS                            
         B        MM1309            BAD VPN                                     
         LW,R14   SDMMCCS,R6        R14=VPN OF ZEROTH PAGE                      
         AND,R14  M17               MASK                                        
         SLS,R14  -9                RIGHT JUSTIFY                               
         LW,R5    R10               VPNH                                        
         SW,R5    R14               R5=RPN OF VPNH                              
         LW,R7    R9                VPNL                                        
         SW,R7    R14               R7=RPN OF VPNL                              
         LI,R4    SDACICNT          OFFSET TO ACI COUNT                         
         LB,R4    *R6,R4            GET NUM OF ACI WORDS                        
         AI,R4    SDACCIMG          OFFSET TO ACCESS IMAGE                      
         AW,R4    R6                R4=ADDRESS OF FLAG BYTES                    
         LI,R3    SDFLAGS           R3=OFFSET TO SDFLAGS                        
         LH,R0    *R6,R3            GET FLAGS                                   
         CI,R0    SDRAC             IS IT A RAC SEGMENT                         
         BANZ     MM1307            B IF RAC SEGMENT                            
         LW,R15   R0                R0=SEG FLAGS                                
         AND,R15  XSDSTATE          R15=SEG STATE                               
         LI,R3    0                 R3=PAGES REQUIRED                           
MM1301   LB,R8    *R4,R7            GET FLAG BYTE                               
         DO       #ROLL                                                         
         CI,R15   SDSTATE6          BEING ROLLED IN                             
         BNE      MM1301A               NO                                      
         CI,R8    SDROL                 PAGE ROLLED OUT                         
         BAZ      MM1302A               NO                                      
         B        MM1302                                                        
         FIN      #ROLL                                                         
MM1301A  CI,R8    SDRPP             CHECK RPP                                   
         BAZ      MM1302                                                        
         LI,R15   TYC98                                                         
         B        MM1309                                                        
MM1302   AI,R3    1                 INCREMENT PAGES NEEDED                      
MM1302A  AI,R7    1                 MOVE TO NEXT PAGE                           
         CW,R7    R5                DONE ?                                      
         BLE      MM1301            B IF NO                                     
         LW,R7    R9                R7=RPN OF VNPL AGAIN                        
         SW,R7    R14                                                           
         DO       #ROLL                                                         
         LW,R2    LMIRECB+MMLMID    ARE MEM REQUESTS QUEUED                     
         BEZ      MM1302B               NO                                      
         LW,R0    ECBPC,R2              COMPARE CALLERS PRIORITY                
         LW,R1    XECBPR                WITH FIRST QUEUED MEM                   
         LB,R2    TCBPOINT              REQUEST (ECB)                           
         CS,R0    STIPRIO,R2                                                    
         BG       MM1306                ECB PRIO >, QUEUE REQ                   
         BL       MM1302B               ECB PRIO <, CONTINUE                    
         CI,R15   SDSTATE6              ECB PRIO =, CONTINUE                    
         BNE      MM1306                IF MMEXEC, QUEUE IF NOT                 
MM1302B  CW,R3    MMTPAGES          ADEQUATE PAGE SUPPLY                        
         BG       MM1306                NO, QUEUE REQUEST                       
         FIN      #ROLL                                                         
         LW,R2    SDMMC,R6          R2=MAP IMAGE ADDRESS                        
         LI,R1    SDRPCNT           R1=LOC OF REAL PAGE COUNT                   
MM1303   LB,R0    *R4,R7            GET FLAG BYTE                               
         DO       #ROLL                                                         
         CI,R15   SDSTATE6          BEING ROLLED IN                             
         BNE      MM1303A               NO, GET ALL PGS NOT RPP                 
         CI,R0    SDROL                 PAGE ROLLED OUT                         
         BAZ      MM1304                NO, SKIP PAGE                           
         FIN      #ROLL                                                         
MM1303A  CI,R0    SDRPP             CHECK RPP                                   
         BANZ     MM1304            B IF RPP IS SET                             
         BAL,R8   MMGSTM            GET A REAL PAGE                             
         B        MM1306                PAGE NOT AVAIL                          
         DO       #SIGMA9M                                                      
         STH,R14  *R2,R7            SET REAL ADDRESS                            
         ELSE     #SIGMA9M                                                      
         STB,R14  *R2,R7            SET REAL ADDRESS                            
         FIN      #SIGMA9M                                                      
         MTB,1    *R6,R1            ADD ONE TO REAL PAGE COUNT                  
         LB,R0    *R4,R7            SET  RPP                                    
         OR,R0    XSDRPP                                                        
         STB,R0   *R4,R7                                                        
         ENABLE                                                                 
         AI,R3    -1                DECREMENT # OF PAGES NEEDED                 
MM1304   AI,R7    1                 MOVE TO NEXT PAGE                           
         CW,R7    R5                DONE ?                                      
         BLE      MM1303            B IF NO                                     
         DO       #ROLL                                                         
         CI,R15   SDSTATE6          DO NOT ALTER ACCESS CODES                   
         BE       MM1305A               OF SEGS BEING ROLLEDIN                  
         FIN      #ROLL                                                         
MM1305   LI,R1    SDFLAGS                                                       
         LH,R0    *R6,R1            REFETCH FLAGS                               
         AND,R0   XSDAPC            GET ACCESS CODES                            
         SLS,R0   -SDAPCS           RIGHT JUSTIFY                               
         BAL,R8   MMSAC             SET ACCESS CODES                            
MM1305A  PULL     8,R1                                                          
         AI,R8    1                 NORMAL EXIT                                 
         B        OLAYEXIT          RETURN                                      
*                                                                               
         DO       #ROLL                                                         
MM1306   CI,R15   SDSTATE6          BEING ROLLED IN                             
         BE       MM1308                YES, EXIT TYC=A4                        
         BAL,R8   MMROLL            REQUEST MEM FROM MEM EXEC                   
         B        MM1309                ERROR EXIT                              
         B        MM1302B           GO BACK WHEN ROLL-OUT IS SATISFIED          
MM1308   LI,R15   TYCA4             ERROR CODE-INADEQUATE PGS                   
         LI,R1    SDNPCNT               SET # OF PAGES NEEDED                   
         STB,R3   *R6,R1                                                        
         B        MM1309                GO TO ERROR RETURN                      
         ELSE                                                                   
MM1306   LI,R15   TYCA4             SET TYC=NO REAL PAGES                       
         B        MM1309                ERROR EXIT                              
         FIN      #ROLL                                                         
*                                                                               
MM1307   BAL,R8   MMGPPS            GET PREFERRED PAGES                         
         B        MM1309                                                        
         B        MM1305                                                        
*                                                                               
MM1309   PULL     8,R1                                                          
         B        OLAYEXIT          ERROR RETURN                                
*                                                                               
         TITLE    '** MMO1 - FIND OVLOAD TABLE ENTRY **'                        
*                                                                               
*        MMFOV    FIND OVLOAD TABLE ENTRY FOR A SEGMENT NUMBER                  
*                                                                               
*                 AT ENTRY:   R8 =LINK                                          
*                             R11=SEGMENT NUMBER (RT.JUSTIFIED)                 
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R15=ERROR CODE  X'96' IF ERROR                    
*                             R14=ADDRESS OF ENTRY IF NO ERROR                  
*                             RETURNS TO LINK IF ERROR                          
*                             RETURNS TO LINK+1 IF NO ERROR                     
MMFOV    CI,R11   0                 IF SEG NUMBER IS ZERO                       
         BE       MM1503                ERROR EXIT                              
         PUSH     R5                SAVE WORKING REGS                           
         LI,R5    PCBOVLD           OFFSET TO  OVLOAD ADDRESS                   
         LW,R5    *PCBPOINT,R5      GET ADDRESS OF OVLOAD TABLE                 
         LW,R0    OVNSEG,R5         GET NUMBER OF SEGMENTS                      
         AI,R5    OVFENT            ADD OFFSET TO FIRST ENTRY                   
         SLS,R5   1                 MAKE HALFWORD ADDRESS                       
         AI,R5    OVSEG             OFFSET TO SEG NUM                           
MM1501   LH,R14   0,R5              ISOLATE SEG NUM IN OVLOAD                   
         AND,R14  M16                   AND COMPARE TO SEG NUM                  
         CW,R11   R14                   IN R11                                  
         BE       MM1504            B IF YES                                    
         AI,R5    OVNXSEG           OFFSET TO NEXT SEGMENT NUMBER               
         BDR,R0   MM1501            B FOR NEXT SEG                              
MM1502   PULL     R5                                                            
MM1503   LI,R15   TYC96             ERROR CODE                                  
         B        OLAYEXIT          EXIT                                        
MM1504   AI,R5    -OVSEG            SUBTRACT OUT  OFFSET                        
         SLS,R5   -1                MAKE WORD ADDRESS                           
         LW,R14   R5                ADDRESS OF OVLOAD ENTRY                     
         PULL     R5                                                            
         AI,R8    1                 NORMAL EXIT                                 
         B        OLAYEXIT          EXIT                                        
         TITLE    '** MMO1 - ACTIVATE A SIGMENT **'                             
*                                                                               
*        MMACT    ACTIVATE A SEGMENT                                            
*                                                                               
*                 AT ENTRY:   R2 =CAL ADDRESS                                   
*                             R3 =ADDRESS OF FPT                                
*                             R8 =LINK                                          
*                             R11=SEGMENT NUMBER                                
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R1 =DESTROYED                                     
*                             R2 =DESTROYED                                     
*                             R3 =ADDRESS OF FPT                                
*                             R5 =DESTROYED                                     
*                             R6 =SD ADDRESS                                    
*                             R7 =DESTROYED                                     
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNH                                          
*                             R11=SEGMENT NUMBER                                
*                             R12=AST ADDRESS                                   
*                             R14=DESTROYED                                     
*                             R15=TYC                                           
*                                                                               
MMACT    BIFPRIM  MM1801A           NO PRIMARYS                                 
         PUSH     R8                SAVE LINK                                   
         BAL,R8   MMSEGCK           SET R6=SD,R12=AST AS F(SEG #)               
         B        MM1801            ERROR                                       
         B        MM1802            INACTIVE TO THIS TASK                       
         LI,R15   TYCA0             ACTIVE TO THIS TASK                         
MM1801   PULL     R8                                                            
         B        OLAYEXIT          ERROR EXIT                                  
MM1801A  LI,R15   TYC6A             INVALID CAL FOR CALLER                      
         B        OLAYEXIT          ERROR EXIT                                  
MM1801B  BAL,R8   MMRDS             RELEASE EXCL USE OF SD                      
         B        MM1801            ERROR EXIT                                  
*                                                                               
MM1802   LW,R9    SDMMCCS,R6        GET START PAGE                              
         SLS,R9   -9                RIGHT JUSTIFY                               
         AND,R9   M8                MASK , YEILDS VPNL                          
         LI,R5    SDVPCNT           VIRTUAL PAGE COUNT                          
         LB,R10   *R6,R5            GET VIRTUAL PAGE COUNT                      
         AI,R10   -1                ADJUST COUNT                                
         AW,R10   R9                YEILDS VPNH                                 
         BAL,R8   MMSDS             ACQUIRE EXCL USE OF SD                      
MM1802A  LI,R1    SDFLAGS                                                       
         LH,R1    *R6,R1            GET SEGMENT FLAGS                           
         AND,R1   XSDSTATE          MASK                                        
         SLS,R1   -SDSTSHF          JUSTIFY                                     
         EXU      MM1803,R1         B TO ROUTINE  BASED ON  SEG STATE           
MM1803   B        MM1804            000 BEING INITIATED                         
         B        MM1808            001 ERASED                                  
         B        MM1809            010 INACTIVE                                
         B        MM1809            011 ACTIVE                                  
         B        MM1815            100 BEING ROLLED OUT                        
         B        MM1814            101 ROLLED OUT                              
         B        MM1815            110 BEING ROLLED IN                         
         B        MM1815            111 BEING LOADED                            
*                                                                               
MM1804   BAL,R8   MMGP              GET PAGES                                   
         B        MM1801B           ERROR EXIT                                  
         B        MM1809            B TO SET UP AST ENTRY                       
*                                   **** GOOD EXITS ****                        
MM1805   BAL,R8   MMRDS             RLEASE EXCL USE OF SD                       
         BAL,R8   LOADMAP           LOAD THE MAP                                
MM1806   LI,R15   TYCNORM           NORMAL COMPLETION                           
MM1807   PULL     R8                NORMAL EXIT                                 
         AI,R8    1                 NORMAL RETURN                               
         B        OLAYEXIT          EXIT                                        
*                                                                               
MM1808   BAL,R8   MMFOV             FIND OVLOAD TABLE ENTRY                     
         B        MM1801B           ERROR, NO ENTRY                             
         LW,R5    R14               SAVE OVLOAD TABLE ADDR                      
         BAL,R8   MMGP              GET PAGES                                   
         B        MM1801B           ERROR                                       
         LW,R14   R5                RESTORE OVLOAD TABLE ADDR                   
         LI,R5    OVLMBL            OFFSET TO LOAD MODULE BYTE LENGTH           
         LW,R0    *R14,R5           GET BYTE LENGTH                             
         AND,R0   M24               MASK                                        
         BNEZ     MM1810            BIF SEGMENT NOT EMPTY                       
MM1809   LI,R14   0                 SET OV=0, SEG LOAD NOT REQD                 
MM1810   DISABLE                    **** UPDATE AST,SD ****                     
         CW,R6    XASTFA            IS THE FIRST ACT BIT ON                     
         BANZ     MM1810A           B IF YES                                    
         OR,R6    XASTFA            SET THE FIRST ACT BIT                       
         LI,R5    SDTERASE          OFFSET TO TASKS ERASED COUNT                
         MTB,1    *R6,R5            INCREMENT TASKS ERASED                      
MM1810A  OR,R6    XASTACT           ACTIVE BIT ON                               
         DO1      #ROLL                                                         
         AND,R6   XASTNRD           REMOVE ROLLED INDICATOR                     
         STW,R6   *R12              STORE INTO AST                              
         LI,R5    SDTACT            OFFSET TO TASKS ACTIVE COUNT                
         MTB,1    *R6,R5            ADD ONE  TO TASKS ACTIVE                    
         LI,R1    SDFLAGS                                                       
         LH,R0    *R6,R1            GET SEGMENT  FLAGS                          
         AND,R0   XSDSTMSK          MASK                                        
         AI,R0    SDSTATE3          ACTIVE STATE                                
         STH,R0   *R6,R1            STORE BACK INTO SD                          
         ENABLE                                                                 
         CI,R14   0                 SEGMENT LOAD NEEDED                         
         BE       MM1805            NO, EXIT                                    
*                                   **** LOAD SEGMENT FROM                      
         BAL,R8   LOADMAP           LOAD MODULE FILE                            
         STW,R11  R13               SEGMENT NUMBER                              
         LI,R14   X'0140'           SEGLOAD FPT CODE (X'01') PLUS               
*                                   P2 BIT SET (ERROR ADDRESS)                  
         LW,R1    R10               SAVE R10 IN CASE OF ERROR                   
         STH,R14  R13               PLACE IN SEGLOAD FPT                        
         LI,R14   MM1813            ERROR ADDRESS                               
         CAL1,8   13                CALL SEGLOAD TO BRING IN SEGMENT            
         BAL,R8   MMRDS             RELEASE SD                                  
         B        MM1806            EXIT                                        
*                                                                               
MM1813   BAL,R8   MMRDS             RELEASE SEGMENT SO                          
         BAL,R8   MMERASE           ERASE CAN GET IT                            
         NOP                        IGNORE ERROR EXIT                           
         LI,R15   TYCA1             SET UNABLE TO LOAD TYC                      
         B        MM1801            ERROR EXIT                                  
*                                                                               
         DO       #ROLL                                                         
MM1814   EQU      %                                                             
         PUSH     R6                SAVE EXISTING SEG FLAGS                     
         BAL,R8   MMRISEG           ROLL IN THE SEGMENT                         
         B        MM1814A           ERROR                                       
         PULL     R8                GET AST FLAGS BEFOR ROLLIN                  
         CW,R8    XASTFA            NEW TASK OR OLD TASK                        
         BANZ     MM1805            SKIP SDTERASE LOGIC IF OLD TASK             
         LI,R1    SDTERASE                                                      
         MTB,1    *R6,R1            UP HIS ERASE COUNT                          
         B        MM1805                                                        
MM1814A  EQU      %                                                             
         PULL     R8                BALANCE STACK                               
         B        MM1801B           ERROR EXIT                                  
         ELSE                                                                   
MM1814   EQU      %                                                             
         FIN      #ROLL                                                         
MM1815   CRASH    'MM18-INVALID SEG STATE'                                      
         TITLE    '** MMO1 - VERIFY VIRTUAL PAGE NUMBER **'                     
*                                                                               
*        MMVVPN   VERIFY  VIRTUAL PAGE NUMBER                                   
*                                                                               
*                 AT ENTRY:   R6 =SD ADDRESS                                    
*                             R8 =LINK                                          
*                             R9 =VPNL                                          
*                             R10=VPNL                                          
*                 AT EXIT:    R0 =DESTROYED                                     
*                             R15=ERROR CODE X'97' IF ERROR                     
*                                                                               
*                             RETURNS TO LINK+1 IF NO ERROR                     
*                             RETURNS TO LINK  IF ERROR                         
MMVVPN   PUSH     R1                SAVE WORK REG                               
         LW,R0    SDMMCCS,R6        GET STARTING VIRTUAL PAGE                   
         AND,R0   M17                                                           
         SLS,R0   -9                RIGHT JUSTIFY                               
         AI,R8    1                 PREPARE FOR NORMAL EXIT                     
         CW,R9    R0                CHECK VPNL                                  
         BL       MM2401            B IF LESS THAN START ADDRESS                
         LI,R1    SDVPCNT           VIRTUAL PAGE COUNT                          
         LB,R1    *R6,R1            GET PAGE COUNT                              
         AW,R0    R1                VIRTUAL PAGE  UPPER BOUND                   
         CW,R10   R0                CHECK VPNH                                  
         BGE      MM2401            B IF GREATER THAN UPPER LIMIT               
         CW,R10   R9                                                            
         BGE      MM2402            B IF OK                                     
MM2401   LI,R15   TYC97                                                         
         AI,R8    -1                ERROR EXIT                                  
MM2402   PULL     R1                                                            
         B        OLAYEXIT          RETURN                                      
         TITLE    '** MMO1 - SUBROUTINE TO START MMEXEC **'                     
*******************                                                             
*    MMSTART      *    SUBR TO ADJUST MMEXEC PRIORITY AND START                 
*******************      START IT                                               
*                                                                               
* ENTRY  BAL,R8   MMSTART                                                       
* EXIT   +1       MMEXEC STARTED                                                
*                                                                               
* REGISTERS USED: R0                                                            
*          SAVED: R1-R15                                                        
* STACK WORDS:    7                                                             
* SUBROUTINES:    TMDQ,TMTRIG                                                   
*                                                                               
MMSTART  PUSH     7,R4              SAVE REGISTERS                              
         DISABLE                                                                
         LW,R7    LMIRECB+MMLMID        START MMEXEC IF ECBS                    
         BEZ      MMSTRT3               ARE QUEUED                              
         LI,R4    MMTID                 R4=MEM EXEC TASK ID                     
         LI,R9    STISTRT               SET START BIT                           
         STS,R9   STIPRIO,R4                                                    
         LW,R6    ECBPC,R7                                                      
         LW,R7    XSTIPR                                                        
         CS,R6    STIPRIO,R4            IS MEMEXEC AT RIGHT PRIO                
         BE       MMSTRT2               NO CHANGE                               
         STS,R6   STIPRIO,R4                                                    
         XPSD,0   TMDQ                                                          
MMSTRT2  ENABLE                                                                 
         BAL,R8   TMTPRIO               TRIGGER THE LEVEL                       
MMSTRT3  ENABLE                                                                 
         PULL     7,R4                                                          
         B        OLAYEXIT                                                      
         TITLE    '** MMO1 - SEGMENT CHECK **'                                  
*                                                                               
*        MMSEGCK  VERIFY SEGMENT NUMBER                                         
*                                                                               
*                 AT ENTRY:   R8 =LINK                                          
*                             R11=SEGMENT NUMBER (RT.JUSTIFIED)                 
*                 AT EXIT:    R6 =SEGMENT DESCRIPTOR ADDRESS                    
*                             R12=AST ADDRESS                                   
*                             R15=ERROR CODE X'96'IF ERROR                      
*                             RETURN IS TO:                                     
*                                            LINK IF ERROR                      
*                                            LINK+1 IF SEGMENT INACTIVE         
*                                            LINK+2 IF SEGMENT ACTIVE           
MMSEGCK  LI,R15   TYC96             ERROR CODE                                  
         CI,R11   0                 IS SEG NUM ZERO                             
         BE       MM3001            B IF YES                                    
         CI,R11   32768             IS IT SPECIAL SYSTEM SEG                    
         BL       MM3002            B IF NO                                     
MM3001   BIFUSER  OLAYEXIT          ERROR IF NOT SYSTEM TASK                    
MM3002   PUSH     2,R7              SAVE RETURN                                 
         LI,R7    STCBAST                                                       
         LW,R12   *TCBPOINT,R7      R12= AST POINTER                            
         BEZ      MM3007                                                        
MM3003   LW,R6    *R12              R6= AST ENTRY                               
         BLEZ     MM3004            B IF NO SEG DESCRIPTOR                      
         LW,R7    SDSEGWD,R6        GET SEG NUMBER                              
         AND,R7   M16               MASK                                        
         CW,R7    R11               THIS SD ?                                   
         BE       MM3005            B IF YES                                    
MM3004   AI,R12   1                 DO NEXT AST                                 
         MTB,-1   R12                                                           
         BNEZ     MM3003                                                        
         B        MM3007            ERROR, NOT FOUND                            
MM3005   PULL     2,R7                                                          
         LI,R15   0                 NO ERROR                                    
         CW,R6    XASTACT           IS IT ACTIVE TO THIS TASK                   
         BAZ      MM3006            B IF INACTIVE                               
         AI,R8    1                 ACTIVE EXIT                                 
MM3006   AI,R8    1                 INACTIVE EXIT                               
         B        OLAYEXIT          EXIT                                        
MM3007   PULL     2,R7                                                          
         B        OLAYEXIT          ERROR NO SD                                 
         TITLE    '** MMO1 - SET DISPATCHER SKIP FLAG **'                       
*                                                                               
*        MMSDS    SET DISPATCHER SKIP FLAG                                      
*                                                                               
*                 AT ENTRY:   R6 =SD ADDRESS                                    
*                             R8 =LINK                                          
*                             R12=AST ADDRESS                                   
*                 AT EXIT:    R0 =DESTROYED                                     
*                             RETURNS TO LINK                                   
MMSDS    PUSH     3,R7              SAVE WORKING REGS                           
         LW,R6    *R12              REFRESH AST ENTRY                           
MM3103   DISABLE                                                                
         LW,R7    0,R6              GET  DISPATCHER FLAGS                       
         CW,R7    XSDDS             CHECK DISPATCHER SKIP FLAG                  
         BAZ      MM3105            B  IF DS OFF                                
         CW,R6    XASTDS            DS ALREADY SET FR THIS TSK                  
         BANZ     MM3106            ASSUME IN TERMINATION                       
         CW,R6    XASTACT           IS SEGMENT ACTIVE TO THIS TASK              
         BAZ      MM3104            B IF NO                                     
         CRASH    'MM31-ERROR'                                                  
MM3104   ENABLE                     WAIT FOR 'DS' TO BE RESET                   
         OR,R6    XASTACT           MAKE AST ENTRY ACTIVE                       
         STW,R6   *R12              RESTORE                                     
         LI,R7    0                                                             
         STW,R7   TDLAST            RESET LAST DISPATCHED TASK ID               
         BAL,R8   TMRDLTRG          WAIT FOR 'DS' DO BE REMOVED                 
         EOR,R6   XASTACT           SET ACTIVE BIT OFF                          
         STW,R6   *R12              RESTORE AST ENTRY                           
         B        MM3103            TRY AGAIN                                   
*                                                                               
MM3105   OR,R7    XSDDS             SET DISPATCHER SKIP FLAG                    
         STW,R7   0,R6              RESTORE IN SD                               
         OR,R6    XASTDS            SET   DS IN AST                             
         STW,R6   *R12              *R12=AST   ADDRESS                          
MM3106   LB,R7    TCBPOINT          R7=TASK ID                                  
         LI,R9    STIDSO            SET DISP SKIP OVERRID                       
         CI,R7    MMTID             IS THIS MMEXEC                              
         BE       %+3               YES, B TO SET, NOT INCREMENT DSO            
         AWM,R9   STIPRIO,R7        NO, INCREMENT DSO                           
         B        %+2                                                           
         STS,R9   STIPRIO,R7                                                    
         ENABLE                                                                 
         PULL     3,R7                                                          
         B        OLAYEXIT          EXIT                                        
         TITLE    '** MMO1 - RESET DISPATCHER SKIP FLAG **'                     
*                                                                               
*        MMRDS    RESET DISPATCHER SKIP FLAG                                    
*                                                                               
*                 AT ENTRY:    R6 =SD ADDRESS (INCL AST FLAGS)                  
*                              R12=AST ADDRESS                                  
*                                                                               
MMRDS    PUSH     3,R7              SAVE WORKING REGISTERS                      
         LW,R6    *R12              REFRESH AST ENTRY                           
         CW,R6    XASTDS            DS SET AT ENTRY                             
         BANZ     MM3602                NO, ERROR                               
         CRASH    'MM36-ERROR'                                                  
MM3602   DISABLE                                                                
         LW,R8    0,R6              RESET DS IN SD                              
         AND,R8   XSDNDS                                                        
         STW,R8   0,R6                                                          
         AND,R6   XASTNDS           RESET DS IN AST                             
         STW,R6   *R12                                                          
         LB,R7    TCBPOINT                                                      
         LW,R0    STIPRIO,R7        RESET DSO                                   
         CI,R7    MMTID             IS THIS MMEXEC                              
         BE       %+3               YES, BRANCH TO RESET DSO                    
         AI,R0    -STIDSO           NO, DECREMENT DSO                           
         B        %+2                                                           
         AND,R0   XSTINDSO                                                      
         STW,R0   STIPRIO,R7                                                    
         ENABLE                                                                 
MM3605   PULL     3,R7              RESTORE REGISTERS                           
         B        OLAYEXIT                                                      
         TITLE    '** MMO1 - SUBROUTINE TO SET SEG VPN ARGUMENTS **'            
*******************                                                             
*    MMSETVPN     *    SUBR TO SET VNPL,VNPH ARGUMENTS FOR MM                   
*******************                                                             
*                                                                               
* ENTRY  R6       SD ADDRESS                                                    
*        BAL,R8   MMSETVPN                                                      
* EXIT   +1       R9-R10=VNPL,VNPH                                              
*                                                                               
* REGISTERS USED: R1,R9,R10                                                     
*          SAVED: R0,R2-R8,R11-R15                                              
* STACK WORDS:    0                                                             
* SUBROUTINES:    NONE                                                          
*                                                                               
MMSETVPN LW,R9    SDMMCCS,R6                                                    
         SLS,R9   -9                                                            
         AND,R9   M8                                                            
         LI,R1    SDVPCNT                                                       
         LB,R10   *R6,R1                                                        
         AI,R10   -1                                                            
         AW,R10   R9                                                            
         B        OLAYEXIT                                                      
         TITLE    '** MMO1 - MEMORY MANAGEMENT CAL PRE-PROCESSOR **'            
MMCAL    EQU      %                                                             
         LW,R11   0,R3              GET SEGMENT NUMBER                          
         AND,R11  M16               MASK                                        
         LD,R5    STIRTSB,R4        GET STACK POSITION AFTER PUSH               
         LW,R2    -4,R5             POINT TO CAL ADDRESS                        
         AI,R1    -X'52'            ACTIVATE FPT CODE                           
         BGEZ     MMCAL02           B IF NOT LESS THAN X'52'                    
MMCAL01  CRASH    'MMCAL- BAD FPT CODE'                                         
MMCAL02  CI,R1    6                 UPPER LIMIT                                 
         BG       MMCAL01           BAD FPT CODE                                
         BAL,R8   MMCALTAB,R1       JUMP TO APPROPRIATE ROUTINE                 
MMCAL03  NOP                        ERROR EXIT                                  
MMCAL04  BAL,R8   TMSETERR                                                      
         BAL,R8   TMTYC15S          DO ERROR AND STATUS POSTING                 
MMCALX   B        CALSTDX           RETURN                                      
MMCAL05  LI,R15   TYC97             VPNL,VPNH ERROR                             
         PULL     R8                RESTORE STACK                               
         B        MMCAL04               EXIT                                    
MMCALTAB BAL,0    MMACT             ACTIVATE                                    
         BAL,0    MMDEACT           DEACTIVATE                                  
         BAL,0    MMERASE           ERASE                                       
         BAL,0    MMLOCK            LOCK                                        
         BAL,0    MMUNLOCK          UNLOCK                                      
         B        MMCALP            GET PAGE                                    
         B        MMCALP            REL PAGE                                    
MMCALP   EQU      %                                                             
         PUSH     R8                                                            
         LI,R15   6                 GET VPNL                                    
         BAL,R5   GETFPTN                                                       
         B        MMCAL05           PARAMETER NOT PRESENT                       
         STW,R15  R9                                                            
         LI,R15   7                 GET VPNH                                    
         BAL,R5   GETFPTN                                                       
         B        MMCAL05           PARAMETER NOT PRESENT                       
         STW,R15  R10                                                           
         AND,R1   M1                SAVE LOW ORDER BIT                          
*                                   1 IF GETPAGE , 0 IF REL PAGE                
         BAL,R8   MMCPTAB,R1        GO TO APPROPRIATE ROUTINE                   
MMCALP00 B        MMCALP01          ERROR                                       
         LI,R15   6                 GET VPNL ADDRESS                            
         BAL,R5   GETFPTN                                                       
         B        %+2               SHOULD NOT HAPPEN                           
         STW,R9   *R14              UPDATE VPNL                                 
         LI,R15   7                 GET VPNH ADDRESS                            
         BAL,R5   GETFPTN                                                       
         B        %+2               SHOULD NOT HAPPEN                           
         STW,R10  *R14              UPDATE VPNH                                 
         LI,R15   TYCNORM               SET TYC TO NORMAL                       
MMCALP01 PULL     R8                                                            
         B        *R8               RETURN                                      
MMCPTAB  BAL,0    MMRELP            GET PAGE                                    
         BAL,0    MMGETP            RELEASE PAGE                                
OLAYEXIT EQU      %                 OVERLAY EXIT                                
MMO1EXIT B        *R8                                                           
         OLAYEND                                                                
         END                                                                    
