### TechNote

Number: 04503-04
Date: April 1994

## Understanding DOS extenders

### 1 Introduction

Conventional memory is the basic type of memory found in all computers running DOS. Most computers can accomodate up to 640Kbytes of conventional memory. DOS and all programs that are written for DOS run in this area. ROM BIOS runs above this, in the upper memory area. ROM BIOS is a set of services that provides an interface to a computer's hardware such as the video display and the keyboard.

The more memory you have, the more data you can store in memory at one time. One way to add more memory to your system is to install extended memory. You can install extended memory on systems with 80286, or higher, processors. However, DOS can only gain access to extended memory with great difficulty, because DOS runs in real mode. Real-mode programs cannot "see" extended memory, because they cannot generate the appropriate addresses to access it.

Two common ways of accessing extended memory on a DOS computer are:

- Using XMS (eXtended Memory Specification) to access extended memory from a DOS program that runs in conventional memory.

- Using a DOS extender. This runs your DOS program in protected mode (rather than in real mode), while using all the available extended memory. A protected-mode DOS program is called a "DOS extended" application.

The main advantage of using a DOS extender rather than XMS is that a DOS extender enables DOS applications to access more memory directly, whereas XMS provides more memory to DOS applications indirectly. That is, with XMS, before a DOS application can use the extra memory, it must copy ("map") an XMS "block" of memory to conventional memory. The DOS application must map in each memory block as it needs it, and map out each block when it has finished with it. However, in protected-mode DOS, any difference between conventional and extended memory is managed by the DOS extender, which provides the DOS application with a single "pool" of memory. There is no limit on data size or code size: protected mode is not limited to addressing only 1Mbyte of memory at a time and the DOS extender can allocate multiple megabytes of extended memory to the DOS application. Therefore, large applications benefit most from using a DOS extender. There are two types of DOS extender:

