;       SCCSID = @(#)viosinit.asm	6.3 92/02/13
;# SCCSID = @(#)viosinit.asm	6.3 92/02/13
; ****************************************************************************
; *                                                                          *
; *                       IBM/Microsoft Confidential                         *
; *                                                                          *
; *                 Copyright (c) IBM Corporation  1987, 1990                *
; *                 Copyright (c) Microsoft Corp.  1987, 1990                *
; *                           All Rights Reserved                            *
; *                                                                          *
; ****************************************************************************
        PAGE    58,132
        SUBTTL  Shell initialization routine
        TITLE   VIOSINIT.ASM
;******************************************************************************
;*******   C H A N G E       H I S T O R Y   **********************************
;******************************************************************************
;$A0= tell sesmgr the address and element size of PAUSE_SEM data
;     9-12-86 (?.??)
;%A0= Use FS RAM sems instead of system sems
;     07-30-87
;P3839 = Cleanup (1.2 PTM 2502)
;@T2  = 04/03/89 TPL, Sizzle work, PTR B700???
;@T8  = 08/17/89 TPL, Compress registration mask for BVS, PTR B707524
;D549 = 11/07/89 WKB, DCR549 Changes
;@T52 = 01/15/90 TPL, DCR 704 work
;@C41 = 02/16/90 CJJ, B787589 Take out interface to SMG for paused semaphore
;@TL1 = 02/20/90 TPL, Add interface to VioHetInit to pass offset of killSG
;@T14 = 03/28/90 TPL, Remove duplication of functions
;B727127 = 09/21/91 WKB, Force setting of SYIsetmodefl, B727127
;@T80 = 02/06/92 TPL, Don't use the reserved register FS, B732479

.xlist
include error.inc                                                       ;P3839
include error2.inc                                                      ;P3839
include struc.inc
include infoseg.inc
include vioextrn.inc
include vioequ.inc
include viomac.inc                                                      ;P3839
include vioidata.inc
include viocdata.inc
.list
.386p                                                                   ;D549

EXTRN   suicide:NEAR
EXTRN   VIOINITSESSION:NEAR                                             ;D549

public  VIOSHELLINIT
public  VIOHETINIT

instance segment byte public 'data'     USE16                           ;D549
instance ends

common segment byte public 'far_data'   USE16                       ;D549;@T52
common ends

cseg    segment byte public 'code'      USE16                           ;D549
        assume  cs:cseg,ds:instance,es:common,ss:nothing
        page

        SUBTTL VIOSHELLINIT - VIOROUTER SHELL INITIALIZATION
        page
;/*********************** START OF SPECIFICATIONS ***********************/
;/* SUBROUTINE NAME: VIOSHELLINIT                                       */
;/*                                                                     */
;/* DESCRIPTIVE NAME: VIOROUTER shell initialization                    */
;/*                                                                     */
;/* FUNCTION: Record the shell PID.                                     */
;/*                                                                     */
;/* NOTES: This call is the first call to the VIOROUTER from the shell  */
;/*        process.                                                     */
;/*                                                                     */
;/* ENTRY POINT: VIOSHELLINIT                                           */
;/*     LINKAGE: FAR CALL (undocumented call from shell)                */
;/*                                                                     */
;/* INPUT: SEL:OFF to DWORD,WORD sesmgr data area                       */
;/*                                                                     */
;/* EXIT-NORMAL: AX = NO_ERROR                                          */
;/*                                                                     */
;/* EXIT-ERROR: N/A                                                     */
;/*                                                                     */
;/* EFFECTS: None.                                                      */
;/*                                                                     */
;/* INTERNAL                                                            */
;/* REFERENCES: SHELLPID - PID of shell process                         */
;/*             LDTINFO - local info data segment selector              */
;/*             GDTINFO - global info data segment selector             */
;/*             currPID - current process PID                           */
;/*   ROUTINES: GETINFOSEGS - get selectors for information segments    */
;/*                                                                     */
;/* EXTERNAL                                                            */
;/* REFERENCES: None.                                                   */
;/*   ROUTINES: None.                                                   */
;/*********************** END OF SPECIFICATIONS *************************/

VIOSHELLINIT proc far

   push fc_shellinit    ;VIO function code (for subsystem)       ;P3839 ;$B7I
   push 0000H           ;dummy IP for BVS expected stack frame          ;$B7I

   push  ds             ;save DS                                        ;P3839
   enter 8,0            ;setup BP and allocate 4 words local storage    ;P3839
   push  es             ;save registers                                 ;P3839
   push  gs             ;save registers                                 ;@T80
   pusha                ;                                               ;P3839

   mov  ax,instance     ;DS <-- instance data selector
   mov  ds,ax           ;

   mov  es,ds:ldtinfo           ;currSG <-- current screen group        ;$A12I
   mov  ax,es:[LIS_CurScrnGrp]  ;                                       ;$A12I
   mov  ds:currSG,ax            ;                                       ;$A12I
   mov  ax,es:[LIS_CurProcID]   ;currPID <-- current process PID           ;D549

   mov  bx,common               ;ES <-- COMMON                         ;@T2;D549
   mov  es,bx                                                          ;@T2;D549
   mov  es:SHELLPID,ax          ;                                ;$B7M;D549,@T14
   mov  es:SYIsetmodefl,1       ;force the setting of this flag as     ;B727127
                                ;there may have been no device         ;B727127
                                ;driver output msgs to do so.          ;B727127

   ;***********************************************************************
   ; Internal interface to Session Manager - store the address of SG 0
   ;     paused semaphore (SGCB ptr points to SG 0 until DOSSMGETSGCB)
   ;***********************************************************************
;@C41   les     di,dword ptr [bp].rout_parm1 ;Ptr to sem table ptr    ;P3839 ;$A0I

;@C41   mov     ax,VIO_paused        ;AX <-- SGCB[0].VIO_paused offset       ;D549
;@C41   add     ax,word ptr ds:SGCB                                          ;D549
;@C41   stosw                        ;                                       ;$A0I

;@C41   mov     ax,word ptr ds:SGCB+2        ;SGCB selector                  ;D549
;@C41   stosw                        ;                                       ;$A0I

   push ds                      ;sel:off to SGCB address                ;D549
   push offset SGCB             ;  (returned)                      ;D549;@T52
   push ds:currSG               ;                                       ;D549
   push Look_up_SGID            ;                                       ;D549
   call DOSSMGETSGCB            ;get addressability to Screen Grp CB    ;D549

   .if <zero ax>                ;no error returned                      ;D549
     lgs  bx,ds:SGCB            ;load gs:[bx] with SGCB ptr             ;@T80

     mov  ax,bx                 ;AX <-- SGDATA[currSG].fsRAMsem         ;D549
     add  ax,VIO_fsRAMsem       ;                                       ;D549
     mov  ds:fsRAMoff,ax        ;initialize fsRAMoff for SG             ;D549
     mov  ds:fsRAMsel,gs        ;semaphore                              ;@T80

     call VIOINITSESSION        ;initialize SGCB                        ;D549
                                                                        ;$B7M
     popa                                                               ;P3839
     pop   gs                                                           ;@T80
     pop   es                                                           ;P3839
     leave                                                              ;P3839

     mov  ax,ds:avs_bvs_bits                                            ;@T8
     call dword ptr ds:bvs_off
   .endif                                                               ;D549

   pop  ds                      ;restore caller's DS                    ;$B7C
   add  sp,4                    ;                                       ;@T2
   ret

;@C41   ret  4                       ;return and pop parameters              ;$B7C

VIOSHELLINIT endp

        page
;/*********************** START OF SPECIFICATIONS ***********************/
;/* SUBROUTINE NAME: VIOHETINIT                                         */
;/*                                                                     */
;/* DESCRIPTIVE NAME: VIOROUTER Hard Error Task initialization          */
;/*                                                                     */
;/* FUNCTION: Record the HET PID.                                       */
;/*     (Added by DRT for purpose of supporting the splitting           */
;/*      of the hard error processing from the session manager.)        */
;/*                                                                     */
;/* NOTES: This call is the first call to the VIOROUTER from the HET    */
;/*        process.                                                     */
;/*                                                                     */
;/* ENTRY POINT: VIOHETINIT                                             */
;/*     LINKAGE: FAR CALL (undocumented call from HET)                  */
;/*                                                                     */
;/* INPUT: None.                                                        */
;/*                                                                     */
;/* EXIT-NORMAL: AX = NO_ERROR                                          */
;/*                                                                     */
;/* EXIT-ERROR: N/A                                                     */
;/*                                                                     */
;/* EFFECTS: None.                                                      */
;/*                                                                     */
;/* INTERNAL                                                            */
;/* REFERENCES: hetpid - PID of hard error process                      */
;/*                                                                     */
;/* EXTERNAL                                                            */
;/* REFERENCES: None.                                                   */
;/*   ROUTINES: None.                                                   */
;/*********************** END OF SPECIFICATIONS *************************/

VIOHETINIT proc far
   enter 0,0                                                            ;@TL1
   push ds              ;save DS
   push es              ;save registers
   push bx                                                              ;@TL1

   mov  ax,instance     ;DS <-- INSTANCE data selector
   mov  ds,ax           ;
   mov  ax,common       ;ES <-- COMMON data selector
   mov  es,ax           ;

   mov  ax,ds:currpid           ;record PID of hard-error-task

   .if <es:HETPID eq 0>
     mov  es:HETPID,ax
     lds  bx,ss:[bp+6]
     mov  word ptr ds:[bx],offset killSG                                ;@TL1
     mov  word ptr ds:[bx+2],es                                         ;@TL1
     xor  ax,ax
   .else
     mov  ax,-1
   .endif

   pop  bx                                                              ;@TL1
   pop  es                      ;
   pop  ds                      ;
   leave                                                                ;@TL1
   ret  4                       ;return and pop parameters              ;@TL1
VIOHETINIT   endp


cseg ends
     end
