What is an Operating System?

circuit board

WHAT IS AN OPERATING SYSTEM?

Operating systems perform two basic unrelated functions, extending the machine and managing resources.

The most fundamental system program is the operating system, whose job is to control all the computer’s resources and provide a base upon which the application programs can be written.

A modern computer system consists of one or more processors, some main memory, disks, printers, a keyboard, a display, network interfaces, and other input/output devices. All in all, a complex system. Writing programs that keep track of all these components and use them correctly, let alone optimally, is an extremely difficult job. If programmers had to deal with this, nobody would program.

Many years ago it became abundantly clear that some way had to be found to shield programmers fro the complexity of the hardware. The way that has evolved was to put a layer of software on top of the hareware, to manage all parts of the system, and present the user with an interface or virtual machine that is easier to understand and program. This layer of software is the operating system.

Let’s look at the diagram below that shows the layout.

  • Application Programs (web browser, etc.)
  • System programs ( compilers, editors, and the operating system)
  • Hardware (Machine language, Microarchitecture, and physical devices)
Bank AppWeb browserCalendar
CompilersEditorsCommand interpreter
Operating System
Machine Language
Microarchitecture
Physical devices

The lowest level contains the physical devices, consisting of integrated circuit chips, wires, power supply, cathode ray tubes, and similar physical devices.

Next is the microarchitecture level, in which the physical devices are grouped together to form functional units. Typically this level contains some registers internal to the CPU and a data path containing an arithmetic logic unit. In each clock cycle, one or two operands are fetched from the registers and combined in arithmetic logic unit (ALU) (for example, by addition or Boolean AND). The result is stored in one or more registers. On some machines, the operation of the data path is controlled by software, called the microprogram. On other machines, it is controlled directly by hardware circuits.

The purpose of the data path is to execute some set of instructions. Some of these can be carried out in one data path cycle; others may require multiple data path cycles. These instructions may use registers or other hardware facilities. Together, the hardware and instructions visible to an assembly language programmer from the ISA (Instruction Set Architecture) This level is often called machine language.

The machine language typically has between 50-300 instructions, mostly for moving data around the machine, doing arithmetic, and computing values. In this level, the input/output devices are controlled by loading values into special device registers. For example, a disk can be commanded to read by loading the value of the disk address, main memory address, byte count, and direction (read or write) into its registers. In practice, many more parameters are needed, and the status returned by the drive after an operation may be complex. Furthermore, for many I/O (Input/Output) devices, timing plays an important role in the programming.

A major function of the operating system is to hide all this complexity and give the programmer a more convenient set of instructions to work with. For example, read block from file is conceptually much simpler than having to worry about the details of moving disk heads, waiting for them to settle down, and so on.

On top of the operating system, we have system software such has a command interpreter (shell), word processors, editors, etc. These programs are not a part of the operating system although they may come with a computer already installed. The operating system is the software that runs in kernel mode or spervisor mode. It is protected from the user tampering. Compilers, editors, etc run in user mode. This separation keeps the user programs from interfering with resources like CPU or memory. The user can write his or her own software, but they cannot write their own clock interrupt handler, which is part of the operating system. The line can be blurred with embedded systems that have run-time programs like java. Clearly everything running in kernel mode is the operating system to some extent. With Linux, Linux is just the Kernel, and the operating system is the GNU (command line shells with commands like: ls, cp, mv, mkdir, etc…). In MINIX the file system is simply a large C program running in user-mode.

The Operating System as an Extended Machine

We mentioned that the operating system is to shield, to some extent, the programmer or user from the complexities of the hardware. Let’s look at an example of why. Now today floppy disks are not used on pc computers, but let’s look at the example. The floppy disk I/O is done using the NEC PD765 compatible controller chips used on many Intel-based personal computers. The PD765 has 16 commands, each specified by loading between 1 and 9 bytes into a device register. These commands are for reading and writing data, moving the disk arm, and formatting tracks, as well as initializing, sensing, resetting, and recalibrating the controller and the drives.

The most basic commands are read and write, each of which requires 13 parameters, packed into 9 bytes. These parameters specify such items as the address of the disk block to be read, the number of sectors per track, the recording mode used on the physical medium, the intersector gap spacing, and what to do with a deleted-data-address-mark. When the operation is completed, the controller chip returns 23 status and error fields packed into 7 bytes. As if this is not enough the floppy disk programmer must be constantly aware if the motor is on or off. If the motor is off, it much be turned on (with a long startup delay) before data can be read or written. The motor cannot be left on too long, however, or the floppy disk will wear out. The programmer is thus forced to deal with the trade-off between long startup delays versus wearing out floppy disks (and losing the data on them). Let’s look at this example below of the complexity.

The NEC µPD765 is a floppy disk controller (FDC) that was widely used in PCs (essentially equivalent to the Intel 8272 and compatible with the WD2797 family).

It recognizes 16 commands (some with multiple variants depending on parameters). These are grouped into categories for read, write, formatting, and drive control. Here’s the full list:

