Skip to main content

asmkit/x86/features/
XSAVE.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/// `XGETBV`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+----------+
16/// | # | Operands |
17/// +---+----------+
18/// | 1 | (none)   |
19/// +---+----------+
20/// ```
21pub trait XgetbvEmitter {
22    fn xgetbv(&mut self);
23}
24
25impl<'a> XgetbvEmitter for Assembler<'a> {
26    fn xgetbv(&mut self) {
27        self.emit(XGETBV, &NOREG, &NOREG, &NOREG, &NOREG);
28    }
29}
30
31/// `XRSTOR`.
32///
33/// Supported operand variants:
34///
35/// ```text
36/// +---+----------+
37/// | # | Operands |
38/// +---+----------+
39/// | 1 | Mem      |
40/// +---+----------+
41/// ```
42pub trait XrstorEmitter<A> {
43    fn xrstor(&mut self, op0: A);
44}
45
46impl<'a> XrstorEmitter<Mem> for Assembler<'a> {
47    fn xrstor(&mut self, op0: Mem) {
48        self.emit(XRSTOR32M, op0.as_operand(), &NOREG, &NOREG, &NOREG);
49    }
50}
51
52/// `XSAVE`.
53///
54/// Supported operand variants:
55///
56/// ```text
57/// +---+----------+
58/// | # | Operands |
59/// +---+----------+
60/// | 1 | Mem      |
61/// +---+----------+
62/// ```
63pub trait XsaveEmitter<A> {
64    fn xsave(&mut self, op0: A);
65}
66
67impl<'a> XsaveEmitter<Mem> for Assembler<'a> {
68    fn xsave(&mut self, op0: Mem) {
69        self.emit(XSAVE32M, op0.as_operand(), &NOREG, &NOREG, &NOREG);
70    }
71}
72
73/// `XSETBV`.
74///
75/// Supported operand variants:
76///
77/// ```text
78/// +---+----------+
79/// | # | Operands |
80/// +---+----------+
81/// | 1 | (none)   |
82/// +---+----------+
83/// ```
84pub trait XsetbvEmitter {
85    fn xsetbv(&mut self);
86}
87
88impl<'a> XsetbvEmitter for Assembler<'a> {
89    fn xsetbv(&mut self) {
90        self.emit(XSETBV, &NOREG, &NOREG, &NOREG, &NOREG);
91    }
92}
93
94impl<'a> Assembler<'a> {
95    /// `XGETBV`.
96    ///
97    /// Supported operand variants:
98    ///
99    /// ```text
100    /// +---+----------+
101    /// | # | Operands |
102    /// +---+----------+
103    /// | 1 | (none)   |
104    /// +---+----------+
105    /// ```
106    #[inline]
107    pub fn xgetbv(&mut self)
108    where
109        Assembler<'a>: XgetbvEmitter,
110    {
111        <Self as XgetbvEmitter>::xgetbv(self);
112    }
113    /// `XRSTOR`.
114    ///
115    /// Supported operand variants:
116    ///
117    /// ```text
118    /// +---+----------+
119    /// | # | Operands |
120    /// +---+----------+
121    /// | 1 | Mem      |
122    /// +---+----------+
123    /// ```
124    #[inline]
125    pub fn xrstor<A>(&mut self, op0: A)
126    where
127        Assembler<'a>: XrstorEmitter<A>,
128    {
129        <Self as XrstorEmitter<A>>::xrstor(self, op0);
130    }
131    /// `XSAVE`.
132    ///
133    /// Supported operand variants:
134    ///
135    /// ```text
136    /// +---+----------+
137    /// | # | Operands |
138    /// +---+----------+
139    /// | 1 | Mem      |
140    /// +---+----------+
141    /// ```
142    #[inline]
143    pub fn xsave<A>(&mut self, op0: A)
144    where
145        Assembler<'a>: XsaveEmitter<A>,
146    {
147        <Self as XsaveEmitter<A>>::xsave(self, op0);
148    }
149    /// `XSETBV`.
150    ///
151    /// Supported operand variants:
152    ///
153    /// ```text
154    /// +---+----------+
155    /// | # | Operands |
156    /// +---+----------+
157    /// | 1 | (none)   |
158    /// +---+----------+
159    /// ```
160    #[inline]
161    pub fn xsetbv(&mut self)
162    where
163        Assembler<'a>: XsetbvEmitter,
164    {
165        <Self as XsetbvEmitter>::xsetbv(self);
166    }
167}