Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress on sel4 crate #15

Merged
merged 7 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions crates/private/support/sel4-simple-task/rpc/src/easy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub mod server {
F: FnOnce(Reception) -> T,
{
let (info, badge) = endpoint.recv(());
sel4::with_borrow_ipc_buffer(|ipc_buffer| {
sel4::with_ipc_buffer(|ipc_buffer| {
let reception = Reception::new(info, badge, ipc_buffer);
f(reception)
})
Expand All @@ -57,7 +57,7 @@ pub mod server {

pub fn reply<T: Serialize>(data: &T) -> Result<(), Error> {
let info = prepare_data_for_send(data)?;
sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| sel4::reply(ipc_buffer, info));
sel4::with_ipc_buffer_mut(|ipc_buffer| sel4::reply(ipc_buffer, info));
Ok(())
}
}
Expand Down Expand Up @@ -90,14 +90,14 @@ impl<'a> Reception<'a> {
}

pub fn read<T: for<'b> Deserialize<'b>>(&self) -> Result<T, Error> {
recv_data_with_borrow_ipc_buffer(&self.info, self.ipc_buffer())
recv_data_with_ipc_buffer(&self.info, self.ipc_buffer())
}
}

// // //

pub fn prepare_data_for_send<T: Serialize>(data: &T) -> Result<MessageInfo, Error> {
let used = sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| {
let used = sel4::with_ipc_buffer_mut(|ipc_buffer| {
postcard::to_slice(data, ipc_buffer.msg_bytes_mut()).map(|used| used.len())
})?;
Ok(MessageInfoBuilder::default()
Expand All @@ -106,7 +106,7 @@ pub fn prepare_data_for_send<T: Serialize>(data: &T) -> Result<MessageInfo, Erro
}

pub fn prepare_bytes_for_send(bytes: &[u8]) -> Result<MessageInfo, Error> {
sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| {
sel4::with_ipc_buffer_mut(|ipc_buffer| {
ipc_buffer.msg_bytes_mut()[..bytes.len()].copy_from_slice(bytes);
});
Ok(MessageInfoBuilder::default()
Expand All @@ -115,20 +115,17 @@ pub fn prepare_bytes_for_send(bytes: &[u8]) -> Result<MessageInfo, Error> {
}

fn recv_data<T: for<'a> Deserialize<'a>>(info: &MessageInfo) -> Result<T, Error> {
sel4::with_borrow_ipc_buffer(|ipc_buffer| recv_data_with_borrow_ipc_buffer(info, ipc_buffer))
sel4::with_ipc_buffer(|ipc_buffer| recv_data_with_ipc_buffer(info, ipc_buffer))
}

fn recv_data_with_borrow_ipc_buffer<T: for<'a> Deserialize<'a>>(
fn recv_data_with_ipc_buffer<T: for<'a> Deserialize<'a>>(
info: &MessageInfo,
ipc_buffer: &IPCBuffer,
) -> Result<T, Error> {
postcard::from_bytes(recv_bytes_with_borrow_ipc_buffer(ipc_buffer, info)).map_err(Into::into)
postcard::from_bytes(recv_bytes_with_ipc_buffer(ipc_buffer, info)).map_err(Into::into)
}

fn recv_bytes_with_borrow_ipc_buffer<'a>(
ipc_buffer: &'a IPCBuffer,
info: &MessageInfo,
) -> &'a [u8] {
fn recv_bytes_with_ipc_buffer<'a>(ipc_buffer: &'a IPCBuffer, info: &MessageInfo) -> &'a [u8] {
&ipc_buffer.msg_bytes()[..BYTES_PER_WORD * usize::try_from(info.length()).unwrap()]
}

Expand Down
65 changes: 64 additions & 1 deletion crates/sel4-capdl-initializer/core/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ mod imp {
pub(crate) type FrameType1 = sel4::cap_type::LargePage;
pub(crate) type FrameType2 = sel4::cap_type::HugePage;

pub(crate) type PageTableType = sel4::cap_type::PT;

pub(crate) const VSPACE_LEVELS: usize = if sel4::sel4_cfg_bool!(ARCH_AARCH64) {
4
} else {
2
};

pub(crate) fn map_page_table(
vspace: sel4::VSpace,
_level: usize,
vaddr: usize,
cap: sel4::Unspecified,
vm_attributes: sel4::VMAttributes,
) -> sel4::Result<()> {
cap.downcast::<PageTableType>()
.pt_map(vspace, vaddr, vm_attributes)
}

pub(crate) fn init_user_context(
regs: &mut sel4::UserContext,
extra: &sel4_capdl_initializer_types::object::TCBExtraInfo,
Expand All @@ -23,6 +42,35 @@ mod imp {
pub(crate) type FrameType1 = sel4::cap_type::LargePage;
pub(crate) type FrameType2 = sel4::cap_type::HugePage;

pub(crate) const VSPACE_LEVELS: usize = if sel4::sel4_cfg_bool!(ARCH_X86_64) {
4
} else {
2
};

pub(crate) fn map_page_table(
vspace: sel4::VSpace,
level: usize,
vaddr: usize,
cap: sel4::Unspecified,
vm_attributes: sel4::VMAttributes,
) -> sel4::Result<()> {
match level {
1 => cap
.downcast::<sel4::cap_type::PDPT>()
.pdpt_map(vspace, vaddr, vm_attributes),
2 => cap
.downcast::<sel4::cap_type::PageDirectory>()
.page_directory_map(vspace, vaddr, vm_attributes),
3 => cap.downcast::<sel4::cap_type::PageTable>().page_table_map(
vspace,
vaddr,
vm_attributes,
),
_ => panic!(),
}
}

pub(crate) fn init_user_context(
regs: &mut sel4::UserContext,
extra: &sel4_capdl_initializer_types::object::TCBExtraInfo,
Expand All @@ -40,6 +88,21 @@ mod imp {
pub(crate) type FrameType1 = sel4::cap_type::MegaPage;
pub(crate) type FrameType2 = sel4::cap_type::GigaPage;

pub(crate) type PageTableType = sel4::cap_type::PageTable;

pub(crate) const VSPACE_LEVELS: usize = sel4::sel4_cfg_usize!(PT_LEVELS);

pub(crate) fn map_page_table(
vspace: sel4::VSpace,
_level: usize,
vaddr: usize,
cap: sel4::Unspecified,
vm_attributes: sel4::VMAttributes,
) -> sel4::Result<()> {
cap.downcast::<PageTableType>()
.page_table_map(vspace, vaddr, vm_attributes)
}

pub(crate) fn init_user_context(
regs: &mut sel4::UserContext,
extra: &sel4_capdl_initializer_types::object::TCBExtraInfo,
Expand All @@ -55,7 +118,7 @@ mod imp {
pub(crate) use imp::*;

pub(crate) mod frame_types {
use sel4::FrameType;
use sel4::SizedFrameType;

pub(crate) use super::{FrameType1, FrameType2};

Expand Down
Loading