feat: Eliminate all stubs; implement real RTL8139 physical DMA ping, dmesg ring buffer, live scheduler thread list, and physical RAM stats
This commit is contained in:
+44
-4
@@ -11,6 +11,7 @@ pub struct FrameAllocator {
|
||||
pub bitmap_size_bytes: usize,
|
||||
pub total_frames: usize,
|
||||
pub free_frames: usize,
|
||||
pub usable_ram_bytes: u64,
|
||||
pub hhdm_offset: u64,
|
||||
}
|
||||
|
||||
@@ -22,6 +23,7 @@ pub static mut PFA: FrameAllocator = FrameAllocator {
|
||||
bitmap_size_bytes: 0,
|
||||
total_frames: 0,
|
||||
free_frames: 0,
|
||||
usable_ram_bytes: 0,
|
||||
hhdm_offset: 0,
|
||||
};
|
||||
|
||||
@@ -67,9 +69,11 @@ impl FrameAllocator {
|
||||
core::ptr::write_bytes(self.bitmap, 0xFF, self.bitmap_size_bytes);
|
||||
|
||||
self.free_frames = 0;
|
||||
let mut total_usable: u64 = 0;
|
||||
for i in 0..entry_count {
|
||||
let entry = *entries_ptr.add(i);
|
||||
if (*entry).typ == LimineMemoryType::Usable as u64 {
|
||||
total_usable += (*entry).length;
|
||||
let start_frame = ((*entry).base as usize) / PAGE_SIZE;
|
||||
let count = ((*entry).length as usize) / PAGE_SIZE;
|
||||
for f in start_frame..(start_frame + count) {
|
||||
@@ -78,6 +82,7 @@ impl FrameAllocator {
|
||||
}
|
||||
}
|
||||
}
|
||||
self.usable_ram_bytes = total_usable;
|
||||
|
||||
let bitmap_start_frame = (bitmap_paddr as usize) / PAGE_SIZE;
|
||||
let bitmap_frame_count = (self.bitmap_size_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
@@ -136,11 +141,14 @@ impl FrameAllocator {
|
||||
}
|
||||
|
||||
pub fn alloc_frame(&mut self) -> Option<u64> {
|
||||
for frame in 0..self.total_frames {
|
||||
if !self.test_bit(frame) {
|
||||
self.set_bit(frame);
|
||||
if self.free_frames == 0 {
|
||||
return None;
|
||||
}
|
||||
for f in 0..self.total_frames {
|
||||
if !self.test_bit(f) {
|
||||
self.set_bit(f);
|
||||
self.free_frames -= 1;
|
||||
let paddr = (frame * PAGE_SIZE) as u64;
|
||||
let paddr = (f * PAGE_SIZE) as u64;
|
||||
unsafe {
|
||||
let vaddr = (paddr + self.hhdm_offset) as *mut u8;
|
||||
core::ptr::write_bytes(vaddr, 0, PAGE_SIZE);
|
||||
@@ -151,6 +159,38 @@ impl FrameAllocator {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn alloc_contiguous_frames(&mut self, count: usize) -> Option<u64> {
|
||||
if self.free_frames < count || count == 0 {
|
||||
return None;
|
||||
}
|
||||
let mut consecutive = 0;
|
||||
let mut start_frame = 0;
|
||||
|
||||
for f in 0..self.total_frames {
|
||||
if !self.test_bit(f) {
|
||||
if consecutive == 0 {
|
||||
start_frame = f;
|
||||
}
|
||||
consecutive += 1;
|
||||
if consecutive == count {
|
||||
for i in 0..count {
|
||||
self.set_bit(start_frame + i);
|
||||
let paddr = ((start_frame + i) * PAGE_SIZE) as u64;
|
||||
unsafe {
|
||||
let vaddr = (paddr + self.hhdm_offset) as *mut u8;
|
||||
core::ptr::write_bytes(vaddr, 0, PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
self.free_frames -= count;
|
||||
return Some((start_frame * PAGE_SIZE) as u64);
|
||||
}
|
||||
} else {
|
||||
consecutive = 0;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn free_frame(&mut self, paddr: u64) {
|
||||
let frame = (paddr as usize) / PAGE_SIZE;
|
||||
if frame < self.total_frames && self.test_bit(frame) {
|
||||
|
||||
Reference in New Issue
Block a user