Skip to content

Commit 9de4a1a

Browse files
committed
multiboot2: streamline tags
- all public fields -> methods - Added missing InformationBuilder support for VBEInfoTag
1 parent fad9745 commit 9de4a1a

File tree

6 files changed

+137
-66
lines changed

6 files changed

+137
-66
lines changed

multiboot2/src/boot_information.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
module, BasicMemoryInfoTag, BootLoaderNameTag, CommandLineTag, EFIBootServicesNotExitedTag,
99
EFIImageHandle32Tag, EFIImageHandle64Tag, EFIMemoryMapTag, EFISdt32Tag, EFISdt64Tag,
1010
ElfSectionIter, ElfSectionsTag, EndTag, FramebufferTag, ImageLoadPhysAddrTag, MemoryMapTag,
11-
ModuleIter, RsdpV1Tag, RsdpV2Tag, SmbiosTag, TagTrait, TagType, VBEInfoTag,
11+
ModuleIter, RsdpV1Tag, RsdpV2Tag, SmbiosTag, TagTrait, VBEInfoTag,
1212
};
1313
use core::fmt;
1414
use core::mem;
@@ -279,8 +279,8 @@ impl<'a> BootInformation<'a> {
279279
pub fn elf_sections(&self) -> Option<ElfSectionIter> {
280280
let tag = self.get_tag::<ElfSectionsTag>();
281281
tag.map(|t| {
282-
assert!((t.entry_size * t.shndx) <= t.size() as u32);
283-
t.sections()
282+
assert!((t.entry_size() * t.shndx()) <= t.size() as u32);
283+
t.sections_iter()
284284
})
285285
}
286286

multiboot2/src/boot_loader_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Module for [`BootLoaderNameTag`].
22
33
use crate::tag::TagHeader;
4-
use crate::{new_boxed, parse_slice_as_string, StringError, TagTrait, TagType};
5-
#[cfg(feature = "builder")]
6-
use alloc::boxed::Box;
4+
use crate::{parse_slice_as_string, StringError, TagTrait, TagType};
75
use core::fmt::{Debug, Formatter};
86
use core::mem;
7+
#[cfg(feature = "builder")]
8+
use {crate::new_boxed, alloc::boxed::Box};
99

1010
const METADATA_SIZE: usize = mem::size_of::<TagHeader>();
1111

multiboot2/src/builder/information.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use crate::{
55
BasicMemoryInfoTag, BootInformationHeader, BootLoaderNameTag, CommandLineTag,
66
EFIBootServicesNotExitedTag, EFIImageHandle32Tag, EFIImageHandle64Tag, EFIMemoryMapTag,
77
EFISdt32Tag, EFISdt64Tag, ElfSectionsTag, EndTag, FramebufferTag, ImageLoadPhysAddrTag,
8-
MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag, TagTrait, TagType, ALIGNMENT,
8+
MemoryMapTag, ModuleTag, RsdpV1Tag, RsdpV2Tag, SmbiosTag, TagTrait, TagType, VBEInfoTag,
9+
ALIGNMENT,
910
};
1011
use alloc::vec::Vec;
1112
use core::fmt::{Display, Formatter};
@@ -300,6 +301,13 @@ impl InformationBuilder {
300301
self.add_tag(tag).unwrap()
301302
}
302303

304+
/// Adds a 'VBE Info' tag (represented by [`VBEInfoTag`]) to the builder.
305+
#[must_use]
306+
pub fn vbe_info_tag(self, tag: &VBEInfoTag) -> Self {
307+
self.add_tag(tag).unwrap()
308+
}
309+
310+
#[must_use]
303311
const fn tag_is_allowed_multiple_times(tag_type: TagType) -> bool {
304312
matches!(
305313
tag_type,

multiboot2/src/elf_sections.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const METADATA_SIZE: usize = mem::size_of::<TagHeader>() + 3 * mem::size_of::<u3
1818
pub struct ElfSectionsTag {
1919
header: TagHeader,
2020
number_of_sections: u32,
21-
pub(crate) entry_size: u32,
22-
pub(crate) shndx: u32, // string table
21+
entry_size: u32,
22+
shndx: u32,
2323
sections: [u8],
2424
}
2525

@@ -35,7 +35,8 @@ impl ElfSectionsTag {
3535
}
3636

3737
/// Get an iterator of loaded ELF sections.
38-
pub(crate) const fn sections(&self) -> ElfSectionIter {
38+
#[must_use]
39+
pub(crate) const fn sections_iter(&self) -> ElfSectionIter {
3940
let string_section_offset = (self.shndx * self.entry_size) as isize;
4041
let string_section_ptr =
4142
unsafe { self.sections.as_ptr().offset(string_section_offset) as *const _ };
@@ -47,6 +48,24 @@ impl ElfSectionsTag {
4748
_phantom_data: PhantomData,
4849
}
4950
}
51+
52+
/// Returns the amount of sections.
53+
#[must_use]
54+
pub const fn number_of_sections(&self) -> u32 {
55+
self.number_of_sections
56+
}
57+
58+
/// Returns the size of each entry.
59+
#[must_use]
60+
pub const fn entry_size(&self) -> u32 {
61+
self.entry_size
62+
}
63+
64+
/// Returns the index of the section header string table.
65+
#[must_use]
66+
pub const fn shndx(&self) -> u32 {
67+
self.shndx
68+
}
5069
}
5170

5271
impl TagTrait for ElfSectionsTag {
@@ -66,7 +85,7 @@ impl Debug for ElfSectionsTag {
6685
.field("number_of_sections", &self.number_of_sections)
6786
.field("entry_size", &self.entry_size)
6887
.field("shndx", &self.shndx)
69-
.field("sections", &self.sections())
88+
.field("sections", &self.sections_iter())
7089
.finish()
7190
}
7291
}

multiboot2/src/lib.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -448,83 +448,83 @@ mod tests {
448448
let vbe = bi.vbe_info_tag().unwrap();
449449
use vbe_info::*;
450450

451-
assert_eq!({ vbe.mode }, 16762);
452-
assert_eq!({ vbe.interface_segment }, 65535);
453-
assert_eq!({ vbe.interface_offset }, 24576);
454-
assert_eq!({ vbe.interface_length }, 79);
455-
assert_eq!({ vbe.control_info.signature }, [86, 69, 83, 65]);
456-
assert_eq!({ vbe.control_info.version }, 768);
457-
assert_eq!({ vbe.control_info.oem_string_ptr }, 3221247964);
451+
assert_eq!({ vbe.mode() }, 16762);
452+
assert_eq!({ vbe.interface_segment() }, 65535);
453+
assert_eq!({ vbe.interface_offset() }, 24576);
454+
assert_eq!({ vbe.interface_length() }, 79);
455+
assert_eq!({ vbe.control_info().signature }, [86, 69, 83, 65]);
456+
assert_eq!({ vbe.control_info().version }, 768);
457+
assert_eq!({ vbe.control_info().oem_string_ptr }, 3221247964);
458458
assert_eq!(
459-
{ vbe.control_info.capabilities },
459+
{ vbe.control_info().capabilities },
460460
VBECapabilities::SWITCHABLE_DAC
461461
);
462-
assert_eq!({ vbe.control_info.mode_list_ptr }, 1610645538);
463-
assert_eq!({ vbe.control_info.total_memory }, 256);
464-
assert_eq!({ vbe.control_info.oem_software_revision }, 0);
465-
assert_eq!({ vbe.control_info.oem_vendor_name_ptr }, 3221247984);
466-
assert_eq!({ vbe.control_info.oem_product_name_ptr }, 3221248003);
467-
assert_eq!({ vbe.control_info.oem_product_revision_ptr }, 3221248023);
468-
assert!({ vbe.mode_info.mode_attributes }.contains(
462+
assert_eq!({ vbe.control_info().mode_list_ptr }, 1610645538);
463+
assert_eq!({ vbe.control_info().total_memory }, 256);
464+
assert_eq!({ vbe.control_info().oem_software_revision }, 0);
465+
assert_eq!({ vbe.control_info().oem_vendor_name_ptr }, 3221247984);
466+
assert_eq!({ vbe.control_info().oem_product_name_ptr }, 3221248003);
467+
assert_eq!({ vbe.control_info().oem_product_revision_ptr }, 3221248023);
468+
assert!({ vbe.mode_info().mode_attributes }.contains(
469469
VBEModeAttributes::SUPPORTED
470470
| VBEModeAttributes::COLOR
471471
| VBEModeAttributes::GRAPHICS
472472
| VBEModeAttributes::NOT_VGA_COMPATIBLE
473473
| VBEModeAttributes::LINEAR_FRAMEBUFFER
474474
));
475-
assert!(vbe.mode_info.window_a_attributes.contains(
475+
assert!(vbe.mode_info().window_a_attributes.contains(
476476
VBEWindowAttributes::RELOCATABLE
477477
| VBEWindowAttributes::READABLE
478478
| VBEWindowAttributes::WRITEABLE
479479
));
480-
assert_eq!({ vbe.mode_info.window_granularity }, 64);
481-
assert_eq!({ vbe.mode_info.window_size }, 64);
482-
assert_eq!({ vbe.mode_info.window_a_segment }, 40960);
483-
assert_eq!({ vbe.mode_info.window_function_ptr }, 3221247162);
484-
assert_eq!({ vbe.mode_info.pitch }, 5120);
485-
assert_eq!({ vbe.mode_info.resolution }, (1280, 800));
486-
assert_eq!(vbe.mode_info.character_size, (8, 16));
487-
assert_eq!(vbe.mode_info.number_of_planes, 1);
488-
assert_eq!(vbe.mode_info.bpp, 32);
489-
assert_eq!(vbe.mode_info.number_of_banks, 1);
490-
assert_eq!(vbe.mode_info.memory_model, VBEMemoryModel::DirectColor);
491-
assert_eq!(vbe.mode_info.bank_size, 0);
492-
assert_eq!(vbe.mode_info.number_of_image_pages, 3);
480+
assert_eq!({ vbe.mode_info().window_granularity }, 64);
481+
assert_eq!({ vbe.mode_info().window_size }, 64);
482+
assert_eq!({ vbe.mode_info().window_a_segment }, 40960);
483+
assert_eq!({ vbe.mode_info().window_function_ptr }, 3221247162);
484+
assert_eq!({ vbe.mode_info().pitch }, 5120);
485+
assert_eq!({ vbe.mode_info().resolution }, (1280, 800));
486+
assert_eq!(vbe.mode_info().character_size, (8, 16));
487+
assert_eq!(vbe.mode_info().number_of_planes, 1);
488+
assert_eq!(vbe.mode_info().bpp, 32);
489+
assert_eq!(vbe.mode_info().number_of_banks, 1);
490+
assert_eq!(vbe.mode_info().memory_model, VBEMemoryModel::DirectColor);
491+
assert_eq!(vbe.mode_info().bank_size, 0);
492+
assert_eq!(vbe.mode_info().number_of_image_pages, 3);
493493
assert_eq!(
494-
vbe.mode_info.red_field,
494+
vbe.mode_info().red_field,
495495
VBEField {
496496
position: 16,
497497
size: 8,
498498
}
499499
);
500500
assert_eq!(
501-
vbe.mode_info.green_field,
501+
vbe.mode_info().green_field,
502502
VBEField {
503503
position: 8,
504504
size: 8,
505505
}
506506
);
507507
assert_eq!(
508-
vbe.mode_info.blue_field,
508+
vbe.mode_info().blue_field,
509509
VBEField {
510510
position: 0,
511511
size: 8,
512512
}
513513
);
514514
assert_eq!(
515-
vbe.mode_info.reserved_field,
515+
vbe.mode_info().reserved_field,
516516
VBEField {
517517
position: 24,
518518
size: 8,
519519
}
520520
);
521521
assert_eq!(
522-
vbe.mode_info.direct_color_attributes,
522+
vbe.mode_info().direct_color_attributes,
523523
VBEDirectColorAttributes::RESERVED_USABLE
524524
);
525-
assert_eq!({ vbe.mode_info.framebuffer_base_ptr }, 4244635648);
526-
assert_eq!({ vbe.mode_info.offscreen_memory_offset }, 0);
527-
assert_eq!({ vbe.mode_info.offscreen_memory_size }, 0);
525+
assert_eq!({ vbe.mode_info().framebuffer_base_ptr }, 4244635648);
526+
assert_eq!({ vbe.mode_info().offscreen_memory_offset }, 0);
527+
assert_eq!({ vbe.mode_info().offscreen_memory_size }, 0);
528528
}
529529

530530
#[test]

multiboot2/src/vbe_info.rs

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,86 @@
11
//! Module for [`VBEInfoTag`].
22
3-
use crate::{TagHeader, TagTrait, TagType, TagTypeId};
3+
use crate::{TagHeader, TagTrait, TagType};
44
use core::fmt;
5+
use core::mem;
56

67
/// This tag contains VBE metadata, VBE controller information returned by the
78
/// VBE Function 00h and VBE mode information returned by the VBE Function 01h.
89
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
910
#[repr(C, align(8))]
1011
pub struct VBEInfoTag {
11-
typ: TagTypeId,
12-
length: u32,
12+
header: TagHeader,
13+
mode: u16,
14+
interface_segment: u16,
15+
interface_offset: u16,
16+
interface_length: u16,
17+
control_info: VBEControlInfo,
18+
mode_info: VBEModeInfo,
19+
}
20+
21+
impl VBEInfoTag {
22+
/// Constructs a new tag.
23+
#[cfg(feature = "builder")]
24+
#[must_use]
25+
pub fn new(
26+
mode: u16,
27+
interface_segment: u16,
28+
interface_offset: u16,
29+
interface_length: u16,
30+
control_info: VBEControlInfo,
31+
mode_info: VBEModeInfo,
32+
) -> Self {
33+
Self {
34+
header: TagHeader::new(Self::ID, mem::size_of::<Self>().try_into().unwrap()),
35+
mode,
36+
interface_segment,
37+
interface_offset,
38+
interface_length,
39+
control_info,
40+
mode_info,
41+
}
42+
}
1343

1444
/// Indicates current video mode in the format specified in VBE 3.0.
15-
pub mode: u16,
45+
#[must_use]
46+
pub const fn mode(&self) -> u16 {
47+
self.mode
48+
}
1649

17-
/// Contain the segment of the table of a protected mode interface defined in VBE 2.0+.
50+
/// Returns the segment of the table of a protected mode interface defined in VBE 2.0+.
1851
///
1952
/// If the information for a protected mode interface is not available
2053
/// this field is set to zero.
21-
pub interface_segment: u16,
22-
23-
/// Contain the segment offset of the table of a protected mode interface defined in VBE 2.0+.
54+
#[must_use]
55+
pub const fn interface_segment(&self) -> u16 {
56+
self.interface_segment
57+
}
58+
/// Returns the segment offset of the table of a protected mode interface defined in VBE 2.0+.
2459
///
2560
/// If the information for a protected mode interface is not available
2661
/// this field is set to zero.
27-
pub interface_offset: u16,
28-
29-
/// Contain the segment length of the table of a protected mode interface defined in VBE 2.0+.
62+
#[must_use]
63+
pub const fn interface_offset(&self) -> u16 {
64+
self.interface_offset
65+
}
66+
/// Returns the segment length of the table of a protected mode interface defined in VBE 2.0+.
3067
///
3168
/// If the information for a protected mode interface is not available
3269
/// this field is set to zero.
33-
pub interface_length: u16,
34-
35-
/// Contains VBE controller information returned by the VBE Function `00h`.
36-
pub control_info: VBEControlInfo,
37-
38-
/// Contains VBE mode information returned by the VBE Function `01h`.
39-
pub mode_info: VBEModeInfo,
70+
#[must_use]
71+
pub const fn interface_length(&self) -> u16 {
72+
self.interface_length
73+
}
74+
/// Returns VBE controller information returned by the VBE Function `00h`.
75+
#[must_use]
76+
pub const fn control_info(&self) -> VBEControlInfo {
77+
self.control_info
78+
}
79+
/// Returns VBE mode information returned by the VBE Function `01h`.
80+
#[must_use]
81+
pub const fn mode_info(&self) -> VBEModeInfo {
82+
self.mode_info
83+
}
4084
}
4185

4286
impl TagTrait for VBEInfoTag {

0 commit comments

Comments
 (0)