probe_rs/architecture/arm/
mod.rs1#[macro_use]
4pub mod ap;
5pub(crate) mod assembly;
6pub(crate) mod communication_interface;
7pub mod component;
8pub mod core;
10pub mod dp;
11pub mod memory;
12pub mod sequences;
13pub mod swo;
14pub(crate) mod traits;
15
16pub use self::core::{Dump, armv6m, armv7a, armv7m, armv8a, armv8m};
17use self::{
18 ap::AccessPortError,
19 dp::DebugPortError,
20 memory::romtable::RomTableError,
21 sequences::ArmDebugSequenceError,
22 {armv7a::Armv7aError, armv8a::Armv8aError},
23};
24use crate::{
25 core::memory_mapped_registers::RegisterAddressOutOfBounds,
26 memory::{InvalidDataLengthError, MemoryNotAlignedError},
27 probe::DebugProbeError,
28};
29pub use communication_interface::{
30 ArmChipInfo, ArmCommunicationInterface, ArmDebugInterface, DapError, DapProbe,
31};
32pub use swo::{SwoAccess, SwoConfig, SwoMode, SwoReader};
33pub use traits::*;
34
35#[derive(Debug, thiserror::Error)]
37#[error("Failed to parse register {name} from {value:#010x}")]
38pub struct RegisterParseError {
39 name: &'static str,
40 value: u32,
41}
42
43impl RegisterParseError {
44 pub fn new(name: &'static str, value: u32) -> Self {
46 RegisterParseError { name, value }
47 }
48}
49
50#[derive(Debug, thiserror::Error, docsplay::Display)]
52pub enum ArmError {
53 ArchitectureRequired(&'static [&'static str]),
55
56 Timeout,
58
59 AddressOutOf32BitAddressSpace,
61
62 NoArmTarget,
64
65 AccessPort {
67 address: FullyQualifiedApAddress,
69 source: AccessPortError,
71 },
72
73 DebugPort(#[from] DebugPortError),
75
76 CoreNotHalted,
78
79 ReAttachRequired,
82
83 #[ignore_extra_doc_attributes]
89 MissingPermissions(String),
90
91 Dap(#[from] DapError),
93
94 Probe(#[from] DebugProbeError),
96
97 MemoryNotAligned(#[from] MemoryNotAlignedError),
100
101 OutOfBounds,
103
104 UnsupportedTransferWidth(usize),
106
107 ApDoesNotExist(FullyQualifiedApAddress),
109
110 WrongApVersion,
112
113 WrongApType,
115
116 UnsupportedBreakpointAddress(u32),
119
120 Armv8a(#[from] Armv8aError),
122
123 Armv7a(#[from] Armv7aError),
125
126 DebugSequence(#[from] ArmDebugSequenceError),
128
129 TracingUnconfigured,
131
132 RegisterParse(#[from] RegisterParseError),
134
135 RomTable(#[source] RomTableError),
137
138 ChipEraseFailed,
140
141 ExtensionRequired(&'static [&'static str]),
143
144 RegisterAddressOutOfBounds(#[from] RegisterAddressOutOfBounds),
146
147 NotImplemented(&'static str),
149
150 InvalidDataLength(#[from] InvalidDataLengthError),
152
153 Other(String),
155}
156
157impl ArmError {
158 pub fn from_access_port(err: AccessPortError, ap_address: &FullyQualifiedApAddress) -> Self {
160 ArmError::AccessPort {
161 address: ap_address.clone(),
162 source: err,
163 }
164 }
165
166 pub fn alignment_error(address: u64, alignment: usize) -> Self {
168 ArmError::MemoryNotAligned(MemoryNotAlignedError { address, alignment })
169 }
170}
171
172impl From<RomTableError> for ArmError {
173 fn from(value: RomTableError) -> Self {
174 match value {
175 RomTableError::Memory(err) => *err,
176 other => ArmError::RomTable(other),
177 }
178 }
179}
180
181pub fn valid_32bit_arm_address(address: u64) -> Result<u32, ArmError> {
184 address
185 .try_into()
186 .map_err(|_| ArmError::AddressOutOf32BitAddressSpace)
187}