;       SCCSID = @(#)iniproc3.asm       6.26 94/07/22
        page    78,132
        title   iniproc3, System Initialization Process - Part 3


SCCSID  equ     "@(#)iniproc3.asm       6.26 94/07/22"

;                 IBM Confidential
;
;           Copyright (c) IBM Corporation  1987, 1994
;                     All Rights Reserved

;
; SOURCE FILE NAME: iniproc3
;
; DESCRIPTIVE NAME: System Initialization Process - Part 3
;
; FUNCTION: To complete initialization of the CP/DOS system
;
; NOTES:
;   DEPENDENCIES: None
;   RESTRICTIONS: None
;
; ENTRY POINTS:
;
;
;       Change History
;
;       90474   07/22/94   ACW  Add UNILOCK support (added entire file)
;                               From Sam Detweiler
;

        subttl  Data Structures
        page
        .xlist
        .xcref
        .sall
        include basemid.inc           ; Message IDs
        include utilmd11.inc          ; #73958 added new error msg. M. Violante
        include utilmd17.inc          ; MSG_REPLACEMENT_STRING
        include devsym.inc            ; Device driver packets
        include basemaca.inc          ; CP/DOS macros
        include fnoinit.inc
        include osmaca.inc            ; CP/DOS macros
        include dosseg.inc            ; CP/DOS segments
        INCL_ERRORS equ 1             ; for bseerr.inc
        include bseerr.inc            ; error codes
        include infoseg.inc           ; System Information Segment
        include inicfg.inc            ; CONFIG.SYS data packets
        include inisms.inc            ; SysInit Message Segment
        include mi.inc
        include sicg.inc              ; SICG packets
        include struc.inc             ; Structured assembler macros
        include fsc.inc               ; for FSD loading
        include ldrvars.inc           ; EQUates for EXT_DEVICE, EXT_FSD
        include curdir.inc            ; Include MAXPATHLEN
        include tkexport.inc
        include ldrxport.inc
        include vmowner.inc
        INCL_DOSSESMGR equ 1          ; #73958 added PM control.    M. Violante
        include bsedos.inc            ; #73958 added PM control.    M. Violante
        include inialtf1.inc
        .list
        .cref
.386p

;       ModName  , FNO_INIPROC3_ASM

        ReferInitGlobal pDosOpen,DWORD
        ReferInitGlobal pDosRead,DWORD
        ReferInitGlobal pDosWrite,DWORD
        ReferInitGlobal pDosClose,DWORD
        ReferInitGlobal pDosAllocSeg,DWORD
        ReferInitGlobal pDosFreeSeg,DWORD
        ReferInitGlobal pDosExecPgm,DWORD
        ReferInitGlobal pDosExit,DWORD
        ReferInitGlobal pDosChgFilePtr,DWORD
        ReferInitGlobal pDosDevIOCtl2,DWORD

INITDATA segment
CurDirPrefix DB      '\OS2\DLL\',  00H
DLLExtension DB      '.dll',  00H
DDFileName DB      '_!.dat',  00H
IDSTRING        DB      'LOCK',  00H
        ORG     $+1
RUNPGM  DB      00H
        DB      259 DUP(0)
INITDATA ends


        FARCODE INITR3
.386p
INITR3CODE segment
        assume  ds:DOSINITDATA,es:nothing
        PUBLIC  _VerifySignature
;_VerifySignature        PROC FAR
Procedure _VerifySignature
        enter   300,0
        push    di
        push    si
;       work = 6
;       DDNameBuffer = 10
;       DDFileNameBuffer = 14
;       workbuff = -300
;       tempwork = -40
;       rc = -4
;       handle = -12
;       handle1 = -16
;       Action = -18
;       bytesread = -14
;       i = -4
;       j = -2
;       register si = q
;       key = -2
;       Checksum = -8
;       temp = -1
;       Size = -22
;       junk = -278
;       FileSize = -30
;       Data = -26
;       p = -10
;       save = -316
; Line 126
        lea     ax,WORD PTR [bp-300]    ;workbuff
        mov     di,ax
        mov     si,OFFSET CurDirPrefix
        push    ss
        pop     es
        mov     cx,5    ;; mov 5 words of path prefix
        rep movsw
;        movsb
; Line 127
        mov     bx,ax
        mov     si,ss
        push    si
        push    ds
        push    si
        mov     si,ax
        pop     ds
        les     di,DWORD PTR [bp+4]     ;work
        mov     cx,-1
        xor     ax,ax
        repnz   scasb
        not     cx
        sub     di,cx
        push    cx
        xchg    di,si
        push    ds
        push    es
        pop     ds
        pop     es
        mov     cx,-1
        repnz   scasb
        dec     di
        pop     cx
        shr     cx,1
        rep     movsw
        adc     cx,cx
        rep     movsb
        pop     ds
        pop     si
; Line 128
        mov     di,ss
        push    di
        push    si
        push    ds
        push    di
        mov     di,OFFSET DLLExtension
        mov     si,bx
        push    ds
        pop     es
        pop     ds
        mov     cx,-1
        repnz   scasb
        not     cx
        sub     di,cx
        push    cx
        xchg    di,si
        push    ds
        push    es
        pop     ds
        pop     es
        mov     cx,-1
        repnz   scasb
        dec     di
        pop     cx
        shr     cx,1
        rep     movsw
        adc     cx,cx
        rep     movsb
        pop     ds
        pop     si
        pop     di
; Line 129
        push    di
        push    si
        push    ds
        lea     si,WORD PTR [bp-40]     ;tempwork
        push    ss
        pop     ds
        les     di,DWORD PTR [bp+4]     ;work
        mov     cx,-1
        xor     ax,ax
        repnz   scasb
        not     cx
        sub     di,cx
        xchg    di,si
        push    ds
        push    es
        pop     ds
        pop     es
        shr     cx,1
        rep     movsw
        adc     cx,cx
        rep     movsb
        pop     ds
        pop     si
        pop     di
; Line 134
        push    ss
        push    bx
        lea     ax,WORD PTR [bp-12]     ;handle
        push    ss
        push    ax
        lea     ax,WORD PTR [bp-18]     ;Action
        push    ss
        push    ax
        push    0
        push    0
        sub     ax,ax
        mov     WORD PTR [bp-4],ax      ;rc
        push    ax
        push    1
        push    64
        push    ax
        push    ax
        call    DWORD PTR pDosOpen
        or      ax,ax
        je      $JCC193
        jmp     $L20008
$JCC193:
; Line 136
        push    WORD PTR [bp-12]        ;handle
        push    -1
        push    -4
        push    2
        lea     ax,WORD PTR [bp-30]     ;FileSize
        push    ss
        push    ax
        call    DWORD PTR pDosChgFilePtr
        mov     si,ax
        or      si,si
        je      $JCC225
        jmp     $I1341
$JCC225:
; Line 138
        push    WORD PTR [bp-12]        ;handle
        lea     ax,WORD PTR [bp-22]     ;Size
        push    ss
        push    ax
        push    4
        lea     ax,WORD PTR [bp-14]     ;bytesread
        push    ss
        push    ax
        call    DWORD PTR pDosRead
        mov     si,ax
        or      si,si
        je      $JCC258
        jmp     $I1341
$JCC258:
; Line 141
        mov     ax,WORD PTR [bp-30]     ;FileSize
        mov     dx,WORD PTR [bp-28]
        cmp     WORD PTR [bp-20],dx
        jbe     $JCC272
        jmp     $I1343
$JCC272:
        jb      $L20013
        cmp     WORD PTR [bp-22],ax     ;Size
        jb      $JCC282
        jmp     $I1343
$JCC282:
$L20013:
        cmp     WORD PTR [bp-22],20     ;Size
        jne     $L20014
        cmp     WORD PTR [bp-20],si
        je      $L20015
$L20014:
        cmp     WORD PTR [bp-20],si
        jne     $L20015
        cmp     WORD PTR [bp-22],410    ;Size
        ja      $JCC308
        jmp     $I1343
$JCC308:
$L20015:
; Line 143
        push    WORD PTR [bp-12]        ;handle
        mov     ax,WORD PTR [bp-22]     ;Size
        mov     dx,WORD PTR [bp-20]
        neg     ax
        adc     dx,si
        neg     dx
        push    dx
        push    ax
        push    2
        lea     ax,WORD PTR [bp-30]     ;FileSize
        push    ss
        push    ax
        call    DWORD PTR pDosChgFilePtr
; Line 144
        sub     ax,ax
        mov     WORD PTR [bp-24],ax
        mov     WORD PTR [bp-26],ax     ;Data
; Line 145
        push    WORD PTR [bp-22]        ;Size
        lea     ax,WORD PTR [bp-24]
        push    ss
        push    ax
        push    0
        call    DWORD PTR pDosAllocSeg
        mov     si,ax
        or      si,si
        je      $JCC377
        jmp     $I1341
$JCC377:
; Line 147
        push    WORD PTR [bp-12]        ;handle
        push    WORD PTR [bp-24]
        push    WORD PTR [bp-26]        ;Data
        push    WORD PTR [bp-22]        ;Size
        lea     ax,WORD PTR [bp-14]     ;bytesread
        push    ss
        push    ax
        call    DWORD PTR pDosRead
        mov     si,ax
        or      si,si
        je      $JCC412
        jmp     $I1346
$JCC412:
; Line 150
        mov     BYTE PTR [bp-2],0       ;j
; Line 152
        lea     ax,WORD PTR [bp-22]     ;Size
        mov     WORD PTR [bp-10],ax     ;p
        mov     WORD PTR [bp-8],ss      ;Checksum
; Line 153
        mov     si,3
$F1347:
; Line 155
        lea     bx,WORD PTR [bp-22][si]
        mov     al,BYTE PTR ss:[bx]
        xor     BYTE PTR [bp-2],al      ;j
        dec     si
        jns     $F1347
; Line 160
        push    ds
        lea     si,WORD PTR [bp-40]     ;tempwork
        push    ss
        pop     ds
        les     di,DWORD PTR [bp+4]     ;work
        mov     cx,-1
        xor     ax,ax
        repnz   scasb
        not     cx
        sub     di,cx
        xchg    di,si
        push    ds
        push    es
        pop     ds
        pop     es
        shr     cx,1
        rep     movsw
        adc     cx,cx
        rep     movsb
        pop     ds
; Line 161
        mov     WORD PTR [bp-4],ax      ;rc
        lea     ax,WORD PTR [bp-40]     ;tempwork
        mov     dx,ax
        mov     di,ax
        push    ss
        pop     es
        mov     cx,-1
        xor     ax,ax
        repnz   scasb
        not     cx
        dec     cx
        je      $FB1352
        mov     si,WORD PTR [bp-4]      ;rc
$F1350:
; Line 162
        mov     al,BYTE PTR [bp-40][si]
        xor     BYTE PTR [bp-2],al      ;j
        lea     ax,WORD PTR [bp-40]     ;tempwork
        mov     dx,ax
        mov     di,ax
        mov     cx,-1
        xor     ax,ax
        repnz   scasb
        not     cx
        dec     cx
        inc     si
        cmp     cx,si
        ja      $F1350
$FB1352:
; Line 163
        mov     al,BYTE PTR [bp-2]      ;j
        mov     BYTE PTR [bp-1],al      ;temp
; Line 164
        sub     si,si
        mov     es,WORD PTR [bp-24]
$F1353:
; Line 166
        mov     bx,WORD PTR [bp-26]     ;Data
        mov     al,BYTE PTR es:[bx][si]
        xor     BYTE PTR [bp-1],al      ;temp
; Line 167
        mov     al,BYTE PTR [bp-2]      ;j
        xor     BYTE PTR es:[bx][si],al
; Line 168
        mov     al,BYTE PTR [bp-1]      ;temp
        mov     BYTE PTR [bp-2],al      ;j
        inc     si
        cmp     si,5
        jb      $F1353
; Line 172
        les     bx,DWORD PTR [bp-26]    ;Data
        cmp     BYTE PTR es:[bx][si],al
        je      $JCC579
        jmp     $I1356
$JCC579:
; Line 174
        mov     di,OFFSET IDSTRING
        push    ds
        pop     es
        push    ds
        lds     si,DWORD PTR [bp-26]    ;Data
        mov     cx,-1
        xor     ax,ax
        repnz   scasb
        not     cx
        sub     di,cx
        repz    cmpsb
        je      $L20017
        sbb     ax,ax
        sbb     ax,-1
$L20017:
        pop     ds
        or      ax,ax
        je      $JCC616
        jmp     $I1357
$JCC616:
; Line 176
        mov     si,1
; Line 177
        cmp     WORD PTR [bp-20],ax
        jne     $L20018
        cmp     WORD PTR [bp-22],410    ;Size
        ja      $JCC634
        jmp     $I1346
$JCC634:
$L20018:
; Line 181
        mov     al,BYTE PTR [bp-2]      ;j
        mov     BYTE PTR [bp-1],al      ;temp
; Line 182
        mov     si,6
        mov     ax,WORD PTR [bp-22]     ;Size
        mov     dx,WORD PTR [bp-20]
        sub     ax,5
        sbb     dx,0
        or      dx,dx
        jne     $L20019
        cmp     ax,si
        jbe     $L20020
$L20019:
; Line 184
        les     bx,DWORD PTR [bp-26]    ;Data
        mov     al,BYTE PTR es:[bx][si]
        xor     BYTE PTR [bp-1],al      ;temp
; Line 185
        mov     al,BYTE PTR [bp-2]      ;j
        xor     BYTE PTR es:[bx][si],al
; Line 186
        mov     al,BYTE PTR [bp-1]      ;temp
        mov     BYTE PTR [bp-2],al      ;j
        mov     ax,WORD PTR [bp-22]     ;Size
        mov     dx,WORD PTR [bp-20]
        sub     ax,5
        sbb     dx,0
        inc     si
        sub     cx,cx
        cmp     dx,cx
        ja      $L20019
        jb      $L20020
        cmp     ax,si
        ja      $L20019
$L20020:
; Line 190
        mov     al,BYTE PTR [bp-2]      ;j
        les     bx,DWORD PTR [bp-26]    ;Data
        cmp     BYTE PTR es:[bx][si],al
        je      $JCC723
        jmp     $I1356
$JCC723:
; Line 195
        mov     ax,bx
        mov     dx,es
        add     ax,6
        mov     di,ax
        push    ds
        lds     si,DWORD PTR [bp+8]    ;DDNameBuffer
        mov     cx,-1
        xor     ax,ax
        repnz   scasb
        not     cx
        sub     di,cx
        xchg    di,si
        push    ds
        push    es
        pop     ds
        pop     es
        shr     cx,1
        rep     movsw
        adc     cx,cx
        rep     movsb
        pop     ds
; Line 196
        mov     WORD PTR [bp-2],15      ;j
; Line 197
        mov     si,OFFSET CurDirPrefix
        les     di,DWORD PTR [bp+12]    ;DDFileNameBuffer
        mov cx,5
        rep movsw
;        movsb
; Line 198
        mov     di,OFFSET DDFileName
        push    ds
        pop     es
        push    ds
        lds     si,DWORD PTR [bp+12]    ;DDFileNameBuffer
        mov     cx,-1
        repnz   scasb
        not     cx
        sub     di,cx
        mov     bx,cx
        xchg    di,si
        push    ds
        push    es
        pop     ds
        pop     es
        mov     cx,-1
        repnz   scasb
        dec     di
        mov     cx,bx
        shr     cx,1
        rep     movsw
        adc     cx,cx
        rep     movsb
        pop     ds
; Line 203
        push    WORD PTR [bp+14]
        push    WORD PTR [bp+12]        ;DDFileNameBuffer
        lea     ax,WORD PTR [bp-16]     ;handle1
        push    ss
        push    ax
        lea     ax,WORD PTR [bp-18]     ;Action
        push    ss
        push    ax
        push    0
        push    0
        push    2
        push    18
        push    18
        push    0
        push    0
        call    DWORD PTR pDosOpen
        or      ax,ax
        jne     $I1356
; Line 205
        mov     si,1
; Line 206
        push    WORD PTR [bp-16]        ;handle1
        mov     ax,WORD PTR [bp-26]     ;Data
        mov     dx,WORD PTR [bp-24]
        add     ax,15
        push    dx
        push    ax
        mov     ax,WORD PTR [bp-22]     ;Size
        sub     ax,20
        push    ax
        lea     ax,WORD PTR [bp-14]     ;bytesread
        push    ss
        push    ax
        call    DWORD PTR pDosWrite
; Line 207
        push    WORD PTR [bp-16]        ;handle1
        call    DWORD PTR pDosClose
; Line 209
        jmp     SHORT $I1346
$L20008:
        mov     si,WORD PTR [bp-4]      ;rc
        jmp     SHORT $I1340
        nop
$I1356:
; Line 228
        mov     si,16
; Line 231
$I1346:
        mov     ax,WORD PTR [bp-26]     ;Data
        inc     ax
        push    ax
        call    DWORD PTR pDosFreeSeg
; Line 234
        jmp     SHORT $I1341
        nop
$I1357:
; Line 223
        sub     si,si
; Line 226
        jmp     SHORT $I1346
$I1343:
; Line 236
        sub     si,si
; Line 240
$I1341:
        push    WORD PTR [bp-12]        ;handle
        call    DWORD PTR pDosClose
; Line 242
$I1340:
        mov     ax,si
; Line 243
        pop     si
        pop     di
        leave
        ret

;_VerifySignature        ENDP

EndProc _VerifySignature

; Line 245
        PUBLIC  _RunningLocked
Procedure _RunningLocked
        enter   6,0
        push    di
        push    si
;       argc = 6
;       argv = 8
;       DDNameBuffer = 12
;       DDFileNameBuffer = 16
;       States = -6
;       register dx = rc
;       register si = j
; Line 247
        sub     si,si
        mov     bx,si
        cmp     WORD PTR [bp+4],bx      ;argc
        je      $FB1382
        mov     WORD PTR [bp-6],bx      ;States
        mov     ax,WORD PTR [bp+6]      ;argv
        mov     dx,WORD PTR [bp+8]
        mov     di,ax
        mov     WORD PTR [bp-2],dx
$F1380:
; Line 250
        push    WORD PTR [bp+16]
        push    WORD PTR [bp+14]        ;DDFileNameBuffer
        push    WORD PTR [bp+12]
        push    WORD PTR [bp+10]        ;DDNameBuffer
        mov     es,WORD PTR [bp-2]
        push    WORD PTR es:[di+2]
        push    WORD PTR es:[di]
        call    _VerifySignature
        add     sp,12
        mov     cx,si
        shl     ax,cl
        or      WORD PTR [bp-6],ax      ;States
        test    BYTE PTR [bp-6],112     ;States
        jne     $L20025
; Line 247
        add     di,4
        mov     ax,WORD PTR [bp-2]
        inc     si
        cmp     WORD PTR [bp+4],si      ;argc
        ja      $F1380
        mov     bx,WORD PTR [bp-6]      ;States
$FB1382:
; Line 273
        mov     al,bl
        and     al,7
        je      $I1384
        mov     al,bl
        and     al,7
        cmp     al,7
        je      $I1385
        mov     dx,1
        jmp     SHORT $I1387
$L20025:
; Line 253
        mov     ax,1
        jmp     SHORT $EX1376
; Line 255
        nop
$I1385:
        mov     dx,2
        jmp     SHORT $I1387
        nop
$I1384:
        sub     dx,dx
$I1387:
        mov     ax,dx
; Line 274
$EX1376:
        pop     si
        pop     di
        leave
        ret

EndProc _RunningLocked
; Line 280
        PUBLIC  _LockProblem
Procedure _LockProblem
; Line 283
        push    0
        push    1
        call    DWORD PTR pDosExit
; Line 285
        ret

EndProc _LockProblem
; Line 288
        PUBLIC  _VerifyDDLoaded
Procedure _VerifyDDLoaded
        enter   4,0
        push    si
;       DDNameBuffer = 6
;       handle = -2
;       register si = rc
;       act = -4
; Line 299
        push    WORD PTR [bp+6]
        push    WORD PTR [bp+4] ;DDNameBuffer
        lea     ax,WORD PTR [bp-2]      ;handle
        push    ss
        push    ax
        lea     ax,WORD PTR [bp-4]      ;act
        push    ss
        push    ax
        push    0
        push    0
        push    0
        push    1
        push    146
        push    0
        push    0
        call    DWORD PTR pDosOpen
        mov     si,ax
        or      si,si
        jne     $I1396
; Line 301
        push    ds
        push    OFFSET RUNPGM
        push    260
        push    si
        push    si
        push    si
        push    1
        push    128
        push    WORD PTR [bp-2] ;handle
        call    DWORD PTR pDosDevIOCtl2
        mov     si,ax
; Line 302
        push    WORD PTR [bp-2] ;handle
        call    DWORD PTR pDosClose
; Line 310
$I1396:
        cmp     si,1
        sbb     ax,ax
        neg     ax
; Line 311
        pop     si
        leave
        ret

EndProc _VerifyDDLoaded
; Line 314
        PUBLIC  _StartLockProgram
Procedure _StartLockProgram
        enter   104,0
        push    di
        push    si
;       buff = -104
;       results = -4
;       register si = rc
; Line 329
        lea     ax,WORD PTR [bp-104]    ;buff
        push    ss
        push    ax
        push    100
        push    0
        push    0
        push    0
        push    0
        push    0
        lea     ax,WORD PTR [bp-4]      ;results
        push    ss
        push    ax
        push    ds
        push    OFFSET RUNPGM
        call    DWORD PTR pDosExecPgm
        mov     si,ax
; Line 330
        sub     ax,ax
        mov     dx,OFFSET RUNPGM
        mov     cx,260
        mov     di,dx
        push    ds
        pop     es
        rep     stosb
; Line 331
        or      si,si
        jne     $I1403
        cmp     WORD PTR [bp-2],ax
        je      $EX1398
$I1403:
; Line 333
        call    _LockProblem
; Line 336
$EX1398:
        pop     si
        pop     di
        leave
        ret
        nop

EndProc _StartLockProgram
INITR3CODE ends

END
