*M*      INITIAL  MONITOR INITIALIZATION ROUTINE - RESIDENT
*P*
*P*      NAME:    INITIAL
*P*
*P*      PURPOSE: INITIALIZATION ROUTINE FOR RESIDENT MONITOR
*P*
*P*      DESCRIPTION: (1) SETS UP TRAP AND INTERRUPT LOCATIONS
*P*                   (2) BALS TO BOOTSUBR FOR FURTHER INITIALIZATION
*P*                                 AND/OR TAPE BOOT PROCESS
*P*                   (3) SETS UP THE HARDWARE WRITE LOCKS AND MAP
*P*                   (4) BUILDS MONITOR JIT
*P*                   (5) INITIATES ALLOCAT AND GHOST1
*P*                   (6) STARTS UP SYSTEM BY EXITING TO SCHEDULER
*P*
         PCC      0
         TITLE    'INITIAL - MONITOR INITIALIZATION ROUTINE'
         DEF      INITIAL:          MODULE NAME
INITIAL: EQU      %
DEBUG    SET      0                 SET TO 1 TO INCLUDE ABS PATCHER
OC       EQU      2
BITS     SET      1                 GET BT31TO0 AND MASKS
         SYSTEM   UTS
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
*  REFS AND DEFS
         SPACE
         REF      NOPPSD            TRAP 40
         REF      UNIMPPSD          TRAP 41
         REF      STKLPSD           TRAP 42
         REF      FIXOVPSD          TRAP 43
         REF      FLTFPSD           TRAP 44
         REF      DECFPSD           TRAP 45
         REF      PSD%T46           TRAP 46 WATCHDOG TIMER
         REF      IPT47             TRAP 47 INTER-PROCESSOR TRAP
         REF      CAL1PSD           TRAP 48
         REF      CAL2PSD           TRAP 49
         REF      J:ALB             TRAP 4A VECTOR IN THE JIT
         REF      CAL4PSD           TRAP 4B
         REF      PSD%T4C           TRAP 4C HARDWARE ERROR TRAP
         REF      PSD%T4D           TRAP 4D REG EXCEPTION TRAP
         REF      LEE20             TRAP 4E XDLT ENTRY
         REF      POWRON            TRAP 50
         REF      POWROFF           TRAP 51
         REF      TINC              INTR 54 CLOCK 3 PULSE
         REF      S:CLOCK4          INTR 55 CLOCK 4 PULSE (         SPACE)
         REF      PSD%I56           INTR 56 MEM PE INTR OR PFI
         REF      PSD%I57           INTR 57 MEM FLT INTR
         REF      CLK3PSD           INTR 5A CLOCK3 ZERO
         REF      CLK4PSD           INTR 5B CLOCK4 ZERO
         REF      IOPSD             INTR 5C
         REF      OCPSD             INTR 5D
         SPACE
         REF      MONORG            START OF RESIDENT CODE
         SPACE
         REF      BOOTHLT           EMERGENCY HALT (BOOT OC INTR)
         SPACE
         REF      MONINIT           ENTRY POINT TO BOOTSUBR
         SPACE
         REF      PSA%END           SET UP FOR RECOVERY
         REF      HGP               SET UP FOR RECOVERY
         REF      BOOTSBAND         SET UP FOR RECOVERY
         REF      BOOTFLG           SIZE OF XDELTAS PATCH FILE
         SPACE
         REF      MB:GPT            USED TO REL GHOST1 SW SPACE
         REF      SL:CORE           USED TO REL GHOST1 SW SPACE
         REF      T:SGRNU           USED TO REL GHOST1 SW SPACE
         REF      MB:GAM4           USED TO REL GHOST1 SW SPACE
         SPACE
         REF      S:GJOBTBL         USED TO START ALLOCAT & GHOST1
         REF      MING              USED TO START ALLOCAT & GHOST1
         REF      T:GJOBSTRT        USED TO START ALLOCAT & GHOST1
         SPACE
         REF      SPOOL             INITIALIZED TO ZERO
         SPACE
         REF      T:SE              ENTRY TO SCHEDULER
         SPACE
         REF      CORED             USED TO SET UP WRITE LOCKS
         REF      PPSTART           USED TO SET UP WRITE LOCKS
         REF      JIT               USED TO SET UP WRITE LOCKS
         REF      LKIMG             USED TO SET UP WRITE LOCKS
         REF      PB:HVA            USED TO SET UP WRITE LOCKS
         REF      IOLOW             USED TO SET UP WRITE LOCKS
         REF      IOHIGH            USED TO SET UP WRITE LOCKS
         REF      SSDATU:           USED TO SET UP WRITE LOCKS
         REF      TOPUMVDTA         USED TO SET UP WRITE LOCKS
         REF      TSTACK            USED TO BUILD MONITOR JIT
         SPACE
         REF      :BIG              USED TO SET UP MAP
         SPACE
         REF      SYSVERS           SET UP FROM X'2B'
         SPACE
         REF      OB:BOPTX          DCTX OF OC FOR ERROR MSG
         REF      DCT1              IO ADDR OF OC FOR ERROR MSG
         SPACE
         REF      CSED%PATH         CLEARED TO ZERO FOR FLT HANDLERS
         SPACE
         REF      LSWAP             NO. OF SWAPPERS IN SYSTEM
         REF      NSWAP             CELL CONTAINING NO. OF SWAPPERS IN SYSTEM
