         PCC      0
         TITLE    'CSECOM  -  SIGMA 9 AND XEROX 560 COMMON CODE'
         DEF      CSECOM:
CSECOM:  EQU      %
RAWORKS  SET      1                 MAYBE THEY'LL FIX IT SOMEDAY
RAWORKS  SET      0                 BUT RIGHT NOW IT DOESN'T WORK
         SYSTEM   UTS
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
         TITLE    'CSECOM  -  REFS AND DEFS'
         REF      CSE%BEST%END%ABORT%STEP
         REF      CSE%BEST%END%SCREECH   (HAND)
         REF      CSE%BEST%END%STOP     (HAND)
         REF      CSE%END
         REF      CSE%MFIX
         SPACE
         DEF      CSE%LOG%PRIMARY%PFI
         DEF      CSE%MDEL%IF%LOGGED
         SPACE
*   TABLE REFS
         SPACE
         DEF      CSE%2:9,CSE%2:560
         DEF      CSE%4:9,CSE%4:560
         DEF      CSE%6:9,CSE%6:560
         DEF      CSE%8:9,CSE%8:560
         DEF      CSE%9:9,CSE%9:560
CSE%4:9  EQU      CSE%MLOG          MEMORY POLLING ROUTINE
CSE%4:560 EQU     CSE%MLOG          MEMORY POLLING ROUTINE
CSE%6:9  EQU      CSE%MDEL          MSTAT CLEARING
CSE%6:560 EQU     CSE%MDEL          MSTAT CLEARING
CSE%2:9    EQU    CSE%MPOLR         MEMORY POLLING ROUTINE
CSE%2:560  EQU    CSE%MPOLR         MEMORY POLLING ROUTINE
CSE%8:9    EQU    CSE%GET%CONTENTS  READ AND INHIBIT PARITY
CSE%8:560  EQU    CSE%GET%CONTENTS  READ AND INHIBIT PARITY
CSE%9:9  EQU      CSE%T46%FIX       WATCHDOG TIMER HANDLER
CSE%9:560 EQU     CSE%T46%FIX       WATCHDOG TIMER HANDLER
         SPACE
         REF      CSE%1,CSE%3,CSE%5,CSE%7
CSE%PPOLR EQU     CSE%1             PROCESSOR POLLING
CSE%PLOG  EQU     CSE%3             PROCESSOR POLL LOGGING
CSE%PDEL  EQU     CSE%5             PSTAT CLEARING
CSE%MFIX%ENTRY  EQU  CSE%7
         SPACE
         REF      CSED%BEST%END,CSED%LOG%MFI,CSED%MAPPED,CSED%RTRY%CNT
         REF      CSED%MSTAT,CSED%PATH,CSED%PSD,CSED%PSD%I57
         REF      CSED%INST
         REF      CSED%EA%VIRT
         REF      CSED%CF
         REF      CSED%LINK
         REF      CSED%SPDF,CSEI%PATH%I57
         REF      CSEI%PATH%MPOL,CSEP%MSTAT%SZE
         REF      CSEP%WHY%WD,CSEP%WHY%MAP,CSEP%WHY%T4D
         SPACE
         SPACE
         DEF      CSE%T4D%FIX,CSE%I57,CSE%T4C%FIX%MAP
         DO1      RAWORKS
         DEF      CSE%RA%TST
         SPACE
         REF      CORED,Y004,Y8,Y1,S:CUN
         REF      ERRLOG,LOADMAP,T:XMMC
         REF      M7
         REF      M24
         REF      X0
         REF      Y01
         REF      COC,LCOC,COCINIT,COH:DN
         REF      CSED%3STAT
         REF      3COUNT
         REF      3BUFCLR
         SPACE
CSEP%PFI%BIT  EQU  X'800'   B20, WD BIT FOR PFI
         TITLE    'CSECOM  -  CSE%MPOLR'
CSE%MPOLR  EQU    %                 MEMORY POLLING
         SPACE
*   ENTER WITH BAL,R15, ALL REGISTERS VOLATILE
         SPACE
         LI,R3    CSEI%PATH%MPOL    CRITICAL PATH BIT
         STS,R3   CSED%PATH         SET FOR REENTRY DETECTION
         LI,R1    CSED%MSTAT        WORD INDEX TO MPOLR TABLE
         LI,R0    -1               ENTRY INDEX IN MPOLR TABLE
         LI,R2    0                 INDEX TO MEMORY
         LI,R10   4                 SIGMA 9 CAN HAVE 4-WAY INTERLEAVE
         LW,R5    CORED             GET MAX MEMORY
         AI,R5    -1                GET MAX ADDRESS
         BIF,S9   CSEM1             B/ YES, SIGMA 9
         LI,R10   2                 X560 CAN ONLY HAVE 2-WAY
