osm$os_trap_handler        IDENT
         list      1,1,0
         title     c'Environment Interface trap handler for the OS'
         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 osa$dft_constants
*copy sya$xp_and_sf_constants
         PAGE
C180EI   SECTION   working,read+execute+write,,0,8
         USE       C180EI
         space     4
...
.        trap       - TRAP INTERRUPT PROCESSOR.
.
.        THIS  SUBROUTINE  GAINS  CONTROL IN C180 PROGRAM STATE AS THE
.        RESULT OF A UCR TRAP FROM  A  C170  PROCESS.   THE  (UCR)  IS
.        AQUIRED  AND  A  TEST  IS  MADE  TO DETERMINE IF THE TRAP WAS
.        CAUSED BY AN UNIMPLEMENTED INSTRUCTION (BIT 49 IN  THE  UCR).
.        IF SO, A BRANCH IS MADE TO THE CMU INSTRUCTION SIMULATOR.  IF
.        NOT,  THE PROCESS INTERVAL TIMER (PIT) BIT IS TESTED.  IF THE
.        PIT BIT (BIT 51)  IS  CLEAR,  THE  TRAPPED  ROUTINE  WILL  BE
.        ABORTED  WITH  THE  GENERAL ERROR CODE OF 67(8).  IF SET, THE
.        (PIT) IS RESET TO ALL ONES AND A RETURN TO THE  C170  PROCESS
.        IS  ACCOMPLISHED.   THE CMU INSTRUCTION SIMULATOR AND THE AOR
.        ROUTINE RETURN TO THIS SUBROUTINE  AT  TAG  trap3  WHERE  THE
.        P-REGISTER  IS  INCREMENTED,  X0  IS  STORED,  AND THE PIT IS
.        RESET.  THE ROUTINE PII EXITS VIA TAG trap5 WHICH ONLY RESETS
.        THE PIT AND DOES NOT INCREMENT P.  AFTER  THE  TRAP  TO  THIS
.        SUBROUTINE  OCCURS TRAPS ARE AUTOMATICALLY DISABLED, AND THEY
.        REMAIN DISABLED UNTIL THE RETURN BACK TO THE C170 PROCESS.
.
.        ENTRY-     (A2) = PVA OF TRAPPED PROCESS STACK FRAME SAVE AREA.
.
.        EXIT-      NONE.
.
.
         ALIGN     0,8                 .FORCE WORD BOUNDRY
         def       osp$os_trap_handler
osp$os_trap_handler  bss  0
trap     ENTL      X0,0
         la        a_nos,a_static,pva_of_os .SET a_nos TO OS PVA
         la        a_dscb,a_static,pva_of_dscb .set a_dscb to the dual state control block
         SBYTS,3   X0,A2,X0,xp_cb0     .CLEAR C170 B0 REGISTER
         lbyts,3   x_rac,a_psa,x0,xp_rac
         shfx      x_rac,x_rac,x0,3
         cpyaa     a_rac,a_nos
         addax     a_rac,x_rac
         cpyax     x_flc,a4
         LBYTS,2   X1,A2,X0,xp_ucr     .GET USER CONDITION REGISTER
         shfc      x2,x1,x0,48         .UCR bit 48
         BRXGT     X0,x2,PIF           .IF privilaged instruction fault
         shfc      x2,x1,x0,49         .UCR bit 49
         BRXGT     X0,x2,CIS           .IF UNIMPLEMENTED INSTRUCTION
         shfc      x2,x1,x0,51         .UCR bit 51
         BRXGT     X0,x2,trap5         .IF PROCESS INTERVAL TIMER
         EIMTRCAL  EIRQC,GENCODE       .ABORT JOB WITH GENERAL ERROR
.
trap2    entp      x1,1                .set ve not active bit
         shfx      x1,x1,x0,30
         iorx      x0,x1
trap3    SX        X0,A2,xp_cx0        .STORE USER X0 REGISTER
trap4    LA        A8,A2,xp_p          .INCREMENT AND STORE P-REGISTER
         ADDAQ     A8,A8,8
         SA        A8,A2,xp_p
trap5    ENTL      X0,0C3(16)
         CPYXS     X0,X0               .SET TEF AND TED
         RETURN                        .RETURN WITH TRAPS ENABLED
