pub struct Cpu { /* private fields */ }Implementations§
Source§impl Cpu
impl Cpu
Sourcepub fn new() -> Cpu
pub fn new() -> Cpu
Examples found in repository?
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}pub fn reset(&mut self)
Sourcepub fn step(&mut self) -> bool
pub fn step(&mut self) -> bool
Step every core once. On the way in: bump system_steps; if the timer is due, broadcast IRQ_TIMER to all cores via AIC. Each core then either takes a pending IRQ (when DAIF.I is clear) or executes one instruction.
Sourcepub fn step_core(&mut self, idx: u32) -> bool
pub fn step_core(&mut self, idx: u32) -> bool
Step a single core. Honours pending IRQs on that core (set either by
the system timer in step() or by another core via IPI MMIO).
Sourcepub fn run(&mut self, max: u32) -> u32
pub fn run(&mut self, max: u32) -> u32
Examples found in repository?
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}Sourcepub fn system_steps(&self) -> u64
pub fn system_steps(&self) -> u64
Examples found in repository?
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}pub fn timer_period(&self) -> u64
Sourcepub fn timer_remaining(&self) -> u64
pub fn timer_remaining(&self) -> u64
System steps until the next timer IRQ fires (0 if it’s due now).
Sourcepub fn timer_ticks(&self) -> u64
pub fn timer_ticks(&self) -> u64
Examples found in repository?
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}Sourcepub fn aic_state(&self) -> AicState
pub fn aic_state(&self) -> AicState
Examples found in repository?
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}pub fn block_state(&self) -> BlockState
Sourcepub fn set_disk_text(&mut self, text: &str)
pub fn set_disk_text(&mut self, text: &str)
Replace disk sector 0 with the given UTF-8 text (padded with zeros to SECTOR_SIZE bytes). Also patches the live disk-buffer page at PA 0x6000 so task B’s printer reflects the change without a reset.
Examples found in repository?
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}pub fn disk_text(&self) -> String
Sourcepub fn state(&self) -> Vec<CoreState>
pub fn state(&self) -> Vec<CoreState>
Returns one CoreState per core.
Examples found in repository?
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}pub fn mem_slice(&self, start: u32, len: u32) -> Vec<u8> ⓘ
Sourcepub fn output(&self) -> String
pub fn output(&self) -> String
Examples found in repository?
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}Sourcepub fn translate(&self, va: u64, core_idx: u32) -> Option<TranslationResult>
pub fn translate(&self, va: u64, core_idx: u32) -> Option<TranslationResult>
Walk page tables for va using the sysregs of core_idx.
Returns None if core_idx is out of range.
pub fn entry_pc(&self) -> u64
pub fn uart_addr(&self) -> u64
pub fn l1_table_pa(&self) -> u64
pub fn num_cores(&self) -> u32
Sourcepub fn atomic_counter(&self) -> u64
pub fn atomic_counter(&self) -> u64
Reads the shared u64 atomic counter at PA 0x6FF8 — task A’s LDXR/STXR loop bumps it once per scheduling round.
Examples found in repository?
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}