entry_efi_64.rs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /// 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))]
  16. pub struct EntryEfi64HeaderTag {
  17. header: HeaderTagHeader,
  18. entry_addr: u32,
  19. }
  20. impl EntryEfi64HeaderTag {
  21. /// Constructs a new tag.
  22. #[must_use]
  23. pub const fn new(flags: HeaderTagFlag, entry_addr: u32) -> Self {
  24. let header = HeaderTagHeader::new(
  25. HeaderTagType::EntryAddressEFI64,
  26. flags,
  27. Self::BASE_SIZE as u32,
  28. );
  29. Self { header, entry_addr }
  30. }
  31. /// Returns the [`HeaderTagType`].
  32. #[must_use]
  33. pub const fn typ(&self) -> HeaderTagType {
  34. self.header.typ()
  35. }
  36. /// Returns the [`HeaderTagFlag`]s.
  37. #[must_use]
  38. pub const fn flags(&self) -> HeaderTagFlag {
  39. self.header.flags()
  40. }
  41. /// Returns the size.
  42. #[must_use]
  43. pub const fn size(&self) -> u32 {
  44. self.header.size()
  45. }
  46. /// Returns the entry address.
  47. #[must_use]
  48. pub const fn entry_addr(&self) -> u32 {
  49. self.entry_addr
  50. }
  51. }
  52. impl Debug for EntryEfi64HeaderTag {
  53. fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
  54. f.debug_struct("EntryEfi64HeaderTag")
  55. .field("type", &self.typ())
  56. .field("flags", &self.flags())
  57. .field("size", &self.size())
  58. .field("entry_addr", &(self.entry_addr as *const u32))
  59. .finish()
  60. }
  61. }
  62. impl MaybeDynSized for EntryEfi64HeaderTag {
  63. type Header = HeaderTagHeader;
  64. const BASE_SIZE: usize = mem::size_of::<HeaderTagHeader>() + mem::size_of::<u32>();
  65. fn dst_len(_header: &Self::Header) -> Self::Metadata {}
  66. }
  67. impl Tag for EntryEfi64HeaderTag {
  68. type IDType = HeaderTagType;
  69. const ID: HeaderTagType = HeaderTagType::EntryAddressEFI64;
  70. }