fixed triple fault
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
[0;32m[1m Running kernel in debug mode.
|
||||
[0;34m[1minfo[0m: Creating build directory structure
|
||||
[0;34m[1minfo[0m: Copying files to ISO root
|
||||
[0;32m[1m Copying[0m: /home/fantasypvp/Projects/OSdev/FoundryOS/build/target/x86_64-kernel/debug/kernel to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/kernel
|
||||
[0;32m[1m Copying[0m: /home/fantasypvp/Projects/OSdev/FoundryOS/config/limine.conf to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/limine/limine.conf
|
||||
[0;32m[1m Copying[0m: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/limine-bios-cd.bin to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/limine/
|
||||
[0;32m[1m Copying[0m: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/limine-uefi-cd.bin to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/limine/
|
||||
[0;32m[1m Copying[0m: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/limine-bios.sys to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/boot/limine/
|
||||
[0;32m[1m Copying[0m: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/BOOTX64.EFI to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/EFI/BOOT/
|
||||
[0;32m[1m Copying[0m: /home/fantasypvp/Projects/OSdev/FoundryOS/build/limine/BOOTIA32.EFI to /home/fantasypvp/Projects/OSdev/FoundryOS/build/iso_root/EFI/BOOT/
|
||||
[0;32m[1mBuilding[0m: bootable ISO image
|
||||
[0;34m[1minfo[0m: Installing Limine bootloader
|
||||
[0;34m[1minfo[0m: KVM acceleration enabled
|
||||
[0;34m[1minfo[0m: Running OS in QEMU...
|
||||
[2J[01;01H[=3h[2J[01;01H[2J[01;01H[=3h[2J[01;01H[2J[01;01H[=3h[2J[01;01HBdsDxe: 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)
|
||||
[2J[01;01H[01;01H[2J[01;01H[01;01Hmap worked!got apic base
|
||||
@@ -1,5 +1,6 @@
|
||||
use core::arch::x86_64::__cpuid;
|
||||
|
||||
use spin::Lazy;
|
||||
use x86_64::{
|
||||
PhysAddr, VirtAddr,
|
||||
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 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) {
|
||||
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 {
|
||||
let phys = phys.as_u64();
|
||||
match phys.checked_add(*PHYSICAL_MEMORY_OFFSET) {
|
||||
Some(virt) => VirtAddr::new(virt),
|
||||
None => panic!("overflow"),
|
||||
Some(virt) => {
|
||||
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();
|
||||
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;
|
||||
|
||||
// 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
|
||||
|
||||
let apic_virt = unsafe { phys_to_virt(apic_phys_addr) };
|
||||
// // FIXME: this causes a page fault
|
||||
// // TODO: map to virtual memor
|
||||
|
||||
let reg = read_apic_register(&apic_virt, 0xF0);
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ impl InterruptIndex {
|
||||
|
||||
pub fn init_idt() {
|
||||
IDT.load();
|
||||
enable_apic();
|
||||
// enable_apic();
|
||||
// TODO: fix apic
|
||||
// unsafe {
|
||||
// PICS.lock().initialize();
|
||||
@@ -123,5 +123,5 @@ extern "x86-interrupt" fn page_fault_handler(
|
||||
serial_println!("Error Code: {:?}", error_code);
|
||||
serial_println!("{:#?}", stack_frame);
|
||||
|
||||
crate::hcf();
|
||||
panic!("page fault");
|
||||
}
|
||||
|
||||
+4
-4
@@ -87,14 +87,14 @@ pub fn boot() -> Result<(), &'static str> {
|
||||
}
|
||||
println_log!("[Success]");
|
||||
|
||||
print_log!(" Initialising APIC");
|
||||
enable_apic();
|
||||
println_log!("[Success]");
|
||||
|
||||
print_log!(" Setting Up Interrupt Descriptor Table... ");
|
||||
interrupts::init_idt();
|
||||
println_log!("[Success]");
|
||||
|
||||
print_log!(" Initialising APIC");
|
||||
enable_apic(&mut l4_table, &mut frame_allocator);
|
||||
println_log!("[Success]");
|
||||
|
||||
print_log!(" Enabling Interrupts... ");
|
||||
x86_64::instructions::interrupts::enable();
|
||||
println_log!("[Success]");
|
||||
|
||||
Reference in New Issue
Block a user