aboutsummaryrefslogtreecommitdiff
path: root/src/simulator.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulator.rs')
-rw-r--r--src/simulator.rs63
1 files changed, 39 insertions, 24 deletions
diff --git a/src/simulator.rs b/src/simulator.rs
index 0101c44..4feb1c0 100644
--- a/src/simulator.rs
+++ b/src/simulator.rs
@@ -368,34 +368,49 @@ impl<'a> Simulator<'a> {
}
}
- pub fn run(&mut self) {
- loop {
- let mut ran = false;
- for core in self.cores.iter_mut() {
- if !core.running {
- continue;
- }
+ fn step(&mut self) -> bool {
+ let mut ran = false;
+ for core in self.cores.iter_mut() {
+ if !core.running {
+ continue;
+ }
- let pc = core.pc;
- let pc = core.mmu.translate(pc);
- let inst = self.memory.borrow_mut().read_instruction(pc);
+ let pc = core.pc;
+ let pc = core.mmu.translate(pc);
+ let inst = self.memory.borrow_mut().read_instruction(pc);
- if let Some(inst) = inst {
- core.step(inst);
- }
- else {
- // TODO: trap
- }
+ if let Some(inst) = inst {
+ core.step(inst);
+ }
+ else {
+ // TODO: trap
+ }
- core.cache.borrow_mut().step();
- ran = true;
+ core.cache.borrow_mut().step();
+ ran = true;
+ }
+ if !ran {
+ println!("All cores are not running, stopping...");
+ for (i, core) in self.cores.iter().enumerate() {
+ println!("Core {}: stalled {} of {}", i, core.stall_count, core.cycle_count);
}
- if !ran {
- println!("All cores are not running, stopping...");
- for (i, core) in self.cores.iter().enumerate() {
- println!("Core {}: stalled {} of {}", i, core.stall_count, core.cycle_count);
- }
- break;
+ }
+
+ ran
+ }
+
+ pub fn run(&mut self) {
+ loop {
+ if !self.step() {
+ break
+ }
+ }
+ }
+
+ pub fn run_max(&mut self, cycles: usize) {
+ for _ in 0..cycles {
+ if !self.step() {
+ break
}
}
}