         DEF      ERHNDLR:
ERHNDLR: EQU      %
   TITLE '* * E R R O R   L O G G I N G   I N T E R F A C E * * '
         SYSTEM   SIG7FDP
S69PROC  SET      1
UTSPROC  SET      0
DISCBPROC SET     1                                                     DISCB
         SYSTEM   UTS
         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
SR1,R8   EQU      8
SR2,R9   EQU      9
SR3,R10  EQU      10
SR4,R11  EQU      11
D1,R12   EQU      12
D2,R13   EQU      13
D3,R14   EQU      14
D4,R15   EQU      15
         PAGE
*
*                 PUSH OR PULL N WORDS SPECIFIED BY FIRST ARGUMENT INTO
*                 REGISTERS STARTING AT SECOND ARGUMENT.
*
*                 ACCEPTABLE FORMS ARE:
*                   PUSH R              PULL R
*                   PUSH 1,R            PULL 1,R
*                   PUSH N,R            PULL N,R 1<N<17
*
PUSH     CNAME    X'9',X'B'
PULL     CNAME    X'8',X'A'
         PROC
         DO       NUM(AF)=1
LF       GEN,1,7,4,3,17  0,NAME(1),AF(1),0,TSTACK
         ELSE
         DO       AF(1)=1
LF       GEN,1,7,4,3,17  0,NAME(1),AF(2),0,TSTACK
         ELSE
         DO       AF(1)=16
LF       LCI      0
         ELSE
LF       LCI      AF(1)
         FIN
         GEN,1,7,4,3,17  0,NAME(2),AF(2),0,TSTACK
         FIN
         FIN
         PEND
*
*                 ENABLE ALL INTERRUPTS (CLEAR MASTER INHIBITS).
*
ENABLE   CNAME
         PROC
LF       GEN,8,24 X'6D',X'27'       ENABLE
         PEND
*
*                 DISABLE ALL INTERRUPTS (SET MASTER INHIBITS).
*
DISABLE  CNAME
         PROC
LF       GEN,8,24 X'6D',X'37'       DISABLE
         PEND
*
         PAGE
*
*        INTERNAL DATA
*
         BOUND    8
MAP1     :PSD     (IA,UNMAP+1),(WK,1),MAP,MASTER
UNMAP1   :PSD     (IA,UNMAP+1),(WK,1),MASTER
ERRFIL   TEXTC    'ERR:FIL'
MISC     DATA     X'01F00A00'       F/C - PRI - RETRIES - DCTX
         PAGE
*
*        SUBROUTINE TO SAVE ENVIRONMENT
*
T:SAVE   LCI      13                SAVE
         PSM,3    TSTACK            INITIAL SET OF REGISTERS
         LW,4     TSTACK            GET TOP OF STACK POINTER
         AI,4     -17               POINT TO SPOT WHERE THE
         STD,0    *4                PSD GOES - AND PUT IT THERE
         B        0,2               EXIT TO CALLER
MAP      LPSD,0   MAP1              GO MAPPED RETURN
UNMAP    LPSD,0   UNMAP1            GO UNMAPPED RETURN
         B        0,1               EXIT
SPC:MSGS DATA,1   2,X'18',X'23'
         BOUND    4
         PAGE
*
*        REQUIRED EXTERNAL REFERENCES
*
         REF      FGRAN1
         REF      BOOTFLG
         REF      BUF1
         REF      TSTACK
         REF      BUF2
         REF      ERBLOCK
         REF      CURBUF
         REF      CURGRAN
         REF      SGRAN
         REF      BGRAN
         REF      24BM2
         REF      M24
         REF      GBG
         REF      NEWQ
         REF      T:GJOBSTRT
         REF      C:TIC
         REF      C:TINC
         REF      C:MSM
         REF      C:CTUN
         REF      DCT5
         REF      QFREE
*
*        REQUIRED INTERNAL DEFINITIONS
*
         DEF      ERRLOG5
         DEF      ERRLOG40
         DEF      T:SAVE
         DEF      ERRLOG9
         DEF      MAP
         DEF      UNMAP