- The 286 DOS Extender, which runs on 80286, or higher, processors, and uses 16-bit protected mode. Examples are Phar Lap Software's 286|DOS Extender, Rational System's DOS/16M, and Ergo Computing's OS/286 and EDU-16.
- The 386 DOS Extender, which runs on 80386, or higher, processors, and uses 32-bit protected mode. Examples are Phar Lap Software's 386|DOS Extender, Ergo Computing's OS/386 and EDU-32, Rational System's DOS/4G, and IGC's (Intelligent Graphics Corporation's) X-AM.

Both of the above work in much the same way.

### What are real mode and protected mode?

The microprocessor in every personal computer has a "real mode", which allows the microprocessor to address up to 1Mbyte of memory. Real mode is so named because it is the original mode that the 8088 microprocessor in the first personal computers used. Real mode is the default mode.

In 80286 or higher computers, the microprocessor also has a "protected mode", which allows the microprocessor to address more than 1Mbyte of memory. Protected mode is so named because, in a multitasking environment, the microprocessor manages the memory so that each program is protected from interference from other programs running at the same time. The combination of the operating system and application that the computer uses determines whether the microprocessor stays in real mode or whether it switches to protected mode.

### 2 How DOS extenders work

DOS applications running in protected mode cannot access directly the services of MS-DOS and ROM BIOS, which are only available in real mode. It is the DOS extender that provides DOS applications with indirect access to these services. A DOS extender is an interface between a DOS application running in protected mode and MS-DOS or ROM BIOS. The DOS extender uses interrupt (INT) calls to access the DOS and BIOS services, just like real- mode DOS, and makes access to the services as transparent as possible for the DOS application.

A DOS extender:

1. Sets up the protected-mode environment by running, in real mode, an initialization code that:

   - Determines:
     - the computer type: an 80286, 80386, or 80486 computer.
     - the presence of extended memorymanagers, such as XMS

     .
   - Allocates memory in the lower 640Kbytes for the system data structures that the DOS extender will use, such as page tables, and builds these structures.

2. Switches to protected mode.

3. Allocates extended memory for the DOS application. If necessary, all the available extended memory can be used.

4. Loads the application in protected mode.

5. Intercepts an interrupt whenever the application generates an interrupt to access a service from MS-DOS or ROM BIOS, and buffers the data into a data structure in conventional DOS memory, that is, below 640Kbytes. The interrupts are usually software interrupts such as DOS calls, which use INT 21h, or ROM BIOS calls such as INT 16h. INT 16h is the interrupt that is generated when a keyboard key is pressed.

6. Switches to real mode.

7. Reissues the interrupt, so that the appropriate DOS or BIOS interrupt handler can service it. However, a small subset of DOS services are completely serviced by the protected-mode part of the DOS extender and are not reissued to real-mode DOS, for example, allocating extended memory for the application, interrupt handling, and starting another protected-mode program.

   Translates any value that is returned from the interrupt request, into protected-mode terms.

8. Switches back to protected mode.

9. Continues to run the application.

This process is known as "reflecting" the interrupt and occurs without the application's knowledge: the application runs as if under a protected-mode version of DOS or ROM BIOS. The DOS extender's handler transparently takes care of all the details of transferring data between conventional memory (where real-mode DOS or BIOS can get at the data) and extended memory (where the protected-mode application allocated the data). The performance penalty for all this is hardly noticeable, except for applications that make enormous numbers of interrupt requests.

### 3 VCPI

Because DOS extenders handle some DOS services themselves, for example, extended- memory allocation, they need to assume complete control of the computer in protected mode. EMS (Expanded Memory Specification) emulators that run on 80386 or 80486 computers, such as Microsoft's EMM386, Qualitas' 386-to-the-Max, and Quarterdeck's QEMM-386, also assume complete control of the computer in protected mode to provide the EMS interface. Therefore, if both an EMS emulator and a DOS extender are installed in a computer, they compete both for control of the computer in protected mode and for extended memory.

#### What is an EMS emulator?

An EMS emulator is a program that provides expanded-memory services without an expanded-memory board installed in the computer. Expanded memory is another way of increasing the memory available on a computer. It is essentially extended memory that is subdivided into smaller chunks called "pages" that can be independently mapped into or out of conventional memory on demand. EMS emulators are also known as memory managers, although strictly speaking, a memory manager is a type of EMS emulator that runs on 80386 and 80486 computers only. The disadvantage of using an EMS emulator is that, unlike when using a DOS extender, DOS applications can only access the extra memory indirectly, because a logical page of memory must first be mapped to a physical page of memory.

To allow DOS extenders and EMS emulators to coexist, Phar Lap Software and Quarterdeck Office Systems developed the VCPI (Virtual Control Program Interface). VCPI is an extension to EMS 4.0. It consists of a set of services that the EMS emulator provides and the DOS extender uses. The EMS emulator is known as the VCPI server, and the DOS extender is known as the VCPI client. They each administer separate, protected-mode program environments.

The main services that the VCPI server provides are:

- Mode switching: allows the DOS extender to switch between real mode and protected mode.

- Memory management: allows the DOS extender to access the memory "pool" that the EMS emulator manages.

VCPI works as follows:

1. At startup, a DOS extender (client) finds out if VCPI is available by checking for the presence of an EMS emulator (server).

2. The client requests the server to:
   1. Switch the client to protected mode.
   2. Set up the conditions that allow the server to switch between its own environment and that of the client, and for the client to request services of the server from protected mode.

3. To obtain memory from the server, the client makes VCPI calls to the server to allocate memory. Under VCPI, memory is allocated in 4Kbyte pages, and the client does not have to switch back to real mode to use the memory that it requested.

4. To return to real mode, the client requests the server to do so on its behalf. The client has to switch to real mode and back again every time an interrupt occurs. The mode- switch calls that the client makes to the server do more than just switch processor modes; they also switch between the server's and the client's environments, which is what really makes VCPI work, because both server and client behave as if they both have complete control of the computer.

Most DOS extenders and popular EMS emulators now support VCPI. Users can install EMS emulators on their 80386 and 80486 computers and run DOS extenders without being aware of any potential resource-contention problems or the existence of VCPI. Although VCPI only solves one specific compatibility problem, it is a valuable technology because of the large and increasing popularity of both EMS emulators and DOS extenders.

### 4 DPMI

Although VCPI works extremely well for the problem it was designed to solve, that is, enabling a DOS extender to run alongside an EMS emulator in the same computer, it does not support hardware virtualization. Hardware virtualization is an important feature, because it enables applications that are running simultaneously in a computer to believe that they each have direct control of the hardware without interfering with each other. This facilitates the multitasking of DOS extended applications, that is, they can run simultaneously. Therefore, VCPI is not adequate for multitasking, because it cannot shield one application from interference by another. Different applications try to access the same hardware devices directly, particularly the video display, which is the most commonly used hardware resource. Microsoft Windows is the most popular user interface that runs on top of DOS. To support hardware virtualization, Microsoft developed a new interface called DPMI (DOS Protected- Mode Interface), and included it in Windows 3.0. DPMI allows DOS extenders to run in the Windows protected mode environment.

DPMI works in the same way as VCPI. Windows 3.0 acts as the DPMI "host", which is similar to a VCPI server in that it provides mode switching and extended memory management to client programs. However, whereas with VCPI, the server and its clients have a peer relationship, that is, they both run at the highest privilege level, with DPMI, the host runs at a higher privilege level than its clients. Privilege levels are a way of prioritizing programs at the processor level. There are four privilege levels that are numbered from zero (most privileged) to three (least privileged). The more privileged a program is, the more activities it can perform.

Because the DPMI host and clients do not have a peer relationship, the DPMI host can support demand-paged virtual memory and maintain full control over clients' access to the hardware. Windows remains in control of the computer in protected mode, but allows each application to think that it has direct control of the hardware, thereby preventing simultaneously running applications from interfering with each other and crashing the computer.