Chapter 04:Kernel === :::info 本章節著重在一些作業系統的基礎功能實作,以便未來各項功能的開發: &emsp; 1. Makefile &emsp; 2. Print Log &emsp; 3. String Functions ::: >[time=Thu, Sep 18, 2025 4:11 AM] --- https://youtu.be/4bTRb6LhmzQ <iframe width="560" height="315" src="https://www.youtube.com/embed/4bTRb6LhmzQ?si=uyAkXz-WMsJNMlhG" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> >[!Note] 檔案架構 >![截圖 2025-09-18 下午5.12.57](https://hackmd.io/_uploads/BJRVTHtjll.png) # Makefile >Reference: >[Makefile 語法和示範](https://hackmd.io/@sysprog/SySTMXPvl) >[GNU Make Manual](https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents) >[!Tip] makefile 只在意依賴性 >[!Note] 基本語法 >![截圖 2025-09-19 晚上11.46.29](https://hackmd.io/_uploads/SkOxseooee.png) >[!Note] 自動化變數 >$@: 工作目標檔名 $<: 第一個必要條件的檔名 $^: 所有必要條件的檔名,並以空格隔開這些檔名 (這份清單已移除重複的檔名) $*: 工作目標的主檔名 >[!Note] Phony Targets >A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance. >[!Note] 讓 GCC 在編譯時不要去搜尋 /usr/include/ 這個系統預設的標頭路徑 >`-nostdinc` 會告訴 GCC 不要搜尋系統的標準 include 目錄 (/usr/include 等)。 ## Source Code >code/makefile https://github.com/srhuang/a-os/commit/0294be3a99cfb8f038cf610b977e23386d119549 >bochs-2.8/gen.sh ```sh= dd if=../code/out/mbr.bin of=./60mb.img bs=512 count=1 conv=notrunc dd if=../code/out/loader.bin of=./60mb.img bs=512 count=4 seek=1 conv=notrunc dd if=../code/out/kernel.bin of=./60mb.img bs=512 count=200 seek=5 conv=notrunc ``` ## Compile ``` make all ``` ## Put on hard disk ``` sh gen.sh ``` ## Checkpoint >[!Note] code/ >![截圖 2025-09-23 清晨6.47.34](https://hackmd.io/_uploads/B1g4z8J3xx.png) >[!Note] bochs-2.8/ >![截圖 2025-09-20 凌晨12.57.34](https://hackmd.io/_uploads/r1esoWsixg.png) # Print Log >[!Note] pushad >![截圖 2025-09-20 凌晨2.13.28](https://hackmd.io/_uploads/rJ_vpzsjgg.png) >[!Note] ASCII code >![ascii-2-1](https://hackmd.io/_uploads/BJqTXCsoee.png) >![截圖 2025-09-20 晚上10.51.26](https://hackmd.io/_uploads/HJZ61S2jlx.png) >[!Note] Test Flow >![截圖 2025-09-23 凌晨1.39.10](https://hackmd.io/_uploads/ryGJqZy2xx.png) ## Source Code https://github.com/srhuang/a-os/commit/4e0ae405749ffc7408085fef2dc6a09ca9147a84 ## Compile ``` make all ``` ## Put on hard disk ``` sh gen.sh ``` ## Checkpoint ![截圖 2025-09-23 清晨6.31.50](https://hackmd.io/_uploads/BJV5CrJ2xg.png) test_all() ![截圖 2025-09-24 上午9.46.06](https://hackmd.io/_uploads/B1zqppg3le.png) test_cls_screen() ![截圖 2025-09-23 清晨6.21.59](https://hackmd.io/_uploads/BywX3B12lx.png) # String Functions >Reference: >[Linux man page](https://linux.die.net/man/) >[Linux man pages online](https://man7.org/linux/man-pages/index.html) >[!Warning] Linker Order >For static linking, the order of libraries is crucial. >**Symbol Resolution**: The linker resolves undefined symbols. It reads through the object files and libraries from left to right. ## Source Code https://github.com/srhuang/a-os/commit/f1cf679d9234e561d5a1b37432e1da8201084e57 ## Compile ``` make all ``` ## Put on hard disk ``` sh gen.sh ``` ## Checkpoint ![截圖 2025-09-24 上午11.23.55](https://hackmd.io/_uploads/rk9vE1Whxe.png) ![截圖 2025-09-24 上午11.22.40](https://hackmd.io/_uploads/rJfQE1Zhgl.png)