For a partitioned drive, the master boot record is loaded first. It contains a small program to load and execute the partition that is marked as the active partition (C:, containing DOS).
The DOS loader in the boot sector (of either the diskette or active partiton) loads IO.SYS, which must be the first file in the root directory of the startup drive, and which must be stored in contiguous sectors. IO.SYS examines the system and installs the internal DOS device drivers, including drivers for all disk drives. In assigning drive letters from C: through Z:, the following rules are used:
All non-DOS partitions are completely ignored. This includes OS/2's hidden DOS partitions.
The first active primary partition on the first harddisk will always be called `C:'. DOS expects to be booted from this partition.
Each active primary DOS partition on each subsequent drive is assigned the next drive letter, even if it is not the first primary DOS partition. If a drive has no active (DOS) partition, its first primary DOS partition is assigned a drive letter. If no primary DOS partition exists on the drive, no drive letter is assigned in this stage.
All extended partitions on all subsequent drives are assigned drive letters in turn.
Lastly, all remaining primary partitions on all subsequent drives are assigned drive letters in turn.
MSDOS.SYS is loaded. It contains the majority of the MSDOS kernel. It must be the second file in the root directory and its sectors must be contigous.
Some interrupt handlers are set up.
INT 21h - DOS kernel
INT 28h - DOS idle poll
INT 29h - DOS fast screen output
Other interrupt numbers from 0Fh - 3Fh without any specific purpose is initialized to point to an IRET instruction. Certain DOS structures are set up, which may be altered or expanded.
DOS versions 6.x may load a special 'pre-loadable' device driver at this stage. The technology responsible for this has apparently been patented by Microsoft; thus no-one else may write a pre-loading driver without a license from Microsoft.
The CONFIG.SYS file is processed. The CONFIG.SYS file allows various operational settings to be made and further device drivers to load. In later versions of DOS it also allows memory resident programs to be loaded, however they are always loaded after all device drivers.
The command interpreter, COMMAND.COM is loaded. It sets up the standard devices for itself, and passes these on to any programs it spawns.
DOS PROGRAM STARTUP
Environment variable storage area is allocated. The environment variables are copied to it, each in the form of a stringz 'name=value'; the final variable is followed by a further nul byte, a WORD value (always 1; meant to signify the nuber of strings following) and the full path including drive and filename of the executed (this) program.
Program memory area is allocated
first 100h bytes becomes the 'Program Segment Prefix' (PSP). The command line arguments are stored in the PSP and the first two arguments are translated as if they were filenames into the two default file control blocks (FCBs) within the PSP.
the program itself is loaded directly after the PSP. The memory block in which the PSP is located is extended to accomodate the program (a second memory block is not allocated).
Various file handles are available (have been inherited from parent process) including:
Handle name
Handle value
STDIN (Standard Input)
0
STDOUT (Standard Output)
1
STDERR (Error output)
2
AUX (Auxillary, usually COM1)
3
PRN (Printer, usually LPT1)
4
The following interrupt vectors are set: Interrupt 22h (terminate address), Interrupt 23h (Ctrl-Break handler) and Interrupt 24h (Critical error handler) to default DOS handlers.
Data Transfer Area (DTA) is set to 80h in the PSP
Command line arguments are placed at address 80h exactly as they appeared on the command line. 80h itself is a byte giving the length of the command line. Pipes and redirections from the command line are not available; to determine if redirection is occuring, a program must determine what file/device is assosciated with the various standard handles.
DS and ES are set to the PSP segment address; for COM files CS and SS are also set to this address. EXE files have a header which specifies values for CS and SS.
SP is for COM files set to the top of the memory block allocated for the program, + 1 (usually this gives it a value of 0), and then the immediate value '0' (a WORD) is pushed onto the stack (placing it at the top of the memory block. This allows a RET instruction to terminate the program). For EXE files SP is set from the header.
code execution begins at CS:100h for COM files. For EXE files, starting address is set by the header. Registers usually contain 0, but it is safest not to assume any value.