osm$os_environment_monitor IDENT
         list      1,1,0
         title     c'OS environment monitor routine'
         space     4
.        TRADE SECRET - PROPRIETARY NOTICE.
.        COPYRIGHT CONTROL DATA SYSTEMS INC. 1992
.        The material contained herein is the property of Control Data
.        Systems Inc and is intended soley for use in the  performance
.        of  contracted  Maintenance  under a Control Data maintenance
.        services agreement.  This material is proprietary to  Control
.        Data  Systems Inc  and  is  not to be disclosed other than to
.        employees  of  Control  Data  Systems Inc  or  other  persons
.        specifically authorized to have access to  this  material  in
.        accordance  with  the  terms and conditions of a Control Data
.        maintenance services agreement.
         page
*copy asmregs
*copy osa$dual_state_control_block
*copy osa$ei_interface_constants
*copy osa$ei_constant_definitions
*copy osa$ei_stack_frame
*copyc sya$xp_and_sf_constants
         page
C180EI   SECTION   working,read+execute+write,,0,8
         USE       C180EI
         space     4
..
.        monitor_mode_ei

         def       osp$monitor_mode_ei
osp$monitor_mode_ei   bss   0
         tpage     x1,a_jps
         ente      x2,r_jps            .jps register
         cpyxs     x1,x2               .update jps
         la        a_nos,a_static,pva_of_os
         PAGE
..
.        PMC        - PROCESS MONITOR CONDITION
.        THIS ROUTINE GAINS CONTROL AS  THE  RESULT  OF  AN  INTERRUPT
.        CONDITION  OCCURRING  IN  THE  C170  VIRTUAL  MACHINE.  THESE
.        INTERRUPTS CAUSE AN EXCHANGE TO OCCUR,  FORCING  THE  MACHINE
.        INTO  THE  MONITOR  STATE  OF THE C180 VIRTUAL MACHINE.  THIS
.        ROUTINE MUST DETERMINE WHAT ERROR CONDITION HAS OCCURRED  AND
.        SIMULATE THE ACTION THAT WOULD BE TAKEN BY C170 HARDWARE.
.
.        ENTRY-     REGISTERS AS DEFINED BY (TMXP)
.
.                   C170 ENVIORNMENT AT THE TIME OF INTERRUPT
.                   CONTAINED IN C180 EXCHANGE PACKAGE TJXP
.
.
PMC      BSS       0
         ENTP      X1,1
         sbyts,1   x1,a_jps,x0,xp_vmid
         entp      x1,2
         SBYTS,1   X1,a_jps,X0,xp_tef  .SET TRAP ENABLES
pmc01    BSS       0
         ENTP      X3,0                .CLEAR X3
         SBYTS,2   X3,a_jps,X0,xp_mcr  .CLEAR MCR
         SBYTS,2   X3,a_jps,X0,xp_ucr  .CLEAR UCR
pmc02    EXCHANGE                      .EXCHANGE TO C180 JOB PROCESS
         CPYAX     X1,a_jps
         PURGE     X1,7                .PURGE CACHE FOR EI SEGMENT
         la        a_dscb,a_static,pva_of_dscb  .fetch dscb pointer
         lbyts,1   x4,a_jps,x0,xp_vmid .get VMID from JPS
         LBYTS,2   X5,a_jps,X0,xp_mcr  .GET MCR OF PROCESS CAUSING  XJ

         shfx      x6,x5,x0,48
         addpxq    a8,x0,pmc03         .exit address if no retry.
         addpxq    a7,x0,pmc01         .exit address when retry
         ente      x3,c170_due
         brxgt     x0,x6,attempt_retry .if DUE set, attempt retry.
.
.        Check if cyber 180 system call.
.
pmc03    ente      x6,mcr_mask
         andx      x6,x5               .clear unimportant bits from MCR
         ente      x1,bit_58
         brrne     x1,x6,pec00         .if not a system call
         brrne     x4,x0,pmc01         .if not C180 system call, ignore interrupt
.
.        PROCESS EXCHANGE REQUEST AS PER REQUEST NUMBER IN JOB'S X0.
.
pmc04    LBYTS,8   X1,a_jps,X0,xp_x0   .GET REQUEST CODE
         ENTE      X2,EIRQC
         BRREQ     X2,X1,pec01         .IF A170 ERROR REQUEST
         ENTE      X2,MTRR#STD         .AWAIT C180 DST REQUEST CODE
         brreq     x2,x1,state_switch  .if deadstart request
         entp      x2,mtrr#ihf
         brreq     x2,x1,ihf           .if inject hardware fault request

