Skip to content

Commit 7bfc0d5

Browse files
committed
doc: add documents of some crates
1 parent 16834a5 commit 7bfc0d5

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ name = "page_table_entry"
33
version = "0.1.0"
44
edition = "2021"
55
authors = ["Yuekai Jia <[email protected]>"]
6-
7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
6+
description = "Page table entry definition for various hardware architectures"
7+
license = "GPL-3.0-or-later OR Apache-2.0"
8+
homepage = "https://github.com/rcore-os/arceos"
9+
repository = "https://github.com/rcore-os/arceos/tree/main/crates/page_table_entry"
10+
documentation = "https://rcore-os.github.io/arceos/page_table_entry/index.html"
811

912
[dependencies]
1013
bitflags = "2.1"

src/arch/aarch64.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! AArch64 VMSAv8-64 translation table format descriptors.
2+
13
use core::fmt;
24
use memory_addr::PhysAddr;
35

@@ -135,13 +137,19 @@ impl From<MappingFlags> for DescriptorAttr {
135137
}
136138
}
137139

140+
/// A VMSAv8-64 translation table descriptor.
141+
///
142+
/// Note that the **AttrIndx\[2:0\]** (bit\[4:2\]) field is set to `0` for device
143+
/// memory, and `1` for normal memory. The system must configure the MAIR_ELx
144+
/// system register accordingly.
138145
#[derive(Clone, Copy)]
139146
#[repr(transparent)]
140147
pub struct A64PTE(u64);
141148

142149
impl A64PTE {
143150
const PHYS_ADDR_MASK: usize = 0x0000_ffff_ffff_f000; // bits 12..48
144151

152+
/// Creates an empty descriptor with all bits set to zero.
145153
pub const fn empty() -> Self {
146154
Self(0)
147155
}

src/arch/riscv.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! RISC-V page table entries.
2+
13
use core::fmt;
24
use memory_addr::PhysAddr;
35

@@ -69,7 +71,7 @@ impl From<MappingFlags> for PTEFlags {
6971
}
7072
}
7173

72-
/// Sv39 and Sv48 page table entry.
74+
/// Sv39 and Sv48 page table entry for RV64 systems.
7375
#[derive(Clone, Copy)]
7476
#[repr(transparent)]
7577
pub struct Rv64PTE(u64);

src/arch/x86_64.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
//! x86 page table entries on 64-bit paging.
2+
13
use core::fmt;
24
use memory_addr::PhysAddr;
3-
use x86_64::structures::paging::page_table::PageTableFlags as PTF;
5+
6+
pub use x86_64::structures::paging::page_table::PageTableFlags as PTF;
47

58
use crate::{GenericPTE, MappingFlags};
69

@@ -48,6 +51,7 @@ impl From<MappingFlags> for PTF {
4851
}
4952
}
5053

54+
/// An x86_64 page table entry.
5155
#[derive(Clone, Copy)]
5256
#[repr(transparent)]
5357
pub struct X64PTE(u64);

src/lib.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
//! This crate provides the definition of page table entry for various hardware
2+
//! architectures.
3+
//!
4+
//! Currently supported architectures and page table entry types:
5+
//!
6+
//! - x86: [`x86_64::X64PTE`]
7+
//! - ARM: [`aarch64::A64PTE`]
8+
//! - RISC-V: [`riscv::Rv64PTE`]
9+
//!
10+
//! All these types implement the [`GenericPTE`] trait, which provides unified
11+
//! methods for manipulating various page table entries.
12+
113
#![no_std]
214
#![feature(const_trait_impl)]
315
#![feature(doc_auto_cfg)]
@@ -11,20 +23,30 @@ use memory_addr::PhysAddr;
1123
pub use self::arch::*;
1224

1325
bitflags::bitflags! {
26+
/// Generic page table entry flags that indicate the corresponding mapped
27+
/// memory region permissions and attributes.
1428
#[derive(Debug, Clone, Copy)]
1529
pub struct MappingFlags: usize {
30+
/// The memory is readable.
1631
const READ = 1 << 0;
32+
/// The memory is writable.
1733
const WRITE = 1 << 1;
34+
/// The memory is executable.
1835
const EXECUTE = 1 << 2;
36+
/// The memory is user accessible.
1937
const USER = 1 << 3;
38+
/// The memory is device memory.
2039
const DEVICE = 1 << 4;
2140
}
2241
}
2342

43+
/// A generic page table entry.
44+
///
45+
/// All architecture-specific page table entry types implement this trait.
2446
pub trait GenericPTE: Debug + Clone + Copy + Sync + Send + Sized {
25-
// Create a page table entry point to a terminate page or block.
47+
/// Create a page table entry point to a terminate page or block.
2648
fn new_page(paddr: PhysAddr, flags: MappingFlags, is_huge: bool) -> Self;
27-
// Create a page table entry point to a next level page table.
49+
/// Create a page table entry point to a next level page table.
2850
fn new_table(paddr: PhysAddr) -> Self;
2951

3052
/// Returns the physical address mapped by this entry.

0 commit comments

Comments
 (0)