  MS-DOS 6.xx/7.00 + Windows 3.1x/95 MEMORY MANAGEMENT TECHNICAL DETAILS



                              MEMORY TYPES



3 different kinds of memory can be installed in your machine:
1. conventional, also called "low" memory (or RAM),
2. extended and
3. expanded memory.
In addition, IBM compatible machines contain a 384K Upper Memory Area (UMA).

NOTE: Windows 386 enhanced mode applies to Windows 3.1x and Windows for
      WorkGroups 3.1x, NOT to Windows 95.
      Only the EMM386.EXE 16bit DOS mode memory management part of Windows 95
      is detailed in this document.


Conventional Memory

Conventional memory is the first 640K of memory in your machine. MS-DOS has
a limit of 1024K of addressable memory (conventional memory plus the UMA),
and all MS-DOS applications must run within this conventional memory. All
Windows 386 enhanced operating mode share this limitation for running MS-DOS
applications, but breaks the 640K limitation for running Windows
applications. Windows 386 enhanced mode can create multiple virtual MS-DOS
machines.

NOTE: 386 enhanced mode Windows also allows MS-DOS applications to break the
      640K barrier if they are written to use the Microsoft DOS Protected
      Mode Interface (DPMI) specification. DPMI allows MS-DOS applications to
      run in protected mode under Windows, using up to 16 megabytes (MB) of
      extended memory directly. Applications must be specifically written for
      DPMI to take advantage of this feature.


384K Upper Memory Area (UMA)

Between the top of conventional memory at 640K & the start of extended memory
at 1024K lies the 384K UMA. This area does not contain physical memory.
Mapped into the 384K UMA are the system BIOS (basic input/output system) ROM
chips & the display adapter memory. When you install other accessory cards,
such as network adapters, they may also occupy space within the 384K UMA. It
is important to remember that the 384K UMA is always located in the same area
of the IBM-compatible computer's address space: from 640K to 1024K (A000 to
FFFF hexadecimal). There are no exceptions to this rule.
This means that a standard IBM-compatible machine with 640K of conventional
memory installed really has 1 MB of address space. The system memory occupies
the first 640K, & the 384K UMA occupies the area from 640K to 1 MB (1024K).
This does not mean that the machine has 1 MB of memory. A machine with 1 MB
of physical memory has an address space of 1408K. This consists of the 640K
of conventional memory, the 384K UMA, & the 384K of extended memory starting
at 1024K.


Extended Memory (XMS)

Extended memory is the simplest type of add-on memory to understand.
It is also the type of memory used by Windows running in 386 enhanced
operating mode. Extended memory is a seamless continuation of the original
1 MB address space on 80286/80386 computers. Extended memory always starts
exactly at 1024K, where the 384K UMA ends. There are no exceptions.
It is not possible for an 8086 or 8088 machine to have extended memory. This
is a hardware limitation of the 8086/8088 processors, which can handle only
1024K of total address space (that is, 640K of system memory plus the 384K
UMA). This is one reason why Windows 3.1xx cannot run on 8086/8088-based
machines, as it requires a minimum of 256K of extended memory (or 1024K for
enhanced mode). The 80286 processor can address 16 MB of total memory, & the
80386 processor can address up to 4 gigabytes (GB).

NOTE: PC manufacturers often refer to extended memory as expansion memory,
      which is not to be confused with expanded memory.

Windows and all applications running under Windows access extended memory
through the Microsoft Extended Memory Specification (XMS). Rather than
accessing extended memory directly, access is made through an XMS driver.
The driver supplied by Microsoft for this purpose is called HIMEM.SYS.
Older MS-DOS applications that check available extended memory through
interrupt 15, service 88H will not see any extended memory with an XMS driver
loaded. Such applications must be rewritten to use the XMS, instead of
interrupt 15, to access extended memory.


Expanded Memory (EMS)

Windows 386 enhanced mode doesn't use expanded memory but may be able to
provide it to MS-DOS applications. It is important to understand the concept
of expanded memory if you still run MS-DOS applications that use it.
There are 2 different kinds of expanded memory, differentiated by their
Lotus/Intel/Microsoft (LIM) Expanded Memory Specification (EMS) version
numbers.