CSEM1    EQU      %
         LI,R4    0                 INTERLEAVING MODIFIER
CSEM2    EQU      %
         LCI      X'8'              LOAD MEMORY STATUS
         LMS,R11  0,R2              WORD ZERO
         BIF,X560 CSEM21            B/ X560 DONT NEED TO SHIFT BITS
         SCS,R11  9                 PUT BITS IN LINE WITH X560 STATUS
CSEM21   SCS,R11  2                 GET B1 FROM X560
         CI,R11   X'7FF'            ARE ANY ERROR BITS SET ?
         BANZ     CSEM4             B/ YES, WE HAVE AN ERROR
CSEM3    EQU      %
         AI,R2    1                 BUMP UP BY ONE
         AI,R4    1                 SO WE CAN COUNT NUMBER OF TIMES BUMPED
         CW,R4    R10               COMPARE WITH MAX INTERLEAVE
         BL       CSEM2             B/ OK TO USE
         SW,R2    R4                SET BUMP=0
         AI,R2    8*1024            8K INCREMENT IS SAFEST
         CW,R2    R5                COMPARE WITH HIGHEST ADDR
         BL       CSEM1             B/ NOT DONE YET
         LI,R2    0                 DONE, RETURN
         STS,R2   CSED%PATH         RESET CRITICAL PATH BIT (USES R3)
         B        *R15              RETURN
CSEM4    EQU      %
         AI,R0    1                 BUMP UP ENTRY INDEX
         CI,R0    CSEP%MSTAT%SZE    COMPARE W/ MAX INDEX
         BLE      CSEM4B            B/ YES, ROOM TO LOG IT
         LCI      X'C'              READ AND RESET
         LMS,R11  0,R2              IN ORDER TO CLEAR FLT REG
         B        CSEM3             CONTINUE POLLING
CSEM4B   EQU      %
         MTW,0    0,R1              R1=WORD INDEX OF ENTRY WORD 0
         BGEZ     CSEM6             B/ B0 NOT SET, OK TO USE
         AI,R1    3                 GO TO NEXT ENTRY
         BIF,X560 CSEM4             X560 ENTRY SIZE IS 3 WORDS
         AI,R1    1                 SIGMA 9 HAS 4 WORD ENTRY
         B        CSEM4             GO TRY NEXT
CSEM6    EQU      %
         BIF,S9   CSEM7             B/ IF SIGMA 9
         LCI      X'A'              X560 WORD 1 B'1010'
         B        CSEM8
CSEM7    LCI      X'9'              SIG9 WORD 1 B'1001'
CSEM8    LMS,R11  0,R2              PICK UP MSW1
         STW,R11  2,R1              MSW1=WORD 2 OF MSTAT ENTRY
         BIF,X560 CSEM9             B/ IF X560
         LCI      X'A'              SIG9 WORD 2 B'1010'
         LMS,R11  0,R2              PICK UP MSW2 (SIG9 ONLY)
         STW,R11  3,R1              MSW2=WORD 3 OF MSTAT ENTRY
CSEM9    LCI      X'C'              WORD 0 AND RESET (SIG9 AND X560)
         LMS,R10  0,R2              PICK UP MSW0 AND RESET
         STW,R10  1,R1              MSW0=WORD 1 OF MSTAT ENTRY
         LW,R10   2,R1              PICK UP MSW1 (FOR X560 = ADDRESS)
         BAL,R14  CSE%MFIX%ENTRY    CHECK MACHINE SPECIFIC BITS
         OR,R10   Y8                SET ENTRY IN USE FLAG
         STW,R10  0,R1              REALL ADDRESS AND FLAGS IN WORD 0
         AI,R1    3                 BUMP UP ENTRY INDEX
         BIF,X560 CSEM3             B/ IF X560 , ENTRY SIZE OF 3 WORDS
         AI,R1    1                 SIGMA 9 HAS 4 WORD ENTRY SIZE
         B        CSEM3             GO LOOK FOR MORE
         TITLE    'CSECOM   -  CSE%MLOG'
*   ROUTINE TO LOG MEMORY SECONDARY RECORDS
         SPACE
CSE%MLOG EQU %
         LI,R4    0                 LOG ALL ENTRIES
         B        CSML1
