DEBUG    SET      0
DEBUG    SET      1
OC       EQU      2
         SYSTEM   UTS
         REF      MONINIT
         REF      IOPSD,OCPSD
         REF      JIT
         REF      SPOOL
         REF      NOPPSD,UNIMPPSD,STKLPSD,FIXOVPSD,FLTFPSD,DECFPSD
         REF      TINC
         DEF      INITIAL,LMA
         DO       DEBUG
         DEF      PACHER,PATCHEE,READCR
         FIN
         DEF      MAPINC,MAPINIT
         DEF      UMOV#
         DEF      TOPROOT
         REF      LKIMG
         REF      MASKS
         REF      IOLOW,IOHIGH,:BIG
         REF      CORED
         REF      SYSVERS
         REF      HGP
         REF      BOOTSBAND
         REF      MB:GAM4
         REF      OB:BOPTX
         REF      T:SGRNU
         REF      CAL1PSD,CAL2PSD,CAL3PSD,CAL4PSD
         REF      POWRON,POWROFF,CLK3PSD,CLK4PSD
         REF      S:CLOCK4
         REF      IPT47             INTER-PROCESSOR TRAP
         REF      S:GJOBTBL,MING
         REF      MN9
         REF      PPSTART
         REF      PB:HVA
         REF      T:SE
         REF      T:GJOBSTRT
         REF      PSA%END                                               DISCB
         REF      SL:CORE
         REF       CSED%PATH
         REF      CSED%PSD%T46
         REF      CSED%PSD%T4C
         REF      CSED%PSD%T4D
         REF      CSED%PSD%I56
         REF      CSED%PSD%I57
         REF      LEE20
         REF      MB:GPT
         REF      MONORG
INITIAL  LPSD,0   INITPSD
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
INIT2    RES
         LW,2     S7TST
         STW,2    X'40'
         EXU      S7INST            CHECK IF SIG7 IN BIG MAP MODE
         LI,2     MONORG-X'60'
         LW,1     MTW0              'MTW,0   0' INSTRUCTION
         STW,1    X'5F',2
         BDR,2    %-1
         LI,1     X'5F'-X'3F'
         LW,2     XPSDS-1,1         SET TRAPS, INTERRUPTS, ETC
         STW,2    X'3F',1
         BDR,1    %-2
         DO       DEBUG
         XPSD,10  TRP51             DO WE WANT TO PATCH ?
         FIN
         LI,1     X'2020'           ARM & ENABLE I/O, CLOCK3
         WD,1     X'1200'
         BAL,11   MONINIT
         BAL,11   LMA
         LI,0     TSTACK+1          BUILD MONITOR JIT
         LI,1     JIT+512-TSTACK-2
         SLS,1    16
         LI,2     DA(TSTACK)-DA(JIT-2)
         STD,0    JIT-2,2
         SD,0     0
         BDR,2    %-2
         LW,9     PSA%END           REL SWAP SPACE FOR GH-1             DISCB
         CI,9     X'1480'           DON'T ALLOCATE LAST
         BL       %+2               4 GRAMS
         AI,9     -8
         STW,9    BOOTSBAND         INITIALIZE BOOTSBAND
         LH,7     HGP+1              FROM END OF PSA
         STH,7    BOOTSBAND         INSERT DCT INDEX
         LB,2     MB:GPT            GRAN PER TRACK
         SLS,2    1                 SECTORS PER TRACK
         LI,8     0
         DW,8     2
         LI,2     0                 SWAPI OF FIRST SWAPPER
         LB,3     MB:GAM4
         SLS,9    1,3
         AW,9     8
         LW,7     SL:CORE
         AI,7     3
         SAS,7    -2
         SAS,7    2
         AI,9     -2
         LW,15    9
         BAL,11   T:SGRNU           REL SL:CORE GRAN FOR GH1
         BCS,1    %-3
         MTW,-2   BOOTSBAND
         BDR,7    %-5
NOSREL   EQU      %
         LW,0     SYSVERS
         STW,0    X'2B'
         LW,0     IOXPSD            REPLACE IOXPSD FOR GHOST1
         STW,0    X'5C'
         LI,R2    0                 LET TRAP HANDLERS
         STW,R2   CSED%PATH         KNOW INITIAL IS DONE
         LD,0     S:GJOBTBL+4       START UP ALLOCAT
         BAL,10   T:GJOBSTRT
         LD,0     S:GJOBTBL+MING+MING
         BAL,10   T:GJOBSTRT        START UP THE STARTER GHOST
         LI,1     X'38F0'           ARM AND ENABLE: PANEL,IO,
