Skip to main content

run/
run.rs

1//! Embed `aarch64-sim` in a plain Rust program.
2//!
3//! Boots the demo, runs for 4000 steps, and prints a few interesting fields.
4//! Run with: `cargo run --example run -p aarch64-sim` (no features needed).
5
6use aarch64_sim::Cpu;
7
8fn main() {
9    let mut cpu = Cpu::new();
10
11    // Override the disk content so task B prints something custom.
12    cpu.set_disk_text("hello, aarch64-sim!\n");
13
14    let _retired = cpu.run(4000);
15
16    println!("system steps: {}", cpu.system_steps());
17    println!("timer ticks:  {}", cpu.timer_ticks());
18    println!("atomic ctr:   {}", cpu.atomic_counter());
19
20    let aic = cpu.aic_state();
21    println!("AIC acks:     {}", aic.total_acks);
22    println!("IPIs sent:    {}", aic.total_ipis);
23
24    println!("UART output:  {:?}", cpu.output());
25
26    for c in cpu.state() {
27        println!(
28            "core {}  {}  pc={:#010x}  el={}  wfi={}",
29            c.id, c.kind, c.pc, c.current_el, c.wfi_halted,
30        );
31    }
32}