MAP:     EQU      MAP
UNMAP:   EQU      UNMAP
         DEF      MAP:,UNMAP:
         DEF      ERRLOG
*
         PAGE
*
*        CP-V / RMA ERROR LOGGING DRIVER.
*
*        **CALLING SEQUENCE**
*
*        LI,R6    ERROR LOG MSG ADDRESS (REGS OR MEMORY)
*        BAL,R5   ERRLOG
*
*
*        R6 WILL CONTAIN A FLAG IN BYTE ZERO ON OCCASION AND
*        THE ERROR LOGGER WILL REMEMBER IT IN R0 UNTIL IT
*        EXITS. THE FLAGS AND THEIR MEANINGS ARE:
*
*        X'40'    I/O ROUTINE RUNNING
*        X'20'    ALLYCAT RUNNING (GRAN,GRANSUB OR ALLYCAT)
*        X'10'    TRAP ROUTINE RUNNING
*
*
ERRLOG   EQU      %
         DISABLE
         PUSH     16,R7             PUSH IF NORMAL ENTRY
         LW,R0    R6                GET FLAG PASSED
         AND,R6   M24               MAKE R6 A 24 BIT ADDRS FIELD
         LI,R3    18                MAX LENGTH FROM CORE
         CI,R6    15                CHECK IF MESSAGE IN REG'S
         BG       ERRLOG1           NO, BRANCH
         LI,R3    14                MAX LENGTH FROM REGS
         AI,R6    -6                YES, MSG IS IN STACK
         BLEZ     %+2               BR IF MSG STARTS IN 0-6
         AI,R6    -16               NO, IN 7-15, LOWER IN STACK
         AW,R6    TSTACK            ADR OF MESSAGE IN STACK
ERRLOG1  LI,R1    1                 INDEX TO COUNT FIELD
         LB,R2    *R6,R1            GET COUNT
         CW,R2    R3                MSG SIZE OKAY
         BLE      ERRLOG2           YUP,GO
         LW,R2    R3                RESET TO MAX COUNT
         STB,R2   *R6,R1            DEPENDING ON SWA
ERRLOG2  EQU      %
         LB,R3    *R6               GET ERROR LOG CODE
         LB,R5    SPC:MSGS          GET LENGTH OF SPECIAL ERROR LOG MSGS
         CB,R3    SPC:MSGS,R5       SEE IF UNIQUE ERROR LOG MESSAGE
         BE       ERRLOG20          YEP
         BDR,R5   %-2               FINISH UP
         B        ERRLOG22          NOT A SPECIAL EVENT
ERRLOG20 EQU      %
ERRLOG21 CI,R3    X'18'             IS START-UP MESSAGE
         BNE      ERRLOG22          NOPE
         BAL,R5   ERRLOG80          GET GRANULES AT STARTUP TIME
         DISABLE
         LW,R4    C:MSM             GET MCS SINCE MIDNIGHT
         B        %+2               JUMP TO PLACE TIME
ERRLOG22 BAL,R5   ERRLOG9           GET TIME OF DAY IN 2/MCS TICS
         STW,R4   1,R6              PLACE TIME INTO MESSAGE
         LW,R1    CURBUF            GET CURRENT BUFFER WA
         LW,R3    *M24,R1           GET #WORDS REMAINING IN BUFFER
         BLZ      ERRLOG6           ITS BEEN WRITTEN OUT....
ERRLOG3  CW,R2    R3                WILL MSG FIT IN THIS BUFFER
         BG       ERRLOG6           NO, BRANCH
