diff --git a/crates/libxernel/src/on_drop.rs b/crates/libxernel/src/on_drop.rs index b8e07899..c43d2b60 100644 --- a/crates/libxernel/src/on_drop.rs +++ b/crates/libxernel/src/on_drop.rs @@ -2,6 +2,8 @@ use core::mem::ManuallyDrop; use core::ops::{Deref, DerefMut}; +use crate::sync::SpinlockGuard; + pub struct OnDrop where F: FnOnce(), @@ -34,6 +36,13 @@ where } } +impl<'a, T, F> OnDrop, F> +where + F: FnOnce(), +{ + pub fn unlock(self) {} +} + impl Deref for OnDrop where F: FnOnce(), diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 6e510844..468bbe50 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -89,122 +89,122 @@ fn panic(info: &PanicInfo) -> ! { // define the kernel's entry point function #[no_mangle] extern "C" fn kernel_main() -> ! { - { - framebuffer::init(); - info!("framebuffer initialized"); + framebuffer::init(); + info!("framebuffer initialized"); - gdt::init(); - info!("GDT loaded"); - amd64::interrupts::init(); - info!("IDT loaded"); - amd64::interrupts::disable_pic(); + gdt::init(); + info!("GDT loaded"); + amd64::interrupts::init(); + info!("IDT loaded"); + amd64::interrupts::disable_pic(); - mem::init(); + mem::init(); - acpi::init(); - info!("acpi initialized"); + acpi::init(); + info!("acpi initialized"); - backtrace::init(); - info!("backtrace initialized"); + backtrace::init(); + info!("backtrace initialized"); - hpet::init(); + hpet::init(); - apic::init(); + apic::init(); - syscall::init(); + syscall::init(); - vfs::init(); + vfs::init(); - vfs::test(); + vfs::test(); - let bootloader_info = BOOTLOADER_INFO - .get_response() - .get() - .expect("barebones: recieved no bootloader info"); + let bootloader_info = BOOTLOADER_INFO + .get_response() + .get() + .expect("barebones: recieved no bootloader info"); - info!( - "bootloader: (name={:?}, version={:?})", - bootloader_info.name.to_str().unwrap(), - bootloader_info.version.to_str().unwrap() - ); + info!( + "bootloader: (name={:?}, version={:?})", + bootloader_info.name.to_str().unwrap(), + bootloader_info.version.to_str().unwrap() + ); - Rtc::read(); + Rtc::read(); - KERNEL_PROCESS.set_once(Arc::new(Spinlock::new(Process::new(None)))); + KERNEL_PROCESS.set_once(Arc::new(Spinlock::new(Process::new(None)))); - let smp_response = SMP_REQUEST.get_response().get_mut().unwrap(); + let smp_response = SMP_REQUEST.get_response().get_mut().unwrap(); - let bsp_lapic_id = smp_response.bsp_lapic_id; + let bsp_lapic_id = smp_response.bsp_lapic_id; - CPU_COUNT.set_once(smp_response.cpu_count as usize); + CPU_COUNT.set_once(smp_response.cpu_count as usize); - register_cpu(); + register_cpu(); - for cpu in smp_response.cpus().iter_mut() { - if cpu.lapic_id != bsp_lapic_id { - cpu.goto_address = arch::amd64::x86_64_ap_main; - } + for cpu in smp_response.cpus().iter_mut() { + if cpu.lapic_id != bsp_lapic_id { + cpu.goto_address = arch::amd64::x86_64_ap_main; } + } - wait_until_cpus_registered(); + wait_until_cpus_registered(); - timer::init(); - info!("scheduler initialized"); + timer::init(); + info!("scheduler initialized"); - let process = Arc::new(Spinlock::new(Process::new(Some(KERNEL_PROCESS.clone())))); + let process = Arc::new(Spinlock::new(Process::new(Some(KERNEL_PROCESS.clone())))); - let _user_task = Thread::new_user_thread(process.clone(), VirtAddr::new(0x200000)); + let _user_task = Thread::new_user_thread(process.clone(), VirtAddr::new(0x200000)); - let page = FRAME_ALLOCATOR.aquire().allocate_frame::().unwrap(); + let page = FRAME_ALLOCATOR.aquire().allocate_frame::().unwrap(); - KERNEL_PAGE_MAPPER.aquire().map( - page, - Page::from_start_address(VirtAddr::new(0x200000)).unwrap(), - PageTableFlags::WRITABLE | PageTableFlags::USER_ACCESSIBLE | PageTableFlags::PRESENT, - true, - ); + KERNEL_PAGE_MAPPER.aquire().map( + page, + Page::from_start_address(VirtAddr::new(0x200000)).unwrap(), + PageTableFlags::WRITABLE | PageTableFlags::USER_ACCESSIBLE | PageTableFlags::PRESENT, + true, + ); - let mut process = process.aquire(); - let pm = process.get_page_table().as_mut().unwrap(); - pm.map( - page, - Page::from_start_address(VirtAddr::new(0x200000)).unwrap(), - PageTableFlags::WRITABLE | PageTableFlags::USER_ACCESSIBLE | PageTableFlags::PRESENT, - true, - ); + let mut process = process.aquire(); + let pm = process.get_page_table().as_mut().unwrap(); + pm.map( + page, + Page::from_start_address(VirtAddr::new(0x200000)).unwrap(), + PageTableFlags::WRITABLE | PageTableFlags::USER_ACCESSIBLE | PageTableFlags::PRESENT, + true, + ); - // unsafe { - // let start_address_fn = test_userspace_fn as usize; + process.unlock(); - // // the `test_userspace_fn` is very small and should fit in 512 bytes - // for i in 0..512 { - // let ptr = (0x200000 + i) as *mut u8; - // let val = (start_address_fn + i) as *mut u8; + // unsafe { + // let start_address_fn = test_userspace_fn as usize; - // ptr.write_volatile(val.read_volatile()); - // } - // } + // // the `test_userspace_fn` is very small and should fit in 512 bytes + // for i in 0..512 { + // let ptr = (0x200000 + i) as *mut u8; + // let val = (start_address_fn + i) as *mut u8; - let main_task = Thread::kernel_thread_from_fn(kmain_thread); + // ptr.write_volatile(val.read_volatile()); + // } + // } - let kernel_task = Thread::kernel_thread_from_fn(task1); + let main_task = Thread::kernel_thread_from_fn(kmain_thread); - let kernel_task2 = Thread::kernel_thread_from_fn(task2); + let kernel_task = Thread::kernel_thread_from_fn(task1); - current_cpu().enqueue_thread(Arc::new(main_task)); - current_cpu().enqueue_thread(Arc::new(kernel_task)); - current_cpu().enqueue_thread(Arc::new(kernel_task2)); + let kernel_task2 = Thread::kernel_thread_from_fn(task2); - let timekeeper = TimerEvent::new(hardclock, (), Duration::from_secs(1), false); + current_cpu().enqueue_thread(Arc::new(main_task)); + current_cpu().enqueue_thread(Arc::new(kernel_task)); + current_cpu().enqueue_thread(Arc::new(kernel_task2)); - current_cpu().enqueue_timer(timekeeper); + let timekeeper = TimerEvent::new(hardclock, (), Duration::from_secs(1), false); - let resched = TimerEvent::new(reschedule, (), Duration::from_millis(5), false); + current_cpu().enqueue_timer(timekeeper); - current_cpu().enqueue_timer(resched); + let resched = TimerEvent::new(reschedule, (), Duration::from_millis(5), false); - amd64::interrupts::enable(); - } + current_cpu().enqueue_timer(resched); + + amd64::interrupts::enable(); hcf(); }