probe_rs/core.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
use crate::{
architecture::{
arm::sequences::ArmDebugSequence, riscv::sequences::RiscvDebugSequence,
xtensa::sequences::XtensaDebugSequence,
},
config::DebugSequence,
error::Error,
memory::CoreMemoryInterface,
CoreType, InstructionSet, MemoryInterface, Target,
};
pub use probe_rs_target::{Architecture, CoreAccessOptions};
use probe_rs_target::{
ArmCoreAccessOptions, MemoryRegion, RiscvCoreAccessOptions, XtensaCoreAccessOptions,
};
use std::{sync::Arc, time::Duration};
pub mod core_state;
pub mod core_status;
#[cfg(feature = "debug")]
pub(crate) mod dump;
pub mod memory_mapped_registers;
pub mod registers;
pub use core_state::*;
pub use core_status::*;
pub use memory_mapped_registers::MemoryMappedRegister;
pub use registers::*;
/// An struct for storing the current state of a core.
#[derive(Debug, Clone)]
pub struct CoreInformation {
/// The current Program Counter.
pub pc: u64,
}
/// A generic interface to control a MCU core.
pub trait CoreInterface: MemoryInterface + CoreMemoryInterfaceShim {
/// Wait until the core is halted. If the core does not halt on its own,
/// a [`DebugProbeError::Timeout`](crate::probe::DebugProbeError::Timeout) error will be returned.
fn wait_for_core_halted(&mut self, timeout: Duration) -> Result<(), Error>;
/// Check if the core is halted. If the core does not halt on its own,
/// a [`DebugProbeError::Timeout`](crate::probe::DebugProbeError::Timeout) error will be returned.
fn core_halted(&mut self) -> Result<bool, Error>;
/// Returns the current status of the core.
fn status(&mut self) -> Result<CoreStatus, Error>;
/// Try to halt the core. This function ensures the core is actually halted, and
/// returns a [`DebugProbeError::Timeout`](crate::probe::DebugProbeError::Timeout) otherwise.
fn halt(&mut self, timeout: Duration) -> Result<CoreInformation, Error>;
/// Continue to execute instructions.
fn run(&mut self) -> Result<(), Error>;
/// Reset the core, and then continue to execute instructions. If the core
/// should be halted after reset, use the [`reset_and_halt`] function.
///
/// [`reset_and_halt`]: Core::reset_and_halt
fn reset(&mut self) -> Result<(), Error>;
/// Reset the core, and then immediately halt. To continue execution after
/// reset, use the [`reset`] function.
///
/// [`reset`]: Core::reset
fn reset_and_halt(&mut self, timeout: Duration) -> Result<CoreInformation, Error>;
/// Steps one instruction and then enters halted state again.
fn step(&mut self) -> Result<CoreInformation, Error>;
/// Read the value of a core register.
fn read_core_reg(
&mut self,
address: registers::RegisterId,
) -> Result<registers::RegisterValue, Error>;
/// Write the value of a core register.
fn write_core_reg(
&mut self,
address: registers::RegisterId,
value: registers::RegisterValue,
) -> Result<(), Error>;
/// Returns all the available breakpoint units of the core.
fn available_breakpoint_units(&mut self) -> Result<u32, Error>;
/// Read the hardware breakpoints from FpComp registers, and adds them to the Result Vector.
/// A value of None in any position of the Vector indicates that the position is unset/available.
/// We intentionally return all breakpoints, irrespective of whether they are enabled or not.
fn hw_breakpoints(&mut self) -> Result<Vec<Option<u64>>, Error>;
/// Enables breakpoints on this core. If a breakpoint is set, it will halt as soon as it is hit.
fn enable_breakpoints(&mut self, state: bool) -> Result<(), Error>;
/// Sets a breakpoint at `addr`. It does so by using unit `bp_unit_index`.
fn set_hw_breakpoint(&mut self, unit_index: usize, addr: u64) -> Result<(), Error>;
/// Clears the breakpoint configured in unit `unit_index`.
fn clear_hw_breakpoint(&mut self, unit_index: usize) -> Result<(), Error>;
/// Returns a list of all the registers of this core.
fn registers(&self) -> &'static registers::CoreRegisters;
/// Returns the program counter register.
fn program_counter(&self) -> &'static CoreRegister;
/// Returns the stack pointer register.
fn frame_pointer(&self) -> &'static CoreRegister;
/// Returns the frame pointer register.
fn stack_pointer(&self) -> &'static CoreRegister;
/// Returns the return address register, a.k.a. link register.
fn return_address(&self) -> &'static CoreRegister;
/// Returns `true` if hardware breakpoints are enabled, `false` otherwise.
fn hw_breakpoints_enabled(&self) -> bool;
/// Configure the target to ensure software breakpoints will enter Debug Mode.
fn debug_on_sw_breakpoint(&mut self, _enabled: bool) -> Result<(), Error> {
// This default will have override methods for architectures that require special behavior, e.g. RISC-V.
Ok(())
}
/// Get the `Architecture` of the Core.
fn architecture(&self) -> Architecture;
/// Get the `CoreType` of the Core
fn core_type(&self) -> CoreType;
/// Determine the instruction set the core is operating in
/// This must be queried while halted as this is a runtime
/// decision for some core types
fn instruction_set(&mut self) -> Result<InstructionSet, Error>;
/// Determine if an FPU is present.
/// This must be queried while halted as this is a runtime
/// decision for some core types.
fn fpu_support(&mut self) -> Result<bool, Error>;
/// Determine the number of floating point registers.
/// This must be queried while halted as this is a runtime
/// decision for some core types.
fn floating_point_register_count(&mut self) -> Result<usize, Error>;
/// Set the reset catch setting.
///
/// This configures the core to halt after a reset.
///
/// use `reset_catch_clear` to clear the setting again.
fn reset_catch_set(&mut self) -> Result<(), Error>;
/// Clear the reset catch setting.
///
/// This will reset the changes done by `reset_catch_set`.
fn reset_catch_clear(&mut self) -> Result<(), Error>;
/// Called when we stop debugging a core.
fn debug_core_stop(&mut self) -> Result<(), Error>;
/// Called during session stop to do any pending cleanup
fn on_session_stop(&mut self) -> Result<(), Error> {
Ok(())
}
/// Enables vector catching for the given `condition`
fn enable_vector_catch(&mut self, _condition: VectorCatchCondition) -> Result<(), Error> {
Err(Error::NotImplemented("vector catch"))
}
/// Disables vector catching for the given `condition`
fn disable_vector_catch(&mut self, _condition: VectorCatchCondition) -> Result<(), Error> {
Err(Error::NotImplemented("vector catch"))
}
/// Check if the integer size is 64-bit
fn is_64_bit(&self) -> bool {
false
}
}
/// Implementation detail to allow trait upcasting-like behaviour.
//
// TODO: replace with trait upcasting once stable
pub trait CoreMemoryInterfaceShim: MemoryInterface {
/// Returns a reference to the underlying `MemoryInterface`.
// TODO: replace with trait upcasting once stable
fn as_memory_interface(&self) -> &dyn MemoryInterface;
/// Returns a mutable reference to the underlying `MemoryInterface`.
// TODO: replace with trait upcasting once stable
fn as_memory_interface_mut(&mut self) -> &mut dyn MemoryInterface;
}
impl<T> CoreMemoryInterfaceShim for T
where
T: CoreInterface,
{
fn as_memory_interface(&self) -> &dyn MemoryInterface {
self
}
fn as_memory_interface_mut(&mut self) -> &mut dyn MemoryInterface {
self
}
}
/// Generic core handle representing a physical core on an MCU.
///
/// This should be considered as a temporary view of the core which locks the debug probe driver to as single consumer by borrowing it.
///
/// As soon as you did your atomic task (e.g. halt the core, read the core state and all other debug relevant info) you should drop this object,
/// to allow potential other shareholders of the session struct to grab a core handle too.
pub struct Core<'probe> {
id: usize,
name: &'probe str,
target: &'probe Target,
inner: Box<dyn CoreInterface + 'probe>,
}
impl CoreMemoryInterface for Core<'_> {
type ErrorType = Error;
fn memory(&self) -> &dyn MemoryInterface<Self::ErrorType> {
self.inner.as_memory_interface()
}
fn memory_mut(&mut self) -> &mut dyn MemoryInterface<Self::ErrorType> {
self.inner.as_memory_interface_mut()
}
}
impl<'probe> Core<'probe> {
/// Borrow the boxed CoreInterface mutable.
pub fn inner_mut(&mut self) -> &mut Box<dyn CoreInterface + 'probe> {
&mut self.inner
}
/// Create a new [`Core`].
pub(crate) fn new(
id: usize,
name: &'probe str,
target: &'probe Target,
core: impl CoreInterface + 'probe,
) -> Core<'probe> {
Self {
id,
name,
target,
inner: Box::new(core),
}
}
/// Returns the memory regions associated with this core.
pub fn memory_regions(&self) -> impl Iterator<Item = &MemoryRegion> {
self.target
.memory_map
.iter()
.filter(|r| r.cores().iter().any(|m| m == self.name))
}
/// Returns the target descriptor of the current `Session`.
pub fn target(&self) -> &Target {
self.target
}
/// Creates a new [`CoreState`]
pub(crate) fn create_state(
id: usize,
options: CoreAccessOptions,
target: &Target,
core_type: CoreType,
) -> CombinedCoreState {
CombinedCoreState {
id,
core_state: CoreState::new(ResolvedCoreOptions::new(target, options)),
specific_state: SpecificCoreState::from_core_type(core_type),
}
}
/// Returns the ID of this core.
pub fn id(&self) -> usize {
self.id
}
/// Wait until the core is halted. If the core does not halt on its own,
/// a [`DebugProbeError::Timeout`](crate::probe::DebugProbeError::Timeout) error will be returned.
#[tracing::instrument(skip(self))]
pub fn wait_for_core_halted(&mut self, timeout: Duration) -> Result<(), Error> {
self.inner.wait_for_core_halted(timeout)
}
/// Check if the core is halted. If the core does not halt on its own,
/// a [`DebugProbeError::Timeout`](crate::probe::DebugProbeError::Timeout) error will be returned.
pub fn core_halted(&mut self) -> Result<bool, Error> {
self.inner.core_halted()
}
/// Try to halt the core. This function ensures the core is actually halted, and
/// returns a [`DebugProbeError::Timeout`](crate::probe::DebugProbeError::Timeout) otherwise.
#[tracing::instrument(skip(self))]
pub fn halt(&mut self, timeout: Duration) -> Result<CoreInformation, Error> {
self.inner.halt(timeout)
}
/// Continue to execute instructions.
#[tracing::instrument(skip(self))]
pub fn run(&mut self) -> Result<(), Error> {
self.inner.run()
}
/// Reset the core, and then continue to execute instructions. If the core
/// should be halted after reset, use the [`reset_and_halt`] function.
///
/// [`reset_and_halt`]: Core::reset_and_halt
#[tracing::instrument(skip(self))]
pub fn reset(&mut self) -> Result<(), Error> {
self.inner.reset()
}
/// Reset the core, and then immediately halt. To continue execution after
/// reset, use the [`reset`] function.
///
/// [`reset`]: Core::reset
#[tracing::instrument(skip(self))]
pub fn reset_and_halt(&mut self, timeout: Duration) -> Result<CoreInformation, Error> {
self.inner.reset_and_halt(timeout)
}
/// Steps one instruction and then enters halted state again.
#[tracing::instrument(skip(self))]
pub fn step(&mut self) -> Result<CoreInformation, Error> {
self.inner.step()
}
/// Returns the current status of the core.
#[tracing::instrument(level = "trace", skip(self))]
pub fn status(&mut self) -> Result<CoreStatus, Error> {
self.inner.status()
}
/// Read the value of a core register.
///
/// # Remarks
///
/// `T` can be an unsigned integer type, such as [u32] or [u64], or
/// it can be [RegisterValue] to allow the caller to support arbitrary
/// length registers.
///
/// To add support to convert to a custom type implement [`TryInto<CustomType>`]
/// for [RegisterValue].
///
/// # Errors
///
/// If `T` isn't large enough to hold the register value an error will be raised.
#[tracing::instrument(skip(self, address), fields(address))]
pub fn read_core_reg<T>(
&mut self,
address: impl Into<registers::RegisterId>,
) -> Result<T, Error>
where
registers::RegisterValue: TryInto<T>,
Result<T, <registers::RegisterValue as TryInto<T>>::Error>: RegisterValueResultExt<T>,
{
let address = address.into();
tracing::Span::current().record("address", format!("{address:?}"));
let value = self.inner.read_core_reg(address)?;
value.try_into().into_crate_error()
}
/// Write the value of a core register.
///
/// # Errors
///
/// If T is too large to write to the target register an error will be raised.
#[tracing::instrument(skip(self, address, value))]
pub fn write_core_reg<T>(
&mut self,
address: impl Into<registers::RegisterId>,
value: T,
) -> Result<(), Error>
where
T: Into<registers::RegisterValue>,
{
let address = address.into();
self.inner.write_core_reg(address, value.into())
}
/// Returns all the available breakpoint units of the core.
pub fn available_breakpoint_units(&mut self) -> Result<u32, Error> {
self.inner.available_breakpoint_units()
}
/// Enables breakpoints on this core. If a breakpoint is set, it will halt as soon as it is hit.
fn enable_breakpoints(&mut self, state: bool) -> Result<(), Error> {
self.inner.enable_breakpoints(state)
}
/// Configure the debug module to ensure software breakpoints will enter Debug Mode.
#[tracing::instrument(skip(self))]
pub fn debug_on_sw_breakpoint(&mut self, enabled: bool) -> Result<(), Error> {
self.inner.debug_on_sw_breakpoint(enabled)
}
/// Returns a list of all the registers of this core.
pub fn registers(&self) -> &'static registers::CoreRegisters {
self.inner.registers()
}
/// Returns the program counter register.
pub fn program_counter(&self) -> &'static CoreRegister {
self.inner.program_counter()
}
/// Returns the stack pointer register.
pub fn frame_pointer(&self) -> &'static CoreRegister {
self.inner.frame_pointer()
}
/// Returns the frame pointer register.
pub fn stack_pointer(&self) -> &'static CoreRegister {
self.inner.stack_pointer()
}
/// Returns the return address register, a.k.a. link register.
pub fn return_address(&self) -> &'static CoreRegister {
self.inner.return_address()
}
/// Find the index of the next available HW breakpoint comparator.
fn find_free_breakpoint_comparator_index(&mut self) -> Result<usize, Error> {
let mut next_available_hw_breakpoint = 0;
for breakpoint in self.inner.hw_breakpoints()? {
if breakpoint.is_none() {
return Ok(next_available_hw_breakpoint);
} else {
next_available_hw_breakpoint += 1;
}
}
Err(Error::Other(
"No available hardware breakpoints".to_string(),
))
}
/// Set a hardware breakpoint
///
/// This function will try to set a hardware breakpoint att `address`.
///
/// The amount of hardware breakpoints which are supported is chip specific,
/// and can be queried using the `get_available_breakpoint_units` function.
#[tracing::instrument(skip(self))]
pub fn set_hw_breakpoint(&mut self, address: u64) -> Result<(), Error> {
if !self.inner.hw_breakpoints_enabled() {
self.enable_breakpoints(true)?;
}
// If there is a breakpoint set already, return its bp_unit_index, else find the next free index.
let breakpoint_comparator_index = match self
.inner
.hw_breakpoints()?
.iter()
.position(|&bp| bp == Some(address))
{
Some(breakpoint_comparator_index) => breakpoint_comparator_index,
None => self.find_free_breakpoint_comparator_index()?,
};
tracing::debug!(
"Trying to set HW breakpoint #{} with comparator address {:#08x}",
breakpoint_comparator_index,
address
);
// Actually set the breakpoint. Even if it has been set, set it again so it will be active.
self.inner
.set_hw_breakpoint(breakpoint_comparator_index, address)?;
Ok(())
}
/// Set a hardware breakpoint
///
/// This function will try to clear a hardware breakpoint at `address` if there exists a breakpoint at that address.
#[tracing::instrument(skip(self))]
pub fn clear_hw_breakpoint(&mut self, address: u64) -> Result<(), Error> {
let bp_position = self
.inner
.hw_breakpoints()?
.iter()
.position(|bp| bp.is_some() && bp.unwrap() == address);
tracing::debug!(
"Will clear HW breakpoint #{} with comparator address {:#08x}",
bp_position.unwrap_or(usize::MAX),
address
);
match bp_position {
Some(bp_position) => {
self.inner.clear_hw_breakpoint(bp_position)?;
Ok(())
}
None => Err(Error::Other(format!(
"No breakpoint found at address {:#010x}",
address
))),
}
}
/// Clear all hardware breakpoints
///
/// This function will clear all HW breakpoints which are configured on the target,
/// regardless if they are set by probe-rs, AND regardless if they are enabled or not.
/// Also used as a helper function in [`Session::drop`](crate::session::Session).
#[tracing::instrument(skip(self))]
pub fn clear_all_hw_breakpoints(&mut self) -> Result<(), Error> {
for breakpoint in (self.inner.hw_breakpoints()?).into_iter().flatten() {
self.clear_hw_breakpoint(breakpoint)?
}
Ok(())
}
/// Returns the architecture of the core.
pub fn architecture(&self) -> Architecture {
self.inner.architecture()
}
/// Returns the core type of the core
pub fn core_type(&self) -> CoreType {
self.inner.core_type()
}
/// Determine the instruction set the core is operating in
/// This must be queried while halted as this is a runtime
/// decision for some core types
pub fn instruction_set(&mut self) -> Result<InstructionSet, Error> {
self.inner.instruction_set()
}
/// Determine if an FPU is present.
/// This must be queried while halted as this is a runtime
/// decision for some core types.
pub fn fpu_support(&mut self) -> Result<bool, Error> {
self.inner.fpu_support()
}
/// Determine the number of floating point registers.
/// This must be queried while halted as this is a runtime decision for some core types.
pub fn floating_point_register_count(&mut self) -> Result<usize, Error> {
self.inner.floating_point_register_count()
}
pub(crate) fn reset_catch_set(&mut self) -> Result<(), Error> {
self.inner.reset_catch_set()
}
pub(crate) fn reset_catch_clear(&mut self) -> Result<(), Error> {
self.inner.reset_catch_clear()
}
pub(crate) fn debug_core_stop(&mut self) -> Result<(), Error> {
self.inner.debug_core_stop()
}
/// Enables vector catching for the given `condition`
pub fn enable_vector_catch(&mut self, condition: VectorCatchCondition) -> Result<(), Error> {
self.inner.enable_vector_catch(condition)
}
/// Disables vector catching for the given `condition`
pub fn disable_vector_catch(&mut self, condition: VectorCatchCondition) -> Result<(), Error> {
self.inner.disable_vector_catch(condition)
}
/// Check if the integer size is 64-bit
pub fn is_64_bit(&self) -> bool {
self.inner.is_64_bit()
}
}
impl CoreInterface for Core<'_> {
fn wait_for_core_halted(&mut self, timeout: Duration) -> Result<(), Error> {
self.wait_for_core_halted(timeout)
}
fn core_halted(&mut self) -> Result<bool, Error> {
self.core_halted()
}
fn status(&mut self) -> Result<CoreStatus, Error> {
self.status()
}
fn halt(&mut self, timeout: Duration) -> Result<CoreInformation, Error> {
self.halt(timeout)
}
fn run(&mut self) -> Result<(), Error> {
self.run()
}
fn reset(&mut self) -> Result<(), Error> {
self.reset()
}
fn reset_and_halt(&mut self, timeout: Duration) -> Result<CoreInformation, Error> {
self.reset_and_halt(timeout)
}
fn step(&mut self) -> Result<CoreInformation, Error> {
self.step()
}
fn read_core_reg(
&mut self,
address: registers::RegisterId,
) -> Result<registers::RegisterValue, Error> {
self.read_core_reg(address)
}
fn write_core_reg(
&mut self,
address: registers::RegisterId,
value: registers::RegisterValue,
) -> Result<(), Error> {
self.write_core_reg(address, value)
}
fn available_breakpoint_units(&mut self) -> Result<u32, Error> {
self.available_breakpoint_units()
}
fn hw_breakpoints(&mut self) -> Result<Vec<Option<u64>>, Error> {
self.inner.hw_breakpoints()
}
fn enable_breakpoints(&mut self, state: bool) -> Result<(), Error> {
self.enable_breakpoints(state)
}
fn set_hw_breakpoint(&mut self, _unit_index: usize, addr: u64) -> Result<(), Error> {
self.set_hw_breakpoint(addr)
}
fn clear_hw_breakpoint(&mut self, _unit_index: usize) -> Result<(), Error> {
self.clear_all_hw_breakpoints()
}
fn registers(&self) -> &'static registers::CoreRegisters {
self.registers()
}
fn program_counter(&self) -> &'static CoreRegister {
self.program_counter()
}
fn frame_pointer(&self) -> &'static CoreRegister {
self.frame_pointer()
}
fn stack_pointer(&self) -> &'static CoreRegister {
self.stack_pointer()
}
fn return_address(&self) -> &'static CoreRegister {
self.return_address()
}
fn hw_breakpoints_enabled(&self) -> bool {
todo!()
}
fn architecture(&self) -> Architecture {
self.architecture()
}
fn core_type(&self) -> CoreType {
self.core_type()
}
fn instruction_set(&mut self) -> Result<InstructionSet, Error> {
self.instruction_set()
}
fn fpu_support(&mut self) -> Result<bool, Error> {
self.fpu_support()
}
fn floating_point_register_count(&mut self) -> Result<usize, crate::error::Error> {
self.floating_point_register_count()
}
fn reset_catch_set(&mut self) -> Result<(), Error> {
self.reset_catch_set()
}
fn reset_catch_clear(&mut self) -> Result<(), Error> {
self.reset_catch_clear()
}
fn debug_core_stop(&mut self) -> Result<(), Error> {
self.debug_core_stop()
}
fn is_64_bit(&self) -> bool {
self.is_64_bit()
}
}
pub enum ResolvedCoreOptions {
Arm {
sequence: Arc<dyn ArmDebugSequence>,
options: ArmCoreAccessOptions,
},
Riscv {
sequence: Arc<dyn RiscvDebugSequence>,
options: RiscvCoreAccessOptions,
},
Xtensa {
sequence: Arc<dyn XtensaDebugSequence>,
options: XtensaCoreAccessOptions,
},
}
impl ResolvedCoreOptions {
fn new(target: &Target, options: CoreAccessOptions) -> Self {
match (options, target.debug_sequence.clone()) {
(CoreAccessOptions::Arm(options), DebugSequence::Arm(sequence)) => {
Self::Arm { sequence, options }
}
(CoreAccessOptions::Riscv(options), DebugSequence::Riscv(sequence)) => {
Self::Riscv { sequence, options }
}
(CoreAccessOptions::Xtensa(options), DebugSequence::Xtensa(sequence)) => {
Self::Xtensa { sequence, options }
}
_ => unreachable!(
"Mismatch between core kind and access options. This is a bug, please report it."
),
}
}
fn interface_idx(&self) -> usize {
match self {
Self::Arm { options, .. } => options.jtag_tap.unwrap_or(0),
Self::Riscv { options, .. } => options.jtag_tap.unwrap_or(0),
Self::Xtensa { options, .. } => options.jtag_tap.unwrap_or(0),
}
}
}
impl std::fmt::Debug for ResolvedCoreOptions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Arm { options, .. } => f
.debug_struct("Arm")
.field("sequence", &"<ArmDebugSequence>")
.field("options", options)
.finish(),
Self::Riscv { options, .. } => f
.debug_struct("Riscv")
.field("sequence", &"<RiscvDebugSequence>")
.field("options", options)
.finish(),
Self::Xtensa { options, .. } => f
.debug_struct("Xtensa")
.field("sequence", &"<XtensaDebugSequence>")
.field("options", options)
.finish(),
}
}
}