diff --git a/src/syscall/invocation/arch/aarch64.rs b/src/syscall/invocation/arch/aarch64.rs new file mode 100644 index 0000000..0f84415 --- /dev/null +++ b/src/syscall/invocation/arch/aarch64.rs @@ -0,0 +1,49 @@ +use sel4_common::{arch::{vm_rights_t, ObjectType}, sel4_config::{asidInvalid, ARM_Large_Page, ARM_Small_Page}}; +use sel4_cspace::arch::cap_t; +use sel4_vspace::pptr_t; + +pub fn arch_create_object( + obj_type: ObjectType, + region_base: pptr_t, + user_size: usize, + device_mem: usize, +) -> cap_t { + match obj_type { + ObjectType::seL4_ARM_SmallPageObject => cap_t::new_frame_cap( + device_mem, + vm_rights_t::VMReadWrite as _, + 0, + ARM_Small_Page, + asidInvalid, + region_base, + ), + ObjectType::seL4_ARM_PageUpperDirectoryObject => { + cap_t::new_page_upper_directory_cap(asidInvalid, region_base, 0, 0) + } + ObjectType::seL4_ARM_PageDirectoryObject => { + cap_t::new_page_directory_cap(asidInvalid, region_base, 0, 0) + } + ObjectType::seL4_ARM_PageTableObject => { + cap_t::new_page_table_cap(asidInvalid, region_base, 0, 0) + } + ObjectType::seL4_ARM_PageGlobalDirectoryObject => { + cap_t::new_page_global_directory_cap(asidInvalid, region_base, 0) + } + ObjectType::seL4_ARM_LargePageObject => cap_t::new_frame_cap( + device_mem, + vm_rights_t::VMReadWrite as _, + 0, + ARM_Large_Page, + asidInvalid, + region_base, + ), + _ => { + unimplemented!( + "create object: {:?} region: {:#x} - {:#x}", + obj_type, + region_base, + region_base + user_size + ) + } + } +} diff --git a/src/syscall/invocation/arch/mod.rs b/src/syscall/invocation/arch/mod.rs new file mode 100644 index 0000000..dc07fff --- /dev/null +++ b/src/syscall/invocation/arch/mod.rs @@ -0,0 +1,9 @@ +#[cfg(target_arch = "aarch64")] +pub(crate) mod aarch64; +#[cfg(target_arch = "riscv64")] +pub(crate) mod riscv64; + +#[cfg(target_arch = "aarch64")] +pub use aarch64::*; +#[cfg(target_arch = "riscv64")] +pub use riscv64::*; diff --git a/src/syscall/invocation/arch/riscv64.rs b/src/syscall/invocation/arch/riscv64.rs new file mode 100644 index 0000000..7804abd --- /dev/null +++ b/src/syscall/invocation/arch/riscv64.rs @@ -0,0 +1,34 @@ +use sel4_common::{arch::{vm_rights_t, ObjectType}, sel4_config::asidInvalid}; +use sel4_cspace::arch::cap_t; +use sel4_vspace::pptr_t; + + +pub fn arch_create_object( + obj_type: ObjectType, + region_base: pptr_t, + user_size: usize, + device_mem: usize, +) -> cap_t { + match obj_type { + ObjectType::PageTableObject => cap_t::new_page_table_cap(asidInvalid, region_base, 0, 0), + + ObjectType::NormalPageObject | ObjectType::GigaPageObject | ObjectType::MegaPageObject => { + cap_t::new_frame_cap( + asidInvalid, + region_base, + obj_type.get_frame_type(), + vm_rights_t::VMReadWrite as usize, + device_mem as usize, + 0, + ) + } + _ => { + unimplemented!( + "create object: {:?} region: {:#x} - {:#x}", + obj_type, + region_base, + region_base + user_size + ) + } + } +} diff --git a/src/syscall/invocation/invoke_untyped.rs b/src/syscall/invocation/invoke_untyped.rs index f87e074..d6ef99f 100644 --- a/src/syscall/invocation/invoke_untyped.rs +++ b/src/syscall/invocation/invoke_untyped.rs @@ -1,8 +1,9 @@ // use crate::ffi::tcbDebugAppend; +use super::arch::arch_create_object; use crate::syscall::{ FREE_INDEX_TO_OFFSET, GET_FREE_INDEX, GET_OFFSET_FREE_PTR, OFFSET_TO_FREE_IDNEX, }; -use sel4_common::arch::{vm_rights_t, ObjectType}; +use sel4_common::arch::ObjectType; use sel4_common::{ sel4_config::*, structures::exception_t, utils::convert_to_mut_type_ref, BIT, ROUND_DOWN, }; @@ -35,7 +36,35 @@ fn create_new_objects( } } -#[cfg(target_arch = "riscv64")] +// #[cfg(target_arch = "riscv64")] +// fn create_object( +// obj_type: ObjectType, +// region_base: pptr_t, +// user_size: usize, +// device_mem: usize, +// ) -> cap_t { +// match obj_type { +// ObjectType::TCBObject => { +// let tcb = convert_to_mut_type_ref::(region_base + TCB_OFFSET); +// tcb.init(); +// tcb.tcbTimeSlice = CONFIG_TIME_SLICE; +// tcb.domain = get_current_domain(); +// // #[cfg(feature="DEBUG_BUILD")] +// // unsafe { +// // tcbDebugAppend(tcb as *mut tcb_t); +// // } +// return cap_t::new_thread_cap(tcb.get_ptr()); +// } + +// ObjectType::EndpointObject => cap_t::new_endpoint_cap(0, 1, 1, 1, 1, region_base), + +// ObjectType::NotificationObject => cap_t::new_notification_cap(0, 1, 1, region_base), + +// ObjectType::CapTableObject => cap_t::new_cnode_cap(user_size, 0, 0, region_base), + +// ObjectType::UnytpedObject => cap_t::new_untyped_cap(0, device_mem, user_size, region_base), +// } +// } fn create_object( obj_type: ObjectType, region_base: pptr_t, @@ -54,128 +83,12 @@ fn create_object( // } return cap_t::new_thread_cap(tcb.get_ptr()); } - - ObjectType::EndpointObject => cap_t::new_endpoint_cap(0, 1, 1, 1, 1, region_base), - - ObjectType::NotificationObject => cap_t::new_notification_cap(0, 1, 1, region_base), - - ObjectType::CapTableObject => cap_t::new_cnode_cap(user_size, 0, 0, region_base), - - ObjectType::UnytpedObject => cap_t::new_untyped_cap(0, device_mem, user_size, region_base), - - ObjectType::PageTableObject => cap_t::new_page_table_cap(asidInvalid, region_base, 0, 0), - - ObjectType::NormalPageObject | ObjectType::GigaPageObject | ObjectType::MegaPageObject => { - cap_t::new_frame_cap( - asidInvalid, - region_base, - obj_type.get_frame_type(), - vm_rights_t::VMReadWrite as usize, - device_mem as usize, - 0, - ) - } - } -} -#[cfg(target_arch = "aarch64")] -fn create_object( - obj_type: ObjectType, - region_base: pptr_t, - user_size: usize, - device_mem: usize, -) -> cap_t { - match obj_type { - ObjectType::TCBObject => { - let tcb = convert_to_mut_type_ref::(region_base + TCB_OFFSET); - tcb.init(); - tcb.tcbTimeSlice = CONFIG_TIME_SLICE; - tcb.domain = get_current_domain(); - // #[cfg(feature="DEBUG_BUILD")] - // unsafe { - // tcbDebugAppend(tcb as *mut tcb_t); - // } - return cap_t::new_thread_cap(tcb.get_ptr()); - } - - ObjectType::seL4_ARM_SmallPageObject => cap_t::new_frame_cap( - device_mem, - vm_rights_t::VMReadWrite as _, - 0, - ARM_Small_Page, - asidInvalid, - region_base, - ), ObjectType::CapTableObject => cap_t::new_cnode_cap(user_size, 0, 0, region_base), ObjectType::NotificationObject => cap_t::new_notification_cap(0, 1, 1, region_base), ObjectType::EndpointObject => cap_t::new_endpoint_cap(0, 1, 1, 1, 1, region_base), ObjectType::UnytpedObject => cap_t::new_untyped_cap(0, device_mem, user_size, region_base), - // TODO: remove ARCH related object to arch-specific module. - ObjectType::seL4_ARM_PageUpperDirectoryObject => { - cap_t::new_page_upper_directory_cap(asidInvalid, region_base, 0, 0) - } - // TODO: remove ARCH related object to arch-specific module. - ObjectType::seL4_ARM_PageDirectoryObject => { - cap_t::new_page_directory_cap(asidInvalid, region_base, 0, 0) - } - // TODO: remove ARCH related object to arch-specific module. - ObjectType::seL4_ARM_PageTableObject => { - cap_t::new_page_table_cap(asidInvalid, region_base, 0, 0) - } - // TODO: remove ARCH related object to arch-specific module. - ObjectType::seL4_ARM_PageGlobalDirectoryObject => { - cap_t::new_page_global_directory_cap(asidInvalid, region_base, 0) - } - // TODO: remove ARCH related object to arch-specific module. - ObjectType::seL4_ARM_LargePageObject => cap_t::new_frame_cap( - device_mem, - vm_rights_t::VMReadWrite as _, - 0, - ARM_Large_Page, - asidInvalid, - region_base, - ), - _ => { - unimplemented!( - "create object: {:?} region: {:#x} - {:#x}", - obj_type, - region_base, - region_base + user_size - ) - } + _ => arch_create_object(obj_type, region_base, user_size, device_mem), } - // match obj_type { - // ObjectType::TCBObject => { - // let tcb = convert_to_mut_type_ref::(region_base + TCB_OFFSET); - // tcb.init(); - // tcb.tcbTimeSlice = CONFIG_TIME_SLICE; - // tcb.domain = get_current_domain(); - // unsafe { - // tcbDebugAppend(tcb as *mut tcb_t); - // } - // return cap_t::new_thread_cap(tcb.get_ptr()); - // } - - // ObjectType::EndpointObject => cap_t::new_endpoint_cap(0, 1, 1, 1, 1, region_base), - - // ObjectType::NotificationObject => cap_t::new_notification_cap(0, 1, 1, region_base), - - // ObjectType::CapTableObject => cap_t::new_cnode_cap(user_size, 0, 0, region_base), - - // ObjectType::UnytpedObject => cap_t::new_untyped_cap(0, device_mem, user_size, region_base), - - // ObjectType::PageTableObject => cap_t::new_page_table_cap(asidInvalid, region_base, 0, 0), - - // ObjectType::NormalPageObject | ObjectType::GigaPageObject | ObjectType::MegaPageObject => { - // cap_t::new_frame_cap( - // asidInvalid, - // region_base, - // obj_type.get_frame_type(), - // vm_rights_t::VMReadWrite as usize, - // device_mem as usize, - // 0, - // ) - // } - // } } pub fn reset_untyped_cap(srcSlot: &mut cte_t) -> exception_t { diff --git a/src/syscall/invocation/mod.rs b/src/syscall/invocation/mod.rs index 3c62ed5..8d5f7b4 100644 --- a/src/syscall/invocation/mod.rs +++ b/src/syscall/invocation/mod.rs @@ -4,6 +4,7 @@ pub mod invoke_irq; mod invoke_mmu_op; mod invoke_tcb; mod invoke_untyped; +pub(crate) mod arch; use core::intrinsics::unlikely;