NEC µPD765 Command Set (16 total)

  1. Read Data – Reads one or more sectors.
  2. Read a Track – Reads an entire track (index to index).
  3. Read ID – Reads sector ID fields from a track.
  4. Read Deleted Data – Reads sectors marked as “deleted data.”
  5. Scan Equal – Compares read data against a pattern; continues until equal.
  6. Scan Low or Equal – Compares read data against a pattern; continues until ≤.
  7. Scan High or Equal – Compares read data against a pattern; continues until ≥.
  8. Write Data – Writes one or more sectors.
  9. Write Deleted Data – Writes data with “deleted data” mark.
  10. Format a Track – Formats an entire track with given sector headers.
  11. Specify – Sets controller parameters (step rate, head load/unload times, DMA, etc).
  12. Sense Interrupt Status – Returns interrupt cause, drive/head status.
  13. Sense Drive Status – Reports drive status flags.
  14. Recalibrate (Seek to Track 0) – Moves head to track 0.
  15. Seek – Moves head to specified track.
  16. Invalid Command (any undefined opcode → results in error)

Notes:

  • Some sources count only the 15 valid commands, with “Invalid” being just the error case. But the original NEC µPD765 documentation lists 16 entries, including the invalid command case.
  • Commands like Scan Equal/High/Low are rarely used in PCs, but they were included for flexibility.
  • DOS and BIOS typically used only a subset: Read DataWrite DataFormat TrackRecalibrateSeekSense Interrupt StatusSpecify.

NEC µPD765 Command Set

CommandOpcode (binary)BytesFunction
1. Read Data0000 0110 (06h)9Reads one or more sectors into memory (with DMA).
2. Read a Track0000 0010 (02h)9Reads an entire track, including all sectors. Rarely used.
3. Read ID0000 1010 (0Ah)2Reads sector ID field (C/H/R/N) from current head position.
4. Read Deleted Data0000 1100 (0Ch)9Reads sectors marked as “deleted data.”
5. Scan Equal1000 0001 (11h)9Compares each byte read with user buffer, stop if equal.
6. Scan Low or Equal1000 1001 (19h)9Compares data, stop if ≤.
7. Scan High or Equal1000 1101 (1Dh)9Compares data, stop if ≥.
8. Write Data0000 0101 (05h)9Writes one or more sectors to disk.
9. Write Deleted Data0000 1001 (09h)9Writes data with “deleted data” mark in the ID field.
10. Format a Track0000 1101 (0Dh)6 + 4×NFormats a full track, writing sector headers and gaps.
11. Specify0000 0011 (03h)3Sets controller timings: step rate, head load/unload, DMA mode.
12. Sense Interrupt0000 1000 (08h)1Returns result of last interrupt (status, drive, cylinder).
13. Sense Drive Status0000 0100 (04h)2Reports drive status (ready, seek end, write protect, etc).
14. Recalibrate0000 0111 (07h)2Seeks head to Track 0 (home).
15. Seek0000 1111 (0Fh)3Moves head to specified track.
16. Invalid Commandanything elseAny undefined opcode → error (sets IC code = 1).

📌 Extra Notes

  • “Bytes” column = total command bytes (opcode + parameters).
  • Read/Write/Scan/Format commands usually require 9 command bytes:
    • Opcode
    • Head/drive
    • Cylinder, Head, Record (sector), N (sector size code)
    • EOT (end of track), GPL (gap length), DTL (data length).
  • Results Phase: Most commands return a Result Phase (status bytes).
  • BIOS typically used only:
    • Read DataWrite DataFormat TrackRecalibrateSeekSense Interrupt, and Specify.

You can plainly see how complex this is, so we, the user or the programmer, to have an abstraction layer. The prgram that hides the truth about the hardware from the programmer or user presents a nice simple view of named files that can be read or written, is the operating system. So in some sense the operating system can be seen as an extended machine or virtual machine. 

Now let’s look at the operating system as a resource manager. We will look at this from a time and space view. If three programs are to use the CPU, the operating system will control this. The first program will get CPU time, then program two, then program three, then program one again. Determining how the resource is time multi-plexed, who goes next and for how long, is the job of the operating system. Another example is having multiple print jobs. If you have multiple print jobs, you need to separate each job, or you’ll have some lines from job one, then some lines of job two printing, etc. This would be a mess, so the operating system controls and separates each job to be printed.

The other kind of multiplexing is space multiplexing. In the example before each users’ program is stored in memory to take turns. It’s more efficient to have multiple programs in memory than to give all of the memory to one program. Access to data in memory is very fast as opposed to retrieving data from the disk. Of course, this raises issues of fairness ( are all programs getting equal access) and protection, etc, so it’s the operating systems job to solve this. Another resource is space on the hard disk. A single disk can hold files for many users at the same time keeping these files separate from each user. Allocating disk space and keeping track of who is using which disk blocks is another task for the operating system.

So in conclusion we can see that the operating system is vital to allow programmers and users to use the system without the complexity.