pub mod decode;
pub mod isa_fpu;
pub mod isa_int;
pub mod isa_mmx;
pub mod mmu;
pub mod regs;
pub use isa_int::Cpu;
pub use mmu::{Mmu, Perm};
pub use regs::{Flags, Regs};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Trap {
MemoryFault { addr: u32 },
ReadProtectFault { addr: u32 },
WriteProtectFault { addr: u32 },
ExecuteProtectFault { addr: u32 },
UndefinedOpcode { eip: u32, opcode: u32 },
PrivilegedOpcode { eip: u32, mnemonic: &'static str },
DivideByZero { eip: u32 },
UnresolvedImport { dll: String, name: String },
InstructionLimitExceeded { eip: u32, count: u64 },
UnimplementedMmx {
eip: u32,
opcode: u32,
mnemonic_hint: &'static str,
},
}
impl core::fmt::Display for Trap {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Trap::MemoryFault { addr } => {
write!(f, "memory fault at {addr:#010x} (page unmapped)")
}
Trap::ReadProtectFault { addr } => {
write!(f, "read-protect fault at {addr:#010x} (no R bit)")
}
Trap::WriteProtectFault { addr } => {
write!(f, "write-protect fault at {addr:#010x} (no W bit)")
}
Trap::ExecuteProtectFault { addr } => {
write!(f, "execute-protect fault at {addr:#010x} (no X bit)")
}
Trap::UndefinedOpcode { eip, opcode } => {
write!(f, "undefined opcode {opcode:#x} at eip={eip:#010x}")
}
Trap::PrivilegedOpcode { eip, mnemonic } => {
write!(f, "privileged opcode {mnemonic:?} at eip={eip:#010x}")
}
Trap::DivideByZero { eip } => write!(f, "divide-by-zero at eip={eip:#010x}"),
Trap::UnresolvedImport { dll, name } => {
write!(f, "unresolved import {dll}!{name}")
}
Trap::InstructionLimitExceeded { eip, count } => write!(
f,
"instruction limit exceeded at eip={eip:#010x} after {count} instructions"
),
Trap::UnimplementedMmx {
eip,
opcode,
mnemonic_hint,
} => write!(
f,
"unimplemented MMX opcode {opcode:#06x} ({mnemonic_hint}) at eip={eip:#010x}"
),
}
}
}