Allow dissasembly errors to include abnormal traps

This commit is contained in:
pjht 2023-12-07 13:56:41 -06:00
parent 849f3c7dd2
commit 030ca22812
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
2 changed files with 21 additions and 8 deletions

View File

@ -144,8 +144,14 @@ impl From<DetailedBusError> for InsExecError {
} }
} }
impl Display for InsExecError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
InsExecError::BusError(err) => f.write_fmt(format_args!("{}", err)),
InsExecError::AbnormalTrap => f.write_str("Abnormal trap"),
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct M68K { pub struct M68K {
@ -243,11 +249,14 @@ impl M68K {
pub fn disassemble( pub fn disassemble(
&mut self, &mut self,
loc: u32, loc: u32,
) -> Result<(Instruction, u32), DisassemblyError<DetailedBusError>> { ) -> Result<(Instruction, u32), DisassemblyError<InsExecError>> {
disas::disasm(loc, &mut |addr| { disas::disasm(loc, &mut |addr| {
self.read_word(addr).map_err(|err| DetailedBusError { self.read_word(addr).map_err(|err| match err {
InsExecError::AbnormalTrap => InsExecError::AbnormalTrap,
InsExecError::BusError(err) => InsExecError::BusError(DetailedBusError {
cause: BusErrorCause::ReadingInstruction, cause: BusErrorCause::ReadingInstruction,
..err.try_into_bus_error().unwrap() ..err
}),
}) })
}) })
} }
@ -316,7 +325,10 @@ impl M68K {
} }
let (ins, new_pc) = match self.disassemble(self.pc) { let (ins, new_pc) = match self.disassemble(self.pc) {
Ok(ins) => ins, Ok(ins) => ins,
Err(DisassemblyError::InvalidInstruction) => panic!("Invalid instruction"), Err(DisassemblyError::InvalidInstruction) => {
self.trap(4)?;
return self.step_ret_berr();
}
Err(DisassemblyError::ReadError(e)) => return Err(e.into()), Err(DisassemblyError::ReadError(e)) => return Err(e.into()),
}; };
self.pc = new_pc; self.pc = new_pc;

View File

@ -25,6 +25,7 @@ use clap::Parser;
use disas::DisassemblyError; use disas::DisassemblyError;
use indexmap::IndexSet; use indexmap::IndexSet;
use itertools::Itertools; use itertools::Itertools;
use m68k::InsExecError;
use parse_int::parse; use parse_int::parse;
use reedline_repl_rs::{ use reedline_repl_rs::{
clap::{builder::BoolishValueParser, Arg, ArgAction, Command}, clap::{builder::BoolishValueParser, Arg, ArgAction, Command},
@ -527,7 +528,7 @@ fn disas_fmt(
cpu: &mut M68K, cpu: &mut M68K,
addr: u32, addr: u32,
symbol_tables: &SymbolTables, symbol_tables: &SymbolTables,
) -> (String, Result<u32, DisassemblyError<DetailedBusError>>) { ) -> (String, Result<u32, DisassemblyError<InsExecError>>) {
let addr_fmt = if let Some((table, symbol, offset)) = symbol_tables.address_to_symbol(addr) { let addr_fmt = if let Some((table, symbol, offset)) = symbol_tables.address_to_symbol(addr) {
format!("{table}:{symbol} + {offset} (0x{addr:x})") format!("{table}:{symbol} + {offset} (0x{addr:x})")
} else { } else {