         SYSTEM   UTS
*                                  DEBUG
         DEF      SNAP
SNAP     EQU      %
         PAGE
DRSPQA   EQU      0                 DRSP SWITCH FOR  QA TEST.
*FOLLOWING TITLE FOR DRSP QA TEST ASSEMBLY ONLY.
         DO       DRSPQA=1
         TITLE    'LH00000B:MONITOR OVERLAY FOR DRSP QA TEST CASE'
         FIN
*
*                        PROGRAM NAME - BATCH DEBUG ROUTINES
*
         PAGE
*                 SYMBOLIC 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      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
*                 PARAMETERS TO DEFINE BATCH MONITOR.
*                 PARAMETERS DEFINING POSITION IN PLIST RELATIVE TO
*                 R7
*
CNTR     EQU      3
STOPC    EQU      1
STRTC    EQU      0
STEPC    EQU      2
FLAG     EQU      6
LINK     EQU      -1
FROM     EQU      0
LFTW     EQU      0
RTW      EQU      1
TSTW     EQU      2
INST     EQU      4
         PAGE
*                 REFS AND DEFS FOR DEBUG MODULE.
*
*                 DEFS.
*
         DEF      MOR,MAND,MIF,MCOUNT,MSNAP,MSNAPC
         DEF      DEBUGX1
*
*
*                 REFS TO EXTERNAL ROUTINES.
*
         REF      T:ABORTM
         REF      FNDDCB
         REF      YFF,RMB,J:DCBLINK,PRINTV
         REF      SETUP
         REF      DUMPW
         REF      REGPRNT
         REF      GMB
         REF      UNSETUP
         REF      PRINTM
         REF      CKLIMIT
*
*                 REFS TO STATIC DATA.
*
         REF      M7,M4,M17
         REF      T:IACU
         REF      J:JIT
         PAGE
*                 IMMEDIATE CONSTANTS USED BY MONITOR.
K0       EQU      0
K1       EQU      1
K4       EQU      4
KF       EQU      15
         PAGE
*
*                 ALL ROUTINES ENTERED WITH R6 CONTAINING FIRST WORD
*                 OF PLIST. R7 CONTAINS ADDRESS OF SECOND WORD.
*
*                   PLIST AS FOLLOWS:
*                        WD 0:
*                          BYTE 0 - CODE
*                          REM.   - LINK. 0 IF NO MORE. ELSE ADDR.
*                        WD 1:
*                          SNAP AND SNAPC - FROM
*                          IF,AND, OR     - LOAD LEFT MEMBER.
*                          COUNT          - NUMBER TO START COUNTER
*                        WD 2:
*                          SNAP AND SNAPC - TO
*                          IF,AND, OR     - LOAD RIGHT MEMBER.
*                          COUNT          - NUMBER TO STOP COUNTER
*                        WD 3:
*                          SNAP AND SNAPC - COMMENT
*                          IF,AND, OR     - RELATION TESTING INST.
*                          COUNT          - INTERVAL AT WHICH TO SNAP
*                        WD 4:
*                          SNAP AND SNAPC - COMMENT AND REG SPEC.
*                          COUNT          - COUNTER
*                        WD 5:
*                          REPLACED INSTRUCTION
*                        WD 6:
*                          B  Z+1   Z IS LOC OF CAL1,3
*                        WD 7:
*                          FLAG WORD. FLAG IF B0 = 1. ADDRESS OF FLAG
*                          IF B0 = 0. FLAG IS B31 OF FLAG.
         PAGE
*                 MCOUNT PROCESSES COUNT PROCEDURE AND SETS FLAG OR
*                 CLEARS FLAG IF APPROPRIATE.
*
MCOUNT   LW,R1    CNTR,R7
         AI,R1    K1
         CW,R1    STOPC,R7
         BG       CLEARF                                                756
         PUSH     R1
         LW,R1    R7
         AI,R1    CNTR
         BAL,SR4  CHKADD            GO-CHECK ADDRESS OF COUNTER
         PULL     R1
*                 CLEAR IF OUT OF RANGE ON HIGH SIDE.
         STW,R1   CNTR,R7
         SW,R1    STRTC,R7
         BLZ      CLEARF
