Skip to content

Commit 9dd5c2a

Browse files
authored
Merge pull request #143 from rust-osdev/dev2
various fixes + cleanup + bump crate versions
2 parents 4908653 + 1f840b2 commit 9dd5c2a

File tree

17 files changed

+125
-124
lines changed

17 files changed

+125
-124
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ jobs:
7575
# check that devs can also use this on Windows.
7676
build_nostd_stable_windows:
7777
name: build no_std (stable) [Windows]
78+
needs: build_stable
7879
uses: ./.github/workflows/_build-rust.yml
7980
with:
8081
runs-on: windows-latest

Cargo.lock

Lines changed: 13 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"multiboot2",
45
"multiboot2-header",
56
]
7+
8+
9+
# This way, the "multiboot2" dependency in the multiboot2-header crate can be
10+
# referenced by version, while still the repository version is used
11+
# transparently during local development.
12+
[patch.crates-io]
13+
multiboot2 = { path = "multiboot2" }

multiboot2-header/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = """
44
Library with type definitions and parsing functions for Multiboot2 headers.
55
This library is `no_std` and can be used in bootloaders.
66
"""
7-
version = "0.2.0"
7+
version = "0.3.0"
88
authors = [
99
"Philipp Schuster <phip1611@gmail.com>"
1010
]
@@ -41,4 +41,4 @@ unstable = []
4141

4242
[dependencies]
4343
# used for MBI tags
44-
multiboot2 = "0.13.2"
44+
multiboot2 = "0.16.0"

multiboot2-header/Changelog.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
# CHANGELOG for crate `multiboot2-header`
22

3-
## Unreleased
3+
## 0.3.0 (xxxx-xx-xx)
44
- MSRV is 1.68.0
55
- renamed the `std` feature to `alloc`
66
- added the optional `unstable` feature (requires nightly)
77
- implement `core::error::Error` for `LoadError`
8+
- depends on `multiboot2@v0.16.0`
89

9-
## v0.2.0 (2022-05-03)
10+
## 0.2.0 (2022-05-03)
1011
- **BREAKING** renamed `EntryHeaderTag` to `EntryAddressHeaderTag`
1112
- **BREAKING** some paths changed from `multiboot2_header::header` to `multiboot2_header::builder`
1213
-> thus, import paths are much more logically now
1314
- internal code improvements
1415

15-
## v0.1.1 (2022-05-02)
16+
## 0.1.1 (2022-05-02)
1617
- fixed a bug that prevented the usage of the crate in `no_std` environments
1718
- added a new default `builder`-feature to Cargo which requires the `alloc`-crate
1819
(this feature can be disabled which will also remove the dependency to the `alloc` crate)
1920

20-
## v0.1.0 (2021-10-08)
21+
## 0.1.0 (2021-10-08)
2122
- initial release
2223

23-
## v0.0.0
24+
## 0.0.0
2425
Empty release to save the name on crates.io

multiboot2-header/src/builder/information_request.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use super::traits::StructAsBytes;
2-
use crate::InformationRequestHeaderTag;
32
use crate::{HeaderTagFlag, MbiTagType};
3+
use crate::{InformationRequestHeaderTag, MbiTagTypeId};
44
use alloc::collections::BTreeSet;
55
use alloc::vec::Vec;
66
use core::fmt::Debug;
77
use core::mem::size_of;
8+
use multiboot2::TagTypeId;
89

