         PCC      0
SMON:    EQU      %
BITS     SET      1
MPBITS   SET      1
UFLAGS   SET      1
         TITLE    ' S L A V E   C P U   M O N I T O R'
         SYSTEM   UTS
*P*
*P*
*M*      SMON - SLAVE CPU CONTROL PROGRAM
*P*
*P*      THIS MODULE CONTAINS ALL OF THE CODE EXECUTED
*P*      BY SLAVE PROCESSORS IN CP-V.  THE CODE IN
*P*      THIS MODULE IS MAP RE-ENTRANT SO THAT SOME APPARENT
*P*      TEMPS ACTUALLY EXIST IN MULTIPLE PHYSICAL COPIES.
*P*
*P*
*P*
*P*      OPERATIONS WHICH MAY VARY WITH CPU TYPE ARE
*P*      ISOLATED TO SUBROUTINES CONTAINED IN THE
*P*      MODULE MP:INT.  REPLACEMENT OF THIS MODULE
*P*      WILL THEN BE ALL THAT IS NECESSARY TO
*P*      OPERATE ON A NEW CPU.
*P*
*P*
*P*
*P*                    EXTERNAL ENTRY POINTS
*P*                    ---------------------
*P*
*P*      T:SINIT  -  PERFORM SLAVE INITIALIZATION OPERATIONS
*P*
*P*      T:SIDLER -  RESTART POINT FOR SLAVE CPU AFTER SINGLE
*P*                  USER ABORT.
*P*
*P*      T:BLOCK  -  BLOCK FURTHER EXECUTION ON SLAVE CPU
*P*
*P*
*P*
*P*
*P*      ASIDE FROM A BRIEF PERIOD DURING INITIALIZATION AND
*P*      RECOVERY, ALL CODE IN THIS MODULE IS EXECUTED MAPPED, MASTER
*P*
*P*      THE SUBJECTIVE COUNTER INTERRUPT (COUNTER 4 ZERO) IS PERMITTED
*P*      ONLY WHILE EXECUTING A USER.  IF THE COUNTER ZERO INTERRUPT
*P*      RESULTS IN A QUANTUM END CONDITION FOR A USER, THE
*P*      INTERRUPT LEVEL WILL REMAIN ACTIVE UNTIL A NEW USER IS
*P*      SCHEDULED.
*P*
*P*
         PAGE
*
*        REGISTER DEFINITIONS
*
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
         PAGE
*
*        REFS AND DEFS
*
*
*        CPU TABLES
         REF      SX:SPP            SLAVE PRIVATE PAGE NUMBER
         REF      SB:STATE          SLAVE CPU STATE
         REF      SB:INIT           CPU START STOP FLAGS
         REF      S:CLAIM           ENTRY CLAIMING SWITCH
         REF      S:PCUN            CURRENT USER
         REF      SB:MPSW           MASTER PROCESSER SWITCH
         REF      SB:PFLG           MASTER ONLY FLAG POST REQUEST
         REF      S:ADR             PROCESSOR HARDWARE ADDRESS
         REF      SB:SFLG           SQUAN FLAG POST REQUEST
         REF      SB:RCVR           RECOVERY REQUEST SWITCH
         REF      SB:RCVA           RECOVERY ACKNOWLEDGE
         REF      SB:MINT           SLAVE TO MASTER INTERRUPT NO
         REF      SH:MINQ           MINI QUAN FOR SLAVE
         REF      SH:MAXQ           MAXI QUAN FOR SLAVE
         REF      S:MPRET           * SLAVE PROCESSOR TEMP CELLS
*
*        PRIVATE PAGE DATA
*
         REF      S:CUN             CURRENT USER NUMBER
         REF      S:PNO             PROCESSOR NUMBER
         REF      S:CLOCK4          INDIRECT ADDRESS FOR CLOCK4
         REF      S:INTBIT          INTERRUPT GROUP AND MASK BIT
         REF      S:DT              SAVED VALUE OF J:DELTAT
         REF      S:IDT             SAVE VALUE OF J:IDELTAT
