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.

README.md 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
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=tuhdo1710%40gmail%2ecom&lc=VN&item_number=tuhdo&currency_code=USD&bn=PP%2dDonationsBF%3aDonate%2dPayPal%2dgreen%2esvg%3aNonHosted)
  2. [Operating Systems: From 0 to 1](https://tuhdo.github.io/os01/)
  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](https://github.com/tuhdo/os01/blob/master/Operating_Systems_From_0_to_1.pdf)
  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](http://wiki.osdev.org/Main_Page); in fact, after you study
  33. everything in part 1 and part 2, you only meet
  34. the [minimum requirement](http://wiki.osdev.org/Required_Knowledge) 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](https://0xax.gitbooks.io/linux-insides/content/), 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. <http://www.allaboutcircuits.com/textbook/>, 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](https://github.com/tuhdo/sample-os) 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](https://github.com/tuhdo/os01/issues/new).