*                                       C4Z,C3Z,C4P,C3P,C2P
         BIF,S7   WD                FOR SIG7, JUST MPI
         LI,R1    X'34F0'           FOR SIG9, JUST MFI
         LI,1     X'34F0'           BUT LEAVE CPU FAULT ARMED
         BIF,S9   WD
         LI,R1    X'3CF0'           FOR X560, MFI AND PFI
WD       EQU      %
         WD,1     X'1200'
         LI,1     X'80'             FIRE CLOCK3 ZERO
         WD,1     X'1700'
         LI,1     0
         STW,1    *SPOOL            END CHAIN
         B        T:SE
LMA      EQU      %
         BAL,R10  LOADWL            GO LOAD WRITE LOCKS
         BAL,R10  LOADMAP           LOAD MAP AND ACCESS CODES
         B        *R11
LOADMAP  EQU      %                 DEF'D FOR CSEHANDLER
         LI,3     64
         SLS,R3   :BIG              SHIFT FOR BIG MAP MODE
         LW,2     MAPINIT
         BAL,4    LOOP
         LDMAP,0  0
         AW,2     MAPINC
LACBF    LW,2     CJOBACC
         LI,3     16
         BAL,4    LOOP
         LPC,0
         LI,R2    -1
         B        *R10
LOADWL   RES
         LW,3     CORED             FIRST SET ALL TO ZERO
         SLS,3    -9-4
         BAL,4    LOOP
         LI,2     0
         LLOCKS,0
         LW,1     WLZAP             ZAP WRITE LOCK BUFFER
         MBS,0    BA(MAPINIT)
         LI,1     0                 NOW SET MON DATA TO 01
         LI,4     PPSTART-1
         LW,2     FIVES
         BAL,6    LWL
         LI,1     JIT               SET JIT TO 01
         LI,4     JIT+511
         BAL,6    LWL
         LI,1     PPSTART+511       SET MON PURE PROCEDURE TO 11
         LI,4     TOPROOT-1-256     IF SPOOL BUFFER, DONT PROTECT IT
         LI,2     -1
         BAL,6    LWL
         LI,1     JIT+512           SET UMOV TO 11
UMOV#    LI,5     0                 FILLED IN BY BOOTSUBR
         LB,4     PB:HVA,5
         SLS,4    9
         AI,4     -1
         BAL,6    LWL
         BIF,S7S9 NOIOWL
         LI,1     IOLOW             SET IO BUFFERS TO 0 FOR 560
         LI,4     IOHIGH-1
         LI,2     0
         BAL,6    LWL
NOIOWL   RES
         LI,0     LKIMG
         LW,1     Y08
Y08      EQU      BT31TO0+28
         LLOCKS,0                   INTO THE HARDWARE REGISTERS
         B        *10               AND RETURN
*
*
WLZAP    GEN,8,24 32,BA(LKIMG)
*
*
LWL      RES
*        SET WRITE LOCK IMAGE  FOR PAGES (1) THRU (4)
*        TO (2) (32 BITS)
         SLS,1    -9
         LI,3     X'F'              GET DISP INTO WORD
         AND,3    1
         MI,3     -2                (COMPLEMENTED)
         LW,3     MASKS+32,3        INITIAL MASK TO USE
         SLS,1    -4                INITIAL WORD DISP
         SLD,4    -9-4              NOW GET MASK FOR LAST STORE
         SLS,5    -28
         MI,5     -2
         LCW,5    MASKS+30,5
         AI,5     -1
LWL1     CW,4     1
         BL       0,6               RETURN IF DONE
         BNE      %+2
         AND,3    5                 SET FINAL MASK (MAY ALSO BE FIRST ONE)
         STS,2    LKIMG,1
         AI,1     1
         LI,3     -1                INTERMEDIATE MASK
         B        LWL1
*
*
*
LOOP     LI,1     1
         LI,0     2
         STB,1    1
         EXU      0,4
         EXU      1,4
LOOP5    BDR,3    LOOP+1
         B        2,4
FIVES    DATA     X'55555555'
MAPINIT  GEN,15,1,6,1,7,1,1   0,1-:BIG,0,1-:BIG,0,1-:BIG,1
MAPINC   GEN,5,1,7,1,1,6,1,7,1,1,1   0,1-:BIG,0,1-:BIG,:BIG,0,1-:BIG,;
                                     0,1-:BIG,:BIG,0
