Megacommit to move some memory code into kernel crate
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
use libk::drivers::memory::{FRAME_ALLOCATOR, OFFSET_PAGE_TABLE};
|
||||
// use libk::drivers::mem::{FRAME_ALLOCATOR, OFFSET_PAGE_TABLE};
|
||||
use libk::prelude::*;
|
||||
use pic8259::ChainedPics;
|
||||
use x86_64::registers::control::Cr2;
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
|
||||
use x86_64::structures::paging::mapper::MapperFlushAll;
|
||||
use x86_64::structures::paging::{FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB};
|
||||
|
||||
use spin::{Lazy, Mutex};
|
||||
|
||||
use super::apic::enable_apic;
|
||||
use super::gdt;
|
||||
|
||||
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
|
||||
@@ -64,6 +60,7 @@ pub fn enable_pic() {
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(unused)]
|
||||
pub fn disable_pic() {
|
||||
unsafe {
|
||||
PICS.lock().disable();
|
||||
@@ -125,31 +122,32 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFr
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn page_fault_handler(
|
||||
stack_frame: InterruptStackFrame,
|
||||
error_code: PageFaultErrorCode,
|
||||
_stack_frame: InterruptStackFrame,
|
||||
_error_code: PageFaultErrorCode,
|
||||
) {
|
||||
todo!("Get this working again.")
|
||||
// serial_println!("Exception: Page Fault");
|
||||
// serial_println!("Accessed Address: {:?}", Cr2::read());
|
||||
// serial_println!("Error Code: {:?}", error_code);
|
||||
// serial_println!("{:#?}", stack_frame);
|
||||
|
||||
if let Some(frame_allocator) = FRAME_ALLOCATOR.get() {
|
||||
let mut f = frame_allocator.lock();
|
||||
// if let Some(frame_allocator) = FRAME_ALLOCATOR.get() {
|
||||
// let mut f = frame_allocator.lock();
|
||||
|
||||
let frame = f.allocate_frame().unwrap();
|
||||
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||
let page: Page<Size4KiB> = Page::containing_address(Cr2::read().unwrap());
|
||||
// let frame = f.allocate_frame().unwrap();
|
||||
// let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||
// let page: Page<Size4KiB> = Page::containing_address(Cr2::read().unwrap());
|
||||
|
||||
unsafe {
|
||||
let mut mapper = OFFSET_PAGE_TABLE.get().unwrap().lock();
|
||||
// unsafe {
|
||||
// let mut mapper = OFFSET_PAGE_TABLE.get().unwrap().lock();
|
||||
|
||||
match mapper.map_to(page, frame, flags, &mut *f) {
|
||||
Ok(_) => {}
|
||||
Err(why) => panic!("failed to map page: {:?}", why),
|
||||
}
|
||||
}
|
||||
MapperFlushAll::new().flush_all();
|
||||
} else {
|
||||
panic!("failed to get frame allocator");
|
||||
}
|
||||
// match mapper.map_to(page, frame, flags, &mut *f) {
|
||||
// Ok(_) => {}
|
||||
// Err(why) => panic!("failed to map page: {:?}", why),
|
||||
// }
|
||||
// }
|
||||
// MapperFlushAll::new().flush_all();
|
||||
// } else {
|
||||
// panic!("failed to get frame allocator");
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user