*M*      ERHNDLR                  MODULE TO CONTAIN ERROR LOGGING
*M*                               INTERFACE PLUS MAP/UNMAP ROUTINES.
*P*
*P*      THIS MODULE CONTAINS THE ROOT PORTION OF THE CP-V
*P*      ERROR LOGGING ROUTINES.
*P*
*P*      THE FOLLOWING ENTRY POINTS ARE HEREIN;
*P*
*P*      ROUTINE                  DESCRIPTION
*P*      -------------            -------------------------------
*P*
*P*      ERRLOG                   ENTRY TO PUT ERROR LOG MSG IN BUFFER
*P*      ERRLOG40                 ERROR LOG END ACTION ROUTINE
*P*      ERRLOG5                  CLOCK4 ENTRY ROUTINE
*P*      MAP                      GOES MAPPED / INT'S ENABLED
*P*      MAP:                     XDELTA'S FORM OF MAP
*P*      UNMAP                    GOES UNMAPPED / INT'S ENABLED
*P*      UNMAP:                   XDELTA'S FORM OF UNMAP
*P*      T:SAVE                   SAVE ENVIRONMENT IN TSTACK
*P*      TQMAP                    GOES MAPPED / INT'S STAY SAME
*P*      TQRETURN                 EXIT FROM MAP/UNMAP/TQMAP/TQUNMAP
*P*      TQUNMAP                  GOES UNMAPPED / INT'S STAY SAME
*P*
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
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
*
*                 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'01B00A00'       FUNCTION CODE = 01 ;
*                                   I/O PRIORITY  = B0 ;
*                                   RETRY COUNT   = 0A
*                                   DCT SET BY ERRLOG91 AT I/O TIME.
         PAGE
*F*
*F*      NAME:    T:SAVE
*F*
*F*      PURPOSE:
*F*               TO STORE REGISTERS R3 THRU R15 IN THE TEMP STACK -
*F*               AND STORE THE PSD BENEATH ALL OF THE REGISTERS
*F*               THEREBYE CREATING THE 'ENVIRONMENT' PUSH.
*F*
*F*      DESCRIPTION:
*F*               YOU MUST HAVE ALREADY PUSHED 6 WORDS STORING
*F*               FOR THE PSD AND STORING R0 THRU R2. BAL HERE
*F*               VIA R2 WITH THE PSD IN R0/R1 AND T:SAVE WILL
*F*               COMPLETE THE ENVIRONMENT PUSH.
*F*
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
         PAGE
*
*F*      NAME:    MAP / UNMAP
*F*
*F*      PURPOSE:
*F*               ROUTINES TO MAP/UNMAP AND ENABLE IN BOTH CASES.
*F*
*F*      DESCRIPTION:
*F*               BAL HERE VIA R1 AND THESE ROUTINES WIL PLACE
*F*               THE CPU IN EITHER THE MAP/UNMAP STATE WITH
*F*               INTERRUPTS ENABLED.
*F*
MAP      LPSD,0   MAP1              GO MAPPED RETURN
UNMAP    LPSD,0   UNMAP1            GO UNMAPPED RETURN
TQRETURN EQU      %               **EXIT POINT FOR ALL OF THEM
         B        0,1               EXIT
         PAGE
*F*
*F*      NAME:    TQMAP / TQUNMAP
*F*
*F*      PURPOSE:
*F*               ROUTINES TO MAP/UNMAP AND PRESERVE STATE OF
*F*               THE INTERRUPT SYSTEM.
*F*
*F*      DESCRIPTION:
*F*               BAL TO EITHER VIA R1 AND THEY WILL GO
*F*               MAPPED/UNMAPPED AND RETURN TO YOU VIA R1.
*F*
*F*
*F*               NOTE THAT THESE TWO ROUTINES KEEP INT'S AS THEY
*F*               WERE.
*F*
TQMAP    EQU      %
         XPSD,0   TQVPSD            VIRTUAL
TQUNMAP  EQU      %
         XPSD,0   TQRPSD            REAL
         PAGE