CSE%MLOG%IF%MFI  EQU  %             FOR SIG9 , MFI LOG ONLY OT AND PF
         LI,R4    -1                SET FLAG
CSML1    EQU      0
         LI,R0    4                 MSTAT SIZE FOR SIGMA9
         LW,R7    =X'43060000'      CODE,COUNT FOR SIGMA 9
         BIF,S9   CSML2             B/ YES,SIGMA 9
         LI,R0    3                 MSTAT ENTRY SIZE FOR X560
         LW,R7    =X'42050000'      CODE,COUNT FOR X560
CSML2    LI,R3    CSEP%MSTAT%SZE    HIGHEST INDEX TO MSTAT TABLE
         MW,R3    R0                TIMES ENTRY SIZE
         STW,R0   R1                R1 IS ENTRY SIZE
         SCS,R0   -4                POSITION R0 FOR LC/LM
         LI,R6    R7                ADDRESS OF BUFFER
         OR,R6    Y1                DONT ENABLE FLAG
CSML3    EQU      %                 BEGINNING OF LOOP
         LC       R0                ENTRY SIZE
         LM,R9    CSED%MSTAT,R3     PICK UP ENTRY
         CI,R9    0                 IS THIS ENTRY USED
         BGEZ     CSML5             B/ NO, TRY NEXT ONE
         CI,R4    0                 IS THIS SIGMA9 MFI
         BEZ      CSML4             B/ NO OK TO LOG ALL
         CW,R10   Y01               YES, IS THIS POWERFAIL, OVERTEMP
         BAZ      CSML5             B/ NO, DONT LOG IT
CSML4    EQU      %
         OR,R9    Y1                SET LOGGED FLAG
         STW,R9   CSED%MSTAT,R3     PUT IT IN TABLE WITH FLAG SET
         AND,R9   M24               GET RID OF FLAGS
         BAL,R5   ERRLOG            GO LOG IT
CSML5    SW,R3    R1                SUBTRACT ENTRY SIZE FROM INDEX
         BGEZ     CSML3             B/ GO GET NEXT ENTRY
         MTW,0    3COUNT            ANY 49 DATA ?
         BEZ      *R15              B/ NO RETURN
         LI,R6    CSED%3STAT        ADDRESS OF ERRLOG IMAGE
         OR,R6    Y1                ERRLOG DONT ENABLE FLAG
         BAL,R5   ERRLOG            GO LOG 49 RECORD
         LW,R5    Y8                SET LOGGED FLAG
         STS,R5   3COUNT
         B        *R15              AND RETURN
         B        *R15              ALL DONE EXIT
         TITLE    'CSEHAND  -  CSE%MDEL'
CSE%MDEL EQU      %
         LI,R9    0                 FLAG FOR ALL
         B        CSMD1
CSE%MDEL%IF%LOGGED  EQU  %
         LI,R9    -1                DELETE ONLY IF LOGGED FLAG
CSMD1    LI,R4    1                 ENTRY SIZE FOR SIG7
         LD,R0    X0                ZERO OUT R0-R1
         BIF,S7   CSMD2             B/ YES, SIG7
         LD,R2    X0                ZERO OUT R1-R3
         LI,R4    4                 ENTRY SIZE FOR SIGMA 9
         BIF,S9   CSMD2             B/ YES, SIGMA 9
         LI,R4    3                 ENTRY SIZE FOR X560
CSMD2    LI,R5    CSEP%MSTAT%SZE    MAX INDEX OF ENTRIES
         MW,R5    R4                TIMES ENTRY SIZE
         STW,R4   R6                SAVE ENTRY SIZE
         SCS,R4   -4                POSITION SIZE FOR LC/STM
CSMD3    CI,R9    0                 OK TO DELETE ALL
         BE       CSMD4             B/ YES, SKIP CHECK
         LW,R7    CSED%MSTAT,R5     PICK UP WORD ZERO
         AND,R7   Y1                IS LOGGED BIT SET ?
         BAZ      CSMD5             B/ NO, DONT DELETE
CSMD4    LC       R4                OK TO DELETE
         STM,R0   CSED%MSTAT,R5     ZERO OUT THIS ENTRY
CSMD5    SW,R5    R6                SUBTRACT ENTRY SIZE
         BGEZ     CSMD3             GO GET ANOTHER
         CI,R9    0                 OK TO DELETE 3DATA ?
         BE       CSMD5B            B/ NO, DONT DELETE
         MTW,0    3COUNT            HAS IT BEEN LOGGED ?
         BGEZ     *R15              B/ NO, RETURN
