Skip to content

Commit

Permalink
add arch relevant invocation and add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
llh730 committed Aug 29, 2024
1 parent 3c9111d commit bd46717
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 119 deletions.
49 changes: 49 additions & 0 deletions src/syscall/invocation/arch/aarch64.rs
Original file line number Diff line number Diff line change
@@ -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
)
}
}
}
9 changes: 9 additions & 0 deletions src/syscall/invocation/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
34 changes: 34 additions & 0 deletions src/syscall/invocation/arch/riscv64.rs
Original file line number Diff line number Diff line change
@@ -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
)
}
}
}
151 changes: 32 additions & 119 deletions src/syscall/invocation/invoke_untyped.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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::<tcb_t>(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,
Expand All @@ -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::<tcb_t>(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::<tcb_t>(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 {
Expand Down
1 change: 1 addition & 0 deletions src/syscall/invocation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit bd46717

Please sign in to comment.