*
*        REQUIRED EXTERNAL REFERENCES
*
         REF      BGRAN           * 'LAST' GRANULE USED
         REF      BOOTFLG         * INDICATES IF SYSTEM UP SLOT
         REF      BUFMSIZ         * MAX USEFUL SPACE IN BUFFER
         REF      BUFTSIZ         * MAX TOTAL SPACE IN BUFFER
         REF      BUF1            * FIRST ERROR LOG BUFFER ADDRS
         REF      BUF2            * SECOND ERROR LOGGING BUFFER
         REF      C:CTUN          *
         REF      C:MSM           * MILS SINCE MIDNIGHT SLOT
         REF      C:TINC          *
         REF      CURBUF          * 'CURRENT' BUFFER POINTER
         REF      CURGRAN         * 'CURRENT' GRANULE IN USE
         REF      DCT5            * DEVICE FLAGS BYTE TABLE
         REF      DOUBLEONE       * DBL-WORD OF 1,1
         REF      DOUBLEZERO        * DOUBLE WORD OF ZERO-ZERO
         REF      ERBLOCK         * INDICATES IF ERROR LOGGER BUSY
         REF      ERINPROG        * NONE-ZERO SAYS RECORDING TOOK PLACE
         REF      ERRCOUNT        * ERROR LOG 'BLOCK' CELL
         REF      FGRAN1          * FIRST AVAIL DISC IN TABLES
         REF      GBG             * GET PUBLIC FILE GRANULE
         REF      M24             * DATA X'00FFFFFF'
         REF      M8              * DATA X'000000FF'
         REF      NEWQ            * MONITOR I/O ENTRY POINT
         REF      QFREE           * HEAD OF FREE IOQ CHAIN SLOT
         REF      SGRAN           * 'NEXT' GRANULE TO USE
         REF      T:GJOBSTRT      * START GHOST JOB ENTRY POINT
         REF      TQRPSD          * XPSD TO UNMAP W/INTS PRESERVED
         REF      TQVPSD          * XPSD TO MAP W/INTS PRESERVED
         REF      TSTACK          * PUSH DOWN STACK FOR MONITOR
         REF      Y4              * DATA OF X'40000000'
         PAGE
*
*        EXTERNAL DEFINITIONS
*
         DEF      ERHNDLR:        * FOR XDELTA PURPOSES
         DEF      ERRLOG          * ERROR LOGGING ENTRY POINT
         DEF      ERRLOG40        * END ACTION I/O ROUTINE
         DEF      ERRLOG5         * DEF FOR CLOCK4 TO ENTER
         DEF      ERRLOG9         * COLLECT TIME ENTRY POINT
         DEF      MAP             * GO 'MAPPED' ROUUTINE
         DEF      MAP:            * FOR XDELTA TO GET
         DEF      T:SAVE          * SAVE ENVIRONMENT ROUTINE
         DEF      TQMAP           *
         DEF      TQRETURN        * RETURN FROM XPSD'S TQMAP/TQUNMAP
         DEF      TQUNMAP         *
         DEF      UNMAP           * GO 'UNMAP'  ROUTINE
         DEF      UNMAP:          * FOR XDELTA TO GET
*
*
MAP:     EQU      MAP
*
UNMAP:   EQU      UNMAP
*
         PAGE
