Compare commits

...

7 Commits

Author SHA1 Message Date
FineFindus
ccc6b002ab Merge 5c3adee95b into 4b023bb432 2024-01-05 18:05:10 +01:00
Philipp Oppermann
4b023bb432 Merge pull request #1262 from acyanbird/main
fix testing and paging introduction chapter errors in zh-CN translation
2024-01-05 18:00:30 +01:00
acyanbird
b1b35833d6 fix zh-CN paging introduction 2024-01-05 16:27:14 +00:00
acyanbird
34120a0409 fix zh-CN testing code err 2024-01-05 16:16:08 +00:00
FineFindus
5c3adee95b feat(epub): use poper file name 2023-08-05 22:16:13 +02:00
FineFindus
fc8c87bee5 feat(epub): add cover image 2023-08-05 22:05:04 +02:00
FineFindus
e1c58bba97 feat: add script to generate epub 2023-08-05 14:38:08 +02:00
4 changed files with 34 additions and 4 deletions

View File

@@ -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() -> ! {

View File

@@ -149,7 +149,7 @@ x86_64 平台使用4级页表页大小为4KiB无论层级每个页表
![Bits 012 are the page offset, bits 1221 the level 1 index, bits 2130 the level 2 index, bits 3039 the level 3 index, and bits 3948 the level 4 index](x86_64-table-indices-from-address.svg)
我们可以看到,每个表索引号占据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比特位必须一同被设置 |
我们可以看到仅1251位会用于存储页帧地址或页表地址其余比特都用于存储标志位或由操作系统自由使用。
其原因就是该地址总是指向一个4096比特对齐的地址、页表或者页帧的起始地址。
其原因就是该地址总是指向一个4096字节对齐的地址、页表或者页帧的起始地址。
这也就意味着0-11位始终为0没有必要存储这些东西硬件层面在使用该地址之前也会将这12位比特设置为052-63位同理因为x86_64平台仅支持52位物理地址类似于上文中提到的仅支持48位虚拟地址的原因
进一步说明一下可用的标志位:

BIN
scripts/cover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

30
scripts/create-book.sh Executable file
View 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/