Skip to content

Commit

Permalink
fix: remove static mut multiboot memory management
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Apr 2, 2024
1 parent 0cb21fd commit 9273860
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/arch/x86_64/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use alloc::format;
use multiboot::information::{MemoryType, Multiboot};
use vm_fdt::{Error as FdtError, FdtWriter};

use super::{mb_info, MEM};
use super::{mb_info, Mem};

pub struct DeviceTree;

impl DeviceTree {
#[cfg(all(target_os = "none", not(feature = "fc")))]
pub fn create() -> Result<&'static [u8], FdtError> {
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut MEM).unwrap() };
let mut mem = Mem;
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut mem).unwrap() };

let all_regions = multiboot
.memory_regions()
Expand Down
8 changes: 4 additions & 4 deletions src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ static mut COM1: SerialPort = unsafe { SerialPort::new(SERIAL_IO_PORT) };

#[cfg(all(target_os = "none", not(feature = "fc")))]
struct Mem;
#[cfg(all(target_os = "none", not(feature = "fc")))]
static mut MEM: Mem = Mem;

#[cfg(all(target_os = "none", not(feature = "fc")))]
impl MemoryManagement for Mem {
Expand Down Expand Up @@ -213,8 +211,9 @@ pub fn find_kernel() -> &'static [u8] {
let page_address = unsafe { mb_info.align_down(Size4KiB::SIZE as usize) };
paging::map::<Size4KiB>(page_address, page_address, 1, PageTableFlags::empty());

let mut mem = Mem;
// Load the Multiboot information and identity-map the modules information.
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut MEM).unwrap() };
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut mem).unwrap() };
let modules_address = multiboot
.modules()
.expect("Could not find a memory map in the Multiboot information")
Expand Down Expand Up @@ -440,7 +439,8 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
entry_point,
} = kernel_info;

let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut MEM).unwrap() };
let mut mem = Mem;
let multiboot = unsafe { Multiboot::from_ptr(mb_info as u64, &mut mem).unwrap() };

// determine boot stack address
let mut new_stack = ptr::addr_of!(kernel_end)
Expand Down

0 comments on commit 9273860

Please sign in to comment.