First steps towards system programming under MS-DOS 7/Introduction

Introduction

Nowadays, the windows of Windows-2000/XP operating system have become familiar in home interior. You look there for work and for fun. One easily gets an impression of ability to access just everything. But it's a deceptive impression: the actual origin of all computer's wonders can't be seen via these windows.

Each advanced user once comes to a sense of a virtual boundary, arranged by the Windows operating system to prevent intrusions into its internal affairs. If you want to understand computer more thoroughly, you have to choose a way leading beyond the familiar windows. But outside the windows there is darkness with no visible fulcrum for support. If you are still eager to go further, then this book is just for you.

0.01 Applied and system software edit

All computer's wonders are performed by programs. More accurately, there is a complex interaction of applied and system software, each playing its own role. For example, the well-known WORD editor program is a typical application, because it needs run-time environment, provided by the Windows operating system. On the other hand, system software is the one that creates, configures and maintains the operating environment.

Much attention is now given to application programming. Microsoft corporation, the owner of Windows operating system, actively promulgates its VISUAL STUDIO packet, comprising several high-level languages for writing applications. Microsoft's interest is obvious: the more applications will require Windows operating system, the more Windows usage licenses will be sold.

Attitude to system programming is quite opposite: leading software vendors are determined to prevent any appearance of rival system products. The right to buy some system data is given to reliable business partners only, and not every company can afford such expense. Accepted information policy doesn't foster attention to system programming, but the latter doesn't become less significant because of that. One can't be a true professional in computer technology without some knowledge and experience in system programming.

System software is not limited to operating systems only. It also includes hardware drivers, fixed BIOS programs, various diagnostic and recovery services. Study of these software functions has always been an important element of computer technology education. Traditionally system programming is taught on the basis of low-level assembler language (MASM or TASM) under documented versions of Microsoft's DOS (MS-DOS).

Now all the documented versions of MS-DOS have become so obsolete, that can't even give access to large storage media used in modern computers. More recent operating systems protect themselves against any attempt of intrusion into their affairs and respond with a known error message "Your program has performed an illegal operation and has to be shut down". Nevertheless an acceptable solution exists. It is an undocumented operating system which can be installed on modern computers and allows to do just everything. Main purpose of this book is to make you acquainted with that operating system and with its usage for solving simple system tasks.

0.02 Real mode and protected mode edit

Protection against execution of inadmissible functions is hardware implemented inside processors (CPU), and it is active while the CPU operates in protected mode. Besides the protection itself, protected mode gives several important advantages, and this is why it has become the main operating mode for modern CPUs. For application programs and for the user the protected mode resembles a virtual shell, disabling all actions which may inflict any harm to vital functions of operating system. This is the main factor of high reliability, inherent to modern operating systems.

Contrary to the protected mode, real mode is a "defenseless" mode, making CPU to emulate archaic processor i8086. One may wonder why this obsolete feature is kept supported in each next CPU generation and is not abandoned yet? There is the only reason : real mode is necessary for modern computer systems. First, real mode is required by BIOS : it must have free access to computer hardware for performing the POST tests. Just because of this mission all processors are automatically set into real mode each time the power supply is switched on. Operating systems too can't obtain control over computer's hardware unless protection is disabled, and therefore must start while CPU runs in a "defenseless" real mode.

Having got total control over computer, operating systems of the Windows clone prepare protection data structure so that after switching to protected mode the highest privilege level is granted to Windows OS itself, whereas both the user and applications are given the third (the lowest) privilege level. Since then and for ever the user wouldn't be allowed to change this allocation of rights. Because of the same reason all opportunities beyond the limits of Windows' API become inaccessible for the user and for his application programs in protected mode.

Nowadays ordinary user's practice doesn't imply experience to act beyond the restrictions, inherent to protected mode. Fundamental concept of modern operating systems is distinction between the user's and system's spheres of responsibility. Excessive user's curiosity is considered destructive and should be suppressed. Protected mode hasn't proved its efficiency against malignant viruses; it provides an effective protection ... against you.

0.03 Why MS-DOS 7 ? edit

If an operating system permits to run applications in real mode, it can't be as stable as those using protected mode. This is the main reason why old-fashioned DOS-like operating systems have been ousted by more modern ones. But ordinary ratings are not valid for emergency services which often require unlimited access rights. Then the main drawback of DOS-like operating systems turns into their unique advantage. Therefore computer professionals haven't forgotten DOS. All bootable diskettes (reparatory, diagnostic, disk service, etc.) need an operating system and load just DOS. Most part of bootable compact disks is DOS-based as well. Besides all, DOS is the simplest operating system, and just for that it is the most suitable for primary study of system functions.

Though DOS is often considered a real-mode operating system, this opinion is not completely true. Initially DOS works in real mode, but it wouldn't object against mode change undertaken either by a driver (5.04-02) or by the user. Thus you get a unique opportunity to assign the highest privilege level to yourself. Only in the latter case the CPU would obey to just any your command, including those which are allowed for execution exclusively in protected mode at the highest privilege level. No one other operating system would transfer its highest privileges to the user. Only DOS can give you full freedom of action in both real and protected modes.