*F*
*F*      NAME:
*F*               ERRLOG
*F*
*F*      PURPOSE:
*F*               ENTRY POINT TO RECORD ERROR LOG RECORD
*F*
*F*      DESCRIPTION:
*F*               BAL HERE VIA R5 WITH R6 POINTING TO ERROR LOG
*F*               MSG (IN REGS OR MEMORY).
*F*
*F*               THE ERROR LOG MSG WILL BE INSERTED INTO THE BUFFERS
*F*               IF ROOM IS AVAIL. AT EXIT 'ERR:FIL' WILL BE
*F*               AWAKENED TO MOVE THE MESSAGE TO THE PUBLIC FILE.
*F*
ERRLOG   EQU      %
         DISABLE
         MTW,0    ERRCOUNT          ARE WE ABOUT TO RE-ENTER
         BNEZ     ERRLOG8           YEP - NO GOOD
         STW,R5   ERRCOUNT          SAVE RETURN LINK-BLOCK RE-ENTER
         PUSH     16,R7             SAVE WORK SPACE
         LC       R6                TEST CALLER'S FLAGS
         BCS,1    %+2               TRAP HANDLER CALLING
         ENABLE                     ANYBODY ELSE ITS OK TO RUN ENABLED
         AND,R6   M24               CLEAR FLAGS -THEY ARE IN THE STACK
         CI,R6    X'1FFF0'          IS MSG IN REGISTERS
         BANZ     ERRLOG1           NOPE
         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  EQU      %
         LH,R2    *R6               GET CODE/COUNT FIELDS
         AND,R2   M8                EXTRACT COUNT ONLY
         CI,R2    18                AT MAX COUNT
         BLE      ERRLOG2           IS OKAY
         LI,R2    18                ELSE RESTRICT TO MAX COUNT
ERRLOG2  EQU      %
         BAL,R5   ERRLOG9           GET MCS/2 SINCE MIDNIGHT
         STW,R4   1,R6              PLACE TIME INTO MESSAGE
         BAL,R5   ERRLOGE           GET BUF ADDRS AND MAKE SIZE TEST
         B        ERRLOG6           MSG WONT FIT
*
*        NOTE:    R2 CONTAINS MESSAGE SIZE
*                 R4 WILL CONTAIN TIME IN MCS/2 COUNTS
*                 R7 IS GOING TO POINT TO BUFFER WA TO MOVE MSG
*
ERRLOG31 EQU      %
         MTW,1    ERINPROG          INDICATE TO CLOCK ROUTINE WE'RE ;
*                                   RECORDING ERROR MESSAGES
         LW,R9    0,R6            * GET WORD
         STW,R9   0,R7             * MOVE TO BUF
         AD,R6    DOUBLEONE         * INCREMENT BUF ADDRESSES
         BDR,R2   %-3                * FINISH MOVE
         LI,R2    2                 LOAD COUNT FOR MISSED MSG
         BAL,R5   ERRLOGF           SEE IF ROOM IN BUFFER
         B        ERRLOG4           NO - CANT MOVE 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
         STW,R3   0,R7              STORE MSG HEADER
         STW,R4   1,R7              STORE TIME INTO MESSAGE
         AI,R7    2                 BOOST BUF TOP WA BY COUNT MOVED
ERRLOG4  EQU      %                 COME HERE IF NO MISSED MSG TO MOVE
         STW,R7   *M24,R1           STORE NEW TOP BUFFER WA
ERRLOG41 EQU      %
         PULL     16,R7
ERRLOG42 EQU      %
         LI,R5    0               * SETUP TO CLEAR
         XW,R5    ERRCOUNT        * RE-ENTRANT FLAG/GET LINK
         B        0,R5            * EXIT TO CALLER
         PAGE
*F*
*F*      NAME:    ERRLOG6
*F*
*F*      PURPOSE:
*F*               TO FIGURE OUT WHAT TO DO SINCE THE CURRENT MSG
*F*               WONT FIT INTO THE CURRENT BUFFER.
*F*
*F*      DESCRIPTION:
*F*               WE GET HERE BY DISCOVERING THAT THE MSG WONT FIT
*F*               INTO THE CURRENT BUFFER.
*F*
*F*               WE WILL WRITE OUT THE CURRENT BUFFER - AND THEN WE
*F*               WILL TEST IF THE MSG WILL FIT IN THE OTHER BUF.
*F*
*F*               IF THE MSG FITS IN THE ALTERNATE BUF - WE GO AHEAD
*F*               AND MOVE IT THERE.
*F*
*F*               IF IT WONT FIT IN THAT ONE EITHER - WE'LL HAVE TO
*F*               SKIP THE WHOLE THING.
*F*
ERRLOG6  EQU      %
         STB,R2   R6                SAVE COUNT IN SOURCE WA REGISTER
         BAL,R5   ERRLOG91          WRITE OUT THE CURRENT BUFFER
         LB,R2    R6                RESTORE COUNT
         BAL,R5   ERRLOGE           SEE IF MSG FITS IN ALT BUFFER
         B        ERRLOG7           MSG DOESNT FIT ALT - EXIT TO CALLER