*                 CLEAR IF BELOW RANGE. ELSE DIVIDE DIFF BY STEP.
         LI,R0    K0
         DW,R0    STEPC,R7
         CI,R0    K0
         BNE      CLEARF
*                 IF NOT EVENLY DIVISABLE, CLEAR FLAG.
         SPACE    5
*                 SET FLAG UNCONDITIONALLY.
SETF     LI,R4    K1
         SPACE    5
*                 SET FLAG TO VALUE IN R4.
SORCFLAG LW,R1    FLAG,R7
         BLZ      SORC1
         LW,R1    R7
         AI,R1    FLAG
SORC1    EQU      %
*        TEST FLAG ADR
         BAL,SR4  CHKADD
         STW,R4   *R1
         SPACE    5
*                 EXIT FROM PROCESSING DEBUG STATEMENT. CHECK FOR MORE.
*                 IF NONE, EXECUTE REPLACED INSTRUCTION AND EXIT.
*
DEBUGX   LC       *TSTACK
         BCS,8    DEBUGX20          CHECKED ALREADY
         LI,0     255
         LW,2     7
         AI,2     -1
DEBUGX10 LW,2     0,2               GET NEXT LINK
         AND,2    M17               CLEAR BAD BITS
         BEZ      DEBUGX20          NO MORE, OK
         BDR,0    DEBUGX10          LUPE FOR MAX
         B        MIF3              ABORT, BAD LINK
*
DEBUGX20 LCI      8
         STCF     *TSTACK
         LW,R1    LINK,R7
         AND,R1   M17
         BEZ      DEBUGX1
*                 GET NEXT PLIST AND DECODE IT.
         AI,R1    K1
         LW,R7    R1
         LW,R1    LINK,R7
         LB,R2    R1
         CI,R2    NDBGS
         BL       DBGTV,R2
         B        MIF3
DBGTV    EQU      %
         B        MSNAP
         B        MSNAPC
         B        MIF
         B        MAND
         B        MOR
         B        MCOUNT
NDBGS    EQU      %-DBGTV
         SPACE    5
*                 FINISHED, EXIT.
DEBUGX1  LW,R1    INST,R7
         LB,R2    R1
         AND,R2   M7
         LW,R0    R7
         AI,R0    INST              CAL RETURNS HERE IF NOT BAL
         CI,R2    X'67'             EXU INSTRUCTION
         BNE      DEBUGX2           NO
         BAL,SR4  GTEADD            YES-GET THE EFFECTIVE ADD. OF EXU
         LW,R1    *R0
         LB,R2    R1
         AND,R2   M7
         LW,R0    R7
         AI,R0    INST              CAL RETURNS HERE IF NOT BAL
DEBUGX2  CI,R2    X'6A'             BAL INSTRUCTION
         BNE      DEBUGX3           NO
         BAL,SR4  GTEADD            YES-GET THE EFFECTIVE ADD. OF BAL
         SLS,R1   -20
         AND,R1   M4                REGISTER OF BAL
         LW,D1    TSTACK+2          CAL ADDRESS
         AI,D1    1                 +1
         AND,D1   M17
         STW,D1   TSTACK+5,R1       MANUFACTURE BAL RETURN ADDRESS
DEBUGX3  AI,R0    -1                BALANCE TRAPEXIT'S +1
         LI,R1    X'1FFFF'
         STS,R0   TSTACK+2          RETURN TO REPLACED INSTRUCTION
         PULL     11
         B        *11
         SPACE    5
*                 M:AND. IF FLAG CLEAR, EXIT. ELSE SAME AS M:IF.
MAND     BAL,SR4  TFLAG
         B        DEBUGX
         SPACE    5
*                 M:IF. SET FLAG ACCORDING TO CONDITION.
MIF      LI,R4    2                 THROUGH THE LOOP TWICE
         LW,R1    LFTW,R7           FIRST LOAD INSTRUCTION
MIF1     LI,R2    4
         LB,R3    R1
         AND,R3   M7
         CB,R3    LDOPS,R2          CHECK FOR LW,LB,LH,LD OP CODE
         BE       MIF2              YES-LEGAL OP CODE
         BDR,R2   %-2
