Lesson 1. The Role of the Operating System

I had a dream to write an operating system (OS) by myself when I was a middle school student. The OS was like a Pandora's box to me, magically managing all hardware components. It would be very exciting to develop my own one. After taking the OS class in college, however, I realized that the OS is one of the most complex software systems. Since it has to communicate with all kinds of hardware devices, you can imagine how much effort it needs to develop a fully functional OS.

The mysterious inside of the OS has always kept me curious. Unfortunately, most of the OS textbooks only focus on algorithms and principles. They seldom touch the implementation details of a real world system, in which I am interested most. I believe many are in the same dilemma. The best source for the OS study is certainly the Linux code. However, getting to know the details is a slow and painful process. As a newbie, I wasted a lot of time in trying to understand some very specific implementation issues. While those issues are not critical to understand the concepts, they become the real obstacles when you try to write your own. This tutorial is meant to share my experience of the operating system learning, post useful materials related to the OS development and provide you the starting point for building your own OS. Due to my limited knowledge, errors can be found here and there in the tutorial. Your comments are always appreciated. Finally but not the last, wish your dream comes true! :) 

Now, let's start the topic. As we all know, the OS is probably the first software you may want to install into your computer. It provides an abstract and consistent view of the underlying hardware so that applications can run on computers with very different hardware composition. Figure.1 illustrates the role of the operating system in the entire system. The underlying hardware generally consists of CPU, memory and peripheral devices. The OS interacts with these hardware components through instruction set architecture (ISA). The ISA provides an abstract view of the underlying hardware to the OS so that latter does not have to worry about the hardware implementation details. Using the concept of "Layer" and "abstraction" is a very important design approach in computer systems. You will get familiar to it. The ISA includes a set of machine instructions and a group of registers. By executing instructions and reading/writing corresponding registers, the OS can instruct the hardware to accomplish a particular task and get necessary feedback. This is exactly how the "magic" happens. Indeed, this is a universal way of cooperating software and hardware. Thus ISA is often called the hardware/software interface.

Now, the OS is able to control CPU and memory transactions using ISA. However, there are a large number of peripheral devices in the market and new products are coming out every day. How can the OS handle such varieties? The common solution is to adopt a modularized approach. The device driver module of the OS is provided by the product vendor. The device driver implements a set of predefined action handlers required by the OS. Whenever the OS wants to access peripheral devices, it request the service through those action handlers. Most of the major OS tasks are implemented in the kernel. They include booting/initialization, process scheduling, memory management, file system management and so on. Hopefully, we can cover them!

The OS wraps up all services it can provide to the applications through a mechanism commonly called "system call". An OS can have more than one hundred system calls, serving all kinds of requests. The role of system calls is similar to the ISA. They are the interface between user applications and the OS. By providing system calls, the OS further abstract its implementation details and allow the user applications to control underlying hardware indirectly and safely without knowing any specifics.

In conclusion, the role of the OS is to provide services to user applications while hiding the underlying hardware complexities as much as possible. So in order to understand an operating system implementation, knowledges of microprocessor architecture and hardware organization  are necessary. But do not worry too much as I will present related background when we see it. I will also demonstrate some experiments and code to further help you better understand.


0 comments: