Skip to content

Commit ec05bf5

Browse files
committed
multiboot2: introduce new TagHeader type
This is a preparation for following refactorings.
1 parent 767eb0c commit ec05bf5

File tree

11 files changed

+88
-85
lines changed

11 files changed

+88
-85
lines changed

multiboot2/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- updated dependencies
66
- MSRV is 1.75
77
- doc fixes
8+
- Introduced new `TagHeader` type as replacement for the `Tag` type that will
9+
be changed in the next step.
810

911
## 0.20.2 (2024-05-26)
1012

multiboot2/src/boot_loader_name.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Module for [`BootLoaderNameTag`].
22
3-
use crate::tag::StringError;
3+
use crate::tag::{StringError, TagHeader};
44
use crate::{Tag, TagTrait, TagType, TagTypeId};
55
use core::fmt::{Debug, Formatter};
66
use core::mem::size_of;
@@ -13,8 +13,7 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>() + size_of::<u32>();
1313
#[derive(ptr_meta::Pointee, PartialEq, Eq, PartialOrd, Ord, Hash)]
1414
#[repr(C)]
1515
pub struct BootLoaderNameTag {
16-
typ: TagTypeId,
17-
size: u32,
16+
header: TagHeader,
1817
/// Null-terminated UTF-8 string
1918
name: [u8],
2019
}
@@ -55,8 +54,8 @@ impl BootLoaderNameTag {
5554
impl Debug for BootLoaderNameTag {
5655
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
5756
f.debug_struct("BootLoaderNameTag")
58-
.field("typ", &{ self.typ })
59-
.field("size", &{ self.size })
57+
.field("typ", &self.header.typ)
58+
.field("size", &self.header.size)
6059
.field("name", &self.name())
6160
.finish()
6261
}

multiboot2/src/command_line.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Module for [`CommandLineTag`].
22
3+
use crate::tag::{StringError, TagHeader};
34
use crate::{Tag, TagTrait, TagType, TagTypeId};
4-
5-
use crate::tag::StringError;
65
use core::fmt::{Debug, Formatter};
76
use core::mem;
87
use core::str;
@@ -18,8 +17,7 @@ pub(crate) const METADATA_SIZE: usize = mem::size_of::<TagTypeId>() + mem::size_
1817
#[derive(ptr_meta::Pointee, PartialEq, Eq, PartialOrd, Ord, Hash)]
1918
#[repr(C)]
2019
pub struct CommandLineTag {
21-
typ: TagTypeId,
22-
size: u32,
20+
header: TagHeader,
2321
/// Null-terminated UTF-8 string
2422
cmdline: [u8],
2523
}
@@ -63,8 +61,8 @@ impl CommandLineTag {
6361
impl Debug for CommandLineTag {
6462
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
6563
f.debug_struct("CommandLineTag")
66-
.field("typ", &{ self.typ })
67-
.field("size", &{ self.size })
64+
.field("typ", &self.header.typ)
65+
.field("size", &self.header.size)
6866
.field("cmdline", &self.cmdline())
6967
.finish()
7068
}

multiboot2/src/efi.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,23 @@
66
//! - [`EFIImageHandle64Tag`]
77
//! - [`EFIBootServicesNotExitedTag`]
88
9-
use crate::TagTypeId;
9+
use crate::tag::TagHeader;
1010
use crate::{Tag, TagTrait, TagType};
1111
use core::mem::size_of;
1212

1313
/// EFI system table in 32 bit mode tag.
1414
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1515
#[repr(C)]
1616
pub struct EFISdt32Tag {
17-
typ: TagTypeId,
18-
size: u32,
17+
header: TagHeader,
1918
pointer: u32,
2019
}
2120

2221
impl EFISdt32Tag {
2322
/// Create a new tag to pass the EFI32 System Table pointer.
2423
pub fn new(pointer: u32) -> Self {
2524
Self {
26-
typ: Self::ID.into(),
27-
size: size_of::<Self>().try_into().unwrap(),
25+
header: TagHeader::new(Self::ID, size_of::<Self>().try_into().unwrap()),
2826
pointer,
2927
}
3028
}
@@ -45,17 +43,15 @@ impl TagTrait for EFISdt32Tag {
4543
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
4644
#[repr(C)]
4745
pub struct EFISdt64Tag {
48-
typ: TagTypeId,
49-
size: u32,
46+
header: TagHeader,
5047
pointer: u64,
5148
}
5249

5350
impl EFISdt64Tag {
5451
/// Create a new tag to pass the EFI64 System Table pointer.
5552
pub fn new(pointer: u64) -> Self {
5653
Self {
57-
typ: Self::ID.into(),
58-
size: size_of::<Self>().try_into().unwrap(),
54+
header: TagHeader::new(Self::ID, size_of::<Self>().try_into().unwrap()),
5955
pointer,
6056
}
6157
}
@@ -77,17 +73,15 @@ impl TagTrait for EFISdt64Tag {
7773
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7874
#[repr(C)]
7975
pub struct EFIImageHandle32Tag {
80-
typ: TagTypeId,
81-
size: u32,
76+
header: TagHeader,
8277
pointer: u32,
8378
}
8479

8580
impl EFIImageHandle32Tag {
8681
#[cfg(feature = "builder")]
8782
pub fn new(pointer: u32) -> Self {
8883
Self {
89-
typ: Self::ID.into(),
90-
size: size_of::<Self>().try_into().unwrap(),
84+
header: TagHeader::new(Self::ID, size_of::<Self>().try_into().unwrap()),
9185
pointer,
9286
}
9387
}
@@ -109,17 +103,15 @@ impl TagTrait for EFIImageHandle32Tag {
109103
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
110104
#[repr(C)]
111105
pub struct EFIImageHandle64Tag {
112-
typ: TagTypeId,
113-
size: u32,
106+
header: TagHeader,
114107
pointer: u64,
115108
}
116109

117110
impl EFIImageHandle64Tag {
118111
#[cfg(feature = "builder")]
119112
pub fn new(pointer: u64) -> Self {
120113
Self {
121-
typ: Self::ID.into(),
122-
size: size_of::<Self>().try_into().unwrap(),
114+
header: TagHeader::new(Self::ID, size_of::<Self>().try_into().unwrap()),
123115
pointer,
124116
}
125117
}
@@ -140,8 +132,7 @@ impl TagTrait for EFIImageHandle64Tag {
140132
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
141133
#[repr(C)]
142134
pub struct EFIBootServicesNotExitedTag {
143-
typ: TagTypeId,
144-
size: u32,
135+
header: TagHeader,
145136
}
146137

147138
impl EFIBootServicesNotExitedTag {
@@ -155,8 +146,7 @@ impl EFIBootServicesNotExitedTag {
155146
impl Default for EFIBootServicesNotExitedTag {
156147
fn default() -> Self {
157148
Self {
158-
typ: TagType::EfiBs.into(),
159-
size: core::mem::size_of::<Self>().try_into().unwrap(),
149+
header: TagHeader::new(Self::ID, size_of::<Self>().try_into().unwrap()),
160150
}
161151
}
162152
}

multiboot2/src/framebuffer.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Module for [`FramebufferTag`].
22
3+
use crate::tag::TagHeader;
34
use crate::{Tag, TagTrait, TagType, TagTypeId};
45
use core::fmt::Debug;
56
use core::mem::size_of;
@@ -51,8 +52,7 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>()
5152
#[derive(ptr_meta::Pointee, Eq)]
5253
#[repr(C)]
5354
pub struct FramebufferTag {
54-
typ: TagTypeId,
55-
size: u32,
55+
header: TagHeader,
5656

5757
/// Contains framebuffer physical address.
5858
///
@@ -185,29 +185,28 @@ impl TagTrait for FramebufferTag {
185185
impl Debug for FramebufferTag {
186186
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
187187
f.debug_struct("FramebufferTag")
188-
.field("typ", &{ self.typ })
189-
.field("size", &{ self.size })
188+
.field("typ", &self.header.typ)
189+
.field("size", &self.header.size)
190190
.field("buffer_type", &self.buffer_type())
191-
.field("address", &{ self.address })
192-
.field("pitch", &{ self.pitch })
193-
.field("width", &{ self.width })
194-
.field("height", &{ self.height })
191+
.field("address", &self.address)
192+
.field("pitch", &self.pitch)
193+
.field("width", &self.width)
194+
.field("height", &self.height)
195195
.field("bpp", &self.bpp)
196196
.finish()
197197
}
198198
}
199199

200200
impl PartialEq for FramebufferTag {
201201
fn eq(&self, other: &Self) -> bool {
202-
({ self.typ } == { other.typ }
203-
&& { self.size } == { other.size }
204-
&& { self.address } == { other.address }
205-
&& { self.pitch } == { other.pitch }
206-
&& { self.width } == { other.width }
207-
&& { self.height } == { other.height }
208-
&& { self.bpp } == { other.bpp }
209-
&& { self.type_no } == { other.type_no }
210-
&& self.buffer == other.buffer)
202+
self.header == other.header
203+
&& self.address == { other.address }
204+
&& self.pitch == { other.pitch }
205+
&& self.width == { other.width }
206+
&& self.height == { other.height }
207+
&& self.bpp == { other.bpp }
208+
&& self.type_no == { other.type_no }
209+
&& self.buffer == other.buffer
211210
}
212211
}
213212

multiboot2/src/image_load_addr.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Module for [`ImageLoadPhysAddrTag`].
22
3-
use crate::{Tag, TagTrait, TagType, TagTypeId};
3+
use crate::tag::TagHeader;
4+
use crate::{Tag, TagTrait, TagType};
45
#[cfg(feature = "builder")]
56
use core::mem::size_of;
67

@@ -10,17 +11,15 @@ use core::mem::size_of;
1011
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1112
#[repr(C)]
1213
pub struct ImageLoadPhysAddrTag {
13-
typ: TagTypeId,
14-
size: u32,
14+
header: TagHeader,
1515
load_base_addr: u32,
1616
}
1717

1818
impl ImageLoadPhysAddrTag {
1919
#[cfg(feature = "builder")]
2020
pub fn new(load_base_addr: u32) -> Self {
2121
Self {
22-
typ: Self::ID.into(),
23-
size: size_of::<Self>().try_into().unwrap(),
22+
header: TagHeader::new(Self::ID, size_of::<Self>().try_into().unwrap()),
2423
load_base_addr,
2524
}
2625
}

multiboot2/src/memory_map.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub use uefi_raw::table::boot::MemoryAttribute as EFIMemoryAttribute;
55
pub use uefi_raw::table::boot::MemoryDescriptor as EFIMemoryDesc;
66
pub use uefi_raw::table::boot::MemoryType as EFIMemoryAreaType;
77

8+
use crate::tag::TagHeader;
89
use crate::{Tag, TagTrait, TagType, TagTypeId};
910
use core::fmt::{Debug, Formatter};
1011
use core::marker::PhantomData;
@@ -27,8 +28,7 @@ const METADATA_SIZE: usize = mem::size_of::<TagTypeId>() + 3 * mem::size_of::<u3
2728
#[derive(ptr_meta::Pointee, Debug, PartialEq, Eq)]
2829
#[repr(C)]
2930
pub struct MemoryMapTag {
30-
typ: TagTypeId,
31-
size: u32,
31+
header: TagHeader,
3232
entry_size: u32,
3333
entry_version: u32,
3434
areas: [MemoryArea],
@@ -246,17 +246,15 @@ impl PartialEq<MemoryAreaTypeId> for MemoryAreaType {
246246
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
247247
#[repr(C)]
248248
pub struct BasicMemoryInfoTag {
249-
typ: TagTypeId,
250-
size: u32,
249+
header: TagHeader,
251250
memory_lower: u32,
252251
memory_upper: u32,
253252
}
254253

255254
impl BasicMemoryInfoTag {
256255
pub fn new(memory_lower: u32, memory_upper: u32) -> Self {
257256
Self {
258-
typ: Self::ID.into(),
259-
size: mem::size_of::<BasicMemoryInfoTag>().try_into().unwrap(),
257+
header: TagHeader::new(Self::ID, size_of::<Self>().try_into().unwrap()),
260258
memory_lower,
261259
memory_upper,
262260
}
@@ -287,8 +285,7 @@ impl AsBytes for EFIMemoryDesc {}
287285
#[derive(ptr_meta::Pointee, PartialEq, Eq, PartialOrd, Ord, Hash)]
288286
#[repr(C)]
289287
pub struct EFIMemoryMapTag {
290-
typ: TagTypeId,
291-
size: u32,
288+
header: TagHeader,
292289
/// Most likely a little more than the size of a [`EFIMemoryDesc`].
293290
/// This is always the reference, and `size_of` never.
294291
/// See <https://github.com/tianocore/edk2/blob/7142e648416ff5d3eac6c6d607874805f5de0ca8/MdeModulePkg/Core/PiSmmCore/Page.c#L1059>.
@@ -380,8 +377,8 @@ impl EFIMemoryMapTag {
380377
impl Debug for EFIMemoryMapTag {
381378
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
382379
f.debug_struct("EFIMemoryMapTag")
383-
.field("typ", &self.typ)
384-
.field("size", &self.size)
380+
.field("typ", &self.header.typ)
381+
.field("size", &self.header.size)
385382
.field("desc_size", &self.desc_size)
386383
.field("buf", &self.memory_map.as_ptr())
387384
.field("buf_len", &self.memory_map.len())

multiboot2/src/module.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Module for [`ModuleTag`].
22
3-
use crate::tag::{StringError, TagIter};
3+
use crate::tag::{StringError, TagHeader, TagIter};
44
use crate::{Tag, TagTrait, TagType, TagTypeId};
55
use core::fmt::{Debug, Formatter};
66
use core::mem::size_of;
@@ -15,8 +15,7 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>() + 3 * size_of::<u32>();
1515
#[derive(ptr_meta::Pointee, PartialEq, Eq, PartialOrd, Ord, Hash)]
1616
#[repr(C)]
1717
pub struct ModuleTag {
18-
typ: TagTypeId,
19-
size: u32,
18+
header: TagHeader,
2019
mod_start: u32,
2120
mod_end: u32,
2221
/// Null-terminated UTF-8 string
@@ -81,8 +80,8 @@ impl TagTrait for ModuleTag {
8180
impl Debug for ModuleTag {
8281
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
8382
f.debug_struct("ModuleTag")
84-
.field("type", &{ self.typ })
85-
.field("size", &{ self.size })
83+
.field("type", &self.header.typ)
84+
.field("size", &self.header.size)
8685
// Trick to print as hex.
8786
.field("mod_start", &self.mod_start)
8887
.field("mod_end", &self.mod_end)

0 commit comments

Comments
 (0)