Skip to content

Commit 3029ef0

Browse files
authoredAug 24, 2024··
Merge pull request #228 from rust-osdev/doc
doc: add figures and better discuss chosen design
2 parents aadcf8b + cb3f83c commit 3029ef0

25 files changed

+503
-72
lines changed
 

‎.typos.toml

+1-1
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]

‎CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Please see:
2+
3+
- [multiboot2/CHANGELOG.md](multiboot2/CHANGELOG.md)
4+
- [multiboot2-header/CHANGELOG.md](multiboot2-header/CHANGELOG.md)
5+
- [multiboot2-common/CHANGELOG.md](multiboot2-common/CHANGELOG.md)

‎Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ exclude = [
1313
bitflags = "2.6.0"
1414
derive_more = { version = "~0.99.18", default-features = false, features = ["display"] }
1515
log = { version = "~0.4", default-features = false }
16+
multiboot2 = { version = "0.22.2", default-features = false }
17+
multiboot2-common = { version = "0.1.2", default-features = false }
1618
ptr_meta = { version = "~0.2", default-features = false }
1719

1820
# This way, the corresponding crate dependency can be normalley referenced by
@@ -21,3 +23,4 @@ ptr_meta = { version = "~0.2", default-features = false }
2123
[patch.crates-io]
2224
multiboot2 = { path = "multiboot2" }
2325
multiboot2-common = { path = "multiboot2-common" }
26+
multiboot2-header = { path = "multiboot2-header" }

‎Changelog.md

-3
This file was deleted.

‎README.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
# Multiboot2: MBI + Header
1+
# Rusty Wrappers for Multiboot2
22

3-
This repository contains the crates `multiboot2` and `multiboot2-header`.
4-
Please check their individual README-files ([multiboot2](multiboot2/README.md),
5-
[multiboot2-header](multiboot2-header/README.md)).
3+
## Repository Overview
64

7-
The `multiboot2` crate helps to parse the Multiboot2 information structure
8-
(MBI) and is relevant in kernels, that get booted by a bootloader such as
9-
GRUB, for example. `multiboot2-header` helps you to either build
10-
Multiboot2-headers yourself, or to parse Multiboot2 headers in custom bootloader
11-
or similar applications.
5+
- [`multiboot2`](./multiboot2/README.md)
6+
- [`multiboot2-header`](./multiboot2-header/README.md)
7+
- [`multiboot2-common`](./multiboot2-common/README.md)
128

139
## License
1410

@@ -22,6 +18,6 @@ at your option.
2218

2319
### Contribution
2420

25-
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the
26-
work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
27-
additional terms or conditions.
21+
Unless you explicitly state otherwise, any contribution intentionally submitted
22+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
23+
dual licensed as above, without any additional terms or conditions.

‎integration-test/bins/Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎multiboot2-common/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog for Crate `multiboot2-common`
2+
3+
## v0.1.2 (2024-08-24)
4+
5+
- Documentation improvements
6+
-
7+
8+
## 0.1.0 / 0.1.1 (2024-08-20)
9+
10+
Initial release.

‎multiboot2-common/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "multiboot2-common"
33
description = """
44
Common helpers for the `multiboot2` and `multiboot2-header` crates.
55
"""
6-
version = "0.1.1"
6+
version = "0.1.2"
77
authors = [
88
"Philipp Schuster <phip1611@gmail.com>"
99
]

‎multiboot2-common/Changelog.md

-5
This file was deleted.

‎multiboot2-common/README.md

+17
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
23+
ABI-compatible rusty types.
24+
825
## MSRV
926

1027
The MSRV is 1.70.0 stable.
183 KB
Loading

‎multiboot2-common/architecture.drawio.xml

+217
Large diffs are not rendered by default.
Loading
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

+81-17
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
//! - header structure (whole)
1616
//! - header tags
1717
//!
18-
//! # The Problem / Difficulties
18+
//! # Solved Problem & Difficulties Along the Way
19+
//!
20+
//! Firstly, the design choice to have ABI-compatible rusty types influenced the
21+
//! requirements and difficulties along the way. They, on the other side,
22+
//! influenced the design. The outcome is what we perceive as the optimal rusty
23+
//! and convenient solution.
1924
//!
2025
//! ## Multiboot2 Structures
2126
//!
@@ -34,15 +39,21 @@
3439
//!
3540
//! Note that these structures can also be nested. So for example, the
3641
//! Multiboot2 boot information contains Multiboot2 tags, and the Multiboot2
37-
//! header contains Multiboot2 header tags - both are itself dynamic structures.
42+
//! header contains Multiboot2 header tags - both are itself **dynamically
43+
//! sized** structures. This means, you can know the size (and amount of
44+
//! elements) **only at runtime!**
3845
//!
3946
//! A final `[u8]` field in the structs is the most rusty way to model this.
4047
//! However, this makes the type a Dynamically Sized Type (DST). To create
4148
//! references to these types from a byte slice, one needs fat pointers. They
4249
//! are a language feature currently not constructable with stable Rust.
4350
//! Luckily, we can utilize [`ptr_meta`].
4451
//!
45-
//! ## Dynamic and Sized Structs
52+
//! Figure 1 in the [README](https://crates.io/crates/multiboot2-common)
53+
//! (currently not embeddable in lib.rs unfortunately) provides an overview of
54+
//! Multiboot2 structures.
55+
//!
56+
//! ## Dynamic and Sized Structs in Rust
4657
//!
4758
//! Note that we also have structures (tags) in Multiboot2 that looks like this:
4859
//!
@@ -68,30 +79,74 @@
6879
//! }
6980
//! ```
7081
//!
71-
//! ## Fat Pointer Requirements
82+
//! ## Chosen Design
83+
//!
84+
//! The overall common abstractions needed to solve the problems mentioned in
85+
//! this section are also mainly influenced by the fact that the `multiboot2`
86+
//! and `multiboot2-header` crates use a **zero-copy** design for parsing
87+
//! the corresponding structures.
88+
//!
89+
//! Further, by having **ABI-compatible types** that fully represent the
90+
//! reality, we can use the same type for parsing **and** for construction,
91+
//! as modelled in the following simplified example:
92+
//!
93+
//! ```rust,ignore
94+
//! /// ABI-compatible tag for parsing.
95+
//! pub struct MemoryMapTag {
96+
//! header: TagHeader,
97+
//! entry_size: u32,
98+
//! entry_version: u32,
99+
//! areas: [MemoryArea],
100+
//! }
101+
//!
102+
//! impl MemoryMapTag {
103+
//! // We can also create an ABI-compatible structure of that type.
104+
//! pub fn new(areas: &[MemoryArea]) -> Box<Self> {
105+
//! // omitted
106+
//! }
107+
//! }
108+
//! ```
109+
//!
110+
//! Hence, the structures can also be build at runtime. This is what we
111+
//! consider **idiomatic and rusty**.
112+
//!
113+
//! ## Creating Fat Pointers with [`ptr_meta`]
72114
//!
73115
//! To create fat pointers with [`ptr_meta`], each tag needs a `Metadata` type
74116
//! which is either `usize` (for DSTs) or `()`. A trait is needed to abstract
75117
//! above sized or unsized types.
76118
//!
77119
//! ## Multiboot2 Requirements
78120
//!
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.
121+
//! All tags must be 8-byte aligned. The actual payload of tags may be followed
122+
//! by padding zeroes to fill the gap until the next alignment boundary, if
123+
//! necessary. These zeroes are not reflected in the tag's size, but for Rust,
124+
//! must be reflected in the memory allocation size.
82125
//!
83126
//! ## Rustc Requirements
84127
//!
85-
//! The allocation space that Rust requires for types is a multiple of the
128+
//! The required allocation space that Rust uses for types is a multiple of the
86129
//! alignment. This means that if we cast between byte slices and specific
87-
//! types, Rust doesn't just see the size reported by the header but also
88-
//! any necessary padding bytes. If this is not the case, for example we
89-
//! cast to a structure from a `&[u8; 15]`, Miri will complain as it expects
90-
//! `&[u8; 16]`
130+
//! types, Rust doesn't just see the "trimmed down actual payload" defined by
131+
//! struct members, but also any necessary, but hidden, padding bytes. If we
132+
//! don't guarantee the correct is not the case, for example we cast the bytes
133+
//! from a `&[u8; 15]` to an 8-byte aligned struct, Miri will complain as it
134+
//! expects `&[u8; 16]`.
91135
//!
92136
//! See <https://doc.rust-lang.org/reference/type-layout.html> for information.
93137
//!
94-
//! # Provided Abstractions
138+
//! Further, this also means that we can't cast references to smaller structs
139+
//! to bigger ones. Also, once we construct a `Box` on the heap and construct
140+
//! it using the [`new_boxed`] helper, we must ensure that the default
141+
//! [`Layout`] for the underlying type equals the one we manually used for the
142+
//! allocation.
143+
//!
144+
//! # Architecture & Provided Abstractions
145+
//!
146+
//! Figure 2 in the [README](https://crates.io/crates/multiboot2-common)
147+
//! (currently not embeddable in lib.rs unfortunately) provides an overview of
148+
//! the parsing of Multiboot2 structures and how the definitions from this
149+
//! crate are used.
95150
//!
96151
//! ## Parsing and Casting
97152
//!
@@ -122,6 +177,8 @@
122177
//! # No Public API
123178
//!
124179
//! Not meant as stable public API for others outside Multiboot2.
180+
//!
181+
//! [`Layout`]: core::alloc::Layout
125182
126183
#![no_std]
127184
#![cfg_attr(feature = "unstable", feature(error_in_core))]
@@ -270,10 +327,17 @@ impl<H: Header> DynSizedStructure<H> {
270327
&self.payload
271328
}
272329

273-
/// Casts the structure tag to a specific [`MaybeDynSized`] implementation which
274-
/// may be a ZST or DST typed tag. The output type will have the exact same
275-
/// size as `*self`. The target type must be sufficient for that. If not,
276-
/// the function will panic.
330+
/// Performs a memory-safe same-size cast from the base-structure to a
331+
/// specific [`MaybeDynSized`]. The idea here is to cast the generic
332+
/// mostly semantic-free version to a specific type with fields that have
333+
/// a semantic.
334+
///
335+
/// The provided `T` of type [`MaybeDynSized`] might be may be sized type
336+
/// or DST. This depends on the type.
337+
///
338+
/// # Panic
339+
/// Panics if base assumptions are violated. For example, the
340+
/// `T` of type [`MaybeDynSized`] must allow a proper casting to it.
277341
///
278342
/// # Safety
279343
/// This function is safe due to various sanity checks and the overall

‎multiboot2-common/src/tag.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use ptr_meta::Pointee;
1010
/// [`DynSizedStructure::cast`].
1111
///
1212
/// Structs that are a DST must provide a **correct**
13-
/// [`MaybeDynSized::dst_len`] implementation.
13+
/// [`MaybeDynSized::dst_len`] implementation. Further, implementors **must**
14+
/// use `#[repr(C)]`.
1415
///
1516
/// [`ID`]: Tag::ID
1617
/// [`DynSizedStructure`]: crate::DynSizedStructure

‎multiboot2-header/Changelog.md renamed to ‎multiboot2-header/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# CHANGELOG for crate `multiboot2-header`
1+
# Changelog for Crate `multiboot2-header`
2+
3+
## v0.5.1 (2024-08-24)
4+
5+
- Documentation improvements
26

37
## v0.5.0 (2024-05-20)
48

‎multiboot2-header/Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[package]
22
name = "multiboot2-header"
33
description = """
4-
Library with type definitions and parsing functions for Multiboot2 headers.
5-
This library is `no_std` and can be used in bootloaders.
4+
Convenient and safe parsing of Multiboot2 Header structures and the
5+
contained header tags. Usable in no_std environments, such as a
6+
bootloader. An optional builder feature also allows the construction of
7+
the corresponding structures.
68
"""
7-
version = "0.5.0"
9+
version = "0.5.1"
810
authors = [
911
"Philipp Schuster <phip1611@gmail.com>"
1012
]
@@ -43,9 +45,9 @@ unstable = []
4345
[dependencies]
4446
derive_more.workspace = true
4547
log.workspace = true
48+
multiboot2-common.workspace = true
49+
multiboot2.workspace = true
4650
ptr_meta.workspace = true
47-
multiboot2 = { version = "0.22.1", default-features = false }
48-
multiboot2-common = "0.1.1"
4951

5052
[package.metadata.docs.rs]
5153
all-features = true

‎multiboot2-header/README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44
[![crates.io](https://img.shields.io/crates/v/multiboot2-header.svg)](https://crates.io/crates/multiboot2-header)
55
[![docs](https://docs.rs/multiboot2-header/badge.svg)](https://docs.rs/multiboot2-header/)
66

7-
Rust library with type definitions and parsing functions for Multiboot2 headers,
8-
as well as a builder to build them at runtime. This library is `no_std` and can
9-
be used in bootloaders.
7+
Convenient and safe parsing of Multiboot2 Header structures and the
8+
contained header tags. Usable in `no_std` environments, such as a
9+
bootloader. An optional `builder` feature also allows the construction of
10+
the corresponding structures.
11+
12+
## Design
13+
14+
For every Multiboot2 header structure, there is an ABI-compatible rusty type.
15+
This enables a zero-copying parsing design while also enabling the creation of
16+
these structures via convenient constructors for the corresponding types.
17+
18+
## Use-Cases
1019

1120
What this library is good for:
1221

‎multiboot2-header/src/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
//! Rust library with type definitions and parsing functions for Multiboot2
2-
//! headers, as well as a builder to build them at runtime. This library is
3-
//! `no_std` and can be used in bootloaders.
1+
//! Convenient and safe parsing of Multiboot2 Header structures and the
2+
//! contained header tags. Usable in `no_std` environments, such as a
3+
//! bootloader. An optional builder feature also allows the construction of
4+
//! the corresponding structures.
5+
//!
6+
//! ## Design
7+
//!
8+
//! For every Multiboot2 header structure, there is an ABI-compatible rusty type.
9+
//! This enables a zero-copying parsing design while also enabling the creation
10+
//! of these structures via convenient constructors on the corresponding types.
411
//!
512
//! # Example: Parsing a Header
613
//!

‎multiboot2/Changelog.md renamed to ‎multiboot2/CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# CHANGELOG for crate `multiboot2`
1+
# Changelog for Crate `multiboot2`
22

3-
## Unreleased
3+
## v0.22.2 (2024-08-24)
44

5+
- Documentation improvements
56
- Improve debug formatting for EFIMemoryMapTag
67

78
## v0.22.1 (2024-08-20)

‎multiboot2/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ structures and the contained information tags. Usable in `no_std` environments,
66
such as a kernel. An optional builder feature also allows the construction of
77
the corresponding structures.
88
"""
9-
version = "0.22.1"
9+
version = "0.22.2"
1010
authors = [
1111
"Philipp Oppermann <dev@phil-opp.com>",
1212
"Calvin Lee <cyrus296@gmail.com>",
@@ -46,8 +46,7 @@ bitflags.workspace = true
4646
derive_more.workspace = true
4747
log.workspace = true
4848
ptr_meta.workspace = true
49-
multiboot2-common = { version = "0.1.1", default-features = false }
50-
49+
multiboot2-common.workspace = true
5150
# We only use a very basic type definition from this crate. To prevent MSRV
5251
# bumps from uefi-raw, I restrict this here. Upstream users are likely to have
5352
# two versions of this library in it, which is no problem, as we only use the

‎multiboot2/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55

66
Convenient and safe parsing of Multiboot2 Boot Information (MBI)
77
structures and the contained information tags. Usable in `no_std` environments,
8-
such as a kernel. An optional builder feature also allows the construction of
8+
such as a kernel. An optional `builder` feature also allows the construction of
99
the corresponding structures.
1010

1111
It follows the Multiboot 2.0 specification
1212
at https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html and the
1313
ELF 64 specification at http://www.uclibc.org/docs/elf-64-gen.pdf.
1414

15+
## Design
16+
17+
For every Multiboot2 structure, there is an ABI-compatible rusty type. This
18+
enables a zero-copying parsing design while also enabling the creation of these
19+
structures via convenient constructors on the corresponding types.
20+
1521
## Features and `no_std` Compatibility
1622

1723
This library is always `no_std` without `alloc`. However, the default `builder`-

‎multiboot2/src/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
#![deny(rustdoc::all)]
1818
// --- END STYLE CHECKS ---
1919

20-
//! Library that assists parsing the Multiboot2 Information Structure (MBI) from
21-
//! Multiboot2-compliant bootloaders, such as GRUB. It supports all tags from the
22-
//! specification including full support for the sections of ELF files. This library
23-
//! is `no_std` and can be used in a Multiboot2-kernel.
20+
//! Convenient and safe parsing of Multiboot2 Boot Information (MBI) structures
21+
//! and the contained information tags. Usable in `no_std` environments, such as
22+
//! a kernel. An optional builder feature also allows the construction of
23+
//! the corresponding structures.
2424
//!
25-
//! The GNU Multiboot(2) specification aims to provide a standardised
26-
//! method of sharing commonly used information about the host machine at
27-
//! boot time and give the payload, i.e. a kernel, a well defined machine
28-
//! state.
25+
//! ## Design
26+
//!
27+
//! For every Multiboot2 structure, there is an ABI-compatible rusty type. This
28+
//! enables a zero-copying parsing design while also enabling the creation of
29+
//! these structures via convenient constructors on the corresponding types.
2930
//!
3031
//! ## Example
3132
//!

0 commit comments

Comments
 (0)
Please sign in to comment.