Skip to main content

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