From 4f8169c3d93e8e088283c30cb395dcdfa085ee8d Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 20 Sep 2025 22:13:16 +0800 Subject: [PATCH] fixup rand for simulation target TRNG doesn't exist in simulation - substitute it for a deterministic PRNG when the simulation target is specified. --- kernel/src/platform/bao1x/mod.rs | 6 +++++- kernel/src/platform/bao1x/rand_fake.rs | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/src/platform/bao1x/mod.rs b/kernel/src/platform/bao1x/mod.rs index 856ed6bfe..e649e6f65 100644 --- a/kernel/src/platform/bao1x/mod.rs +++ b/kernel/src/platform/bao1x/mod.rs @@ -2,7 +2,11 @@ // SPDX-FileCopyrightText: 2024 bunnie // SPDX-License-Identifier: Apache-2.0 -#[cfg(feature = "bao1x")] +#[cfg(all(feature = "bao1x", not(feature = "verilator-only")))] +#[path = "rand.rs"] +pub mod rand; +#[cfg(all(feature = "bao1x", feature = "verilator-only"))] +#[path = "rand_fake.rs"] pub mod rand; #[cfg(any(feature = "debug-print", feature = "print-panics"))] diff --git a/kernel/src/platform/bao1x/rand_fake.rs b/kernel/src/platform/bao1x/rand_fake.rs index 217671f63..3e6932b7b 100644 --- a/kernel/src/platform/bao1x/rand_fake.rs +++ b/kernel/src/platform/bao1x/rand_fake.rs @@ -24,7 +24,9 @@ static LOCAL_RNG_STATE: [AtomicU32; 8] = [ pub fn init() {} -/// This a fully deterministic PRNG that relies on Chacha8 for state evolution. +/// This a fully deterministic PRNG that relies on Chacha8 for state evolution. This is +/// used in verilator simulation environments. +#[cfg(feature = "verilator-only")] pub fn get_u32() -> u32 { // Local storage for the seed. let mut seed = [0u8; 32];