wip
This commit is contained in:
@ -14,7 +14,7 @@ use core::ptr::addr_of;
|
||||
use x86_64::VirtAddr;
|
||||
|
||||
use crate::{
|
||||
constant::{BANNER, KERNEL_STACK_SIZE, PKG_VERSION},
|
||||
constant::{BANNER, BITS_PER_ENTRY, KERNEL_STACK_SIZE, PKG_VERSION},
|
||||
memory::BitmapMemoryTable,
|
||||
};
|
||||
|
||||
@ -85,10 +85,15 @@ pub extern "sysv64" fn main(usable_memory: &nel_os_common::memory::UsableMemory)
|
||||
"Memory bitmap initialized: {} -> {}",
|
||||
bitmap_table.start, bitmap_table.end
|
||||
);
|
||||
info!("Usable memory map:");
|
||||
|
||||
let mut usable_frame = 0;
|
||||
for i in bitmap_table.start..bitmap_table.end {
|
||||
info!(" {:064b}", bitmap_table.used_map[i]);
|
||||
if bitmap_table.get_bit(i) {
|
||||
usable_frame += 1;
|
||||
}
|
||||
}
|
||||
|
||||
info!("Usable memory in bitmap: {}MiB", usable_frame * 4 / 1024);
|
||||
|
||||
hlt_loop();
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
use nel_os_common::memory::{self, UsableMemory};
|
||||
|
||||
use crate::{
|
||||
constant::{BITS_PER_ENTRY, ENTRY_COUNT, PAGE_SIZE},
|
||||
info,
|
||||
};
|
||||
use crate::constant::{BITS_PER_ENTRY, ENTRY_COUNT, PAGE_SIZE};
|
||||
|
||||
pub struct BitmapMemoryTable {
|
||||
pub used_map: [usize; ENTRY_COUNT],
|
||||
@ -31,12 +28,15 @@ impl BitmapMemoryTable {
|
||||
if table.used_map[index] != 0 {
|
||||
let offset = 63 - table.used_map[index].leading_zeros();
|
||||
table.end = (index + 1) * BITS_PER_ENTRY + offset as usize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
table
|
||||
}
|
||||
|
||||
pub fn get_free_frame(&self) {}
|
||||
|
||||
pub fn set_range(&mut self, range: &memory::Range) {
|
||||
let start = Self::addr_to_pfn(range.start as usize);
|
||||
let size = (range.end - range.start) / PAGE_SIZE as u64;
|
||||
@ -61,6 +61,13 @@ impl BitmapMemoryTable {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_bit(&self, frame: usize) -> bool {
|
||||
let index = Self::frame_to_index(frame);
|
||||
let offset = Self::frame_to_offset(frame);
|
||||
|
||||
(self.used_map[index] & (1usize << offset)) != 0
|
||||
}
|
||||
|
||||
pub fn addr_to_pfn(addr: usize) -> usize {
|
||||
addr / PAGE_SIZE
|
||||
}
|
||||
|
Reference in New Issue
Block a user