China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 13:42
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Detailed Explanation of Memory Terms DigestII View 12,170 Replies 10
Original Poster Posted 2004-02-27 00:00 ·  中国 广东 广州 海珠区 电信
初级用户
Credits 152
Posts 10
Joined 2004-02-24 00:00
22-year member
UID 18295
Gender Male
Status Offline
Detailed Explanation of Memory Terms

You may have heard or read terms such as Epanded memory (expanded memory), EMS, Extended memory, XMS, EMM, UMB, HMA, VCPI, and DPMI. To explain how programs are allocated to access memory beyond 1MB, this article will define these terms, so that when these concepts are connected with later articles you will already be familiar with them. As we know today, the architecture of the PC is based on a fully usable 1024K (1MB) memory space. As far as DOS is concerned, 1MB is all the memory available, but for real-world use, 1MB of memory proved to be too little; users wanted larger documents and larger spreadsheets and databases, while programmers writing more powerful programs required larger executable files (the files that run programs).
In response to the popularity of the PC and the constantly changing needs of users, programmers and hardware engineers worked hard to explore ways to provide more memory and ways to use that memory. Actually providing more memory was not a big problem: just insert more chips or memory cards. Making the extra memory usable was the real challenge. Clearly, more memory space was needed, so the computer industry developed many standards for using memory beyond 1MB.

Expanded Memory

The first of these standards was Expanded Memory. Expanded memory refers to extra memory above 1MB that can be accessed by programs (and in some cases by hardware) using the expanded memory specification (explained later in this article). It is not correct to call expanded memory memory beyond a fixed boundary (such as 640K or 1024K), because expanded memory has no real location until it is mapped. This is why we say expanded memory is “somewhere else.” Expanded memory can be used on any model of IBM PC-compatible computer: 8088, 8086, 80286, i386, i486, and later machines. It was invented for any PC in use in 1985 and later computers. Although 286 and later processors have protected mode and can use extended memory (discussed later in this chapter), the first standard invented for using more than 1MB of memory was designed to be used on any processor starting with the 8088, so as to serve the largest possible programs and users later on. On 386 and later computers, the memory-management program required for using extra memory has been built into the processor chip (CPU). On 286 and lower computers, special expanded-memory hardware (usually a memory expansion board) is required to provide expanded memory.

Expanded Memory Specification (EMS)

To use expanded memory, programs must follow the Expanded Memory Specification (EMS)--the rules specifying how to access expanded memory. In 1985 Lotus developed EMS so that programs could access more memory. Intel joined in by manufacturing expanded memory boards. Soon after EMS was released, Microsoft requested some changes to the specification and asked to join the alliance. Thus we had LIM/EMS--Lotus, Intel, Microsoft / Expanded Memory Specification. However, all expanded memory issues are more suitably called EMS.

How EMS Works

EMS works in an indirect way. EMS makes DOS think that data located somewhere in memory is actually stored in the lower 640K.
EMS redirects one block of memory addresses to another block of memory addresses. These blocks can be as high as 1MB--thereby providing a way for the program itself to run in expanded memory. This means programs can be larger. And larger programs can do more work faster.
Why must EMS redirect memory? Because DOS can only see applications and their data below 640K. DOS cannot see any memory beyond 1024K. Expanded-memory hardware can show a piece of memory located somewhere else as if it were at an address below 1024K, no matter where it is actually located. This process of representing one memory block by the address of another memory block is called mapping. Through a combination of hardware and software, the expanded memory piece masquerades as conventional memory. DOS is not smart, so programs can use much more memory than before by accessing memory fragments called pages.

To put expanded memory to use, three things must work together.

1. Write the program according to EMS; such a program usually runs much faster and can access more data than a program that can only run in conventional memory.

2. Install memory-management hardware in the computer. No matter what type of computer you have, you need to install actual memory (chips or cards) above 1MB. On a 286 or lower computer, the correct type of memory-management hardware is an expanded memory card (not an extended memory card--extended memory and expanded memory are different). On a 366 or better computer, the correct type of memory hardware is the processor chip itself (this hardware is already included in the processor chip).

3. An EMM (expanded memory manager): an EMM is a program that controls the extra memory supported by the Expanded Memory Specification. The EMM is the traffic cop that interprets all memory calls and directs them to ensure that all programs, devices, and other memory references in the computer get what they want when they need it, without conflicts.
Examples of EMMs are EMM386 (which comes with D0S5 and D0S6), QEMM, and 386MAX.

