multiboot2_header/
entry_efi_64.rs

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