*
         AND,R6   M24               MSG FITS - SCRUB R6 WHERE CNT SAT
         B        ERRLOG31          MERGE TO MOVE MSG TO ALT BUF
*
*
ERRLOG7  EQU      %
         BAL,R5   ERRLOG91          IF IT DOESNT FIT ALT-WRITE ALT OUT
         LI,R5    ERRLOG41          LOAD INTERNAL ADDRESS LINK
ERRLOG8  EQU      %
         MTW,1    ERBLOCK           BUMP 'MISSED' COUNTER
         B        0,R5              GO TO EXTERNAL CALLER/OR EXIT
         PAGE
*F*
*F*      NAME:    ERRLOG9
*F*
*F*      PURPOSE:
*F*               TO CALCULATE MILLISECONDS SINCE MIDNIGHT.
*F*
*F*      DESCRIPTION:
*F*               COUNTERS ARE ACCUMULATED TO PRODUCE THE COUNT
*F*               OF MILS SINCE MIDNIGHT.
*F*
*F*               NOTE THAT 'ERR:FIL' UTILIZES THIS ROUTINE ALSO.
*F*
*
ERRLOG9  EQU      %
         LW,R4    C:CTUN
         SW,R4    C:TINC
         AW,R4    C:MSM
         B        0,R5
         PAGE
*
*        LOAD CURRENT BUFFER ADDRESS AND MAKE SIZE TEST
*
*        THE SIZE OF THE CURRENT MSG TO GO INTO THE BUF IS IN R2
*
*        RETURN TO BAL+1 IF MSG WILL NOT FIT
*
*        RETURN TO BAL+2 IF MSG WILL FIT
*
ERRLOGE  EQU      %
         LW,R1    CURBUF          LOAD 'CURRENT' BUF ADDRS
         INT,R7   *M24,R1           GET NEXT AVAIL WA / TEST IO FLAG
         BCS,4    0,R5              BUFFER BEING WRITTEN OUT
ERRLOGF  EQU      %                 COME HERE IF R7 ALREADY LOADED
         LI,R3    BUFMSIZ           MAX USEFUL SPACE IN BUFFER
         AW,R3    R1                ADD BUFFER WA
         SW,R3    R7                CALCULATE ROOM REMAINING IN BUFFER
         CW,R2    R3                WILL MSG FIT IN THIS BUFFER
         BG       0,R5              NOPE
         B        1,R5              YES - RETURN POINTERS TO CALLER
         PAGE
*F*
*F*      NAME:    ERRLOG40
*F*
*F*      PURPOSE:
*F*               SERVES AS END ACTION ROUTINE FOR ALL ERROR LOG
*F*               BUFFER WRITING.
*F*
*F*      DESCRIPTION:
*F*               THIS ROUTINE IS CALLED WHENEVER I/O HAS BEEN
*F*               COMPLETED - IT WILL RESET THE BUFFER BUSY FLAG
*F*               AND MAKE THE BUFFER AVAIL AGAIN.
*F*
*
ERRLOG40 EQU      %
         DISABLE
         LW,R1    M24               24 BIT MINUS ONE CELL
         STW,R14  *R14,R1           STORE NEW BUF 'NEXT' WA
         MTW,3    *R14,R1           POINT TO FIRST AVAIL WORD IN BUF
         LCFI     2
         LM,R0    DOUBLEZERO        GET SOME ZEROS
         STM,R0   *R14              AND CLEAR BLINK/FLINK FIELDS
         ENABLE
         B        *R11              EXIT
         PAGE