*copy osi$c170_cmu_emulation
*copy osi$privilaged_170_instructions
.
.        request table for EI.
.
         fn017     rspt,read_set_pit   .read and set pit register
         fn017     cinv,bmi            .cache invalidate
         fn017     cpcm,minilink
         fn017     eccp,bcm            .block copy
         fn017     cecp,bcm
         fn017     dscb,sip            .store EI communications block pointer
         fn017     cpva,srapva
         fn017     rpva,fetch_pva
         fn017     scpu,hlt
         fn017     ihfu,ihf            .inject hardware fault
         fn017     3,downc180
         fn017     2002(8),status_ve
         fn017     end
.
         brreq     x0,x0,pif4          .invalid function
         page
.
.        srapva - set reference addresses.
.
.        entry:
.
.        TRAP      Xi,Xj,1002
.
.        Xi = address space descriptor in bits 56 to 63.
.           0 = illegal.
.           1 = Start of NOS/VE memory.
.           2 = Start of SSR.
.           3 = Start of Mainframe wired.
.           4 = Start of DFT buffer.  Bits 48 to 55 are an index into the first DFT
.                buffer of the buffer to dump.  If the DFT revision level is 3 or
.                less, the maximum buffer index is 3.  For DFT revision level 4 or
.                greater, the value in the "PO" field of the DFT control word is
.                used as the maximum buffer index.
.        Xj = Word address for the pointer.
.
srapva   bss       0
         lxi       x1,a_psa,x_reg1,xp_cx0 .fetch address space descriptor
         lxi       x2,a_psa,x_reg2,xp_cx0 .fetch word address
         cpyaa     a8,a_nos
         cpyxx     x4,x1
         shfx      x2,x2,x0,3          .byte address.
         isob      x1,x1,x0,7007(8)    .address space descriptor.
         addax     a8,x2
         shfx      x1,x1,x0,3
         brreq     x1,x0,iip           .if attempt to change DSCB
         ente      x3,pva_table_len
         brrge     x1,x3,iip           .if invalid address descriptor
         brreq     x2,x0,srapva15      .if clearing pva
         ente      x5,4*8
         brreq     x5,x1,srapva5       .if setting DFT buffer pva.
         lx        x3,a_dscb,d7cm+8
         isob      x4,x3,x0,2027(8)    .isolate fwa
         isob      x5,x3,x0,5027(8)    .isolate lwa
         shfx      x4,x4,x0,9+3
         shfx      x5,x5,x0,9+3
         brrge     x2,x5,aor           .if address too large
         brrgt     x4,x2,aor           .if address too small
         sai       a8,a_static,x1,pva_table
         brreq     x0,x0,trap2         .exit
.
.        Set pva of DFT buffer and DFT buffer index.
.
srapva5  bss       0
         lx        x5,a_dscb,d7ty      .170 OS type.
         isob      x4,x4,x0,6007(8)    .DFT buffer index.
         entp      x6,3
         isob      x5,x5,x0,6405(8)    .EICB version number.
         brrgt     x6,x5,iip           .if EICB version does not have DFT pointer.
.
.        Set pva of fixed portion of DFT buffer in all cases.
.
         lx        x3,a_dscb,dscm+(3*8)  .DFT OS buffer pointer, r-register format.
         cpyaa     a8,a_nos
         isob      x7,x3,x0,2017(8)    .r_upper.
         isob      x5,x3,x0,4017(8)    .r_lower.
         shfx      x7,x7,x0,12+6       .r_upper * 100(8).
         shfx      x5,x5,x0,6          .r_lower * 100(8).
         isob      x6,x3,x0,0413(8)    .DFT buffer offset relative to r pointer.
         iorx      x5,x7               .combine r_upper and r_lower.
         isob      x7,x3,x0,6017(8)    .length of DFT block.
         addr      x5,x6               .word offset of DFT block.
         brreq     x7,x0,iip           .if DFT block not defined.
         shfx      x5,x5,x0,3          .byte offset of DFT block.
         addax     a8,x5               .pva of fixed portion of DFT buffer.
         entp      x6,3                .initialize maximum DFT buffer index for
                                       .DFT revision 3.

         lbyts,1   x3,a8,x0,2          .DFT revision level.
         entp      x8,4
         brrgt     x8,x3,srapva7       .if DFT revision level < 4.
         lbyts,1   x6,a8,x0,0          .get maximum buffer index from po field.
