Verified Commit adfeb79e authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Ensure physical memory passed to the kernel are within the 8 GiB mapping

parent 944189f6
use std::vec::Vec;
use std::{slice, vec::Vec};
use uefi::guid::GuidKind;
pub(crate) static mut RSDPS_AREA: Option<Vec<u8>> = None;
use crate::{Disk, Os, OsVideoMode};
pub(crate) static mut RSDPS_AREA_BASE: *mut u8 = 0 as *mut u8;
pub(crate) static mut RSDPS_AREA_SIZE: usize = 0;
struct Invalid;
......@@ -53,11 +56,11 @@ fn validate_rsdp(address: usize, v2: bool) -> core::result::Result<usize, Invali
Ok(length)
}
pub(crate) fn find_acpi_table_pointers() {
let rsdps_area = unsafe {
RSDPS_AREA = Some(Vec::new());
RSDPS_AREA.as_mut().unwrap()
};
pub(crate) fn find_acpi_table_pointers<
D: Disk,
V: Iterator<Item=OsVideoMode>
>(os: &mut dyn Os<D, V>) {
let mut rsdps_area = Vec::new();
let cfg_tables = std::system_table().config_tables();
......@@ -81,4 +84,16 @@ pub(crate) fn find_acpi_table_pointers() {
Err(_) => log::warn!("Found RSDP that was not valid at {:p}", address as *const u8),
}
}
if ! rsdps_area.is_empty() {
unsafe {
// Copy to page aligned area
RSDPS_AREA_SIZE = rsdps_area.len();
RSDPS_AREA_BASE = os.alloc_zeroed_page_aligned(RSDPS_AREA_SIZE);
slice::from_raw_parts_mut(
RSDPS_AREA_BASE,
RSDPS_AREA_SIZE
).copy_from_slice(&rsdps_area);
}
}
}
use core::{mem, ptr};
use std::vec::Vec;
use uefi::status::Result;
use crate::{
......@@ -10,7 +9,8 @@ use crate::{
use super::super::{
OsEfi,
acpi::{
RSDPS_AREA,
RSDPS_AREA_BASE,
RSDPS_AREA_SIZE,
find_acpi_table_pointers,
},
memory_map::memory_map,
......@@ -62,17 +62,20 @@ pub fn main() -> Result<()> {
//TODO: support this in addition to ACPI?
// let dtb = find_dtb()?;
find_acpi_table_pointers();
let mut os = OsEfi {
st: std::system_table(),
};
// Disable cursor
let _ = (os.st.ConsoleOut.EnableCursor)(os.st.ConsoleOut, false);
find_acpi_table_pointers(&mut os);
let (page_phys, mut args) = crate::main(&mut os);
unsafe {
args.acpi_rsdps_base = RSDPS_AREA.as_ref().map(Vec::as_ptr).unwrap_or(core::ptr::null()) as usize as u64 + PHYS_OFFSET;
args.acpi_rsdps_size = RSDPS_AREA.as_ref().map(Vec::len).unwrap_or(0) as u64;
args.acpi_rsdps_base = RSDPS_AREA_BASE as u64;
args.acpi_rsdps_size = RSDPS_AREA_SIZE as u64;
kernel_entry(
page_phys,
......
use core::{mem, ptr};
use std::vec::Vec;
use uefi::status::Result;
use x86::{
controlregs::{self, Cr0, Cr4},
......@@ -14,7 +13,8 @@ use crate::{
use super::super::{
OsEfi,
acpi::{
RSDPS_AREA,
RSDPS_AREA_BASE,
RSDPS_AREA_SIZE,
find_acpi_table_pointers,
},
memory_map::memory_map,
......@@ -72,17 +72,20 @@ unsafe extern "C" fn kernel_entry(
pub fn main() -> Result<()> {
LOGGER.init();
find_acpi_table_pointers();
let mut os = OsEfi {
st: std::system_table(),
};
// Disable cursor
let _ = (os.st.ConsoleOut.EnableCursor)(os.st.ConsoleOut, false);
find_acpi_table_pointers(&mut os);
let (page_phys, mut args) = crate::main(&mut os);
unsafe {
args.acpi_rsdps_base = RSDPS_AREA.as_ref().map(Vec::as_ptr).unwrap_or(core::ptr::null()) as usize as u64 + PHYS_OFFSET;
args.acpi_rsdps_size = RSDPS_AREA.as_ref().map(Vec::len).unwrap_or(0) as u64;
args.acpi_rsdps_base = RSDPS_AREA_BASE as u64;
args.acpi_rsdps_size = RSDPS_AREA_SIZE as u64;
kernel_entry(
page_phys,
......
......@@ -59,10 +59,11 @@ impl Os<
let pages = (size + page_size - 1) / page_size;
let ptr = {
let mut ptr = 0;
// Max address mapped by src/arch paging code (8 GiB)
let mut ptr = 0x2_0000_0000;
status_to_result(
(self.st.BootServices.AllocatePages)(
0, // AllocateAnyPages
1, // AllocateMaxAddress
MemoryType::EfiRuntimeServicesData, // Keeps this memory out of free space list
pages,
&mut ptr
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment