16.2 Going Behind the Scenes

The startup of a protected-mode program is far more complex than a real-mode program. First, DOS reads in the real-mode stub and executes it. This real-mode stub checks to see if DPMI is available, and then uses it to switch to protected mode. After switching to protected mode, it then asks the operating system to allocate memory for the program's code and data segments, loads the protected mode image from disk, and then directs processor execution into the DJGPP library startup code. This startup code does some dirty work such as reading the command line and initializing the standard library, and then (finally) runs _main.