Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

415 lines
10 KiB

  1. PAGE ,132
  2. TITLE DXEMM.ASM -- Dos Extender MEMM Disable Code
  3. ; Copyright (c) Microsoft Corporation 1989-1991. All Rights Reserved.
  4. ;***********************************************************************
  5. ;
  6. ; DXEMM.ASM -- Dos Extender MEMM Disable Code
  7. ;
  8. ;-----------------------------------------------------------------------
  9. ;
  10. ; This module provides routines that attempt to disable MEMM/CEMM/EMM386
  11. ; drivers. DOSX tries to disable MEMM when starting up, and enables MEMM
  12. ; when terminating.
  13. ;
  14. ; NOTE: All the code in this module is consider initialization, and
  15. ; is discarded before going operational. This includes code
  16. ; segment variables. The MEMM enable code is not in this file
  17. ; since that cannot be discarded.
  18. ;
  19. ;-----------------------------------------------------------------------
  20. ;
  21. ; 12/08/89 jimmat Minor changes so enable code could be finished.
  22. ; 07/14/89 jimmat Original version - but largely taken from Windows/386
  23. ; code from ArronR
  24. ;
  25. ;***********************************************************************
  26. .286p
  27. ; -------------------------------------------------------
  28. ; INCLUDE FILE DEFINITIONS
  29. ; -------------------------------------------------------
  30. .xlist
  31. .sall
  32. include segdefs.inc
  33. include gendefs.inc
  34. .list
  35. if NOT VCPI
  36. ; -------------------------------------------------------
  37. ; GENERAL SYMBOL DEFINITIONS
  38. ; -------------------------------------------------------
  39. EMM_OK equ 0
  40. ; Device driver header for Microsoft 386 EMM drivers
  41. ;
  42. emm_hdr STRUC
  43. ;
  44. DW ? ;Null segment address
  45. DW ? ;Null offset address
  46. DW ? ;Attribute - Char
  47. DW ? ;Strategy routine entry
  48. DW ? ;Interrupt routine entry
  49. DB 'EMMXXXX0' ;Character device name
  50. ;
  51. ; GENERAL FUNCTIONS ENTRY POINT
  52. ; ELIM_Entry is a entry point for executing general MEMM
  53. ; functions. (e.g. ON, OFF function).
  54. ;
  55. ELIM_Entry_off dw ? ; general entry point
  56. ;
  57. ; MEMM signature
  58. ;
  59. emmsig db ? ; MEMM signature
  60. emm_hdr ENDS
  61. ; -------------------------------------------------------
  62. ; EXTERNAL SYMBOL DEFINITIONS
  63. ; -------------------------------------------------------
  64. ; -------------------------------------------------------
  65. ; DATA SEGMENT DEFINITIONS
  66. ; -------------------------------------------------------
  67. DXDATA segment
  68. extrn MEMM_State:BYTE ; initial on/off/auto state
  69. extrn MEMM_Call:DWORD ; far call address into MEMM driver
  70. extrn fMEMM_Disabled:BYTE ; NZ if MEMM was disabled
  71. DXDATA ends
  72. ; -------------------------------------------------------
  73. ; CODE SEGMENT VARIABLES
  74. ; -------------------------------------------------------
  75. DXCODE segment
  76. extrn segDXData:WORD
  77. EMMDevNameRM DB "EMMXXXX0" ;Character device name
  78. MEMMsig db 'MICROSOFT EXPANDED MEMORY MANAGER 386'
  79. MEMMsiglen equ $ - MEMMsig
  80. CEMMsig db 'COMPAQ EXPANDED MEMORY MANAGER 386'
  81. CEMMsiglen equ $ - CEMMsig
  82. DXCODE ends
  83. DXPMCODE segment
  84. DXPMCODE ends
  85. ; -------------------------------------------------------
  86. subttl MEMM/CEMM/EMM386 Disable Routines
  87. page
  88. ; -------------------------------------------------------
  89. ; MEMM/CEMM/EMM386 DISABLE ROUTINES
  90. ; -------------------------------------------------------
  91. DXCODE segment
  92. assume cs:DXCODE
  93. ; -------------------------------------------------------
  94. ; EMMDisable -- This routine attempts to disable any installed
  95. ; MEMM/CEMM/EMM386 driver.
  96. ;
  97. ; Input: none
  98. ; Output: CY off - EMM driver disabled (or not installed)
  99. ; CY set - EMM installed, and can't disable
  100. ; Errors:
  101. ; Uses: All registers preserved
  102. assume ds:DGROUP,es:NOTHING,ss:NOTHING
  103. public EMMDisable
  104. EMMDisable proc near
  105. pusha
  106. push ds
  107. push es
  108. call Check_for_EMM_Driver ;is there and EMM driver?
  109. jc emmd_ok ; no, then we're already done
  110. call MEMM_Inst_chk ;is it one we know about?
  111. jc emmd_bad ; no, then we can't disable it
  112. ; Get the current EMM driver state before checking for open handles. The
  113. ; process of checking for handles may change the driver from AUTO to ON.
  114. xor ax,ax ; get & save current emm state
  115. call [MEMM_Call] ; returns ah = 0 - on, 1 - off,
  116. mov MEMM_state,ah ; 2 - auto & off, 3 - auto & on
  117. call AnyMEMMHandles ;does it have any handles allocated?
  118. jc emmd_bad ; yes, then we can't disable it
  119. call TurnMEMMOff ;try to disable it
  120. jc emmd_bad
  121. mov fMEMM_Disabled,1 ;remember that we disabled MEMM
  122. emmd_ok:
  123. clc ;indicate disabled (or not installed)
  124. emmd_ret:
  125. pop es
  126. pop ds
  127. popa
  128. ret
  129. emmd_bad:
  130. stc ;can't disable!
  131. jmp short emmd_ret
  132. EMMDisable endp
  133. ; -------------------------------------------------------
  134. ; Windows/386 EMM Disable Code
  135. ; -------------------------------------------------------
  136. assume ds:NOTHING,es:NOTHING,ss:NOTHING
  137. BeginProc macro name
  138. name proc near
  139. endm
  140. EndProc macro name
  141. name endp
  142. endm
  143. ;--------------------------------------------------------
  144. ;******************************************************************************
  145. ;
  146. ; MEMM_Inst_chk - Check to see if MEMM/CEMM is already installed
  147. ;
  148. ; ENTRY:
  149. ; Know there is an EMM driver so INT 67 vector points to something
  150. ;
  151. ; EXIT:
  152. ; Carry set
  153. ; No MEMM/CEMM driver
  154. ; Carry Clear
  155. ; [entry_seg] = segment of driver header
  156. ; [entry_off] = offset of status routine in MEMM
  157. ;
  158. ; USES: AX,CX,SI,DI,FLAGS
  159. ;
  160. ;******************************************************************************
  161. assume ds:NOTHING, es:NOTHING
  162. BeginProc MEMM_Inst_chk
  163. push ds
  164. push es
  165. xor ax,ax
  166. mov ds,ax
  167. mov ax,word ptr ds:[(67h * 4)+2] ; get segment pointed to by int 67
  168. mov ds,ax
  169. mov si,emmsig
  170. cld ; strings foward
  171. mov di,offset MEMMsig
  172. push cs
  173. pop es
  174. mov cx,MEMMsiglen
  175. cld
  176. repe cmpsb ; q: is the MEMM signature out there?
  177. je short found_sig ; y: return one
  178. mov si,emmsig
  179. mov di,offset CEMMsig
  180. mov cx,CEMMsiglen
  181. cld
  182. repe cmpsb ; q: is the CEMM signature out there?
  183. jne short Not_Found ; n: done, not found
  184. found_sig:
  185. mov es,segDXData
  186. xor si,si
  187. mov word ptr es:[MEMM_Call+2],ds ; save segment for far call
  188. mov cx,ds:[si.ELIM_Entry_off]
  189. mov word ptr es:[MEMM_Call],cx ; Offset for far call
  190. clc
  191. MEMM_Inst_Done:
  192. pop es
  193. pop ds
  194. ret
  195. Not_Found:
  196. stc
  197. jmp short MEMM_Inst_Done
  198. EndProc MEMM_Inst_chk
  199. ;******************************************************************************
  200. ;
  201. ; TurnMEMMOff
  202. ;
  203. ; Turn MEMM off (CEMM, IEFF, MEMM)
  204. ;
  205. ; ENTRY:
  206. ; entry_seg entry_off set to CEMM/MEMM enable disable routine
  207. ;
  208. ; EXIT:
  209. ; Carry Set
  210. ; Could not disable EMM
  211. ; Carry Clear
  212. ; MEMM CEMM EMM turned off
  213. ;
  214. ; USES: EAX,FLAGS
  215. ;
  216. ;******************************************************************************
  217. assume ds:DGROUP, es:NOTHING
  218. BeginProc TurnMEMMOff
  219. cmp MEMM_state,1 ; MEMM already off?
  220. jz short memm_off ; yes, nothing to do
  221. mov AX,0101h ; no, turn it OFF
  222. call [MEMM_Call]
  223. jc short memm_err
  224. memm_off:
  225. clc
  226. memm_done:
  227. ret
  228. memm_err:
  229. stc ; Error, set carry
  230. jmp short memm_done
  231. EndProc TurnMEMMOff
  232. ;******************************************************************************
  233. ;
  234. ; AnyMEMMHandles/Check_For_EMM_Handles
  235. ;
  236. ; Are there any open MEMM handles
  237. ;
  238. ; ENTRY:
  239. ; entry_seg entry_off set to CEMM/MEMM enable disable routine
  240. ;
  241. ; EXIT:
  242. ; Carry Set
  243. ; There are open handles
  244. ; Carry Clear
  245. ; There are no open handles
  246. ;
  247. ; USES: EAX,EBX,ECX,FLAGS
  248. ;
  249. ;******************************************************************************
  250. assume ds:DGROUP, es:NOTHING
  251. BeginProc AnyMEMMHandles
  252. mov ax,4600h
  253. int 67h
  254. cmp ah,EMM_OK
  255. jne short memm_is_off
  256. mov cx,ax
  257. mov ax,4B00h
  258. int 67h
  259. cmp ah,EMM_OK
  260. jne short memm_is_off
  261. cmp cl,40h
  262. jb short Check_Cnt
  263. or bx,bx ; Don't dec through 0!!!
  264. jz short Check_Cnt
  265. dec bx ; Do not include handle 0 on 4.0 drivers
  266. Check_Cnt:
  267. cmp bx,0
  268. stc
  269. jne short HaveHandles
  270. memm_is_off:
  271. clc
  272. HaveHandles:
  273. ret
  274. EndProc AnyMEMMHandles
  275. ;******************************************************************************
  276. ;
  277. ; Check_For_EMM_Driver
  278. ;
  279. ; See if an EMM driver is around
  280. ;
  281. ; ENTRY:
  282. ; None
  283. ;
  284. ; EXIT:
  285. ; Carry Set
  286. ; No EMM driver around
  287. ; Carry Clear
  288. ; EMM driver is around
  289. ;
  290. ; USES: AX,CX,SI,DI,FLAGS
  291. ;
  292. ;******************************************************************************
  293. assume ds:NOTHING,es:NOTHING
  294. BeginProc Check_For_EMM_Driver
  295. push ds
  296. push es
  297. ; Note, DS:SI & ES:DI used to be swapped, but on at least one system where
  298. ; Int 67h pointed to F000 and there was not ram or rom at F000:000A (rom
  299. ; started at F0000:8000), bus noise made the compare work when it shouldn't
  300. ; have. Swapping ES:DI / DS:SI corrected this.
  301. xor ax,ax
  302. mov es,ax
  303. mov ax,word ptr es:[(67h * 4)+2] ; get segment pointed to by int 67
  304. mov es,ax
  305. mov di,000Ah ; Offset of device name
  306. mov si,offset EMMDevNameRM
  307. push cs
  308. pop ds
  309. mov cx,8
  310. cld
  311. repe cmpsb
  312. jne short NoEMM_Seen
  313. clc
  314. EMMTstDone:
  315. pop es
  316. pop ds
  317. ret
  318. NoEMM_Seen:
  319. stc
  320. jmp short EMMTstDone
  321. EndProc Check_For_EMM_Driver
  322. ; -------------------------------------------------------
  323. DXCODE ends
  324. ;****************************************************************
  325. endif ; NOT VCPI
  326. end