MS-DOS in Operation It is unlikely that you will ever be called upon to configure the MS-DOS software for a new model of computer. Still, an acquaintance with the general structure of MSDOS can often be very helpful in understanding the behavior of the system as a whole. In this chapter, we will discuss how MS-DOS is organized and how it is loaded into memory when the computer is turned on. The Structure of MS-DOS MS-DOS is partitioned into several layers that serve to isolate the kernel logic of the operating system, and the user's perception of the system, from the hardware it is running on. These layers are: 1. The BIOS (Basic Input/Output System) 2. The DOS kernel 3. The command processor (shell) The BIOS Module The BIOS is specific to the individual computer system and is provided by the manufacturer of the system. It contains the default resident hardware-dependent drivers for the following devices: 1. Console display and keyboard (CON) 2. Line printer (PRN) 3. Auxiliary device (AUX) 4. Date and time (CLOCK$) 5. Boot disk device (block device) The MS-DOS kernel communicates with these device drivers through I/O request packets; the drivers then translate these requests into the proper commands for the various hardware controllers. In many MS-DOS systems, including the IBM PC, the most primitive parts of the hardware drivers are located in read-only memory (ROM) so that they can be used by stand-alone applications, diagnostics, and the system startup program. The terms resident and installable are used to distinguish between the drivers built into the BIOS and the drivers installed during system initialization by DEVICE commands in the CONFIG.SYS file. The BIOS is read into random-access memory (RAM) during system initialization as part of a file named IO.SYS. (In PC-DOS, the file is called IBMBIO.COM.) This file is marked with the special attributes hidden and system. The DOS Kernel The DOS kernel implements MS-DOS as it is seen by application programs. The kernel is a proprietary program supplied by Microsoft Corporation and provides a collection of hardware-independent services called system functions. These functions include the following: 1. File and record management 2. Memory management 3. Character-device input/output 4. Spawning of other programs þ Access to the real-time clock
Programs can access system functions by loading registers with function-specific parameters and then transferring to the operating system by means of a software interrupt. The DOS kernel is read into memory during system initialization from the MSDOS.SYS file on the boot disk. (The file is called IBMDOS.COM in PC-DOS.) This file is marked with the attributes hidden and system. The Command Processor The command processor, or shell, is the user's interface to the operating system. It is responsible for parsing and carrying out user commands, including the loading and execution of other programs from a disk or other mass-storage device. The default shell that is provided with MS-DOS is found in a file called COMMAND.COM. Although COMMAND.COM prompts and responses constitute the ordinary user's complete perception of MS-DOS, it is important to realize that COMMAND.COM is not the operating system, but simply a special class of program running under the control of MS-DOS. COMMAND.COM can be replaced with a shell of the programmer's own design by simply adding a SHELL directive to the system-configuration file (CONFIG.SYS) on the system startup disk. The product COMMAND-PLUS from ESP Systems is an example of such an alternative shell. COMMAND.COM The default MS-DOS shell, COMMAND.COM, is divided into three parts: 1. A resident portion 2. An initialization section 3. A transient module The resident portion is loaded in lower memory, above the DOS kernel and its buffers and tables. It contains the routines to process Ctrl-C and Ctrl-Break, critical errors, and the termination (final exit) of other transient programs. This part of COMMAND.COM issues error messages and is responsible for the familiar prompt Abort, Retry, Ignore? The resident portion also contains the code required to reload the transient portion of COMMAND.COM when necessary. The initialization section of COMMAND.COM is loaded above the resident portion when the system is started. It processes the AUTOEXEC.BAT batch file (the user's list of commands to execute at system startup), if one is present, and is then discarded. The transient portion of COMMAND.COM is loaded at the high end of memory, and its memory can also be used for other purposes by application programs. The transient module issues the user prompt, reads the commands from the keyboard or batch file, and causes them to be executed. When an application program terminates, the resident portion of COMMAND.COM does a checksum of the transient module to determine whether it has been destroyed and fetches a fresh copy from the disk if necessary.
The user commands that are accepted by COMMAND.COM fall into three categories: 1. Internal commands 2.External commands 3. Batch files Internal commands, sometimes called intrinsic commands, are those carried out by code embedded in COMMAND.COM itself. Commands in this category include COPY, REN(AME), DIR(ECTORY), and DEL(ETE). The routines for the internal commands are included in the transient part of COMMAND.COM. External commands, sometimes called extrinsic commands or transient programs, are the names of programs stored in disk files. Before these programs can be executed, they must be loaded from the disk into the transient program area (TPA) of memory. (See "How MS-DOS Is Loaded" in this chapter.) Familiar examples of external commands are CHKDSK, BACKUP, and RESTORE. As soon as an external command has completed its work, it is discarded from memory; hence, it must be reloaded from disk each time it is invoked. Batch files are text files that contain lists of other intrinsic, extrinsic, or batch commands. These files are processed by a special interpreter that is built into the transient portion of COMMAND.COM. The interpreter reads the batch file one line at a time and carries out each of the specified operations in order. In order to interpret a user's command, COMMAND.COM first looks to see if the user typed the name of a built-in (intrinsic) command that it can carry out directly. If not, it searches for an external command (executable program file) or batch file by the same name. The search is carried out first in the current directory of the current disk drive and then in each of the directories specified in the most recent PATH command. In each directory inspected, COMMAND.COM first tries to find a file with the extension .COM, then .EXE, and finally .BAT. If the search fails for all three file types in all of the possible locations, COMMAND.COM displays the familiar message. INTERRUPT SERVICES:====>
DOS INT 21H INT 21,1 - KEYBOARD INPUT WITH ECHO AH = 01 on return: AL = character from standard input device - waits for keyboard input from STDIN and echoes to STDOUT - returns 0 for extended keystroke, then function must be called again to return scan code - if ~Ctrl-Break~ is detected, ~INT 23~ is executed
INT 21,2 - DISPLAY OUTPUT AH = 02
DL = character to output returns nothing - outputs character to STDOUT - backspace is treated as non-destructive cursor left - if ~Ctrl-Break~ is detected, ~INT 23~ is executed
INT 21,8 - CONSOLE INPUT WITHOUT ECHO AH = 08 on return: AL = character from STDIN - returns 0 for extended keystroke, then function must be called again to return scan code - waits for character from STDIN and returns data in AL - if ~Ctrl-Break~ is detected, ~INT 23~ is executed
INT 21,9 - PRINT STRING AH = 09 DS:DX = pointer to string ending in "$" returns nothing - outputs character string to STDOUT up to "$" - backspace is treated as non-destructive - if ~Ctrl-Break~ is detected, ~INT 23~ is executed
INT 21,A - BUFFERED KEYBOARD INPUT AH = 0A DS:DX = pointer to input buffer of the format: ¦ max ¦ count ¦ BUFFER (N bytes) ¦ ¦ +------ input buffer ¦ +------------ number of characters returned (byte) +-------------- maximum number of characters to read (byte) returns nothing - since strings can be pre-loaded, it is recommended that the default string be terminated with a CR - N bytes of data are read from STDIN into buffer+2 - max buffer size is 255, minimum buffer size is 1 byte - chars up to and including a CR are placed into the buffer beginning at byte 2; Byte 1 returns the number of chars placed into the buffer (extended codes take 2 characters) - DOS editing keys are active during this call - ~INT 23~ is called if Ctrl-Break or Ctrl-C detected
BIOS INT 16H INT 16,2 - READ KEYBOARD FLAGS AH = 02 on return: AL = BIOS keyboard flags (located in ~BIOS Data Area~ 40:17) ¦7¦6¦5¦4¦3¦2¦1¦0¦ AL or BIOS Data Area 40:17 ¦ ¦ ¦ ¦ ¦ ¦ ¦ +---- right shift key depressed ¦ ¦ ¦ ¦ ¦ ¦ +----- left shift key depressed ¦ ¦ ¦ ¦ ¦ +------ CTRL key depressed ¦ ¦ ¦ ¦ +------- ALT key depressed ¦ ¦ ¦ +-------- scroll-lock is active ¦ ¦ +--------- num-lock is active ¦ +---------- caps-lock is active +----------- insert is active
BIOS INT 10H INT 10,6 - Scroll Window Up AH = 06 AL = number of lines to scroll, previous lines are blanked, if 0 or AL > screen size, window is blanked BH = attribute to be used on blank line CH = row of upper left corner of scroll window CL = column of upper left corner of scroll window DH = row of lower right corner of scroll window DL = column of lower right corner of scroll window returns nothing - in video mode 4 (300x200 4 color) on the EGA, MCGA and VGA this function scrolls page 0 regardless of the current page - can be used to scroll graphics screens, using character coords - on CGA's this function disables video adapter, causing flitter INT 10,7 - Scroll Window Down AH = 07 AL = number of lines to scroll, previous lines are blanked, if 0 or AL > screen size, window is blanked BH = attribute to be used on blank line CH = row of upper left corner of scroll window
CL = column of upper left corner of scroll window DH = row of lower right corner of scroll window DL = column of lower right corner of scroll window returns nothing - in video mode 4 (300x200 4 color) on the EGA, MCGA and VGA this function scrolls page 0 regardless of the current page - can be used to scroll graphics screens, using character coords - on CGA's this function disables video adapter, causing flitter INT 21,41 - DELETE FILE AH = 41h DS:DX = pointer to an ASCIIZ filename on return: AX = error code if CF set (see DOS ERROR CODES) - marks first byte of file directory entry with E5 to indicate the file has been deleted. The rest of the directory entry stays intact until reused. ~FAT~ pointers are returned to DOS - documented as not accepting wildcards in filename but actually does in several DOS versions
INT 21,56 - RENAME FILE AH = 56h DS:DX = pointer to old ASCIIZ path/filename ES:DI = pointer to new ASCIIZ path/filename on return: AX = error code if CF set (see ~DOS ERROR CODES~) - supports full pathnames and allows renaming files across directories and in DOS 3.x allows renaming subdirectories - does not support use of wildcards unless invoked from via ~INT 21,5D~ in which case error code 12h is returned - unpredictable result may occur if an opened file is renamed
INT 21,43 - GET/SET FILE ATTRIBUTES AH = 43h AL = 00 to get attribute = 01 to set attribute DS:DX = pointer to an ASCIIZ path name CX = attribute to set ¦5¦4¦3¦2¦1¦0¦ CX valid file attributes ¦ ¦ ¦ ¦ ¦ +---- 1 = read only ¦ ¦ ¦ ¦ +----- 1 = hidden ¦ ¦ ¦ +------ 1 = system ¦ +--------- not used for this call +---------- 1 = archive on return: AX = error code if CF set (see ~DOS ERROR CODES~)
CX = the attribute if AL was 00
INT 21,39 - CREATE SUBDIRECTORY (MKDIR) AH = 39h DS:DX = pointer to ASCIIZ path name on return: CF = 0 if successful = 1 if error AX = error code (see ~DOS ERROR CODES~) - creates specified subdirectory - returns error if directory already exists, element of the path is not found, directory full or write protected disk
INT 21,3A - REMOVE SUBDIRECTORY (RMDIR) AH = 3A DS:DX = pointer to ASCIIZ path name on return: CF = 0 if successful = 1 if error AX = error code (see ~DOS ERROR CODES~) - allows deletion of a subdirectory as long as it exists, is empty and not the current directory
INT 21,3B - CHANGE CURRENT DIRECTORY (CHDIR) AH = 3B DS:DX = pointer to ASCIIZ path name on return: CF = 0 if successful = 1 if error AX = error code if CF set (see ~DOS ERROR CODES~) - changes the current directory to the directory specified by pointer DS:DX