mtm$process_170_mtr_requests ident
         list      1,1,0
*copy ASMREGS
*copy OSA$DUAL_STATE_CONTROL_BLOCK
*copy OSA$EI_INTERFACE_CONSTANTS
*copy osa$dual_state_170_os_stack
*copy OSA$EI_CONSTANT_DEFINITIONS
*copy OSA$CYBIL_INTERFACE
*copy sya$xp_and_sf_constants
         PAGE
......................................................................
.
.         EIMT       - VE ERR0R INTERFACE
.
.         THIS PROCEDURE PROVIDES THE MONITOR MODE INTERFACE BETWEEN
.         THE NOS/VE AND C170 OPERATING SYSTEMS FOR ERROR PROCESSING
.         ON FOR THE C170 OPERATING SYSTEM.  THIS SOFTWARE SIMULATES
.         THE EFFECTS OF HARDWARE ERRORS ON C170 HARDWARE.  THIS DECK
.
. PROCEDURE mtp$process_170_mtr_requests ( req_code : mtt$ei_request_code;
.           mcr_valu : mtt$eim_mcr_value;
.           VAR err_flag : boolean);
.
. TYPE
.   mtt$ei_request_code = (mtc$eim_system_call, mtc$eim_unused_value,
.        mtc$eim_process_uncorrected_err),
.   mtt$ei_mcr_value : 0..0ffff(16)
.
......................................................................
         def       mtp$process_170_mtr_requests
         ref       dpp$process_scd_block
         ref       mtp$idle_180
         ref       mtv$ns_xp_p
         ref       mtv$nst_p
         ref       mtv$nos_jps
         ref       osp$a170_fatal_error
         ref       osp$abort_a170_job
         use       binding             .define binding section
nos_jps  address   p,mtv$nos_jps       .nos exchange package rma
osp_afe  address   p,osp$a170_fatal_error
osp_aaj  address   p,osp$abort_a170_job
mtp_hei  address   p,stop170
nos_xp   address   p,mtv$ns_xp_p             .nos/rs exchange package
pva_dscb address   p,mtv$nst_p           .dual state interface block
mtpeim   address   ce,mtp$process_170_mtr_requests
dpppsb   address   ce,dpp$process_scd_block
bs_idle  address   ce,mtp$idle_180
.
fatalerr equ       1
noerr    equ       0
.
amacscr  areg      5
.
.
.         setup registers for ei usage.
.
         use       code
BGNEIMT  BSS       0
         align     0,8
mtp$process_170_mtr_requests   procedur
req_code param     val,subrange,1
mcr_valu param     val,subrange,2
err_flag param     ref,boolean
.
         la        a6,A_bindin,nos_xp
         la        A_jps,a6,0          .pointer to nos exchange package
         lbyts,2   x1,A_jps,x0,xp_a0   .a170 working storage ring+segment#
         shfx      x1,x1,x0,32
         cpyxa     a_wrk,x1            .ei working storage PVA in AD
         la        a_nos,a_wrk,pva_of_os
         la        a_dscb,a_wrk,pva_of_dscb
         ploadx    x6,mcr_valu         .fetch mcr value
.
         ploadx    x1,req_code         .fetch request type
.
         cpyax     x4,A_jps
         purge     x4,4                .purge cache for C170 exchange package
         lbyts,1   x4,A_jps,x0,xp_vmid   .fetch VMID
         la        a7,a_bindin,osp_afe
         ente      x2,max_req
         brrge     x1,x2,pmce1         .if invalid request
         shfx      x1,x1,x0,1
         addpxq    a8,x1,req_tble
         brdir     a8,x0               .service request
.
req_tble bss       0                   .request branch table
         brreq     x0,x0,sys_call      .process system call
         brreq     x0,x0,store_err     .store error into dscb
         brreq     x0,x0,pec00         .process fatal error
max_req  equ       3
.
.        halt for invalid entry conditions.
.
pmce1    halt
         page
.
.        exit from eimt.
.
pmc      BSS       0
         ENTP      X1,1
         SBYTS,1   X1,A_jps,X0,xp_vmid .SET A170 VMID
         ENTP      X1,2                .TE=ON, TED=OFF
         SBYTS,1   X1,A_jps,X0,xp_tef  .SET TRAP ENABLES
