blob: be4920ac7656edc43ddd680e8495dab3aff98eee (
plain)
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
|
/// The struct that represents an A64 breakpoint instruction that can be encoded.
///
/// +-------------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
/// | 31 30 29 28 | 27 26 25 24 | 23 22 21 20 | 19 18 17 16 | 15 14 13 12 | 11 10 09 08 | 07 06 05 04 | 03 02 01 00 |
/// | 1 1 0 1 0 1 0 0 0 0 1 0 0 0 0 0 |
/// | imm16.................................................. |
/// +-------------+-------------+-------------+-------------+-------------+-------------+-------------+-------------+
///
pub struct Breakpoint {
/// The value to be captured by ESR_ELx.ISS
imm16: u16
}
impl Breakpoint {
/// BRK
/// https://developer.arm.com/documentation/ddi0596/2020-12/Base-Instructions/BRK--Breakpoint-instruction-
pub fn brk(imm16: u16) -> Self {
Self { imm16 }
}
}
/// https://developer.arm.com/documentation/ddi0602/2022-03/Index-by-Encoding/Branches--Exception-Generating-and-System-instructions?lang=en#control
const FAMILY: u32 = 0b101;
impl From<Breakpoint> for u32 {
/// Convert an instruction into a 32-bit value.
fn from(inst: Breakpoint) -> Self {
let imm16 = inst.imm16 as u32;
0
| (0b11 << 30)
| (FAMILY << 26)
| (1 << 21)
| (imm16 << 5)
}
}
impl From<Breakpoint> for [u8; 4] {
/// Convert an instruction into a 4 byte array.
fn from(inst: Breakpoint) -> [u8; 4] {
let result: u32 = inst.into();
result.to_le_bytes()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_brk() {
let result: u32 = Breakpoint::brk(7).into();
assert_eq!(0xd42000e0, result);
}
}
|