Skip to main content

multiboot2_header/
entry_efi_64.rs

1use crate::{HeaderTagFlag, HeaderTagHeader, HeaderTagType};
2use core::fmt;
3use core::fmt::{Debug, Formatter};
4use multiboot2_common::{MaybeDynSized, Tag};
5
6/// Contains the entry address for EFI amd64 machine state.
7///
8/// This tag is taken into account only on EFI amd64 platforms when Multiboot2 image header
9/// contains EFI boot services tag. Then entry point specified in ELF header and the entry address
10/// tag of Multiboot2 header are ignored.
11///
12/// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different
13/// [`crate::HeaderTagType`].
14#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
15#[repr(C, align(8))]
16pub struct EntryEfi64HeaderTag {
17    header: HeaderTagHeader,
18    entry_addr: u32,
19}
20
21impl EntryEfi64HeaderTag {
22    /// Constructs a new tag.
23    #[must_use]
24    pub const fn new(flags: HeaderTagFlag, entry_addr: u32) -> Self {
25        let header = HeaderTagHeader::new(
26            HeaderTagType::EntryAddressEFI64,
27            flags,
28            Self::BASE_SIZE as u32,
29        );
30        Self { header, entry_addr }
31    }
32
33    /// Returns the [`HeaderTagType`].
34    #[must_use]
35    pub const fn typ(&self) -> HeaderTagType {
36        self.header.typ()
37    }
38
39    /// Returns the [`HeaderTagFlag`]s.
40    #[must_use]
41    pub const fn flags(&self) -> HeaderTagFlag {
42        self.header.flags()
43    }
44
45    /// Returns the size.
46    #[must_use]
47    pub const fn size(&self) -> u32 {
48        self.header.size()
49    }
50
51    /// Returns the entry address.
52    #[must_use]
53    pub const fn entry_addr(&self) -> u32 {
54        self.entry_addr
55    }
56}
57
58impl Debug for EntryEfi64HeaderTag {
59    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
60        f.debug_struct("EntryEfi64HeaderTag")
61            .field("type", &self.typ())
62            .field("flags", &self.flags())
63            .field("size", &self.size())
64            .field("entry_addr", &self.entry_addr)
65            .finish()
66    }
67}
68
69impl MaybeDynSized for EntryEfi64HeaderTag {
70    type Header = HeaderTagHeader;
71
72    const BASE_SIZE: usize = size_of::<HeaderTagHeader>() + size_of::<u32>();
73}
74
75impl Tag for EntryEfi64HeaderTag {
76    type IDType = HeaderTagType;
77    const ID: HeaderTagType = HeaderTagType::EntryAddressEFI64;
78}