diff --git a/kernel/src/boot/mod.rs b/kernel/src/boot/mod.rs index b778462..1199737 100644 --- a/kernel/src/boot/mod.rs +++ b/kernel/src/boot/mod.rs @@ -143,26 +143,25 @@ pub fn bi_finalise(dtb_size: usize, dtb_phys_addr: usize, extra_bi_size: usize) pub fn init_core_state(scheduler_action: *mut tcb_t) { // unsafe { - // #[cfg(feature = "ENABLE_SMP")] - // if scheduler_action as usize != 0 && scheduler_action as usize != 1 { - // tcbDebugAppend(scheduler_action); - // } - // let idle_thread = { - // #[cfg(not(feature = "ENABLE_SMP"))] - // { - // ksIdleThread as *mut tcb_t - // } - // #[cfg(feature = "ENABLE_SMP")] - // { - // ksSMP[cpu_id()].ksIdleThread as *mut tcb_t - // } - // }; - // tcbDebugAppend(idle_thread); - // } - - set_current_scheduler_action(scheduler_action as usize); - set_current_thread(get_idle_thread()); - + // #[cfg(feature = "ENABLE_SMP")] + // if scheduler_action as usize != 0 && scheduler_action as usize != 1 { + // tcbDebugAppend(scheduler_action); + // } + // let idle_thread = { + // #[cfg(not(feature = "ENABLE_SMP"))] + // { + // ksIdleThread as *mut tcb_t + // } + // #[cfg(feature = "ENABLE_SMP")] + // { + // ksSMP[cpu_id()].ksIdleThread as *mut tcb_t + // } + // }; + // tcbDebugAppend(idle_thread); + // } + + set_current_scheduler_action(scheduler_action as usize); + set_current_thread(get_idle_thread()); } #[cfg(feature = "ENABLE_SMP")] diff --git a/kernel/src/interfaces_impl/cspace.rs b/kernel/src/interfaces_impl/cspace.rs index 4840ef6..bc0ec6c 100644 --- a/kernel/src/interfaces_impl/cspace.rs +++ b/kernel/src/interfaces_impl/cspace.rs @@ -199,7 +199,7 @@ pub fn finaliseCap(cap: &cap_t, _final: bool, _exposed: bool) -> finaliseCap_ret safe_unbind_notification(tcb); tcb.cancel_ipc(); tcb.suspend(); - // #[cfg(feature="DEBUG_BUILD")] + // #[cfg(feature="DEBUG_BUILD")] // unsafe { // tcbDebugRemove(tcb as *mut tcb_t); // } diff --git a/kernel/src/kernel/fastpath.rs b/kernel/src/kernel/fastpath.rs index 8d00587..e937bea 100644 --- a/kernel/src/kernel/fastpath.rs +++ b/kernel/src/kernel/fastpath.rs @@ -134,7 +134,7 @@ pub fn fastpath_copy_mrs(length: usize, src: &mut tcb_t, dest: &mut tcb_t) { #[no_mangle] #[cfg(target_arch = "aarch64")] pub fn fastpath_restore(_badge: usize, _msgInfo: usize, cur_thread: *mut tcb_t) { - use core::arch::asm; + use core::arch::asm; unsafe { (*cur_thread).tcbArch.load_thread_local(); asm!( @@ -180,13 +180,13 @@ pub fn fastpath_restore(_badge: usize, _msgInfo: usize, cur_thread: *mut tcb_t) pub fn fastpath_restore(_badge: usize, _msgInfo: usize, cur_thread: *mut tcb_t) { #[cfg(feature = "ENABLE_SMP")] {} - extern "C" { - pub fn __fastpath_restore(badge: usize, msgInfo: usize, cur_thread_reg: usize); - } - unsafe { - __fastpath_restore(_badge,_msgInfo,(*cur_thread).tcbArch.raw_ptr()); - } - panic!("unreachable") + extern "C" { + pub fn __fastpath_restore(badge: usize, msgInfo: usize, cur_thread_reg: usize); + } + unsafe { + __fastpath_restore(_badge, _msgInfo, (*cur_thread).tcbArch.raw_ptr()); + } + panic!("unreachable") } #[inline] @@ -262,7 +262,7 @@ pub fn fastpath_call(cptr: usize, msgInfo: usize) { info.set_caps_unwrapped(0); let msgInfo1 = info.to_word(); let badge = ep_cap.get_ep_badge(); - fastpath_restore(badge, msgInfo1, get_currenct_thread()); + fastpath_restore(badge, msgInfo1, get_currenct_thread()); } #[inline] @@ -344,18 +344,18 @@ pub fn fastpath_reply_recv(cptr: usize, msgInfo: usize) { ); // unsafe { - let node = convert_to_mut_type_ref::(caller_slot.cteMDBNode.get_prev()); - mdb_node_ptr_mset_mdbNext_mdbRevocable_mdbFirstBadged(&mut node.cteMDBNode, 0, 1, 1); - caller_slot.cap = cap_t::new_null_cap(); - caller_slot.cteMDBNode = mdb_node_t::new(0, 0, 0, 0); - fastpath_copy_mrs(length, current, caller); - - caller.tcbState.words[0] = ThreadState::ThreadStateRunning as usize; - let cap_pd = new_vtable.get_pt_base_ptr() as *mut PTE; - let stored_hw_asid: PTE = PTE(new_vtable.get_pt_mapped_asid()); - switchToThread_fp(caller, cap_pd, stored_hw_asid); - info.set_caps_unwrapped(0); - let msg_info1 = info.to_word(); - fastpath_restore(0, msg_info1, get_currenct_thread() as *mut tcb_t); + let node = convert_to_mut_type_ref::(caller_slot.cteMDBNode.get_prev()); + mdb_node_ptr_mset_mdbNext_mdbRevocable_mdbFirstBadged(&mut node.cteMDBNode, 0, 1, 1); + caller_slot.cap = cap_t::new_null_cap(); + caller_slot.cteMDBNode = mdb_node_t::new(0, 0, 0, 0); + fastpath_copy_mrs(length, current, caller); + + caller.tcbState.words[0] = ThreadState::ThreadStateRunning as usize; + let cap_pd = new_vtable.get_pt_base_ptr() as *mut PTE; + let stored_hw_asid: PTE = PTE(new_vtable.get_pt_mapped_asid()); + switchToThread_fp(caller, cap_pd, stored_hw_asid); + info.set_caps_unwrapped(0); + let msg_info1 = info.to_word(); + fastpath_restore(0, msg_info1, get_currenct_thread() as *mut tcb_t); // } } diff --git a/kernel/src/kernel/mod.rs b/kernel/src/kernel/mod.rs index 9f9ccbd..f0f1588 100644 --- a/kernel/src/kernel/mod.rs +++ b/kernel/src/kernel/mod.rs @@ -1,5 +1,5 @@ pub mod boot; pub mod fastpath; pub mod fault; -#[cfg(target_arch="riscv64")] -core::arch::global_asm!(include_str!("fastpath_restore.S")); \ No newline at end of file +#[cfg(target_arch = "riscv64")] +core::arch::global_asm!(include_str!("fastpath_restore.S")); diff --git a/kernel/src/syscall/invocation/invoke_untyped.rs b/kernel/src/syscall/invocation/invoke_untyped.rs index 7c3ff70..f87e074 100644 --- a/kernel/src/syscall/invocation/invoke_untyped.rs +++ b/kernel/src/syscall/invocation/invoke_untyped.rs @@ -48,7 +48,7 @@ fn create_object( tcb.init(); tcb.tcbTimeSlice = CONFIG_TIME_SLICE; tcb.domain = get_current_domain(); - // #[cfg(feature="DEBUG_BUILD")] + // #[cfg(feature="DEBUG_BUILD")] // unsafe { // tcbDebugAppend(tcb as *mut tcb_t); // } @@ -90,7 +90,7 @@ fn create_object( tcb.init(); tcb.tcbTimeSlice = CONFIG_TIME_SLICE; tcb.domain = get_current_domain(); - // #[cfg(feature="DEBUG_BUILD")] + // #[cfg(feature="DEBUG_BUILD")] // unsafe { // tcbDebugAppend(tcb as *mut tcb_t); // } diff --git a/kernel/src/utils.rs b/kernel/src/utils.rs index 2919b96..8996159 100644 --- a/kernel/src/utils.rs +++ b/kernel/src/utils.rs @@ -1,9 +1,9 @@ -#[cfg(target_arch="aarch64")] +#[cfg(target_arch = "aarch64")] use sel4_common::{ sel4_config::{ID_AA64PFR0_EL1_ASIMD, ID_AA64PFR0_EL1_FP}, MASK, }; -#[cfg(target_arch="aarch64")] +#[cfg(target_arch = "aarch64")] use sel4_vspace::{dsb, isb}; use crate::BIT; @@ -62,7 +62,7 @@ pub fn clear_memory_pt(ptr: *mut u8, bits: usize) { } #[inline] -#[cfg(target_arch="aarch64")] +#[cfg(target_arch = "aarch64")] pub fn setVTable(addr: usize) { dsb(); unsafe { @@ -72,7 +72,7 @@ pub fn setVTable(addr: usize) { } #[inline] -#[cfg(target_arch="aarch64")] +#[cfg(target_arch = "aarch64")] pub fn fpsimd_HWCapTest() -> bool { let mut id_aa64pfr0: usize; diff --git a/sel4_vspace/src/arch/aarch64/boot.rs b/sel4_vspace/src/arch/aarch64/boot.rs index 2cc5813..444e738 100644 --- a/sel4_vspace/src/arch/aarch64/boot.rs +++ b/sel4_vspace/src/arch/aarch64/boot.rs @@ -3,7 +3,6 @@ use sel4_common::{ config::{PADDR_BASE, PADDR_TOP, PPTR_BASE, PPTR_TOP}, vm_rights_t, }, - ffi_call, sel4_config::{seL4_LargePageBits, ARM_Large_Page, ARM_Small_Page, PUD_INDEX_BITS}, utils::convert_to_mut_type_ref, BIT, @@ -124,7 +123,7 @@ pub fn rust_map_kernel_window() { BIT!(PUD_INDEX_BITS) - 1, PDE::new_small(kpptr_to_paddr(get_kernel_page_table_base())), ); - map_kernel_devices(); + map_kernel_devices(); // ffi_call!(map_kernel_devices()); } diff --git a/sel4_vspace/src/arch/aarch64/device.rs b/sel4_vspace/src/arch/aarch64/device.rs index 4ffe8fd..956d8a2 100644 --- a/sel4_vspace/src/arch/aarch64/device.rs +++ b/sel4_vspace/src/arch/aarch64/device.rs @@ -1,19 +1,19 @@ -use crate::{paddr_t, pptr_t, vm_attributes_t}; use super::boot::map_kernel_frame; +use crate::{paddr_t, pptr_t, vm_attributes_t}; use sel4_common::arch::vm_rights_t::VMKernelOnly; use sel4_common::{sel4_config::PAGE_BITS, BIT}; pub const KDEV_BASE: usize = 0xFFFFFFFFC0000000; -pub(crate) const NUM_KERNEL_DEVICE_FRAMES:usize=3; -pub(crate) const UART_PPTR:usize=KDEV_BASE+ 0x0; -pub(crate) const GIC_V2_DISTRIBUTOR_PPTR:usize= KDEV_BASE + 0x1000; -pub(crate) const GIC_V2_CONTROLLER_PPTR:usize=KDEV_BASE + 0x2000; +pub(crate) const NUM_KERNEL_DEVICE_FRAMES: usize = 3; +pub(crate) const UART_PPTR: usize = KDEV_BASE + 0x0; +pub(crate) const GIC_V2_DISTRIBUTOR_PPTR: usize = KDEV_BASE + 0x1000; +pub(crate) const GIC_V2_CONTROLLER_PPTR: usize = KDEV_BASE + 0x2000; #[derive(Copy, Clone)] -struct kernel_frame_t{ - paddr:paddr_t, - pptr:pptr_t, - armExecuteNever:isize, - userAvailable:isize, +struct kernel_frame_t { + paddr: paddr_t, + pptr: pptr_t, + armExecuteNever: isize, + userAvailable: isize, } #[derive(Copy, Clone)] @@ -23,43 +23,48 @@ struct p_region_t { pub end: usize, } extern "C" { - pub(self) fn reserve_region(reg: p_region_t) -> bool; + pub(self) fn reserve_region(reg: p_region_t) -> bool; } #[no_mangle] #[link_section = ".boot.text"] -pub(self) static mut kernel_device_frames:[kernel_frame_t;NUM_KERNEL_DEVICE_FRAMES]=[ - kernel_frame_t{ - paddr:paddr_t(0x9000000), - pptr :UART_PPTR, - armExecuteNever : 1, - userAvailable : 1 - }, - kernel_frame_t{ - paddr : paddr_t(0x8000000), - pptr : GIC_V2_DISTRIBUTOR_PPTR, - armExecuteNever : 1, - userAvailable : 0 - }, - kernel_frame_t{ - paddr : paddr_t(0x8010000), - pptr : GIC_V2_CONTROLLER_PPTR, - armExecuteNever :1, - userAvailable :0 - }, +pub(self) static mut kernel_device_frames: [kernel_frame_t; NUM_KERNEL_DEVICE_FRAMES] = [ + kernel_frame_t { + paddr: paddr_t(0x9000000), + pptr: UART_PPTR, + armExecuteNever: 1, + userAvailable: 1, + }, + kernel_frame_t { + paddr: paddr_t(0x8000000), + pptr: GIC_V2_DISTRIBUTOR_PPTR, + armExecuteNever: 1, + userAvailable: 0, + }, + kernel_frame_t { + paddr: paddr_t(0x8010000), + pptr: GIC_V2_CONTROLLER_PPTR, + armExecuteNever: 1, + userAvailable: 0, + }, ]; #[no_mangle] -pub fn map_kernel_devices(){ - unsafe { - for kernel_frame in kernel_device_frames{ - let vm_attr:vm_attributes_t=vm_attributes_t(kernel_frame.armExecuteNever as usize); - map_kernel_frame(kernel_frame.paddr.0,kernel_frame.pptr,VMKernelOnly,vm_attr); - if kernel_frame.userAvailable ==0{ - reserve_region(p_region_t { - start: kernel_frame.paddr.0, - end: kernel_frame.paddr.0 + BIT!(PAGE_BITS), - }); - } - } - } -} \ No newline at end of file +pub fn map_kernel_devices() { + unsafe { + for kernel_frame in kernel_device_frames { + let vm_attr: vm_attributes_t = vm_attributes_t(kernel_frame.armExecuteNever as usize); + map_kernel_frame( + kernel_frame.paddr.0, + kernel_frame.pptr, + VMKernelOnly, + vm_attr, + ); + if kernel_frame.userAvailable == 0 { + reserve_region(p_region_t { + start: kernel_frame.paddr.0, + end: kernel_frame.paddr.0 + BIT!(PAGE_BITS), + }); + } + } + } +} diff --git a/sel4_vspace/src/arch/aarch64/mod.rs b/sel4_vspace/src/arch/aarch64/mod.rs index 0b6520f..34b502c 100644 --- a/sel4_vspace/src/arch/aarch64/mod.rs +++ b/sel4_vspace/src/arch/aarch64/mod.rs @@ -1,18 +1,18 @@ mod asid; mod boot; +mod device; mod interface; mod machine; mod pagetable; mod pte; mod structures; mod utils; -mod device; pub use asid::*; pub use boot::*; +pub use device::*; pub use interface::*; pub use machine::*; pub use pagetable::create_it_pud_cap; pub use pte::PTEFlags; pub use structures::*; pub use utils::*; -pub use device::*; \ No newline at end of file