Understanding PC Memory by Paul Williamson (c) 1994 Backyard Software Systems, Inc. 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. Between the top of conventional memory at 640K and the start of extended memory at 1024K lies the 384K Upper Memory Area (UMA). This area does not contain physical memory. Mapped into the 384K UMA are the system BIOS (basic input/output system) ROM chips (in the F000 to FFFF address space) and the Display Adapter memory (in the A000 to B7FF address space). 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 addresses conventional memory in the first 640K, and the UMA in the next 384K, the area from 640K to 1 MB (1024K). This does not mean that the machine has 1 MB of physical 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, and the 384K of extended memory starting at 1024K. EXTENDED MEMORY Extended memory is the simplest type of add-on memory to under-stand. It is also the type of memory used by Windows 3.x running in either standard or 386 enhanced operating mode. Extended memory is a seamless continuation of the original 1 MB address space on 80286 and 80386 (and higher) 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.1 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, and 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. Due to the way DOS addresses memory, the actual amount of memory that can be physically addressed is 64K more than 1M. This means that the first 64K of extended memory can be directly accessed by DOS. With version 5.0 of MS-DOS, this area was designated the High Memory Area (HMA) and is normally reserved for DOS use. Windows 3.x and all applications running under Windows 3.x 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, ones 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 It is important to understand the concept of expanded memory if you still run DOS applications that use it. There are two 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 and 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, called the Page Frame. 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 four 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 and 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. 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. Although LIM 4.0 is a standard that offers many advantages over LIM 3.2, few applications have yet been written to take advantage of LIM 4.0. 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, and 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. If you're using an expanded memory board on an 80386 machine, read your manual carefully before you backfill. Not all memory boards have the register support to supply more than four 16K pages (LIM 3.2). Though a memory driver may conform to the LIM 4.0 specification, that does not mean the hardware can provide more than four pages. Also, because Windows 3.1 supports extended memory directly, backfilling expanded memory will not give you any advantages, and the memory on the motherboard is often faster than memory on an expanded memory board. LIMulators Some programs, known as LIMulators, emulate expanded memory on 8088- and 80286-based machines using hard disk space and/or extended memory. These programs are not much of an advantage, because although they supply expanded memory, they are not hardware. They must locate a 64K EMS page frame in conventional memory and also take up space for the driver itself. LIMulators generally take close to 80K of conventional memory to run. Because conventional memory is the most precious memory on your machine, these types of programs are not recommended. They are also typically extremely slow. On 80386 machines, it is possible to use a 386 Expanded Memory Manager (such as EMM386 or Quarterdeck's QEMM) to emulate expanded memory. These LIMulators use the XMS rather than interrupt 15 memory to emulate expanded memory and 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, such as network cards; 3270 emulation cards; RLL, SCSI, and ESDI disk controllers; and even high-resolution video cards, can contend for this address space. Several potential difficulties can arise due to this contention: 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. Complicating this process are boards such as the IBM 3270, which have nonmovable addresses in most machines. Mapping Conflicts. Most 386 EMMs (such as EMM386.EXE and Windows 3.1 386 enhanced mode) use a search algorithm to find unused memory addresses between C000 and 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 documentation for information 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. Paul Williamson is an on-site consultant for Chase Manhattan Bank. He is well known on the nets and has hosted many conferences. He is on the WindoWatch Editorial Board and can be reached at 72611,1543@compuserve.com ww