Skip to content

Commit 82b93e7

Browse files
committed
multiboot2-common: doc improvement with figures
1 parent aadcf8b commit 82b93e7

File tree

7 files changed

+386
-8
lines changed

7 files changed

+386
-8
lines changed

.typos.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[files]
44
extend-exclude = [
5-
# "uefi/src/table/boot.rs"
5+
"*.drawio.xml"
66
]
77

88
[default.extend-words]

multiboot2-common/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55

66
Common helpers for the `multiboot2` and `multiboot2-header` crates.
77

8+
## Architecture
9+
10+
The following figures, not displayable in `lib.rs` / on `docs.rs` unfortunately,
11+
outline the design of this crate:
12+
13+
![Overview Multiboot2 Structures](./overview-multiboot2-structures.drawio.png "Overview Multiboot2 Structures")
14+
15+
Overview of Multiboot2 structures: Multiboot2 boot information, boot
16+
information tags, Multiboot2 headers, and Multiboot2 header tags all share the
17+
same technical foundation: They have a common header and a possible dynamic
18+
size, depending on the header.
19+
20+
![Crate Architecture Overview](./architecture.drawio.png "Crate Architecture Overview")
21+
22+
Overview of how raw bytes are modelled to be representable by high-level rusty
23+
types.
24+
825
## MSRV
926

1027
The MSRV is 1.70.0 stable.
175 KB
Loading

multiboot2-common/architecture.drawio.xml