*
*        PSDS
*
         REF      BLKPSD            BLOCK XPSD TARGET
         REF      CLK4PSD           QUANTUM CLOCK PSD
*
*        USER TABLES
*
         REF      UH:FLG            USER FLAGS
         REF      UH:DL             DO LIST
         REF      UX:JIT            JIT PAGE NUMBER
         REF      UB:MPFLG          MULTI-PROCESSING FLAGS
         REF      UB:CALR           CAL RATE
         REF      UB:PRIO           CURRENT PRIORITY
         REF      UB:PRIOB          BASE PRIORITY
         REF      UB:US             STATE
*
*        PERFORMANCE MONITORING
*
         REF      C:SIDLE           IDLE TIME ACCUMULATION
         REF      C:SUSER           SLAVE CPU USER EXEC
         REF      C:SCHED           SCHEDULE COUNT
*
*        SYSTEM CONTROL
*
         REF      SL:SQUAN          SWAP QUANTUM
         REF      SL:OPC            OVERLAY PROTECTION COUNTER
         REF      S:OPC             CURRENT OPC
         REF      SL:QUAN           ONLINE/GHOST QUANTUM
         REF      PLH:QN            BATCH PARTITION QUANTUMS
*
*        JIT CELLS
*
         REF      J:RNST            RUNSTATUS
         REF      J:DELTAT          CURRENT QUANTUM
         REF      J:IDELTAT         INITIAL QUANTUM VALUE
         REF      J:CTIME           ACCUMULATED IOTA
         REF      J:OVHTIM          SERVICE TIME
         REF      J:TIMENT          USER'S M:STIMER ADDRESS
         REF      J:UTIMER          M:STIMER TICS LEFT TO GO
         REF      JIT               BASE OF JIT
*
*        SPECIAL GLOBAL CELLS
*
         REF      SL:BSTRT          AUTO START INHIBIT
         REF      S:SSCRCH          SLAVE INITIATED SCREECH CODE
         REF      S:MPKYN           KEYIN RE-ENTRANCY COUNTER
*
*        CPU DEPENDENT SUBROUTINES
*
         REF      MP:HPN            OBTAIN HARDWARE PROCESSOR ADDRESS
         REF      MP:SCA            SUBJECTIVE COUNTER ENABLE
         REF      MP:SCD            SUBJECTIVE COUNTER DISABLE
         REF      MP:LLK            LOAD WRITE LOCKS
         REF      MP:MTRIG          TRIGGER MASTER CPU
*
*        CENTRAL SUBROUTINES
*
         REF      BLOCKER           BLOCK SUBROUTINE
         REF      MAP               SET MAP BIT IN CURRENT PSD
         REF      SYSTRT            SYSTEM START ADDRESS (X'26')
         REF      T:ACCTEX          ACCOUNT FOR EXECUTION TIME
         REF      T:MASTER          CHECK PSD FOR MASTER MODE
         REF      T:PULLE           RETURN TO SAVED ENVIRONMENT
         REF      T:SAVE            SAVE STANDARD ENVIRONMENT
         REF      T:SCREECHS        PERFORM SLAVE REQUESTED SCREECH
*
*        MAP AND ACCESS CONTROL WORDS
*
         REF      S:ACCW            USER ACCESS LOADING CW
         REF      S:MAPCW           USER MAP LOADING CONTROL WORD
         REF      S:SJACCW          SPECIAL JIT ACCESS CW
*
*        ENTRY POINTS
*
         DEF      T:BLOCK           BLOCK SLAVE CPU
         DEF      T:SCRASH          SLAVE SHUTDOWN FOR RECOVERY
         DEF      T:SIDLER          SUA RETURN
         DEF      T:SINIT           SLAVE INITIALIZATION
         DEF      SMON:             MODULE NAME FOR PATCHING
         DEF      T:SIDLE           ENTRY FROM SFAULT
         DEF      T:SQECK           SLAVE CLOCK4 ENTRY
         DEF      T:SQEND           SLAVE QUANTUM END CHECK
         DEF      T:SPARK           PARK USER FOR MASTER
         DEF      T:PFRET           ENTRY FROM POWER ON INTERRUPT
         PAGE
         PAGE