CSMD5B   EQU      %
         LW,R1    3BUFCLR           MBS SETUP TO CLEAR CSED%3STAT
         MBS,R0   0                 DO IT
         B        *R15              RETURN, ALL DONE
         TITLE    'CSECOM  -  CSE%T4C%FIX%MAP'
CSE%T4C%FIX%MAP  EQU  %
         BAL,R10  LOADMAP           LOAD COMPLETE MAP
         LW,R4    S:CUN             GET CURRENT USER NUMBER
         BAL,R11  T:XMMC            LOAD USERS MAP IMAGE
         LI,R11   CSEP%WHY%MAP      IN CASE WE ABORT
         MTW,-1   CSED%RTRY%CNT     DECRMT RETRY COUNTER
         DO       RAWORKS
         BGZ      CSE%RA%TST        OK TO RETRY, CHECK RA BIT
         ELSE
         BGZ      CSEASTEP          GO ABORT USERS STEP
         FIN
         BAL,R12  CSE%BEST%END%STOP QUIT, RETRY FAILED
         B        *R15
         SPACE    2
         DO       RAWORKS
CSE%RA%TST  EQU   %
         LW,R1    CSED%PSD+1        GET PSD WORD 2
         CI,R1    X'8'              CHECK RA BIT
         BAZ      *R15              OK TO RETRY
         FIN
CSEASTEP  BAL,R12 CSE%BEST%END%ABORT%STEP  CANT RETRY , ABORT STEP
         B        *R15
         TITLE    'CSECOM  -  CSE%T46%FIX'
CSE%T46%FIX  EQU  %
         STW,R15  CSED%LINK         SAVE RETURN IN CASE COCINIT
         BIF,X560 NOTSIG9           B/ NOT SIGMA 9
         LC       CSED%CF           GET TCC
         BCR,7    *R15              SIGMA 9 PHASE 1 TIMEOUT, RETURN
NOTSIG9  EQU      %
         LB,R1    CSED%INST         GET INSTRUCTION
         AND,R1   M7                STRIP OFF INDIRECT
         CLM,R1   6C6D              RD OR WD
         BCS,9    NOTRDWD           B/ NO
         LW,R1    CSED%EA%VIRT      GET EFFECTIVE ADDRESS
         CI,R1    X'2000'           MODE >= 2 ?
         BL       OKOP              B/ NOT EXTERNAL MODE
         MTW,R1   CSED%PSD          INCR. PSD TO SKIP INSTRUCTION
         B        *R15              AND RETURN
NOTRDWD  EQU      %
         CLM,R1   4C4F              IS IT I/O INSTRUCTION ?
         BCS,9    OKOP              B/ NO
         LI,R2    COC               YES, CHECK FOR COC @ THIS IOP
         BEZ      OKOP              B/ NON COC SYSTEM
         LW,R2    CSED%EA%VIRT      GET I/O ADDRESS
         LI,R3    X'1F00'           MASK FOR IOP ADDRESS
         RIO,0    0,R2              RIO TO IOP TO CLEAR IT
         LI,R1    LCOC              NUMBER OF COCS
NEXTCOC  EQU      %
         LH,R0    COH:DN,R1         GET COC ADDRESS
         CS,R2    R0                IS COC ON THIS IOP ?
         BE       GOTONE            B/ YES, GO RESTART COC'S
         AI,R1    -1                DECR COC INDEX
         BGEZ     NEXTCOC
         B        CS461             SKIP COCINIT
GOTONE   BAL,R11  COCINIT           GO START UP COC'S
CS461    EQU      %
         MTW,-1   CSED%RTRY%CNT     DECR RETRY COUNT
         BGZ      *CSED%LINK        RETURN IF NOT EXHAUSTED
OKOP     EQU      %
         LI,R11   CSEP%WHY%WD       WHY CODE
         BAL,R12  CSE%BEST%END%ABORT%STEP SET UP TO ABORT STEP (SCREECH)
         B        *CSED%LINK        RETURN
         TITLE    'CSECOM  -  CSE%T4D%FIX'
CSE%T4D%FIX  EQU  %
         LI,R11   CSEP%WHY%T4D
         BAL,R12  CSE%BEST%END%SCREECH  MUST BE MASTER MODE
         B        *R15                    OR WE WOULDN'T BE HERE
         TITLE    'CSECOM  -  CSE%GET%CONTENTS'