MIF3     LI,14    X'B003'
         SCS,14   -8
         B        T:ABORTM          B003 ILLEGAL PARAMETER IN DEBUG CAL.
MIF2     PUSH     R4
         PUSH     R7
         BAL,SR4  GETOPD            GO-GET OPERAND OF LOAD INSTRUCTION
         PULL     R7
         PULL     R4
         LB,R2    R1
         AND,R2   M7
         CI,R2    X'12'             LOAD DOUBLE
         BE       %+2               YES
         LI,D4    0                 ZERO LOW ORDER 32 BITS
         LW,R1    RTW,R7
         PUSH     2,D3              SAVE OPERAND
         BDR,R4   MIF1
         PULL     2,D3              SECOND OPERAND
         PULL     2,D1              FIRST OPERAND
         LW,R4    Y7FF
         AND,R4   TSTW,R7
         LB,R2    R4                OP CODE OF BRANCH
         CI,R2    X'68'             BCR
         BE       %+3               YES-O.K.
         CI,R2    X'69'             BCS
         BNE      MIF3              NO-BAD CAL
         AI,R4    SETF
         CD,D1    D3
         EXU      R4
*                 CONTINUE TO CLEARF IF CONDITION FALSE
         SPACE    5
*                 CLEAR FLAG. SET R4=0 AND GO TO SORCFLAG.
CLEARF   LI,R4    K0
         B        SORCFLAG
         SPACE    5
*                 M:OR.  IF FLAG SET, EXIT. ELSE LIKE M:IF
MOR      BAL,SR4  TFLAG
         B        MIF
         B        DEBUGX
         SPACE    5
*                 CHECK FLAG.RETURN +2 IF SET, +1 IF CLEAR.
TFLAG    LW,R2    FLAG,R7
         BGEZ     TF1
         LW,R2    *R2
TF1      AND,R2   X1
         B        *SR4,R2
         PAGE
*                 SNAP AND SNAPC.
*                 M:SNAPC. IF FLAG SET, SNAP. ELSE EXIT.
MSNAPC   BAL,SR4  TFLAG
         B        DEBUGX
         SPACE    5
*                 SNAP SPECIFIED AREA.
MSNAP    EQU      %
         LI,5     J:JIT
         LCI      K4
         LM,D1    FROM,R7
         LW,R0    D1
         BGEZ     %+3
         BAL,SR4  OGTWD
         LW,D1    R1
         LW,R0    D2
         BGEZ     %+3
         BAL,SR4  OGTWD
         LW,D2    R1
         LI,SR3   TSTACK+20
         LW,R2    J:DCBLINK
         BEZ      DEBUGX            NO DCB'S, NO SNAP
         PUSH     2,R6
         PUSH     4,D1
MSNAP05  BAL,R0   FNDDCB
         BNEZ     MSNAP10
         PULL     6,R6
         B        DEBUGX            CAN'T FIND M:DO, CAN'T GIVE SNAP
MSNAP10  LW,SR2   D1                SET FOR FILE EXTENSION
         LCI      2
         LM,D1    *D1
         AND,D2   YFF
         CD,D1    TXTMDO            M:DO DCB
         BNE      MSNAP05           NO, TRY AGAIN
         LW,R6    SR1               DCB ADDR TO RIGHT REG
         BAL,SR4  GMB
         BEZ      %-1
         PULL     2,R1
         LW,R0    BLKS
         LCI      3
         STM,R0   *D3               MESSAGE TO BUFFER
         LI,D4    TSTACK
         BAL,R0   SETUP
         LI,D4    12                MESSAGE LENGTH
         BAL,D1   PRINTV
         LI,D4    TSTACK
         BAL,SR4  REGPRNT
         PULL     4,SR1             LIMITS BACK FROM STACK
         PUSH     2,SR3
*FOLLOWING CODE ASSEMBLED IN DRSP QA VERSION OF SNAP WHEN SWITCH=1
         DO       DRSPQA=1          IF DRSPQA SWITCH IS SET,
         BAL,SR4  MO1ENTRY          .EXECUTE SPECIAL PART
         B        MSNAP11           ..OF SNAP AND IGNORE
         FIN                        ...REGULAR DUMP OUTPUT.