Extended Memory

Extended memory is memory above 1MB on 286 or higher computers. Accessing extended memory is simpler than accessing expanded memory, because the processor chips on 286 and higher computers were designed to “know” about the installed extra memory. Extended memory cannot be used on computers below the 286, because their processors were not designed for it. Unfortunately, DOS does not know how to perform the simple function of accessing extended memory. Unlike expanded memory (which can be used in real mode), extended memory can only be used in protected mode. Programs using extended memory under DOS need to put the processor into a special mode to use extended memory, and return to another mode to talk to DOS.

Real Mode and Protected Mode

A PC can have several operating modes. An 8086 has one operating mode: real mode. A 286 has two modes: real mode and protected mode. An i386 has four modes: real mode, protected mode, virtual 8086 mode, and flat 32-bit mode. Each mode allows different access to memory and other functions. Each mode can access a completely different processor model. It depends on the better memory management and newer programs provided by the processor. To run both old and new existing programs, various processor models are available in the chip. Your software puts the computer into the necessary mode to provide the kind of memory the software wants. A DOS extender is usually used to do this.

A DOS extender is a special program set inside a DOS extended program. When the program wants to use D0S, for example to write a file, it makes a “DOS call.” The DOS extender monitors these DOS calls and makes sure that when a DOS call occurs, the program switches the processor back to real mode. The DOS extender lets D0S do its work, then switches the processor back to protected mode so that the program can continue working.

Real Mode
Among the three operating modes of 286, 386, i486, or Pentium computers, this is the most compatible. In real mode, a 386 processor behaves as if it has reverted to an 8086 processor. Real mode is the mode in which any D0S program can run on any 80x86 computer. A DOS extended program must switch from protected mode to real mode to access any DOS service (such as saving a file). In real mode, programs cannot access any advanced functions of a 386 computer, such as advanced memory management and protection.

Protected Mode
Protected mode is the mode in which DOS extended programs can run and store their data in extended memory. A DOS extended program is a program that can not only store data in extended memory, but also run its own code in extended memory. To do this, the DOS extended program must be in protected mode. In protected mode, programs can access the paged memory-management unit on the 386 processor chip and use the processor’s 32-bit registers and addressing modes. Protected mode and the DOS extended programs that use it dramatically increased the use of memory on the PC, making it possible to have larger and faster programs that can use more data than ever before.


Extended Memory Specification: XMS

A new specification called the Extended Memory Specification (xMs) was developed to manage the use of extended memory. XMS provides access to as much as 4 gigabytes of memory above 640K. To do this, the computer needs an XMS driver, either a strict XMS driver such as Microsoft’s HIMEM.SYS, or an XMS manager included together with other memory-management functions (EMM, high RAM access, and so on), such as Quanerdeck’s QEMM, QEMM.386, and other third-party memory managers, which convert extended memory into expanded memory for programs that still want to use expanded memory. Therefore, whether your software uses EMS or XMS, memory allocation is transparent; this means there is no need to tell the memory hardware that some memory is assigned as EMS while another part is assigned as XMS.
There are several ways a program can access extended memory. Memory addresses can be allocated by reading and writing from the top of memory or from the bottom of memory. One of the first programs to use extended memory was VDISK. It uses the bottom-to-top allocation method. Other programs also use this method to access extended memory; QEXT is one such program. A program may optionally use an XMS driver for memory allocation, and then get its memory through that XMS driver. This is the most common and most desirable way to make use of extended memory, because if programs use the industry-standard means of using memory, they can coexist with other programs using the same standard. Using an XMS driver, the memory manager (as opposed to the program) obtains the memory directly, and gives a small amount of memory to the program that calls the XMS driver,
XMS requires DOS 3.0 or later.

A20 Gate

During booting, the computer may display a message such as “A20 line enabled.” XMS uses the A20 line to use memory above 1024K. The A20 line is a combination of hardware on the motherboard and the capabilities of the processor chip. The A20 line is the 21st address line of the 80x86CPU, and it allows access to memory above 1024K. If the A20 line is gated on, the processor can see memory above 1MB. If the A20 line is not allowed, then any reference to a memory address above 1MB folds straight back down to the beginning of memory. This mechanism is called A20 “gating,” because it determines whether address lines 20, 21, 22, and 23 (up to 31 on 386PC machines) are allowed to become visible (gated). Using the A20 line, XMS can also make use in real mode of a newly created 64K of conventional memory more than it otherwise could.


