Skip to content

Access RSDP from BootInfo #141

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

Closed
Andy-Python-Programmer opened this issue Mar 22, 2021 · 5 comments
Closed

Access RSDP from BootInfo #141

Andy-Python-Programmer opened this issue Mar 22, 2021 · 5 comments

Comments

@Andy-Python-Programmer
Copy link

Is there a way to access the RSDP from boot info?

https://wiki.osdev.org/RSDP

@phil-opp
Copy link
Member

Not yet, but the upcoming version in #130 will include the RSDP in the boot info. You can try to use https://docs.rs/acpi/2.3.0/acpi/struct.AcpiTables.html#method.search_for_rsdp_bios directly until then.

@Andy-Python-Programmer
Copy link
Author

Is there any example to help integrate it with boot loader. As it requires a handler. Do I have to make my own one it’s not documented @phil-opp

@phil-opp
Copy link
Member

The function works by scanning certain physical memory regions for the RSDP signature (see https://wiki.osdev.org/RSDP#Detecting_the_RSDP ). For this is needs access to physical memory. This is what the handler is for.

You can create your own handler by implementing the AcpiHandler trait. For this you need to provide methods to map and unmap physical memory pages. If you're using the map-physical-memory feature of the bootloader, you don't need to do any actual mapping in it as you can just add the offset.

For an example implementation, this is how we implemented it in the upcoming new version of the bootloader crate:

bootloader/src/bin/bios.rs

Lines 193 to 225 in 873351c

fn detect_rsdp() -> Option<PhysAddr> {
use core::ptr::NonNull;
use rsdp::{
handler::{AcpiHandler, PhysicalMapping},
Rsdp,
};
#[derive(Clone)]
struct IdentityMapped;
impl AcpiHandler for IdentityMapped {
unsafe fn map_physical_region<T>(
&self,
physical_address: usize,
size: usize,
) -> PhysicalMapping<Self, T> {
PhysicalMapping {
physical_start: physical_address,
virtual_start: NonNull::new(physical_address as *mut _).unwrap(),
region_length: size,
mapped_length: size,
handler: Self,
}
}
fn unmap_physical_region<T>(&self, _region: &PhysicalMapping<Self, T>) {}
}
unsafe {
Rsdp::search_for_on_bios(IdentityMapped)
.ok()
.map(|mapping| PhysAddr::new(mapping.physical_start as u64))
}
}

Instead of an identity mapping, you probably have the physical memory mapped at an offset, which you need to add to the address when filling the virtual_start field of the PhysicalMapping.

Hope this helps!

@Andy-Python-Programmer
Copy link
Author

It does. Thanks!

@Andy-Python-Programmer
Copy link
Author

Closing as version 0.10.0 is released!

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