Skip to main content

asmkit/x86/features/
OSPKE.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/// `RDPKRU` (RDPKRU). 
11/// Reads the value of PKRU into EAX and clears EDX. ECX must be 0 when RDPKRU is executed; otherwise, a general-protection exception (#GP) occurs.
12///
13///
14/// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/RDPKRU.html).
15///
16/// Supported operand variants:
17///
18/// ```text
19/// +---+----------+
20/// | # | Operands |
21/// +---+----------+
22/// | 1 | (none)   |
23/// +---+----------+
24/// ```
25pub trait RdpkruEmitter {
26    fn rdpkru(&mut self);
27}
28
29impl<'a> RdpkruEmitter for Assembler<'a> {
30    fn rdpkru(&mut self) {
31        self.emit(RDPKRU, &NOREG, &NOREG, &NOREG, &NOREG);
32    }
33}
34
35/// `WRPKRU` (WRPKRU). 
36/// Writes the value of EAX into PKRU. ECX and EDX must be 0 when WRPKRU is executed; otherwise, a general-protection exception (#GP) occurs.
37///
38///
39/// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/WRPKRU.html).
40///
41/// Supported operand variants:
42///
43/// ```text
44/// +---+----------+
45/// | # | Operands |
46/// +---+----------+
47/// | 1 | (none)   |
48/// +---+----------+
49/// ```
50pub trait WrpkruEmitter {
51    fn wrpkru(&mut self);
52}
53
54impl<'a> WrpkruEmitter for Assembler<'a> {
55    fn wrpkru(&mut self) {
56        self.emit(WRPKRU, &NOREG, &NOREG, &NOREG, &NOREG);
57    }
58}
59
60
61impl<'a> Assembler<'a> {
62    /// `RDPKRU` (RDPKRU). 
63    /// Reads the value of PKRU into EAX and clears EDX. ECX must be 0 when RDPKRU is executed; otherwise, a general-protection exception (#GP) occurs.
64    ///
65    ///
66    /// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/RDPKRU.html).
67    ///
68    /// Supported operand variants:
69    ///
70    /// ```text
71    /// +---+----------+
72    /// | # | Operands |
73    /// +---+----------+
74    /// | 1 | (none)   |
75    /// +---+----------+
76    /// ```
77    #[inline]
78    pub fn rdpkru(&mut self)
79    where Assembler<'a>: RdpkruEmitter {
80        <Self as RdpkruEmitter>::rdpkru(self);
81    }
82    /// `WRPKRU` (WRPKRU). 
83    /// Writes the value of EAX into PKRU. ECX and EDX must be 0 when WRPKRU is executed; otherwise, a general-protection exception (#GP) occurs.
84    ///
85    ///
86    /// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/WRPKRU.html).
87    ///
88    /// Supported operand variants:
89    ///
90    /// ```text
91    /// +---+----------+
92    /// | # | Operands |
93    /// +---+----------+
94    /// | 1 | (none)   |
95    /// +---+----------+
96    /// ```
97    #[inline]
98    pub fn wrpkru(&mut self)
99    where Assembler<'a>: WrpkruEmitter {
100        <Self as WrpkruEmitter>::wrpkru(self);
101    }
102}