mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Compare commits
7 Commits
f4bdfb24fd
...
ccc6b002ab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccc6b002ab | ||
|
|
4b023bb432 | ||
|
|
b1b35833d6 | ||
|
|
34120a0409 | ||
|
|
5c3adee95b | ||
|
|
fc8c87bee5 | ||
|
|
e1c58bba97 |
@@ -989,7 +989,7 @@ harness = false
|
||||
#![no_main]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use blog_os::{QemuExitCode, exit_qemu, serial_println};
|
||||
use blog_os::{QemuExitCode, exit_qemu, serial_println, serial_print};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
|
||||
@@ -149,7 +149,7 @@ x86_64 平台使用4级页表,页大小为4KiB,无论层级,每个页表
|
||||
|
||||

|
||||
|
||||
我们可以看到,每个表索引号占据9个字节,这当然是有道理的,每个表都有 2^9 = 512 个条目,低12位用来表示内存页的偏移量(2^12 bytes = 4KiB,而上文提到页大小为4KiB)。第48-64位毫无用处,这也就意味着 x86_64 并非真正的64位,因为它实际上支持48位地址。
|
||||
我们可以看到,每个表索引号占据 9 个比特,这当然是有道理的,每个表都有 2^9 = 512 个条目,低12位用来表示内存页的偏移量(2^12 bytes = 4KiB,而上文提到页大小为4KiB)。第 48-64 位毫无用处,这也就意味着 x86_64 并非真正的 64 位,因为它实际上支持 48 位地址。
|
||||
|
||||
[5-level page table]: https://en.wikipedia.org/wiki/Intel_5-level_paging
|
||||
|
||||
@@ -191,7 +191,7 @@ x86_64 平台使用4级页表,页大小为4KiB,无论层级,每个页表
|
||||
- 1个4级页表
|
||||
- 512个3级页表(因为4级页表可以有512个条目)
|
||||
- 512*512个2级页表(因为每个3级页表可以有512个条目)
|
||||
- 512*512*512个1级页表(因为每个2级页表可以有512个条目)
|
||||
- 512\*512\*512个1级页表(因为每个2级页表可以有512个条目)
|
||||
|
||||
### 页表格式
|
||||
|
||||
@@ -225,7 +225,7 @@ pub struct PageTable {
|
||||
| 63 | no execute | 禁止在该页中运行代码(EFER寄存器中的NXE比特位必须一同被设置) |
|
||||
|
||||
我们可以看到,仅12–51位会用于存储页帧地址或页表地址,其余比特都用于存储标志位,或由操作系统自由使用。
|
||||
其原因就是,该地址总是指向一个4096比特对齐的地址、页表或者页帧的起始地址。
|
||||
其原因就是,该地址总是指向一个4096字节对齐的地址、页表或者页帧的起始地址。
|
||||
这也就意味着0-11位始终为0,没有必要存储这些东西,硬件层面在使用该地址之前,也会将这12位比特设置为0,52-63位同理,因为x86_64平台仅支持52位物理地址(类似于上文中提到的仅支持48位虚拟地址的原因)。
|
||||
|
||||
进一步说明一下可用的标志位:
|
||||
|
||||
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