Pages

Monday, December 1, 2008

DOS

DOS, short for "Disk Operating System",[1] is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.
Related systems include MS-DOS, PC-DOS, DR-DOS, FreeDOS, GLaDOS, PTS-DOS, ROM-DOS, JM-OS, and several others.
In spite of the common usage, none of these systems were simply named "DOS" (a name given only to an unrelated IBM mainframe operating system in the 1960s). A number of unrelated, non-x86 microcomputer disk operating systems had "DOS" in their name, and are often referred to simply as "DOS" when discussing machines that use them (e.g. AmigaDOS, AMSDOS, ANDOS, Apple DOS, Atari DOS, Commodore DOS, CSI-DOS, ProDOS, and TRS-DOS). While providing many of the same operating system functions for their respective computer systems, programs running under any one of these operating systems would not run under others.

Design
All MS-DOS-type operating systems run on machines with the Intel x86 or compatible CPUs, mainly the IBM PC and compatibles. Machine-dependent versions of MS-DOS were produced for many non-IBM-compatible x86-based machines, with variations from relabelling of the Microsoft distribution under the manufacturer's name, to versions specifically designed to work with non-IBM-PC-compatible hardware. DOS-C's predecessor DOS/NT ran on Motorola 68000 CPU's.
DOS is a single-user, single-task operating system with basic kernel functions that are non-reentrant: only one program at a time can use them. There is an exception with Terminate and Stay Resident (TSR) programs, and some TSRs can allow multitasking. However, there is still a problem with the non-reentrant kernel: once a process calls a service inside of operating system kernel (system call), it must not be interrupted with another process calling system call, until the first call is finished.
The DOS kernel provides various functions for programs (an application program interface), like displaying characters on-screen, reading a character from the keyboard, accessing disk files and more.
DOS by default provides a primitive ability for shell scripting, via batch files (with the filename extension .BAT). These are text files that can be created in any DOS text editor, such as the MS-DOS Editor. They are executed in the same fashion as compiled programs, and run each line of the batch file as a command. Batch files can also make use of several internal commands, such as goto and conditional statements. gosub and simple arithmetic is supported in some third-party shells but can also be faked via strange workarounds; however, no real form of programming is usually enabled.
The operating system offers a hardware abstraction layer that allows development of character-based applications, but not for accessing most of the hardware, such as graphics cards, printers, or mice. This required programmers to access the hardware directly, usually resulting in each application having its own set of device drivers for each hardware peripheral. Hardware manufacturers would release specifications to ensure device drivers for popular applications were available.

Drive naming scheme
In DOS, drives are referred to by identifying letters. Standard practice is to reserve "A" and "B" for floppy drives. On systems with only one floppy drive DOS assigns both letters to the drive, prompting the user to swap disks as programs alternate access between them. This facilitates copying from floppy to floppy or having a program run from one floppy while accessing its data on another. Hard drives were originally assigned the letters "C" and "D". DOS could only support one active partition per drive. As support for more hard drives became available, this developed into first assigning a drive letter to each drive's active primary partition, then making a second pass over the drives to allocate letters to logical drives in the extended partition, then a third pass to give any other non-active primary partitions their names (where such additional partitions existed and contained a DOS-supported file system.) Lastly, DOS allocates letters for optical disc drives, RAM disks, and other hardware. Letter assignments usually occur in the order the drivers are loaded, but the drivers can instruct DOS to assign a different letter; drivers for network drives, for example, typically assign letters nearer the end of the alphabet.
Because DOS applications use these drive letters directly (unlike the /dev directory in Unix-like systems), they can be disrupted by adding new hardware that needs a drive letter. An example is the addition of a new hard drive having a primary partition where a pre-existing hard drive contains logical drives in extended partitions; the new drive will be assigned a letter that was previously assigned to one of the extended partition logical drives. Moreover, even adding a new hard drive having only logical drives in an extended partition would still disrupt the letters of RAM disks and optical drives. This problem persisted through the 9x versions of Windows until NT, which preserves the letters of existing drives until the user changes them.

Boot sequence
The boot sector on PC-compatible computers (MBR) is located at track zero. The boot sector on all disc devices are then in turn loaded into memory segment 0000:7C00, and if the sector contains the values "0x55 0xAA" at position 0x1FE, it's considered to be valid and is executed. On harddiscs each of the four partitions are searched for an active partition (bit-7=1 at pos 0x1BE+0x10*n).
The boot sector code loads the DOS-BIOS into segment 0000:0600; which is located in the file IO.SYS on MS-DOS systems. In some cases the boot sector instead relocates itself into 0000:0600 and loads the partition boot code into 0000:7C00 and executes it.
The DOS-BIOS will then load the DOS kernel, located in MSDOS.SYS on MS-DOS systems. In the DOS-kernel Windows 9x, the DOS-BIOS and kernel are combined in IO.SYS, and MSDOS.SYS is used as a text configuration file.
The kernel then loads the \CONFIG.SYS file to parse configuration parameters. The SHELL variable specifies the location of the shell which defaults to \COMMAND.COM.
The shell is loaded and executed.
The startup batch file AUTOEXEC.BAT is then run by the shell. DR-DOS allows specification of the startup batch file through a parameter in the SHELL statement.:392
The BIOS and kernel files loaded by the boot sector must be contiguous and be the first two directory entries. As such, removing and adding this file is likely to render the media unbootable. It is, however, possible to replace the shell at will, a method that can be used to start the execution of dedicated applications faster.
Variations from MS DOS re-name the BIOS and kernel files, for example, in DR-DOS and PC-DOS IBMBIO.COM is used in place of IO.SYS and IBMDOS.COM in place of MSDOS.SYS. On systems designed for PC-DOS v1.10 the signature 0x55 0xAA at position 0x1FE is not checked.