Skip to main content

asmkit/x86/features/
MONITOR.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/// `MONITOR`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+----------+
16/// | # | Operands |
17/// +---+----------+
18/// | 1 | (none)   |
19/// +---+----------+
20/// ```
21pub trait MonitorEmitter {
22    fn monitor(&mut self);
23}
24
25impl<'a> MonitorEmitter for Assembler<'a> {
26    fn monitor(&mut self) {
27        self.emit(MONITOR, &NOREG, &NOREG, &NOREG, &NOREG);
28    }
29}
30
31/// `MWAIT` (MWAIT). 
32/// MWAIT instruction provides hints to allow the processor to enter an implementation-dependent optimized state. There are two principal targeted usages: address-range monitor and advanced power management. Both usages of MWAIT require the use of the MONITOR instruction.
33///
34///
35/// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/MWAIT.html).
36///
37/// Supported operand variants:
38///
39/// ```text
40/// +---+----------+
41/// | # | Operands |
42/// +---+----------+
43/// | 1 | (none)   |
44/// +---+----------+
45/// ```
46pub trait MwaitEmitter {
47    fn mwait(&mut self);
48}
49
50impl<'a> MwaitEmitter for Assembler<'a> {
51    fn mwait(&mut self) {
52        self.emit(MWAIT, &NOREG, &NOREG, &NOREG, &NOREG);
53    }
54}
55
56
57impl<'a> Assembler<'a> {
58    /// `MONITOR`.
59    ///
60    /// Supported operand variants:
61    ///
62    /// ```text
63    /// +---+----------+
64    /// | # | Operands |
65    /// +---+----------+
66    /// | 1 | (none)   |
67    /// +---+----------+
68    /// ```
69    #[inline]
70    pub fn monitor(&mut self)
71    where Assembler<'a>: MonitorEmitter {
72        <Self as MonitorEmitter>::monitor(self);
73    }
74    /// `MWAIT` (MWAIT). 
75    /// MWAIT instruction provides hints to allow the processor to enter an implementation-dependent optimized state. There are two principal targeted usages: address-range monitor and advanced power management. Both usages of MWAIT require the use of the MONITOR instruction.
76    ///
77    ///
78    /// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/MWAIT.html).
79    ///
80    /// Supported operand variants:
81    ///
82    /// ```text
83    /// +---+----------+
84    /// | # | Operands |
85    /// +---+----------+
86    /// | 1 | (none)   |
87    /// +---+----------+
88    /// ```
89    #[inline]
90    pub fn mwait(&mut self)
91    where Assembler<'a>: MwaitEmitter {
92        <Self as MwaitEmitter>::mwait(self);
93    }
94}