LIM 3.2 Expanded Memory

We discussed earlier how PC/XT machines with 8086/8088 processors can address
only 1024K of memory, of which only 640K can be used as RAM for MS-DOS &
MS-DOS applications. You can't add more than 640K of conventional memory to
the system, but you can provide more than 640K through a technique called
bank switching. Expanded memory uses an empty area in the 384K UMA of the
machine to provide this functionality.
To use an expanded memory card, you must load a device driver to let the card
know how to communicate with the PC. This device driver is called an expanded
memory manager (EMM). A LIM 3.2 EMM establishes a 64K page frame within the
384K UMA to perform EMS bank switching. The 64K page frame consists of 4
contiguous 16K pages. LIM 3.2 expanded memory won't work without a 64K
contiguous page frame.
The page frame is the area where the EMM maps information into & out of the
RAM of the expanded memory card. Information is not physically copied from
the EMS card to the RAM of the computer; the device driver simply makes the
page frame point to the data on the expanded memory card. The data then
appears in the page frame, and your application can access it.


LIM 4.0 Expanded Memory

LIM 3.2 expanded memory is fine for storing data such as spreadsheets in
expanded memory; however, because the LIM 3.2 specification does not allow
programs to run in expanded memory, it is not useful for multitasking.
There are 2 major differences between LIM 3.2 & 4.0. First, with LIM 4.0 you
can have many more than four 16K pages. LIM 4.0 supports up to 64 pages,
which are enough to bank 1 MB of memory at once. Second, the page frame
itself no longer must be four contiguous 16K pages. In fact, you need no
page frame at all. Whichever EMS version you are dealing with, the basic
operating principle of bank switching is still at work.


Backfilling

With LIM 4.0's limit of 64 16K pages, you have enough pages to bank switch
the entire conventional address range of the processor.
However, there must be no active ROM or RAM of any sort where you put an
expanded memory page. Thus, you can't map EMS pages on top of anything that
is already occupying address space in your machine (such as loaded MS-DOS or
video/system ROM). On the 80286 processor, you should disable as much
motherboard memory as possible (down to 256K) and let the expanded memory
card supply that memory. This process is called backfilling. This doesn't
mean that your computer will have only 256K, your programs still see a 640K
machine. But because the expanded memory card is now supplying the memory,
it can bank switch the memory. This capability is called "large page frame"
EMS, & it allows programs to run executable code in expanded memory, a major
improvement over LIM 3.2.
The 80386 processor has a built-in ability to readdress any page of memory to
any other location. This means you don't have to backfill on an 80386 to get
large page frame LIM 4.0 functionality, nor do you need an expanded memory
board. It's easy to convert your 80386's extended memory to expanded memory
with an 80386 EMM such as Microsoft's EMM386.EXE.
Though a memory driver may conform to the LIM 4.0 specification, that doesn't
mean the hardware can provide more than 4 pages. Also, because Windows 3.1x
supports extended memory directly, backfilling expanded memory will not give
you any advantages, & the memory on the motherboard is often faster than
memory on an expanded memory board.


LIMulators

On 80386 machines, it is possible to use a 386 expanded memory manager (such
as EMM386, QEMM386, RM386 or 386MAX) to emulate expanded memory. These
LIMulators use the XMS rather than interrupt 15 memory to emulate expanded
memory & are much more efficient than other types of LIMulators.


Expanded Memory Difficulties

LIM 3.2 expanded memory requires a page frame to work, and the page frame is
located within the 384K UMA of your machine. Unfortunately, your EMM is not
the only competitor for that memory space. Add-on boards: network cards; 3270
emulation cards; RLL, SCSI, IDE & EIDE disk controllers; high-resolution
video cards, can contend for this address space. Several potential
difficulties can arise due to this contention:
1. LACK OF SPACE. The major problem is simply finding at least 64K of
   contiguous free space in which to locate the LIM 3.2 page frame. LIM 4.0
   does not require a 64K page frame but is almost useless without it, as
   very few applications have been written to take advantage of the LIM 4.0
   specification. Frequently, the address areas of various adapter cards need
   to be shuffled to open a contiguous 64K page frame.
