mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-20 16:07:49 +00:00
Compare commits
9 Commits
28a5eefc91
...
bf1cca4d45
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf1cca4d45 | ||
|
|
4d7b78069f | ||
|
|
56d66b6b24 | ||
|
|
ed38ea1aa0 | ||
|
|
d8204b05cc | ||
|
|
5f00ca206d | ||
|
|
5c3adee95b | ||
|
|
fc8c87bee5 | ||
|
|
e1c58bba97 |
@@ -119,7 +119,7 @@ error: `#[panic_handler]` function required, but not found
|
||||
error: language item required, but not found: `eh_personality`
|
||||
```
|
||||
|
||||
現在編譯氣告訴我們缺少 `#[panic_handler]` 函式以及 _language item_。
|
||||
現在編譯器告訴我們缺少 `#[panic_handler]` 函式以及 _language item_。
|
||||
|
||||
## 實作 panic 處理函式
|
||||
|
||||
@@ -220,9 +220,9 @@ pub extern "C" fn _start() -> ! {
|
||||
}
|
||||
```
|
||||
|
||||
我們使用 `no_mangle` 屬性來停用[名字修飾][name mangling],確保 Rust 編譯器輸出的函式名稱會是 `_start`。沒有這個屬性的話,編譯器會產生符號像是 `_ZN3blog_os4_start7hb173fedf945531caE` 來讓每個函式的名稱都是獨一無二的。我們會需要這項屬性的原因是因為我們接下來希望連結器能夠呼叫入口點函式的名稱。
|
||||
我們使用 `no_mangle` 屬性來停用[名稱重整][name mangling],確保 Rust 編譯器輸出的函式名稱會是 `_start`。沒有這個屬性的話,編譯器會產生符號像是 `_ZN3blog_os4_start7hb173fedf945531caE` 來讓每個函式的名稱都是獨一無二的。我們會需要這項屬性的原因是因為我們接下來希望連結器能夠呼叫入口點函式的名稱。
|
||||
|
||||
我們還將函式標記為 `extern "C"` 來告訴編譯器這個函式應當使用 [C 的調用約定][C calling convention],而不是 Rust 的調用約定。而函式名稱選用 `_start` 的原因是因為這是大多數系統的預設入口點名稱。
|
||||
我們還將函式標記為 `extern "C"` 來告訴編譯器這個函式應當使用 [C 的呼叫慣例][C calling convention],而不是 Rust 的呼叫慣例。而函式名稱選用 `_start` 的原因是因為這是大多數系統的預設入口點名稱。
|
||||
|
||||
[name mangling]: https://en.wikipedia.org/wiki/Name_mangling
|
||||
[C calling convention]: https://en.wikipedia.org/wiki/Calling_convention
|
||||
@@ -511,7 +511,7 @@ cargo rustc -- -C link-args="/ENTRY:_start /SUBSYSTEM:console"
|
||||
cargo rustc -- -C link-args="-e __start -static -nostartfiles"
|
||||
```
|
||||
|
||||
注意這只是最小的 Rust 獨立執行檔範例,它還是會仰賴一些事情發生,像是當 `_start` 函式呼叫時堆疊已經初始化完畢。**所以如果想真的使用這樣的執行檔的話還需要更多步驟。**
|
||||
注意這只是最小的 Rust 獨立執行檔範例,它還是會依賴一些事情,像是當 `_start` 函式呼叫時堆疊已經初始化完畢。**所以如果想真的使用這樣的執行檔的話還需要更多步驟。**
|
||||
|
||||
## 接下來呢?
|
||||
|
||||
|
||||
BIN
scripts/cover.png
Normal file
BIN
scripts/cover.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
30
scripts/create-book.sh
Executable file
30
scripts/create-book.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
# create working dir
|
||||
rm -r book/
|
||||
mkdir book/
|
||||
|
||||
# copy data to working dir
|
||||
cat ../blog/content/edition-2/posts/*/index.md > book/book.md
|
||||
find ../blog/content/edition-2/posts ! -name "*.md" -exec cp -t book/ {} +
|
||||
|
||||
# remove zola metadata
|
||||
sed -i '/^+++/,/^+++/d' book/book.md
|
||||
# remove br in table in 06, pandoc handles the layout
|
||||
sed -i '/<br>/d' book/book.md
|
||||
# details/summary breaks epub layout
|
||||
sed -i '/^<details>/d' book/book.md
|
||||
sed -i '/^<\/details>/d' book/book.md
|
||||
sed -i '/^<summary>/d' book/book.md
|
||||
|
||||
# special fix for linking to different folder
|
||||
sed -i 's|../paging-introduction/||g' book/book.md
|
||||
|
||||
# go to work dir and create epub
|
||||
cd book/
|
||||
pandoc book.md -o "Writing an OS in Rust.epub" --metadata cover-image="../cover.png" --metadata title="Writing an OS in Rust" --metadata author="Philipp Oppermann" --metadata description="This blog series creates a small operating system in the Rust programming language. Each post is a small tutorial and includes all needed code, so you can follow along if you like. The source code is also available in the corresponding Github repository."
|
||||
|
||||
#clean up
|
||||
cd ..
|
||||
mv "book/Writing an OS in Rust.epub" .
|
||||
rm -rf book/
|
||||
Reference in New Issue
Block a user