Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating from 0.9 to 0.11 -- unresolved imports MemoryMap and MemoryRegionType #442

Closed
nschmoyer opened this issue May 15, 2024 · 2 comments

Comments

@nschmoyer
Copy link

Blog_OS V2 provided a memory.rs module, which contains the following code:

use bootloader::boot_info::{MemoryMap, MemoryRegionType};

...

/// A FrameAllocator that returns usable frames from the bootloader's memory map.
pub struct BootInfoFrameAllocator {
    memory_map: &'static MemoryMap,
    next: usize,
}

...

impl BootInfoFrameAllocator {
    /// Create a FrameAllocator from the passed memory map.
    ///
    /// This function is unsafe because the caller must guarantee that the passed
    /// memory map is valid. The main requirement is that all frames that are marked
    /// as `USABLE` in it are really unused.
    pub unsafe fn init(memory_map: &'static MemoryMap) -> Self {
        BootInfoFrameAllocator {
            memory_map,
            next: 0,
        }
    }

    /// Returns an iterator over the usable frames specified in the memory map.
    fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> {
        // get usable regions from memory map
        let regions = self.memory_map.iter();
        let usable_regions = regions.filter(|r| r.region_type == MemoryRegionType::Usable);
        // map each region to its address range
        let addr_ranges = usable_regions.map(|r| r.range.start_addr()..r.range.end_addr());
        // transform to an iterator of frame start addresses
        let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
        // create `PhysFrame` types from the start addresses
        frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr)))
    }
}

And the initialization occurs in kernel_main of main.rs:

let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
let mut mapper = unsafe { kernel::memory::init(phys_mem_offset) };

After upgrading to v0.11 and replacing the kernel crate with bootloader_api, MemoryMap and MemoryRegionType are no longer found. What is the appropriate way to update these structs?

@bjorn3
Copy link
Contributor

bjorn3 commented May 15, 2024

The second edition of blog os depends on bootloader 0.9. Bootloader 0.11 doesn't just have a different api, but also requires building the kernel in a significantly different way. If you want to use bootloader 0.11, you have to use the work in progress third edition of blog os.

@nschmoyer
Copy link
Author

I was able to get it working (and the rest of my existing kernel code, for that matter) by using bits and pieces of code from the third edition (or at least, what's there so far) and some of the common code from this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants