Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decrease size of ModelEmulated from ~50k to 192 bytes. #1750

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 0 additions & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions hw-model/src/model_emulated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> Bus for EmulatedApbBus<'a> {

/// Emulated model
pub struct ModelEmulated {
cpu: Cpu<BusLogger<CaliptraRootBus>>,
cpu: Box<Cpu<BusLogger<CaliptraRootBus>>>,
swenson marked this conversation as resolved.
Show resolved Hide resolved
soc_to_caliptra_bus: SocToCaliptraBus,
output: Output,
trace_fn: Option<Box<InstrTracer<'static>>>,
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions sw-emulator/lib/cpu/src/csr_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]>,
swenson marked this conversation as resolved.
Show resolved Hide resolved
/// Timer
timer: Timer,
}
Expand All @@ -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),
};

Expand Down
4 changes: 2 additions & 2 deletions sw-emulator/lib/periph/src/root_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MlDsa87>,

#[peripheral(offset = 0x4000_0000, mask = 0x0fff_ffff)]
pub iccm: Iccm,
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions sw-emulator/lib/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
23 changes: 23 additions & 0 deletions sw-emulator/lib/types/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,26 @@ pub trait Bus {
// By default, do nothing
}
}

#[cfg(feature = "std")]
impl<T: Bus> Bus for Box<T> {
fn read(&mut self, size: RvSize, addr: RvAddr) -> Result<RvData, BusError> {
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)
}
}
2 changes: 1 addition & 1 deletion sw-emulator/lib/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading