entry_efi_64.rs 2.2 KB

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