CJOBACC  DATA     X'BFFFFFFF'
TOPROOT  RES
XPSDS    XPSD,10  NOPPSD
         XPSD,10  UNIMPPSD
         XPSD,10  STKLPSD
         XPSD,10  FIXOVPSD
         XPSD,10  FLTFPSD
         XPSD,10  DECFPSD
         XPSD,8   CSED%PSD%T46
         XPSD,10  IPT47             INTER-PROCESSOR TRAP
         XPSD,10  CAL1PSD
         XPSD,10  CAL2PSD
         XPSD,10  CAL3PSD
         XPSD,10  CAL4PSD
         XPSD,0   CSED%PSD%T4C      USE SAME REG BLOCK IN CASE RBLK PARITY
         XPSD,8   CSED%PSD%T4D
         XPSD,8   LEE20             LEES WATERING HOLE
         DATA     JIT+255**24       CJOB
         XPSD,10  POWRON
         XPSD,10  POWROFF
         MTW,0    0
         MTW,0    0                 CLOCK2
         MTW,-1   TINC
         MTW,1    *S:CLOCK4         ACCOUNTING CLOCK (CLOCK4)
         XPSD,8   CSED%PSD%I56
         XPSD,8   CSED%PSD%I57
         MTW,0    0                 CLOCK1
MTW0     MTW,0    0                 CLOCK2
         XPSD,10  CLK3PSD
         XPSD,10  CLK4PSD
         XPSD,10  AIOPSD            INITIAL IO INTERRUPT XPSD
         XPSD,8   OCPSD
         DATA     0,INITIAL         MON START ADR FOR DISCBOOT
IOXPSD   XPSD,8   IOPSD
INITPSD  :PSD     (IA,INIT2)
AIOPSD   :PSD     RES,(IA,AIOSRV)
S7MSG    GEN,8,24,32   5,BA(S7TXT),31
S7ERR    DATA     0,0,%+2,0
         LI,1     OC                OC OP LEBEL INDEX
         LB,1     OB:BOPTX,1        DCTX OF OC
         LH,1     DCT1,1
         AI,R1    -X'C100'          MAKE INTO SIGMA7 ADDRESS
         LI,0     DA(S7MSG)         TELL OPERATOR AND QUIT.
         SIO,0    *1
         B        %
         B        %-2
S7TST    XPSD,10  S7ERR
S7INST   GEN,5,1,26    5,:BIG,0
S7TXT    DATA,1   X'15',X'15','S','Y'
         TEXT     'STEM REQUIRES SIG9 OR X560'
         REF      DCT1
AIOSRV   AIO,0    0
         STCF     S9AIOCC           SAVE AIO CC
         LPSD,X'B'  AIOPSD          RETURN
S9AIOCC  DATA     0
         DO       DEBUG
         PAGE
*******************
*   B O O T   T I M E    P A T C H    R O U T I N E
*
*        PATCH CP-V MONITOR ROOT AND BOOT TIME ROUTINE
*        WITH ABSOLUTE PATCHES. PATCH FORMAT IS:
*
*        COL.1         COL.9
*
*        LOC.          VALUE
*
*                 WHERE: LOC    =5 HEX DIGIT ADDR
*                        VALUE  =8 HEX DIGIT VALUE
*
*   ENTRY  :      BY EXECUTING TRAP LOC. X'51' WHICH CONTAINS XPSD
*   EXIT   :       BY LPSD TO RESULT OF ENTRY XPSD
*
*
*        PATCHES ARE TERMINATED BY  A !EOD CARD, AND ARE
*        READ FROM THE CARD READER
*
*        PATCHES ARE PRINTED ON THE LINE PRINTER
*
******************
         SPACE    3
         SPACE    3
PACHER   EQU      %                 ENTRY-------
         LCI      0                 SAVE REGS.
         PSM,R0   STK
         LI,0     DA(PTHMSG)        ASK IF THEY WANT TO PATCH
         SIO,0    *TYNDD
         TIO,0    *TYNDD
         BCS,12   %-1
         LB,R1    ADDR              GET ANSWER
         CI,R1    'Y'               IS IT YES
         BNE      EXIT              B IF NOT
         LI,R0    DA(PRNTEST)
         SIO,R2   *LPNDD            EJECT A PAGE
         BCS,CC   %
         TIO,R4   *LPNDD
         BCS,CC   %-1
READCR   EQU      %
         LI,0     DA(READ)          READ A CARD
         SIO,R2   *CRNDD
         BCS,CC   %
         TIO,R4   *CRNDD            WAIT FOR
         BCS,CC   %-1               I/O DONE
PRNTOK   EQU      %
         LI,R0    DA(PRINT)
PRNTOK0  EQU      %
         SIO,R2   *LPNDD            PRINT CARD
         BCS,CC   %                 STOP SOMETHING IS WRONG
         TIO,R4   *LPNDD            WAIT FOR
         BCS,CC   %-1               I/O TO FINISH
