Chapter 04:Kernel
===
:::info
本章節著重在一些作業系統的基礎功能實作,以便未來各項功能的開發:
  1. Makefile
  2. Print Log
  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] 檔案架構
>
# 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] 基本語法
>
>[!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/
>
>[!Note] bochs-2.8/
>
# Print Log
>[!Note] pushad
>
>[!Note] ASCII code
>
>
>[!Note] Test Flow
>
## Source Code
https://github.com/srhuang/a-os/commit/4e0ae405749ffc7408085fef2dc6a09ca9147a84
## Compile
```
make all
```
## Put on hard disk
```
sh gen.sh
```
## Checkpoint

test_all()

test_cls_screen()

# 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

