emm386.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:5k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. ;/*
  2. ; *                      Microsoft Confidential
  3. ; *                      Copyright (C) Microsoft Corporation 1988 - 1991
  4. ; *                      All Rights Reserved.
  5. ; */
  6. ;
  7. ;  EMM386.ASM
  8. ;
  9. ;     fIsPooled() - Returns version if pooling is in effect, else 0
  10. ;
  11. .MODEL SMALL
  12. include rombios.inc
  13. ;
  14. ;emm defines
  15. ;
  16. EMM_INT_VECT EQU  67h
  17. DEVICE_OFFSET EQU 10
  18. EMM_POOLED_VER EQU 42Dh   ; emm386 pooled version is 4.45
  19. EMM_READ_FUNC EQU 1
  20. EMM_GET_VER EQU 2
  21. EMM_DEV_NAME     EQU     "EMMXXXX0",0 ; Name for EMM driver IOCTL open.
  22. EMM_DEV_NOEMS           EQU     '$'          ; M000: Replacement for first
  23.                                              ;   char. of EMM_DEV_NAME when
  24.                                              ;   "device=EMM386 NOEMS".
  25. EMM_DEV_VCPI            EQU     "EMMQXXX0",0 ; M002: Name for EMM driver when
  26.                                              ;   VCPI but not EMS support.
  27. EMM386_SIG            EQU     "MICROSOFT"  ; M001: EMM386 Signature.
  28.                                              ; M001: Offset from device base.
  29. EMM386_SIG_OFFSET       EQU     (0ah + EMM_DEV_NAME_LEN - 1 + 2)
  30. ; Structure of the data returned on the IOCTL call to the EMM driver
  31. EMM_STRUC struc
  32.     EMM_Version_Maj db ?   ; Internal revision number
  33.     EMM_Version_Min db ?
  34. EMM_STRUC ends
  35. Version EQU (-((SIZE EMM_STRUC) - EMM_Version_Maj))
  36. Function EQU (-(SIZE EMM_STRUC))
  37. .DATA
  38. DevName db 'EMMXXXX0'
  39. DeviceName db EMM_DEV_NAME ; Name for EMM IOCTL opens.
  40. EMM_DEV_NAME_LEN EQU    ($-DeviceName)  ; M001: Length of DeviceName string.
  41. EMM386Sig     db      EMM386_SIG ; M001: Signature for EMM386 device.
  42. EMM386_SIG_LEN  EQU     ($-EMM386Sig)  ; M001: Signature length.
  43. ;M002
  44. VCPIDevName db EMM_DEV_VCPI ; Name for EMM VCPI IOCTL opens.
  45. _MaxMin  dw 2 dup (0)
  46. public _MaxMin
  47. .CODE
  48. public _fIsPooled
  49. _fIsPooled proc near
  50. push ES
  51. push SI
  52. push DI
  53. pushf ; M001: Save flags due to CLD below.
  54. push BP
  55. mov BP,SP
  56. sub SP,SIZE EMM_STRUC
  57. ;M000
  58.         xor     ax, ax
  59. mov [_MaxMin],   ax
  60. mov [_MaxMin+2], ax      ; First, we initialize the buffer.
  61. mov DX,OFFSET DeviceName ; DS:DX pointer to emm name
  62. mov AX,3d02h ; Try to open the device
  63. int 21h
  64.         jnc     GEV40                   ; Jump if device opens.
  65. mov DeviceName,EMM_DEV_NOEMS ; DS:DX -> NOEMS emm name
  66. mov AX,3d02h ; Try to open the device
  67. int 21h
  68.         jnc     GEV40                   ; Jump if device opens.
  69. ;M002
  70. mov DX,OFFSET VCPIDevName ; DS:DX pointer to VCPI emm name
  71. mov AX,3d02h ; Try to open the device
  72. int 21h
  73.         jc      GEV60                   ; Jump if device not found.
  74. ; M001: Validate "MICROSOFT" signature.
  75. GEV40:  push    AX                      ; Save EMM device handle.
  76.         mov     AX,(35h SHL 8) OR EMM_INT_VECT
  77.         int     21h                     ; ES:BX -> EMM device handler.
  78.                                         ; ES:0000 -> EMM device base.
  79.         mov     DI,EMM386_SIG_OFFSET    ; ES:DI -> EMM Signature.
  80.         mov     SI,OFFSET EMM386Sig ; DS:SI -> EMM386 Signature.
  81.         mov     CX,EMM386_SIG_LEN       ; CX = Signature length.
  82.         cld
  83.         repz    cmpsb                   ; Signature match?
  84.         jz      GEV80                   ;   Yes, jump.
  85.                                         ;   No, fall thru and exit.
  86. GEV60: xor AX,AX ; return code = 0.
  87. jmp SHORT FunctExit         ; Go fix stack and exit.
  88. GEV80: pop BX ; BX = device handle.
  89. ;M000
  90. mov AX,4400h ; IOCTL get device information.
  91. int 21h
  92. jc SHORT ErrorClose ; Carry indicates call unsuccesful
  93. test DX,0080h ; Test if clock device.
  94. jz SHORT ErrorClose ; if not, we can't steal memory.
  95. test DX,4000h ; Are IOCTL's 02h and 03h supported
  96. jz SHORT ErrorClose ; if not we cannot steal memory.
  97. push DS
  98. mov AX,SS
  99. mov DS,AX
  100. mov DX,BP ; DS:DX == SS:BP
  101. mov CX,SIZE EMM_STRUC ; CX == size of the ctrl string
  102. sub DX,CX ; DS:DX --> Start of data struct
  103. mov BYTE PTR [BP].Function,EMM_GET_VER
  104. mov AX,4402h ; Read control device string function
  105. int 21h
  106. pop DS
  107. jc SHORT ErrorClose ; Carry indicates call unsuccesful
  108. cmp AX,CX ; If ax != cx we did not get the
  109. jne SHORT ErrorClose ; number of bytes we requested !
  110. mov AX,WORD PTR [BP].Version ; Have good version #
  111. xchg AH,AL ; Put major ver. in AH & minor in AL
  112. cmp AX,EMM_POOLED_VER ; if emm386 ver 4.45 continue
  113. jl SHORT ErrorClose ; else return 0
  114.         mov     cx, 4
  115. mov dx, offset _MaxMin     ; offset of emm386 max allocated and min allocated buffer
  116. mov byte ptr [_MaxMin], 3  ; set function code for IOCTL
  117.         mov     ax, 4402h              ; read control data from char device
  118. int 21h        ; get max-min allocated for emm386
  119. jmp SHORT CloseHandle
  120. ErrorClose:
  121. xor AX,AX ; Invalid EMM386 version #
  122. CloseHandle:
  123. push AX
  124. mov AX,3E00h ; Close device, handle in BX.
  125. int 21h ; Call DOS
  126. pop AX
  127. FunctExit:
  128. mov SP,BP
  129. pop BP
  130.         popf                            ; M001
  131. pop DI
  132. pop SI
  133. pop ES
  134. ret ; return to caller.
  135. _fIsPooled endp
  136. end