mirror of
https://github.com/transistorfet/moa.git
synced 2024-12-23 03:29:24 +00:00
Separated debugging code into its own file
This commit is contained in:
parent
38bcf0af3f
commit
4b577ad403
61
src/cpus/m68k/debugger.rs
Normal file
61
src/cpus/m68k/debugger.rs
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::memory::{Address, AddressSpace};
|
||||
|
||||
use super::execute::{MC68010};
|
||||
use super::decode::{Instruction, Target, Size, Direction, Condition, ControlRegister, RegisterType};
|
||||
|
||||
pub struct M68kDebugger {
|
||||
pub breakpoints: Vec<u32>,
|
||||
pub use_tracing: bool,
|
||||
pub use_debugger: bool,
|
||||
}
|
||||
|
||||
|
||||
impl M68kDebugger {
|
||||
pub fn new() -> M68kDebugger {
|
||||
M68kDebugger {
|
||||
breakpoints: vec!(),
|
||||
use_tracing: false,
|
||||
use_debugger: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MC68010 {
|
||||
pub fn enable_tracing(&mut self) {
|
||||
self.debugger.use_tracing = true;
|
||||
}
|
||||
|
||||
pub fn add_breakpoint(&mut self, addr: Address) {
|
||||
self.debugger.breakpoints.push(addr as u32);
|
||||
}
|
||||
|
||||
pub fn check_breakpoints(&mut self) {
|
||||
for breakpoint in &self.debugger.breakpoints {
|
||||
if *breakpoint == self.state.pc {
|
||||
self.debugger.use_tracing = true;
|
||||
self.debugger.use_debugger = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_debugger(&mut self, space: &mut AddressSpace) {
|
||||
self.dump_state(space);
|
||||
let mut buffer = String::new();
|
||||
|
||||
loop {
|
||||
std::io::stdin().read_line(&mut buffer).unwrap();
|
||||
match buffer.as_ref() {
|
||||
"dump\n" => space.dump_memory(self.state.msp as Address, (0x200000 - self.state.msp) as Address),
|
||||
"continue\n" => {
|
||||
self.debugger.use_debugger = false;
|
||||
return;
|
||||
},
|
||||
_ => { return; },
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
use crate::error::Error;
|
||||
use crate::memory::{Address, AddressSpace};
|
||||
|
||||
use super::debugger::M68kDebugger;
|
||||
use super::decode::{
|
||||
M68kDecoder,
|
||||
Instruction,
|
||||
@ -15,6 +16,7 @@ use super::decode::{
|
||||
sign_extend_to_long
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
pub trait Processor {
|
||||
fn reset();
|
||||
@ -76,35 +78,23 @@ impl MC68010State {
|
||||
|
||||
pub struct MC68010 {
|
||||
pub state: MC68010State,
|
||||
|
||||
pub decoder: M68kDecoder,
|
||||
|
||||
pub breakpoints: Vec<u32>,
|
||||
pub use_tracing: bool,
|
||||
pub use_debugger: bool,
|
||||
pub debugger: M68kDebugger,
|
||||
}
|
||||
|
||||
impl MC68010 {
|
||||
pub fn new() -> MC68010 {
|
||||
MC68010 {
|
||||
state: MC68010State::new(),
|
||||
|
||||
decoder: M68kDecoder::new(0),
|
||||
|
||||
breakpoints: vec![],
|
||||
use_tracing: false,
|
||||
use_debugger: false,
|
||||
debugger: M68kDebugger::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.state = MC68010State::new();
|
||||
|
||||
self.decoder = M68kDecoder::new(0);
|
||||
|
||||
self.breakpoints = vec![];
|
||||
self.use_tracing = false;
|
||||
self.use_debugger = false;
|
||||
self.debugger = M68kDebugger::new();
|
||||
}
|
||||
|
||||
pub fn is_running(&self) -> bool {
|
||||
@ -138,10 +128,6 @@ impl MC68010 {
|
||||
println!("");
|
||||
}
|
||||
|
||||
pub fn add_breakpoint(&mut self, addr: Address) {
|
||||
self.breakpoints.push(addr as u32);
|
||||
}
|
||||
|
||||
pub fn step(&mut self, space: &mut AddressSpace) -> Result<(), Error> {
|
||||
match self.state.status {
|
||||
Status::Init => self.init(space),
|
||||
@ -158,15 +144,9 @@ impl MC68010 {
|
||||
self.decoder = M68kDecoder::decode_at(space, self.state.pc)?;
|
||||
self.state.pc = self.decoder.end;
|
||||
|
||||
for breakpoint in &self.breakpoints {
|
||||
if *breakpoint == self.decoder.start {
|
||||
self.use_tracing = true;
|
||||
self.use_debugger = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.check_breakpoints();
|
||||
|
||||
if self.use_tracing {
|
||||
if self.debugger.use_tracing {
|
||||
// Print instruction bytes for debugging
|
||||
let ins_data: Result<String, Error> =
|
||||
(0..((self.state.pc - self.decoder.start) / 2)).map(|offset|
|
||||
@ -175,29 +155,12 @@ impl MC68010 {
|
||||
debug!("{:#010x}: {}\n\t{:?}\n", self.decoder.start, ins_data?, self.decoder.instruction);
|
||||
}
|
||||
|
||||
if self.use_debugger {
|
||||
if self.debugger.use_debugger {
|
||||
self.run_debugger(space);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_debugger(&mut self, space: &mut AddressSpace) {
|
||||
self.dump_state(space);
|
||||
let mut buffer = String::new();
|
||||
|
||||
loop {
|
||||
std::io::stdin().read_line(&mut buffer).unwrap();
|
||||
match buffer.as_ref() {
|
||||
"dump\n" => space.dump_memory(self.state.msp as Address, (0x200000 - self.state.msp) as Address),
|
||||
"continue\n" => {
|
||||
self.use_debugger = false;
|
||||
return;
|
||||
},
|
||||
_ => { return; },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn execute_current(&mut self, space: &mut AddressSpace) -> Result<(), Error> {
|
||||
match self.decoder.instruction {
|
||||
Instruction::ADD(src, dest, size) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
mod decode;
|
||||
mod execute;
|
||||
//mod debugger;
|
||||
mod debugger;
|
||||
mod tests;
|
||||
|
||||
pub use self::execute::MC68010;
|
||||
|
@ -30,7 +30,7 @@ fn main() {
|
||||
//cpu.add_breakpoint(0x0838);
|
||||
//cpu.add_breakpoint(0x0ea0);
|
||||
|
||||
cpu.use_tracing = true;
|
||||
cpu.enable_tracing();
|
||||
while cpu.is_running() {
|
||||
match cpu.step(&mut space) {
|
||||
Ok(()) => { },
|
||||
|
Loading…
Reference in New Issue
Block a user