High Memory Area (HMA)

The High Memory Area (HMA) is the first 64K of extended memory. Almost 64K. Memory terminology is full of exceptions. The HMA is actually 64K minus l6 bytes, because the HMA begins at the top 16 bytes of the upper memory area (UMBs). The HMA is unique, because code in it can be executed in real mode. This is because it can be grabbed by the 16-byte address space that exists below lMB. The reason we quibble over these l6 bytes is that only programs specially written to run in this HMA can make use of this flash of memory, although most programs have not undergone major modification. Examples of programs that can use the HMA are DOS 5 and DOS 6 using DOS=HIGH, DESQview, DR DOS, and Novell’s XMSNET. The HMA is one of the small dark corners of DOS memory areas that can be used to increase the amount of memory available below 640K.

Upper Memory Blocks (UMBs) and Extended Memory Blocks (EMBs)

All the memory specifications discussed in this article focus on gaining access to more memory. Although the vast region above 1MB has been opened up for use, memory below 640K is the most useful, because DOS can understand everything that goes on there and work with it. DOS device drivers require very little memory below 640K, but programs using EMS and standard (non-extended) DOS programs run specifically below 640K. To obtain more memory resources in this area, XMS provides a way to use memory between 640K and 1024K instead of memory below 640K. This is done by creating UMBs into which device drivers can be loaded.

UMBs

On 80x86-based computers, Upper Memory Blocks (UMBs) located between the 640K and 1MB address boundaries are memory blocks available to DOS. The number, size, and location of these blocks vary greatly depending on the types of hardware adapter cards installed in the machine.
UMBs can be used to store programs, code, and data that normally must reside below 640K. This is sometimes called “loading device drivers high.”

EMBs

Extended Memory Blocks (EMBs) are extended memory located above the HMA, and can only be used to store data or DOS extended programs.


Virtual Control Program Interface VCPI) and DOS Protected Mode Interface (DPMI)

Other extended memory formats make multitasking of DOS extended programs easy to implement. Multitasking DOS extended programs require the Virtual Control Program Interface (VCPI) or DOS Protected Mode Interface (DPMI), because both the multitasking environment and the DOS extended programs running under that multitasking environment use extended memory. VCPI and DPMI establish more standards for how each program can use extended memory without conflicting with other programs.

VCPI

VCPI is a protected-mode specification developed in 1987, and it is a superset of the EMS 4.0 specification. VCPI was created to avoid conflicts among programs that need extended memory by allowing them to share extended memory. Before XMS, there was no way for a program to ensure that any memory it accessed was not being used by another program.

In addition, VCPI manages memory allocation and switches between real mode and protected mode.

VCPI allows programs running in protected mode to coexist with 386 memory-management programs and programs running in other protected modes. VCPI does not work on 286 machines, because it is not supported by 286 hardware. VCPI calls (made by a program) are supported by a VCPI service program (server), which is usually included in the expanded memory manager. A service program is a program like a waiter in a restaurant. It accepts orders (in the form of memory calls) from customers (a program making a request for memory), and then gives a specific block of memory to that program. If a program makes a VCPI call but does not find a VCPI service program running, the program directly takes over the computer hardware and manages its own memory. The program can directly get the memory it wants, but without a memory manager to schedule it to prevent conflicts, no other program can use that extended memory.

DPMI is a more recent (1990) protected-mode interface. The main difference between VCPI and DPMI is that DPMI does its work without allowing applications to access the lowest level of the CPU. VCPI, however, allows any program to access the lowest level of the CPU, which means no other program (including the operating system) can conflict with VCPI. This is a drawback, because operating system designers do not want programs to interfere with each other. They want only the operating system to be able to see other programs.

DPMI can also manage more than one entity that requires protected mode, for example several protected-mode programs being multitasked. In addition, DPMI includes a newer programming interface for DOS and BI0S calls that can be made by protected-mode programs. Unlike VCPI, DPMI can be implemented on 286 machines, and can cross multiple operating systems, such as OS/2 and UNIX as well as DOS.
For backward compatibility, a program requesting DPMI services, if it does not find a DPMI service program when making these calls, can resort to a VCPI service program (if VCPI is available).

