entry_address.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. use crate::{HeaderTagFlag, HeaderTagType};
  2. use core::fmt;
  3. use core::fmt::{Debug, Formatter};
  4. use core::mem::size_of;
  5. /// Specifies the physical address to which the boot loader should jump in
  6. /// order to start running the operating system. Not needed for ELF files.
  7. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
  8. #[repr(C)]
  9. pub struct EntryAddressHeaderTag {
  10. typ: HeaderTagType,
  11. flags: HeaderTagFlag,
  12. size: u32,
  13. entry_addr: u32,
  14. }
  15. impl EntryAddressHeaderTag {
  16. pub const fn new(flags: HeaderTagFlag, entry_addr: u32) -> Self {
  17. EntryAddressHeaderTag {
  18. typ: HeaderTagType::EntryAddress,
  19. flags,
  20. size: size_of::<Self>() as u32,
  21. entry_addr,
  22. }
  23. }
  24. pub const fn typ(&self) -> HeaderTagType {
  25. self.typ
  26. }
  27. pub const fn flags(&self) -> HeaderTagFlag {
  28. self.flags
  29. }
  30. pub const fn size(&self) -> u32 {
  31. self.size
  32. }
  33. pub const fn entry_addr(&self) -> u32 {
  34. self.entry_addr
  35. }
  36. }
  37. impl Debug for EntryAddressHeaderTag {
  38. fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
  39. f.debug_struct("EntryAddressHeaderTag")
  40. .field("type", &{ self.typ })
  41. .field("flags", &{ self.flags })
  42. .field("size", &{ self.size })
  43. .field("entry_addr", &(self.entry_addr as *const u32))
  44. .finish()
  45. }
  46. }
  47. #[cfg(test)]
  48. mod tests {
  49. use crate::EntryAddressHeaderTag;
  50. #[test]
  51. fn test_assert_size() {
  52. assert_eq!(core::mem::size_of::<EntryAddressHeaderTag>(), 2 + 2 + 4 + 4);
  53. }
  54. }