.        The 'donothing' request is not checked for.  That and unknown monitor
.        requests fall through to 'stop170'.

.
.        THE  C170  VIRTUAL MACHINE WAS EXECUTING IN MONITOR MODE WHEN
.        THE EXIT CONDITION OCCURRED.  ALL C170 ERRORS  OF  THIS  TYPE
.        CAUSE THE C170 CPU TO STOP, AND THEREFORE WE WILL END IT HERE
.        BY HANGING THE C180 CPU.
.
STOP170  BSS       0
         la        a7,a_static,pva_halt_ei
         brdir     a7,x0
         page
..
.        attempt_retry - check if process is retryable and retry it if
.          retry count is not exceeded.
.
.        ENTRY -   A_DSCB = PVA of EICB.
.                  A_JPS = address of exchange package or stack frame save area that
.                          got DUE.
.                  A7 = return address if retry is attempted.
.                  A8 = return address if no retry attempted.
.                  X3 = source of DUE error, cyber 170 or cyber 180.
.
.

attempt_retry bss  0
         purge     x0,2                .purge all of cache to clear cache
.                                       parity errors.
         purge     x0,15               .purge all maps too.
         lx        x6,a_dscb,d7ty      .fetch 170 interface level
         isob      x6,x6,x0,52*64+5
         entp      x1,if_versn
         brrgt     x1,x6,rty04         .if interface level less than 2
         entp      x0,3                .process not damaged bit
         lbit      x6,a_jps,xp_pnd,x0
         entp      x2,0                .clear retry count
         brreq     x6,x0,rty02         .if process damaged
         incr      x3,retry_failed
         lx        x6,a_jps,xp_p/8*8
         lbyts,4   x1,a_wrk,x0,sf_retry+4  .byte offset of previous retry
         brrne     x1,x6,rty01         .if different pva
         lbyts,4   x2,a_wrk,x0,sf_retry  .current retry count
rty01    incr      x2,1                .increment retry count
         sbyts,4   x2,a_wrk,x0,sf_retry
         sbyts,4   x6,a_wrk,x0,sf_retry+4
         entp      x1,8                .maximum retry count
         brrgt     x2,x1,rty02         .if retry count exceeded
         cpyaa     a8,a7               .set retry return pva
         incr      x3,retry_due-retry_failed
.
rty02    entl      x0,11(16)           .get processor id
         cpysx     x6,x0
         addr      x6,x6               .multiply by 2
         addaq     a5,a_dscb,dscm
         cpyax     x1,a5
         purge     x1,3                .purge cache at error word in EICB.
         lbyts,1   x1,a5,x6,3
         brreq     x0,x1,rty03         .if no previous status
         brrge     x3,x1,rty04         .if previous error was worse
rty03    entp      x0,63-59            .Update the interface block
         lbset     x1,a5,x0
         brrne     x1,x0,rty03         .If interlock not set
         sbyts,1   x3,a_dscb,x6,dscm+3 .store status
         sbyts,1   x2,a_dscb,x6,dscm+2 .store retry count
         entp      x0,0
         sbyts,1   x0,a_dscb,x0,dscm   .clear interlock.
rty04    brdir     a8,x0               .continue processing
         page
..
.        state_switch - process a state switch to dual state mode.
.
.        This routine gains control as the result of a request from
.        a validated job in the C170 OS requesting a deadstart to dual
.        state mode.
.
state_switch bss   0
.
.        PROCESS THE HALT IN EI REQUEST FOR DUAL STATE DEADSTART.
.
         ADDAQ     a5,a_dscb,ds_flag
         CPYAX     X7,a5
         PURGE     X7,3
         tpage     x1,a_jps
         sbyts,4   x1,a_dscb,x0,os_jps .save jps rma
.
         ENTE      X5,CPUIDLS
         sbyts,1   x5,a_dscb,x0,ds_stat+3
         lbyts,4   xf,a5,x0,0          .fetch deadstart flag
         mulr      XF,XF
         sbyts,4   xf,a5,x0,0          .store response
.
idl01    PURGE     X7,3
         lbyts,4   x6,a5,x0,0
         BRRNE     X6,X0,idl01         .IF CONTINUE WITH IDLE
         entp      x1,1
         sbyts,1   x1,a_wrk,x0,xtra_xj .allow one extra state switch
         CPYAX     X7,a_jps
         PURGE     X7,3                .PURGE CACHE FOR EI SEGMENT
         BRREQ     X0,X0,pmc01         .RETURN TO EI JOB MODE
         page