2. MAPPING CONFLICTS. Most 386 EMMs (such as EMM386.EXE) use a search
   algorithm to find unused memory addresses between C000 & DFFF located in
   the 384K UMA to use as page frames. Some cards (adapters) do not reserve
   their address space until you access the card, so the memory manager can
   inadvertently map EMS pages on top of an address the card will request.
   This is often true of Token Ring network adapters and can cause hanging
   and intermittent operation.
In case of problems, the first thing to do is disable expanded memory.
This procedure will determine whether a page conflict is causing your
difficulty. If the problem goes away without expanded memory, the memory
manager must be told to exclude the address the adapter is occupying from
consideration as a page location. Consult your memory manager's manual for
info on how to exclude an address range. The adapter may also have to be
moved; you do this in different ways with different memory managers.



                   EMM386.EXE v4.45 and v4.95 Memory Manager



I. Using the /S Switch with DEVICEHIGH/LOADHIGH

You can use the DEVICEHIGH/LOADHIGH switches /S and /L together to control
where programs are loaded in upper memory blocks (UMBs) and how much space
they allocate. Both switches affect the way programs interpret UMBs.
If you load a program with the /L switch, the program only recognizes
the memory regions you specify in the /L parameters. If you load a
program with the /S switch, the program only recognizes the regions
you specify and the amount of memory you specify--these switches are
useful if you are optimizing conventional memory because you can
restrict the way a program uses a particular memory region.
For example, the SMARTDrive utility has the ability to load itself
into UMBs: it is first loaded and initialized in conventional memory
and then is relocated to the largest available UMB it finds. By
default, SMARTDrive attempts to load as much of itself as it can into
UMBs; other programs will not be able to use free UMBs because
SMARTDrive has used too much space. Since SMARTDrive does not have to
reside in one memory area, you can use your UMBs more efficiently by
forcing SMARTDrive to use only a certain amount of UMB space. You can
accomplish this by using the /L and /S switches together.
The following command line (from AUTOEXEC.BAT) tells SMARTDrive that
only region 0 (conventional memory) and 3 are free:
LOADHIGH /L:0;3,42416 /S C:\DOS\SMARTDRV.EXE
SMARTDrive is first loaded and initialized in conventional memory
(region 0) and then relocates itself to region 3. Since the /L switch
specifies a minimum size of 42416 bytes and the /S switch changes this
minimum to the absolute value free in region 3, SMARTDrive only
recognizes region 0 and 3 as free and only recognizes 42416 bytes
available in region 3. Therefore, SMARTDrive loads 42416 bytes of
itself into region 3 and the rest in region 0. This loading process
results in more free memory in region 3 because SMARTDrive is not able
to relocate all of itself in that region. The next program you load
with the LOADHIGH command has enough space to load completely and your
available conventional memory is increased.



II. Regions Scanned by the EMM386.EXE HIGHSCAN Switch

HIGHSCAN switch included in EMM386.EXE version 4.45 allows EMM386.EXE
to map expanded memory pages or upper memory blocks (UMBs) over portions
of the upper memory area (UMA) used by system read-only memory (ROM).
Choosing "Yes" in response to the MemMaker prompt "Scan the upper memory area
aggressively?" causes MemMaker to add HIGHSCAN to EMM386.EXE device= line.
If you use HIGHSCAN on the DEVICE=C:\DOS\EMM386.EXE line in CONFIG.SYS,
EMM386.EXE examines system ROM area starting at memory location F000:0000.
If EMM386.EXE determines that ROM is duplicated between F000h-F7FFh and
F800h-FFFFh, EMM386.EXE uses the F000h-F7FFh region for expanded memory page
mapping or UMB memory. This adds up to 32KB to the UMA.
NOTE: On some systems, EMM386.EXE uses the ROM area and the system doesn't
operate correctly. The symptoms of this condition vary. For example, the
system may stop responding (hang) or appear to operate normally until you use
a floppy disk drive. Because of these potential problems, HIGHSCAN is not
used by default.



III. Changes in EMM386.EXE versions 4.45 and 4.95 (MS-DOS 6.xx and 7.00)

