Skip to content

Commit d0c6faa

Browse files
committed
Document the crate and hide certain types in the docs
1 parent e4aded3 commit d0c6faa

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

src/bootinfo/memory_map.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const PAGE_SIZE: u64 = 4096;
55

66
const MAX_MEMORY_MAP_SIZE: usize = 64;
77

8+
/// A map of the physical memory regions of the underlying machine.
89
#[repr(C)]
910
pub struct MemoryMap {
1011
entries: [MemoryRegion; MAX_MEMORY_MAP_SIZE],
@@ -13,6 +14,7 @@ pub struct MemoryMap {
1314
next_entry_index: u64,
1415
}
1516

17+
#[doc(hidden)]
1618
impl MemoryMap {
1719
pub fn new() -> Self {
1820
MemoryMap {
@@ -83,13 +85,17 @@ impl fmt::Debug for MemoryMap {
8385
}
8486
}
8587

88+
/// Represents a region of physical memory.
8689
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8790
#[repr(C)]
8891
pub struct MemoryRegion {
92+
/// The range of frames that belong to the region.
8993
pub range: FrameRange,
94+
/// The type of the region.
9095
pub region_type: MemoryRegionType,
9196
}
9297

98+
#[doc(hidden)]
9399
impl MemoryRegion {
94100
pub fn empty() -> Self {
95101
MemoryRegion {
@@ -102,11 +108,19 @@ impl MemoryRegion {
102108
}
103109
}
104110

111+
/// A range of frames with an exclusive upper bound.
105112
#[derive(Clone, Copy, PartialEq, Eq)]
106113
#[repr(C)]
107114
pub struct FrameRange {
115+
/// The frame _number_ of the first 4KiB frame in the region.
116+
///
117+
/// This convert this frame number to a physical address, multiply it with the
118+
/// page size (4KiB).
108119
pub start_frame_number: u64,
109-
// exclusive
120+
/// The frame _number_ of the first 4KiB frame that does no longer belong to the region.
121+
///
122+
/// This convert this frame number to a physical address, multiply it with the
123+
/// page size (4KiB).
110124
pub end_frame_number: u64,
111125
}
112126

@@ -122,14 +136,17 @@ impl FrameRange {
122136
}
123137
}
124138

139+
/// Returns true if the frame range contains no frames.
125140
pub fn is_empty(&self) -> bool {
126141
self.start_frame_number == self.end_frame_number
127142
}
128143

144+
/// Returns the physical start address of the memory region.
129145
pub fn start_addr(&self) -> u64 {
130146
self.start_frame_number * PAGE_SIZE
131147
}
132148

149+
/// Returns the physical end address of the memory region.
133150
pub fn end_addr(&self) -> u64 {
134151
self.end_frame_number * PAGE_SIZE
135152
}
@@ -146,41 +163,47 @@ impl fmt::Debug for FrameRange {
146163
}
147164
}
148165

166+
/// Represents possible types for memory regions.
149167
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
150168
#[repr(C)]
151169
pub enum MemoryRegionType {
152-
/// free RAM
170+
/// Unused memory, can be freely used by the kernel.
153171
Usable,
154-
/// used RAM
172+
/// Memory that is already in use.
155173
InUse,
156-
/// unusable
174+
/// Memory reserved by the hardware. Not usable.
157175
Reserved,
158176
/// ACPI reclaimable memory
159177
AcpiReclaimable,
160178
/// ACPI NVS memory
161179
AcpiNvs,
162180
/// Area containing bad memory
163181
BadMemory,
164-
/// kernel memory
182+
/// Memory used for loading the kernel.
165183
Kernel,
166-
/// kernel stack memory
184+
/// Memory used for the kernel stack.
167185
KernelStack,
168-
/// memory used by page tables
186+
/// Memory used for creating page tables.
169187
PageTable,
170-
/// memory used by the bootloader
188+
/// Memory used by the bootloader.
171189
Bootloader,
172-
/// frame at address zero
190+
/// Frame at address zero.
173191
///
174192
/// (shouldn't be used because it's easy to make mistakes related to null pointers)
175193
FrameZero,
176-
/// an empty region with size 0
194+
/// An empty region with size 0
177195
Empty,
178-
/// used for storing the boot information
196+
/// Memory used for storing the boot information.
179197
BootInfo,
180-
/// used for storing the supplied package
198+
/// Memory used for storing the supplied package
181199
Package,
200+
/// Additional variant to ensure that we can add more variants in the future without
201+
/// breaking backwards compatibility.
202+
#[doc(hidden)]
203+
NonExhaustive,
182204
}
183205

206+
#[doc(hidden)]
184207
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
185208
#[repr(C)]
186209
pub struct E820MemoryRegion {

src/bootinfo/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1+
//! Provides boot information to the kernel.
2+
13
#![deny(improper_ctypes)]
24

35
pub use self::memory_map::*;
46

57
mod memory_map;
68

9+
/// This structure represents the information that the bootloader passes to the kernel.
10+
///
11+
/// The information is passed as an argument to the entry point:
12+
///
13+
/// ```ignore
14+
/// pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
15+
/// // […]
16+
/// }
17+
/// ```
18+
///
19+
/// Note that no type checking occurs for the entry point function, so be careful to
20+
/// use the correct argument types. To ensure that the entry point function has the correct
21+
/// signature, use the [`entry_point`] macro.
722
#[derive(Debug)]
823
#[repr(C)]
924
pub struct BootInfo {
25+
/// A map of the physical memory regions of the underlying machine.
26+
///
27+
/// The bootloader queries this information from the BIOS/UEFI firmware and translates this
28+
/// information to Rust types. It also marks any memory regions that the bootloader uses in
29+
/// the memory map before passing it to the kernel. Regions marked as usable can be freely
30+
/// used by the kernel.
1031
pub memory_map: MemoryMap,
1132
/// The virtual address of the recursively mapped level 4 page table.
1233
#[cfg(feature = "recursive_page_table")]
@@ -25,7 +46,9 @@ pub struct BootInfo {
2546
}
2647

2748
impl BootInfo {
49+
/// Create a new boot information structure. This function is only for internal purposes.
2850
#[allow(unused_variables)]
51+
#[doc(hidden)]
2952
pub fn new(memory_map: MemoryMap, recursive_page_table_addr: u64, physical_memory_offset: u64) -> Self {
3053
BootInfo {
3154
memory_map,

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
//! This library part of the bootloader allows kernels to retrieve information from the bootloader.
2+
//!
3+
//! To combine your kernel with the bootloader crate you need a tool such
4+
//! as [`bootimage`](https://github.com/rust-osdev/bootimage). See the
5+
//! [_Writing an OS in Rust_](https://os.phil-opp.com/minimal-rust-kernel/#creating-a-bootimage)
6+
//! blog for an explanation.
7+
18
#![no_std]
9+
#![warn(missing_docs)]
210

311
pub use crate::bootinfo::BootInfo;
412

0 commit comments

Comments
 (0)