entry_header.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.
  7. /// Not needed for ELF files.
  8. #[derive(Copy, Clone)]
  9. #[repr(C, packed(8))]
  10. pub struct EntryHeaderTag {
  11. typ: HeaderTagType,
  12. flags: HeaderTagFlag,
  13. size: u32,
  14. entry_addr: u32,
  15. }
  16. impl EntryHeaderTag {
  17. pub const fn new(flags: HeaderTagFlag, entry_addr: u32) -> Self {
  18. EntryHeaderTag {
  19. typ: HeaderTagType::EntryAddress,
  20. flags,
  21. size: size_of::<Self>() as u32,
  22. entry_addr,
  23. }
  24. }
  25. pub const fn typ(&self) -> HeaderTagType {
  26. self.typ
  27. }
  28. pub const fn flags(&self) -> HeaderTagFlag {
  29. self.flags
  30. }
  31. pub const fn size(&self) -> u32 {
  32. self.size
  33. }
  34. pub const fn entry_addr(&self) -> u32 {
  35. self.entry_addr
  36. }
  37. }
  38. impl Debug for EntryHeaderTag {
  39. fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
  40. f.debug_struct("EntryHeaderTag")
  41. .field("type", &{ self.typ })
  42. .field("flags", &{ self.flags })
  43. .field("size", &{ self.size })
  44. .field("entry_addr", &(self.entry_addr as *const u32))
  45. .finish()
  46. }
  47. }