*********************************************************
*        SLAVE PROCESSOR INITIALIZATION                 *
*********************************************************
T:SINIT  EQU      %
         LI,R1    1                 INITIALIZE PROCESSOR INDEX
SINIT1   LB,R2    SB:INIT,R1        GET INITIALIZATION CONTROL FLAGS
         AND,R2   M2                EXTRACT START STOP FLAGS
         CI,R2    1                 CHECK FOR STARTED
         BE       SINIT2            YES, GO TRY TO CLAIM IT
*
SINIT3   AI,R1    1                 NEXT CPU ENTRY
         CI,R1    NCPU              CHECK FOR END
         BL       SINIT1            NO, CONTINUE
         B        SYSTRT            END, BRANCH THROUGH X'26'
*                                   PROBABLY BACK TO T:SINIT
*
*        STARTED ENTRY, CHECK FURTHER
*
SINIT2   LOAD,R8  SX:SPP,R1         GET PAGE FOR PROCESSOR
         BEZ      SINIT3            NONE, GET NEXT ENTRY
         LAS,R12  S:CLAIM,R1        TRY TO CLAIM IT
         BNE      SINIT3            ALREADY BUSY, TRY ANOTHER
         LI,R12   SINIT4            SET RETURN FOR T:PFRET
*
*        GOT IT - NOW SET UP MAP AND ARM INTERRUPTS
*
*        POWER-ON INTERRUPT PROCESSING FOR A SLAVE CPU ENTERS
*        AT T:PFRET TO RE-INITIALIZE THE SLAVE CPU AND RESUME OPERATIONS
*
*        R1 - PROCESSOR INDEX
*        R8 - PHYS PAGE # OF PRIVATE PAGE
*        R12 - LINK
*
T:PFRET  LW,R15   R1                SAVE PROCESSOR INDEX
         STW,12   S:MPRET,1         * STORE OUR CALLERS ADDRESS
         LPSD,0   WRITEKEY          * GET WK=0
WRITEKEY :PSD     (IA,WRITEL),(WK,0)
WRITEL   BAL,11   MP:LLK            * GO LOAD MAPS
         LW,1     15                * RESTORE INDEX (PROCESSOR NUMBER)
         LW,12    S:MPRET,1         * AND FINISH THE KLUDGE
         LI,R3    3                 BUILD MAP IMAGE
         LI,R0    0                 SET PAGE ZERO=0
         STORE,R3 R0,R3             IN REGS R2,R3
         BDR,R3   %-1               PAGES 0,1,2,3
         LI,R3    VPXPSDT           SET PAGE INTO SKEL
         STORE,R8 R0,R3             TO COMPLETE MAP IMAGE
         LI,R8    0                 POINT TO MAP IMAGE IN R0,R1
         LW,R9    Y01               SET COUNT AND CONTROL START
         LW,R4    R15               RESTORE PROCESSOR INDEX
         LDMAP,R8 0                 SET UP ROOT MAP
         BAL,R1   MAP               NOW GO MAPPED
         LI,R11   C:SIDLE           SET CLOCK TO ACCOUNT IDLE
         AW,R11   R4                FOR PROCESSOR
         STW,R4   S:PNO             SAVE PROCESSOR NUMBER
         STW,R11  S:CLOCK4          SET INDIRECT CELL FOR SUBJ CNTR
*
*        ARM SUBJECTIVE COUNTERS
*
         BAL,R11  MP:SCA            ARM AND ENABLE SUBJECTIVE COUNTER
         B        *R12              RETURN, PROBABLY TO %+1
