OS-9: A Structured Operating System
by Mark G. Boyd
from the June 1983 issue of Micro magazine
When something new comes along most of us tend to be conservative about giving up the familiar. A good example of this behavior is the use of structured programming languages on microcomputers. Languages like Pascal have been available to us for a couple of years; they are easier to program in and more efficient than BASIC. However, only a relative minority of microcomputer users have switched to a structured language, and none of the major manufacturers offer anything other than BASIC as standard equipment.
Recently a number of new operating systems have come on the market. These operating systems bear about the same relationship to the currently dominant systems (CP/M, Apple DOS, Flex) as Pascal does to BASIC. They are more powerful and, usually, easier to use.
Structured operating systems have the same type of structure found in a structured program, looking like an upside-down tree. The highest level is called the root node and is the overall control structure and most abstract part of the system. The root node is connected to the highest level of branch nodes, each of which are connected to their own set of branch nodes on the next lower level. On any level, a node may not be connected to any lower-level nodes. This type of node is called a leaf node and is connected only to a single branch node on the next higher level. In a structured program the leaf nodes are the most detailed part of the program. In a structured operating system they are the I/O device drivers, the data files, and the lowest level routines in the programs.
There are different types of tree structures used in structured programming and as data structures. I will restrict my discussion to one particular type: the hierarchical structure. In this structure the root node is called the ancestor of all other nodes. The next lower level of nodes are the children of the root node, each of which may have children of its own. As you work down the tree, each level of nodes represents a new generation of children. Each node has only one parent node, but it may have any number of child nodes. A path from the root node to any other node in the structure is simply a list of descendants, starting with the root node and ending with the desired node. The path from the root node to any other node is unique. Any node may be reached from any other node by working up the structure until a common ancestor node is found and then working down to the desired node.
Data flow in a hierarchical structure is allowed only along the paths connecting the nodes. All data is local to the procedures /files that are the nodes. Data may be passed from a parent to its child or from a child to its parent; it cannot be passed to any- other node without working through a path that involves a common ancestor. This system sounds complex but, as you shall see, it is the basis for very simple, but powerful operating systems.
OS-9, which uses this hierarchical structure and is a by-product of BASIC-09, is a result of Motorola’s 6809 development process. The software was developed simultaneously with the hardware it is designed to use. Motorola and Microware, realizing that BASIC-09 needed an equally well-structured operating system to support it, developed OS-9 to allow BASIC-09 users realize the full potential of a modern programming language.
I feel OS-9 is the best of the new operating systems. It is one of the most powerful 8-bit operating systems available today and is the only truly powerful operating system that can run on a relatively small system. A 24K-byte system can support OS9, and 48K system can run several users simultaneously in a high-level language. A fully extended OS-9 system can have 1 megabyte of main memory, hard disk drives, and many users.
A Structured Operating System
OS-9 is a descendant of UNIX, the Bell Telephone Laboratories operating system for large minicomputer systems. UNIX has become the standard for multiprogramming minicomputer systems because of it’s versatility, power, and elegantly simple design. OS-9 looks much like UNIX, but its actual operation is quite different. UNIX dynamically swaps programs into memory from large, fast disk systems. OS-9 cannot do this because of the slow disk systems used with microcomputers. In order to support mulitple users, OS-9 makes use of position-independent re-entrant programs in RAM or ROM. Because the programs are re-entrant, multiple users can use the same code while maintaining different data and stack areas, and because the code is position independent, it can be brought into memory, in any available location, as needed. These two factors allow OS-9 to be much more efficient in its use of RAM and ROM than UNIX.
Multiprogramming means that the system can execute many different programs simultaneously. CPU time is divided in time slices (about . 1 seconds in OS-9), which are allocated by the system to the various tasks currently running and to the operating system overhead. With a powerful microprocessor like the 6809 and a welldesigned multiprogramming operating system like OS-9, users are not aware that they have only part of the CPU time.
OS-9 can run processes sequentially or concurrently. Each process is created by an existing process and may in turn create child processes of its own. This leads to a hierarchical structure where all processes are descendants of the original process run when OS-9 was brought up. To the user the root of each tree of processes is a process called Shell. A Shell process is executed when the system is started, and a new incarnation of Shell is created for each user who logs onto the system. Shell is a command interpreter that accepts input from the user and creates new processes in response to that input. Shell also can pass parameters to the process it creates.
When a Shell creates a process it puts itself into a waiting state until that process is finished. The user has the option of causing the Shell to create another incarnation of itself before it goes into its waiting state. This new Shell then can be used to create a new process and another incarnation of Shell, allowing a single user to make effective use of OS-9’s multiprogramming capabilities. I’ll give an example of this at the end of the article.
A hierarchical system also is used for all input and output. The top level (or root) of this tree is a general I/O manager. At this level all data is essentially a stream of bytes. Data being sent out to an external device passes down through the tree to a device driver, which is a leaf node (for single file devices) or the root node of the device file structure (for disk drives). The characteristics required for the data actually sent to the device are added as it passes down the tree. For example, data going to the disk would be blocked to sector size at one level, the appropriate preamble and postamble added at another level, and the actual sectors to be written determined at yet another level. Input data undergoes the reverse of this process as it passes up the tree. Data at the top, which is the data passed to or from a process, has the same structure regardless of its course or its destination.
The device independence of I/O data has two advantages. First, it means that I/O paths can be redirected at any time. A program that normally outputs to the printer can have its output redirected to a disk file for later printing. Input to the Shell can be redirected to allow a disk file to control the system. In other words, printer spooling and procedure files are inherent in OS-9. Second, OS-9 programs are essentially hardware independent. The program is not aware of the device driver modules, so it cannot depend on the details of the I/O hardware. A program that runs on a small OS-9 system with one minifloppy and a serial printer will run, without modification, on a large system with hard disks and a chain printer. No more problems with software transportability or system upgrades!
The heirarchical structiare extends to the file structure on the disk drive(s) . A file is accessed by specifying a path to it. This path is simply a list of all of its direct ancestors. Each entry in the list, except for the first and last, is a directory file. Directory files are the branch nodes of the tree structure and contain only the names of their immediate descendants and pointers to them. The leaf nodes of the tree are the actual data or program files. The first entry in the path list may be a device driver (e.g.,/Dl) or it may be a directory file in the current directory. The last entry is the name of the desired file. If the desired file is in the current directory, only the last entry is required.
Finally, lets explore some Shell commands. These commands are entered in response to the prompt OS9 and consist of a process name that may be followed by parameters for the process, a parameter that modifies the amount of memory used by the process, parameters that redirect the input/output paths of the process, and finally by a parameter that results in concurrent processing (i.e., creates a new incarnation of Shell). The parameters are separated by spaces and the entry is terminated by a return. Some examples are:
- OS9: LIST FILE 7
- OS9: COPY FILE3 FILE 7
- OS9: LIST /Dl/ASSMFILES/BPROM
- OS9: LIST /DO/MARKLIB/LETTER>/Pl
- OS9: LIST FILE7>/P1 & EXECUTE #7K
The first example runs the process LIST with input from FILE7, which lists FILE7 to the terminal. The second example runs the process COPY with input from FILE3 and output to FILE7. So far things are much the same as in any DOS.
The third example runs the process LIST. Input is from the file BPROM. The path list specifies that BPROM is listed in the directory file ASSM-FILES, which itself is listed in the primary directory for the disk mounted in drive Dl. The fourth example is similar to the third but it also demonstrates output redirection (>) to the serial printer driver /PI. This process lists the file LETTER to the serial printer.
The fifth example introduces concurrent execution (&.). The Shell creates a process that starts listing FILE7 to the printer. Then it creates another Shell that starts the process EXECUTE (EXECUTE is allocated 7K of RAM (#7K). All processes have a certain minimum amount of RAM that they require. This information is stored on the disk with each process. The #7K is an execution modifier that can be used to allocate larger amounts of RAM at the time the process is created.
On my system EXECUTE is a BASIC-09 program. This information is noted by the system and, when a process using EXECUTE is created, BASIC-09 is loaded automatically and instructed to run the process. EXECUTE must be in packed form and located in the CMDS directory, but that’s a subject for another article.
References
-
OS-9 Level I Operating System V1.1 Users Guide, Microwave Systems Corporation, 1981.
-
OS-9 Level I Operating System V1.1 System Programmer’s Manual, Microware Systems Corporation, 1981