Skip to content

Commit aac1825

Browse files
committed
Document the remaining API items
1 parent 391f743 commit aac1825

File tree

9 files changed

+105
-6
lines changed

9 files changed

+105
-6
lines changed

src/binary/bios/memory_descriptor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ impl LegacyMemoryRegion for E820MemoryRegion {
1818
}
1919
}
2020

21+
/// A physical memory region returned by an `e820` BIOS call.
22+
///
23+
/// See http://wiki.osdev.org/Detecting_Memory_(x86)#Getting_an_E820_Memory_Map for more info.
2124
#[doc(hidden)]
2225
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2326
#[repr(C)]

src/binary/bios/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/// Provides an abstraction type for a BIOS-provided memory region.
12
pub mod memory_descriptor;

src/binary/legacy_memory_region.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub trait LegacyMemoryRegion: Copy + core::fmt::Debug {
1515
fn kind(&self) -> MemoryRegionKind;
1616
}
1717

18+
/// A physical frame allocator based on a BIOS or UEFI provided memory map.
1819
pub struct LegacyFrameAllocator<I, D> {
1920
original: I,
2021
memory_map: I,
@@ -69,10 +70,17 @@ where
6970
}
7071
}
7172

73+
/// Returns the number of memory regions in the underlying memory map.
74+
///
75+
/// The function always returns the same value, i.e. the length doesn't
76+
/// change after calls to `allocate_frame`.
7277
pub fn len(&self) -> usize {
7378
self.original.len()
7479
}
7580

81+
/// Returns the largest detected physical memory address.
82+
///
83+
/// Useful for creating a mapping for all physical memory.
7684
pub fn max_phys_addr(&self) -> PhysAddr {
7785
self.original
7886
.clone()
@@ -84,9 +92,7 @@ where
8492
/// Converts this type to a boot info memory map.
8593
///
8694
/// The memory map is placed in the given `regions` slice. The length of the given slice
87-
/// must be at least the value returned by [`len`]. Be aware that the value returned by
88-
/// `len` might increase by 1 whenever [`allocate_frame`] is called, so the length should be
89-
/// queried as late as possible.
95+
/// must be at least the value returned by [`len`] pluse 1.
9096
///
9197
/// The return slice is a subslice of `regions`, shortened to the actual number of regions.
9298
pub fn construct_memory_map(

src/binary/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ use x86_64::{
1717
PhysAddr, VirtAddr,
1818
};
1919

20+
/// Provides BIOS-specific types and trait implementations.
2021
#[cfg(feature = "bios_bin")]
2122
pub mod bios;
23+
/// Provides UEFI-specific trait implementations.
2224
#[cfg(feature = "uefi_bin")]
23-
pub mod uefi;
25+
mod uefi;
2426

27+
/// Provides a frame allocator based on a BIOS or UEFI memory map.
2528
pub mod legacy_memory_region;
2629
/// Provides a type to keep track of used entries in a level 4 page table.
2730
pub mod level_4_entries;

src/boot_info.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl Into<&'static mut [MemoryRegion]> for MemoryRegions {
102102
}
103103
}
104104