Lines changed: 217 additions & 0 deletions
Large diffs are not rendered by default.
122 KB
Loading
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" version="24.7.7">
2+
<diagram name="Seite-1" id="t28IrSg9-075dSeR9zn3">
3+
<mxGraphModel dx="989" dy="487" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0" />
6+
<mxCell id="1" parent="0" />
7+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-1" value="" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">
8+
<mxGeometry x="80" y="40" width="140" height="380" as="geometry" />
9+
</mxCell>
10+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-2" value="" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">
11+
<mxGeometry x="240" y="40" width="140" height="380" as="geometry" />
12+
</mxCell>
13+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-4" value="&lt;b&gt;&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; face=&quot;Roboto&quot;&gt;CommandLineTag&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&amp;nbsp;&lt;font color=&quot;#0000cc&quot;&gt;type: u32 = 1&lt;br&gt;&amp;nbsp;size: u32 = 11&lt;/font&gt;&lt;br&gt;&amp;nbsp;str: [u8] = [&lt;br&gt;&amp;nbsp; &#39;h&#39;&lt;br&gt;&amp;nbsp; &#39;i&#39;&lt;br&gt;&amp;nbsp; &#39;\0&#39;&lt;br&gt;&amp;nbsp;]" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;align=left;" vertex="1" parent="1">
14+
<mxGeometry x="90" y="110" width="120" height="130" as="geometry" />
15+
</mxCell>
16+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-7" value="&lt;b&gt;&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; face=&quot;Roboto&quot;&gt;Multiboot2&lt;br&gt;Boot Information&lt;/font&gt;&lt;/b&gt;" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">
17+
<mxGeometry x="80" y="40" width="140" height="40" as="geometry" />
18+
</mxCell>
19+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-8" value="&lt;b&gt;Multiboot2&lt;br&gt;Header&lt;/b&gt;" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">
20+
<mxGeometry x="240" y="40" width="140" height="40" as="geometry" />
21+
</mxCell>
22+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-10" value="size: u32" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;" vertex="1" parent="1">
23+
<mxGeometry x="80" y="80" width="140" height="20" as="geometry" />
24+
</mxCell>
25+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-11" value="size: u32" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;" vertex="1" parent="1">
26+
<mxGeometry x="240" y="80" width="140" height="20" as="geometry" />
27+
</mxCell>
28+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-12" value="&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; face=&quot;Roboto&quot;&gt;Tag X&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&amp;nbsp;&lt;font color=&quot;#0000cc&quot;&gt;type: u32 = x&lt;br&gt;&lt;/font&gt;&lt;div&gt;&lt;font color=&quot;#0000cc&quot;&gt;&amp;nbsp;size: u32 = y&lt;/font&gt;&lt;div&gt;&amp;nbsp;a: u16 = z&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=top;align=left;" vertex="1" parent="1">
29+
<mxGeometry x="90" y="250" width="120" height="70" as="geometry" />
30+
</mxCell>
31+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-14" value="&lt;b&gt;&lt;font face=&quot;Roboto&quot;&gt;InformationReq&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&amp;nbsp;&lt;font color=&quot;#007fff&quot;&gt;type: u16 = 1&lt;br&gt;&amp;nbsp;flags: u16 = 0&lt;br&gt;&amp;nbsp;size: u32 = 11&lt;/font&gt;&lt;br&gt;&amp;nbsp;reqs: [u32] = [&lt;br&gt;&amp;nbsp; 1&lt;br&gt;&amp;nbsp;];" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;align=left;verticalAlign=top;" vertex="1" parent="1">
32+
<mxGeometry x="250" y="110" width="120" height="110" as="geometry" />
33+
</mxCell>
34+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-15" value="&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; face=&quot;Roboto&quot;&gt;Tag Y&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&amp;nbsp;&lt;font color=&quot;#007fff&quot;&gt;type: u16 = x&lt;br&gt;&amp;nbsp;flags: u16 = y&lt;br&gt;&amp;nbsp;size: u32 = z&lt;/font&gt;&lt;br&gt;&amp;nbsp;bar: u64 = x&lt;br&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=top;align=left;" vertex="1" parent="1">
35+
<mxGeometry x="250" y="250" width="120" height="90" as="geometry" />
36+
</mxCell>
37+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-16" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
38+
<mxGeometry x="90" y="390" width="120" height="20" as="geometry" />
39+
</mxCell>
40+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-20" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 2;strokeWidth=2;rounded=0;strokeColor=#FF9999;" edge="1" parent="1">
41+
<mxGeometry width="50" height="50" relative="1" as="geometry">
42+
<mxPoint x="30" y="250" as="sourcePoint" />
43+
<mxPoint x="400" y="250" as="targetPoint" />
44+
</mxGeometry>
45+
</mxCell>
46+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-22" value="&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; style=&quot;font-size: 10px;&quot;&gt;8-byte&lt;br style=&quot;font-size: 10px;&quot;&gt;alignment&lt;/font&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;fontSize=10;fontColor=#FF3333;" vertex="1" parent="1">
47+
<mxGeometry x="10" y="250" width="60" height="30" as="geometry" />
48+
</mxCell>
49+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-23" value="&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; style=&quot;font-size: 10px;&quot;&gt;8-byte&lt;br style=&quot;font-size: 10px;&quot;&gt;alignment&lt;/font&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;fontSize=10;fontColor=#FF3333;" vertex="1" parent="1">
50+
<mxGeometry x="10" y="110" width="60" height="30" as="geometry" />
51+
</mxCell>
52+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-24" value="&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; style=&quot;font-size: 10px;&quot;&gt;8-byte&lt;br style=&quot;font-size: 10px;&quot;&gt;alignment&lt;/font&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;fontSize=10;fontColor=#FF3333;" vertex="1" parent="1">
53+
<mxGeometry x="10" y="40" width="60" height="30" as="geometry" />
54+
</mxCell>
55+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-26" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 2;strokeWidth=2;rounded=0;strokeColor=#FF9999;" edge="1" parent="1">
56+
<mxGeometry width="50" height="50" relative="1" as="geometry">
57+
<mxPoint x="30" y="110" as="sourcePoint" />
58+
<mxPoint x="400" y="110" as="targetPoint" />
59+
</mxGeometry>
60+
</mxCell>
61+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-27" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 2;strokeWidth=2;rounded=0;strokeColor=#FF9999;" edge="1" parent="1">
62+
<mxGeometry width="50" height="50" relative="1" as="geometry">
63+
<mxPoint x="30" y="39.31" as="sourcePoint" />
64+
<mxPoint x="400" y="39.31" as="targetPoint" />
65+
</mxGeometry>
66+
</mxCell>
67+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-28" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 2;strokeWidth=2;rounded=0;strokeColor=#FF9999;" edge="1" parent="1">
68+
<mxGeometry width="50" height="50" relative="1" as="geometry">
69+
<mxPoint x="30" y="420" as="sourcePoint" />
70+
<mxPoint x="400" y="420" as="targetPoint" />
71+
</mxGeometry>
72+
</mxCell>
73+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-29" value="&lt;font data-font-src=&quot;https://fonts.googleapis.com/css?family=Roboto&quot; style=&quot;font-size: 10px;&quot;&gt;8-byte&lt;br style=&quot;font-size: 10px;&quot;&gt;alignment&lt;/font&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;fontSize=10;fontColor=#FF3333;" vertex="1" parent="1">
74+
<mxGeometry x="10" y="390" width="60" height="30" as="geometry" />
75+
</mxCell>
76+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-32" value="Overview of Multiboot2 Structures" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontFamily=Roboto;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DRoboto;fontSize=14;fontStyle=1" vertex="1" parent="1">
77+
<mxGeometry x="80" width="300" height="30" as="geometry" />
78+
</mxCell>
79+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-33" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
80+
<mxGeometry x="250" y="390" width="120" height="20" as="geometry" />
81+
</mxCell>
82+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-34" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
83+
<mxGeometry x="250" y="360" width="120" height="20" as="geometry" />
84+
</mxCell>
85+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-35" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
86+
<mxGeometry x="90" y="360" width="120" height="20" as="geometry" />
87+
</mxCell>
88+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-36" value="&lt;div&gt;&lt;div&gt;&lt;div&gt;...&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
89+
<mxGeometry x="90" y="330" width="120" height="20" as="geometry" />
90+
</mxCell>
91+
<mxCell id="Sv76AHv-8cPqDwbSuwtx-39" value="Padding" style="rounded=0;whiteSpace=wrap;html=1;fontFamily=Source Code Pro;fontSource=https%3A%2F%2Ffonts.googleapis.com%2Fcss%3Ffamily%3DSource%2BCode%2BPro;verticalAlign=middle;align=center;" vertex="1" parent="1">
92+
<mxGeometry x="250" y="230" width="120" height="10" as="geometry" />
93+
</mxCell>
94+
</root>
95+
</mxGraphModel>
96+
</diagram>
97+
</mxfile>

