Accessing Upper Memory

▌Overview▐█ 
  Starting with DOS 5.0, DOS supports access to Upper Memory Blocks (UMBs)
  on 386+ based computers which have installed the HIMEM.SYS and EMM386.EXE
  device drivers and have use DOS=UMB in CONFIG.SYS.

   Notes: ■ See XMS for info on accessing Extended memory
          ■ See EMS for info on accessing Expanded memory
          ■ See INT 2fH 4axxH for info on allocating part of the HMA

  At the user-interface level, just use the DOS Loadhigh command or the
  DEVICEHIGH= CONFIG.SYS command to load a TSR or device driver into upper
  memory.  TSRs and applications can also make use of upper memory via:

    Fn 5800H (query allocation strategy)       3.0+
    Fn 5801H (set allocation strategy)         3.0+
    Fn 5802H (query upper-memory link state)   5.0+
    Fn 5803H (set upper-memory link state)     5.0+

█▌Allocating in UMBs▐█
  To obtain access to an unallocated portion of a UMB, use the following
  steps:

   1) Use fn 5802H and save the current UMB link state.

   2) Use fn 5803H with BX=0001H to link-in upper memory.

   3) Use fn 5800H and save the current allocation strategy code.

   4) Use fn 5801H with BX=0041H (for instance) to set the allocation
      strategy to "best fit high-only".

   5) Use fn 48H with BX=ffffH to learn the size of the largest available
      allocation in upper memory.

   6) Use fn 48H with BX=desired_size to allocate the memory.  The segment
      returned in AX will be higher than a000H if the memory was allocated
      in a UMB.

   7) Be sure to use fns 5803H and 5801H to restore the previous link state
      and allocation strategy saved in steps 1 and 3.  And use fn 49H to
      free the allocation when you're done with it.

█▌Loading a TSR High▐█
  A TSR can load itself into a upper memory automatically, without having
  the user use the Loadhigh command via these steps:

   1) Check to see if this is the second copy of your program.  One
      technique is to hook INT 2fH and watch for your own MUX-ID (and
      communicate with the resident copy via your own internal API).
      Another it to examine the MCB chain and look for your own name.
      Another way might be to see if your PSP is above a000H.

      If this is the second copy, just initialize yourself and exit via
      fn 31H (terminate and stay resident).

   2) Set the link to upper memory via fn 5803H and select a "load high
      only" allocation strategy via fn 5801H.

   3) Make sure there is enough upper memory for your program.

   4) Examine the DOS Environment to learn the filespec (including drive
      and path) that was used to start you.

   5) Use DOS fn 4b00H (or a variant) to load and execute another copy of
      your program.  Since the UMB-link is set and there is enough high
      RAM, the copy will be loaded into upper memory.

   6) Restore the UMB-link and allocation strategy via fns 5803H and 5801H
      and terminate normally via fn 4cH.

  Of course, if there is no room in upper memory, you should install
  yourself normally, into conventional memory.

  Important: If you use this technique, be sure to provide a way for users
  to override (e.g., a /LOW command-line option).  Many users require very
  specific control over UMB usage.

█▌HMA Suballocations▐█
  A small part of the HMA (up to about 16K, but often much less) may be
  available for use by device drivers and TSRs.  It is usually occupied by
  DOS buffers (see BUFFERS=) or by the MRCI-engine portion of the
  DoubleSpace support for DOS 6.2.

  See the ◄undocumented► function INT 2fH 4axxH for details.

See Also: Memory Control Functions
          DOS Functions
                                    -♦-