From 8b8465a63c7c1eea1b8c1733ea5924f370120042 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Tue, 5 Mar 2024 07:15:34 +0000 Subject: [PATCH] sel4-simple-task: Add 32-bit support Signed-off-by: Nick Spinale --- .../sel4-simple-task/config-types/src/lib.rs | 4 +-- .../config-types/src/when_not_sel4.rs | 2 ++ .../config-types/src/when_sel4.rs | 2 ++ .../sel4-simple-task/runtime/Cargo.nix | 7 +++--- .../sel4-simple-task/runtime/Cargo.toml | 6 +++-- .../sel4-simple-task/runtime/src/lib.rs | 25 ++++++++++++++++--- .../capdl_simple_composition/kernel_config.py | 11 +++++--- 7 files changed, 42 insertions(+), 15 deletions(-) diff --git a/crates/private/support/sel4-simple-task/config-types/src/lib.rs b/crates/private/support/sel4-simple-task/config-types/src/lib.rs index 5b4ad1259..c8b422ae4 100644 --- a/crates/private/support/sel4-simple-task/config-types/src/lib.rs +++ b/crates/private/support/sel4-simple-task/config-types/src/lib.rs @@ -20,8 +20,6 @@ cfg_if::cfg_if! { } } -pub type RawConfigWord = u64; - #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(transparent)] pub struct ConfigBadge(RawConfigWord); @@ -34,7 +32,7 @@ impl ConfigBadge { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[serde(transparent)] -pub struct ConfigCPtrBits(u64); +pub struct ConfigCPtrBits(RawConfigWord); impl ConfigCPtrBits { pub fn new(word: RawConfigWord) -> Self { diff --git a/crates/private/support/sel4-simple-task/config-types/src/when_not_sel4.rs b/crates/private/support/sel4-simple-task/config-types/src/when_not_sel4.rs index 45c319877..33f0fe03a 100644 --- a/crates/private/support/sel4-simple-task/config-types/src/when_not_sel4.rs +++ b/crates/private/support/sel4-simple-task/config-types/src/when_not_sel4.rs @@ -4,6 +4,8 @@ // SPDX-License-Identifier: BSD-2-Clause // +pub type RawConfigWord = u64; + macro_rules! dummies { { $($i:ident)* diff --git a/crates/private/support/sel4-simple-task/config-types/src/when_sel4.rs b/crates/private/support/sel4-simple-task/config-types/src/when_sel4.rs index 626e3d017..dad3a9c06 100644 --- a/crates/private/support/sel4-simple-task/config-types/src/when_sel4.rs +++ b/crates/private/support/sel4-simple-task/config-types/src/when_sel4.rs @@ -11,6 +11,8 @@ use sel4::{Badge, CPtrBits, Cap, CapType}; use crate::{ConfigBadge, ConfigCPtr, ConfigCPtrBits}; +pub type RawConfigWord = sel4::Word; + pub trait WrappedCPtr { fn wrap(bits: CPtrBits) -> Self; } diff --git a/crates/private/support/sel4-simple-task/runtime/Cargo.nix b/crates/private/support/sel4-simple-task/runtime/Cargo.nix index 5ed0c91aa..f6ff2e864 100644 --- a/crates/private/support/sel4-simple-task/runtime/Cargo.nix +++ b/crates/private/support/sel4-simple-task/runtime/Cargo.nix @@ -15,7 +15,6 @@ mk { inherit (localCrates) sel4 - sel4-backtrace-simple sel4-dlmalloc sel4-immediate-sync-once-cell sel4-panicking @@ -25,10 +24,12 @@ mk { sel4-simple-task-threading sel4-sync ; - - sel4-backtrace = localCrates.sel4-backtrace // { features = [ "unwinding" "postcard" ]; }; sel4-runtime-common = localCrates.sel4-runtime-common // { features = [ "tls" "unwinding" ]; }; }; + target."cfg(not(target_arch = \"arm\"))".dependencies = { + sel4-backtrace = localCrates.sel4-backtrace // { features = [ "unwinding" "postcard" ]; }; + inherit (localCrates) sel4-backtrace-simple; + }; features = { serde_json = [ "dep:serde_json" diff --git a/crates/private/support/sel4-simple-task/runtime/Cargo.toml b/crates/private/support/sel4-simple-task/runtime/Cargo.toml index 7f9303cf9..a8b379996 100644 --- a/crates/private/support/sel4-simple-task/runtime/Cargo.toml +++ b/crates/private/support/sel4-simple-task/runtime/Cargo.toml @@ -29,8 +29,6 @@ serde_json = ["dep:serde_json"] [dependencies] postcard = { version = "1.0.2", default-features = false } sel4 = { path = "../../../../sel4" } -sel4-backtrace = { path = "../../../../sel4-backtrace", features = ["unwinding", "postcard"] } -sel4-backtrace-simple = { path = "../../../../sel4-backtrace/simple" } sel4-dlmalloc = { path = "../../../../sel4-dlmalloc" } sel4-immediate-sync-once-cell = { path = "../../../../sel4-immediate-sync-once-cell" } sel4-panicking = { path = "../../../../sel4-panicking" } @@ -42,3 +40,7 @@ sel4-simple-task-threading = { path = "../threading" } sel4-sync = { path = "../../../../sel4-sync" } serde = { version = "1.0.147", default-features = false } serde_json = { version = "1.0.87", default-features = false, optional = true } + +[target."cfg(not(target_arch = \"arm\"))".dependencies] +sel4-backtrace = { path = "../../../../sel4-backtrace", features = ["unwinding", "postcard"] } +sel4-backtrace-simple = { path = "../../../../sel4-backtrace/simple" } diff --git a/crates/private/support/sel4-simple-task/runtime/src/lib.rs b/crates/private/support/sel4-simple-task/runtime/src/lib.rs index 91b80b20c..e6f8c21cd 100644 --- a/crates/private/support/sel4-simple-task/runtime/src/lib.rs +++ b/crates/private/support/sel4-simple-task/runtime/src/lib.rs @@ -16,7 +16,6 @@ use core::ptr; use core::slice; use sel4::Endpoint; -use sel4_backtrace_simple::SimpleBacktracing; use sel4_dlmalloc::StaticHeapBounds; use sel4_immediate_sync_once_cell::ImmediateSyncOnceCell; use sel4_panicking::ExternalPanicInfo; @@ -24,6 +23,9 @@ use sel4_panicking_env::{abort, AbortInfo}; use sel4_simple_task_runtime_config_types::RuntimeConfig; use sel4_simple_task_threading::StaticThread; +#[cfg(not(target_arch = "arm"))] +use sel4_backtrace_simple::SimpleBacktracing; + mod declare_main; mod termination; @@ -79,12 +81,17 @@ pub unsafe extern "C" fn cont_fn(cont_arg: *mut sel4_runtime_common::ContArg) -> if thread_index == 0 { CONFIG.set(config.clone()).unwrap(); - sel4_runtime_common::set_eh_frame_finder().unwrap(); + + #[cfg(not(target_arch = "arm"))] + { + sel4_runtime_common::set_eh_frame_finder().unwrap(); + } + sel4_panicking::set_hook(&panic_hook); sel4_runtime_common::run_ctors(); __sel4_simple_task_main(config.arg()); } else { - let endpoint = Endpoint::from_bits(thread_config.endpoint().unwrap()); + let endpoint = Endpoint::from_bits(thread_config.endpoint().unwrap().try_into().unwrap()); let reply_authority = { sel4::sel4_cfg_if! { if #[sel4_cfg(KERNEL_MCS)] { @@ -105,6 +112,8 @@ pub fn try_idle() { CONFIG .get() .and_then(RuntimeConfig::idle_notification) + .map(sel4::CPtrBits::try_from) + .map(Result::unwrap) .map(sel4::Notification::from_bits) .map(sel4::Notification::wait); } @@ -128,7 +137,11 @@ sel4_panicking_env::register_debug_put_char!(sel4::debug_put_char); fn panic_hook(info: &ExternalPanicInfo<'_>) { debug_println!("{}", info); - get_backtracing().collect_and_send(); + + #[cfg(not(target_arch = "arm"))] + { + get_backtracing().collect_and_send(); + } } fn get_static_heap_bounds() -> StaticHeapBounds { @@ -144,14 +157,18 @@ fn get_static_heap_mutex_notification() -> sel4::Notification { .get() .unwrap() .static_heap_mutex_notification() + .map(sel4::CPtrBits::try_from) + .map(Result::unwrap) .map(sel4::Notification::from_bits) .unwrap() } +#[cfg(not(target_arch = "arm"))] pub fn get_backtracing() -> SimpleBacktracing { SimpleBacktracing::new(get_backtrace_image_identifier()) } +#[allow(dead_code)] fn get_backtrace_image_identifier() -> Option<&'static str> { CONFIG.get().unwrap().image_identifier() } diff --git a/hacking/src/python/capdl_simple_composition/kernel_config.py b/hacking/src/python/capdl_simple_composition/kernel_config.py index acbc3e362..b31765e18 100644 --- a/hacking/src/python/capdl_simple_composition/kernel_config.py +++ b/hacking/src/python/capdl_simple_composition/kernel_config.py @@ -37,11 +37,16 @@ def is_mcs(self): # TODO def page_sizes_in_bits(self): - if self.arch() == 'arm': + sel4_arch = self.sel4_arch() + if sel4_arch == 'aarch64': return [12, 21] - elif self.sel4_arch() == 'riscv64': + elif sel4_arch == 'aarch32': + return [12, 20] + elif sel4_arch == 'riscv64': return [12, 21] - elif self.arch() == 'x86': + elif sel4_arch == 'riscv32': + return [12, 22] + elif sel4_arch == 'x86_64': return [12, 21] else: raise NotImplementedError