multiboot2-common/src/lib.rs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! - header structure (whole)
1616
//! - header tags
1717
//!
18-
//! # The Problem / Difficulties
18+
//! # Solved Problem & Difficulties Along the Way
1919
//!
2020
//! ## Multiboot2 Structures
2121
//!
@@ -34,15 +34,21 @@
3434
//!
3535
//! Note that these structures can also be nested. So for example, the
3636
//! Multiboot2 boot information contains Multiboot2 tags, and the Multiboot2
37-
//! header contains Multiboot2 header tags - both are itself dynamic structures.
37+
//! header contains Multiboot2 header tags - both are itself **dynamically
38+
//! sized** structures. This means, you can know the size (and amount of
39+
//! elements) **only at runtime!**
3840
//!
3941
//! A final `[u8]` field in the structs is the most rusty way to model this.
4042
//! However, this makes the type a Dynamically Sized Type (DST). To create
4143
//! references to these types from a byte slice, one needs fat pointers. They
4244
//! are a language feature currently not constructable with stable Rust.
4345
//! Luckily, we can utilize [`ptr_meta`].
4446
//!
45-
//! ## Dynamic and Sized Structs
47+
//! Figure 1 in the [README](https://crates.io/crates/multiboot2-common)
48+
//! (currently not embeddable in lib.rs unfortunately) provides an overview of
49+
//! Multiboot2 structures.
50+
//!
51+
//! ## Dynamic and Sized Structs in Rust
4652
//!
4753
//! Note that we also have structures (tags) in Multiboot2 that looks like this:
4854
//!
@@ -68,17 +74,49 @@
6874
//! }
6975
//! ```
7076
//!
71-
//! ## Fat Pointer Requirements
77+
//! ## Chosen Design
78+
//!
79+
//! The overall common abstractions needed to solve the problems mentioned in
80+
//! this section are also mainly influenced by the fact that the `multiboot2`
81+
//! and `multiboot2-header` crates use a **zero-copy** design for parsing
82+
//! the corresponding structures.
83+
//!
84+
//! Further, by having **ABI-compatible types** that fully represent the
85+
//! reality, we can use the same type for parsing **and** for construction,
86+
//! as modelled in the following simplified example:
87+
//!
88+
//! ```rust,ignore
89+
//! /// ABI-compatible tag for parsing.
90+
//! pub struct MemoryMapTag {
91+
//! header: TagHeader,
92+
//! entry_size: u32,
93+
//! entry_version: u32,
94+
//! areas: [MemoryArea],
95+
//! }
96+
//!
97+
//! impl MemoryMapTag {
98+
//! // We can also create an ABI-compatible structure of that type.
99+
//! pub fn new(areas: &[MemoryArea]) -> Box<Self> {
100+
//! // omitted
101+
//! }
102+
//! }
103+
//! ```
104+
//!
105+
//! Hence, the structures can also be build at runtime. This is what we
106+
//! consider **idiomatic and rusty**.
107+
//!
108+
//! ## Creating Fat Pointers with [`ptr_meta`]
72109
//!
73110
//! To create fat pointers with [`ptr_meta`], each tag needs a `Metadata` type
74111
//! which is either `usize` (for DSTs) or `()`. A trait is needed to abstract
75112
//! above sized or unsized types.
76113
//!
77114
//! ## Multiboot2 Requirements
78115
//!
79-
//! All tags must be 8-byte aligned. Space between multiple tags may be
80-
//! filled with zeroes if necessary. These zeroes are not reflected in the
81-
//! previous tag's size.
116+
//! All tags must be 8-byte aligned. The actual payload of tags may be followed
117+
//! by padding zeroes to fill the gap until the next alignment boundary, if
118+
//! necessary. These zeroes are not reflected in the tag's size, but for Rust,
119+
//! must be reflected in the memory allocation size.
82120
//!
83121
//! ## Rustc Requirements
84122
//!
@@ -91,8 +129,15 @@
91129
//!
92130
//! See <https://doc.rust-lang.org/reference/type-layout.html> for information.
93131
//!
132+
//! Further, the [`Layout`]
133+
//!
94134
//! # Provided Abstractions
95135
//!
136+
//! Figure 2 in the [README](https://crates.io/crates/multiboot2-common)
137+
//! (currently not embeddable in lib.rs unfortunately) provides an overview of
138+
//! the parsing of Multiboot2 structures and how the definitions from this
139+
//! crate are used.
140+
//!
96141
//! ## Parsing and Casting
97142
//!
98143
//! First, we need byte slices which are guaranteed to be aligned and are a
@@ -122,6 +167,8 @@
122167
//! # No Public API
123168
//!
124169
//! Not meant as stable public API for others outside Multiboot2.
170+
//!
171+
//! [`Layout`]: core::alloc::Layout
125172
126173
#![no_std]
127174
#![cfg_attr(feature = "unstable", feature(error_in_core))]

0 commit comments

Comments
 (0)