Skip to main content

asmkit/x86/features/
SVM.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/// `INVLPGA`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+----------+
16/// | # | Operands |
17/// +---+----------+
18/// | 1 | (none)   |
19/// +---+----------+
20/// ```
21pub trait InvlpgaEmitter {
22    fn invlpga(&mut self);
23}
24
25impl<'a> InvlpgaEmitter for Assembler<'a> {
26    fn invlpga(&mut self) {
27        self.emit(INVLPGA, &NOREG, &NOREG, &NOREG, &NOREG);
28    }
29}
30
31/// `VMLOAD`.
32///
33/// Supported operand variants:
34///
35/// ```text
36/// +---+----------+
37/// | # | Operands |
38/// +---+----------+
39/// | 1 | (none)   |
40/// +---+----------+
41/// ```
42pub trait VmloadEmitter {
43    fn vmload(&mut self);
44}
45
46impl<'a> VmloadEmitter for Assembler<'a> {
47    fn vmload(&mut self) {
48        self.emit(VMLOAD, &NOREG, &NOREG, &NOREG, &NOREG);
49    }
50}
51
52/// `VMMCALL`.
53///
54/// Supported operand variants:
55///
56/// ```text
57/// +---+----------+
58/// | # | Operands |
59/// +---+----------+
60/// | 1 | (none)   |
61/// +---+----------+
62/// ```
63pub trait VmmcallEmitter {
64    fn vmmcall(&mut self);
65}
66
67impl<'a> VmmcallEmitter for Assembler<'a> {
68    fn vmmcall(&mut self) {
69        self.emit(VMMCALL, &NOREG, &NOREG, &NOREG, &NOREG);
70    }
71}
72
73/// `VMRUN`.
74///
75/// Supported operand variants:
76///
77/// ```text
78/// +---+----------+
79/// | # | Operands |
80/// +---+----------+
81/// | 1 | (none)   |
82/// +---+----------+
83/// ```
84pub trait VmrunEmitter {
85    fn vmrun(&mut self);
86}
87
88impl<'a> VmrunEmitter for Assembler<'a> {
89    fn vmrun(&mut self) {
90        self.emit(VMRUN, &NOREG, &NOREG, &NOREG, &NOREG);
91    }
92}
93
94/// `VMSAVE`.
95///
96/// Supported operand variants:
97///
98/// ```text
99/// +---+----------+
100/// | # | Operands |
101/// +---+----------+
102/// | 1 | (none)   |
103/// +---+----------+
104/// ```
105pub trait VmsaveEmitter {
106    fn vmsave(&mut self);
107}
108
109impl<'a> VmsaveEmitter for Assembler<'a> {
110    fn vmsave(&mut self) {
111        self.emit(VMSAVE, &NOREG, &NOREG, &NOREG, &NOREG);
112    }
113}
114
115
116impl<'a> Assembler<'a> {
117    /// `INVLPGA`.
118    ///
119    /// Supported operand variants:
120    ///
121    /// ```text
122    /// +---+----------+
123    /// | # | Operands |
124    /// +---+----------+
125    /// | 1 | (none)   |
126    /// +---+----------+
127    /// ```
128    #[inline]
129    pub fn invlpga(&mut self)
130    where Assembler<'a>: InvlpgaEmitter {
131        <Self as InvlpgaEmitter>::invlpga(self);
132    }
133    /// `VMLOAD`.
134    ///
135    /// Supported operand variants:
136    ///
137    /// ```text
138    /// +---+----------+
139    /// | # | Operands |
140    /// +---+----------+
141    /// | 1 | (none)   |
142    /// +---+----------+
143    /// ```
144    #[inline]
145    pub fn vmload(&mut self)
146    where Assembler<'a>: VmloadEmitter {
147        <Self as VmloadEmitter>::vmload(self);
148    }
149    /// `VMMCALL`.
150    ///
151    /// Supported operand variants:
152    ///
153    /// ```text
154    /// +---+----------+
155    /// | # | Operands |
156    /// +---+----------+
157    /// | 1 | (none)   |
158    /// +---+----------+
159    /// ```
160    #[inline]
161    pub fn vmmcall(&mut self)
162    where Assembler<'a>: VmmcallEmitter {
163        <Self as VmmcallEmitter>::vmmcall(self);
164    }
165    /// `VMRUN`.
166    ///
167    /// Supported operand variants:
168    ///
169    /// ```text
170    /// +---+----------+
171    /// | # | Operands |
172    /// +---+----------+
173    /// | 1 | (none)   |
174    /// +---+----------+
175    /// ```
176    #[inline]
177    pub fn vmrun(&mut self)
178    where Assembler<'a>: VmrunEmitter {
179        <Self as VmrunEmitter>::vmrun(self);
180    }
181    /// `VMSAVE`.
182    ///
183    /// Supported operand variants:
184    ///
185    /// ```text
186    /// +---+----------+
187    /// | # | Operands |
188    /// +---+----------+
189    /// | 1 | (none)   |
190    /// +---+----------+
191    /// ```
192    #[inline]
193    pub fn vmsave(&mut self)
194    where Assembler<'a>: VmsaveEmitter {
195        <Self as VmsaveEmitter>::vmsave(self);
196    }
197}