console.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. use crate::{HeaderTagFlag, HeaderTagType};
  2. use core::mem::size_of;
  3. /// Possible flags for [`ConsoleHeaderTag`].
  4. #[repr(u32)]
  5. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
  6. pub enum ConsoleHeaderTagFlags {
  7. /// Console required.
  8. ConsoleRequired = 0,
  9. /// EGA text support.
  10. EgaTextSupported = 1,
  11. }
  12. /// Tells that a console must be available in MBI.
  13. /// Only relevant for legacy BIOS.
  14. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
  15. #[repr(C)]
  16. pub struct ConsoleHeaderTag {
  17. typ: HeaderTagType,
  18. flags: HeaderTagFlag,
  19. size: u32,
  20. console_flags: ConsoleHeaderTagFlags,
  21. }
  22. impl ConsoleHeaderTag {
  23. pub const fn new(flags: HeaderTagFlag, console_flags: ConsoleHeaderTagFlags) -> Self {
  24. ConsoleHeaderTag {
  25. typ: HeaderTagType::ConsoleFlags,
  26. flags,
  27. size: size_of::<Self>() as u32,
  28. console_flags,
  29. }
  30. }
  31. pub const fn typ(&self) -> HeaderTagType {
  32. self.typ
  33. }
  34. pub const fn flags(&self) -> HeaderTagFlag {
  35. self.flags
  36. }
  37. pub const fn size(&self) -> u32 {
  38. self.size
  39. }
  40. pub const fn console_flags(&self) -> ConsoleHeaderTagFlags {
  41. self.console_flags
  42. }
  43. }
  44. #[cfg(test)]
  45. mod tests {
  46. use crate::ConsoleHeaderTag;
  47. #[test]
  48. fn test_assert_size() {
  49. assert_eq!(core::mem::size_of::<ConsoleHeaderTag>(), 2 + 2 + 4 + 4);
  50. }
  51. }