os-tutorial
從頭創(chuàng)造一個操作系統(tǒng)卸夕!
這個教程完全是從@cfenollosa
fork來的,這個教程將復(fù)雜的系統(tǒng)編寫任務(wù)分解為很多簡單步驟搀缠,在每一個小步驟中穿插著需要讀者自學(xué)的簡單知識點(diǎn)缰泡,幾乎每一節(jié)課都有一點(diǎn)點(diǎn)積累,然后突然就在其中某個時刻完成了一個階段性的目標(biāo)弱左,這是讓人驚嘆的教育手段窄陡,至少我本人佩服至極,所以在我第二次學(xué)習(xí)這個教程的過程中拆火,順便將教程做了粗糙的翻譯跳夭,修正了個別bug,以作為@cfenollosa
倉庫的中文概覽们镜,如果能幫后來者節(jié)省一些時間币叹,我將深感欣慰!
@cfenollosa
的教程其實(shí)也是大量參考了別的英文的教程模狭,os-dev是前面十幾節(jié)課的參考書籍颈抚,可惜這本書沒有寫完
,但即使只是一本沒有寫完的書籍也絕對是神作嚼鹉,從BIOS到屏幕打印的接口贩汉,總是從初學(xué)者的角度娓娓道來,至少是本人見過最好的操作系統(tǒng)入門書籍锚赤。各位剛開始時匹舞,一定要細(xì)細(xì)的讀os-dev這本書,然后嘗試跟著本倉庫的節(jié)奏寫程序宴树,出現(xiàn)任何問題策菜,請對照倉庫中現(xiàn)成的程序修改。
以下是@cfenollosa
原文:
How to create an OS from scratch!
I have always wanted to learn how to make an OS from scratch. In college I was taught how to implement advanced features (pagination, semaphores, memory management, etc) but:
- I never got to start from my own boot sector
- College is hard so I don't remember most of it.
- I'm fed up with people who think that reading an already existing kernel, even if small, is a good idea to learn operating systems.
Inspired by this document and the OSDev wiki, I'll try to make short step-by-step READMEs and code samples for anybody to follow. Honestly, this tutorial is basically the first document but split into smaller pieces and without the theory.
Updated: more sources: the little book about OS development, JamesM's kernel development tutorials
Features
- This course is a code tutorial aimed at people who are comfortable with low level computing. For example, programmers who have curiosity on how an OS works but don't have the time or willpower to start reading the Linux kernel top to bottom.
- There is little theory. Yes, this is a feature. Google is your theory lecturer. Once you pass college, excessive theory is worse than no theory because it makes things seem more difficult than they really are.
- The lessons are tiny and may take 5-15 minutes to complete. Trust me and trust yourself. You can do it!
How to use this tutorial
Start with the first folder and go down in order. They build on previous code, so if you jump right to folder 05 and don't know why there is a
mov ah, 0x0e
, it's because you missed lecture 02. Really, just go in order. You can always skip stuff you already know.Open the README and read the first line, which details the concepts you should be familiar with before reading the code. Google concepts you are not familiar with. The second line states the goals for each lesson. Read them, because they explain why we do what we do. The "why" is as important as the "how".
Read the rest of the README. It is very concise.
(Optional) Try to write the code files by yourself after reading the README.
Look at the code examples. They are extremely well commented.
(Optional) Experiment with them and try to break things. The only way to make sure you understood something is trying to break it or replicate it with different commands.
TL;DR: First read the README on each folder, then the code files. If you're brave, try to code them yourself.
Strategy
We will want to do many things with our OS:
- Boot from scratch, without GRUB - DONE!
- Enter 32-bit mode - DONE
- Jump from Assembly to C - DONE!
- Interrupt handling - DONE!
- Screen output and keyboard input - DONE!
- A tiny, basic
libc
which grows to suit our needs - DONE! - Memory management
- Write a filesystem to store files
- Create a very simple shell
- User mode
- Maybe we will write a simple text editor
- Multiple processes and scheduling
Probably we will go through them in that order, however it's soon to tell.
If we feel brave enough:
- A BASIC interpreter, like in the 70s!
- A GUI
- Networking
Contributing
This is a personal learning project, and even though it hasn't been updated for a long time, I still have hopes to get into it at some point.
I'm thankful to all those who have pointed out bugs and submitted pull requests. I will need some time to review everything and I cannot guarantee that at this moment.
Please feel free to fork this repo. If many of you are interested in continuing the project, let me know and I'll link the "main fork" from here.