Skip to content

Commit 95e463a

Browse files
committed
multiboot2: split TagType into TagType and TagTypeId
This change allows to get custom tag types.
1 parent 9fbe6d6 commit 95e463a

File tree

12 files changed

+366
-127
lines changed

12 files changed

+366
-127
lines changed

multiboot2/Changelog.md

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

3+
## 0.15.0 (2022-XX-XX)
4+
- `BootInformation` now publicly exports the `get_tag` function allowing you to
5+
work with custom tags. An example is given in the function documentation.
6+
(check docs.rs). There is also a small unit test that you can use to learn
7+
from.
8+
- **BREAKING:** `TagType` is now split into `TagTypeId` and `TagType`
9+
- `TagTypeId` is a binary-compatible form of a Multiboot2 tag id
10+
- `TagType` is a higher-level abstraction for either specified or custom tags
11+
but not ABI compatible.
12+
- There exists a seamless integration between `u32`, `TagType`, `TagType`, and
13+
`TagTypeId` via `From` and `PartialEq`-implementations.
14+
315
## 0.14.0 (2022-06-30)
416
- **BREAKING CHANGES** \
517
This version includes a few small breaking changes that brings more safety when parsing strings from the

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,
@@ -50,7 +50,7 @@ mod tests {
5050
// size is: 4 bytes for tag + 4 bytes for size + length of null-terminated string
5151
let size = (4 + 4 + MSG.as_bytes().len() + 1) as u32;
5252
[
53-
&((TagType::Cmdline as u32).to_ne_bytes()),
53+
&((TagType::Cmdline.val()).to_ne_bytes()),
5454
&size.to_ne_bytes(),
5555
MSG.as_bytes(),
5656
// 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
@@ -55,8 +55,8 @@ pub use memory_map::{
5555
};
5656
pub use module::{ModuleIter, ModuleTag};
5757
pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
58-
pub use tag_type::TagType;
59-
use tag_type::{Tag, TagIter};
58+
pub use tag_type::{Tag, TagType, TagTypeId};
59+
use tag_type::TagIter;
6060
pub use vbe_info::{
6161
VBECapabilities, VBEControlInfo, VBEDirectColorAttributes, VBEField, VBEInfoTag,
6262
VBEMemoryModel, VBEModeAttributes, VBEModeInfo, VBEWindowAttributes,
@@ -319,16 +319,16 @@ impl BootInformation {
319319

320320
impl BootInformationInner {
321321
fn has_valid_end_tag(&self) -> bool {
322-
const END_TAG: Tag = Tag {
323-
typ: TagType::End,
322+
let end_tag_prototype: Tag = Tag {
323+
typ: TagType::End.into(),
324324
size: 8,
325325
};
326326

327327
let self_ptr = self as *const _;
328-
let end_tag_addr = self_ptr as usize + (self.total_size - END_TAG.size) as usize;
328+
let end_tag_addr = self_ptr as usize + (self.total_size - end_tag_prototype.size) as usize;
329329
let end_tag = unsafe { &*(end_tag_addr as *const Tag) };
330330

331-
end_tag.typ == END_TAG.typ && end_tag.size == END_TAG.size
331+
end_tag.typ == end_tag_prototype.typ && end_tag.size == end_tag_prototype.size
332332
}
333333
}
334334

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,
@@ -123,7 +123,7 @@ impl<'a> Iterator for MemoryAreaIter<'a> {
123123
#[derive(Debug)]
124124
#[repr(C)]
125125
pub struct EFIMemoryMapTag {
126-
typ: TagType,
126+
typ: TagTypeId,
127127
size: u32,
128128
desc_size: u32,
129129
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)