PRNTOK1  EQU      %
         LW,R1    PACHBUF
         BEZ      EXIT              B IF END OF PATCHING
         CW,R1    L('!EOD')         NO----CHECK FOR
         BNE      PATCH             END OF PATCHES
         LI,R1    0                 WE ARE DONE, SO SET
         STW,R1   PACHBUF           PATCHING FLAG
         LI,R0    DA(PRNTEST)
         B        PRNTOK0           EJECT PAGE
*----------------------------
PATCH    EQU      %
         LI,R8    0                 FLAG FOR 'LOC' CONVERS.
         LD,R6    LOC               GET LOC FIELD
         BAL,R9   CONV              CONVERT TO HEX
*
*  RETURN WITH R10 = LOC.
*
         STW,R10  ADDR
         LI,R8    1                 VALUE CONVERS.
         LD,R6    VALUE             VALUE FIELD
         BAL,R9   CONV              CONVERT TO HEX
*
*  RETURN WITH R10 = VALUE
*
         STW,R10  *ADDR             PATCH MONITOR
         B        READCR            GET NEXT CARD
*
*
*
         PAGE
**************************
*
*  C O N V  R O U T I N E
*
*        PART OF BOOTPATCH ROUTINE. CONVERTS EIGHT (8)
*        EBC CHARACTERS TO 8 HEX CHARACTERS
*
*  ENTRY : R6-R7  = 8 EBC CHAR.
*          R8     = 0 CONVERT LOC
*                 = 1 CONVERT VALUE
*
*  EXIT  : R10    = 8 HEX CHAR (CONVERTED)
*
*  ENTERED BY :    BAL,R9
*
**************************
         SPACE    3
CONV     EQU      %           ENTRY..........
         CI,R8    0
         BNEZ     CONV1             NO---LOC CONV.
         OR,R7    L(' 000')         YES--5 CHAR LOC BECOMES
         SCD,R6   -24               8 CHAR
CONV1    EQU      %
         LI,R15   8                 8 DIGITS
CONV2    EQU      %
         LB,R11   R6                GET CHAR
         SLD,R6   8                 TO NEXT CHAR
         CI,R11   '0'
         BGE      %+2
         AI,R11   X'39'             CONVERT
         AI,R11   -'0'              EBC DIGIT
         SCS,R11  -4
         SLD,R10  4
         BDR,R15  CONV2             GET NEXT CHAR.
         B        *R9               ------- RETURN
***********************
         PAGE
***********************
*  D A T A  I N F O
***********************
         SPACE    3
***********
         BOUND    8
NEWPAGE  TEXT     '1   '            TOP OF FORM
PRNTBUF  TEXT     'A   '            UPSPACE ONE LINE
PACHBUF  RES      20                INPUT BUFFER FOR PATCHES
*******************
CC       EQU      X'C'              CONDITION CODE FOR I/O CHECK
LOC      EQU      PACHBUF+0         WD-0 IN BUF OF LOC (2 WDS TOTAL)
VALUE    EQU      PACHBUF+2         WD-2 IN BUF OF VALUE (2WDS TOTAL)
******
CRNDD    DATA     0003              CR ADDR
LPNDD    DATA     0002              LP ADDR
TYNDD    DATA     0001              TY ADDR
******
ADDR     PZE      0                 WHERE TO PATCH
********
         BOUND    8
STKSZ    EQU      16
STK      PZE      %+1
         GEN,16,16 STKSZ,0
         RES      STKSZ
******
         SPACE    3
*******
         BOUND    8
READ     EQU      %                 IOCD TO READ A CARD
         GEN,8,24  X'06',BA(PACHBUF)
         GEN,8,24  X'00',20*4
******
         BOUND    8
PRINT    EQU      %                 IOCD TO PRINT A CARD
         GEN,8,24  X'05',BA(PRNTBUF)
         GEN,8,24  X'00',21*4
******
         BOUND    8
PRNTEST  EQU      %                 IOCD TO DETERMINE PRINTER TYPE
         GEN,8,24  X'05',BA(NEWPAGE)      AND EJECT PAGE
         GEN,8,24  X'00',1*4
******
************
******************
EXIT     EQU      %
         LCI      0
         PLM,R0   STK
         LPSD,0   TRP51             RETURN
***************************
         BOUND    8
TRP51    DATA     0,0,PACHER,0
*
*
         BOUND    8
*
PTHMSG   GEN,8,24 X'05',BA(BUSH)
         GEN,8,24 X'20',BUSHSZE
         GEN,8,24  X'86',BA(ADDR)
         GEN,8,24 X'00',4
*
*
BUSH  TEXT  ' IF YOU WANT TO PATCH, ANSW. YES  '
BUSHSZE  EQU      BA(%)-BA(BUSH)
*
*
PATCHEE  RES    50
*
         FIN
         END      INITIAL