*F*
*F*      NAME:
*F*               ERRLOG5
*F*
*F*      PURPOSE:
*F*               SERVES AS TIME-BASED ENTRY FROM CLOCK4 TO KEEP
*F*               SUFFICIENT GRANULES ON HAND TO WRITE BUFFERS.
*F*
*F*      DESCRIPTION:
*F*               CLOCK4 CALLS HERE EVERY SECOND.
*F*
ERRLOG5  EQU      %
ERRLOG80 EQU      %
         DISABLE
         MTW,0    ERRCOUNT          IS FRONT END RUNNING
         BNEZ     0,R5              YUP--RETURN TO CLOCK4
         STW,R5   ERRCOUNT          NO---PREVENT IT FROM DOING SO
         ENABLE
         LI,R4    CURGRAN           FIRST ONE TO CHECK
         LI,R3    4                 LOOP COUNT
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
         LI,R0    0                 LETS CHECK TO SEE IF
         STW,R0   ERRCOUNT          UNLOCK FRONT-END
         XW,R0    ERINPROG          FRONT-END HAS BEEN LOGGIN
         BEZ      0,R5              NOPE-RETURN TO CLOCK4
         LD,R0    ERRFIL            YUP - LOAD GHOST NAME
         LW,R10   R5                MOVE  LINK
         B        T:GJOBSTRT        AND START UP GHOST JOB
         PAGE
*F*
*F*      NAME:
*F*               ERRLOG91
*F*
*F*      PURPOSE:
*F*               TO WRITE OUT THE BUFFER POINTED TO BY R1.
*F*
*F*      DESCRIPTION:
*F*               THE BUFFER MANAGEMENT ROUTINE HAS TRIED
*F*               TO MOVE A MESSAGE INTO THE BUFFER POINTED  TO BY R1
*F*               AND IT WOULD NOT FIT. THIS ROUTINE WILL SWITCH THE
*F*               'CURRENT' BUFFER POINTER (CURBUF) TO THE ALT
*F*               AND WRITE OUT THE CURRENT BUFFER.
*F*
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       *TSTACK           TEST CALLER'S FLAGS
         BCS,11   0,R5              ITS ALLYCAT OR A TRAP HANDLER
*
*        NOTE:    DO NOT DO I/O IF A TRAP HANDLER OR ALLYCAT
*                 OR IOINT IS CALLING.
*
         INT,R8   *M24,R1           TEST FOR IO IN PROGRESS FLAG
         BCS,4    0,R5              BUFFER BEING WRITTEN - EXIT NOW
         PUSH     2,R5              SAVE LINK / MESSAGE ADDRS IN R6
         LW,R13   R1                BUFFER ADDRESS
         SLS,R13  2                 BYTE ADDRESS
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      ERRLOG94          **NONE; DEFER BUFFER WRITE
         MTB,0    QFREE             ANY QUEUE ENTRIES AVAILABLE
         BEZ      ERRLOG94          **NONE; DEFER BUFFER WRITE
         DISABLE                    GOT ONE -- HOLD IT
         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
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
         OR,R12   MISC              INSERT I/O PRI/FUNCTION/RETRY COUNT
         STW,R5   0,R1              SET BUFFER BLINK
         STW,R7   1,R1              SET BUFFER FLINK
         LW,R14   *M24,R1           GET NEXT AVAIL WA IN BUFFER
         SW,R14   R1                CALCULATE NUMBER OF WORDS USED
         STW,R14  2,R1              STORE THEM IN THE BUF HEADER
         OR,R14   Y4                SET IN BUF BUSY BIT
         STW,R14  *M24,R1           AND STORE BUSY BIT IN TABLES
         SLS,R14  2                 SHIFT TO PRODUCE BYTE COUNT
         BAL,R11  NEWQ              CALL IOQ TO WRITE OUT THEBUFFER
         NOP                        IGNORE ERROR RETURN
ERRLOG94 EQU      %
         LD,R0    ERRFIL            NAME OF GHOST
         BAL,R10  T:GJOBSTRT        START UP ERR:FIL AGAIN
         PULL     2,R5              RESTORE LINK / MSG ADDRESS IN R6
         B        0,R5              EXIT TO CALLER
ERHNDLRSZ EQU     %-ERHNDLR:
         END

