Skip to content

Add a builder to multiboot2 #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
152c985
multiboot2: Add basic information builder
YtvwlD Mar 6, 2023
544e1ca
multiboot2: Implement setting the command line
YtvwlD Mar 6, 2023
535c9e7
multiboot2: Implement adding module tags
YtvwlD Mar 7, 2023
41428fb
multiboot2: Implement setting ELF section tag
YtvwlD Mar 7, 2023
08df6c2
multiboot2: Implement setting boot loader name
YtvwlD Mar 7, 2023
bb21998
multiboot2: Implement setting the framebuffer tag
YtvwlD Mar 8, 2023
0320148
multiboot2: Implement setting the BasicMemoryInfoTag
YtvwlD Mar 8, 2023
d198dce
multiboot2: Implement setting memory map tag
YtvwlD Mar 8, 2023
122fc9c
multiboot2: Implement building the multiboot2 information
YtvwlD Mar 8, 2023
6379b42
multiboot2: Implement Debug and PartialEq for packed structs
YtvwlD Mar 14, 2023
d5e99f7
multiboot2: Support passing the EFI System Table
YtvwlD Mar 27, 2023
888dd27
multiboot2: Allow setting the SMBIOS tag
YtvwlD Mar 28, 2023
79646bb
multiboot2: Allow setting the RSDP tags
YtvwlD Mar 28, 2023
690c84a
multiboot2: Support setting the EFI memory map tag
YtvwlD Apr 3, 2023
12f4642
multiboot2: Support setting Boot Services not exited tag
YtvwlD Apr 3, 2023
ed316cb
multiboot2: Support setting the image handle pointer
YtvwlD Apr 4, 2023
cbc47ab
multiboot2: Support setting the image load address
YtvwlD Apr 4, 2023
2f2a058
multiboot2: Improve builder test
YtvwlD Jun 4, 2023
09de523
multiboot2-header: Improve builder test
YtvwlD Jun 4, 2023
69630b3
multiboot2: Don't require an offset for the ELF sections
YtvwlD Jun 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
multiboot2: Add basic information builder
  • Loading branch information
YtvwlD committed May 26, 2023
commit 152c9855914ab8e87f0fa4c7fa6075749f68140f
5 changes: 4 additions & 1 deletion multiboot2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ repository = "https://github.com/rust-osdev/multiboot2"
documentation = "https://docs.rs/multiboot2"

[features]
default = []
# by default, builder is included
default = ["builder"]
std = []
builder = ["std"]
# Nightly-only features that will eventually be stabilized.
unstable = []

Expand Down
16 changes: 16 additions & 0 deletions multiboot2/src/builder/information.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Exports item [`Multiboot2InformationBuilder`].
use crate::{builder::traits::StructAsBytes, CommandLineTag};

use alloc::boxed::Box;

/// Builder to construct a valid Multiboot2 information dynamically at runtime.
/// The tags will appear in the order of their corresponding enumeration,
/// except for the END tag.
#[derive(Debug)]
pub struct Multiboot2InformationBuilder {}

impl Multiboot2InformationBuilder {
pub const fn new() -> Self {
Self {}
}
}
6 changes: 6 additions & 0 deletions multiboot2/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Module for the builder-feature.

mod information;
pub(self) mod traits;

pub use information::Multiboot2InformationBuilder;
30 changes: 30 additions & 0 deletions multiboot2/src/builder/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Module for the helper trait [`StructAsBytes`].

use core::mem::size_of;

/// Trait for all tags that helps to create a byte array from the tag.
/// Useful in builders to construct a byte vector that
/// represents the Multiboot2 information with all its tags.
pub(crate) trait StructAsBytes: Sized {
/// Returns the size in bytes of the struct, as known during compile
/// time. This doesn't use read the "size" field of tags.
fn byte_size(&self) -> usize {
size_of::<Self>()
}

/// Returns a byte pointer to the begin of the struct.
fn as_ptr(&self) -> *const u8 {
self as *const Self as *const u8
}

/// Returns the structure as a vector of its bytes.
/// The length is determined by [`Self::byte_size`].
fn struct_as_bytes(&self) -> alloc::vec::Vec<u8> {
let ptr = self.as_ptr();
let mut vec = alloc::vec::Vec::with_capacity(self.byte_size());
for i in 0..self.byte_size() {
vec.push(unsafe { *ptr.add(i) })
}
vec
}
}
6 changes: 6 additions & 0 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
//! ## MSRV
//! The MSRV is 1.56.1 stable.

#[cfg(feature = "builder")]
extern crate alloc;

// this crate can use std in tests only
#[cfg_attr(test, macro_use)]
#[cfg(test)]
Expand Down Expand Up @@ -81,6 +84,9 @@ mod smbios;
mod tag_type;
mod vbe_info;

#[cfg(feature = "builder")]
pub mod builder;

/// Magic number that a multiboot2-compliant boot loader will store in `eax` register
/// right before handoff to the payload (the kernel). This value can be used to check,
/// that the kernel was indeed booted via multiboot2.
Expand Down