Versions 4.45/4.95 of the Microsoft expanded memory manager (EMM386.EXE),
provided with MS-DOS version 6.xx/7.00, have the following new features (also
valid for MS DOS 7.00/Windows 95 version):
 - Advanced Upper Memory Scanning
 - Expanded and Extended Memory Sharing
 - Ability to Provide Upper Memory Regions for Microsoft Windows
 - Ability to Load with NOEMS When No Page Frame Is Available
 - NOVCPI Switch for Smaller Load Size
 - Automatic IBM Token Ring Adapter Detection (added NOTR switch)
 - Quiet Loading
 - Ability to Provide ROM Shadowing


Advanced Upper Memory Scanning

EMM386.EXE can now scan the F000h-F7FFh region when the system read-only
memory (ROM) is duplicated between F000h-F7FFh and F800h-FFFFh. Also,
EMM386.EXE will include the ROM BASIC area on IBM PS/2 systems.
To enable advanced upper memory scanning, add the HIGHSCAN switch to the
DEVICE= line for EMM386.EXE in CONFIG.SYS.
NOTE: On some machines, with older BIOS versions, specifying HIGHSCAN on the
      EMM386.EXE line could hang the system. Replace HIGHSCAN with the less
      agressive RAM switch, which does a similar good job in identifying
      useable upper memory blocks (UMBs).


Expanded and Extended Memory Sharing

Previous versions of EMM386.EXE allocated as much extended memory memory as
possible during the initialization phase. This tied up memory that could
otherwise have been used by programs that use expanded memory. EMM386.EXE
version 4.45 includes support for dynamic allocation of memory. This means
EMM386.EXE can create and make available different types of memory as your
system requirements change (expanded and/or extended).
Example of EMM386.EXE line in CONFIG.SYS that enable the dynamic use of
expanded and/or extended memory:
DEVICE=C:\path\EMM386.EXE RAM AUTO


Ability to Provide Upper Memory Regions for Windows

EMM386.EXE version 4.45 includes a new WIN= switch that defines upper memory
regions available for use by Windows. These regions are similar to X=
regions; memory is not mapped to those areas. But unlike X= regions, Windows
(in 386 enhanced mode) can map its own memory into these upper memory regions
and make more conventional memory available to MS-DOS-based applications
running with Windows.


Ability to Load with No Page Frame

Previous versions of EMM386.EXE do not load if expanded memory support is
enabled and there is not enough contiguous available address space for an
expanded memeory page frame. To support MEMMAKER.EXE, EMM386.EXE 4.45
displays a warning message and continues to load when this situation occurs.


NOVCPI Switch for Smaller Load Size

Previous versions of EMM386.EXE disable both expanded memory and virtual
control program interface (VCPI) support when the NOEMS switch is used.
EMM386.EXE 4.45 leaves VCPI support enabled by default when the NOEMS option
is used, relying on the expanded and extended memory sharing enhancement to
supply VCPI memory. VCPI support can be disabled with the new NOVCPI switch.
Using NOEMS and NOVCPI together results in a reduction in the amount of
extended memory used by EMM386.EXE.


Token Ring Adapter Detection

EMM386.EXE automatically detects the memory location of IBM Token Ring
adapter cards and prevents the mapping of expanded or upper memory over the
adapter. The new Token Ring adapter detection can be disabled by using the
new NOTR switch.


Quiet Loading

By default, EMM386.EXE versionS 4.45/4.95 displays messages only if it
encounters an error condition. Adding the /VERBOSE (or /V) switch to the
EMM386 line in CONFIG.SYS forces EMM386.EXE to display status and error
messages while loading. To display status messages without adding the /V
switch, press and hold down ALT while EMM386.EXE starts and loads.


Ability to Provide ROM Shadowing

EMM386.EXE versionS 4.45/4.95 include a new ROM= switch that defines
regions of read-only memory (ROM) for EMM386.EXE to "shadow." EMM386.EXE
copies the contents of the ROM to extended memory (RAM) and maps the ROM
addresses to this memory. Specifying this switch can speed up your system
if it does not already use shadow RAM (most newer 80486 and all Pentium
systems use ROM shadowing).


IV. Troubleshooting MS-DOS 6.xx and EMM386.EXE Versions 4.45 and 4.95