..
.        PEC       - Process Error Conditions.
.
.
.
pec00    addpxq    a8,x0,pec02         .return address
         la        a7,a_static,pva_due_handler
         brdir     a7,x0
.
pec01    addpxq    a8,x0,pec02         .return address
         la        a7,a_static,pva_abort_job
         brdir     a7,x0
.
.        If this is concurrent C170 (both CPUs may run concurrently in C170
.        state), then the monitor mode interlock must be obtained before
.        continuing on.  The monitor mode interlock bit is defined either
.        in the segment descriptor table or in low core word 71(8), bit 4.
.        If the monitor mode interlock bit is defined in word 71(8), bit 4,
.        then bit 5 must first be checked to see if the second CPU is
.        actually in use.  Otherwise, setting the interlock bit could cause
.        problems in NOS/BE.
.
pec02    lbyts,1   x7,a_static,x0,dual_170
         brreq     x7,x0,pmc           .if not on a concurrent C170
         entp      x1,1
         brreq     x7,x1,pec04         .if monitor mode bit in SDT
.
.        The monitor mode bit is defined in low core word 71(8), bit 4.
.
         addaq     a7,a_nos,eicb_ptr*8
         entp      x0,5                .check bit 5 to see if second CPU in use
         lbit      x1,a7,0,x0
         brreq     x1,x0,pmc           .if second CPU not in use
pec03    entp      x0,4                .check bit 4
         lbset     x1,a7,x0
         brrne     x1,x0,pec03         .if monitor mode interlock not obtained
         PURGE     x0,2                 .purge all entries in cache
         brreq     x0,x0,pmc           .restart c170
.
.        The monitor mode bit is defined in the SDT.
.
pec04    lbyts,1   x7,a_jps,x0,xp_p+1  .fetch os segment number
         shfx      x7,x7,x0,3
         la        a7,a_static,pva_segment_table
         addax     a7,x7               .os segment table entry pva
pec05    entp      x0,2                .check bit 2
         lbset     x1,a7,x0
         brrne     x1,x0,pec05         .if monitor mode interlock not obtained


         brreq     x0,x0,pmc           .restart c170
         page
..
.        osp$mtr_trap_handler - processes traps in EI monitor mode.
.                  Currently the only errors processed are DUEs.
.                  Traps are disabled when trap handler is entered.
.

         def       osp$mtr_trap_handler
         align     0,16
osp$mtr_trap_handler bss 0
         entp      x0,0
         lbit      x3,a_psa,sfsa_mcr,x0  .DUE bit from MCR in SFSA.
         addpxq    a8,x0,trp02         .if no retry
         addpxq    a7,x0,trp01         .if attempt at retry
         brreq     x3,x0,trp02         .if not DUE.
         cpyaa     a_jps,a_psa         .address of SFSA with DUE.
         ente      x3,c180_due
         brreq     x0,x0,attempt_retry
.
trp01    entl      x0,r_ted
         cpyxs     x0,x0               .set tef and ted
         return
.
trp02    cpyaa     a0,a2               .update tos register
         pop
         entl      x0,r_te             .set tef
         cpyxs     x0,x0
         brreq     x0,x0,stop170       .bring things to a close
         page
..
.        IHF - inject hardware fault.  This procedure processes the inject
.        hardware fault monitor request to inject hardware faults in monitor
.        mode.
.
. DESIGN:
.   Special microcode is required that actually causes the desired hardware fault.
.   The special microcode recoginizes specific unimplemented instructions that are
.   issued and dependent on the J K fields causes a specific fault.  The J field
.   specifies the kind of hardware fault and the K field specifies an X register
.   that contains the RMA of a word in memory with a parity error.  This word in
.   memory has to be preconditioned with a parity error before IPL.
.
.        ENTRY:
.                  a_jps = PVA of job mode exchange package.
.                  X1 = Word 0 of monitor request.
.
.        INPUT (format of monitor request):
.                  Monitor request in X0 and X1 of job exchange package.
.                  X0 = 16/0
.                       8/traps enabled, = 0 implies traps disabled, = 1 implies traps
.                         enabled.
.                       8/fault kind.  A fault kind of 80(16) or greater is a request
.                         to perform some subfunction.  These subfunctions are:
.                         = 80(16) - clear synchronous bits in monitor mask register
.                                    of job exchange package.
.                       32/monitor request code.
.                  X1 = RMA of parity error.
.
.        EXIT:
.                  Specified fault is caused.
.                  Error status is returned in X2 of job exchange package.  Non zero
.                  value implies an error.
.

