asmkit/x86/features/PTWRITE.rs
1use crate::x86::assembler::*;
2use crate::x86::operands::*;
3use super::super::opcodes::*;
4use crate::core::emitter::*;
5use crate::core::operand::*;
6
7/// A dummy operand that represents no register. Here just for simplicity.
8const NOREG: Operand = Operand::new();
9
10/// `PTWRITE` (PTWRITE).
11/// This instruction reads data in the source operand and sends it to the Intel Processor Trace hardware to be encoded in a PTW packet if TriggerEn, ContextEn, FilterEn, and PTWEn are all set to 1. For more details on these values, see Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3C, Section 33.2.2, “Software Trace Instrumentation with PTWRITE.” The size of data is 64-bit if using REX.W in 64-bit mode, otherwise 32-bits of data are copied from the source operand.
12///
13///
14/// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/PTWRITE.html).
15///
16/// Supported operand variants:
17///
18/// ```text
19/// +---+----------+
20/// | # | Operands |
21/// +---+----------+
22/// | 1 | Gpd |
23/// | 2 | Gpq |
24/// | 3 | Mem |
25/// +---+----------+
26/// ```
27pub trait PtwriteEmitter<A> {
28 fn ptwrite(&mut self, op0: A);
29}
30
31impl<'a> PtwriteEmitter<Gpd> for Assembler<'a> {
32 fn ptwrite(&mut self, op0: Gpd) {
33 self.emit(PTWRITE32R, op0.as_operand(), &NOREG, &NOREG, &NOREG);
34 }
35}
36
37impl<'a> PtwriteEmitter<Mem> for Assembler<'a> {
38 fn ptwrite(&mut self, op0: Mem) {
39 self.emit(PTWRITE32M, op0.as_operand(), &NOREG, &NOREG, &NOREG);
40 }
41}
42
43impl<'a> PtwriteEmitter<Gpq> for Assembler<'a> {
44 fn ptwrite(&mut self, op0: Gpq) {
45 self.emit(PTWRITE64R, op0.as_operand(), &NOREG, &NOREG, &NOREG);
46 }
47}
48
49
50impl<'a> Assembler<'a> {
51 /// `PTWRITE` (PTWRITE).
52 /// This instruction reads data in the source operand and sends it to the Intel Processor Trace hardware to be encoded in a PTW packet if TriggerEn, ContextEn, FilterEn, and PTWEn are all set to 1. For more details on these values, see Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3C, Section 33.2.2, “Software Trace Instrumentation with PTWRITE.” The size of data is 64-bit if using REX.W in 64-bit mode, otherwise 32-bits of data are copied from the source operand.
53 ///
54 ///
55 /// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/PTWRITE.html).
56 ///
57 /// Supported operand variants:
58 ///
59 /// ```text
60 /// +---+----------+
61 /// | # | Operands |
62 /// +---+----------+
63 /// | 1 | Gpd |
64 /// | 2 | Gpq |
65 /// | 3 | Mem |
66 /// +---+----------+
67 /// ```
68 #[inline]
69 pub fn ptwrite<A>(&mut self, op0: A)
70 where Assembler<'a>: PtwriteEmitter<A> {
71 <Self as PtwriteEmitter<A>>::ptwrite(self, op0);
72 }
73}