15.2 About DPMI

DPMI is the DOS Protected Mode Interface. The programs produced by DJGPP run in 32-bit protected mode. The transition from real-mode to protected-mode is provided by the DJGPP real-mode stub, which calls DPMI. DPMI is also used by DJGPP programs to allocate memory, set interrupt vectors, and perform protected-mode to real-mode (and vice-versa) interrupt call translations.

Why is DPMI necessary? Multitasking operating systems such as Windows 2000 run DOS programs within a "virtual 8086" environment, provided by 80386 and higher processors, that isolates the operating system from program errors. However, this processor mode also restricts access to certain features of the processor, such as the ability to switch between real and protected mode. DPMI is a standardized interface that provides interrupt-level functions for things such as switching between real and protected mode, allocating memory, and setting interrupt vectors.

If we were writing programs under a non-multitasking operating system such as DOS, our programs would have complete control of the machine, as we wouldn't be limited by the virtual 8086 mode. However, DPMI isn't available; we'd have to implement all of its functionality by manipulating control registers on the processor and building various data structures by hand. While this would be an interesting (yet difficult) exercise, fortunately Charles Sandmann has already done it for us by writing the CWSDPMI utility, a full DPMI provider that runs on DOS.

As we'll assume DPMI is the lowest level protected mode interface available for our programs' use, we will learn about protected mode by first using these functions directly. Later, we'll combine these low-level functions into higher-level, easier-to-use library functions.