disarm64/
lib.rs

1//! This is a library for decoding ARM64 instructions.
2//!
3//! The main entry point is the `decode` function, which decodes a single instruction:
4//!
5//! ```
6//! use disarm64::decoder;
7//! use disarm64_defn::defn::InsnOpcode;
8//!
9//! let insn = decoder::decode(0x11000000).unwrap();
10//!
11//! println!("Instruction: {insn:?}");
12//! println!("Formatted: {insn}");
13//! println!("Definition: {:?}", insn.definition());
14//! ```
15//!
16
17#![no_std]
18
19use core::fmt::Display;
20use core::fmt::Formatter;
21
22#[cfg(feature = "full")]
23pub mod decoder_full;
24#[cfg(feature = "full")]
25pub use decoder_full as decoder;
26#[cfg(feature = "full")]
27pub use decoder_full::Opcode;
28#[cfg(feature = "full")]
29impl Display for Opcode {
30    /// The program counter is not used for the PC-relative addressing here.
31    /// Thus this default formattikng is not able to emit the target address
32    /// in the disassembly so it emits the offset.
33    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
34        crate::format_insn::format_insn_pc(0, f, self)
35    }
36}
37
38#[cfg(feature = "exception")]
39pub mod decoder_exception;
40#[cfg(feature = "exception")]
41pub use decoder_exception::Opcode as ExceptionOpcode;
42#[cfg(feature = "exception")]
43impl Display for ExceptionOpcode {
44    /// The program counter is not used for the PC-relative addressing here.
45    /// Thus this default formattikng is not able to emit the target address
46    /// in the disassembly so it emits the offset.
47    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
48        crate::format_insn::format_insn_pc(0, f, self)
49    }
50}
51
52#[cfg(feature = "load_store")]
53pub mod decoder_load_store;
54#[cfg(feature = "load_store")]
55pub use decoder_load_store::Opcode as LoadStoreOpcode;
56#[cfg(feature = "load_store")]
57impl Display for LoadStoreOpcode {
58    /// The program counter is not used for the PC-relative addressing here.
59    /// Thus this default formattikng is not able to emit the target address
60    /// in the disassembly so it emits the offset.
61    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
62        crate::format_insn::format_insn_pc(0, f, self)
63    }
64}
65
66#[cfg(feature = "system")]
67pub mod decoder_system;
68#[cfg(feature = "system")]
69pub use decoder_system::Opcode as SystemOpcode;
70#[cfg(feature = "system")]
71impl Display for SystemOpcode {
72    /// The program counter is not used for the PC-relative addressing here.
73    /// Thus this default formattikng is not able to emit the target address
74    /// in the disassembly so it emits the offset.
75    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
76        crate::format_insn::format_insn_pc(0, f, self)
77    }
78}
79
80pub mod format_insn;
81pub mod registers;