You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

  1. use arch::x86_64::memory::Frame;
  2. pub struct Entry(u64);
  3. impl Entry {
  4. pub fn is_unused(&self) -> bool {
  5. self.0 == 0
  6. }
  7. pub fn set_unused(&mut self) {
  8. self.0 = 0;
  9. }
  10. pub fn flags(&self) -> EntryFlags {
  11. EntryFlags::from_bits_truncate(self.0)
  12. }
  13. pub fn pointed_frame(&self) -> Option<Frame> {
  14. if self.flags().contains(PRESENT) {
  15. Some(Frame::containing_address(
  16. self.0 as usize & 0x000fffff_fffff000
  17. ))
  18. } else {
  19. None
  20. }
  21. }
  22. pub fn set(&mut self, frame: Frame, flags: EntryFlags) {
  23. // Frame physical address must be page-aligned and smaller than 2^52
  24. assert!(frame.start_address() & !0x000fffff_fffff000 == 0);
  25. self.0 = (frame.start_address() as u64) | flags.bits();
  26. }
  27. }
  28. bitflags! {
  29. pub struct EntryFlags: u64 {
  30. const PRESENT = 1 << 0;
  31. const WRITABLE = 1 << 1;
  32. const USER_ACCESSIBLE = 1 << 2;
  33. const WRITE_THROUGH = 1 << 3;
  34. const NO_CACHE = 1 << 4;
  35. const ACCESSED = 1 << 5;
  36. const DIRTY = 1 << 6;
  37. const HUGE_PAGE = 1 << 7;
  38. const GLOBAL = 1 << 8;
  39. const NO_EXECUTE = 1 << 63;
  40. }
  41. }