fixed triple fault

This commit is contained in:
2025-02-27 16:52:31 +00:00
parent 821759ec63
commit 2178215a01
4 changed files with 53 additions and 18 deletions
+17
View File
@@ -0,0 +1,17 @@
 Running kernel in debug mode.
info: Creating build directory structure
info: Copying files to ISO root
 Copying: /home/fantasypvp/Projects/OSdev/FoundryOS/build/target/x86_64-kernel/debug/kernel to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/kernel
 Copying: /home/fantasypvp/Projects/OSdev/FoundryOS/config/limine.conf to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/limine/limine.conf
 Copying: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/limine-bios-cd.bin to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/limine/
 Copying: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/limine-uefi-cd.bin to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/limine/
 Copying: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/limine-bios.sys to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/limine/
 Copying: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/BOOTX64.EFI to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/EFI/BOOT/
 Copying: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/BOOTIA32.EFI to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/EFI/BOOT/
Building: bootable ISO image
info: Installing Limine bootloader
info: KVM acceleration enabled
info: Running OS in QEMU...
[=3h[=3h[=3hBdsDxe: loading Boot0001 "UEFI QEMU DVD-ROM QM00005 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x2,0xFFFF,0x0)
BdsDxe: starting Boot0001 "UEFI QEMU DVD-ROM QM00005 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x2,0xFFFF,0x0)
map worked!got apic base
+30 -12
View File
@@ -1,5 +1,6 @@
use core::arch::x86_64::__cpuid; use core::arch::x86_64::__cpuid;
use spin::Lazy;
use x86_64::{ use x86_64::{
PhysAddr, VirtAddr, PhysAddr, VirtAddr,
instructions::port::Port, instructions::port::Port,
@@ -23,7 +24,12 @@ const IA32_APIC_BASE_MSR_DISABLE: u64 = !IA32_APIC_BASE_MSR_ENABLE;
const CPUID_FEAT_EDX_APIC: u64 = 1 << 9; // the cpuid instruction will return this flag if it supports APIC const CPUID_FEAT_EDX_APIC: u64 = 1 << 9; // the cpuid instruction will return this flag if it supports APIC
const APIC_VIRTUAL_ADDRESS: u64 = 0xFEC00000; // const APIC_VIRTUAL_ADDRESS: Lazy<VirtAddr> = Lazy::new(|| {
// let apic_base = get_apic_base();
// let virt_addr = unsafe { phys_to_virt(apic_base) };
// virt_addr
// });
fn set_apic_base_enable(apic: PhysAddr) { fn set_apic_base_enable(apic: PhysAddr) {
let rax = (apic.as_u64() & 0xfffff0000) | IA32_APIC_BASE_MSR_ENABLE; let rax = (apic.as_u64() & 0xfffff0000) | IA32_APIC_BASE_MSR_ENABLE;
@@ -65,27 +71,39 @@ pub fn check_apic() -> bool {
unsafe fn phys_to_virt(phys: PhysAddr) -> VirtAddr { unsafe fn phys_to_virt(phys: PhysAddr) -> VirtAddr {
let phys = phys.as_u64(); let phys = phys.as_u64();
match phys.checked_add(*PHYSICAL_MEMORY_OFFSET) { match phys.checked_add(*PHYSICAL_MEMORY_OFFSET) {
Some(virt) => VirtAddr::new(virt), Some(virt) => {
None => panic!("overflow"), serial_print!("map worked!");
VirtAddr::new(virt)
}
None => {
serial_print!("THIS IS A PROBLEM");
panic!("overflow")
}
} }
} }
pub fn enable_apic() { pub fn enable_apic(
mapper: &mut impl Mapper<Size4KiB>,
frame_allocator: &mut FoundryOSFrameAllocator,
) {
let apic_phys_addr = get_apic_base(); let apic_phys_addr = get_apic_base();
set_apic_base_enable(apic_phys_addr);
// map virt address of apic
// let frame = PhysFrame::containing_address(apic_phys_addr); 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 flags: PageTableFlags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
// unsafe { // unsafe {
// mapper.map_to(page, frame, flags, frame_allocator); // match mapper.map_to(page, frame, flags, frame_allocator) {
// Ok(_) => {}
// Err(why) => panic!("failed to map apic: {:?}", why),
// }
// } // }
set_apic_base_enable(apic_phys_addr); // // FIXME: this causes a page fault
// // TODO: map to virtual memor
// FIXME: this causes a page fault
// TODO: map to virtual memor
let apic_virt = unsafe { phys_to_virt(apic_phys_addr) };
let reg = read_apic_register(&apic_virt, 0xF0); let reg = read_apic_register(&apic_virt, 0xF0);
+2 -2
View File
@@ -52,7 +52,7 @@ impl InterruptIndex {
pub fn init_idt() { pub fn init_idt() {
IDT.load(); IDT.load();
enable_apic(); // enable_apic();
// TODO: fix apic // TODO: fix apic
// unsafe { // unsafe {
// PICS.lock().initialize(); // PICS.lock().initialize();
@@ -123,5 +123,5 @@ extern "x86-interrupt" fn page_fault_handler(
serial_println!("Error Code: {:?}", error_code); serial_println!("Error Code: {:?}", error_code);
serial_println!("{:#?}", stack_frame); serial_println!("{:#?}", stack_frame);
crate::hcf(); panic!("page fault");
} }
+4 -4
View File
@@ -87,14 +87,14 @@ pub fn boot() -> Result<(), &'static str> {
} }
println_log!("[Success]"); println_log!("[Success]");
print_log!(" Initialising APIC");
enable_apic();
println_log!("[Success]");
print_log!(" Setting Up Interrupt Descriptor Table... "); print_log!(" Setting Up Interrupt Descriptor Table... ");
interrupts::init_idt(); interrupts::init_idt();
println_log!("[Success]"); println_log!("[Success]");
print_log!(" Initialising APIC");
enable_apic(&mut l4_table, &mut frame_allocator);
println_log!("[Success]");
print_log!(" Enabling Interrupts... "); print_log!(" Enabling Interrupts... ");
x86_64::instructions::interrupts::enable(); x86_64::instructions::interrupts::enable();
println_log!("[Success]"); println_log!("[Success]");