ihf      bss       0                   .Entry.
         lbyts,8   xe,a_jps,x0,xp_x0+8  .RMA of parity error.
         isob      x5,x1,x0,(24*64)+7  .Fault kind.
         ente      xa,80(16)
         isob      x6,x1,x0,(16*64)+7  .Traps enabled flag.
         brrge     x5,xa,ihf25         .If subfunction request.
         shfc      x5,x5,x0,1          .(jump table index)/2.
         ente      xa,ihfpl            .jump table length.
         entp      x7,1                .Set error status.
         brrgt     x5,xa,ihf20         .If unknown hardware fault kind.
ihf5     bss     0
         brrne     x6,x0,ihf10         .If traps enabled.
         entl      x0,r_td             .Disable traps.
         cpyxs     x0,x0
ihf10    bss       0
         addpxq    aa,x5,ihfp          .address in jump table to process
                                       . hardware fault kind.
         entp      x7,0                .Set no error.
         brdir     aa,x0               .cause specified hardware fault.

.        Fault injection processors return here if control returned after
.        error injected.

ihf15    bss       0
         brrne     x6,x0,ihf20         .If traps enabled.
         entl      x0,r_te             .Reenable traps.
         cpyxs     x0,x0
ihf20    bss       0
         sbyts,8   x7,a_jps,x0,xp_x0+(2*8)  .Return error status in X2.
         brreq     x0,x0,pmc01         .Return to job.

.        Process subfunction requests.
.
.        ENTRY:
.                  a_jps = PVA of job mode exchange package.
.                  X5 = subfunction request code.
.
.        EXIT:
.                  Subfunction processed.
.

ihf25    bss       0
         ente      xa,80(16)
         entp      x7,1                .Set error.
         brrne     x5,xa,ihf20         .If not known subfunction request.

.        Process subfunction to clear synchronous bits in calling task's
.        exchange package.

         lbyts,2   xa,a_jps,x0,xp_mm   .Monitor mask from job exchange package.
         ente      x9,ihfa
         inhx      xa,x9               .Clear synchronous bits in monitor mask.
         entp      x7,0                .Set no error.
         sbyts,2   xa,a_jps,x0,xp_mm   .Update monitor mask in job exchange package.
         brreq     x0,x0,ihf20         .Return.


.        Define synchronous bits in the monitor mask register.

ihfa     equ       bit_48+bit_49+bit_51+bit_52+bit_54+bit_55+bit_60+bit_61

.        Define a jump table for each hardware fault kind to cause.

ihfp     bss       0
         brreq     x0,x0,retry         .cause successful retry.
         brreq     x0,x0,exchange      .cause exchange fault.
         brreq     x0,x0,itrap         .cause trap fault.
         brreq     x0,x0,halt          .cause halt fault.
         brreq     x0,x0,pdm_halt      .cause pdm halt fault.
         brreq     x0,x0,swerr         .software error, error stop.
ihfpl    equ       $-ihfp              .length of jump table.

.        Cause successful retry error.

retry    bss     0
         vfd,32    0fd0e0000(16)       .condition microcode.
         vfd,32    0fe0e0000(16)       .cause hardware fault.
         brreq     x0,x0,ihf15         .Return.

.        Cause exchange error.

exchange bss     0
         vfd,32    0fd1e0000(16)       .condition microcode.
         vfd,32    0fe1e0000(16)       .cause hardware fault.
         brreq     x0,x0,ihf15         .Return.

.        Cause trap error.

itrap    bss     0
         vfd,32    0fd2e0000(16)       .condition microcode.
         vfd,32    0fe2e0000(16)       .cause hardware fault.
         brreq     x0,x0,ihf15         .Return.

.        Cause halt error.

halt     bss     0
         vfd,32    0fd3e0000(16)       .condition microcode.
         vfd,32    0fe3e0000(16)       .cause hardware fault.
         brreq     x0,x0,ihf15         .Return.

.        Cause PDM halt error.

pdm_halt bss     0
         vfd,32    0fd4e0000(16)       .condition microcode.
         vfd,32    0fe4e0000(16)       .cause hardware fault.
         brreq     x0,x0,ihf15         .Return.

.        Cause software error, error stop.

swerr    bss     0
         halt
         brreq     x0,x0,ihf15         .Return.

.
         END