*
*        OBTAIN HARWARE PROCESSOR NUMBER
*
SINIT4   BAL,R11  MP:HPN            READ PROCESSOR ADDRESS
         STW,R8   S:ADR,R4          SAVE PROCESSOR ADDRESS
         PAGE
**********************************************************
*             SLAVE PROCESSOR IDLE LOOP                  *
**********************************************************
T:SPARK  EQU      %
         LW,R2    S:PNO             GET PROCESSOR NUMBER
         LI,R1    1                 MARK MASTER ONLY FLAG
         STB,R1   SB:PFLG,R2        AND FALL INTO IDLE LOOP
T:SIDLE  EQU      %
         MTW,0    S:CUN
         BEZ      %+2               ACCOUNT EXECUTION
         BAL,R3   T:ACCTEX          IF THERES A USER
         LI,R1    IDLE              SET STATE TO IDLE
         LW,R2    S:PNO             GET PROCESSOR INDEX
         STB,R1   SB:STATE,R2       ANNOUNCE STATE
*
         LI,R8    C:SIDLE           SET CLOCK TO IDLE
         AW,R8    S:PNO             FOR THIS PROCESSOR
         STW,R8   S:CLOCK4
*
         LI,R0    0                 ZAP PREVIOUS
         STW,R0   S:CUN             CURRENT USER NUMBER
         STB,R1   SB:MPSW,R2        SET MASTER REQUEST FLAG
         BAL,R11  MP:MTRIG          TRIGGER MASTER CPU
SIDL1    LB,R10   SB:MPSW,R2        TEST MASTER REQUEST DONE
         BNE      SIDL2             NO
         LW,R4    S:PCUN,R2         GET CURRENT USER NUMBER
         BNE      T:RUN             GOT ONE GO RUN HIM
         STB,R1   SB:MPSW,R2        SET REQUEST FOR MASTER AGAIN
         B        SIDL1             REPEAT REQUEST
SIDL2    LB,R10   SB:RCVR,R2        TEST FOR RECOVER REQUEST
         BNE      T:SCRASH          YES
         LB,R12   SB:INIT,R2        GET START/STOP FLAGS
         CI,R12   STOPBIT           SHOULD WE STOP
         BANZ     T:STOPS           YES
         LCI      NREGLOOP          GET REGISTER
         LM,R8    REGLOOP           CONTAINED IDLE LOOP
         LFI      7                 FLOAT BITS SAY IDLE
*                                   FOR HARDWARE MONITOR
         B        R8                AND TRANSFER TO IT
REGLOOP  BDR,DLYC R8                LOOP AT R8 FOR ABOUT 100 MICS
         NOP                        FOR SIGMA 9 PIPELINE
         NOP                        "    "    "    "
         B        SIDL1             AND CHECK AGAIN
DLYR     DATA     80                DELAY COUNTER
NREGLOOP EQU      %-REGLOOP         SIZE OF REGISTER IDLE LOOP
DLYC     EQU      R8+DLYR-REGLOOP   REGISTER CONTAINING DELAY COUNTER
         PAGE
**********************************************************
*              RUN USER IN SLAVE PROCESSOR               *
**********************************************************
T:RUN    EQU      %
         STW,R4   S:CUN             REMEMBER NEW CURRENT USER
         LOAD,R0  UX:JIT,R4         GET JIT PHYSICAL PAGE NUMBER
         STORE,R0 R0                SET IN B/HW ZERO
         LI,R8    0                 BUILD CONTROL WORD
         LI,R9    JIT               SET CONTROL START
         AW,R9    Y01               NO SET COUNT
         LDMAP,R8 0                 MOVE TO MAP
         LD,R8    S:ACCW            GET ACCES CONTROL WORD
         AI,R8    JIT               POINT TO VIRTUAL JIT
         LPC,R8   0                 LOAD ACCESS
         LD,R8    S:MAPCW           GET MAP LOADING SKELETON CW
         AI,R8    JIT               POINT TO VIRTUAL JIT
         LDMAP,R8 0                 LOAD USER MAP
         LH,R15   UH:FLG,R4         GET USER FLAGS
         CI,R15   SJAC              CHECK FOR SPECIAL JIT ACCESS
         BAZ      %+3               NO, SKIP IT
         LD,R8    S:SJACCW          GET SJAC CONTROL WORD
         LPC,R8   0                 AND LOAD ACCESS CONTROLS SOME MORE
         LCW,R8   J:DELTAT          DONT COUNT MASTER TIME
         AW,R8    J:IDELTAT         IN SLAVE BUCKETS
         SW,R8    J:OVHTIM
         AWM,R8   C:SUSER,R2
         LW,R7    TSTACK            GET TSA
         AI,R7    -17               POINT AT PSD
         LD,R8    *R7               GET PSD
         CW,R8    Y008              CHECK FOR SLAVE BIT
         BAZ      T:SPARK           MASTER, BAD
