- implemented a custom allocator (fixed size block) with a fallback (linked list allocator) for larger block sizes
- apic code still not working (commented out, check lib.rs)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use core::arch::x86_64::__cpuid;
|
||||
|
||||
use libk::drivers::memory::FoundryOSFrameAllocator;
|
||||
use libk::drivers::memory::{FoundryOSFrameAllocator, FRAME_ALLOCATOR, OFFSET_PAGE_TABLE};
|
||||
use spin::Lazy;
|
||||
use x86_64::{
|
||||
PhysAddr, VirtAddr,
|
||||
@@ -68,37 +68,28 @@ pub fn check_apic() -> bool {
|
||||
#[inline(always)]
|
||||
unsafe fn phys_to_virt(phys: PhysAddr) -> VirtAddr {
|
||||
let phys = phys.as_u64();
|
||||
match phys.checked_add(*PHYSICAL_MEMORY_OFFSET) {
|
||||
Some(virt) => {
|
||||
serial_print!("map worked!");
|
||||
VirtAddr::new(virt)
|
||||
}
|
||||
None => {
|
||||
serial_print!("THIS IS A PROBLEM");
|
||||
panic!("overflow")
|
||||
}
|
||||
}
|
||||
phys.checked_add(*PHYSICAL_MEMORY_OFFSET).map_or_else(|| panic!(" overflow"), VirtAddr::new)
|
||||
}
|
||||
|
||||
pub fn enable_apic(
|
||||
mapper: &mut impl Mapper<Size4KiB>,
|
||||
frame_allocator: &mut FoundryOSFrameAllocator,
|
||||
) {
|
||||
pub fn enable_apic() {
|
||||
let mut mapper = OFFSET_PAGE_TABLE.get().unwrap().lock();
|
||||
let mut frame_allocator = FRAME_ALLOCATOR.get().unwrap().lock();
|
||||
|
||||
let apic_phys_addr = get_apic_base();
|
||||
set_apic_base_enable(apic_phys_addr);
|
||||
// map virt address of apic
|
||||
|
||||
let apic_virt = unsafe { phys_to_virt(apic_phys_addr) };
|
||||
// let page: Page<Size4KiB> = Page::containing_address(apic_virt);
|
||||
// let frame: PhysFrame<Size4KiB> = PhysFrame::containing_address(apic_phys_addr);
|
||||
// let flags: PageTableFlags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||
let page: Page<Size4KiB> = Page::containing_address(apic_virt);
|
||||
let frame: PhysFrame<Size4KiB> = PhysFrame::containing_address(apic_phys_addr);
|
||||
let flags: PageTableFlags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||
|
||||
// unsafe {
|
||||
// match mapper.map_to(page, frame, flags, frame_allocator) {
|
||||
// Ok(_) => {}
|
||||
// Err(why) => panic!("failed to map apic: {:?}", why),
|
||||
// }
|
||||
// }
|
||||
unsafe {
|
||||
match mapper.map_to(page, frame, flags, &mut *frame_allocator) {
|
||||
Ok(_) => {}
|
||||
Err(why) => panic!("failed to map apic: {:?}", why),
|
||||
}
|
||||
}
|
||||
|
||||
// // FIXME: this causes a page fault
|
||||
// // TODO: map to virtual memor
|
||||
|
||||
@@ -127,10 +127,10 @@ extern "x86-interrupt" fn page_fault_handler(
|
||||
_stack_frame: InterruptStackFrame,
|
||||
_error_code: PageFaultErrorCode,
|
||||
) {
|
||||
// serial_println!("Exception: Page Fault");
|
||||
// serial_println!("Accessed Address: {:?}", Cr2::read());
|
||||
// serial_println!("Error Code: {:?}", error_code);
|
||||
// serial_println!("{:#?}", _stack_frame);
|
||||
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();
|
||||
|
||||
+2
-2
@@ -99,9 +99,9 @@ pub fn boot() -> Result<(), &'static str> {
|
||||
// print_log!(" Disabling PICs... ");
|
||||
// interrupts::disable_pic();
|
||||
// println_log!("[Success]");
|
||||
//
|
||||
|
||||
// print_log!(" Initialising APIC");
|
||||
// enable_apic(&mut l4_table, &mut frame_allocator);
|
||||
// enable_apic();
|
||||
// println_log!("[Success]");
|
||||
|
||||
print_log!(" Enabling Interrupts... ");
|
||||
|
||||
@@ -28,6 +28,13 @@ extern "C" fn kmain() -> ! {
|
||||
println!("Dimensions: {}x{} (px)", dimensions2.0, dimensions2.1);
|
||||
println!("Dimensions: {}x{} (chars)", dimensions.0, dimensions.1);
|
||||
|
||||
// println!("TESTING :: Allocation");
|
||||
// let somevec = vec![0; 1_000_000];
|
||||
// println!("{:?}", somevec);
|
||||
// println!("{}", somevec.len());
|
||||
// println!("PASSED!");
|
||||
|
||||
|
||||
let mut executor = Executor::new();
|
||||
executor.spawn(Task::new(shell()));
|
||||
executor.run();
|
||||
|
||||
Reference in New Issue
Block a user