pmce2    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
         ENTE      X1,NOERR
pmce3    bss       0
         pstorxp   x1,err_flag         .set error status
         RETURN                        .RETURN TO NVE MONITOR
.
.         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 IN STAND ALONE MODE, IN DUAL STATE JUST
.         SET FATAL ERROR STATUS IN THE CALL PARAMETER LIST.
.
.        a6 = pointer to message.
.        a_dscb = pointer to EI control block (EICB).

STOP170  BSS       0
         ENTE      X1,STP170S
         SBYTS,1   X1,A_dscb,X0,ds_stat+3 .SET FATAL C170 ERROR

.        Move the message to the EICB if the EICB level is greater than 3.

         lx        x6,a_dscb,d7ty
         ente      x1,eml              .set message length.
         isob      x6,x6,x0,52*64+5    .EICB version number.
         decx      x6,4
         brrgt     x0,x6,stop170_5     .If EICB version less than 4.

.        EICB version of 4 or greater, has space for a message in the EICB.  Move the
.        message to the EICB and set values to reflect message length and indicate
.        that there is a new message.

         cpyxx     x0,x1               .set source field length.
         movb,a6,x0  a_dscb,x1  1,9,0,0  1,9,0,dfcm+(1*8)  .move message to EICB.
         sbyts,2   x1,a_dscb,x0,dfcm+2 .set message length.

.        Update the processor and model number in the message stored in the EICB.

         entl      x0,r_pid
         entx      x1,c'C'             .processor 0 value.
         cpysx     x6,x0               .get processor number.
         entl      x0,r_eid
         addx      x6,x1               .set character for processor.
         cpysx     x0,x0               .element id.
         sbyts,1   x6,a_dscb,x0,dfcm+(1*8)+14  .update processor in message.
         isob      x6,x0,x0,(40*64)+3  .high order 4 bits of model number.
         entp      x2,9
         entx      x1,c'0'
         brrge     x2,x6,stop170_2     .if digit 0 through 9.
         decx      x6,10
         entx      x1,c'A'
stop170_2 bss      0
         addx      x6,x1               .convert digit to ascii.
         sbyts,1   x6,a_dscb,x0,dfcm+(1*8)+15  .update high order 4 bits of
                                       . model number.
         isob      x6,x0,x0,(44*64)+3  .low order 4 bits of model number.
         entx      x1,c'0'
         brrge     x2,x6,stop170_4     .if digit 0 through 9.
         decx      x6,10
         entx      x1,c'A'
stop170_4 bss      0
         addx      x6,x1               .convert digit to ascii.
         lbyts,2   x1,a_dscb,x0,dfcm+6  .set new message in EICB.
         sbyts,1   x6,a_dscb,x0,dfcm+(1*8)+16  .update low order 4 bits of
                                       . model number.
         incx      x1,1
         sbyts,2   x1,a_dscb,x0,dfcm+6 .indicate new message in EICB.
stop170_5 bss      0
         ENTE      X1,FATALERR
         BRREQ     X0,X0,pmce3         .RETURN TO NVE

eml      equ       24                  .error message length, bytes.

.        Define error message put in EICB.  The error codes, "damm" and "dabr'
.        are defined in deck cti$dft_analysis_codes.  If more messages are
.        added the codes should be added to that deck.  The fault symptom
.        code format is 'Temmxxx' with the following meaning:
.                   'T' - Environment interface (EI) identifier.
.                   'e' - Processor number, C through F.
.                   'mm' - Model number.
.                   'xxx' - Error code.

damm     vfd,eml*8  c'         ERR=Temm60D    '  .170 mcr fault in monitor mode.
dabr     vfd,eml*8  c'         ERR=Temm60E    '  .bad system request from 170.
         page
..
.
.        pec00 - process error conditions.
.
pec00    addpxq    a8,x0,pec005        .return address.
         ente      x1,mcr_mask-bit_58
         andx      x6,x1               .clear unimportant MCR bits
         addaq     a_wrk,a_wrk,sf_wrk
         brdir     a7,x0               .process 170 error condition.

pec005   bss       0
         brreq     x6,x0,pmc           .if not a 170 fatal error.
         addpxq    a6,x0,damm          .PVA of error message.
         brreq     x0,x0,stop170       .process 170 fatal error.

         page