RUN1     LB,R5    J:RNST            GET RUN STATUS
         BNEZ     T:SPARK           SOME ABORT CONDITION
         MTW,0    J:TIMENT          DOES THE USER HAVE A TIMER?
         BEZ      %+3               IF NOT IT CAN'T HAVE RUN OUT
         MTW,0    J:UTIMER          HAS USER'S TIMER RUN OUT?
         BLEZ     T:SPARK           IF SO PARK USER FOR THE MASTER
         LH,R5    UH:DL,R4          GET DO-LIST HEAD AND FLAGS
         BEZ      RUNX              OK, CONTINUE RUNNING
         AND,R5   M12               SCRUB TO DO-LIST POINTER
         BEZ      T:SPARK           ONE OF THE FLAGS IS SET
         LD,R8    0,R5              GET DO-LIST ENTRY
         LB,R9    R8                GET PRIORITY OF BLOCK
         CB,R9    UB:PRIO,R4        TEST AGAINST CURRENT PRIO
         BLE      T:SPARK           HIGHER OR EQUAL, HONOR IT
*
*        A USER WILL BE PERMITTED TO RUN IN A SLAVE CPU WITH
*        WAITING DO-LIST ENTRIES DEFERRED DUE TO PRIORITY.  THIS IS
*        TO ALLOW SLAVE MODE REAL-TIME USERS A CHANCE TO EXECUTE
*        ON SLAVE CPUS.
*
RUNX     LCH,R10  SH:MINQ,R2        INVERT TIME PERIOD
         AWM,R10  J:IDELTAT         ADD TO JIT
         AWM,R10  J:DELTAT          UNTIL A SLICE IS THERE
         BGEZ     %-3
         LI,R10   J:DELTAT          SET CLOCK TO USER
         STW,R10  S:CLOCK4          TO ACCOUNT EXECUTION TIME
         BAL,R11  MP:SCA            ARM, ENABLE AND CLEAR SUBJ COUNTER
         LI,R8    USER              SET STATE TO ACTIVE
         STB,R8   SB:STATE,R2       BEFORE GOING TO USER
         LB,R9    SB:RCVR,R2        CHECK FOR RECOVER REQUEST
         BEZ      T:PULLE           ALL OK
         B        T:SCRASH          BAD, SCREECK REQUESTED
         PAGE
**********************************************************
*             CHECK FOR QUANTUM END (T:SQECK)            *
**********************************************************
T:SQECK  EQU      %
         MTW,0    S:CUN             CHECK FOR CURRENT USER
         BEZ      NOUSER            NONE, TROUBLE
         PUSH     6,R13             SAVE REGS AGAIN
         LD,R0    CLK4PSD           GET INTERRUPT PSD
         BAL,R2   T:SAVE            SAVE STANDARD ENVIRONMENT
         LW,R2    S:PNO             GET PROCESSOR INDEX
         LB,R3    SB:RCVR,R2        CHECK FOR RECOVER REQUEST
         BNE      T:SCRASH          YES
         BAL,R2   T:MASTER          CHECK FOR MONITOR RUNNING
