Write OS kernel from scratch (Preface)

Time:2021-10-25

This is a series that I wanted to do for a long time. Writing a small operating system from scratch is not only a tribute to the OS project done in the previous school, but also hopes to help students who are interested in this piece.

Operating system is the core discipline of computer major, but I think even CS undergraduate operating system courses in many universities may not set projects of such scale and difficulty. I took their undergraduate OS courses when I was a graduate student in CMU15-410, this is the largest project assignment of the course. For many students majoring in computer science and students who transfer from non science classes to computer science, it is of great benefit to try to do it, even to understand such a project.

Project expectation

There are many similar and good series of tutorials on the Internet. I also hope my series can bring some differences. You can roughly have a psychological expectation:

  • This is a series of articles on practice + principle interpretation. I will use pictures instead of words as much as possible;
  • This is not a hand-in-hand teaching series. Some hands-on places need to be solved by yourself. Of course, I will give my git project address for your reference;
  • I will not post too much code line by line explanation, nor will I explain too much professional knowledge in some textbooks or manuals (I think you should know, or have the ability to self-study / check);

Knowledge preparation

In order to understand this series, you need to have sufficient professional knowledge preparation. In general, you need to know all the theoretical knowledge of the University operating system professional course. You don’t need to be proficient, but at least you can understand it and know how to check it when you need it. Recommended here《Deep understanding of computer systems》This book, if your level has covered this book, you can continue.

More specifically, I hope your theoretical and practical abilities can cover the following:

  • Solid C language skills;
  • It also has sufficient x86 assembly capacity (which can be improved in the project);
  • Familiar with Linux system and system programming experience under Linux;
  • Use of GCC, makefile and other tools;
  • Have a good understanding of the principles of compiling, linking and executing code;
  • The principle of memory management by hardware and OS, especially virtual memory;
  • Program loading in the operating system, execution process, memory use and distribution;
  • Concept and handling of interrupt;
  • Concept and principle of process and thread;
  • Multithreading programming, synchronization and lock concept;

Does it seem a little too much… This is indeed the basic requirement for you, but it’s still the same sentence. You don’t need to be proficient. You just need to be able to “understand”. You can only have a vague theoretical concept and a weak practical foundation. You can improve these abilities in the project, which is also the ultimate purpose of the project.

Recommended bibliographies and tutorials

Just looking at my series may not be enough or suitable for everyone, so I recommend some books and tutorials I have read:

JamesM’s kernel development tutorials

This series is highly recommended. The author has a clear grasp of the key points, and the organizational structure and code are very clear. However, the scale of this series of projects is relatively small. There is no thread, process and system call after the boot loader and kernel are formed. As a whole, it is partial to demo and teaching, which is very suitable for beginners.

Operating system truth restore

This is also a recommended book. Contrary to the above series, this book completely implements a fully functional kernel from beginning to end, with a large scale, and the author’s explanation is very detailed and tireless. Even I think it is a little wordy, which is more suitable for reference and theoretical manual query in actual project development, rather than reading through from beginning to end.

In fact, my series of projects refer to and integrate the above two, take a compromise, and control the scale and difficulty to what I think is more reasonable.

Project directory

Before we start the series, let’s first make a list of the items and fill in the holes one by one.

There’s still a lot of content. Let’s take it step by step and get ready to go.