entry_efi_32.rs 2.0 KB

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