瀏覽代碼

multiboot2: Add BasicMemoryInfoTag

Niklas Sombert 2 年之前
父節點
當前提交
4bf969f2fb
共有 2 個文件被更改,包括 42 次插入2 次删除
  1. 7 2
      multiboot2/src/lib.rs
  2. 35 0
      multiboot2/src/memory_map.rs

+ 7 - 2
multiboot2/src/lib.rs

@@ -52,8 +52,8 @@ pub use elf_sections::{
 pub use framebuffer::{FramebufferColor, FramebufferField, FramebufferTag, FramebufferType};
 pub use image_load_addr::ImageLoadPhysAddr;
 pub use memory_map::{
-    EFIMemoryAreaType, EFIMemoryDesc, EFIMemoryMapTag, MemoryArea, MemoryAreaIter, MemoryAreaType,
-    MemoryMapTag,
+    BasicMemoryInfoTag, EFIMemoryAreaType, EFIMemoryDesc, EFIMemoryMapTag, MemoryArea,
+    MemoryAreaIter, MemoryAreaType, MemoryMapTag,
 };
 pub use module::{ModuleIter, ModuleTag};
 pub use rsdp::{RsdpV1Tag, RsdpV2Tag};
@@ -218,6 +218,11 @@ impl BootInformation {
         self.get().total_size as usize
     }
 
+    /// Search for the basic memory info tag.
+    pub fn basic_memory_info_tag(&self) -> Option<&BasicMemoryInfoTag> {
+        self.get_tag::<BasicMemoryInfoTag, _>(TagType::BasicMeminfo)
+    }
+
     /// Search for the ELF Sections tag.
     pub fn elf_sections_tag(&self) -> Option<ElfSectionsTag> {
         self.get_tag::<Tag, _>(TagType::ElfSections)

+ 35 - 0
multiboot2/src/memory_map.rs

@@ -123,6 +123,41 @@ impl<'a> Iterator for MemoryAreaIter<'a> {
     }
 }
 
+/// Basic memory info
+///
+/// This tag includes "basic memory information".
+/// This means (legacy) lower and upper memory:
+/// In Real Mode (modeled after the 8086),
+/// only the first 1MB of memory is accessible.
+/// Typically, the region between 640KB and 1MB is not freely usable,
+/// because it is used for memory-mapped IO, for instance.
+/// The term “lower memory” refers to those first 640KB of memory that are
+/// freely usable for an application in Real Mode.
+/// “Upper memory” then refers to the next freely usable chunk of memory,
+/// starting at 1MB up to about 10MB, in practice.
+/// This is the memory an application running on a 286
+/// (which had a 24-bit address bus) could use, historically.
+/// Nowadays, much bigger chunks of continuous memory are available at higher
+/// addresses, but the Multiboot standard still references those two terms.
+#[derive(Debug)]
+#[repr(C, packed)]
+pub struct BasicMemoryInfoTag {
+    typ: TagTypeId,
+    size: u32,
+    memory_lower: u32,
+    memory_upper: u32,
+}
+
+impl BasicMemoryInfoTag {
+    pub fn memory_lower(&self) -> u32 {
+        self.memory_lower
+    }
+
+    pub fn memory_upper(&self) -> u32 {
+        self.memory_upper
+    }
+}
+
 /// EFI memory map as per EFI specification.
 #[derive(Debug)]
 #[repr(C)]