浏览代码

Merge pull request #61 from CWood1/patch-1

Add MemoryAreaType, to allow users to access memory area types in a type-safe way
Rob Gries 5 年之前
父节点
当前提交
d3a6f022c7
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 4 1
      src/lib.rs
  2. 19 0
      src/memory_map.rs

+ 4 - 1
src/lib.rs

@@ -7,7 +7,7 @@ use header::{Tag, TagIter};
 pub use boot_loader_name::BootLoaderNameTag;
 pub use elf_sections::{ElfSectionsTag, ElfSection, ElfSectionIter, ElfSectionType, ElfSectionFlags};
 pub use framebuffer::{FramebufferTag, FramebufferType, FramebufferField, FramebufferColor};
-pub use memory_map::{MemoryMapTag, MemoryArea, MemoryAreaIter};
+pub use memory_map::{MemoryMapTag, MemoryArea, MemoryAreaType, MemoryAreaIter};
 pub use module::{ModuleTag, ModuleIter};
 pub use command_line::CommandLineTag;
 pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
@@ -223,6 +223,7 @@ mod tests {
     use super::{load, load_with_offset};
     use super::{BootInformation, ElfSectionFlags, ElfSectionType};
     use super::FramebufferType;
+    use super::MemoryAreaType;
 
     #[test]
     fn no_tags() {
@@ -1066,10 +1067,12 @@ mod tests {
         assert_eq!(0x00000000, mm1.start_address());
         assert_eq!(0x009_FC00, mm1.end_address());
         assert_eq!(0x009_FC00, mm1.size());
+        assert_eq!(MemoryAreaType::Available, mm1.typ());
         let mm2 = mm.next().unwrap();
         assert_eq!(0x010_0000, mm2.start_address());
         assert_eq!(0x7FE_0000, mm2.end_address());
         assert_eq!(0x7EE_0000, mm2.size());
+        assert_eq!(MemoryAreaType::Available, mm2.typ());
         assert!(mm.next().is_none());
 
         // Test the RSDP tag

+ 19 - 0
src/memory_map.rs

@@ -44,6 +44,25 @@ impl MemoryArea {
     pub fn size(&self) -> u64 {
         self.length
     }
+
+    pub fn typ(&self) -> MemoryAreaType {
+        match self.typ {
+            1 => MemoryAreaType::Available,
+            3 => MemoryAreaType::AcpiAvailable,
+            4 => MemoryAreaType::ReservedHibernate,
+            5 => MemoryAreaType::Defective,
+            _ => MemoryAreaType::Reserved,
+        }
+    }
+}
+
+#[derive(Debug, PartialEq, Eq)]
+pub enum MemoryAreaType {
+    Reserved,
+    Available,
+    AcpiAvailable,
+    ReservedHibernate,
+    Defective,
 }
 
 #[derive(Clone, Debug)]