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
//! 特定于 ARM 编译器的内部函数
//!
//! # References
//!
//! - [ARM Compiler v 6.10 - armclang Reference Guide][arm_comp_ref]
//!
//! [arm_comp_ref]: https://developer.arm.com/docs/100067/0610

#[cfg(test)]
use stdarch_test::assert_instr;

/// 插入断点指令。
///
/// `VAL` 是 `[0, 255]` 范围内的编译时常量整数。
///
/// 插入的断点指令是 A32/T32 上的 `BKPT`。
///
/// # Note
///
/// [ARM 的文档][arm_docs] 定义了 `__breakpoint` 并接受以下值作为 `VAL`:
///
/// - 当编译为 A32 时 为 `0...65535`,
/// - 当编译为 T32 时为 `0...255`。
///
/// 当前的实现只接受 `[0, 255]` 范围内的值。
///
/// [arm_docs]: https://developer.arm.com/docs/100067/latest/compiler-specific-intrinsics/__breakpoint-intrinsic
///
#[cfg_attr(test, assert_instr(bkpt, VAL = 0))]
#[inline(always)]
#[rustc_legacy_const_generics(0)]
pub unsafe fn __breakpoint<const VAL: i32>() {
    static_assert_uimm_bits!(VAL, 8);
    crate::arch::asm!("bkpt #{}", const VAL);
}