Skip to content

Commit

Permalink
Add spawn-task example
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Mar 14, 2024
1 parent 9b844c9 commit 5d9339d
Show file tree
Hide file tree
Showing 13 changed files with 628 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ members = [
"crates/examples/root-task/example-root-task",
"crates/examples/root-task/example-root-task-without-runtime",
"crates/examples/root-task/hello",
"crates/examples/root-task/spawn-task",
"crates/examples/root-task/spawn-task/child",
"crates/examples/root-task/spawn-thread",
"crates/private/meta",
"crates/private/support/sel4-simple-task/config-types",
Expand Down
18 changes: 18 additions & 0 deletions crates/examples/root-task/spawn-task/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, versions, localCrates }:

mk {
package.name = "spawn-task";
dependencies = {
object = { version = versions.object; default-features = false; features = [ "read" ]; };
inherit (localCrates)
sel4
sel4-root-task
;
};
}
22 changes: 22 additions & 0 deletions crates/examples/root-task/spawn-task/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# 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 = "spawn-task"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
object = { version = "0.32.1", default-features = false, features = ["read"] }
sel4 = { path = "../../../sel4" }
sel4-root-task = { path = "../../../sel4-root-task" }
26 changes: 26 additions & 0 deletions crates/examples/root-task/spawn-task/child/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, versions, localCrates }:

mk {
package.name = "spawn-task-child";
dependencies = {
inherit (versions) cfg-if;
inherit (localCrates)
sel4
sel4-panicking-env
sel4-dlmalloc
sel4-sync
;
sel4-panicking = localCrates.sel4-panicking // {
features = [ "unwinding" "alloc" ];
};
sel4-runtime-common = localCrates.sel4-runtime-common // {
features = [ "start" "tls" "unwinding" ];
};
};
}
29 changes: 29 additions & 0 deletions crates/examples/root-task/spawn-task/child/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# 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 = "spawn-task-child"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
cfg-if = "1.0.0"
sel4 = { path = "../../../../sel4" }
sel4-dlmalloc = { path = "../../../../sel4-dlmalloc" }
sel4-panicking = { path = "../../../../sel4-panicking", features = ["unwinding", "alloc"] }
sel4-panicking-env = { path = "../../../../sel4-panicking/env" }
sel4-sync = { path = "../../../../sel4-sync" }

[dependencies.sel4-runtime-common]
path = "../../../../sel4-runtime-common"
features = ["start", "tls", "unwinding"]
20 changes: 20 additions & 0 deletions crates/examples/root-task/spawn-task/child/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]
#![no_main]

mod runtime;

fn main() -> ! {
sel4::debug_println!("In child task");

sel4::Notification::from_bits(1).signal();

sel4::Tcb::from_bits(2).tcb_suspend().unwrap();

unreachable!()
}
67 changes: 67 additions & 0 deletions crates/examples/root-task/spawn-task/child/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

use core::ptr;

use sel4::CapTypeForFrameObjectOfFixedSize;
use sel4_dlmalloc::{StaticDlmallocGlobalAlloc, StaticHeap};
use sel4_panicking::catch_unwind;
use sel4_panicking_env::abort;
use sel4_sync::{GenericRawMutex, PanickingMutexSyncOps};

use crate::main;

const STACK_SIZE: usize = 1024 * 64;

sel4_runtime_common::declare_stack!(STACK_SIZE);

const HEAP_SIZE: usize = 1024 * 64;

static STATIC_HEAP: StaticHeap<HEAP_SIZE> = StaticHeap::new();

#[global_allocator]
static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc<
GenericRawMutex<PanickingMutexSyncOps>,
&'static StaticHeap<HEAP_SIZE>,
> = StaticDlmallocGlobalAlloc::new(
GenericRawMutex::new(PanickingMutexSyncOps::new()),
&STATIC_HEAP,
);

sel4_panicking_env::register_debug_put_char!(sel4::debug_put_char);

#[no_mangle]
unsafe extern "C" fn sel4_runtime_rust_entry() -> ! {
unsafe extern "C" fn cont_fn(_cont_arg: *mut sel4_runtime_common::ContArg) -> ! {
inner_entry()
}

sel4_runtime_common::initialize_tls_on_stack_and_continue(cont_fn, ptr::null_mut())
}

fn inner_entry() -> ! {
unsafe {
sel4_runtime_common::set_eh_frame_finder().unwrap();
sel4::set_ipc_buffer(get_ipc_buffer().as_mut().unwrap());
sel4_runtime_common::run_ctors();
}

match catch_unwind(main) {
Ok(never) => never,
Err(_) => abort!("main() panicked"),
}
}

fn get_ipc_buffer() -> *mut sel4::IpcBuffer {
extern "C" {
static _end: usize;
}
unsafe {
(ptr::addr_of!(_end) as usize)
.next_multiple_of(sel4::cap_type::Granule::FRAME_OBJECT_TYPE.bytes())
as *mut sel4::IpcBuffer
}
}
Loading

0 comments on commit 5d9339d

Please sign in to comment.