support low ram machine
Some checks failed
Check / Build ISO (nightly-2025-04-27) (push) Failing after 43s
Some checks failed
Check / Build ISO (nightly-2025-04-27) (push) Failing after 43s
This commit is contained in:
@ -6,7 +6,7 @@ EFI_BINARY="$1"
|
|||||||
./create-iso.sh "$EFI_BINARY"
|
./create-iso.sh "$EFI_BINARY"
|
||||||
|
|
||||||
qemu-system-x86_64 -enable-kvm \
|
qemu-system-x86_64 -enable-kvm \
|
||||||
-m 4G \
|
-m 512M \
|
||||||
-serial mon:stdio \
|
-serial mon:stdio \
|
||||||
-nographic \
|
-nographic \
|
||||||
-no-reboot \
|
-no-reboot \
|
||||||
|
@ -13,7 +13,4 @@ pub const HEAP_START: usize = 0x4444_4444_0000;
|
|||||||
pub const HEAP_SIZE: usize = 128 * 1024;
|
pub const HEAP_SIZE: usize = 128 * 1024;
|
||||||
|
|
||||||
pub const PAGE_SIZE: usize = 4096;
|
pub const PAGE_SIZE: usize = 4096;
|
||||||
pub const MAX_MEMORY: usize = 256 * 1024 * 1024 * 1024;
|
|
||||||
pub const FRAME_COUNT: usize = MAX_MEMORY / PAGE_SIZE;
|
|
||||||
pub const BITS_PER_ENTRY: usize = 8 * core::mem::size_of::<usize>();
|
pub const BITS_PER_ENTRY: usize = 8 * core::mem::size_of::<usize>();
|
||||||
pub const ENTRY_COUNT: usize = FRAME_COUNT / BITS_PER_ENTRY;
|
|
||||||
|
@ -98,10 +98,13 @@ pub extern "sysv64" fn main(boot_info: &nel_os_common::BootInfo) {
|
|||||||
|
|
||||||
let ranges = boot_info.usable_memory.ranges();
|
let ranges = boot_info.usable_memory.ranges();
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
let mut max_range = 0;
|
||||||
for range in ranges {
|
for range in ranges {
|
||||||
count += range.end - range.start;
|
count += range.end - range.start;
|
||||||
|
max_range = max_range.max(range.end);
|
||||||
}
|
}
|
||||||
info!("Usable memory: {}MiB", count / 1024 / 1024);
|
info!("Usable memory: {}MiB", count / 1024 / 1024);
|
||||||
|
memory::memory::MAX_MEMORY.call_once(|| max_range as usize * 2);
|
||||||
|
|
||||||
let mut bitmap_table = BitmapMemoryTable::init(&boot_info.usable_memory);
|
let mut bitmap_table = BitmapMemoryTable::init(&boot_info.usable_memory);
|
||||||
info!(
|
info!(
|
||||||
|
@ -1,12 +1,22 @@
|
|||||||
use core::slice;
|
use core::slice;
|
||||||
|
|
||||||
use nel_os_common::memory::{self, UsableMemory};
|
use nel_os_common::memory::{self, UsableMemory};
|
||||||
|
use spin::Once;
|
||||||
use x86_64::{
|
use x86_64::{
|
||||||
structures::paging::{FrameAllocator, PhysFrame, Size4KiB},
|
structures::paging::{FrameAllocator, PhysFrame, Size4KiB},
|
||||||
PhysAddr,
|
PhysAddr,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::constant::{BITS_PER_ENTRY, ENTRY_COUNT, PAGE_SIZE};
|
use crate::{
|
||||||
|
constant::{BITS_PER_ENTRY, PAGE_SIZE},
|
||||||
|
info,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub static MAX_MEMORY: Once<usize> = Once::new();
|
||||||
|
|
||||||
|
pub fn get_entry_count() -> usize {
|
||||||
|
MAX_MEMORY.get().unwrap_or(&0) / PAGE_SIZE / BITS_PER_ENTRY
|
||||||
|
}
|
||||||
|
|
||||||
pub struct BitmapMemoryTable {
|
pub struct BitmapMemoryTable {
|
||||||
pub used_map: &'static mut [usize],
|
pub used_map: &'static mut [usize],
|
||||||
@ -21,16 +31,17 @@ impl BitmapMemoryTable {
|
|||||||
max_addr = max_addr.max(range.end);
|
max_addr = max_addr.max(range.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
let bitmap_size = ENTRY_COUNT * core::mem::size_of::<usize>();
|
let entry_count = get_entry_count();
|
||||||
|
let bitmap_size = entry_count * core::mem::size_of::<usize>();
|
||||||
|
|
||||||
let bitmap_addr = ((max_addr as usize).saturating_sub(bitmap_size)) & !(PAGE_SIZE - 1);
|
let bitmap_addr = ((max_addr as usize).saturating_sub(bitmap_size)) & !(PAGE_SIZE - 1);
|
||||||
|
|
||||||
let used_map = unsafe {
|
let used_map = unsafe {
|
||||||
let ptr = bitmap_addr as *mut usize;
|
let ptr = bitmap_addr as *mut usize;
|
||||||
slice::from_raw_parts_mut(ptr, ENTRY_COUNT)
|
slice::from_raw_parts_mut(ptr, entry_count)
|
||||||
};
|
};
|
||||||
|
|
||||||
(0..ENTRY_COUNT).for_each(|i| {
|
(0..entry_count).for_each(|i| {
|
||||||
used_map[i] = 0;
|
used_map[i] = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,8 +61,8 @@ impl BitmapMemoryTable {
|
|||||||
table.set_frame(bitmap_start_frame + i, false);
|
table.set_frame(bitmap_start_frame + i, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..ENTRY_COUNT {
|
for i in 0..entry_count {
|
||||||
let index = ENTRY_COUNT - i - 1;
|
let index = entry_count - i - 1;
|
||||||
if table.used_map[index] != 0 {
|
if table.used_map[index] != 0 {
|
||||||
let offset = 63 - table.used_map[index].leading_zeros();
|
let offset = 63 - table.used_map[index].leading_zeros();
|
||||||
table.end = index * BITS_PER_ENTRY + (BITS_PER_ENTRY - offset as usize);
|
table.end = index * BITS_PER_ENTRY + (BITS_PER_ENTRY - offset as usize);
|
||||||
|
Reference in New Issue
Block a user