..
.        store_err - update the error status in the dual state control block.
.
.        entry     x6 = error condition to set in the log
.
store_err bss      0
         entl      x0,r_pid            .get processor id
         cpysx     x4,x0
         addr      x4,x4               .multiply by 2
         addaq     a5,a_dscb,dscm
         cpyax     x1,a5
         purge     x1,3
         lbyts,1   x1,a5,x4,3
         brreq     x0,x1,sto01         .if no previous status
         brrge     x6,x1,sto02         .if previous error was worse
sto01    entp      x0,63-59            .Update the interface block
         lbset     x1,a5,x0
         brrne     x1,x0,sto01         .If interlock not set
         entp      x0,0
         sbyts,2   x6,a5,x4,2          .store status, clear retry count
         sbyts,1   x0,a5,x0,0
sto02    entp      x1,noerr
         brreq     x0,x0,pmce3         .return
         page
........................................................................
.
.         sys_call   - process requests from NOS trap handler.
.
.         this routine gains control as the result of a request from the
.         NOS trap handler to do something with NOS.  The requests are:
.         1 - Abort NOS job with specified error condition.
.         2 - Await recovery to NOS stand alone operation.
.         3 - Do nothing.
.         4 - set interface table address.
.
........................................................................
sys_call bss       0                   .process system call
         lx        x1,a_jps,xp_x0      .get request code
         la        a7,a_bindin,osp_aaj
         entp      X2,EIRQC
         BRREQ     X2,X1,pec00         .IF A170 ERROR REQUEST
.
.        check for 180 termination request.
.
         entp      x2,dstrtxr
         brreq     x2,x1,term180       .terminate the 180
         entp      x2,donthing
         brreq     x2,x1,pmce2         .do nothing
         addpxq    a6,x0,dabr          .PVA of error message.
         brreq     x0,x0,stop170       .bad request, terminate the 170.
         page

........................................................................
.
.        term180   - start the 180 termination sequence for NOS/VE.
.
.        This starts the NOS/VE termination sequence by setting the deadstart
.        flag in the environment interface control block (EICB) to a  1 if
.        running standalone.  If running dual state the ve_down flag is set
.        and the NVE subsystem will advance to termination and a request
.        is made to revert the CPU to 170 standalone which sets the deadstart
.        flag in the EICB.  SCI starts its termination sequence when it sees
.        the deadstart flag set.
.
.        Exit is to mtp$idle_180.
.
........................................................................

         align     0,8
         def       term180
term180  ALIAS     mtp$terminate_180
term180  bss       0
 .
         la        a6,A_bindin,nos_xp  .pointer to 170 OS xp pointer.
         la        A_jps,a6,0          .PVA of 170 OS xp.
         cpyax     x2,A_jps
         isom      x3,x0,2020(8),x0
         brxeq     x2,x3,term180_1     .If 170 OS not running, standalone.

.        Form PVA of 170 trap handlers stack.

         lbyts,2   x1,A_jps,x0,xp_a0   .EI working storage ring+segment#
         shfx      x3,x3,x0,-32        .16 bits of ones right justified.
         brxeq     x1,x3,term180_1     .If 170 OS not running, xp not initialized.

.        Dual state termination.

         shfx      x1,x1,x0,32
         cpyxa     a_wrk,x1
         isom      x1,x0,(33*100(8)+0)  .set bit 2**30, VE down flag.
         sx        x1,a_wrk,ve_down    .set ve down bit for trap handler
         brxeq     x0,x0,term180_2     .continue dual state termination sequence.
.
term180_1 bss      0
         entp      x1,1                .Set VE down flag, this informs SCI to
                                       . start VE termination.
         sbyts,4   x1,a_dscb,x0,ds_flag
term180_2 bss      0
         addaq     a0,a1,8           .Dont allow resume system
         entl      x0,0              .  commands.
         sx        x0,a1,0
         cpyaa     a6,a1               .parameter list address.
         ente      x0,0120(16)       .Call mtp$idle_180.
         callseg   bs_idle,a_bindin,a6
.
errhalt  brreq     x0,x0,errhalt
         page
ENDEIMT  EQU       $
         ORG       ENDEIMT
         END
