-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crates/sel4-microkit: Factor out runtime
Signed-off-by: Nick Spinale <[email protected]>
- Loading branch information
Showing
23 changed files
with
468 additions
and
399 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Copyright 2023, Colias Group, LLC | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
|
||
{ mk, localCrates }: | ||
|
||
mk { | ||
package.name = "sel4-microkit-base"; | ||
dependencies = { | ||
inherit (localCrates) | ||
sel4-immutable-cell | ||
sel4 | ||
; | ||
}; | ||
features = { | ||
extern-symbols = []; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# Copyright 2023, Colias Group, LLC | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# | ||
# This file is generated from './Cargo.nix'. You can edit this file directly | ||
# if you are not using this project's Cargo manifest management tools. | ||
# See 'hacking/cargo-manifest-management/README.md' for more information. | ||
# | ||
|
||
[package] | ||
name = "sel4-microkit-base" | ||
version = "0.1.0" | ||
authors = ["Nick Spinale <[email protected]>"] | ||
edition = "2021" | ||
license = "BSD-2-Clause" | ||
|
||
[features] | ||
extern-symbols = [] | ||
|
||
[dependencies] | ||
sel4 = { path = "../../sel4" } | ||
sel4-immutable-cell = { path = "../../sel4-immutable-cell" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// Copyright 2023, Colias Group, LLC | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// | ||
|
||
use core::fmt; | ||
|
||
use crate::MessageInfo; | ||
|
||
const BASE_OUTPUT_NOTIFICATION_SLOT: usize = 10; | ||
const BASE_ENDPOINT_SLOT: usize = BASE_OUTPUT_NOTIFICATION_SLOT + 64; | ||
const BASE_IRQ_SLOT: usize = BASE_ENDPOINT_SLOT + 64; | ||
|
||
const MAX_CHANNELS: usize = 63; | ||
|
||
/// A channel between this protection domain and another, identified by a channel index. | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
pub struct Channel { | ||
index: usize, | ||
} | ||
|
||
impl Channel { | ||
pub const fn new(index: usize) -> Self { | ||
assert!(index < MAX_CHANNELS); | ||
Self { index } | ||
} | ||
|
||
fn cap<T: sel4::CapType>(&self, base_slot: usize) -> sel4::Cap<T> { | ||
sel4::Cap::from_bits((base_slot + self.index) as sel4::CPtrBits) | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn notification(&self) -> sel4::Notification { | ||
self.cap::<sel4::cap_type::Notification>(BASE_OUTPUT_NOTIFICATION_SLOT) | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn irq_handler(&self) -> sel4::IrqHandler { | ||
self.cap::<sel4::cap_type::IrqHandler>(BASE_IRQ_SLOT) | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn endpoint(&self) -> sel4::Endpoint { | ||
self.cap::<sel4::cap_type::Endpoint>(BASE_ENDPOINT_SLOT) | ||
} | ||
|
||
pub fn notify(&self) { | ||
self.notification().signal() | ||
} | ||
|
||
pub fn irq_ack(&self) -> Result<(), IrqAckError> { | ||
self.irq_handler() | ||
.irq_handler_ack() | ||
.map_err(IrqAckError::from_inner) | ||
} | ||
|
||
pub fn pp_call(&self, msg_info: MessageInfo) -> MessageInfo { | ||
MessageInfo::from_inner(self.endpoint().call(msg_info.into_inner())) | ||
} | ||
} | ||
|
||
/// Error type returned by [`Channel::irq_ack`]. | ||
#[derive(Debug, PartialEq, Eq)] | ||
pub struct IrqAckError(sel4::Error); | ||
|
||
impl IrqAckError { | ||
fn from_inner(inner: sel4::Error) -> Self { | ||
Self(inner) | ||
} | ||
|
||
fn inner(&self) -> &sel4::Error { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl fmt::Display for IrqAckError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "irq ack error: {:?}", self.inner()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright 2024, Colias Group, LLC | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// | ||
|
||
#![no_std] | ||
#![feature(used_with_arg)] | ||
|
||
mod channel; | ||
mod message; | ||
mod symbols; | ||
|
||
pub use channel::{Channel, IrqAckError}; | ||
pub use message::{ | ||
get_mr, set_mr, with_msg_bytes, with_msg_bytes_mut, with_msg_regs, with_msg_regs_mut, | ||
MessageInfo, MessageLabel, MessageRegisterValue, | ||
}; | ||
pub use symbols::{ipc_buffer_ptr, pd_is_passive, pd_name}; | ||
|
||
// For macros | ||
#[doc(hidden)] | ||
pub mod _private { | ||
pub use sel4_immutable_cell::ImmutableCell; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.