Note: the exception to this definition is the expanded memory card. Expanded memory cards are now all obsolete.

In today’s assembly textbooks, after finishing real-mode assembly they begin explaining protected-mode assembly. And protected-mode assembly starts by explaining many concepts such as the flat memory model, segmented memory management, and paged memory management. This makes it difficult for many people to understand. The problem lies in cutting off the inevitable connection between real mode and protected mode. Through this article’s explanation, you can clearly see the main line of development:

Real mode (small-memory use, single-tasking)---->customer demand, hardware progress---->protected mode (large-memory use, multitasking)---->early stage (VCPI, no interprocess protection)---->development stage (DPMI, with protective measures)---->the relationships among today’s protected-mode methods.


Protected Mode Began with the 80286

For the 80286, Intel decided to multiply the maximum accessible memory by 16 and give the 286 a 24-bit address bus and a maximum of 16 megabytes of RAM. But calculating 24-bit addresses in a 16-bit CPU was not as easy as again multiplying the segment value by 16, and the designers wanted to add extra capabilities to the addressing functions. In fact, the CPU had to run in a completely different way called protected mode. Protected mode not only gives the processor the ability to protect memory contents when multiple programs are running, but also provides more memory addresses. It uses a more complicated method to calculate actual memory addresses.

The advantage of the CPU running in protected mode is that when several programs share memory together, each program can be guaranteed that its memory space will not be interfered with by any other program.

On the other hand, the 8088 and 8086 run in real mode, which has no memory protection. Any program can access any memory area between 0K and 1024K. Because the 8088 and 8086 each had only one megabyte of memory available, the chance of several programs being there at the same time seemed very remote (unlikely) to the designers of those CPu, so memory protection was not an important feature. To obtain a 24-bit address, it seemed natural to multiply the segment register directly by 256 instead of by 16. This would make the two registers overlap by only 8, thus forming 24 bits.
However, this is not the way the 80286 works. Protected mode needs more information than directly calculating the actual address. It also needs some protection information. The method actually used by protected mode is to let part of the segment register indicate a table in memory, which describes how the segment is established. This table, which has an entry for each segment of memory, is automatically referred to by the CPU. The table contains access permissions (read, write, or execute only), the size of the segment, information about whether the memory actually exists, and other matters. The result is still a 24-bit actual address, but the calculation is much more complicated.


80386--An Epoch-Making Processor

The 803386 has more functions and greater power. The chip has 32-bit registers, a 32-bit data bus, and a 32-bit address bus. What does this mean? It means the 386 can access an extraordinarily large 4G of RAM. That is four gigabytes of memory! But accessing more memory was only the beginning. Besides this flash-memory addressing capacity, there were all the additional operating modes. The 386 not only supports the 8026 real mode and the 80285 protected mode, but now also works in its own 32-bit protected mode (as distinct from the 286’s 16-bit protected mode) and virtual 8086 mode.

32-bit protected mode (also called the flat model (float model)) allows the CPU to use a 16-bit segment value and a 16-bit offset together as a complete 32-bit address.
In reality, this 32-bit flat model uses a descriptor table similar to the 80286 protected mode in order to provide similar protection functions. Even so, the fact that a 16-bit segment and 16-bit offset effectively describe the actual physical address makes programming in this mode much easier. This mode also allows the CPU to use space on the hard disk as memory when the computer does not have enough physical RAM. This “virtual memory” allows programs to concentrate on completing their tasks without caring about the amount of physical memory in the computer. Part of the information in the descriptor table tracks physical memory. When a memory reference is calculated, the descriptor is checked to look for the memory. If this is not the case, the disk is used to obtain the correct memory mapping and put it into actual memory, and then the program continues to run. When done correctly, virtual memory only appears to be slightly slower than actual memory, with the benefit of accessing data areas far larger than the actual physical memory in the computer, allowing larger and more powerful programs to run.

Another V86 Mode for DOS

