Skip to content

Commit 6da9096

Browse files
committed
multiboot2: split TagType into TagType and TagTypeId
This change allows to get custom tag types.
1 parent 4a3f720 commit 6da9096

File tree

12 files changed

+365
-128
lines changed

12 files changed

+365
-128
lines changed

multiboot2/Changelog.md

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

33
## Unreleased
4-
- MSRV is 1.56.1
4+
- **BREAKING:** MSRV is 1.56.1
5+
- **BREAKING:** `TagType` is now split into `TagTypeId` and `TagType`
6+
- `TagTypeId` is a binary-compatible form of a Multiboot2 tag id
7+
- `TagType` is a higher-level abstraction for either specified or custom tags
8+
but not ABI compatible.
9+
- `BootInformation` now publicly exports the `get_tag` function allowing you to
10+
work with custom tags. An example is given in the function documentation.
11+
(check docs.rs). There is also a small unit test that you can use to learn
12+
from.
13+
- There exists a seamless integration between `u32`, `TagType`, `TagType`, and
14+
`TagTypeId` via `From` and `PartialEq`-implementations.
515

616
## 0.14.2 (2023-03-17)
717
- documentation fixes

multiboot2/src/boot_loader_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::TagType;
1+
use crate::TagTypeId;
22
use core::str::Utf8Error;
33