srapva7  brrgt     x4,x6,iip           .if DFT buffer index exceeded.
         cpyaa     a6,a8
         brreq     x4,x0,srapva10      .if setting pva of fixed portion.
.
.        Set pva of specified DFT buffer.
.
         lxi       x3,a8,x4,0          .DFT buffer pointer, r-register format.
         cpyaa     a6,a_nos
         isob      x7,x3,x0,2017(8)    .r_upper.
         isob      x5,x3,x0,4017(8)    .r_lower.
         shfx      x7,x7,x0,12+6       .r_upper * 100(8).
         shfx      x5,x5,x0,6          .r_lower * 100(8).
         isob      x6,x3,x0,0413(8)    .DFT buffer offset relative to r pointer.
         iorx      x5,x7               .combine r_upper and r_lower.
         isob      x7,x3,x0,6017(8)    .length of DFT buffer.
         addr      x5,x6               .word offset of DFT block.
         shfx      x5,x5,x0,3          .byte offset of DFT buffer.
         addax     a6,x5               .pva of DFT buffer.
srapva10 bss       0
         brreq     x7,x0,iip           .if length = zero.
         brreq     x5,x0,iip           .if offset = zero.
         sai       a6,a_static,x1,pva_table  .set DFT buffer pointer.
         sbyts,2   x4,a_static,x1,pva_table-2  .set DFT buffer index.
         sa        a8,a_static,pva_of_first_dftb  .set pva of first DFT buffer.
         brreq     x0,x0,trap2         .exit
.
srapva15 sbyts,6   x2,a_static,x1,pva_table    .clear pva
         brreq     x0,x0,trap2         .exit
         page
...
.        SIP        -SET INTERFACE POINTER.
.
.        INSTRUCTION FORMAT.
.        017ij 00001 0000000000
.
.        (Xi) = ADDRESS OF DUAL STATE INTERFACE BLOCK.
.        (Xj) = IGNORED.
.
.        THE C170 OPERATING SYSTEM USES THIS REQUEST TO  TELL  EI  THE
.        LOCATION  OF THE DUAL STATE INTERFACE BLOCK.  THIS BLOCK MUST
.        BE DEFINED  TO  IF  OTHER  DUAL  STATE  REQUESTS  ARE  TO  BE
.        VALIDATED AND HONORED.
.
SIP      LXI       X3,A2,x_reg1,xp_cx0 .FETCH REGISTER WITH ADDRESS
         SHFX      X3,X3,X0,3          .FORM BYTE ADDRESS
         cpyaa     a_dscb,a_nos
         ADDAX     a_dscb,X3           .FORM PVA for the dual state control block
         SA        a_dscb,a_static,pva_of_dscb
         addpxq    a4,x0,ei_version
         la        a4,a4,0
         lbyts,1   x3,a4,x0,3          .EI version number.
         lbyts,3   x6,a4,x0,0          .version and level of interface block.
         shfx      x3,x3,x0,18
         iorx      x6,x3
         SX        X6,a_dscb,D8TY
         entp      x0,0
         sx        x0,a_dscb,d8jp      .clear nos/ve priority
         sx        x0,a_dscb,d8jp+8
         BRREQ     X0,X0,trap4         .EXIT AND INCREMENT P
         SPACE     10
..
.        HLT        - HALT PROCESSOR IN C180 MODE.
.
.        INSTRUCTION FORMAT.
.        017 ij 00002 0000000000
.
.        REQUEST  THE  EI  TO  IDLE IN C180 MODE.  Xi, Xj ARE IGNORED.
.        WHEN EI IS IDLED, NOS/VE WILL HALT THE PROCESSOR  AND  CHANGE
.        THE ENVIRONMENT TO USE THE NOS/VE TRAP HANDLER INSTEAD.  WHEN
.        NOS/VE IS BROUGHT DOWN, EI'S STACK FRAME IS RESET TO THE LAST
.        VALID C170 EXCHANGE PACKAGE AND EI IS RESTARTED USING THE MPS
.        PACKAGE.   EVENTUALLY  A RETURN IS MADE TO C170 STATE THROUGH
.        THIS ROUTINE.
.
HLT      BSS       0
         LA        a8,A2,xp_p          .INCREMENT AND STORE P-REGISTER
         ADDAQ     a8,a8,8
         SA        a8,A2,xp_p
         LBYTS,2   X4,A2,X0,xp_p       .SAVE RING/SEGM # OF P
         ENTE      X1,SRTDSTS          .SET D/S INITIATED STATUS
         sbyts,1   x1,a_dscb,x0,ds_stat+3
         ENTN      X1,1                .SET DEADSTART INITIATED
         sbyts,4   x1,a_dscb,x0,ds_flag
