diff --git a/src/arch/x86/x64.rs b/src/arch/x86/x64.rs index a0a275a..cad4592 100644 --- a/src/arch/x86/x64.rs +++ b/src/arch/x86/x64.rs @@ -46 +46 @@ pub unsafe fn paging_create(os: &impl Os, kernel_phys: u64, kernel_size: u64) -> - for pdp_i in 0..8 { + for pdp_i in 0..64 { @@ -103 +103 @@ pub unsafe fn paging_framebuffer( - if framebuffer_phys + framebuffer_size <= 0x2_0000_0000 { + if framebuffer_phys + framebuffer_size <= 0x10_0000_0000 { diff --git a/src/main.rs b/src/main.rs index a41086e..1ce4bf3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -560,11 +560 @@ fn main(os: &impl Os) -> (usize, u64, KernelArgs) { - let max_preload: u64 = 128 * MIBI as u64; - let preload_size = if size > max_preload { - println!( - "live: filesystem is {} MiB, capping preload at {} MiB", - size / MIBI as u64, - max_preload / MIBI as u64 - ); - max_preload - } else { - size - }; + let mut preload_size: u64 = size; @@ -572,4 +562,5 @@ fn main(os: &impl Os) -> (usize, u64, KernelArgs) { - print!("live: 0/{} MiB", preload_size / MIBI as u64); - - let live_size = match usize::try_from(preload_size) { - Ok(live_size) => live_size, + let mut ptr = ptr::null_mut(); + if live { + ptr = os.alloc_zeroed_page_aligned( + match usize::try_from(preload_size) { + Ok(s) => s, @@ -581 +572,19 @@ fn main(os: &impl Os) -> (usize, u64, KernelArgs) { - }; + } + ); + if ptr.is_null() && live { + println!( + "\rlive: unable to allocate {} MiB, halving...", + preload_size / MIBI as u64 + ); + let floor: u64 = 128 * MIBI as u64; + while preload_size > floor { + preload_size /= 2; + if let Ok(smaller) = usize::try_from(preload_size) { + ptr = os.alloc_zeroed_page_aligned(smaller); + if !ptr.is_null() { + break; + } + } + } + } + } @@ -583,6 +592 @@ fn main(os: &impl Os) -> (usize, u64, KernelArgs) { - let ptr = if live { - os.alloc_zeroed_page_aligned(live_size) - } else { - ptr::null_mut() - }; - if live && ptr.is_null() { + if ptr.is_null() { @@ -595,0 +600,11 @@ fn main(os: &impl Os) -> (usize, u64, KernelArgs) { + print!("live: 0/{} MiB", preload_size / MIBI as u64); + + let live_size = match usize::try_from(preload_size) { + Ok(live_size) => live_size, + Err(_) => { + println!("\rlive: disabled (image too large for bootloader address space)"); + live = false; + 0 + } + }; + diff --git a/src/os/uefi/mod.rs b/src/os/uefi/mod.rs index d0b2cf1..dacead6 100644 --- a/src/os/uefi/mod.rs +++ b/src/os/uefi/mod.rs @@ -48,2 +48 @@ pub(crate) fn alloc_zeroed_page_aligned(size: usize) -> *mut u8 { - // Max address mapped by src/arch paging code (8 GiB) - let mut ptr = 0x2_0000_0000; + let mut ptr = 0; @@ -51,2 +50,2 @@ pub(crate) fn alloc_zeroed_page_aligned(size: usize) -> *mut u8 { - 1, // AllocateMaxAddress - MemoryType::EfiRuntimeServicesData, // Keeps this memory out of free space list + 0, // AllocateAnyPages + MemoryType::EfiLoaderData, // Valid until ExitBootServices