ERRLOG31 LW,R7    *24BM2,R1         GET NEXT BUFFER ENTRY WA
         STB,R2   R7                SET WORD COUNT
         SLD,R6   2                 SET UP FOR MOVE-BYTE-STRING
         MBS,R6   0                 MOVE INTO PLACE
         SW,R3    R2                SUBTRACT SIZE JUST MOVED IN BUF
         BLEZ     ERRLOG4           NO MORE ROOM
         CI,R3    2                 WILL LOST ENTRY MSG FIT
         BL       ERRLOG4           NOPE
         LI,R9    8                 8 BYTES IN MSG
         LI,R3    0
         XW,R3    ERBLOCK           GET LOST ENTRY COUNTER
         BEZ      ERRLOG4           NOTHING TO DO
         LI,R8    X'1E02'           CODE/COUNT
         STH,R8   R3                SET UP MSG
         BAL,R5   ERRLOG9           GET TIME SINCE MIDNIGHT (MCS RESO.)
         LI,R6    4*R3              BYTE LOC OF THIS MSG
         STB,R9   R7                COUNT OF MSG
         MBS,R6   0                 MOVE LOST ENTRY MSG INTO BUFFER
         AI,R2    2                 BUMP COUNT OF WORDS MOVED
ERRLOG4  EQU      %
         AWM,R2   *24BM2,R1         ADVANCE BUFFER WA POINTER
         AWM,R2   2,R1              ADVANCE **BUFFER** MARKER
         LCW,R2   R2                COMPLEMENT SIZE
         AWM,R2   *M24,R1           DECREMENT SIZE REMAINING
         BAL,R5   ERRLOGD           TEST FOR BUFFER WRITE-OUT
ERRLOG41 EQU      %
         LC       R0                TEST FLAGS
         BCS,1    ERRLOG42          EXIT IF A TRAP ROUTINE RUNNING
         MTW,0    BOOTFLG           ARE WE REALLY UP
         BNEZ     ERRLOG42          NO - DONT CALL THE GHOST
         LD,0     ERRFIL            SET UP
         BAL,10   T:GJOBSTRT        CALL TO WAKE UP THE GHOST
ERRLOG42 EQU      %                 CAME BACK ENABLED
         PULL     16,R7
         B        0,R5              AND EXIT
         PAGE
*
*        'CLOCK4' WILL CALL EVERY 1.2 SECONDS TO ENABLE
*        ERROR LOGGER TO FLUSH ITS BUFFERS.
*
ERRLOG5  PUSH     R5                SAVE RETURN LINK
         BAL,R5   ERRLOG80          SEE IF WE NEED ANY GRANULES
         BAL,R5   ERRLOGD
         PULL     R5                EXTRACT LINK FROM STACK
         B        0,R5              AND GET OUT
         PAGE
*
*        THE ERROR MESSAGE WILL NOT FIT INTO 'CURBUF',QUEUE
*        THE CURRENT BUFFER AND SWITCH TO THE ALTERNATE
*        BUFFER. IF THE ALTERNATE IS FULL AND/OR QUEUED
*        WE'LL HAVE TO SKIP THE ERROR MSG COMPLETELY.
*
ERRLOG6  BAL,R5   ERRLOG91          QUEUE CURRENT BUFFER
         BAL,R7   ERRLOGA           SEE IF OTHER BUFFER AVAIL.
         B        ERRLOG8           DIDNT MAKE IT - BUMP MISSED COUNTER
ERRLOG7  DISABLE                    WE CAME BACK ENABLED
         CW,R2    R3                WILL MESSAGE FIT IN THIS BUFFER
         BLE      ERRLOG31          IT FITS - GO MOVE IT
         BAL,R5   ERRLOG90          NOPE, WRITE IT OUT
ERRLOG8  MTW,1    ERBLOCK           BUMP # RECORDS SKIPPED
         B        ERRLOG41          JUST EXIT
         PAGE
*
*        COLLECT MILLISECONDS SINCE MIDNIGHT INTO R4
*
ERRLOG9  EQU      %
         LW,R4    C:CTUN
         SW,R4    C:TINC
         AW,R4    C:TIC
         AW,R4    C:MSM
         B        0,R5
         PAGE
*
*        WAIT A SHORT SPAN FOR BUFFER TO COME IN
*
ERRLOGA  LI,R4    50
         LW,R1    CURBUF            LOAD BUFFER ADDRESS
ERRLOGB  LW,R3    *M24,R1           CHECK AVAIL SPACE COUNT
         BGZ      1,R7              ITS IN CORE
         LC       R0                IS A TRAP ROUTINE RUNNING
         BCS,1    0,R7              YES, GET OUT
         ENABLE                     NO
         WAIT                       WAIT FOR EVENT TO OCCUR
         BDR,R4   ERRLOGB           CHECK IT ONE MORE TIME
         B        0,R7              HASNT GOT IN YET
         PAGE