Practical need of real-mode access forces software vendors to continue development of DOS-like operating systems. Independent FreeDOS project slowly advances towards completion ( http://www.freedos.org/ ). One more commercial version of ROM-DOS recently has emerged ( http://www.datalight.com/ ). Some less fresh shareware versions also have found their interested consumers. A lot of drivers are written in order to supply obsolete DOS versions (MS-DOS 6.22, IBM PC DOS 2000, etc.) with new properties, including access to disks with widespread file systems FAT-32 and NTFS. But drivers, not integrated into the DOS's core, give no opportunity to install DOS onto such disks.

If you have ever dared to buy a computer without preinstalled commercial operating system, you almost certainly found there a typical DOS prompt and a HDD (hard disk drive) formatted with FAT-32. Most probably neither of the mentioned DOS versions has any relation to that. Computer initialization is usually done with tools, supplied by Microsoft on emergency diskettes for Windows-95/98 operating systems. Formally it is known as "command line only" loading mode.

Simple examination reveals, however, that "command line only" mode doesn't resemble the Windows operating system, but rather is a typical version of DOS. Inside almost every file's code on emergency diskette you can find the proof - a string "MS-DOS Version 7...". The 7th version of MS-DOS is just that Microsoft's undocumented operating system, which is the main subject of this book. For MS-DOS taken from Windows-95 OSR2 release, function INT 21\AH=30h (8.02-22) reports exact version number 07.0Ah, or decimal 7.10. It is just this version which here and forth is referred to as MS-DOS 7.

MS-DOS 7 is not the latest version of MS-DOS. Windows-ME release is based on MS-DOS 8. Having been recompiled for modern CPUs, MS-DOS 8 became more compact, but has lost compatibility with some 486 CPU clones. Besides this, it doesn't play an active role during loading of Windows-ME and thus is unable to implement different loading schemes. But other features of MS-DOS8 are similar to those of MS-DOS 7, so most data in this book are equally true for both. Each exception is explicitly noted.

0.04 What is this book about? edit

System programming is a vast theme; its narration tends to grow beyond all affordable limits. Therefore this book doesn't pretend to completeness: several large topics (in particular, networks) have been deliberately left aside. Some other items are touched in short, as far as it is enough for comprehension.

Chapters 1–4 of this book make the reader acquainted with keyboard, with command line composition and with internal commands. These short chapters are addressed to newbies who had no deal with MS-DOS 7 ever before.

Chapter 5 describes important drivers for computer's hardware, including the most recent ones, developed by various software vendors during 2004–2008. Chapter 6 presents a survey of selected utilities for MS-DOS 7. Special attention is paid to programming instrument DEBUG.EXE – the worst documented utility inside the undocumented DOS.

Chapter 7 is devoted exclusively to DEBUG's assembler commands. The 8th chapter describes various services which can be called for in MS-DOS 7 via interrupts.

The 9th chapter presents examples of programming with the tools from Windows-95/98 standard release. Examples will help you to write your own interpretable and executable files according to your needs. Presented selection of examples illustrates the scope of opportunities which can become available in MS-DOS 7, if properly asked for.

The last chapter ("A") consists of 16 thematic appendixes with a lot of data tables, concerning both MS-DOS 7 and AT-compatible PCs. The last (16th) appendix is a glossary, explaining the abbreviations used in this book.

0.05 Some more remarks edit

For a long time leading software vendors inculcate hard selling of operating systems, which inhibit user's access to real mode. But sales of both OS/2 (IBM, 1989) and Windows-NT (Microsoft, 1994) went bad. The next attempt – Windows-2000 – opened an opportunity to employ DOS's services on disks formatted with FAT-32. As soon as success of Windows-2000 became obvious, Microsoft decided to kill the whole rival Windows-95/98/ME brood. However, this decision doesn't eliminate necessity of real mode and provides no alternative real-mode tools. I suggest to regard this Microsoft's decision as a guarantee that your study of MS-DOS 7 today will not go in vain tomorrow due to advent of any better version of MS-DOS.

One more challenge to renewal arose in 2002, when Intel has developed and began to produce the Itanium CPU, providing no support for old-fashioned 16-bit machine code. All former real-mode tools, including MS-DOS 7, could be turned into trash by forthcoming emergence of new PCs with 32-bit BIOS code, and then this book were not worth writing. Seven years have elapsed since, but the expected marvel hasn't happened. Public PCs with Itanium CPU have not emerged. One has to admit that preservation of support for 16-bit code in all newer CPUs must be caused by firm reasons. Until these reasons persist, experience in DOS will still be beneficial for you.

How to get MS-DOS 7 launched? If Windows-95/98 is installed already, just keep the F8 key pressed while PC starts to boot operating system, and you'll get into boot menu ; then choose "command line only" option, and you're there. Otherwise you'll have to get a Windows-95/98 emergency diskette, and boot your PC with this diskette. Suitable images of bootable diskettes can be found in many internet sites, for example, in http://www.bootdisk.com/ . Standard loading procedure leaves you with a "raw" DOS's command line. MS-DOS 7 may appear much more convenient and friendly, if you'll follow the advices given in parts 6.25 and 9.01 of this book. Part 9.11 suggests some other ways of launching MS-DOS 7, including those sharing common disk with Windows OS.