*
*             CHECK FOR QUANTUM END
*                 ENTRY POINT FOR TRAPEXIT ON SLAVES
*
T:SQEND  EQU      %
         LW,R8    J:DELTAT          COMPUTE ELAPSED TIME
         SW,R8    J:IDELTAT         IN THIS SHOT
         LW,R2    S:PNO             GET PROCESSORE NUMBER
         AW,R8    J:OVHTIM          ADD SERV TIME
         AW,R8    J:CTIME           AND IOTA ACCUMULATION
         CH,R8    SH:MAXQ,R2        CHECK FOR MAX QUAN
         BGE      T:SIDLE           YES
         CW,R8    SL:SQUAN          HAD SQUAN ?
         BL       %+3               NO
         LI,R1    1                 SET FLAG TO
         STB,R1   SB:SFLG,R2        POST SQUAN FLAG
         LW,R10   S:OPC             CHECK FOR SWAP PROB
         AW,R10   SL:OPC            2 X SL:OPC SWAP FAILURES
         BLZ      T:SPARK           YES,PARK USER
SQECK1   LW,R4    S:CUN             GET CURRENT USER NUMBER
         B        RUN1              MERGE WITH RUN
         PAGE
*********************************************************
*            CENTRAL SLAVE BLOCK PROCESSING            *
*********************************************************
T:BLOCK  EQU      %
         PUSH     6,R13             SAVE REGS IN USER TSTACK
         LW,R0    BLKPSD            GET PSW1 OF BLOCK ENV
         AI,R0    -(BLOCKER+1)      CLEAR IA
         OR,R0    R1                MERGE IN RETURN
         LW,R1    BLKPSD+1          GET PSW2
         BAL,R2   T:SAVE            SAVE STANDARD ENVIRONMENT
         B        T:SPARK           AND PARK USER
         PAGE
**********************************************************
*             SLAVE INVOKED SOFTWARE CHECK               *
**********************************************************
NOUSER   SCREECH  X'78',1           TRAP OR INTERRUPT WITHOUT USER
         PAGE
**********************************************************
*             SLAVE SHUTDOWN FOR RECOVERY                *
**********************************************************
T:SCRASH EQU      %
         BAL,R11  MP:SCD            DISARM SUBJECTIVE COUNTER
         LCI      12                PICK UP REGISTER LOOP
         LM,R4    REGIDLE
         LW,R2    S:PNO             PROCESSOR INDEX
         B        4                 TRANSFER TO REGS
REGIDLE  STB,R2   SB:RCVA,R2        SET RECOVERY ACKNOWLEDGE FLAG
         LB,R0    SB:RCVR,R2        AND WAIT FOR RECOVERY TO
         BNEZ     5                 COMPLETE
         LB,R0    SYSTRT            CHECK FOR BRANCH
         CI,R0    X'68'             IN START LOCATION
         BNE      7                 NO, WAIT
         B        SYSTRT            YES EXIT TO IT
         PAGE
*
*        RESTART LOCATION AFTER SINGLE USER ABORT
*
T:SIDLER EQU      %
         CW,R2    S:PNO             CHECK FOR PROCESSOR NO
         BNE      T:SINIT           NO, RE-INITIALIZE
         B        SIDL1             WADE INTO IDLE
         PAGE
**************************************************************
*              NORMAL SLAVE SHUTDOWN                         *
**************************************************************
T:STOPS  EQU      %
         BAL,R11  MP:SCD            DISARM SUBJECTIVE COUNTER
         LW,R2    S:PNO             GET PROCESSOR NUMBER
         LI,R0    STOPPED           ZAPPER
         MTB,1    SB:MPSW,R2        SET MASTER FLAG
         STB,R0   SB:STATE,R2       SET STATE TO GONE
         LCI      8                 PICK UP REGIST ROUTINE
         LM,R4    REGIDLE           AND WAIT IN REGISTERS
         B        7
         PAGE
         END