Although some programs such as AutoCAD, Paradox, OS/2, and Microsoft WinDows (enhanced mode) made use of the 32-bit flat model to increase memory space and speed, DOS programs did not. Therefore the 386 has a compromise method called virtual 8086 mode. This mode can emulate an 8086 with one megabyte of memory for each program running in the computer. With virtual 8086 mode, many real-mode programs can execute in their normal way while actually using memory that would otherwise not be available to them. In other words, the 80386 can allocate 1M memory blocks anywhere in RAM, even if the memory is physically located in address regions beyond the first 1024K, and assign each memory block to a different DOS program. When a program requests memory at a specific address, the 386 memory management unit (MMU) checks the address assigned to that specific program and translates the requested address into the actual physical address without the program knowing, just as if a group of 8086 computers all had memory at the same time. Microsoft wmdows uses this function to allow DOS programs to multitask without those programs knowing it.

Summary:
In the time of early processors (8088, 8086), because of the limitations of hardware conditions, software and hardware engineers devoted themselves to how to increase the usable memory space of programs (and thus the concept of expanded memory appeared). By the 286 era, INTEL’s hardware engineers developed the 286, a freak with 16-bit registers but 24 address lines; it could address 16 megabytes of memory (at the time, this was a huge number). This made multitasking in parallel possible. The problem it brought was the coordination among multiple tasks. Therefore it was designed with the ability to have a protected execution mode. Because of the irrationality of its design, it became a flash-in-the-pan product.
The appearance of the 386 was epoch-making. It corrected many of the 286’s design defects and became INTEL’s first 32-bit processor. The later 486, pentium, and pentiumII kept this design architecture and successively added technologies such as superpipelining, frequency multiplication, and superscalar execution. But their memory working modes are no different from the 386’s.
Floor 2 Posted 2004-02-28 00:00 ·  中国 辽宁 抚顺 联通
银牌会员
★★★
论坛候鸟
Credits 1,131
Posts 332
Joined 2003-11-27 00:00
22-year member
UID 13461
Gender Male
Status Offline
Thanks! Continue!!!!
Floor 3 Posted 2004-02-28 00:00 ·  中国 湖南 株洲 电信
初级用户
Credits 141
Posts 8
Joined 2004-02-26 00:00
22-year member
UID 18510
Gender Male
Status Offline
Pretty good, not bad!! Continue!
Floor 4 Posted 2004-03-06 00:00 ·  马来西亚
初级用户
Credits 105
Posts 1
Joined 2004-03-06 00:00
22-year member
UID 19390
Gender Female
Status Offline
Why not continue?? Thanks
Floor 5 Posted 2004-03-19 00:00 ·  中国 贵州 贵阳 电信
初级用户
Credits 110
Posts 2
Joined 2004-03-18 00:00
22-year member
UID 20425
Gender Male
Status Offline
Good stuff, continue
Floor 6 Posted 2009-10-13 07:54 ·  中国 湖北 天门 电信
中级用户
★★
Credits 208
Posts 135
Joined 2009-09-12 12:00
16-year member
UID 151902
From 离恨天
Status Offline
Worth collecting. Hope the OP posts more good threads.
Salute to the OP.
Floor 7 Posted 2009-10-18 05:01 ·  中国 广东 深圳 电信
初级用户
Credits 40
Posts 23
Joined 2009-10-15 21:49
16-year member
UID 153140
Gender Male
Status Offline
Thanks for sharing, collected it~~
Floor 8 Posted 2009-10-18 15:16 ·  中国 四川 成都 温江区 电信
中级用户
★★
Credits 274
Posts 192
Joined 2009-01-07 21:09
17-year member
UID 136069
Gender Male
Status Offline
Good materials, collected it first
Floor 9 Posted 2010-01-01 20:54 ·  中国 陕西 西安 电信
新手上路
Credits 18
Posts 9
Joined 2009-12-27 23:51
16-year member
UID 157451
Gender Male
Status Offline
I kind of can’t understand it
Floor 10 Posted 2010-01-28 15:03 ·  中国 浙江 台州 电信
初级用户
Credits 37
Posts 14
Joined 2008-12-10 11:41
17-year member
UID 133406
Gender Male
Status Offline
A very good article, thanks to lz for organizing it
Floor 11 Posted 2010-01-28 15:23 ·  中国 浙江 杭州 电信
初级用户
Credits 76
Posts 23
Joined 2010-01-26 14:45
16-year member
UID 159517
Gender Male
Status Offline
Can’t understand it
Forum Jump: