home *** CD-ROM | disk | FTP | other *** search
- page ,132
- title vmutil - VM util routines
- ;***
- ;vmutil.asm - VM util routines
- ;
- ; Copyright (c) 1989-1992, Microsoft Corporation. All rights reserved.
- ;
- ;*******************************************************************************
-
- include version.inc
- .model large,pascal
-
- .data?
-
- extrn C _rghpgdHash:word
- extrn C _segVmDos:word
-
- extrn __VmTerminate:far
-
- szFilename db 128 dup(?)
-
- .code VM_TEXT
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* FVmWin30StandardMode
- ;*
- ;* This function returns true if running in Windows 3.0 standard
- ;* mode.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* DOS only.
- ;*
- ;* Exit Conditions:
- ;*
- ;* None.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-
- __FVmWin30StandardMode proc near uses di
-
- ;If running in Windows 3.1 standard mode a task switcher is
- ;active. Windows 3.0 standard mode doesn't support the task
- ;switcher API. There is a loophole. The DOS 5.0 shell with
- ;task switcher enabled can be run in a DOS session under
- ;Windows 3.0 standard mode. This will result in this function
- ;reporting that Windows 3.0 standard mode is not active.
-
- mov ax,4B02h ;SWTCH_DETECT_SWITCHER API
- xor bx,bx
- mov di,bx
- mov es,bx
- int 2Fh ;AX = 0 if task switcher is active
- or ax,ax ;Is a switcher active?
- jz Exit ;Brif so.
-
- mov ax,4680h ;IS_WINOLDAP_ACTIVE
- int 2Fh ;AX = 0 if winoldap is active
- or ax,ax ;Is Windows 3.0 winoldap active?
- jnz Not30StandardMode ;Brif not.
-
- mov ax,sp ;We are in Win 3.0 standard mode.
- jmp Exit
-
- Not30StandardMode:
- xor ax,ax ;We are not in Win 3.0 standard mode
-
- Exit:
- ret
-
- __FVmWin30StandardMode endp
-
- page
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* CParaVmDosAvail
- ;*
- ;* This function returns the number of paragraphs in the largest
- ;* memory block available in the DOS memory heap.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* DOS only.
- ;*
- ;* Exit Conditions:
- ;*
- ;* None.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-
- __CParaVmDosAvail proc near
-
- mov ah,48h ;Allocate Memory Block
- mov bx,0FFFFh ;Try for all available memory
- int 21h ;Do it
- xchg ax,bx ;Return size of available block
- ret
-
- __CParaVmDosAvail endp
-
- page
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* SegVmDosAllocate
- ;*
- ;* This function allocates the requested number of paragraphs
- ;* from the DOS heap and returns the segment value of the block.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* DOS only.
- ;*
- ;* Exit Conditions:
- ;*
- ;* Returns the segment if the allocation succeeds or _NULLSEG if
- ;* the allocation fails.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-
- __SegVmDosAllocate proc near cPara:word
-
- mov ah,48h ;Allocate Memory Block
- mov bx,[cPara]
- int 21h ;Do it
- jnc @F ;Brif allocation succeeded
- xor ax,ax ;Return 0 == _NULLSEG
- @@:
- ret
-
- __SegVmDosAllocate endp
-
- page
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* VmDosFreeSeg
- ;*
- ;* This function releases the specified DOS memory block.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* DOS only.
- ;*
- ;* Exit Conditions:
- ;*
- ;* None.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- __VmDosFreeSeg proc near segDos:word
-
- mov ah,49h ;Release Memory Block
- mov es,[segDos]
- int 21h ;Do it
- ret
-
- __VmDosFreeSeg endp
-
- page
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* VmCreateTemp
- ;*
- ;* This function creates a file for disk swapping.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* DOS only.
- ;*
- ;* Exit Conditions:
- ;*
- ;* None.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- __VmCreateTemp proc near uses si di
-
- mov ah,62h
- int 21h
- jc UseCurrentDirectory
- mov ds,bx ;DS:0 = Psp
- assume ds:nothing
- mov ds,ds:[2Ch]
- xor si,si ;DS:SI -> Environment
-
- CheckEnvironmentVar:
- lodsw
- or al,al ;End of enviroment?
- jz UseCurrentDirectory ;Brif so, use current directory
-
- cmp ax,'MT' ;Look for TMP=
- jne @F
- lodsw
- cmp ax,'=P'
- je CopyTMP
- @@:
- lodsb
- or al,al
- jnz @B
- jmp CheckEnvironmentVar
-
- CopyTMP:
- mov cx,SIZE szFilename-13
- mov di,OFFSET DGROUP:szFilename
- push ss
- pop es ;ES:DI = pszFilename
-
- @@:
- lodsb
- stosb
- or al,al ;End of environment string?
- jz CreateFile ;Brif so
- dec cx ;Is buffer full?
- jz EndOfTMP ;Brif so. Truncate it.
- cmp al,';' ;Path seperator?
- jne @B ;Brif not.
-
- EndOfTMP:
- dec di ;Backup over last character
- mov al,0
- stosb ;Zero terminate
- jmp short CreateFile
-
- UseCurrentDirectory:
- mov word ptr [szFilename],'.'
-
- CreateFile:
- push ss ;Restore DS == DGROUP
- pop ds
- assume ds:DGROUP
-
- mov ah,5Ah ;Create temporary file
- xor cx,cx ;Normal file
- mov dx,OFFSET ds:szFilename
- int 21h
- jnc @F
- cmp word ptr [szFilename],'.'
- jne UseCurrentDirectory ;Retry create in current directory
- mov ax,0FFFFh
- @@:
- ret
-
- __VmCreateTemp endp
-
- page
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* VmCloseTemp
- ;*
- ;* This function closes and deletes the disk swap file.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* The fh parameter is the DOS file handle of the swap file.
- ;*
- ;* Exit Conditions:
- ;*
- ;* None.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- __VmCloseTemp proc near fh:word
-
- mov ah,3Eh ;Close file
- mov bx,[fh]
- int 21h
-
- mov ah,41h ;Delete file
- mov dx,OFFSET ds:szFilename
- int 21h
-
- ret
-
- __VmCloseTemp endp
-
- page
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* FVmExtendTemp
- ;*
- ;* This function extends the size of the swap file.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* The fh parameter is the DOS file handle of the swap file. The
- ;* lfa parameter is the new size of the file.
- ;*
- ;* Exit Conditions:
- ;*
- ;* If the disk swap file can be grown, the function returns TRUE.
- ;* If the disk allocation fails, the function retunrs FALSE.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- __FVmExtendTemp proc near \
- fh:word, \
- lfa:dword
-
- push [fh]
- push word ptr [lfa+2]
- push word ptr [lfa+0]
- push ds ;Dummy far pointer
- push dx
- xor ax,ax
- push ax
- call near ptr __FVmWriteTemp ;Write 0 bytes
-
- mov ax,4202h ;Seek relative to end
- mov bx,[fh]
- xor cx,cx
- xor dx,dx
- int 21h
-
- jc @F ;Brif seek failed. AX != 0
- xor dx,word ptr [lfa+2] ;Is current size = requested size?
- xor ax,word ptr [lfa+0]
- or ax,dx ;AX != 0 if size mismatch
- @@:
- ret
-
- __FVmExtendTemp endp
-
- page
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* FVmReadTemp
- ;*
- ;* This function reads a page from the disk swap file.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* The fh parameter is the DOS file handle of the swap file. The
- ;* lfa parameter is the file offset of the page to be read. The pv
- ;* parameter is the address into which the page is to be read. The
- ;* cb parameter is the number of bytes to be read.
- ;*
- ;* Exit Conditions:
- ;*
- ;* If the read succeeds the function returns TRUE. If the read
- ;* fails, the function returns false.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- __FVmReadTemp proc near uses ds, \
- fh:word, \
- lfa:dword, \
- pv:far ptr, \
- cb:word
-
- mov ax,4200h ;Seek absolute
- mov bx,[fh]
- mov cx,word ptr [lfa+2]
- mov dx,word ptr [lfa+0]
- int 21h
- jc CheckForFailure ;Brif Int 21 Failed
-
- mov ah,3Fh
- mov cx,[cb]
- lds dx,[pv]
- assume ds:nothing
- int 21h
-
- CheckForFailure:
- mov ax,0 ;Assume failure. Return FALSE
- jc @F ;Brif Int 21 Failed
- mov ax,sp ;Return TRUE for success
- @@:
- ret
-
- __FVmReadTemp endp
-
- assume ds:DGROUP
-
- page
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* FVmWriteTemp
- ;*
- ;* This function writes a page to the disk swap file.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Entry Conditions:
- ;*
- ;* The fh parameter is the DOS file handle of the swap file. The
- ;* lfa parameter is the file offset of the page to be write. The pv
- ;* parameter is the address into which the page is to be write. The
- ;* cb parameter is the number of bytes to be write.
- ;*
- ;* Exit Conditions:
- ;*
- ;* If the write succeeds the function returns TRUE. If the write
- ;* fails, the function returns false.
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- __FVmWriteTemp proc near uses ds, \
- fh:word, \
- lfa:dword, \
- pv:far ptr, \
- cb:word
-
- mov ax,4200h ;Seek absolute
- mov bx,[fh]
- mov cx,word ptr [lfa+2]
- mov dx,word ptr [lfa+0]
- int 21h
- jc CheckForFailure ;Brif Int 21 Failed
-
- mov ah,40h
- mov cx,[cb]
- lds dx,[pv]
- assume ds:nothing
- int 21h
-
- CheckForFailure:
- mov ax,0 ;Assume failure. Return FALSE
- jc @F ;Brif Int 21 Failed
- mov ax,sp ;Return TRUE for success
- @@:
-
- ret
-
- __FVmWriteTemp endp
-
- assume ds:DGROUP
-
- page
-
- __HpgdSearchCache proc near \
- vp:dword
-
- mov ax,word ptr [vp] ;DX:AX = vp
- mov dx,word ptr [vp+2]
-
- and ax,0F800h ;DX:AX = VpPageOfVp(vp)
-
- and dx,03Fh ;DX:AX = vp & ipgdHashMask
-
- mov bx,ax ;Save for comparison below
-
- mov cx,79
- div cx ;DX = ipgd = IpgdHashOfVp(vp)
-
- mov ax,bx ;AX = Low word of VpPageOfVp(vp)
-
- mov bx,dx ;BX = ipgd
- add bx,bx ;Scale to index into word array
- mov bx,_rghpgdHash[bx] ;BX = hpgd = _rghpgdHash[ipgd]
-
- cmp bx,0FFFFh ;Is this hpgdNil
- je Exit ;Brif so, page is not resident
-
- mov es,[_segVmDos]
- mov dx,word ptr [vp+2] ;DX:AX = VpPageOfVp(vp)
-
- CheckPage:
- cmp es:[bx],ax ;Compare low word of VP
- jne @F ;No match
- cmp es:[bx+2],dx ;Compare high word of VP
- je Exit ;There is a match
- @@:
- mov bx,es:[bx+12] ;BX = PpgdOfHpgd(hpgd)->hpgdHashNext
- cmp bx,0FFFFh ;Is this hpgdNil
- jne CheckPage ;Brif not, compare address
-
- Exit:
- xchg ax,bx ;AX = hpgd
- ret
-
- __HpgdSearchCache endp
-
-
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* C Runtime Termination Entry
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- ;*
- ;* Place the address of the VM termination routine in the C runtime
- ;* far terminator table. The C runtime will then call this routine
- ;* at termination so that VM resources can be cleaned up (in the case
- ;* where the user didn't previously do so).
- ;*
- ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- XCFB segment word public 'DATA'
- XCFB ends
- XCF segment word public 'DATA'
- XCF ends
- XCFE segment word public 'DATA'
- XCFE ends
-
- DGROUP group XCFB, XCF, XCFE
-
- XCF segment
-
- dd __VmTerminate
-
- XCF ends
-
-
- end
-