910
/// Helper to build the dynamically sized [`InformationRequestHeaderTag`]
1011
/// at runtime. The information request tag has a dedicated builder because this way one
@@ -21,7 +22,6 @@ pub struct InformationRequestHeaderTagBuilder {
2122
#[cfg(feature = "builder")]
2223
impl InformationRequestHeaderTagBuilder {
2324
/// New builder.
24-
#[allow(clippy::missing_const_for_fn)] // TODO remove once MSRV is higher than 1.65.0
2525
pub fn new(flag: HeaderTagFlag) -> Self {
2626
Self {
2727
irs: BTreeSet::new(),
@@ -31,10 +31,9 @@ impl InformationRequestHeaderTagBuilder {
3131

3232
/// Returns the expected length of the information request tag,
3333
/// when the `build`-method gets called.
34-
#[allow(clippy::missing_const_for_fn)] // TODO remove once MSRV is higher than 1.65.0
3534
pub fn expected_len(&self) -> usize {
3635
let basic_header_size = size_of::<InformationRequestHeaderTag<0>>();
37-
let req_tags_size = self.irs.len() * size_of::<MbiTagType>();
36+
let req_tags_size = self.irs.len() * size_of::<MbiTagTypeId>();
3837
basic_header_size + req_tags_size
3938
}
4039

@@ -74,8 +73,13 @@ impl InformationRequestHeaderTagBuilder {
7473
);
7574
}
7675

77-
for tag in &self.irs {
78-
let bytes: [u8; 4] = (*tag as u32).to_ne_bytes();
76+
for tag_type in self
77+
.irs
78+
.into_iter()
79+
// Transform to the ABI-compatible type
80+
.map(TagTypeId::from)
81+
{
82+
let bytes: [u8; 4] = (u32::from(tag_type)).to_le_bytes();
7983
data.extend(&bytes);
8084
}
8185

@@ -91,7 +95,7 @@ impl InformationRequestHeaderTagBuilder {
9195
#[cfg(test)]
9296
mod tests {
9397
use crate::builder::information_request::InformationRequestHeaderTagBuilder;
94-
use crate::{HeaderTagFlag, InformationRequestHeaderTag, MbiTagType};
98+
use crate::{HeaderTagFlag, InformationRequestHeaderTag, MbiTagType, MbiTagTypeId};
9599

96100
#[test]
97101
fn test_builder() {
@@ -111,11 +115,19 @@ mod tests {
111115
// type(u16) + flags(u16) + size(u32) + 3 tags (u32)
112116
assert_eq!(tag.size(), 2 + 2 + 4 + 3 * 4);
113117
assert_eq!(tag.dynamic_requests_size(), 3);
114-
assert!(tag.requests().contains(&MbiTagType::EfiMmap));
115-
assert!(tag.requests().contains(&MbiTagType::BootLoaderName));
116-
assert!(tag.requests().contains(&MbiTagType::Cmdline));
118+
assert!(tag
119+
.requests()
120+
.contains(&MbiTagTypeId::from(MbiTagType::EfiMmap)));
121+
assert!(tag
122+
.requests()
123+
.contains(&MbiTagTypeId::from(MbiTagType::BootLoaderName)));
124+
assert!(tag
125+
.requests()
126+
.contains(&MbiTagTypeId::from(MbiTagType::Cmdline)));
117127
assert_eq!(tag.requests().len(), 3);
118-
assert!(!tag.requests().contains(&MbiTagType::AcpiV1));
128+
assert!(!tag
129+
.requests()
130+
.contains(&MbiTagTypeId::from(MbiTagType::AcpiV1)));
119131
println!("{:#?}", tag);
120132
}
121133
}

multiboot2-header/src/information_request.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use crate::HeaderTagType;
21
use crate::{HeaderTagFlag, MbiTagType};
2+
use crate::{HeaderTagType, MbiTagTypeId};
33
use core::fmt;
44
use core::fmt::{Debug, Formatter};
55
use core::marker::PhantomData;
66
use core::mem::size_of;
7+
use multiboot2::TagType;
78

89
/// Specifies what specific tag types the bootloader should provide
910
/// inside the mbi.
@@ -15,14 +16,14 @@ pub struct InformationRequestHeaderTag<const N: usize> {
1516
size: u32,
1617
// Length is determined by size.
1718
// Must be parsed during runtime with unsafe pointer magic and the size field.
18-
requests: [MbiTagType; N],
19+
requests: [MbiTagTypeId; N],
1920
}
2021

2122
impl<const N: usize> InformationRequestHeaderTag<N> {
2223
/// Creates a new object. The size parameter is the value of the size property.
2324
/// It doesn't have to match with `N` necessarily, because during compile time we
2425
/// can't know the size of the tag in all runtime situations.
25-
pub fn new(flags: HeaderTagFlag, requests: [MbiTagType; N], size: Option<u32>) -> Self {
26+
pub fn new(flags: HeaderTagFlag, requests: [MbiTagTypeId; N], size: Option<u32>) -> Self {
2627
InformationRequestHeaderTag {
2728
typ: HeaderTagType::InformationRequest,
2829
flags,
@@ -44,7 +45,7 @@ impl<const N: usize> InformationRequestHeaderTag<N> {
4445
/// Returns the requests as array. Only works if the number of requests
4546
/// is known at compile time. For safety and correctness during runtime,
4647
/// you should use `req_iter()`.
47-
pub const fn requests(&self) -> [MbiTagType; N] {
48+
pub const fn requests(&self) -> [MbiTagTypeId; N] {
4849
// cheap to copy, otherwise difficult with lifetime
4950
self.requests
5051
}
@@ -70,7 +71,7 @@ impl<const N: usize> InformationRequestHeaderTag<N> {
7071
let base_ptr = self as *const InformationRequestHeaderTag<N>;
7172
let base_ptr = base_ptr as *const u8;
7273
let base_ptr = unsafe { base_ptr.add(base_struct_size) };
73-
let base_ptr = base_ptr as *const MbiTagType;
74+
let base_ptr = base_ptr as *const MbiTagTypeId;
7475
InformationRequestHeaderTagIter::new(count, base_ptr)
7576
}
7677
}
@@ -90,32 +91,32 @@ impl<const N: usize> Debug for InformationRequestHeaderTag<N> {
9091
/// that are requested.
9192
#[derive(Copy, Clone)]
9293
pub struct InformationRequestHeaderTagIter<'a> {
93-
base_ptr: *const MbiTagType,
94+
base_ptr: *const MbiTagTypeId,
9495
i: u32,
9596
count: u32,
9697
_marker: PhantomData<&'a ()>,
9798
}
9899

99100
impl<'a> InformationRequestHeaderTagIter<'a> {
100-
fn new(count: u32, base_ptr: *const MbiTagType) -> Self {
101-
#[allow(clippy::default_constructed_unit_structs)]
101+
const fn new(count: u32, base_ptr: *const MbiTagTypeId) -> Self {
102102
Self {
103103
i: 0,
104104
count,
105105
base_ptr,
106-
_marker: PhantomData::default(),
106+
_marker: PhantomData,
107107
}
108108
}
109109
}
110110

111111
impl<'a> Iterator for InformationRequestHeaderTagIter<'a> {
112-
type Item = &'a MbiTagType;
112+
type Item = MbiTagType;
113113

114114
fn next(&mut self) -> Option<Self::Item> {
115115
if self.i < self.count {
116116
let ptr = unsafe { self.base_ptr.offset(self.i as isize) };
117117
self.i += 1;
118-
Some(unsafe { &*ptr })
118+
let tag_type_id = unsafe { *ptr };
119+
Some(TagType::from(tag_type_id))
119120
} else {
120121
None
121122
}
@@ -126,7 +127,7 @@ impl<'a> Debug for InformationRequestHeaderTagIter<'a> {
126127
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
127128
let mut debug = f.debug_list();
128129
(*self).for_each(|e| {
129-
debug.entry(e);
130+
debug.entry(&e);
130131
});
131132
debug.finish()
132133
}

multiboot2-header/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ pub use self::tags::*;
7979
pub use self::uefi_bs::*;
8080

8181
/// Re-export of [`multiboot2::TagType`] from `multiboot2`-crate.
82-
pub use multiboot2::TagType as MbiTagType;
82+
pub use multiboot2::{TagType as MbiTagType, TagTypeId as MbiTagTypeId};

multiboot2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Multiboot2-compliant bootloaders, like GRUB. It supports all tags from the speci
66
including full support for the sections of ELF-64. This library is `no_std` and can be
77
used in a Multiboot2-kernel.
88
"""
9-
version = "0.15.1"
9+
version = "0.16.0"
1010
authors = [
1111
"Philipp Oppermann <dev@phil-opp.com>",
1212
"Calvin Lee <cyrus296@gmail.com>",

multiboot2/Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CHANGELOG for crate `multiboot2`
22

3-
## unreleased
3+
## 0.16.0 (xxxx-xx-xx)
44
- Add `TagTrait` trait which enables to use DSTs as multiboot2 tags. This is
55
mostly relevant for the command line tag, the modules tag, and the bootloader
66
name tag. However, this might also be relevant for users of custom multiboot2

multiboot2/src/boot_loader_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ mod tests {
8484
// size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
8585
let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
8686
[
87-
&((TagType::BootLoaderName.val()).to_ne_bytes()),
88-
&size.to_ne_bytes(),
87+
&((TagType::BootLoaderName.val()).to_le_bytes()),
88+
&size.to_le_bytes(),
8989
MSG.as_bytes(),
9090
// Null Byte
9191
&[0],

multiboot2/src/command_line.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ mod tests {
9393
// size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
9494
let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
9595
[
96-
&((TagType::Cmdline.val()).to_ne_bytes()),
97-
&size.to_ne_bytes(),
96+
&((TagType::Cmdline.val()).to_le_bytes()),
97+
&size.to_le_bytes(),
9898
MSG.as_bytes(),
9999
// Null Byte
100100
&[0],

0 commit comments

Comments
 (0)