diff --git a/app/grapefruit/app.toml b/app/grapefruit/app.toml index 7d21e50ea..79cb2ec55 100644 --- a/app/grapefruit/app.toml +++ b/app/grapefruit/app.toml @@ -109,6 +109,7 @@ max-sizes = {flash = 8192, ram = 2048} start = true # task-slots is explicitly empty: packrat should not send IPCs! task-slots = [] +features = ["grapefruit", "boot-kmdb"] [tasks.hiffy] name = "task-hiffy" diff --git a/task/packrat/Cargo.toml b/task/packrat/Cargo.toml index 9221c4fb8..8b7aeb80e 100644 --- a/task/packrat/Cargo.toml +++ b/task/packrat/Cargo.toml @@ -26,6 +26,7 @@ build-util = { path = "../../build/util" } [features] gimlet = ["drv-cpu-seq-api"] +grapefruit = [] boot-kmdb = [] no-ipc-counters = ["idol/no-counters"] diff --git a/task/packrat/src/grapefruit.rs b/task/packrat/src/grapefruit.rs new file mode 100644 index 000000000..a9b2b9edf --- /dev/null +++ b/task/packrat/src/grapefruit.rs @@ -0,0 +1,46 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +//! Grapefruit-specific packrat data. + +use task_packrat_api::HostStartupOptions; + +pub(crate) struct GrapefruitData { + host_startup_options: HostStartupOptions, +} + +const fn default_host_startup_options() -> HostStartupOptions { + if cfg!(feature = "boot-kmdb") { + // We have to do this because const fn. + let bits = HostStartupOptions::STARTUP_KMDB.bits() + | HostStartupOptions::STARTUP_PROM.bits() + | HostStartupOptions::STARTUP_VERBOSE.bits() + | HostStartupOptions::STARTUP_BOOT_RAMDISK.bits(); + match HostStartupOptions::from_bits(bits) { + Some(options) => options, + None => panic!("must be valid at compile-time"), + } + } else { + HostStartupOptions::empty() + } +} + +impl GrapefruitData { + pub(crate) fn new() -> Self { + Self { + host_startup_options: default_host_startup_options(), + } + } + + pub(crate) fn host_startup_options(&self) -> HostStartupOptions { + self.host_startup_options + } + + pub(crate) fn set_host_startup_options( + &mut self, + options: HostStartupOptions, + ) { + self.host_startup_options = options; + } +} diff --git a/task/packrat/src/main.rs b/task/packrat/src/main.rs index 71b33dc94..bcd004df1 100644 --- a/task/packrat/src/main.rs +++ b/task/packrat/src/main.rs @@ -42,6 +42,9 @@ use userlib::RecvMessage; #[cfg(feature = "gimlet")] mod gimlet; +#[cfg(feature = "grapefruit")] +mod grapefruit; + #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[allow(dead_code)] // not all variants are used, depending on cargo features enum Trace { @@ -111,6 +114,8 @@ fn main() -> ! { identity, #[cfg(feature = "gimlet")] gimlet_data: gimlet::GimletData::new(gimlet_bufs), + #[cfg(feature = "grapefruit")] + grapefruit_data: grapefruit::GrapefruitData::new(), }; let mut buffer = [0; idl::INCOMING_SIZE]; @@ -124,6 +129,8 @@ struct ServerImpl { identity: &'static mut Option, #[cfg(feature = "gimlet")] gimlet_data: gimlet::GimletData, + #[cfg(feature = "grapefruit")] + grapefruit_data: grapefruit::GrapefruitData, } impl ServerImpl { @@ -204,7 +211,15 @@ impl idl::InOrderPackratImpl for ServerImpl { Ok(self.gimlet_data.host_startup_options()) } - #[cfg(not(feature = "gimlet"))] + #[cfg(feature = "grapefruit")] + fn get_next_boot_host_startup_options( + &mut self, + _: &RecvMessage, + ) -> Result> { + Ok(self.grapefruit_data.host_startup_options()) + } + + #[cfg(not(any(feature = "gimlet", feature = "grapefruit")))] fn get_next_boot_host_startup_options( &mut self, _: &RecvMessage, @@ -228,7 +243,21 @@ impl idl::InOrderPackratImpl for ServerImpl { Ok(()) } - #[cfg(not(feature = "gimlet"))] + #[cfg(feature = "grapefruit")] + fn set_next_boot_host_startup_options( + &mut self, + _: &RecvMessage, + host_startup_options: HostStartupOptions, + ) -> Result<(), RequestError> { + ringbuf_entry!(Trace::SetNextBootHostStartupOptions( + host_startup_options + )); + self.grapefruit_data + .set_host_startup_options(host_startup_options); + Ok(()) + } + + #[cfg(not(any(feature = "gimlet", feature = "grapefruit")))] fn set_next_boot_host_startup_options( &mut self, _: &RecvMessage,