Add info and reset commands

This commit is contained in:
Michel Heily 2019-06-25 05:16:14 +03:00
parent fc28d89097
commit 9921f1c974
2 changed files with 37 additions and 2 deletions

View file

@ -1,3 +1,5 @@
use std::convert::TryFrom;
use crate::num_traits::FromPrimitive;
use super::arm::*;
@ -5,9 +7,16 @@ use super::sysbus::SysBus;
#[derive(Debug, PartialEq)]
pub enum CpuError {
ArmDecodeError(ArmDecodeError),
IllegalInstruction,
}
impl From<ArmDecodeError> for CpuError {
fn from(e: ArmDecodeError) -> CpuError {
CpuError::ArmDecodeError(e)
}
}
pub type CpuResult<T> = Result<T, CpuError>;
#[derive(Debug, PartialEq)]
@ -92,7 +101,12 @@ impl Core {
}
fn step_arm(&mut self, sysbus: &mut SysBus) -> CpuResult<()> {
Err(CpuError::IllegalInstruction)
// fetch
let insn = sysbus.read_32(self.pc);
// decode
let insn = ArmInstruction::try_from((insn, self.pc))?;
Ok(())
}
pub fn step(&mut self, sysbus: &mut SysBus) -> CpuResult<()> {

View file

@ -26,9 +26,16 @@ pub struct Debugger {
#[derive(Debug, PartialEq)]
pub enum DebuggerError {
ParsingError(String),
CpuError(cpu::CpuError),
InvalidCommand(String)
}
impl From<cpu::CpuError> for DebuggerError {
fn from(e: cpu::CpuError) -> DebuggerError {
DebuggerError::CpuError(e)
}
}
impl From<nom::Err<(&str, nom::error::ErrorKind)>> for DebuggerError {
fn from(e: nom::Err<(&str, nom::error::ErrorKind)>) -> DebuggerError {
DebuggerError::ParsingError("parsing of command failed".to_string())
@ -39,11 +46,13 @@ type DebuggerResult<T> = Result<T, DebuggerError>;
#[derive(Debug, PartialEq)]
enum DebuggerCommand {
Info,
SingleStep,
Continue,
Disass { addr: u32, num_opcodes: usize },
AddBreakpoint(u32),
ListBreakpoints,
Reset,
Quit,
Nop,
}
@ -79,6 +88,7 @@ fn parse_debugger_command(input: &str) -> DebuggerResult<DebuggerCommand> {
// TODO this code is shit!
let (input, command_name) = parse_word(input)?;
match command_name {
"i" | "info" => Ok(Info),
"s" | "step" => Ok(SingleStep),
"c" | "continue" => Ok(Continue),
"d" | "disass" => {
@ -96,6 +106,7 @@ fn parse_debugger_command(input: &str) -> DebuggerResult<DebuggerCommand> {
}
"bl" => Ok(ListBreakpoints),
"q" | "quit" => Ok(Quit),
"r" | "reset" => Ok(Reset),
"" => Ok(Nop),
_ => Err(DebuggerError::InvalidCommand(command_name.to_string()))
}
@ -119,8 +130,13 @@ impl Debugger {
let command = parse_debugger_command(&line);
match command {
Ok(Nop) => (),
Ok(Info) => {
println!("cpu info: {:#?}", self.cpu)
}
Ok(SingleStep) => {
self.cpu.step(&mut self.sysbus).unwrap()
println!("single step:");
self.cpu.step(&mut self.sysbus)?;
()
},
Ok(Quit) => {
print!("Quitting!");
@ -141,6 +157,11 @@ impl Debugger {
println!("[{}] 0x{:08x}", i, b)
}
}
Ok(Reset) => {
println!("resetting cpu...");
self.cpu.reset();
println!("cpu is restarted!")
}
Err(DebuggerError::InvalidCommand(command)) => {
println!("invalid command: {}", command)
}