*
*        EXAMINE BUF COUNTS TO INSURE EACH HAS
*       ROOM FOR THE MOST COMMON ERROR MSG. IF ROOM
*       ISN'T AVAILABLE, QUEUE THE BUFFER
*
ERRLOGD  EQU      %
         PSW,R5   TSTACK            SAVE THE LINK
         LW,R1    CURBUF            CURRENT BUFFER ADDRESS
         BAL,R5   ERRLOG90          YEP - WRITE IT OUT
         CI,R1    BUF1
         BE       %+2               CALCULATE OTHER BUFFER ADDRESS
         LI,R1    BUF1+BUF1-BUF2
         AI,R1    BUF2-BUF1
         BAL,R5   ERRLOG90          CHECK THE OTHER ONE
         PLW,R5   TSTACK
         B        0,R5              AND GET OUT
         PAGE
*
*
*        END ACTION RECEIVER FOR ALL ERROR LOG
*        WRITING
*
*
ERRLOG40 EQU      %
         DISABLE
         LW,R1    R14               BUFFER ADR
         LI,R2    61                NO. OF WORDS IN BUFFER FOR MESSAGES
         LI,R3    0
         STW,R3   0,R1              ZAP BLINK
         STW,R3   1,R1              ZAP FLINK
         STW,R3   2,R1              SET USED WORD COUNT = 0
         STW,R1   *24BM2,R1         SET NEXT AVAILABLE POINTER
         MTW,3    *24BM2,R1
         STW,R2   *M24,R1           SET AVAIL SPACE = 61
         ENABLE
         B        *R11              EXIT
         PAGE
*
*        ALLOCATE GRANULES FOR THE ERROR LOG SYSTEM
*        FILE VIA A CALL ON 'GBG'. WE ALWAYS KEEP
*        A COUPLE OF EXTRA GRANULES YOU WILL NOTICE.
*
*        IF BIT 2 OF R0 (READ Y2) IS SET
*        IT INDICATES THAT ALLYCAT IS CALLING HERE
*        AND FURTHER INDICATES THAT ERRLOG SHOULD NOT
*        ASK FOR A GRANULE AT THIS TIME.
*
*
ERRLOG80 EQU      %
         LC       R0                TEST FLAGS
         BCS,3    0,R5              EXIT IF ALLYCAT IS CALLING
         LI,R4    CURGRAN           FIRST ONE TO CHECK
         LI,R3    4                 LOOP COUNT
         PUSH     2,R0              SAVE FLAG
ERRLOG81 LI,R0    X'70B'            PACK THEN RAD GRANULES
         MTW,0    0,R4              NEED ONE HERE
         BNEZ     ERRLOG82          GOT ONE IN THIS SLOT
         BAL,R11  GBG               GET BACKGROUND GRANULE
         STW,R8   0,R4              SAVE IT (OR A ZERO)
ERRLOG82 AI,R4    1                 STEP TO NEXT ONE
         BDR,R3   ERRLOG81          FINISH UP
         PULL     2,R0              RESTORE FLAG CELL
         B        0,R5              AND EXIT
         PAGE
*
*        QUEUE THE BUFFER POINTED BY R1, THE BUFFER HEADER
*        INFO IS OBTAINED FROM THE TABLES THAT PRECEDE
*        IT IN THE MODULE 'TABLES'.
*
*
ERRLOG90 EQU      %
         DISABLE
         LW,R4    2,R1              GET WORD CNT ASSOCIATED
         CI,R4    48                HAVE USED 2/3 OF BUFFER
         BL       0,R5              NOPE - NOT YET - WAIT