*
         PUSH     7
         LW,7     8                 GET START ADDRESS
         LW,15    9
         SW,15    8
         SLS,15   2                 & # BYTES
         BAL,0    CKLIMIT           GET MAX PROT TYPE
         BCR,2    %+2               OK
         BCS,1    CHKADDBAD         TYPE 3, ABORT THE DUDE
         PULL     7
         LI,15    TSTACK
         BAL,SR4  DUMPW
MSNAP11  EQU      %
         BAL,R1   UNSETUP
         BAL,SR4  RMB
         PULL     2,R6
         B        DEBUGX
CHKADDBAD EQU     %
         BAL,SR4  RMB
         LI,14    X'B001'           ATTEMPT TO DUMP BAD LOC
         B        MIF3+1
         PAGE
*        BAL,SR4  GETOPD            GET OPERAND-LOAD INSTRUCTION ONLY
*                 R1                INSTRUCTION
*                 RETURN
*                 D3,D4             OPERAND
*                                   ALL REGISTERS DESTROYED
GETOPD   EQU      %
         PUSH     SR4               SAVE RETURN
         LW,R2    Y00E
         LW,R3    Y00F
         STS,R2   R1                CHANGE REGISTER TO 14
         PUSH     R1                PUT INSTRUCTION IN STACK
         LCI      0
         LM,0     TSTACK+5          BRING UP ALL USER REGS
         EXU      *TSTACK           EXECUTE THE LOAD
         PULL     R1
         PULL     SR4
         B        *SR4              RETURN
*        BAL,SR4  GTEADD            GET EFFECTIVE ADDESS
*                 R1                INSTRUCTION
*                 RETURN
*                 R0                EFFECTIVE ADDRESS
GTEADD   EQU      %
         PUSH     SR4
         PUSH     R7
         PUSH     R1
         LCI      0
         LM,0     TSTACK+5          BRING UP ALL USER REGISTERS
         ANLZ,0   *TSTACK           GET EFFECTIVE ADDRESS
         PULL     R1
         PULL     R7
         PULL     SR4
         B        *SR4              RETURN
*        BAL,SR4  CHKADD            CHECK ADDRESS
*                 R1                ADDRESS TO CHECK
*                                   ABORT IF NOT IN (00) (01)
CHKADD   EQU      %
         PUSH     SR4
         PUSH     R7
         LW,R7    R1
         SLS,R7   -9                PAGE NO. OF ADDRESS
         BAL,SR4  T:IACU            GO-GET THE PAGE ACCESS CODE
         BCR,2    MIF4              O.K.- (00) OR (01)
         LI,14    X'B002'
         B        MIF3+1            B002 BAD ADDRESS IN DEBUG CAL
MIF4     PULL     R7
         PULL     SR4
         B        *SR4              RETURN
*FOLLOWING CODE ASSEMBLED IN DRSP QA VERSION OF SNAP WHEN SWITCH=1
         DO       DRSPQA=1
MO1ENTRY PUSH     11                STORE EXIT.
         LI,1     RESPONSE          PRINT OVERLAY
         BAL,11   PRINTM            .IDENTIFICATION.
         PULL     11
         B        *11               EXIT.
RESPONSE TEXTC    'DRSP QA TEST: MODIFIED DEBUG OVERLAY'
         FIN
*
         PAGE
*                 GTWD CONVERTS R0 TO TRUE MEMORY ADDRESS AND RETURNS
*                 CONTENTS IN R1.  LINK = SR4
GTWD     BAL,R1   CVREG
GTWD1    LW,R1    *R0
         B        *SR4
         SPACE    5
*                 CVREG CONVERTS REG ADDR TO STACK ADDR.
CVREG    AND,R0   M17
         CI,R0    KF
         BG       %+2
         AI,R0    TSTACK+5
         B        *R1
OGTWD    EQU      GTWD
LDOPS    DATA     X'00327252',X'12000000'
Y00E     DATA     X'00E00000'
Y00F     DATA     X'00F00000'
Y7FF     DATA     X'7FF00000'
BLKS     DATA     X'C3404040'
         BOUND    8
TXTMDO   GEN,8,32,24 4,'M:DO',0
         END