CSE%GET%CONTENTS  EQU  %
         SPACE
*   ENTER WITH REAL WORD ADDRESS IN R0, LINK IN R13
*   RETURN WITH CONTENTS IN R0, CC4=1 IF PARITY ERROR, 0 IF NOT
         SPACE
         LCI      X'1'              READ AND INHIBIT PARITY
         LMS,R0   *R0               GET CONTENTS
         STCF     R2                SAVE CC FOR CALLING ROUTINE
         BCS,X'C' CSGET1            B/ PAR ERROR
         LCI      0                 NO ERROR
         B        *R13
CSGET1   LCI      1                 PARITY ERROR OR DATA BUS CHECK
         B        *R13
         TITLE    'CSECOM  -  CSE%I57  -  MFI'
CSE%I57  EQU      %
         PUSH     16,R0             SAVE REGS IN TSTACK
         LI,R1    CSEI%PATH%I57     PATH BIT FOR I57
         STS,R1   CSED%PATH         SET FOR REENTRY CHECK
         LI,R2    CSEP%PFI%BIT      WD BIT FOR PFI
         WD,R2    X'1100'           DISARM PFI
         LI,R0    0
         STW,R0   CSED%BEST%END     CLEAR BEST END FLAG
         STW,R0   CSED%LOG%MFI      CLEAR ERROR LOGGER FLAG
         BAL,R15  CSE%PPOLR         PROCESSOR POLLING
         BAL,R15  CSE%MPOLR         MEMORY POLLING
         BAL,R15  CSE%MFIX          LOOK AT MEMORY ERRORS
         MTW,0    CSED%LOG%MFI      CHECK LOGGER FLAG
         BEZ      CSMFI1            B/ NO, SOMEONE ELSE WILL
         BAL,R15  CSE%LOG%PRIMARY%MFI
         BAL,R15  CSE%PLOG          LOG PPOLR SECONDARIES
         BAL,R15  CSE%MLOG%IF%MFI  LOG ONLY THOSE NOT DUALLY REPORTED
         MTW,0    CSED%BEST%END     OK TO RETURN
         BEZ      CSMFI1            B/ YES
         LI,R0    0                 NO, SET UP FOR CSE%END EXIT
         STW,R0   CSED%SPDF         RESET REENTRY FLAG
         STW,R0   CSED%MAPPED       RESET MAPPED FLAG
         LD,R0    CSED%PSD%I57      MOVE PSD
         STD,R0   CSED%PSD
         CW,R0    Y004              CHECK MAPPED BIT
         BAZ      CSE%END           GO EXIT (SCREECH OR STOP)
*                                   NOTE TSTACK NOT PULLED
*                                   SAVE IT FOR RECOVERY
         MTW,1    CSED%MAPPED       SET MAPPED FLAG
         B        CSE%END           GO EXIT
         SPACE
CSMFI1   EQU      %
         BAL,R15  CSE%PDEL          CLEAR PSTAT (PPOLR TABLE)
         BAL,R15  CSE%MDEL%IF%LOGGED  CLEAR MSTAT (MPOLR TABLE) IF LOGGED
         BIF,S9   CSMFI2            B/ IF SIGMA 9 (DONT ARM PFI)
         LI,R1    CSEP%PFI%BIT      WD BIT FOR PFI
         WD,R1    X'1200'           ARM PFI
CSMFI2   LI,R0    0
         LI,R1    CSEI%PATH%I57     PATH BIT FOR I57
         STS,R0   CSED%PATH         RESET REENTRY FLAG
         PULL     16,R0             RESTORE REGS
         LPSD,X'B'  CSED%PSD%I57    GO BACK WITH NEW RP, MFI CLEARED
         TITLE    'CSECOM   -  CSE%LOG%PRIMARY%PMFI'
CSE%LOG%PRIMARY%PFI  EQU  %
         LW,R3    =X'30020000'      CODE,COUNT,SHADED
         B        CSLP1
CSE%LOG%PRIMARY%MFI  EQU  %
         LW,R3    =X'31020000'      CODE,COUNT,SHADED
CSLP1    EQU      %
         LI,R6    R3                ADDRESS OF MSG
         OR,R6    Y1                DONT ENABLE/DISABLE FLAG
         BAL,R5   ERRLOG            GO DO IT
         B        *R15              RETURN
4C4F     DATA     X'4C',X'4F'       I/O INSTR
6C6D     DATA     X'6C',X'6D'       RD,WD INSTR
         END

