|
9 | 9 | #![allow(rustdoc::private_doc_tests)] |
10 | 10 | // --- END STYLE CHECKS --- |
11 | 11 |
|
12 | | -//! Library that helps you to parse the multiboot information structure (mbi) from |
| 12 | +//! Library that assists parsing the Multiboot2 Information Structure (MBI) from |
13 | 13 | //! Multiboot2-compliant bootloaders, like GRUB. It supports all tags from the specification |
14 | 14 | //! including full support for the sections of ELF-64. This library is `no_std` and can be |
15 | 15 | //! used in a Multiboot2-kernel. |
@@ -139,6 +139,42 @@ pub enum MbiLoadError { |
139 | 139 | #[cfg(feature = "unstable")] |
140 | 140 | impl core::error::Error for MbiLoadError {} |
141 | 141 |
|
| 142 | +#[repr(C, align(8))] |
| 143 | +struct BootInformationInner { |
| 144 | + total_size: u32, |
| 145 | + _reserved: u32, |
| 146 | + // followed by various, dynamically sized multiboot2 tags |
| 147 | + tags: [Tag; 0], |
| 148 | +} |
| 149 | + |
| 150 | +impl BootInformationInner { |
| 151 | + #[cfg(feature = "builder")] |
| 152 | + fn new(total_size: u32) -> Self { |
| 153 | + Self { |
| 154 | + total_size, |
| 155 | + _reserved: 0, |
| 156 | + tags: [], |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + fn has_valid_end_tag(&self) -> bool { |
| 161 | + let end_tag_prototype = EndTag::default(); |
| 162 | + |
| 163 | + let self_ptr = self as *const _; |
| 164 | + let end_tag_addr = self_ptr as usize + (self.total_size - end_tag_prototype.size) as usize; |
| 165 | + let end_tag = unsafe { &*(end_tag_addr as *const Tag) }; |
| 166 | + |
| 167 | + end_tag.typ == end_tag_prototype.typ && end_tag.size == end_tag_prototype.size |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +#[cfg(feature = "builder")] |
| 172 | +impl StructAsBytes for BootInformationInner { |
| 173 | + fn byte_size(&self) -> usize { |
| 174 | + core::mem::size_of::<Self>() |
| 175 | + } |
| 176 | +} |
| 177 | + |
142 | 178 | /// A Multiboot 2 Boot Information (MBI) accessor. |
143 | 179 | #[repr(transparent)] |
144 | 180 | pub struct BootInformation<'a>(&'a BootInformationInner); |
@@ -191,35 +227,7 @@ impl BootInformation<'_> { |
191 | 227 |
|
192 | 228 | Ok(Self(mbi)) |
193 | 229 | } |
194 | | -} |
195 | | - |
196 | | -#[repr(C, align(8))] |
197 | | -struct BootInformationInner { |
198 | | - total_size: u32, |
199 | | - _reserved: u32, |
200 | | - // followed by various, dynamically sized multiboot2 tags |
201 | | - tags: [Tag; 0], |
202 | | -} |
203 | | - |
204 | | -impl BootInformationInner { |
205 | | - #[cfg(feature = "builder")] |
206 | | - fn new(total_size: u32) -> Self { |
207 | | - Self { |
208 | | - total_size, |
209 | | - _reserved: 0, |
210 | | - tags: [], |
211 | | - } |
212 | | - } |
213 | | -} |
214 | | - |
215 | | -#[cfg(feature = "builder")] |
216 | | -impl StructAsBytes for BootInformationInner { |
217 | | - fn byte_size(&self) -> usize { |
218 | | - core::mem::size_of::<Self>() |
219 | | - } |
220 | | -} |
221 | 230 |
|
222 | | -impl BootInformation<'_> { |
223 | 231 | /// Get the start address of the boot info. |
224 | 232 | pub fn start_address(&self) -> usize { |
225 | 233 | core::ptr::addr_of!(*self.0) as usize |
@@ -438,18 +446,6 @@ impl BootInformation<'_> { |
438 | 446 | } |
439 | 447 | } |
440 | 448 |
|
441 | | -impl BootInformationInner { |
442 | | - fn has_valid_end_tag(&self) -> bool { |
443 | | - let end_tag_prototype = EndTag::default(); |
444 | | - |
445 | | - let self_ptr = self as *const _; |
446 | | - let end_tag_addr = self_ptr as usize + (self.total_size - end_tag_prototype.size) as usize; |
447 | | - let end_tag = unsafe { &*(end_tag_addr as *const Tag) }; |
448 | | - |
449 | | - end_tag.typ == end_tag_prototype.typ && end_tag.size == end_tag_prototype.size |
450 | | - } |
451 | | -} |
452 | | - |
453 | 449 | // SAFETY: BootInformation contains a const ptr to memory that is never mutated. |
454 | 450 | // Sending this pointer to other threads is sound. |
455 | 451 | unsafe impl Send for BootInformation<'_> {} |
|
0 commit comments