You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long. 7.7KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. [![Donate](](
  2. [Operating Systems: From 0 to 1](
  3. =============================
  4. This book helps you gain the foundational knowledge required to write an
  5. operating system from scratch. Hence the title, 0 to 1.
  6. After completing this book, at the very least you will learn:
  7. - How to write an operating system from scratch by reading hardware datasheets.
  8. In the real world, it works like that. You won't be able to consult Google for
  9. a quick answer.
  10. - A big picture of how each layer of a computer is related to the other, from hardware to software.
  11. - Write code independently. It's pointless to copy and paste code. Real learning
  12. happens when you solve problems on your own. Some examples are given to kick
  13. start, but most problems are yours to conquer. However, the solutions are
  14. available online for you to examine after giving it a good try.
  15. - Linux as a development environment and how to use common tools for low-level
  16. programming.
  17. - x86 assembly in-depth.
  18. - How a program is structured so that an operating system can run.
  19. - How to debug a program running directly on hardware with gdb and QEMU.
  20. - Linking and loading on bare metal x86_64, with pure C. No standard library. No
  21. runtime overhead.
  22. [Download the book](
  23. # The pedagogy of the book
  24. > You give a poor man a fish and you feed him for a day. You teach him to fish
  25. > and you give him an occupation that will feed him for a lifetime.
  26. This has been the guiding principle of the book when I was writing it. The book does
  27. not try to teach you everything, but enough to enable you to learn by yourself.
  28. The book itself, at this point, is quite "complete": once you master part 1 and
  29. part 2 (which consist of 8 chapters), you can drop the book and learn by
  30. yourself. At this point, smart readers should be able to continue on their own.
  31. For example, they can continue their journeys
  32. on [OSDev wiki](; in fact, after you study
  33. everything in part 1 and part 2, you only meet
  34. the [minimum requirement]( by OSDev
  35. Wiki (well, not quite, the book actually goes deeper for the suggested topics).
  36. Or, if you consider developing an OS for fun is impractical, you can continue
  37. with a Linux-specific book, such as this free
  38. book [Linux Insides](, or other
  39. popular Linux kernel books. The book tries hard to provide you a strong
  40. foundation, and that's why part 1 and part 2 were released first.
  41. The book teaches you core concepts, such as x86 Assembly, ELF, linking and
  42. debugging on bare metal, etc., but more importantly, where such information
  43. come from. For example, instead of just teaching x86 Assembly, it also teaches
  44. how to use reference manuals from Intel. Learning to read the official
  45. manuals is important because only the hardware manufacturers themselves
  46. understand how their hardware work. If you only learn from the secondary
  47. resources because it is easier, you will never gain a complete understanding of
  48. the hardware you are programming for. Have you ever read a book on Assembly, and
  49. wondered where all the information came from? How does the author know
  50. everything he says is correct? And how one seems to magically know so much about
  51. hardware programming? This book gives pointers to such questions.
  52. As an example, you should skim through chapter 4, "x86 Assembly and C", to see
  53. how it makes use of the Intel manual, Volume 2. And in
  54. the process, it guides you how to use the official manuals.
  55. Part 3 is planned as a series of specifications that a reader will implement to
  56. complete each operating system component. It does not contain code aside from a
  57. few examples. Part 3 is just there to shorten the reader's time when reading the
  58. official manuals by giving hints where to read, explaining difficult concepts
  59. and how to use the manuals to debug. In short, the implementation is up to the
  60. reader to work on his or her own; the chapters are just like university assignments.
  61. # Prerequisites
  62. Know some circuit concepts:
  63. + Basic Concepts of Electricity: atoms, electrons, protons, neutrons, current flow.
  64. + Ohm's law
  65. However, if you know absolutely nothing about electricity, you can quickly learn it here:
  66. <>, by reading chapter 1 and chapter 2.
  67. C programming. In particular:
  68. + Variable and function declarations/definitions
  69. + While and for loops
  70. + Pointers and function pointers
  71. + Fundamental algorithms and data structures in C
  72. Linux basics:
  73. + Know how to navigate directory with the command line
  74. + Know how to invoke a command with options
  75. + Know how to pipe output to another program
  76. Touch typing. Since we are going to use Linux, touch typing helps. I know typing
  77. speed does not relate to problem-solving, but at least your typing speed should
  78. be fast enough not to let it get it the way and degrade the learning experience.
  79. In general, I assume that the reader has basic C programming knowledge, and can
  80. use an IDE to build and run a program.
  81. # Status:
  82. * Part 1
  83. - Chapter 1: Complete
  84. - Chapter 2: Complete
  85. - Chapter 3: Almost. Currently, the book relies on the Intel Manual for fully explaining x86 execution environment.
  86. - Chapter 4: Complete
  87. - Chapter 5: Complete
  88. - Chapter 6: Complete
  89. * Part 2
  90. - Chapter 7: Complete
  91. - Chapter 8: Complete
  92. * Part 3
  93. - Chapter 9: Incomplete
  94. - Chapter 10: Incomplete
  95. - Chapter 11: Incomplete
  96. - Chapter 12: Incomplete
  97. - Chapter 13: Incomplete
  98. ... and future chapters not included yet ...
  99. In the future, I hope to expand part 3 to cover more than the first 2 parts. But
  100. for the time being, I will try to finish the above chapters first.
  101. # Sample OS
  102. [This repository]( is the sample OS of the
  103. book that is intended as a reference material for part 3. It covers 10 chapters
  104. of the "System Programming Guide" (Intel Manual Volume 3), along with a simple
  105. keyboard and video driver for input and output. However, at the moment, only the
  106. following features are implemented:
  107. - Protected mode.
  108. - Creating and managing processes with TSS (Task State Structure).
  109. - Interrupts
  110. - LAPIC.
  111. Paging and I/O are not yet implemented. I will try to implement it as the book progresses.
  112. # Contributing
  113. If you find any grammatical issues, please report it using Github Issues. Or, if
  114. some sentence or paragraph is difficult to understand, feel free to open an
  115. issue with the following title format: `[page number][type] Descriptive Title`.
  116. For example: `[pg.9][grammar] Incorrect verb usage`.
  117. `type` can be one of the following:
  118. - `Typo`: indicates typing mistake.
  119. - `Grammar`: indicates incorrect grammar usage.
  120. - `Style`: indicates a style improvement.
  121. - `Content`: indicates problems with the content.
  122. Even better, you can make a pull request with the provided book source. The main
  123. content of the book is in the file "Operating Systems: From 0 to 1.lyx". You can
  124. edit the .txt file, then I will integrate the changes manually. It is a
  125. workaround for now since Lyx can cause a huge diff which makes it impossible to
  126. review changes.
  127. The book is in development, so please bear with me if the English irritates you.
  128. I really appreciate it.
  129. Finally, if you like the project and if it is possible, please donate to help
  130. this project and keep it going.
  131. # Got questions?
  132. If you have any question related to the material or the development of the book,
  133. feel free to [open a Github issue](