- C 68%
- Assembly 14.9%
- Makefile 5.7%
- Python 3.6%
- TeX 2.7%
- Other 5.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
release / book (push) Successful in 2m13s
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> |
||
| .forgejo/workflows | ||
| .github/workflows | ||
| book | ||
| book_src | ||
| code | ||
| tools | ||
| .gitignore | ||
| _config.yml | ||
| CHANGELOG.md | ||
| LICENSE | ||
| Operating_Systems_From_0_to_1.pdf | ||
| OVERHAUL.md | ||
| README.md | ||
Operating Systems: From 0 to 1
This book helps you gain the foundational knowledge required to write an operating system from scratch. Hence the title, 0 to 1.
After completing this book, at the very least you will learn:
- How to write an operating system from scratch by reading hardware datasheets. In the real world, it works like that. You won't be able to consult Google for a quick answer.
- A big picture of how each layer of a computer is related to the other, from hardware to software.
- Write code independently. It's pointless to copy and paste code. Real learning happens when you solve problems on your own.
- Linux as a development environment and how to use common tools for low-level programming.
- x86 assembly in-depth.
- How a program is structured so that an operating system can run.
- How to debug a program running directly on hardware with gdb and QEMU.
- Linking and loading on bare metal, with pure C. No standard library. No runtime overhead.
- Protected mode, device drivers, interrupts, paging, processes, user mode and system calls, and a filesystem: a kernel that boots from a disk image and runs user programs read from an ext2 partition.
Second edition
The second edition is a full overhaul of the 2017-2020 text. What changed and why is recorded in OVERHAUL.md. In short:
- A new chapter 0 sets up a reproducible toolchain (a container, or packages), and every listing in the book was regenerated with it, so what you see on your screen matches the page.
- Part III (chapters 9 to 17) is written, with the sample code grown chapter by
chapter under
code/, each state boot-tested in QEMU by the continuous integration of this repository. Chapter 16 is a debugging guide and Appendix C a tested long-mode bootstrap. - Every chapter ends with exercises and "Check your understanding" questions (answers in Appendix E); each part closes with a milestone project and the epilogue with three capstone projects and their rubric.
- The source is Markdown under
book/; HTML, PDF and EPUB are built from it.
Reading the book
Download a build from the releases page, or build it yourself:
make -C book html # book/out/os01.html, the whole book in one file (no TeX needed)
make -C book site # book/out/site/, one page per chapter with a table of
# contents in the sidebar; open index.html (no TeX needed)
make -C book # all of the above plus os01.pdf (xelatex) and os01.epub
Requirements: pandoc 3, TeX Live with xelatex and the TeX Gyre fonts,
librsvg (rsvg-convert).
Running the code
docker build -t os01 tools/
docker run --rm -it --user "$(id -u):$(id -g)" --security-opt seccomp=unconfined -v "$PWD":/work -w /work os01
make -C code/chapter7/os test
See chapter 0 and code/README.md.
Prerequisites
Know some circuit concepts:
- Basic Concepts of Electricity: atoms, electrons, protons, neutrons, current flow.
- Ohm's law
However, if you know absolutely nothing about electricity, you can quickly learn it here: http://www.allaboutcircuits.com/textbook/, by reading chapter 1 and chapter 2.
C programming. In particular:
- Variable and function declarations/definitions
- While and for loops
- Pointers and function pointers
- Fundamental algorithms and data structures in C
Linux basics:
- Know how to navigate directory with the command line
- Know how to invoke a command with options
- Know how to pipe output to another program
In general, I assume that the reader has basic C programming knowledge, and can use an IDE to build and run a program.
Status
| Part | Chapters | State |
|---|---|---|
| Front matter | Preface, 0 Environment | complete |
| I Preliminary | 1-6 | complete, listings regenerated for the pinned toolchain |
| II Groundwork | 7-8 | complete, code fixed for current binutils |
| III Kernel programming | 9-17 | written in the second edition; code under code/chapter9 to code/chapter15, chapter 16 is the debugging guide, chapter 17 the epilogue with the capstone projects |
| Appendices | A toolchain reference, B errata, C long-mode bootstrap (code/appendix-c-longmode), D reading the manuals, E answers; glossary |
complete |
Contributing
The book is plain Markdown: one file per chapter in book/, conventions in
book/STYLE.md. Fix a typo by editing the file and opening a
pull request; CI builds the book and boots every chapter's code.
To report a problem, open an issue with the title format
[chapter N][type] Descriptive title, where type is one of Typo,
Grammar, Style, Content, Code.
The original LyX source of the first edition is kept under book_src/ for
reference and is no longer edited.
Translations
The Markdown source makes a translation a matter of editing text files, with the same build producing HTML, PDF and EPUB. The suggested workflow:
- open an issue first, titled
[translation] <language>, so that translators of the same language find each other and the maintainers know the work is under way; - copy
book/tobook-<lang>/(for examplebook-fr/) and keep the file names, so that a chapter can be compared with its original side by side and updates to the English text can be followed by file name; - translate the prose, the captions and the exercise text, but leave the listings, the command lines, the program output and the identifiers alone: the reader must see on their screen what is on the page;
- build with
make -C book-<lang>(ormake -C book-<lang> htmlfor a quick check) and fix anything pandoc reports.
Figures under book/images/ with text in them are SVG files and can be
translated with any text editor.
License
The book and its sample code are released under the GNU General Public
License, version 3 or (at your option) any later version. See LICENSE.
The original author chose the GPL in issue #91; the second edition applies
that choice to the whole repository. For the purpose of the GPL, the "source
code" of the book is the Markdown under book/ together with the figures
under book/images/, and the "source code" of the kernel is everything under
code/.
Got questions?
If you have any question related to the material or the development of the book, feel free to open a Github issue.