ERRLOG91 EQU      %                 ALTERNATIVE ENTRY TO QUEUE BUFFER
         LW,R8    R1                CURRENT BUFFER WA
         CI,R8    BUF1              NOW DOING BUFFER 1
         BE       %+2               YEP
         LI,R8    BUF1+BUF1-BUF2    NO - ON BUFFER 2
         AI,R8    BUF2-BUF1         MAKE R8 POINT TO NEXT ONE
         STW,R8   CURBUF            LEAVE NEW BUFFER POINTER SET
         LC       0                 GET FLAG
         BCS,1    0,R5              JUST GET OUT NOW...
         LW,R8    *M24,R1           GET I/O PENDING FLAG
         BLZ      0,R5              ITS ALREADY WRITTEN OUT
         PUSH     8,R0              SAVE REGS OF NECESSARY INFO
         LW,R13   R1                BUFFER ADDRESS
         SLS,R13  2                 BYTE ADDRESS
         LI,R14   64*4              BUFFER SIZE
ERRLOG92 MTW,0    FGRAN1            MUST HAVE A FORWARD LINK
         BEZ      ERRLOG94          HAVE TO DEFER THE WRITE-OUT
         LW,R15   CURGRAN           DISC ADDRESS OF CURRENT GRANULE
         BEZ      ERRLOG95          GO GET A NEW GRANULE
         MTW,0    SGRAN             IS THIS FIRST GRAN EVER
         BNEZ     %+2               NO, SKIP
         STW,R15  SGRAN             YEP, SET STARTING DISK ADDR.
         LDCTX,R12 R15              GET DCT INDEX WE GONNA WRITE TO
         LW,R2    R12               MOVE IT TO R2 FOR INDEXING
         LC       DCT5,R2           CHECK FOR CLEANUP PENDING/IN PROGRESS
         BCS,4    ERRLOG94          GET OUT - OUR DEVICE IS IN CLEANUP
         LB,R2    QFREE             NOT IN CLEANUP - R THERE ANY Q'S
         BEZ      ERRLOG94          NOPE - DEFER WRITE OUT TILL LATER
ERRLOG93 LI,R0    ERRLOG40          SET END ACTION ADDRESS
         LI,R10   0
         LCI      5                 GET
         LM,R5    BGRAN             AND
         STM,R6   BGRAN             MOVE BACK NEW GRANULES
         AW,R12   MISC              PUT TOGETHER PRI/FC..ETC
         LI,R10   -1                NOW SET I/O FLAG
         STW,R10  *M24,R1           FOR THE RESET OF ERRLOG TO LOOK AT
         STW,R5   0,R1              SET BUFFER BLINK
         STW,R7   1,R1              SET BUFFER FLINK
         BAL,R11  NEWQ              CALL IOQ TO WRITE OUT THEBUFFER
         NOP                        IGNORE ERROR RETURN
ERRLOG94 EQU      %
         PULL     8,R0              RESTORE EXTERNAL INFO
         B        0,R5              EXIT TO CALLER
         PAGE
*
*        'CURGRAN' WAS ZERO,INDICATING WE MISSED GETTING
*        A GRANULE EARLIER IN THE GAME,SHUFFLE THE  DISC
*        ADDRESSES BACK AND TRY AGAIN
*
ERRLOG95 EQU      %
         BAL,R5   ERRLOG80          GO EXAMINE TABLES FOR A GRANULE
         DISABLE                    CAME BACK ENABLED..
         LCI      4                 MOVE EM
         LM,R4    FGRAN1            BACK ONE POSITION
         STM,R4   CURGRAN           THERE....
         B        ERRLOG92
*
*        NOTE: IF THE I/O EVENT IS ABORTED DUE TO THE
*        LACK OF A DISC ADDRESS, THE BUFFER HAS STILL BEEN
*        MARKED AS FULL AND WILL NOT BE USED UNTIL IT HAS
*        BEEN WRITTEN. EACH TIME THE ERROR LOGGER IS
*        CALLED AN ATTEMPT IS MADE TO GET DISC ADDRESSES IF
*        NECESSARY, GUARANTEED TO PRODUCE A WRITE-OUT AT A LATER
*        TIME, WHICH IS OBVIOUSLY ALL THAT CAN HAPPEN.
*
ERHNDLRSZ EQU     %-ERHNDLR:
         END