44
/// This tag contains the name of the bootloader that is booting the kernel.
@@ -8,7 +8,7 @@ use core::str::Utf8Error;
88
#[derive(Clone, Copy, Debug)]
99
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
1010
pub struct BootLoaderNameTag {
11-
typ: TagType,
11+
typ: TagTypeId,
1212
size: u32,
1313
/// Null-terminated UTF-8 string
1414
string: u8,
@@ -47,7 +47,7 @@ mod tests {
4747
// size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
4848
let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
4949
[
50-
&((TagType::BootLoaderName as u32).to_ne_bytes()),
50+
&((TagType::BootLoaderName.val()).to_ne_bytes()),
5151
&size.to_ne_bytes(),
5252
MSG.as_bytes(),
5353
// Null Byte

multiboot2/src/command_line.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Module for [CommandLineTag].
22
3-
use crate::TagType;
3+
use crate::TagTypeId;
44
use core::mem;
55
use core::slice;
66
use core::str;
@@ -12,7 +12,7 @@ use core::str;
1212
#[derive(Clone, Copy, Debug)]
1313
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
1414
pub struct CommandLineTag {
15-
typ: TagType,
15+
typ: TagTypeId,
1616
size: u32,
1717
/// Null-terminated UTF-8 string
1818
string: u8,
@@ -51,7 +51,7 @@ mod tests {
5151
// size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
5252
let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
5353
[
54-
&((TagType::Cmdline as u32).to_ne_bytes()),
54+
&((TagType::Cmdline.val()).to_ne_bytes()),
5555
&size.to_ne_bytes(),
5656
MSG.as_bytes(),
5757
// Null Byte

multiboot2/src/efi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! All MBI tags related to (U)EFI.
22
3-
use crate::TagType;
3+
use crate::TagTypeId;
44

55
/// EFI system table in 32 bit mode
66
#[derive(Clone, Copy, Debug)]
77
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
88
pub struct EFISdt32 {
9-
typ: TagType,
9+
typ: TagTypeId,
1010
size: u32,
1111
pointer: u32,
1212
}
@@ -22,7 +22,7 @@ impl EFISdt32 {
2222
#[derive(Clone, Copy, Debug)]
2323
#[repr(C)]
2424
pub struct EFISdt64 {
25-
typ: TagType,
25+
typ: TagTypeId,
2626
size: u32,
2727
pointer: u64,
2828
}
@@ -38,7 +38,7 @@ impl EFISdt64 {
3838
#[derive(Debug)]
3939
#[repr(C)]
4040
pub struct EFIImageHandle32 {
41-
typ: TagType,
41+
typ: TagTypeId,
4242
size: u32,
4343
pointer: u32,
4444
}
@@ -54,7 +54,7 @@ impl EFIImageHandle32 {
5454
#[derive(Debug)]
5555
#[repr(C)]
5656
pub struct EFIImageHandle64 {
57-
typ: TagType,
57+
typ: TagTypeId,
5858
size: u32,
5959
pointer: u64,
6060
}

multiboot2/src/elf_sections.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::tag_type::Tag;
2+
use crate::TagType;
23
use core::fmt::{Debug, Formatter};
34

45
/// This tag contains section header table from an ELF kernel.
@@ -11,7 +12,7 @@ pub struct ElfSectionsTag {
1112
}
1213

1314
pub unsafe fn elf_sections_tag(tag: &Tag, offset: usize) -> ElfSectionsTag {
14-
assert_eq!(9, tag.typ);
15+
assert_eq!(TagType::ElfSections.val(), tag.typ);
1516
let es = ElfSectionsTag {
1617
inner: (tag as *const Tag).offset(1) as *const ElfSectionsTagInner,
1718
offset,

multiboot2/src/image_load_addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::TagType;
1+
use crate::TagTypeId;
22

33
/// If the image has relocatable header tag, this tag contains the image's
44
/// base physical address.
55
#[derive(Debug)]
66
#[repr(C)]
77
pub struct ImageLoadPhysAddr {
8-
typ: TagType,
8+
typ: TagTypeId,
99
size: u32,
1010
load_base_addr: u32,
1111
}

multiboot2/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub use memory_map::{
5454
};
5555
pub use module::{ModuleIter, ModuleTag};
5656
pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
57-
pub use tag_type::TagType;
58-
use tag_type::{Tag, TagIter};
57+
pub use tag_type::{Tag, TagType, TagTypeId};
58+
use tag_type::TagIter;
5959
pub use vbe_info::{
6060
VBECapabilities, VBEControlInfo, VBEDirectColorAttributes, VBEField, VBEInfoTag,
6161
VBEMemoryModel, VBEModeAttributes, VBEModeInfo, VBEWindowAttributes,
@@ -325,16 +325,16 @@ impl BootInformation {
325325

326326
impl BootInformationInner {
327327
fn has_valid_end_tag(&self) -> bool {
328-
const END_TAG: Tag = Tag {
329-
typ: TagType::End,
328+
let end_tag_prototype: Tag = Tag {
329+
typ: TagType::End.into(),
330330
size: 8,
331331
};
332332

333333
let self_ptr = self as *const _;
334-
let end_tag_addr = self_ptr as usize + (self.total_size - END_TAG.size) as usize;
334+
let end_tag_addr = self_ptr as usize + (self.total_size - end_tag_prototype.size) as usize;
335335
let end_tag = unsafe { &*(end_tag_addr as *const Tag) };
336336

337-
end_tag.typ == END_TAG.typ && end_tag.size == END_TAG.size
337+
end_tag.typ == end_tag_prototype.typ && end_tag.size == end_tag_prototype.size
338338
}
339339
}
340340

multiboot2/src/memory_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::TagType;
1+
use crate::TagTypeId;
22
use core::marker::PhantomData;
33

44
/// This tag provides an initial host memory map.
@@ -14,7 +14,7 @@ use core::marker::PhantomData;
1414
#[derive(Debug)]
1515
#[repr(C)]
1616
pub struct MemoryMapTag {
17-
typ: TagType,
17+
typ: TagTypeId,
1818
size: u32,
1919
entry_size: u32,
2020
entry_version: u32,
@@ -126,7 +126,7 @@ impl<'a> Iterator for MemoryAreaIter<'a> {
126126
#[derive(Debug)]
127127
#[repr(C)]
128128
pub struct EFIMemoryMapTag {
129-
typ: TagType,
129+
typ: TagTypeId,
130130
size: u32,
131131
desc_size: u32,
132132
desc_version: u32,

multiboot2/src/module.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::tag_type::{Tag, TagIter, TagType};
2+
use crate::TagTypeId;
23
use core::fmt::{Debug, Formatter};
34
use core::str::Utf8Error;
45

@@ -7,7 +8,7 @@ use core::str::Utf8Error;
78
#[derive(Clone, Copy)]
89
#[repr(C, packed)] // only repr(C) would add unwanted padding near name_byte.
910
pub struct ModuleTag {
10-
typ: TagType,
11+
typ: TagTypeId,
1112
size: u32,
1213
mod_start: u32,
1314
mod_end: u32,
@@ -102,7 +103,7 @@ mod tests {
102103
// 4 bytes mod_start + 4 bytes mod_end
103104
let size = (4 + 4 + 4 + 4 + MSG.as_bytes().len() + 1) as u32;
104105
[
105-
&((TagType::Module as u32).to_ne_bytes()),
106+
&((TagType::Module.val()).to_ne_bytes()),
106107
&size.to_ne_bytes(),
107108
&0_u32.to_ne_bytes(),
108109
&0_u32.to_ne_bytes(),

multiboot2/src/rsdp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! Even though the bootloader should give the address of the real RSDP/XSDT, the checksum and
1010
//! signature should be manually verified.
11-
use crate::TagType;
11+
use crate::TagTypeId;
1212
use core::slice;
1313
use core::str;
1414
use core::str::Utf8Error;
@@ -19,7 +19,7 @@ const RSDPV1_LENGTH: usize = 20;
1919
#[derive(Clone, Copy, Debug)]
2020
#[repr(C, packed)]
2121
pub struct RsdpV1Tag {
22-
typ: TagType,
22+
typ: TagTypeId,
2323
size: u32,
2424
signature: [u8; 8],
2525
checksum: u8,
@@ -66,7 +66,7 @@ impl RsdpV1Tag {
6666
#[derive(Clone, Copy, Debug)]
6767
#[repr(C, packed)]
6868
pub struct RsdpV2Tag {
69-
typ: TagType,
69+
typ: TagTypeId,
7070
size: u32,
7171
signature: [u8; 8],
7272
checksum: u8,

0 commit comments

Comments
 (0)