Debugging mode
This commit is contained in:
150
simu/src/main.rs
150
simu/src/main.rs
@@ -8,6 +8,7 @@
|
||||
|
||||
use std::env::args;
|
||||
use std::hint::unlikely;
|
||||
use std::io::stdin;
|
||||
use std::process::exit;
|
||||
use std::sync::{
|
||||
Arc,
|
||||
@@ -34,6 +35,7 @@ use cpu::SHARED;
|
||||
fn wait_int() {
|
||||
let mut v = (&SHARED.external_interupts).load(Acquire);
|
||||
while unlikely(v != 0) {
|
||||
#[cfg(feature = "debug")]
|
||||
println!("wating for interupt clear {v}");
|
||||
atomic_wait::wait(&SHARED.external_interupts, v);
|
||||
v = (&SHARED.external_interupts).load(Acquire);
|
||||
@@ -87,33 +89,40 @@ impl<'a> ApplicationHandler for App<'a> {
|
||||
if enabled {
|
||||
wait_int();
|
||||
}
|
||||
#[cfg(feature = "debug")]
|
||||
print!("Keyboard event: ");
|
||||
#[cfg(feature = "rich_keyboard")]
|
||||
{
|
||||
let txt = key_event
|
||||
let kb0 = key_event
|
||||
.logical_key
|
||||
.to_text()
|
||||
.unwrap_or("")
|
||||
.as_bytes()
|
||||
.into_iter()
|
||||
.fold(0, |a, e| a << 8 | (*e as u32));
|
||||
SHARED.keyboard[0].store(txt, Relaxed);
|
||||
let txt = key_event
|
||||
SHARED.keyboard[0].store(kb0, Relaxed);
|
||||
let kb1 = key_event
|
||||
.key_without_modifiers()
|
||||
.to_text()
|
||||
.unwrap_or("")
|
||||
.as_bytes()
|
||||
.into_iter()
|
||||
.fold(0, |a, e| a << 8 | (*e as u32));
|
||||
SHARED.keyboard[1].store(txt, Relaxed);
|
||||
SHARED.keyboard[2].store(
|
||||
key_event.state.is_pressed() as u32 | ((key_event.repeat as u32) << 1),
|
||||
Relaxed,
|
||||
);
|
||||
SHARED.keyboard[1].store(kb1, Relaxed);
|
||||
let kb2 =
|
||||
key_event.state.is_pressed() as u32 | ((key_event.repeat as u32) << 1);
|
||||
SHARED.keyboard[2].store(kb2, Relaxed);
|
||||
#[cfg(feature = "debug")]
|
||||
print!("{kb0} {kb1} {kb2}")
|
||||
}
|
||||
SHARED.keyboard[3]
|
||||
.store(key_event.physical_key.to_scancode().unwrap_or(0), Relaxed);
|
||||
let kb3 = key_event.physical_key.to_scancode().unwrap_or(0);
|
||||
#[cfg(feature = "debug")]
|
||||
println!(" {kb3}");
|
||||
SHARED.keyboard[3].store(kb3, Relaxed);
|
||||
if enabled {
|
||||
(&SHARED.external_interupts).store(MMIOInterupt::Keyboard.into(), Release);
|
||||
#[cfg(feature = "debug")]
|
||||
println!("wake due to keyboard event");
|
||||
atomic_wait::wake_all(&SHARED.external_interupts);
|
||||
}
|
||||
}
|
||||
@@ -141,7 +150,8 @@ impl<'a> ApplicationHandler for App<'a> {
|
||||
}
|
||||
if enabled {
|
||||
(&SHARED.external_interupts).store(MMIOInterupt::MouseMove.into(), Release);
|
||||
println!("wake mouse move");
|
||||
#[cfg(feature = "debug")]
|
||||
println!("wake due mouse move");
|
||||
atomic_wait::wake_all(&SHARED.external_interupts);
|
||||
}
|
||||
}
|
||||
@@ -174,6 +184,7 @@ impl<'a> ApplicationHandler for App<'a> {
|
||||
};
|
||||
if enabled {
|
||||
(&SHARED.external_interupts).store(MMIOInterupt::MouseClick.into(), Release);
|
||||
#[cfg(feature = "debug")]
|
||||
println!("wake mouse click");
|
||||
atomic_wait::wake_all(&SHARED.external_interupts);
|
||||
}
|
||||
@@ -286,12 +297,120 @@ fn main() -> Result<(), Error> {
|
||||
let program = args()
|
||||
.nth(1)
|
||||
.expect("you must supply the exec name as the first argument");
|
||||
|
||||
scope(|sc| {
|
||||
sc.spawn(|| {
|
||||
let mut simulation = Computer::new(program);
|
||||
#[cfg(not(feature = "debug"))]
|
||||
loop {
|
||||
simulation.step();
|
||||
}
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
let mut input = stdin().lines();
|
||||
loop {
|
||||
{
|
||||
println!(
|
||||
"interrupts are {:?}, with mmio interupts flags {}",
|
||||
simulation.interupts,
|
||||
SHARED.external_enabled_interupts.load(Relaxed)
|
||||
);
|
||||
for i in 0..8 {
|
||||
println!(
|
||||
"r{i} 0x{:08x} r{} 0x{:08x}",
|
||||
simulation.regs[i],
|
||||
i + 1,
|
||||
simulation.regs[i + 1]
|
||||
);
|
||||
}
|
||||
println!("SP: {:08x} PC: {:08x}", simulation.sp, simulation.pc);
|
||||
println!("RAM near SP");
|
||||
let min_pc = (simulation.pc).min(0x0100_0000 / 4 - 8);
|
||||
let min_sp = (simulation.sp).min(0x0100_0000 / 4 - 8);
|
||||
for i in 0..8 {
|
||||
println!(
|
||||
"{:8x}: 0x{:08x}",
|
||||
(min_sp + i) * 4,
|
||||
simulation.ram[min_sp + i],
|
||||
);
|
||||
}
|
||||
println!("Ram near PC");
|
||||
for i in 0..8 {
|
||||
let idx = min_pc + i;
|
||||
let istr = simulation.ram[idx];
|
||||
if let Some(s) = simulation.book.get(&(idx as u32 * 4)) {
|
||||
println!("{s}:")
|
||||
};
|
||||
println!(
|
||||
"{:8x}: 0x{:08x} {}",
|
||||
idx * 4,
|
||||
istr,
|
||||
cpu::instr_to_text(istr, idx as u32 * 4, &simulation.book)
|
||||
)
|
||||
}
|
||||
}
|
||||
while {
|
||||
let next = input.next().unwrap().unwrap();
|
||||
let next: Vec<_> = next.split_ascii_whitespace().collect();
|
||||
if next.len() > 0 {
|
||||
match next[0] {
|
||||
"s" | "step" => {
|
||||
let n: usize = {
|
||||
if next.len() >= 2 {
|
||||
parse_int::parse(next[1]).unwrap_or(1)
|
||||
} else {
|
||||
1
|
||||
}
|
||||
};
|
||||
for _ in 0..n {
|
||||
if simulation.error {
|
||||
println!("cannot step, cpu killed");
|
||||
break;
|
||||
}
|
||||
simulation.step();
|
||||
}
|
||||
false
|
||||
}
|
||||
"r" | "run" => {
|
||||
while !simulation.error {
|
||||
simulation.step();
|
||||
}
|
||||
false
|
||||
}
|
||||
"p" | "print" => {
|
||||
if next.len() >= 2 {
|
||||
match parse_int::parse::<u32>(next[1]) {
|
||||
Ok(i) => {
|
||||
let v = simulation.ram[i as usize/4];
|
||||
println!(
|
||||
"0x{:8x} -- {}",
|
||||
v,
|
||||
cpu::instr_to_text(v, i, &simulation.book)
|
||||
);
|
||||
false
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{e}");
|
||||
false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
"c" | "context" => false,
|
||||
_ => {
|
||||
println!("{HELP_MSG}");
|
||||
true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("{HELP_MSG}");
|
||||
true
|
||||
}
|
||||
} {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
#[allow(deprecated)]
|
||||
@@ -305,3 +424,12 @@ fn main() -> Result<(), Error> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
const HELP_MSG: &str = "
|
||||
step n - step trough n instructions (alias s)
|
||||
run - run program until exit / error (alias r)
|
||||
context - print context (alias c)
|
||||
print n - print ram content at address n and next 8 (alias p)
|
||||
- repeat last step (yes, do no enter anything and press Enter)
|
||||
";
|
||||
|
||||
Reference in New Issue
Block a user