*,*                                 INITIALLY SET AT ONE.
         SPACE
         DEF      INITIAL           ENTRY POINT AND MODULE BASE
         DEF      LMA               ENTRY TO RELOAD WRT LOCKS,MAP % ACC
         DEF      UMOV#             INSTR FILLED IN BY BOOTSUBR
         DEF      TOPROOT           TOP OF RESIDENT CODE
         PAGE
*F*  NAME:  INITIAL
*F*
*F*  PURPOSE:  INITIAL ENTRY POINT FOR STARTUP OF SYSTEM
*F*            DURING ANY TYPE OF BOOT OR RECOVERY
         SPACE
INITIAL  LPSD,0   INITPSD
INIT2    RES
         LW,2     S7TST
         STW,2    X'40'
*
*O*      MESSAGE: SYSTEM REQUIRES SIG9 OR X560
*O*
*O*      MEANING: THIS PO TAPE CANNOT BE BOOTED ON A SIGMA 6/7
*O*               BECAUSE IT NEEDS HALFWORD MAP FORMAT
*
         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'2030'           ARM/ENABLE I/O,CLOCK3,OC
         MTB,0    X'2A'             NO OC IF RECOVERY
         BNEZ     %+2
         AI,1     -X'10'
         :WD,1    ARM%ENABLE
         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
         SW,9     BOOTFLG           LEAVE PAACH FILE THERE
         STH,0    9                 ZAP GARBAGE
         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'
         LD,0     IOXPSDS           REPLACE XPSDS
         STD,0    X'5C'             FOR I/O AND OC
         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,R1    LSWAP+1           NO. OF SWAPPERS IN SYSTEM
         STW,R1   NSWAP
         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
         BIF,S9   WD
         LI,R1    X'3CF0'           FOR X560, MFI AND PFI
WD       EQU      %
         :WD,1    ARM%ENABLE
         LI,1     X'80'             FIRE CLOCK3 ZERO
         :WD,1    TRIGGER
         LI,1     0
         STW,1    *SPOOL            END CHAIN
         B        T:SE
*
*F*      NAME:    LMA
*F*
*F*      PURPOSE: TO RELOAD WRITE LOCKS AND MAP AND ACCESS CODES
*F*
*F*      DESCRIPTION: CALLED DURING INITIALIZATION AND
*F*                   CALLED AFTER POWER FAIL/RESTORE OR AFTER
*F*                   PARITY ERROR TO RELOAD THE HARDWARE REGISTERS
*F*
*D*      NAME:    LMA
*D*
*D*      CALL:    BAL,11 LMA
*D*
*D*      REGISTERS: ALL REGISTERS VOLATILE
*
LMA      EQU      %
         BAL,R10  LOADWL            GO LOAD WRITE LOCKS
         BAL,R10  LOADMAP           LOAD MAP AND ACCESS CODES
         B        *R11
LOADMAP  EQU      %
         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
         EXU      UMOV#
         BEZ      NOUMVDTA
         LI,1     SSDATU:           SET UMOV DATA TO 01
         LI,4     TOPUMVDTA
         LW,2     FIVES
         BAL,6    LWL
NOUMVDTA EQU      %
         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
         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
         SAD,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,2   PSD%T46
         XPSD,10  IPT47             INTER-PROCESSOR TRAP
         XPSD,10  CAL1PSD
         XPSD,10  CAL2PSD
         XPSD,10  *J:ALB            VECTOR CAL3 THRU THE JIT
         XPSD,10  CAL4PSD
         XPSD,2   PSD%T4C
         XPSD,2   PSD%T4D
         XPSD,8   LEE20             LEES WATERING HOLE
         DATA     JIT+255**24       CJOB
         XPSD,0   POWRON
         XPSD,10  POWROFF
         MTW,0    0
         MTW,0    0                 CLOCK2
         MTW,-1   TINC
         MTW,1    *S:CLOCK4         ACCOUNTING CLOCK (CLOCK4)
         XPSD,0   PSD%I56
         XPSD,0   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,10  HLTPSD            BOOT RESTART HALT
         DATA     0,INITIAL         MON START ADR FOR DISCBOOT
         BOUND    8
IOXPSDS  XPSD,8   IOPSD
         XPSD,8   OCPSD
HLTPSD   :PSD     RES,(IA,BOOTHLT)
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'
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

