home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / xmm12 / xms30.doc < prev   
Encoding:
Text File  |  1992-07-05  |  39.5 KB  |  1,129 lines

  1. eXtended Memory Specification (XMS), version 3.0
  2.  
  3.  
  4. January 1991
  5.  
  6.  
  7. Copyright (c) 1988, Microsoft Corporation, Lotus Development
  8. Corporation, Intel Corporation, and AST Research, Inc.
  9.  
  10. Microsoft Corporation
  11. Box 97017
  12.  
  13. One Microsoft Way
  14. Redmond, WA 98073
  15.  
  16. LOTUS (r)
  17. INTEL (r)
  18. MICROSOFT (r)
  19. AST (r) Research
  20.  
  21. This specification was jointly developed by Microsoft Corporation,
  22. Lotus Development Corporation, Intel Corporation,and AST Research,
  23. Inc. Although it has been released into the public domain and is not
  24. confidential or proprietary, the specification is still the copyright
  25. and property of Microsoft Corporation, Lotus Development Corporation,
  26. Intel Corporation, and AST Research, Inc.
  27.  
  28. Disclaimer of Warranty
  29.  
  30. MICROSOFT CORPORATION, LOTUS DEVELOPMENT CORPORATION, INTEL
  31. CORPORATION, AND AST RESEARCH, INC., EXCLUDE ANY AND ALL IMPLIED
  32. WARRANTIES, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  33. PARTICULAR PURPOSE. NEITHER MICROSOFT NOR LOTUS NOR INTEL NOR AST
  34. RESEARCH MAKE ANY WARRANTY OF REPRESENTATION, EITHER EXPRESS OR
  35. IMPLIED, WITH RESPECT TO THIS SPECIFICATION, ITS QUALITY,
  36. PERFORMANCE, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  37. NEITHER MICROSOFT NOR LOTUS NOR INTEL NOR AST RESEARCH SHALL HAVE ANY
  38. LIABILITY FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
  39. OUT OF OR RESULTING FROM THE USE OR MODIFICATION OF THIS
  40. SPECIFICATION.
  41.  
  42. This specification uses the following trademarks:
  43.  
  44. Intel is a registered trademark of Intel Corporation, Microsoft is a
  45. registered trademark of Microsoft Corporation, Lotus is a registered
  46. trademark of Lotus Development Corporation, and AST is a registered
  47. trademark of AST Research, Inc.
  48.  
  49.  
  50. Extended Memory Specification
  51.  
  52. The purpose of this document is to define the Extended Memory
  53. Specification (XMS) version 3.00 for MS-DOS. XMS allows DOS programs to
  54. utilize additional memory found in Intel's 80286 and 80386 based
  55. machines in a consistent, machine independent manner. With some
  56. restrictions, XMS adds almost 64K to the 640K which DOS programs can
  57. access directly. Depending on available hardware, XMS may provide even
  58. more memory to DOS programs. XMS also provides DOS programs with a
  59. standard method of storing data in extended memory.
  60.  
  61. To be considered fully XMS 3.0 compliant, all calls except those
  62. associated with UMB support must be implemented. UMB functions 10h, 11h
  63. and 12h are optional for XMS 3.0 and may return the Function Not
  64. Implemented error code, 80h.
  65.  
  66. DEFINITIONS:
  67.  
  68. Extended Memory:
  69.  
  70. Memory in 80286 and 80386 based machines which is located above the 1MB
  71. address boundary.
  72.  
  73. High Memory Area (HMA):
  74.  
  75. The first 64K of extended memory.  The High Memory Area is unique
  76. because code can be executed in it while in real mode. The HMA
  77. officially starts at FFFF:10h and ends at FFFF:FFFFh making it 64K-16
  78. bytes in length.
  79.  
  80. Upper Memory Blocks (UMBs):
  81.  
  82. Blocks of memory available on some 80x86 based machines which are
  83. located between DOS's 640K limit and the 1MB address boundary.  The
  84. number, size, and location of these blocks vary widely depending upon
  85. the types of hardware adapter cards installed in the machine.
  86.  
  87. Extended Memory Blocks (EMBs):
  88.  
  89. Blocks of extended memory located above the HMA which can only be used
  90. for data storage.
  91.  
  92. A20 Line:
  93.  
  94. The 21st address line of 80x86 CPUs.  Enabling the A20 line allows
  95. access to the HMA.
  96.  
  97. XMM:
  98.  
  99. An Extended Memory Manager.  A DOS device driver which implements XMS.
  100. XMMs are machine specific but allow programs to use extended memory in a
  101. machine-independent manner.
  102.  
  103. HIMEM.SYS:
  104.  
  105. The Extended Memory Manager currently being distributed by Microsoft.
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. Extended Memory
  119. (Other EMBs could exist above 1088K (1MB+64K)
  120.  
  121.  
  122.  
  123.  
  124. Top of Memory
  125. 
  126. 
  127. High Memory Area (HMA)
  128.  
  129. 1088K
  130. 
  131. 
  132.  
  133.  
  134. Upper Memory Area
  135.  
  136.  
  137.  
  138. 1024K
  139. 
  140. 
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. Conventional or DOS memory
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. 640K
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167. 0K
  168. 
  169. 
  170.  
  171.  
  172. DRIVER INSTALLATION:
  173.  
  174. An XMS driver is installed by including a DEVICE= statement in the
  175. machine's CONFIG.SYS file.It must be installed prior to any other
  176. devices or TSRs which use it.  An optional parameter after the driver's
  177. name (suggested name "/HMAMIN=") indicates the minimum amount of space
  178. in the HMA a program can use.  Programs which use less than the minimum
  179. will not be placed in the HMA.  See "Prioritizing HMA Usage" below for
  180. more information.  A second optional parameter (suggested name
  181. "/NUMHANDLES=") allows users to specify the maximum number of extended
  182. memory blocks which may be allocated at any time.
  183.  
  184. NOTE: XMS requires DOS 3.00 or above.
  185.  
  186.  
  187. THE PROGRAMMING API:
  188.  
  189. The XMS API Functions are accessed via the XMS driver's Control
  190. Function. The address of the Control Function is determined via INT 2Fh.
  191. First, a program should determine if an XMS driver is installed.  Next,
  192. it should retrieve the address of the driver's Control Function.  It can
  193. then use any of the available XMS functions.  The functions are divided
  194. into several groups:
  195.  
  196. 1. Driver Information Functions (0h)
  197. 2. HMA Management Functions (1h-2h)
  198. 3. A20 Management Functions (3h-7h)
  199. 4. Extended Memory Management Functions (8h-Fh)
  200. 5. Upper Memory Management Functions (10h-11h)
  201.  
  202.  
  203. DETERMINING IF AN XMS DRIVER IS INSTALLED:
  204.  
  205. The recommended way of determining if an XMS driver is installed is to
  206. set AH=43h and AL=00h and then execute INT 2Fh.  If an XMS driver is
  207. available, 80h will be returned in AL.
  208.  
  209. Example:
  210.  
  211. ; Is an XMS driver installed?
  212. mov     ax,4300h
  213. int     2Fh         
  214. cmp     al,80h  
  215. jne     NoXMSDriver
  216.  
  217.  
  218. CALLING THE API FUNCTIONS:
  219.  
  220. Programs can execute INT 2Fh with AH=43h and AL=10h to obtain the
  221. address of the driver's control function.  The address is returned in
  222. ES:BX.  This function is called to access all of the XMS functions.  It
  223. should be called with AH set to the number of the API function
  224. requested.  The API function will put a success code of 0001h or 0000h
  225. in AX.  If the function succeeded (AX=0001h), additional information may
  226. be passed back in BX and DX.  If the function failed (AX=0000h), an
  227. error code may be returned in BL.  Valid error codes have their high bit
  228. set.  Developers should keep in mind that some of the XMS API functions
  229. may not be implemented by all drivers and will return failure in all
  230. cases.
  231.  
  232. Example:
  233.  
  234. ; Get the address of the driver's control function
  235. mov     ax,4310h
  236. int     2Fh
  237. mov     word ptr [XMSControl],bx        ; XMSControl is a DWORD
  238. mov     word ptr [XMSControl+2],es
  239.            
  240. ; Get the XMS driver's version number
  241. mov     ah,00h
  242. call    [XMSControl]    ; Get XMS Version Number
  243.  
  244. NOTE: Programs should make sure that at least 256 bytes of stack space
  245. is available before calling XMS API functions.
  246.  
  247.  
  248. API FUNCTION DESCRIPTIONS:
  249.  
  250. The following XMS API functions are available:
  251.  
  252. 0h)  Get XMS Version Number
  253. 1h)  Request High Memory Area
  254. 2h)  Release High Memory Area
  255. 3h)  Global Enable A20
  256. 4h)  Global Disable A20
  257. 5h)  Local Enable A20
  258. 6h)  Local Disable A20
  259. 7h)  Query A20
  260. 8h)  Query Free Extended Memory
  261. 9h)  Allocate Extended Memory Block
  262. Ah)  Free Extended Memory Block
  263. Bh)  Move Extended Memory Block
  264. Ch)  Lock Extended Memory Block
  265. Dh)  Unlock Extended Memory Block
  266. Eh)  Get Handle Information
  267. Fh)  Reallocate Extended Memory Block
  268. 10h)  Request Upper Memory Block
  269. 11h)  Release Upper Memory Block
  270. 12h) Realloc Upper Memory Block
  271. 88h) Query any Free Extended Memory
  272. 89h) Allocate any Extended Memory Block
  273. 8Eh) Get Extended EMB Handle
  274. 8Fh) Realloc any Extended Memory
  275.  
  276. Each is described below.
  277.  
  278.  
  279. Get XMS Version Number (Function 00h):
  280.  
  281.     ARGS:    AH = 00h
  282.     RETS:    AX = XMS version number
  283.         BX = Driver internal revision number
  284.         DX = 0001h if the HMA exists, 0000h otherwise
  285.     ERRS:    None
  286.  
  287. This function returns with AX equal to a 16-bit BCD number representing
  288. the revision of the DOS Extended Memory Specification which the driver
  289. implements (e.g. AX=0235h would mean that the driver implemented XMS
  290. version 2.35). BX is set equal to the driver's internal revision number
  291. mainly for debugging purposes.  DX indicates the existence of the HMA
  292. (not its availability) and is intended mainly for installation programs.
  293.  
  294. NOTE: This document defines version 3.00 of the specification.
  295.  
  296.  
  297. Request High Memory Area (Function 01h):
  298.  
  299.     ARGS:    AH = 01h
  300.          If the caller is a TSR or device driver,
  301.         DX = Space needed in the HMA by the caller in bytes
  302.         If the caller is an application program,
  303.         DX = FFFFh
  304.  
  305.     RETS:    AX = 0001h if the HMA is assigned to the caller, 0000h otherwise
  306.  
  307.         ERRS:     BL = 80h if the function is not implemented
  308.            BL = 81h if a VDISK device is detected
  309.            BL = 90h if the HMA does not exist
  310.            BL = 91h if the HMA is already in use
  311.            BL = 92h if DX is less than the /HMAMIN= parameter
  312.  
  313. This function attempts to reserve the 64K-16 byte high memory area for
  314. the caller.  If the HMA is currently unused, the caller's size parameter
  315. is compared to the /HMAMIN= parameter on the driver's command line. If
  316. the value passed by the caller is greater than or equal to the amount
  317. specified by the driver's parameter, the request succeeds.  This
  318. provides the ability to ensure that programs which use the HMA
  319. efficiently have priority over those which do not.
  320.  
  321. NOTE: See the sections "Prioritizing HMA Usage" and "High Memory Area
  322. Restrictions" below for more information.
  323.  
  324.  
  325. Release High Memory Area (Function 02h):
  326.  
  327.     ARGS:    AH = 02h
  328.  
  329.     RETS:    AX = 0001h if the HMA is successfully released, 0000h otherwise
  330.  
  331.     ERRS:     BL = 80h if the function is not implemented
  332.         BL = 81h if a VDISK device is detected
  333.            BL = 90h if the HMA does not exist
  334.         BL = 93h if the HMA was not allocated
  335.  
  336. This function releases the high memory area and allows other programs to
  337. use it. Programs which allocate the HMA must release it before exiting.
  338. When the HMA has been released, any code or data stored in it becomes
  339. invalid and should not be accessed.
  340.  
  341.  
  342. Global Enable A20 (Function 03h):
  343.  
  344.     ARGS:    AH = 03h
  345.  
  346.     RETS:    AX = 0001h if the A20 line is enabled, 0000h otherwise
  347.  
  348.     ERRS:    BL = 80h if the function is not implemented
  349.         BL = 81h if a VDISK device is detected
  350.         BL = 82h if an A20 error occurs
  351.  
  352. This function attempts to enable the A20 line.  It should only be used
  353. by programs which have control of the HMA. The A20 line should be turned
  354. off via Function 04h (Global Disable A20) before a program releases
  355. control of the system.
  356.  
  357. NOTE: On many machines, toggling the A20 line is a relatively slow operation.
  358.  
  359.  
  360. Global Disable A20 (Function 04h):
  361.  
  362.     ARGS:    AH = 04h
  363.  
  364.     RETS:     AX = 0001h if the A20 line is disabled, 0000h otherwise
  365.  
  366.     ERRS:    BL = 80h if the function is not implemented
  367.         BL = 81h if a VDISK device is detected
  368.         BL = 82h if an A20 error occurs
  369.         BL = 94h if the A20 line is still enabled
  370.  
  371. This function attempts to disable the A20 line.  It should only be used
  372. by programs which have control of the HMA.  The A20 line should be
  373. disabled before a program releases control of the system.
  374.  
  375. NOTE: On many machines, toggling the A20 line is a relatively slow
  376. operation.
  377.  
  378.  
  379. Local Enable A20 (Function 05h):
  380.  
  381.     ARGS:    AH = 05h
  382.  
  383.     RETS:    AX = 0001h if the A20 line is enabled, 0000h otherwise
  384.  
  385.     ERRS:    BL = 80h if the function is not implemented
  386.         BL = 81h if a VDISK device is detected
  387.         BL = 82h if an A20 error occurs
  388.  
  389. This function attempts to enable the A20 line.  It should only be used
  390. by programs which need direct access to extended memory. Programs which
  391. use this function should call Function 06h (Local Disable A20) before
  392. releasing control of the system.
  393.  
  394. NOTE: On many machines, toggling the A20 line is a relatively slow
  395. operation.
  396.  
  397.  
  398. Local Disable A20 (Function 06h):
  399.  
  400.     ARGS:    AH = 06h
  401.  
  402.     RETS:    AX = 0001h if the function succeeds, 0000h otherwise
  403.  
  404.     ERRS:    BL = 80h if the function is not implemented
  405.         BL = 81h if a VDISK device is detected
  406.         BL = 82h if an A20 error occurs
  407.         BL = 94h if the A20 line is still enabled
  408.  
  409. This function cancels a previous call to Function 05h (Local Enable
  410. A20).  It should only be used by programs which need direct access to
  411. extended memory.  Previous calls to Function 05h must be canceled before
  412. releasing control of the system.
  413.  
  414. NOTE: On many machines, toggling the A20 line is a relatively slow operation.
  415.  
  416. Query A20 (Function 07h):
  417.  
  418.     ARGS:    AH = 07h
  419.  
  420.     RETS:    AX = 0001h if the A20 line is physically enabled, 0000h otherwise
  421.  
  422.     ERRS:    BL = 00h if the function succeeds
  423.         BL = 80h if the function is not implemented
  424.         BL = 81h if a VDISK device is detected
  425.  
  426. This function checks to see if the A20 line is physically enabled. It
  427. does this in a hardware independent manner by seeing if "memory wrap"
  428. occurs.
  429.  
  430.  
  431. Query Free Extended Memory (Function 08h):
  432.  
  433.     ARGS:    AH = 08h
  434.  
  435.     RETS:    AX = Size of the largest free extended memory block in K-bytes
  436.         DX = Total amount of free extended memory in K-bytes
  437.  
  438.     ERRS:    BL = 80h if the function is not implemented
  439.         BL = 81h if a VDISK device is detected
  440.         BL = A0h if all extended memory is allocated
  441.  
  442. This function returns the size of the largest available extended memory
  443. block in the system.
  444.  
  445. NOTE: The 64K HMA is not included in the returned value even if it is
  446. not in use.
  447.  
  448.  
  449. Allocate Extended Memory Block (Function 09h):
  450.  
  451.     ARGS:    AH = 09h
  452.         DX = Amount of extended memory being requested in K-bytes
  453.  
  454.     RETS:    AX = 0001h if the block is allocated, 0000h otherwise
  455.         DX = 16-bit handle to the allocated block
  456.  
  457.     ERRS:    BL = 80h if the function is not implemented
  458.         BL = 81h if a VDISK device is detected
  459.         BL = A0h if all available extended memory is allocated
  460.         BL = A1h if all available extended memory handles are in use
  461.  
  462. This function attempts to allocate a block of the given size out of the
  463. pool of free extended memory. If a block is available, it is reserved
  464. for the caller and a 16-bit handle to that block is returned.  The
  465. handle should be used in all subsequent extended memory calls. If no
  466. memory was allocated, the returned handle is null.
  467.  
  468. NOTE: Extended memory handles are scarce resources. Programs should try
  469. to allocate as few as possible at any one time. When all of a driver's
  470. handles are in use, any free extended memory is unavailable.
  471.  
  472. Free Extended Memory Block (Function 0Ah):
  473.  
  474.     ARGS:    AH = 0Ah
  475.         DX = Handle to the allocated block which should be freed
  476.  
  477.     RETS:    AX = 0001h if the block is successfully freed, 0000h otherwise
  478.  
  479.     ERRS:    BL = 80h if the function is not implemented
  480.         BL = 81h if a VDISK device is detected
  481.         BL = A2h if the handle is invalid
  482.         BL = ABh if the handle is locked
  483.  
  484. This function frees a block of extended memory which was previously
  485. allocated using Function 09h (Allocate Extended Memory Block). Programs
  486. which allocate extended memory should free their memory blocks before
  487. exiting. When an extended memory buffer is freed, its handle and all
  488. data stored in it become invalid and should not be accessed.
  489.  
  490.  
  491. Move Extended Memory Block (Function 0Bh):
  492.  
  493.     ARGS:    AH = 0Bh
  494.         DS:SI = Pointer to an Extended Memory Move Structure (see below)
  495.  
  496.     RETS:    AX = 0001h if the move is successful, 0000h otherwise
  497.  
  498.     ERRS:    BL = 80h if the function is not implemented
  499.         BL = 81h if a VDISK device is detected
  500.         BL = 82h if an A20 error occurs
  501.         BL = A3h if the SourceHandle is invalid
  502.         BL = A4h if the SourceOffset is invalid
  503.         BL = A5h if the DestHandle is invalid
  504.         BL = A6h if the DestOffset is invalid
  505.         BL = A7h if the Length is invalid
  506.         BL = A8h if the move has an invalid overlap
  507.         BL = A9h if a parity error occurs
  508.  
  509. Extended Memory Move Structure Definition:
  510.  
  511.         ExtMemMoveStruct    struc
  512.             Length              dd  ?   ; 32-bit number of bytes to transfer
  513.             SourceHandle        dw  ?   ; Handle of source block
  514.             SourceOffset        dd  ?   ; 32-bit offset into source 
  515.             DestHandle          dw  ?   ; Handle of destination block
  516.             DestOffset          dd  ?   ; 32-bit offset into destination block
  517.         ExtMemMoveStruct    ends
  518.             
  519. This function attempts to transfer a block of data from one location to
  520. another. It is primarily intended for moving blocks of data between
  521. conventional memory and extended memory, however it can be used for
  522. moving blocks within conventional memory and within extended memory.
  523.  
  524. NOTE: If SourceHandle is set to 0000h, the SourceOffset is interpreted
  525. as a standard segment:offset air which refers to memory that is directly
  526. accessible by the processor.  The segment:offset pair is stored in Intel
  527. DWORD notation. The same is true for DestHandle and DestOffset.
  528.  
  529.  
  530.    SourceHandle and DestHandle do not have to refer to locked memory
  531.    blocks.
  532.    Length must be even.
  533.    Although not required, WORD-aligned moves can be significantly faster
  534.    on most machines. DWORD aligned move can be even faster on 80386
  535.    machines.
  536.    If the source and destination blocks overlap, only forward moves
  537.    (i.e. where the source base is less than the destination base) are
  538.    guaranteed to work properly.
  539.    Programs should not enable the A20 line before calling this function.
  540.    The state of the A20 line is preserved.
  541.  
  542. This function is guaranteed to provide a reasonable number of  interrupt
  543. windows during long transfers.
  544.  
  545.  
  546. Lock Extended Memory Block (Function 0Ch):
  547.  
  548.     ARGS:    AH = 0Ch
  549.         DX = Extended memory block handle to lock
  550.  
  551.     RETS:    AX = 0001h if the block is locked, 0000h otherwise
  552.         DX:BX = 32-bit physical address of the locked block
  553.  
  554.     ERRS:    BL = 80h if the function is not implemented
  555.         BL = 81h if a VDISK device is detected
  556.         BL = A2h if the handle is invalid
  557.         BL = ACh if the block's lock count overflows
  558.         BL = ADh if the lock fails
  559.  
  560. This function locks an extended memory block and returns its base
  561. address as a 32-bit physical address.  Locked memory blocks are
  562. guaranteed not to move.  The 32-bit pointer is only valid while the
  563. block is locked.Locked blocks should be unlocked as soon as possible.
  564.  
  565. NOTE: A block does not have to be locked before using Function 0Bh (Move
  566. Extended Memory Block). "Lock counts" are maintained for EMBs.
  567.  
  568.  
  569. Unlock Extended Memory Block (Function 0Dh):
  570.  
  571.     ARGS:    AH = 0Dh
  572.         DX = Extended memory block handle to unlock
  573.  
  574.     RETS:    AX = 0001h if the block is unlocked, 0000h otherwise
  575.  
  576.     ERRS:    BL = 80h if the function is not implemented
  577.         BL = 81h if a VDISK device is detected
  578.         BL = A2h if the handle is invalid
  579.         BL = AAh if the block is not locked
  580.     
  581. This function unlocks a locked extended memory block.  Any
  582. 32-bitpointers into the block become invalid and should no longer be
  583. used.
  584.  
  585.  
  586. Get EMB Handle Information (Function 0Eh):
  587.  
  588.     ARGS:    AH = 0Eh
  589.         DX = Extended memory block handle
  590.     RETS:    AX = 0001h if the block's information is found, 0000h otherwise
  591.         BH = The block's lock count
  592.         BL = Number of free EMB handles in the system
  593.         DX = The block's length in K-bytes
  594.  
  595.     ERRS:    BL = 80h if the function is not implemented
  596.         BL = 81h if a VDISK device is detected
  597.         BL = A2h if the handle is invalid
  598.  
  599. This function returns additional information about an extended memory
  600. block to the caller.
  601.  
  602. NOTE: To get the block's base address, use Function 0Ch (Lock Extended
  603. Memory Block).
  604.  
  605.  
  606. Reallocate Extended Memory Block (Function 0Fh):
  607.  
  608.     ARGS:    AH = 0Fh
  609.         BX = New size for the extended memory block in K-bytes
  610.         DX = Unlocked extended memory block handle to reallocate
  611.  
  612.     RETS:    AX = 0001h if the block is reallocated, 0000h otherwise
  613.  
  614.     ERRS:    BL = 80h if the function is not implemented
  615.         BL = 81h if a VDISK device is detected
  616.         BL = A0h if all available extended memory is allocated
  617.         BL = A1h if all available extended memory handles are in use
  618.         BL = A2h if the handle is invalid
  619.         BL = ABh if the block is locked
  620.  
  621. This function attempts to reallocate an unlocked extended memory block
  622. so that it becomes the newly specified size.  If the new size is smaller
  623. than the old block's size, all data at the upper end of the old block is
  624. lost.
  625.  
  626.  
  627. Request Upper Memory Block (Function 10h):
  628.  
  629.     ARGS:    AH = 10h
  630.         DX = Size of requested memory block in paragraphs
  631.  
  632.     RETS:    AX = 0001h if the request is granted, 0000h otherwise
  633.         BX = Segment number of the upper memory block
  634.         If the request is granted,
  635.         DX = Actual size of the allocated block in paragraphs otherwise,
  636.         DX = Size of the largest available UMB in paragraphs
  637.  
  638.     ERRS:    BL = 80h if the function is not implemented
  639.         BL = B0h if a smaller UMB is available
  640.         BL = B1h if no UMBs are available
  641.  
  642. This function attempts to allocate an upper memory block to the caller.
  643. If the function fails, the size of the largest free UMB is returned in
  644. DX.
  645.  
  646. NOTE: By definition UMBs are located below the 1MB address boundary.
  647. The A20 Line does not need to be enabled before accessing an allocated
  648. UMB.
  649.  
  650.    UMBs are paragraph aligned.
  651.    To determine the size of the largest available UMB, attempt to
  652.    allocate one with a size of FFFFh.
  653.    UMBs are unaffected by EMS calls.
  654.  
  655.  
  656. Release Upper Memory Block (Function 11h):
  657.  
  658.     ARGS:    AH = 11h
  659.         DX = Segment number of the upper memory block
  660.  
  661.     RETS:    AX = 0001h if the block was released, 0000h otherwise
  662.  
  663.     ERRS:    BL = 80h if the function is not implemented
  664.         BL = B2h if the UMB segment number is invalid
  665.  
  666. This function frees a previously allocated upper memory block.  When an
  667. UMB has been released, any code or data stored in it becomes invalid and
  668. should not be accessed.
  669.  
  670.  
  671. Reallocate Upper Memory Block (Function 12h)
  672.  
  673.     ARGS:    AH = 12h
  674.         BX = New size for UMB in paragraphs
  675.         DX = Segment number of the UMB to reallocate
  676.  
  677.     RETS:    AX = 1 if the block was reallocated, 0 otherwise
  678.  
  679.     ERRS:    BL = 80h if the function is not implemented
  680.                 BL = B0h if no UMB large enough to satisfy the request
  681.                          is available.
  682.                          In this event, DX is returned with the size of
  683.                          the largest UMB that is available.
  684.                 BL = B2h if the UMB segment number is invalid
  685.  
  686. This function attempts to reallocate an Upper Memory Block to a newly
  687. specified size. If the new size is smaller than the old block's size,
  688. all data at the upper end of the block is lost.
  689.  
  690.  
  691. SUPER EXTENDED MEMORY SUPPORT
  692.  
  693. These changes are intended to provide support for extended memory pools
  694. up to 4 Gb in size. The current XMS API, since it uses 16-bit values to
  695. specify block sizes in Kb, is limited to 64 Mb maximum block size.
  696. Future machines are expected to support memory above 64 MB.
  697.  
  698. This support is implemented in the form of extensions to existing
  699. functions, rather than entirely new entry points, to allow for more
  700. efficient implementations.
  701.  
  702. Programs should generally use the existing functions, instead of these
  703. extended ones, unless they have an explicit need to deal with memory
  704. above 64 Mb.  
  705.  
  706. Query Any Free Extended Memory (Function 88h)
  707.  
  708.     ARGS:    AH = 88h
  709.  
  710.     RETS:    EAX = Size of largest free extended memory block in Kb.
  711.         BL = 0 if no error occurs, otherwise it takes an error code.
  712.         ECX = Highest ending address of any memory block.
  713.         EDX = Total amount of free memory in Kb.
  714.  
  715.     ERRS:    BL = 80h if the function is not implemented.
  716.         BL = 81h if a VDISK device is detected.
  717.         BL = A0h if all extended memory is allocated.
  718.  
  719. This function uses 32-bit values to return the size of available memory,
  720. thus allowing returns up to 4GByte. Additionally, it returns the highest
  721. known physical memory address, that is, the physical address of the last
  722. byte of memory.  There may be discontinuities in the memory map below
  723. this address.
  724.  
  725. The memory pool reported on is the same as that reported on by the
  726. existing Query Free Extended Memory function.  If the highest memory
  727. address is not more than 64 Mb, then these two functions will return the
  728. same results.
  729.  
  730. Because of its reliance on 32-bit registers, this function is only
  731. available on 80386 and higher processors.  XMS drivers on 80286 machines
  732. should return error code 80h if this function is called.
  733.  
  734. If error code 81h is returned, the value in ECX will still be valid.  If
  735. error code A0h is returned, EAX and EDX will be 0, and ECX will still be
  736. valid.
  737.  
  738.  
  739. Allocate Any Extended Memory (Function 89h)
  740.  
  741.     ARGS:    AH = 89h
  742.         EDX = Amount of extended memory requested, in Kb.
  743.  
  744.     RETS:    AX = 1 if the block is allocated, 0 if not
  745.         DX = Handle to allocated block.
  746.  
  747.     ERRS:    BL = 80h if the function is not implemented.
  748.         BL = 81h if a VDISK device is detected.
  749.         BL = A0h if all available extended memory is allocated.
  750.         BL = A1h if all available extended memory handles are in use.
  751.  
  752. This function is similar to the existing Allocate Extended Memory,
  753. except that it uses a 32-bit instead of a 16-bit value to specify the
  754. amount of memory requested.  It allocates from the same memory and
  755. handle pool as the current function.  Since it requires a 32-bit
  756. register, this function can be supported only on 80386 and higher
  757. processors, and XMS drivers on 80286 machines should return error code
  758. 80h.
  759.  
  760. Get Extended EMB Handle Information (Function 8Eh)
  761.  
  762.     ARGS:    AH = 8Eh
  763.         DX = Extended memory block handle.
  764.  
  765.     RETS:    AX = 1 if the block's information is found, 0 if not
  766.         BH = Block lock count
  767.         CX = Number of free EMB handles in the system
  768.         EDX = Block's length in Kb.
  769.  
  770.     ERRS:    BL = 80h if the function is not implemented.
  771.         BL = 81h if a VDISK device is detected.
  772.         BL = A2h if the handle is invalid.
  773.  
  774. This function is similar to the Get EMB Handle Information function.
  775. Since it uses a 32-bit register to report the block size, it can be used
  776. to get information on blocks larger than 64 Mb.  It also uses a 16-bit
  777. instead of 8-bit register to report the number of free handles, allowing
  778. the handle pool to be extended beyond 256 entries.
  779.  
  780. Because of its reliance on a 32-bit register, this function is available
  781. on 80386 and higher processors.  XMS drivers on 80286 machines should
  782. return error code 80h if this function is called.
  783.  
  784.  
  785. Reallocate Any Extended Memory (Function 8Fh)
  786.  
  787.     ARGS:    AH = 8Fh
  788.         EBX = New size for extended memory block, in Kb.
  789.         DX = Unlocked handle for memory block to be resized.
  790.  
  791.     RETS:    AX = 1 if the block is reallocated, 0 if not
  792.  
  793.     ERRS:    BL = 80h if the function is not implemented.
  794.         BL = 81h if a VDISK device is detected.
  795.         BL = A0h if all available extended memory is allocated.
  796.         BL = A1h if all available extended memory handles are in use.
  797.         BL = A2h if the handle is invalid.
  798.         BL = ABh if the block is locked.
  799.  
  800. This function is similar to the existing Reallocate Extended Memory,
  801. except that it uses a 32-bit instead of a 16-bit value to specify the
  802. amount of memory requested.  It allocates from the same memory and
  803. handle pool as the current function.  Since it requires a 32-bit
  804. register, this function can be supported only on 80386 and higher
  805. processors, and XMS drivers on 80286 machines should return error code
  806. 80h.
  807.  
  808.  
  809. PRIORITIZING HMA USAGE:
  810.  
  811. For DOS users to receive the maximum benefit from the High Memory Area,
  812. programs which use the HMA must store as much of their resident code in
  813. it as is possible. It is very important that developers realize that the
  814. HMA is allocated as a single unit. 
  815.  
  816. For example, a TSR program which grabs the HMA and puts 10K of code into
  817. it may prevent a later TSR from putting 62K into the HMA.  Obviously,
  818. regular DOS programs would have more memory available to them below the
  819. 640K line if the 62K TSR was moved into the HMA instead of the 10K one.
  820.  
  821. The first method for dealing with conflicts such as this is to require
  822. programs which use the HMA to provide a command line option for
  823. disabling this feature.  It is crucial that TSRs which do not make full
  824. use of the HMA provide such a switch on their own command line
  825. (suggested name "/NOHMA").
  826.  
  827. The second method for optimizing HMA usage is through the
  828. /HMAMIN=parameter on the XMS device driver line.  The number after the
  829. parameter is defined to be the minimum amount of HMA space (in K-bytes)
  830. used by any driver or TSR. For example, if "DEVICE=HIMEM.SYS /HMAMIN=48"
  831. is in a user's CONFIG.SYS file, only programs which request at least 48K
  832. would be allowed to allocate the HMA.  This number can be adjusted
  833. either by installation programs or by the user himself.  If this
  834. parameter is not specified, the default value of 0 is used causing the
  835. HMA to be allocated on a first come, first served basis.
  836.  
  837. Note that this problem does not impact application programs.  If the HMA
  838. is available when an application program starts, the application is free
  839. to use as much or as little of the HMA as it wants.  For this reason,
  840. applications should pass FFFFh in DX when calling Function 01h.
  841.  
  842.  
  843. HIGH MEMORY AREA RESTRICTIONS:
  844.  
  845.     Far pointers to data located in the HMA cannot be passed to DOS. DOS
  846.     normalizes any pointer which is passed into it. This will cause data
  847.     addresses in the HMA to be invalidated.
  848.  
  849.     Disk I/O directly into the HMA (via DOS, INT 13h, or otherwise) is
  850.     not recommended.
  851.  
  852.     Programs, especially drivers and TSRs, which use the HMA *MUST* use
  853.     as much of it as possible. If a driver or TSR is unable to use at
  854.     least 90% of the available HMA (typically ~58K), they must provide a
  855.     command line switch for overriding HMA usage. This will allow the
  856.     user to configure his machine for optimum use of the HMA.
  857.  
  858.     Device drivers and TSRs cannot leave the A20 line permanently turned
  859.     on. Several applications rely on 1MB memory wrap and will overwrite
  860.     the HMA if the A20 line is left enabled potentially causing a system
  861.     crash.
  862.  
  863.     Interrupt vectors must not point into the HMA.  This is a result of
  864.     the previous restriction. Note that interrupt vectors can point into
  865.     any allocated upper memory blocks however.
  866.  
  867. ERROR CODE INDEX:
  868.  
  869. If AX=0000h when a function returns and the high bit of BL is set,
  870.  
  871. BL=    80h if the function is not implemented
  872.     81h if a VDISK device is detected
  873.     82h if an A20 error occurs
  874.     8Eh if a general driver error occurs
  875.     8Fh if an unrecoverable driver error occurs
  876.     90h if the HMA does not exist
  877.     91h if the HMA is already in use
  878.     92h if DX is less than the /HMAMIN= parameter
  879.     93h if the HMA is not allocated
  880.     94h if the A20 line is still enabled
  881.     A0h if all extended memory is allocated
  882.     A1h if all available extended memory handles are in use
  883.     A2h if the handle is invalid
  884.     A3h if the SourceHandle is invalid
  885.     A4h if the SourceOffset is invalid
  886.         A5h if the DestHandle is invalid
  887.        A6h if the DestOffset is invalid
  888.     A7h if the Length is invalid
  889.     A8h if the move has an invalid overlap
  890.     A9h if a parity error occurs
  891.     AAh if the block is not locked
  892.     ABh if the block is locked
  893.     ACh if the block's lock count overflows
  894.     ADh if the lock fails
  895.     B0h if a smaller UMB is available
  896.     B1h if no UMBs are available
  897.     B2h if the UMB segment number is invalid
  898.  
  899.  
  900. IMPLEMENTATION NOTES FOR DOS XMS DRIVERS:
  901.  
  902.     A DOS XMS driver's control function must begin with code similar to
  903.     the following:
  904.  
  905. XMMControl  proc    far
  906.  
  907.         jmp     short XCControlEntry    ; For "hookability"
  908.         nop                   ; NOTE: The jump must be a short
  909.         nop                 ;  jump to indicate the end of
  910.         nop                 ;  any hook chainThe nop's
  911.                         ;  allow a far jump to be
  912.                         ;  patched in.
  913. XCControlEntry:
  914.  
  915.  
  916.     XMS drivers must preserve all registers except those containing
  917.     returned values across any function call.
  918.  
  919.     XMS drivers are required to hook INT 15h and watch for calls to
  920.     functions 87h (Block Move) and 88h (Extended Memory Available). The
  921.     INT 15h Block Move function must be hooked so that the state of the
  922.     A20 line is preserved across the call. The INT 15h Extended Memory
  923.     Available function must be hooked to return 0h to protect the HMA.
  924.  
  925.     In order to maintain compatibility with existing device drivers, DOS
  926.     XMS drivers must not hook INT 15h until the first non-Version Number
  927.     call to the control function is made.
  928.  
  929.     XMS drivers are required to check for the presence of drivers which
  930.     use the IBM VDISK allocation scheme.  Note that it is not sufficient
  931.     to check for VDISK users at installation time but at the time when
  932.     the HMA is first allocated.  If a VDISK user is detected, the HMA
  933.     must not be allocated. Microsoft will publish a standard method for
  934.     detecting drivers which use the VDISK allocation scheme.
  935.  
  936.     XMS drivers which have a fixed number of extended memory handles
  937.     (most do) should implement a command line parameter for adjusting
  938.     that number (suggested name "/NUMHANDLES=")
  939.  
  940.     XMS drivers should make sure that the major DOS version number is
  941.     greater than or equal to 3 before installing themselves.
  942.  
  943.     UMBs cannot occupy memory addresses that can be banked by EMS
  944.     4.0.EMS 4.0 takes precedence over UMBs for physically addressable
  945.     memory.
  946.  
  947.     All driver functions must be re-entrant.  Care should be taken to
  948.     not leave interrupts disabled for long periods of time.
  949.  
  950.  
  951.     Allocation of a zero length extended memory buffer is allowed.
  952.     Programs which hook XMS drivers may need to reserve a handle for
  953.     private use via this method.  Programs which hook an XMS driver
  954.     should pass all requests for zero length EMBs to the next driver in
  955.     the chain.
  956.  
  957.     Drivers should control the A20 line via an "enable count." Local
  958.     Enable only enables the A20 line if the count is zero.  It then
  959.     increments the count. Local Disable only disables A20 if the count
  960.     is one.  It then decrements the count. Global Enable/Disable keeps a
  961.     flag which indicates the state of A20.  They use Local
  962.     Enable/Disable to actually change the state.
  963.  
  964.     Drivers should always check the physical A20 state in the local
  965.     Enable-Disable calls, to see that the physical state matches the
  966.     internal count.  If the physical state does not match, it should be
  967.     modified so that it matches the internal count.  This avoids
  968.     problems with applications that modify A20 directly.
  969.  
  970.  
  971. IMPLEMENTATION OF CODE FOR HOOKING THE XMS DRIVER:
  972.  
  973. In order to support the hooking of the XMS driver by multiple pieces of
  974. code, the following code sample should be followed. Use of other methods
  975. for hooking the XMS driver will not work in many cases. This method is
  976. the official supported one.
  977.  
  978. The basic strategy is:
  979.  
  980.     Find the XMS driver header which has the "near jump" dispatch.
  981.  
  982.     Patch the near jump to a FAR jump which jumps to my HOOK XMS driver
  983.     header.
  984.  
  985. NOTES:
  986.  
  987.     This architecture allows the most recent HOOKer to undo his XMS
  988.     driver hook at any time without having to worry about damaging a
  989.     "hook chain".
  990.  
  991.     This architecture allows the complete XMS hook chain to be
  992.     enumerated at any time. There are no "hidden hooks".
  993.  
  994.     This architecture allows the HOOKer to not have to worry about
  995.     installing an "INT 2F hook" to hook the AH=43h INT 2Fs handled by
  996.     the XMS driver. The base XMS driver continues to be the only one
  997.     installed on INT 2Fh AH=43h.
  998.  
  999.     This avoids all of the problems of undoing a software interrupt
  1000.     hook.
  1001.  
  1002.   ;
  1003.   ; When I wish to CHAIN to the previous XMS driver, I execute a FAR JMP
  1004.   ; to the address stored in this DWORD.
  1005.   ;
  1006.   PrevXMSControlAddr    dd      ?
  1007.  
  1008.   ;
  1009.   ; The next two data items are needed ONLY if I desire to be able to undo
  1010.   ; my XMS hook.
  1011.   ; PrevXMSControlJmpVal stores the previos XMS dispatch near jump offset
  1012.   ; value that is used to unhook my XMS hook
  1013.   ; PrevXMSControlBase stores the address of the XMS header that I hooked
  1014.   ;
  1015.   PrevXMSControlBase    dd      ?
  1016.   PrevXMSControlJmpVal  db      ?
  1017.  
  1018.   ;
  1019.   ; This is MY XMS control header.
  1020.   ;   MyXMSControlFunc proc FAR
  1021.         jmp     short XMSControlEntry
  1022.         nop
  1023.         nop
  1024.         nop
  1025.   XMSControlEntry:
  1026.  
  1027.   ......
  1028.  
  1029.   Chain:
  1030.         jmp     cs:[PrevXMSControlAddr]
  1031.  
  1032.   MyXMSControlFunc endp
  1033.  
  1034.  
  1035.   .......
  1036.   ;
  1037.   ; This is the code which installs my hook into the XMS driver.
  1038.   ;
  1039.   ;
  1040.   ; See if there is an XMS driver to hook
  1041.   ;
  1042.         mov     ax,4300h
  1043.         int     2Fh
  1044.         cmp     al,80h
  1045.         jne     NoXMSDrvrToHookError
  1046.   ;
  1047.   ; Get the current XMS driver Control address
  1048.   ;
  1049.         mov     ax,4310h
  1050.         int     2Fh
  1051.   NextXMSHeader:
  1052.         mov     word ptr [PrevXMSControlAddr+2],es
  1053.         mov     word ptr [PrevXMSControlBase+2],es
  1054.         mov     word ptr [PrevXMSControlBase],bx
  1055.         mov     cx,word ptr es:[bx]
  1056.         cmp     cl,0EBh                         ; Near JUMP
  1057.         je      ComputeNearJmp
  1058.         cmp     cl,0EAh                         ; Far JUMP
  1059.         jne     XMSDrvrChainMessedUpError
  1060.   ComputeFarJmp:
  1061.         mov     si,word ptr es:[bx+1]           ; Offset of jump
  1062.         mov     es,word ptr es:[bx+1+2]         ; Seg of jump
  1063.         mov     bx,si
  1064.         jmp     short NextXMSHeader
  1065.  
  1066.   ComputeNearJmp:
  1067.         cmp     word ptr es:[bx+2],9090h        ; Two NOPs?
  1068.         jne     XMSDrvrChainMessedUpError       ; No
  1069.         cmp     byte ptr es:[bx+4],90h          ; Total of 3 NOPs?
  1070.         jne     XMSDrvrChainMessedUpError       ; No
  1071.         mov     di,bx                           ; Save pointer to header
  1072.         xor     ax,ax
  1073.         mov     al,ch                           ; jmp addr of near jump
  1074.         mov     [PrevXMSControlJmpVal],al
  1075.         add     ax,2                            ; NEAR JMP is 2 byte instruction
  1076.         add     bx,ax                           ; Target of jump
  1077.         mov     word ptr [PrevXMSControlAddr],bx
  1078.   ;
  1079.   ; Now INSTALL my XMS HOOK
  1080.   ;
  1081.         cli                             ; Disable INTs in case someone calls
  1082.                                         ;       XMS at interrupt time
  1083.         mov     byte ptr es:[di],0EAh   ; Far Immed. JUMP instruction
  1084.         mov     word ptr es:[di+1],offset MyXMSControlFunc
  1085.         mov     word ptr es:[di+3],cs
  1086.         sti
  1087.     .....
  1088.  
  1089.   ;   ; Deinstall my XMS hook. This can be done IF AND ONLY IF my XMS header
  1090.   ;   still contains the near jump dispatch
  1091.   ;
  1092.         cmp     byte ptr [MyXMSControlFunc],0EBh
  1093.         jne     CantDeinstallError
  1094.         mov     al,0EBh
  1095.         mov     ah,[PrevXMSControlJmpVal]
  1096.         les     bx,[PrevXMSControlBase]
  1097.         cli                             ; Disable INTs in case someone calls
  1098.                                         ;       XMS at interrupt time
  1099.         mov     word ptr es:[bx],ax
  1100.         mov     word ptr es:[bx+2],9090h
  1101.         mov     byte ptr es:[bx+4],90h
  1102.         sti
  1103.     ....
  1104.  
  1105.  
  1106. IMPLEMENTATION NOTES FOR HIMEM.SYS:
  1107.  
  1108.     HIMEM.SYS currently supports true AT-compatibles, 386 AT machines,
  1109.     IBM PS/2s, AT&T 6300 Plus systems and Hewlett Packard Vectras.
  1110.  
  1111.     If HIMEM finds that it cannot properly control the A20 line or if
  1112.     there is no extended memory available when HIMEM.SYS is invoked, the
  1113.     driver does not install itself. HIMEM.SYS displays the message "High
  1114.     Memory Area Unavailable" when this situation occurs.
  1115.  
  1116.     If HIMEM finds that the A20 line is already enabled when it is
  1117.     invoked, it will NOT change the A20 line's state.  The assumption is
  1118.     that whoever enabled it knew what they were doing.  HIMEM.SYS
  1119.     displays the message "A20 Line Permanently Enabled" when this
  1120.     situation occurs.
  1121.  
  1122.     HIMEM.SYS is incompatible with IBM's VDISK.SYS driver and other
  1123.     drivers which use the VDISK scheme for allocating extended memory.
  1124.     However,  HIMEM does attempt to detect these drivers and will not
  1125.     allocate the HMA if one is found.
  1126.  
  1127.     HIMEM.SYS supports the optional "/HMAMIN=" parameter.  The valid
  1128.     values are decimal numbers between 0 and 63.
  1129.  
  1130.     By default, HIMEM.SYS has 32 extended memory handles available for
  1131.     use. This number may be adjusted with the "/NUMHANDLES=" parameter.
  1132.     The maximum value for this parameter is 128 and the minimum is 0.
  1133.     Each handle currently requires 6 bytes of resident space.
  1134.  
  1135. Extended Memory Specification (XMS) version 3.0
  1136.  
  1137.  
  1138. Copyright (c) 1988,1992 Microsoft Corporation
  1139.  
  1140.  
  1141.