Skip to main content

asmkit/x86/features/
FRED.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/// `ERETS`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+----------+
16/// | # | Operands |
17/// +---+----------+
18/// | 1 | (none)   |
19/// +---+----------+
20/// ```
21pub trait EretsEmitter {
22    fn erets(&mut self);
23}
24
25impl<'a> EretsEmitter for Assembler<'a> {
26    fn erets(&mut self) {
27        self.emit(ERETS, &NOREG, &NOREG, &NOREG, &NOREG);
28    }
29}
30
31/// `ERETU`.
32///
33/// Supported operand variants:
34///
35/// ```text
36/// +---+----------+
37/// | # | Operands |
38/// +---+----------+
39/// | 1 | (none)   |
40/// +---+----------+
41/// ```
42pub trait EretuEmitter {
43    fn eretu(&mut self);
44}
45
46impl<'a> EretuEmitter for Assembler<'a> {
47    fn eretu(&mut self) {
48        self.emit(ERETU, &NOREG, &NOREG, &NOREG, &NOREG);
49    }
50}
51
52/// `LKGS`.
53///
54/// Supported operand variants:
55///
56/// ```text
57/// +---+----------+
58/// | # | Operands |
59/// +---+----------+
60/// | 1 | Gpd      |
61/// | 2 | Mem      |
62/// +---+----------+
63/// ```
64pub trait LkgsEmitter<A> {
65    fn lkgs(&mut self, op0: A);
66}
67
68impl<'a> LkgsEmitter<Gpd> for Assembler<'a> {
69    fn lkgs(&mut self, op0: Gpd) {
70        self.emit(LKGSR, op0.as_operand(), &NOREG, &NOREG, &NOREG);
71    }
72}
73
74impl<'a> LkgsEmitter<Mem> for Assembler<'a> {
75    fn lkgs(&mut self, op0: Mem) {
76        self.emit(LKGSM, op0.as_operand(), &NOREG, &NOREG, &NOREG);
77    }
78}
79
80impl<'a> Assembler<'a> {
81    /// `ERETS`.
82    ///
83    /// Supported operand variants:
84    ///
85    /// ```text
86    /// +---+----------+
87    /// | # | Operands |
88    /// +---+----------+
89    /// | 1 | (none)   |
90    /// +---+----------+
91    /// ```
92    #[inline]
93    pub fn erets(&mut self)
94    where
95        Assembler<'a>: EretsEmitter,
96    {
97        <Self as EretsEmitter>::erets(self);
98    }
99    /// `ERETU`.
100    ///
101    /// Supported operand variants:
102    ///
103    /// ```text
104    /// +---+----------+
105    /// | # | Operands |
106    /// +---+----------+
107    /// | 1 | (none)   |
108    /// +---+----------+
109    /// ```
110    #[inline]
111    pub fn eretu(&mut self)
112    where
113        Assembler<'a>: EretuEmitter,
114    {
115        <Self as EretuEmitter>::eretu(self);
116    }
117    /// `LKGS`.
118    ///
119    /// Supported operand variants:
120    ///
121    /// ```text
122    /// +---+----------+
123    /// | # | Operands |
124    /// +---+----------+
125    /// | 1 | Gpd      |
126    /// | 2 | Mem      |
127    /// +---+----------+
128    /// ```
129    #[inline]
130    pub fn lkgs<A>(&mut self, op0: A)
131    where
132        Assembler<'a>: LkgsEmitter<A>,
133    {
134        <Self as LkgsEmitter<A>>::lkgs(self, op0);
135    }
136}