If you encounter unexpected behavior (for example, system hangs or program
hangs) when using EMM386.EXE version 4.45 (which ships with MS-DOS 6.22),
use these steps to correct the problems:
1. Turn your machine off, then turn it back on (cold boot) to fully
   reinitialize the system.
2. Start MS-DOS 6.xx interactively by pressing the F8 key as soon as
   the text "Starting MS-DOS..." appears.
3. When prompted to load EMM386.EXE, choose N for No. If the problem
   persists without loading EMM386.EXE, something other than EMM386.EXE
   is causing the problem.
4. If the problem disappears when EMM386.EXE is not loaded, edit CONFIG.SYS
   as follows using an ASCII text editor (such as MS-DOS Editor):
device=c:\dos\emm386.exe x=a000-f7ff nohi noems novcpi nomovexbda notr
   NOTE: If the problem is specific to the use of the CTRL+ALT+DEL key
   combination (warm boot) and EMM386.EXE, add the ALTBOOT parameter to
   the above line.
5. Cold boot the machine after making the above changes. If the problem
   persists, the system may have faulty RAM chips or may require a special
   machine switch for HIMEM.SYS. In addition, any CMOS settings (such as
   shadow RAM) may need to be disabled, or the system ROM BIOS may need to be
   upgraded for compatibility with MS-DOS 6.0. Consult the system vendor for
   information on CMOS settings and/or the availability of BIOS upgrades.
6. If the problem disappears after loading EMM386.EXE as specified above,
   EMM386.EXE itself is not the source of the problem. Instead, the problem
   may be related to some service(s) that EMM386.EXE provides.
If the above procedure does not correct the problem, remove each command-line
option for EMM386.EXE one by one and cold boot the machine.
If the problem reappears, use the information below to find a resolution.

NOTE: most of these troubleshooting tips are also valid for EMM386.EXE
      version 4.95, which ships with MS-DOS 7.00 (Windows 95 version).


X=A000-F7FF

If excluding the entire upper memory area (UMA) resolves a system problem,
EMM386.EXE may be scanning too aggressively and setting up upper memory
blocks (UMBs) on top of some adapter ROM or RAM. Use any available hardware
documentation (including documentation on the add-on hardware devices such
as video, network, and disk controller cards) to identify any ROM or RAM
present in the UMA for that device, and exclude all pertinent regions.
The Microsoft Diagnostic utility (MSD.EXE) may also be useful in identifying
various mapped memory regions. Run:
MSD
from a DOS prompt.


NOHI

EMM386.EXE has the ability to load a portion of itself into UMBs. If the NOHI
option corrects the problem with EMM386.EXE, EMM386.EXE may be loading into
an occupied UMB. (Excluding the appropriate ranges in the UMA may correct
this problem; see the "X=A000-F7FF" section above.) If all such regions are
excluded, EMM386.EXE cannot be loaded high on the system, and NOHI must be
used. Contact the system manufacturer/vendor for additional information on
compatibility with EMM386.EXE.


NOEMS

If the NOEMS parameter corrects the problem with EMM386.EXE, EMM386.EXE may
be inadvertently conflicting with some hardware ROM or RAM address in the UMA
when attempting to establish an expanded memory (EMS) page frame. If EMS is
required to run MS-DOS-based applications, use the parameter FRAME= or M<x>
(where <x> is the defined hexadecimal address) to explicitly specify
placement of the EMS page frame in a nonconflicting region. If no
applications require EMS, simply continue to use the NOEMS parameter.


NOVCPI

The NOVCPI switch disables Virtual Control Program Interface (VCPI) support
and can be used only in conjunction with the NOEMS parameter. If using NOVCPI
corrects the problem, the application may not be fully compatible with the
EMM386.EXE VCPI allocation scheme. Either continue using NOVCPI, or do not
load EMM386.EXE when using the application.


NOMOVEXBDA

Some machines use the last kilobyte of conventional memory for an extended
BIOS Data Area. By default, EMM386.EXE remaps this memory area into the UMA
instead of conventional memory. If this causes unexpected system behavior,
the NOMOVEXBDA parameter MUST be used.


NOTR

EMM386.EXE's detection code searches for the presence of a Token Ring network
adapter. This detection code may cause some computers to hang. The NOTR
switch can be used to disable this search.

