Skip to main content

asmkit/x86/features/
SVM.rs

1use super::super::opcodes::*;
2use crate::core::emitter::*;
3use crate::core::operand::*;
4use crate::x86::assembler::*;
5use crate::x86::operands::*;
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
115impl<'a> Assembler<'a> {
116    /// `INVLPGA`.
117    ///
118    /// Supported operand variants:
119    ///
120    /// ```text
121    /// +---+----------+
122    /// | # | Operands |
123    /// +---+----------+
124    /// | 1 | (none)   |
125    /// +---+----------+
126    /// ```
127    #[inline]
128    pub fn invlpga(&mut self)
129    where
130        Assembler<'a>: InvlpgaEmitter,
131    {
132        <Self as InvlpgaEmitter>::invlpga(self);
133    }
134    /// `VMLOAD`.
135    ///
136    /// Supported operand variants:
137    ///
138    /// ```text
139    /// +---+----------+
140    /// | # | Operands |
141    /// +---+----------+
142    /// | 1 | (none)   |
143    /// +---+----------+
144    /// ```
145    #[inline]
146    pub fn vmload(&mut self)
147    where
148        Assembler<'a>: VmloadEmitter,
149    {
150        <Self as VmloadEmitter>::vmload(self);
151    }
152    /// `VMMCALL`.
153    ///
154    /// Supported operand variants:
155    ///
156    /// ```text
157    /// +---+----------+
158    /// | # | Operands |
159    /// +---+----------+
160    /// | 1 | (none)   |
161    /// +---+----------+
162    /// ```
163    #[inline]
164    pub fn vmmcall(&mut self)
165    where
166        Assembler<'a>: VmmcallEmitter,
167    {
168        <Self as VmmcallEmitter>::vmmcall(self);
169    }
170    /// `VMRUN`.
171    ///
172    /// Supported operand variants:
173    ///
174    /// ```text
175    /// +---+----------+
176    /// | # | Operands |
177    /// +---+----------+
178    /// | 1 | (none)   |
179    /// +---+----------+
180    /// ```
181    #[inline]
182    pub fn vmrun(&mut self)
183    where
184        Assembler<'a>: VmrunEmitter,
185    {
186        <Self as VmrunEmitter>::vmrun(self);
187    }
188    /// `VMSAVE`.
189    ///
190    /// Supported operand variants:
191    ///
192    /// ```text
193    /// +---+----------+
194    /// | # | Operands |
195    /// +---+----------+
196    /// | 1 | (none)   |
197    /// +---+----------+
198    /// ```
199    #[inline]
200    pub fn vmsave(&mut self)
201    where
202        Assembler<'a>: VmsaveEmitter,
203    {
204        <Self as VmsaveEmitter>::vmsave(self);
205    }
206}