Browse Source

multiboot2: Implement setting the BasicMemoryInfoTag

Niklas Sombert 2 years ago
parent
commit
03201482a1
2 changed files with 22 additions and 2 deletions
  1. 10 1
      multiboot2/src/builder/information.rs
  2. 12 1
      multiboot2/src/memory_map.rs

+ 10 - 1
multiboot2/src/builder/information.rs

@@ -1,6 +1,9 @@
 //! Exports item [`Multiboot2InformationBuilder`].
 use crate::builder::traits::StructAsBytes;
-use crate::{BootLoaderNameTag, CommandLineTag, ElfSectionsTag, FramebufferTag, ModuleTag};
+use crate::{
+    BasicMemoryInfoTag, BootLoaderNameTag, CommandLineTag, ElfSectionsTag, FramebufferTag,
+    ModuleTag,
+};
 
 use alloc::boxed::Box;
 use alloc::vec::Vec;
@@ -10,6 +13,7 @@ use alloc::vec::Vec;
 /// except for the END tag.
 #[derive(Debug)]
 pub struct Multiboot2InformationBuilder {
+    basic_memory_info_tag: Option<BasicMemoryInfoTag>,
     boot_loader_name_tag: Option<Box<BootLoaderNameTag>>,
     command_line_tag: Option<Box<CommandLineTag>>,
     elf_sections_tag: Option<Box<ElfSectionsTag>>,
@@ -20,6 +24,7 @@ pub struct Multiboot2InformationBuilder {
 impl Multiboot2InformationBuilder {
     pub const fn new() -> Self {
         Self {
+            basic_memory_info_tag: None,
             boot_loader_name_tag: None,
             command_line_tag: None,
             elf_sections_tag: None,
@@ -28,6 +33,10 @@ impl Multiboot2InformationBuilder {
         }
     }
 
+    pub fn basic_memory_info_tag(&mut self, basic_memory_info_tag: BasicMemoryInfoTag) {
+        self.basic_memory_info_tag = Some(basic_memory_info_tag)
+    }
+
     pub fn bootloader_name_tag(&mut self, boot_loader_name_tag: Box<BootLoaderNameTag>) {
         self.boot_loader_name_tag = Some(boot_loader_name_tag);
     }

+ 12 - 1
multiboot2/src/memory_map.rs

@@ -1,5 +1,7 @@
-use crate::TagTypeId;
+use crate::tag_type::{TagType, TagTypeId};
+use core::convert::TryInto;
 use core::marker::PhantomData;
+use core::mem;
 
 /// This tag provides an initial host memory map.
 ///
@@ -149,6 +151,15 @@ pub struct BasicMemoryInfoTag {
 }
 
 impl BasicMemoryInfoTag {
+    pub fn new(memory_lower: u32, memory_upper: u32) -> Self {
+        Self {
+            typ: TagType::BasicMeminfo.into(),
+            size: mem::size_of::<BasicMemoryInfoTag>().try_into().unwrap(),
+            memory_lower,
+            memory_upper,
+        }
+    }
+
     pub fn memory_lower(&self) -> u32 {
         self.memory_lower
     }