#[macro_use]
pub mod ap;
pub(crate) mod assembly;
pub(crate) mod communication_interface;
pub mod component;
pub mod core;
pub mod dp;
pub mod memory;
pub mod sequences;
pub mod swo;
pub(crate) mod traits;
pub use self::core::{Dump, armv6m, armv7a, armv7m, armv8a, armv8m};
use self::{
ap::AccessPortError,
dp::DebugPortError,
memory::romtable::RomTableError,
sequences::ArmDebugSequenceError,
{armv7a::Armv7aError, armv8a::Armv8aError},
};
use crate::{
core::memory_mapped_registers::RegisterAddressOutOfBounds,
memory::{InvalidDataLengthError, MemoryNotAlignedError},
probe::DebugProbeError,
};
pub use communication_interface::{
ArmChipInfo, ArmCommunicationInterface, ArmDebugInterface, DapError, DapProbe,
};
pub use swo::{SwoAccess, SwoConfig, SwoMode, SwoReader};
pub use traits::*;
#[derive(Debug, thiserror::Error)]
#[error("Failed to parse register {name} from {value:#010x}")]
pub struct RegisterParseError {
name: &'static str,
value: u32,
}
impl RegisterParseError {
pub fn new(name: &'static str, value: u32) -> Self {
RegisterParseError { name, value }
}
}
#[derive(Debug, thiserror::Error, docsplay::Display)]
pub enum ArmError {
ArchitectureRequired(&'static [&'static str]),
Timeout,
AddressOutOf32BitAddressSpace,
NoArmTarget,
AccessPort {
address: FullyQualifiedApAddress,
source: AccessPortError,
},
DebugPort(#[from] DebugPortError),
CoreNotHalted,
ReAttachRequired,
#[ignore_extra_doc_attributes]
MissingPermissions(String),
Dap(#[from] DapError),
Probe(#[from] DebugProbeError),
MemoryNotAligned(#[from] MemoryNotAlignedError),
OutOfBounds,
UnsupportedTransferWidth(usize),
ApDoesNotExist(FullyQualifiedApAddress),
WrongApVersion,
WrongApType,
UnsupportedBreakpointAddress(u32),
Armv8a(#[from] Armv8aError),
Armv7a(#[from] Armv7aError),
DebugSequence(#[from] ArmDebugSequenceError),
TracingUnconfigured,
RegisterParse(#[from] RegisterParseError),
RomTable(#[source] RomTableError),
ChipEraseFailed,
ExtensionRequired(&'static [&'static str]),
RegisterAddressOutOfBounds(#[from] RegisterAddressOutOfBounds),
NotImplemented(&'static str),
InvalidDataLength(#[from] InvalidDataLengthError),
Other(String),
}
impl ArmError {
pub fn from_access_port(err: AccessPortError, ap_address: &FullyQualifiedApAddress) -> Self {
ArmError::AccessPort {
address: ap_address.clone(),
source: err,
}
}
pub fn alignment_error(address: u64, alignment: usize) -> Self {
ArmError::MemoryNotAligned(MemoryNotAlignedError { address, alignment })
}
}
impl From<RomTableError> for ArmError {
fn from(value: RomTableError) -> Self {
match value {
RomTableError::Memory(err) => *err,
other => ArmError::RomTable(other),
}
}
}
pub fn valid_32bit_arm_address(address: u64) -> Result<u32, ArmError> {
address
.try_into()
.map_err(|_| ArmError::AddressOutOf32BitAddressSpace)
}