NOTE: For more information on EMM386.EXE command-line parameters and
      syntax, refer to the MS-DOS 6.xx Help File by running:
      HELP EMM386.EXE
      from a MS-DOS prompt.

NOTE: For Windows 95 users: read the MSDOSDRV.TXT text file (the EMM386.EXE
      topic), installed in your Windows folder by Win95's setup.
      Open MSDOSDRV.TXT with Notepad in Windows.



V. MS-DOS BUFFERS

A BUFFER is a portion of memory that DOS sets aside for buffering disk I/O.
DOS stores directories and partial blocks here. DOS must read a full sector
of information from the disk. If the application asks for an amount of
information that is not an exact multiple of the sector size then the whole
sector must be stored somewhere while DOS gives the partial amount asked for
to the application that asked for it. DOS uses BUFFERS to store directories
because it needs somewhere to store information for its own use.
DOS keeps one BUFFER in the kernel to make sure that it has at least one at
all times. The rest are loaded as "Added Data".
In MS-DOS 4.xx and up the size of each BUFFER is fixed at 528 bytes.
You only need one BUFFER. Any program that claims it needs more is really
only making a recommendation. Of course, your system will probably run slower
if you have only one BUFFER, but no more than one is actually needed to
operate. Consult your MS-DOS manual for suggestions about how many BUFFERS
you should have.
Disk caches may perform some of the same services that DOS BUFFERS perform.
If you use a disk cache consult the disk cache documentation when deciding
how many BUFFERS to allocate.
BUFFERS is actually an area of RAM which is available for buffering disk I/O;
they are not used by the count. If you want 20 BUFFERS, what you really mean
is that you want 10KB of disk buffering.
The BUFFERS= line can only be specified in your CONFIG.SYS.
If you are using MS SmartDrive 4.xx or better to cache your disk/s
reads/writes (or if you are using Windows 32bit Fast Disk Access), you ONLY
need 10 BUFFERS, specified by this CONFIG.SYS line:
BUFFERS=10



VI. EMM386 error messages

If EMM386 displays a message such as "EMM386 has detected error #12 in an
application," this indicates that the processor has reported an exception
error to EMM386. An exception error typically occurs when an application
gives the processor an instruction under invalid or unexpected conditions.
In most cases, these errors are related to a specific program. If you are
receiving an error that does not occur with any particular application, the
error might be caused by a device driver or a TSR. To avoid errors:

* Identify the program involved. See if the error occurs when the program is
not running. If you suspect a memory-resident program or device driver, try
bypassing it when your computer starts.

* Disable EMM386. If a particular application is to blame, disabling EMM386
might allow that application to generate an error message. Disabling EMM386
might also change your memory configuration so the error no longer occurs.

* Change the order in which you load device drivers and/or TSR-s in your
CONFIG.SYS and/or AUTOEXEC.BAT files. It might help because some errors
occur only under specific memory conditions.

* Error 12 message: a stack is being used incorrectly. Add this line to your
CONFIG.SYS:
STACKS=12,512
and reboot.

NOTE: DOS uses a maximum of 16 STACKS (and any number greater than 16 is a
      waste of memory). Maximum values allowed: STACKS=16,512.

Or modify the STACKS line to read:
STACKS=0,0
to revert to MS-DOS version 3.xx stack handling (if you believe you don't
have any MS-DOS programs that require stack handling). The STACKS=0,0 line
actually speeds up your system. If you find out that your Windows 3.1x/95
programs won't need stack handling, set STACKS to 0 in your CONFIG.SYS:
STACKS=0,0
to save memory space.

* Error 13 message: the program may be trying to use protected mode
without cooperating with EMM386. You may need to obtain a VCPI-compliant
version of the program from your vendor, or not load EMM386 when using that
particular application.

Code #   What it means
------------------------------------
0        Divide error
1        Debugger interrupt
2        Nonmaskable interrupt
3        Breakpoint
4        Overflow interrupt
5        Array boundary violation
6        Invalid opcode
7        Coprocessor not available
8        Double fault
9        Coprocessor segment overrun
10       Invalid task state segment
11       Segment not present
12       Stack exception
13       General protection violation
14       Page fault
16       Coprocessor error