diff --git a/Cargo.lock b/Cargo.lock index 70faca31c3..80360096b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -214,7 +214,6 @@ version = "0.1.0" dependencies = [ "bitflags 2.4.0", "caliptra-api-types", - "caliptra-emu-types", "caliptra-error", "caliptra-registers", "ureg", diff --git a/Cargo.toml b/Cargo.toml index ad3a1b5fa4..5585397fb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -112,7 +112,7 @@ caliptra-emu-cpu = { path = "sw-emulator/lib/cpu" } caliptra-emu-crypto = { path = "sw-emulator/lib/crypto" } caliptra-emu-derive = { path = "sw-emulator/lib/derive" } caliptra-emu-periph = { path = "sw-emulator/lib/periph" } -caliptra-emu-types = { path = "sw-emulator/lib/types" } +caliptra-emu-types = { path = "sw-emulator/lib/types", features = ["std"] } caliptra-error = { path = "error", default-features = false } caliptra-fpga-boss = { path = "ci-tools/fpga-boss" } caliptra-gen-linker-scripts = { path = "cpu/gen" } diff --git a/api/Cargo.toml b/api/Cargo.toml index 06cee6cc25..bde2e44d58 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -11,7 +11,6 @@ edition = "2021" bitflags.workspace = true caliptra-error.workspace = true zerocopy.workspace = true -caliptra-emu-types.workspace = true caliptra-registers.workspace = true caliptra-api-types.workspace = true ureg.workspace = true diff --git a/hw-model/src/model_emulated.rs b/hw-model/src/model_emulated.rs index 881bec4001..c4f71e536a 100644 --- a/hw-model/src/model_emulated.rs +++ b/hw-model/src/model_emulated.rs @@ -54,7 +54,7 @@ impl<'a> Bus for EmulatedApbBus<'a> { /// Emulated model pub struct ModelEmulated { - cpu: Cpu>, + cpu: Box>>, soc_to_caliptra_bus: SocToCaliptraBus, output: Output, trace_fn: Option>>, @@ -187,7 +187,7 @@ impl HwModel for ModelEmulated { dccm_dest.copy_from_slice(params.dccm); } let soc_to_caliptra_bus = root_bus.soc_to_caliptra_bus(); - let cpu = Cpu::new(BusLogger::new(root_bus), clock); + let cpu = Box::new(Cpu::new(BusLogger::new(root_bus), clock)); let mut hasher = DefaultHasher::new(); std::hash::Hash::hash_slice(params.rom, &mut hasher); diff --git a/sw-emulator/lib/cpu/src/csr_file.rs b/sw-emulator/lib/cpu/src/csr_file.rs index d77346ce4b..8a0575a986 100644 --- a/sw-emulator/lib/cpu/src/csr_file.rs +++ b/sw-emulator/lib/cpu/src/csr_file.rs @@ -102,7 +102,7 @@ impl Csr { /// Configuration and status register file pub struct CsrFile { /// CSRS - csrs: [Csr; CsrFile::CSR_COUNT], + csrs: Box<[Csr; CsrFile::CSR_COUNT]>, /// Timer timer: Timer, } @@ -114,7 +114,10 @@ impl CsrFile { /// Create a new Configuration and status register file pub fn new(clock: &Clock) -> Self { let mut csrs = Self { - csrs: [Csr::new(0, 0); CsrFile::CSR_COUNT], + csrs: vec![Csr::new(0, 0); CsrFile::CSR_COUNT] + .try_into() + .map_err(|_| ()) + .unwrap(), timer: Timer::new(clock), }; diff --git a/sw-emulator/lib/periph/src/root_bus.rs b/sw-emulator/lib/periph/src/root_bus.rs index d6d5c35f6c..827dbf1d40 100644 --- a/sw-emulator/lib/periph/src/root_bus.rs +++ b/sw-emulator/lib/periph/src/root_bus.rs @@ -268,7 +268,7 @@ pub struct CaliptraRootBus { pub sha256: HashSha256, #[peripheral(offset = 0x1003_0000, mask = 0x0000_7fff)] // TODO update when known - pub ml_dsa87: MlDsa87, + pub ml_dsa87: Box, #[peripheral(offset = 0x4000_0000, mask = 0x0fff_ffff)] pub iccm: Iccm, @@ -331,7 +331,7 @@ impl CaliptraRootBus { key_vault: key_vault.clone(), sha512, sha256: HashSha256::new(clock), - ml_dsa87: MlDsa87::new(clock), + ml_dsa87: Box::new(MlDsa87::new(clock)), iccm, dccm: Ram::new(vec![0; Self::DCCM_SIZE]), uart: Uart::new(), diff --git a/sw-emulator/lib/types/Cargo.toml b/sw-emulator/lib/types/Cargo.toml index 81a483692f..68d76afc0c 100644 --- a/sw-emulator/lib/types/Cargo.toml +++ b/sw-emulator/lib/types/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +[features] +std = [] \ No newline at end of file diff --git a/sw-emulator/lib/types/src/bus.rs b/sw-emulator/lib/types/src/bus.rs index 2b7019ceba..5e92848b8c 100644 --- a/sw-emulator/lib/types/src/bus.rs +++ b/sw-emulator/lib/types/src/bus.rs @@ -75,3 +75,26 @@ pub trait Bus { // By default, do nothing } } + +#[cfg(feature = "std")] +impl Bus for Box { + fn read(&mut self, size: RvSize, addr: RvAddr) -> Result { + T::read(self, size, addr) + } + + fn write(&mut self, size: RvSize, addr: RvAddr, val: RvData) -> Result<(), BusError> { + T::write(self, size, addr, val) + } + + fn poll(&mut self) { + T::poll(self) + } + + fn warm_reset(&mut self) { + T::warm_reset(self) + } + + fn update_reset(&mut self) { + T::update_reset(self) + } +} diff --git a/sw-emulator/lib/types/src/lib.rs b/sw-emulator/lib/types/src/lib.rs index 6b608907c3..16828d7458 100644 --- a/sw-emulator/lib/types/src/lib.rs +++ b/sw-emulator/lib/types/src/lib.rs @@ -11,7 +11,7 @@ Abstract: File contains exports for for Caliptra Emulator Types library. --*/ -#![cfg_attr(not(test), no_std)] +#![cfg_attr(not(any(test, feature = "std")), no_std)] pub mod bus; mod exception;