105+
/// A pixel-based framebuffer that controls the screen output.
105106
#[derive(Debug)]
106107
#[repr(C)]
107108
pub struct FrameBuffer {
@@ -111,6 +112,7 @@ pub struct FrameBuffer {
111112
}
112113

113114
impl FrameBuffer {
115+
/// Returns the raw bytes of the framebuffer.
114116
pub fn buffer(&mut self) -> &mut [u8] {
115117
unsafe { self.create_buffer() }
116118
}
@@ -119,28 +121,53 @@ impl FrameBuffer {
119121
unsafe { slice::from_raw_parts_mut(self.buffer_start as *mut u8, self.buffer_byte_len) }
120122
}
121123

124+
/// Returns layout and pixel format information of the framebuffer.
122125
pub fn info(&self) -> FrameBufferInfo {
123126
self.info
124127
}
125128
}
126129

130+
/// Describes the layout and pixel format of a framebuffer.
127131
#[derive(Debug, Clone, Copy)]
128132
#[repr(C)]
129133
pub struct FrameBufferInfo {
134+
/// The total size in bytes.
130135
pub byte_len: usize,
136+
/// The width in pixels.
131137
pub horizontal_resolution: usize,
138+
/// The height in pixels.
132139
pub vertical_resolution: usize,
140+
/// The color format of each pixel.
133141
pub pixel_format: PixelFormat,
142+
/// The number of bytes per pixel.
134143
pub bytes_per_pixel: usize,
144+
/// Number of bytes between the start of a line and the start of the next.
145+
///
146+
/// Some framebuffers use additional padding bytes at the end of a line, so this
147+
/// value might be larger than `horizontal_resolution * bytes_per_pixel`. It is
148+
/// therefore recommended to use this field for calculating the start address of a line.
135149
pub stride: usize,
136150
}
137151

152+
/// Color format of pixels in the framebuffer.
138153
#[derive(Debug, Clone, Copy)]
139154
#[non_exhaustive]
140155
#[repr(C)]
141156
pub enum PixelFormat {
157+
/// One byte red, then one byte green, then one byte blue.
158+
///
159+
/// Length might be larger than 3, check [`bytes_per_pixel`][FrameBufferInfo::bytes_per_pixel]
160+
/// for this.
142161
RGB,
162+
/// One byte blue, then one byte green, then one byte red.
163+
///
164+
/// Length might be larger than 3, check [`bytes_per_pixel`][FrameBufferInfo::bytes_per_pixel]
165+
/// for this.
143166
BGR,
167+
/// A single byte, representing the grayscale value.
168+
///
169+
/// Length might be larger than 1, check [`bytes_per_pixel`][FrameBufferInfo::bytes_per_pixel]
170+
/// for this.
144171
U8,
145172
}
146173

@@ -172,7 +199,9 @@ pub struct TlsTemplate {
172199
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
173200
#[repr(C)]
174201
pub enum Optional<T> {
202+
/// Some value `T`
175203
Some(T),
204+
/// No value
176205
None,
177206
}
178207

src/config.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
1+
/// Allows configuring the bootloader behavior.
2+
///
3+
/// To control these, use a `[package.metadata.bootloader]` table in the `Cargo.toml` of
4+
/// your kernel.
15
#[derive(Debug)]
26
pub struct Config {
7+
/// Whether to create a virtual mapping of the complete physical memory.
8+
///
9+
/// Defaults to `false`.
310
pub map_physical_memory: bool,
4-
pub map_page_table_recursively: bool,
5-
pub kernel_stack_size: Option<u64>,
11+
/// Map the physical memory at a specified virtual address.
12+
///
13+
/// If not given, the bootloader searches for a free virtual address dynamically.
14+
///
15+
/// Only considered if `map_physical_memory` is `true`.
616
pub physical_memory_offset: Option<u64>,
17+
/// Whether to create a recursive entry in the level 4 page table.
18+
///
19+
/// Defaults to `false`.
20+
pub map_page_table_recursively: bool,
21+
/// Create the recursive mapping in at the given entry of the level 4 page table.
22+
///
23+
/// If not given, the bootloader searches for a free level 4 entry dynamically.
24+
///
25+
/// Only considered if `map_page_table_recursively` is `true`.
726
pub recursive_index: Option<u16>,
27+
/// Use the given stack size for the kernel.
28+
///
29+
/// Defaults to at least 80KiB if not given.
30+
pub kernel_stack_size: Option<u64>,
31+
/// Create the kernel stack at the given virtual address.
32+
///
33+
/// Looks for a free virtual memory region dynamically if not given.
834
pub kernel_stack_address: Option<u64>,
35+
/// Create the boot information at the given virtual address.
36+
///
37+
/// Looks for a free virtual memory region dynamically if not given.
938
pub boot_info_address: Option<u64>,
39+
/// Whether to map the framebuffer to virtual memory.
40+
///
41+
/// Defaults to `true`.
1042
pub map_framebuffer: bool,
43+
/// Map the framebuffer memory at the specified virtual address.
44+
///
45+
/// If not given, the bootloader searches for a free virtual memory region dynamically.
46+
///
47+
/// Only considered if `map_framebuffer` is `true`.
1148
pub framebuffer_address: Option<u64>,
1249
}
1350

src/disk_image.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{io, path::Path, process::Command};
22
use thiserror::Error;
33

4+
/// Creates a bootable disk image from the given bootloader executable.
45
pub fn create_disk_image(
56
bootloader_elf_path: &Path,
67
output_bin_path: &Path,

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,25 @@
1515

1616
pub use crate::boot_info::BootInfo;
1717

18+
/// Configuration options for the bootloader.
1819
pub mod config;
1920

21+
/// Contains the boot information struct sent by the bootloader to the kernel on startup.
2022
pub mod boot_info;
23+
/// Provides a memory region type that is used in the memory map of the boot info structure.
2124
pub mod memory_region;
2225

26+
/// Contains the actual bootloader implementation ("bootloader as a binary").
27+
///
28+
/// Useful for reusing part of the bootloader implementation for other crates.
29+
///
30+
/// Only available when the `binary` feature is enabled.
2331
#[cfg(feature = "binary")]
2432
pub mod binary;
2533

34+
/// Provides a function to turn a bootloader executable into a disk image.
35+
///
36+
/// Used by the `builder` binary. Only available when the `builder` feature is enabled.
2637
#[cfg(feature = "builder")]
2738
pub mod disk_image;
2839

src/memory_region.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
/// Represent a physical memory region.
12
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
23
#[repr(C)]
34
pub struct MemoryRegion {
5+
/// The physical start address of the region.
46
pub start: u64,
7+
/// The physical end address (exclusive) of the region.
58
pub end: u64,
9+
/// The memory type of the memory region.
10+
///
11+
/// Only [`Usable`][MemoryRegionKind::Usable] regions can be freely used.
612
pub kind: MemoryRegionKind,
713
}
814

915
impl MemoryRegion {
16+
/// Creates a new empty memory region (with length 0).
1017
pub const fn empty() -> Self {
1118
MemoryRegion {
1219
start: 0,
@@ -16,6 +23,7 @@ impl MemoryRegion {
1623
}
1724
}
1825

26+
/// Represents the different types of memory.
1927
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2028
#[non_exhaustive]
2129
#[repr(C)]

0 commit comments

Comments
 (0)