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

操作系统开发

开发平台:

Visual C++

  1. ;******************************************************************************
  2. ;
  3. ;   (C) Copyright MICROSOFT Corp. 1989-1991
  4. ;
  5. ;   Module:   HIGHEXIT.INC - Code executed after LoadHigh or DeviceHigh
  6. ;
  7. ;   Date:     May 14, 1992
  8. ;
  9. ;******************************************************************************
  10. ;
  11. ;   Modification log:
  12. ;
  13. ;     DATE    WHO      DESCRIPTION
  14. ;   --------  -------  --------------------------------------------------------
  15. ;   05/14/92  t-richj  Original
  16. ;   06/21/92  t-richj  Final revisions before check-in
  17. ;
  18. ;******************************************************************************
  19. ;
  20. ;
  21. ; Public:
  22. ;
  23. ;       PROCEDURES
  24. ; FreeUMBs
  25. ; HeadUMB
  26. ;               UnHideUMBs
  27. ;
  28. ; Internal:
  29. ;
  30. ;       PROCEDURES
  31. ; freeMCB
  32. ;               he_unlink
  33. ; isHideMCB
  34. ;               linkumb
  35. ;
  36. ; Definitions:
  37. ;
  38. ;       DOS_STRATEGY_SET -      AX value when calling int 21h, to set the DOS
  39. ;                               memory-allocation strategy.
  40. ;       DOS_UMBLINK_SET -       AX value when calling int 21h, to set the UMB
  41. ;                               link-state.
  42. ;       DOS_GET_LISTS -         AH value when calling int 21h, to get the DOS
  43. ;                               "list of lists".
  44. ;       UMB_HeadIdx -           After returning from int 21h, func 52h...
  45. ;                               ES:[Umb_HeadIdx] will contain the address of
  46. ;                               the first UMB delimiter, usually 0x9FFF... if
  47. ;                               it's 0xFFFF, then it hasn't been set yet.
  48. ;
  49. ; *****************************************************************************
  50. DOS_STRATEGY_GET  equ   5800h ; Int 21h, Func 58h, Svc 0 = get alloc strategy
  51. DOS_STRATEGY_SET  equ   5801h ; Int 21h, Func 58h, Svc 1 = set alloc strategy
  52. DOS_UMBLINK_GET   equ   5802h ; Int 21h, Func 58h, Svc 2 = get link state
  53. DOS_UMBLINK_SET   equ   5803h ; Int 21h, Func 58h, Svc 3 = set link state
  54. DOS_GET_LISTS     equ     52h ; Int 21h, Func 52h = get list of lists
  55. UMB_HeadIdx       equ     8Ch ; Offset from ES (after func52h) to get UMBHead
  56. ;
  57. ; If HV_LoadHigh has been defined, this is going into stub.asm under
  58. ; cmdcommand... and stub doesn't include dosmac.inc.  So, rather than
  59. ; include dosmac to get BREAK, its definition is just copied here.
  60. ;
  61. ifdef HV_LoadHigh
  62. BREAK   MACRO   subtitle ; Arena.inc, below, needs this macro... but
  63. SUBTTL  subtitle ; if we include dosmac to get it, we've gotta
  64. PAGE ; include more crap, and so on, and so on, and
  65. ENDM ; so on, and so on, and so on, and so on...
  66. include arena.inc ; For DeviceHigh, highload and highexit are in the
  67. ; same module, so they both have arena.inc; in LoadHigh
  68. endif ; they don't.
  69. ; -----------------------------------------------------------------------------
  70. ;*** UnHideUMBs - Marks HIDDEN elements as FREE
  71. ; -----------------------------------------------------------------------------
  72. ; ENTRY:  None; perhaps, earlier, HideUMBs was called... if not, we have
  73. ;               very little to do, as no elelments will be marked as HIDDEN.
  74. ; EXIT:   Sets InHigh to zero; carry clear if HideUMBs was called earlier.
  75. ; ERROR:  None
  76. ; USES:   fInHigh (from highvar.inc), carry flag
  77. ; -----------------------------------------------------------------------------
  78. public  UnHideUMBs
  79. UnHideUMBs proc near
  80. push ax ; Save ax for what we're about to do
  81. ; -----------------------------------------------------------------------------
  82. ; BUGBUG t-richj 11-8-92: The following six lines were commented out for a good
  83. ;    length of time.  Those six constitute a check of whether or not we should
  84. ;    indeed clean up the upper-memory chain; without such a check, COMMAND.COM
  85. ;    will destroy the current link-state and memory-allocation strategy after
  86. ;    every command execution.
  87. ; -----------------------------------------------------------------------------
  88. getdata al, fInHigh ; Get InHigh from data segment
  89. or al, al
  90. jnz uhu10 ; If didn't call loadhigh/devicehigh earlier,
  91. pop ax ; then there's nothing to do here... so
  92. stc ; restore everything and return.  Just like
  93. ret ; that.
  94. uhu10: call linkumb ; Make sure UMBs are linked in.
  95. call FreeUMBs
  96. putdata fInHigh, 0 ; We're leaving, so update fInHigh.
  97. call he_unlink ; Unlink UMBs
  98. pop ax
  99. clc
  100. ret
  101. UnHideUMBs endp
  102. ; -----------------------------------------------------------------------------
  103. ;*** he_unlink - unlinks UMBs if fm_umb is set to 0
  104. ; -----------------------------------------------------------------------------
  105. ; ENTRY:    fm_umb == 1 : leave linked, else unlink
  106. ; EXIT:     None
  107. ; ERROR:    None
  108. ; USES:     AX, BX
  109. ; -----------------------------------------------------------------------------
  110. he_unlink proc near
  111. xor bh, bh
  112. getdata bl, fm_umb ; Restore original link-state
  113. mov ax, DOS_UMBLINK_SET
  114. int 21h
  115. ifdef HV_LoadHigh
  116. xor bh, bh
  117. getdata bl, fm_strat ; Restore original mem-alloc strategy
  118. mov ax, DOS_STRATEGY_SET
  119. int 21h
  120. endif
  121. ret
  122. he_unlink endp
  123. ; -----------------------------------------------------------------------------
  124. ;*** freeUMBs - frees all HIDDEN memory elements in upper-memory.
  125. ; -----------------------------------------------------------------------------
  126. ; ENTRY:    None
  127. ; EXIT:     None; HIDDEN memory elements returned to FREE
  128. ; ERROR:    None (ignore CF)
  129. ; USES:     Flags
  130. ; -----------------------------------------------------------------------------
  131. public FreeUMBs
  132. FreeUMBs proc near
  133. pushreg <ax, es>
  134. call HeadUmb ; Returns with carry if err, else ES == MCB
  135. jc fusX
  136. mov es, ax ; Prepare for the loop; ES = current MCB addr.
  137. fus10: call isHideMCB ; Returns with ZF set if owner is 0
  138. jnz fus20
  139. call freeMCB
  140. fus20: mov al, es:[arena_signature]
  141. cmp al, arena_signature_end
  142. jz fusX ; That means this was the last MCB--that's it.
  143. mov ax, es
  144. add ax, es:[arena_size]
  145. inc ax
  146. mov es, ax ; Go on forward.
  147. jmp short fus10
  148. fusX: popreg <es, ax>
  149. ret
  150. FreeUMBs endp
  151. ; -----------------------------------------------------------------------------
  152. ;*** isHideMCB - returns with ZF set if current MCB (ES:0) is HIDDEN
  153. ; -----------------------------------------------------------------------------
  154. ; ENTRY:    ES:0 should point to an MCB
  155. ; EXIT:     ZF set if MCB is hidden, else !ZF
  156. ; ERROR:    None
  157. ; USES:     Flags
  158. ; -----------------------------------------------------------------------------
  159. isHideMCB proc near
  160. push ax
  161. cmp es:[arena_owner], SystemPSPOwner ; If the owner's SYSTEM
  162. jnz ihm_x ; then check for HIDDEN
  163. mov ax, word ptr es:[arena_name]
  164. cmp ax, 'IH'
  165. jnz ihm_x
  166. mov ax, word ptr es:[arena_name+2]
  167. cmp ax, 'DD'
  168. jnz ihm_x
  169. mov ax, word ptr es:[arena_name+4]
  170. cmp ax, 'NE'
  171. jnz ihm_x
  172. mov ax, word ptr es:[arena_name+6]
  173. cmp ax, '  '
  174. ihm_x: pop ax
  175. ret
  176. isHideMCB endp
  177. ; -----------------------------------------------------------------------------
  178. ;*** freeMCB - marks as free the MCB at ES:0
  179. ; -----------------------------------------------------------------------------
  180. ; ENTRY:    ES:0 should point to an MCB
  181. ; EXIT:     None; MCB free'd
  182. ; ERROR:    None
  183. ; USES:     AX
  184. ; -----------------------------------------------------------------------------
  185. freeMCB proc near
  186. mov es:[arena_owner], 0
  187. mov ax, '  '
  188. mov word ptr es:[arena_name+0], ax
  189. mov word ptr es:[arena_name+2], ax
  190. mov word ptr es:[arena_name+4], ax
  191. mov word ptr es:[arena_name+6], ax
  192. ret
  193. freeMCB endp
  194. ; -----------------------------------------------------------------------------
  195. ;*** HeadUmb - returns in AX the address of the first UMB block (0x9FFF)
  196. ; -----------------------------------------------------------------------------
  197. ; ENTRY:  Nothing
  198. ; EXIT:   AX contains 0x9FFF for most systems
  199. ; ERROR:  Carry set if pointer is 0xFFFF (if not set up yet--DH runs into this)
  200. ; USES:   Flags, AX
  201. ; -----------------------------------------------------------------------------
  202. public HeadUmb
  203. HeadUmb proc near
  204. pushreg <si, ds, es>
  205. mov ah, DOS_GET_LISTS ; Call int 21h, function 52h...
  206. int 21h
  207. mov ax, es:[UMB_HeadIdx] ; And read what's in ES:008C
  208. cmp ax, 0FFFFh
  209. jz xhu_e ; If it's 0xFFFF, it's an error...
  210. clc ; Else, it isn't.
  211. jmp short xhu_x
  212. xhu_e: stc
  213. xhu_x: popreg <es, ds, si>
  214. ret
  215. HeadUmb endp
  216. ; -----------------------------------------------------------------------------
  217. ;*** linkumb - links UMBs not already linked in; updates fm_umb as needed
  218. ; -----------------------------------------------------------------------------
  219. ; ENTRY:    None
  220. ; EXIT:     fm_umb == 0 if not linked in previously, 1 if already linked in
  221. ; ERROR:    None
  222. ; USES:     AX, BX, fm_umb
  223. ; -----------------------------------------------------------------------------
  224. linkumb proc near
  225. mov ax, DOS_UMBLINK_GET
  226. int 21h ; Current link-state is now in al
  227. or al, al ; BUGBUG: proper check?
  228. jnz lumbX ; Jumps if UMBs already linked in
  229. mov ax, DOS_UMBLINK_SET
  230. mov bx, 1
  231. int 21h
  232. lumbX:
  233. ret
  234. linkumb endp