         PCC      0
         SYSTEM   SIG7
         TITLE    'LEMUR5 -- ERROR HANDLING FOR LEMUR'
         SPACE    3
*M* LEMUR5  OVERLAY PORTION OF ERROR HANDLING ROUTINES.
         SPACE    2
*P*****************************************************************
*P*
*P* NAME:  LEMUR5
*P*      OVERLAY SECTION OF ERROR HANDLER.
*P*
*P* DESCRIPTION:
*P*      WHEN AN ERROR IS DETECTED, A BRANCH IS MADE TO THE
*P*      OVERLAY ERROR HANDLER'S ENTRY POINT, ERR#.  R1 SHOULD
*P*      CONTAIN THE ERROR CODE INDEX FOR THE ERROR WHICH WAS DETECTED.
*P*      THUS, IF YOU WANT TO REPORT E#XXX WITHOUT DOING A BRANCH
*P*      TO ERRENT+E#XXX, YOU SHOULD LOAD R1 WITH E#XXX, AND THEN
*P*      BRANCH TO ERR:+1.
*P*      (IF YOU ARE COMING FROM THE ROOT, IT'S PROBABLY JUST
*P*      AS EASY TO BRANCH DIRECTLY TO ERR#.
*P*
*P* AUTHOR:
*P*      TERRY MOORE, XEROX CORP.   JULY 21, 1975
*P*
*P*****************************************************************
         TITLE    'LEMUR5 -- REFS & DEFS'
         SPACE
***********************************************************************
*
* ----- R E F S   &   D E F S -----
*
*  1.    ROUTINES DEFINED IN THIS MODULE:
*
         SPACE
         DEF      ERR#              RTN:   ENTRY TO ERROR HANDLING.
         SPACE    3
*
*  2.    ROUTINES DEFINED IN OTHER MODULES:
*
         SPACE
         REF      RDERRFL           RTN:   READ MESSAGE FROM ERROR FILE
         REF      WRITEDO           RTN:   WRITE DIAGNOSTIC MESSAGE
         REF      WRITELL           RTN:   WRITE LISTING LOG.
         REF      EXTOPT            RTN:   GET OPTION VALUE.
         REF      WINDOWN           RTN:   TERMINATE EXECUTION.
         REF      RESTART           RTN:   RESTART LEMUR.
         PAGE
         SPACE
*
*  3.    DYNAMIC DATA
*
         REF      INBUF             BUFFER:
*,*                                        USED TO READ IN ERROR MSG.
*,*                                        FROM ERRMSG.:SYS
         REF      DO#LL             FLAG:  BITS 2-3 ON MEAN THAT M:DO IS
*,*                                        DIFFERENT THAN M:LL
         REF      C%OPTS            DWD:   OPTION BITS.
         REF      ERRHIT            CELL:  # OF ERRORS ENCOUNTERED.
         PAGE
         SPACE
*
*  4.    STATIC OPTION DATA CELLS:
*
         SPACE
         REF      O%ERR             IF ON, ABORT AT EXIT.
         REF      O%X               IF ON, ABORT WHEN ERROR DETECTED
         PAGE
         SPACE
*
*  5.     DATA FROM 'LITERALS':
*
         SPACE
         REF      Y03               X'03000000'
         SPACE    3
*
*  6.    MONITOR-DEFINED CELLS:
*
         SPACE
         REF      J:TCB             POINTER TO LEMUR'S TCB TEMP STACK.
         SPACE    3
*
*  7.    EXTERNALLY-DEFINED CONSTANT SYMBOLS:
*
         SPACE
         REF      #IO               LEMUR I/O ERROR GROUP CODE.
         SPACE    3
*
*  8.    EXTERNALLY-DEFINED STATIC DATA  (NOT FROM 'LITERALS'):
*
         SPACE
         REF      GRPCODE           CELL:  LEMUR'S GROUP CODE, Y03.
         TITLE    'LEMUR5 -- MISCELLANEOUS DEFINITIONS'
         SPACE
***************************************************************
*
* REGISTER DEFINITIONS
*
I1       EQU      1
I2       EQU      2
I3       EQU      3
T0       EQU      4
T1       EQU      5
T2       EQU      6
T3       EQU      7
R0       EQU      8
R1       EQU      9
R2       EQU      10
R3       EQU      11
A0       EQU      12
A1       EQU      13
A2       EQU      14
A3       EQU      15
RTN      EQU      A3
*
* I AGREE, THEY ARE RATHER NON-STANDARD.
*
***************************************************************
         PAGE
         SPACE
*************************************************************
*
* CONTROL SECTIONS --
*
         SPACE
CODE     CSECT    1
STRINGS  CSECT    1
         USECT    CODE
         PAGE
         SPACE
***************************************************************
*
*  TYPES OF OBJECTS IN SCTBL--
*
* NAME            VALUE             MEANING                DESCRIPTORS
* ----            -----             -------                -----------
         SPACE
T%MNAME  EQU      1                 MODULE NAME            1
T%GRP    EQU      2                 GROUP NAME             1
T%DNAME  EQU      3                 SYMBOL (DEF)           1
T%LID    EQU      4                 LIBRARY NAME (N).A.P   3
T%FID    EQU      5                 FILE NAME N(.(A)(.P))  3
T%DEF    EQU      6                 DEF W/ MNAME DEF>>M    2
T%EOL    EQU      7                 END OF LINE
T%GRNCH  EQU      8                 N(.(A)(.P))<GNAM>/MNAM 5
T%UN     EQU      9                 + (UNION OP)           0
T%INT    EQU      10                - (INTERSECTION)       0
T%EQ     EQU      11                = (REPLACEMENT)        0
T%ON     EQU      12                'ON'/'TO'              0
T%OVER   EQU      13                'OVER'                 0
T%USING  EQU      14                'USING'                0
         TITLE    'LEMUR5 -- MACROS'
         SPACE
***************************************************************
*
*  MISCELLANEOUS MACROS--
*
*        CALL     ROUTINE
*                 EMITS A STANDARD (BAL,RTN) CALL TO AF(1)
*
CALL     S:SIN,1  X'6AF'
         SPACE
*
*
* SUBROUTINE:
*        GENERATES A 'PSW,15 *J:TCB'
*
SUBROUTINE ;
         CNAME
         PROC
LF       EQU,0    %
         PSW,RTN  *J:TCB
         PEND
         PAGE
         SPACE
*
*        PUSH     R                 PUSHES REGISTER 'R' ONTO TEMP STACK IN TCB
*        POP      R                 POPS TCB STACK INTO REGISTER R
*        PUSH     R1,R2             PUSHES REGISTERS R1 THROUGH R2 ON
*                                   TCB TEMP STACK
*        POP      R1,R2             POPS REGISTERS R1 THROUGH R2 FROM
*                                   TCB TEMP STACK
*
         SPACE
PUSH     CNAME    1
POP      CNAME    0
         PROC
LF       EQU,0    %
         LOCAL    I
         DO       NUM(AF)>1
I        SET      ((AF(2)-AF(1))+17)&X'F'
         DO1      I=1
I        SET      0
         LCI      I
         ELSE                       JUST A SIMPLE PSW,OR PLW, PLEASE.
I        SET      1                 PUSHING 1 WORD.
         FIN
         GEN,1,5,1,1,4,3,17 1,2,I~=1,NAME,AF(1),0,J:TCB
         PEND
         PAGE
         SPACE
*
*  D(STRING)
*        RETURNS AS ITS VALUE THE DESCRIPTOR OF ITS ARGUMENT
D        FNAME    0
D        CNAME    1
         PROC
         LOCAL    HERE,I
HERE     EQU      %
         USECT    STRINGS
I        TEXT     AF
         USECT    HERE
         DO1      NAME
LF       GEN,8,5,19  S:NUMC(AF),0,BA(I)
         PEND     (S:NUMC(AF)**24)+BA(I)
         SPACE
*
*  E(ERROR NUMBER)
*        RETURNS AS ITS VALUE THE ADDRESS TO BRANCH TO FOR
*        THAT ERROR CODE.
*
E        FNAME
         PROC
         PEND     AF
         TITLE    'LEMUR5 -- ERR# -- RUN-TIME ERROR HANDLER'
         SPACE
***********************************************************************
*
*   NAME:
*        ERR#     HANDLES RUNTIME ERRORS REPORTED BY LEMUR.
*
*   ON ENTRY, ERR# EXPECTS THE FOLLOWING:
*
*        I1:  BITS 16-23 = ERROR CODE,  24-31 = SUBCODE.
*
*   IT PRINTS AN APPROPRIATE MESSAGE, THEN FOR NON-FATAL ERRORS
*   BRANCHES TO 'RESTART'.  IF THE 'X' OPTION WAS SPECIFIED, OR
*   IF A FATAL I/O ERROR WAS ISSUED, THEN AN EXIT IS MADE TO
*   'WINDOWN' WITH THE 'ERR' OPTION SPECIFIED, THUS FORCING AN
*   ABORT CAL.
*
*   IF THE ERROR CODE WAS #IO, THEN THE PROPER MESSAGE IS READ
*   FROM THE ERROR FILE ACCORDING TO REGISTER 10 (R2).
*
*   ERROR MESSAGES ARE ALWAYS SENT TO M:DO;  IF M:LL DIFFERS, THEN
*   A COPY IS SENT THERE, TOO.
*
*   IF 'F%ERRMSG' WAS 1 AT ASSEMBLY TIME, THEN WE READ THE ERROR
*   MESSAGE FROM ERRMSG.:SYS;  OTHERWISE, ERROR MESSAGES ARE GENERATED
*   INLINE.
*
***********************************************************************
         PAGE
         SPACE
F%ERRMSG EQU      0                 GENERATE MESSAGES INLINE.
         SPACE    2
ERR#     PUSH     R2                SAVE POSSIBLE I/O ERROR CODE.
         MTW,+1   ERRHIT            BUMP # OF ERRORS SEEN.
         SPACE
         DO       F%ERRMSG=1        (REDUNDANT BUT CLEAR)
         SPACE
*** READ MESSAGE FROM FILE;  PUT DESCRIPTOR IN A2.
         LW,A1    I1                GET COPY OF ERROR CODE,
         AW,A1    GRPCODE           MAKE A KEY,
         LI,A2    +BA(INBUF)        GET DESTINATION.
         CALL     RDERRFL           AND GET THE RECORD.
         ELSE
         SPACE
*** READ MESSAGE FROM INLINE; PUT DESCRIPTOR IN A2.
*** KLUDGINESS INCARNATE.
         LW,I2    I1                GET COPY OF CODE/SUBCODE;
         SLD,I2   -8                EXTRACT CODE INTO I2,
         LB,I3    I3                SUBCODE INTO I3.
         EXU      PTRTBL,I2         GET DESCRIPTOR OF MESSAGE INTO A2.
         SPACE
*** MESSAGES:
         CSECT    1                 HANDY, OUT-OF-THE-WAY PLACE.
PTRTBL   EQU,0    %
         LW,A2    SYNE,I3           GET SYNTAX ERROR MESSAGES.
         LW,A2    SEME,I3           GET SEMANTICS ERROR MESSAGES.
         LW,A2    ROME,I3           GET ROM LANGUAGE ERRORS.
         LW,A2    COME,I3           GET COMMAND ERRORS.
         LW,A2    IOE,I3            GET I/O ERROR MESSAGES.
         LW,A2    LIBE,I3           GET LIBRARY FORMAT ERROR MESSAGES.
         SPACE
*** MESSAGES:
SYNE     D        '*** ACCOUNT NAME TOO LONG'
         D        '*** BAD FILE I.D.'
         D        '*** BAD QUOTE STRING'
         D        '*** GARBAGE AT END OF LINE'
         D        '*** EH?'
         D        '*** FILE NAME TOO LONG'
         D        '*** LIBRARY NAME TOO LONG'
         D        '*** MISSING FILE NAME'
         D        '*** MALFORMED OPTION'
         D        '*** LIBRARY NAME MISSING'
         D        '*** ILLEGAL CONTINUATION LINE'
         D        '*** ")" MISSING AFTER OPTION'
         D        '*** MODULE NAME MISSING'
         D        '*** PASSWORD TOO LONG'
         D        '*** COMMAND TOO LONG'
***
SEME     EQU,0    %
         D        '*** ILLEGAL OPTION FOR THIS COMMAND'
         D        '*** YOU USED THE SAME OPTION TWICE'
         D        '*** UNKNOWN COMMAND'
         D        '*** UNKNOWN OPTION'
***
ROME     EQU,0    %
         D        '*** ILLEGAL ROM RECORD LENGTH'
         D        '*** ILLEGAL ROM RECORD HEADER'
         D        '*** ILLEGAL ROM LANGUAGE'
         D        '*** MAXIMUM SEVERITY LEVEL EXCEEDED'
         D        '*** UNEXPECTED END OF ROM'
***
COME     EQU,0    %
         D        '*** MODULE ALREADY EXISTS'
         D        '*** NOT ENOUGH SYMBOL SPACE'
         D        '*** NOT ENOUGH CORE'
         D        '*** ILLEGAL DUPLICATE SYMBOL'
***
IOE      EQU,0    %
         D        '*** CAN''T OPEN FILE:'
         D        '*** I/O ERROR:'
         D        '*** FATAL I/O ERROR:'
         D        '*** CAN''T OPEN LIBRARY:'
         D        '*** CAN''T CREATE LIBRARY:'
***
LIBE     EQU,0    %
         D        '*** ILLEGAL LIBRARY FORMAT'
         D        '*** OLD STYLE LIBRARY--MUST CONVERT'
         D        '*** SOURCE SAME AS DESTINATION LIBRARY'
***
         USECT    CODE
         FIN
         PAGE
         SPACE
*
* AT THIS POINT, A2 HAS THE DESCRIPTOR OF THE ERROR MESSAGE.
*
         SPACE
         CALL     WRITEDO           SEND THE MESSAGE TO THE ERROR FILE,
         LC       DO#LL             ALSO TO LISTING DEVICE?
         BE       ERR#1             B/ NO:  DO IS LL; IT'S ALREADY THERE
         CALL     WRITELL           ELSE SEND TO LL.
         SPACE
*
* NOW, CHECK FOR SPECIAL CASE FOR I/O ERRORS.
*
ERR#1    LW,I2    I1                GET CODE, SUBCODE.
         SLS,I2   -8                GET CODE.
         CI,I2    +#IO              IS IT AN I/O ERROR?
         BNE      ERRABRT           B/ NO-- PREPARE TO RESTART.
         SPACE
* PRINT OUT ERROR MESSAGE FOR I/O ERROR.
         POP      A1                GET I/O ERROR CODE IN RAW FORM.
         LI,A0    +0                PREPARE TO PUT I/O CODE IN CANONICAL
         SLD,A0   +8                ...FORM.
         SLS,A1   -1
         SLD,A0   -24
         AW,A1    Y03               GET LENGTH BYTE.
         LI,A2    +BA(INBUF)        GET WHERE TO PUT IT.
         CALL     RDERRFL           AND READ IN THE RECORD.
         CALL     WRITEDO           WRITE TO M:DO
         LC       DO#LL             ALSO TO M:LL (QUESTION) ?
         BE       %+2               B/ NO.
         CALL     WRITELL
         SPACE
* FOR I/O ERRORS ONLY--  IF IT WAS SUBCODE =2, THEN ABORT.
         LI,I2    +X'FF'            EXTRACT SUBCODE,
         AND,I2   I1
         CI,I2    +2                HMM.
         BE       ABORT             B/ DIE.
         SPACE
* FOR ALL ERRORS -- ABORT IF '(X)' WAS SPECIFIED.
ERRABRT  LW,R1    O%X               SEE IF OPTION WAS SPECIFIED
         CW,R1    C%OPTS
         BAZ      RESTART           B/ GO TRY ALL OVER AGAIN.
***
ABORT    LW,R1    O%ERR             SET THE FLAG THAT TELLS WINDOWN...
         STS,R1   C%OPTS            ...TO FLICK IT IN W/ M:XXX
         B        WINDOWN           AND DIE.
         END