.
         lbyts,4   x1,a_dscb,x0,ve_sfsa
         brreq     x1,x0,hlt01         .if no RMA to copy to
         cpyaa     a8,a_nos
         addax     a8,x1               .form PVA of ve stack
         movb,a2,x0  a8,x1  0,0,25*8,0    0,9,25*8,0
         movb,a2,x0  a8,x1  0,0,27*8,25*8 0,9,27*8,25*8
hlt01    tpage     x1,a2
         sbyts,4   x1,a_dscb,x0,os_sfsa .save sfsa rma
         entp      x1,0
         sbyts,4   x1,a_dscb,x0,ve_jps  .ensure ve jps is cleared
.
         ente      x5,0c9(16)          .PIT register number
         cpysx     x3,x5               .save PIT
.
         EIMTRCAL  MTRR#STD,0,NOHLT
.
.        RETURN FROM 180 MONITOR MODE.
.
         CPYAX     X1,a_dscb
         PURGE     X1,3
         ADDXQ     X1,X1,D8SV
         PURGE     X1,3
         ENTP      X0,0
         sx        x0,a_dscb,d8jp      .clear c180 priority
         sx        x0,a_dscb,d8jp+8
.
.        Reset EI version number and version and level number of dual state control
.        block in the dual state control block.
.
         addpxq    a4,x0,ei_version
         la        a4,a4,0
         lbyts,1   x3,a4,x0,3          .EI version number.
         lbyts,3   x6,a4,x0,0          .version and level of interface block.
         shfx      x3,x3,x0,18
         iorx      x6,x3
         SX        X6,a_dscb,D8TY
.
         lx        x6,a_dscb,ve_sfsa
         brreq     x6,x0,hlt02         .if ve_jps is 0
         lbyts,2   x2,a_nos,x6,xp_pit  .upper 32 bits of pit
         lbyts,2   x3,a_nos,x6,xp_pit+8
         insb      x3,x2,x0,4017(8)
         cpyxs     x3,x5               .update PIT
         lbyts,1   x1,a_nos,x6,xp_vmid
         brrne     x1,x0,hlt03         .if vmid at ve_jps is 1
hlt02    shfc      x6,x6,x0,32
         brreq     x6,x0,hlt05         .if no sfsa
hlt03    cpyaa     a8,a_nos
         addax     a8,x6
         movb,a8,x0  a2,x1  0,0,16*8,17*8  0,0,16*8,17*8
.
         ente      x6,xp_x0
         entp      x5,0
hlt04    lbyts,6   x1,a8,x5,xp_p
         sbyts,6   x1,a2,x5,xp_p
         incr      x5,8
         brrne     x5,x6,hlt04         .if more A registers to copy
.
hlt05    SBYTS,2   X4,A2,X0,xp_p       .RESET RING NUMBER OF P
         SA        A2,A2,xp_a0         .RESET A0
         SA        A2,A2,xp_a0+8       .RESET A1
         ENTN      X1,1
         SBYTS,6   X1,A2,X0,xp_a0+16   .RESET A2
.
         BRREQ     X0,X0,trap5         .EXIT WITHOUT INCREMENT OF P
         PAGE
.        downc180   - TERMINATE NOSVE ENVIRONMENT.
.                  In EI this function only returns ve down status.
.
downc180 BSS       0
         brreq     x0,x0,trap2         .exit with ve down status
         space      4
.        status_ve - get the current running status of ve.
.
status_ve bss      0
         entp      x2,1                .return ve down
         shfx      x2,x2,x0,30
         sxi       x2,a_psa,x_reg1,xp_cx0
         brreq     x0,x0,trap2         .return ve down
.
         ref       osv$ei_version
ei_version  address  p,osv$ei_version
.
         end
