Skip to main content

asmkit/x86/features/
FXSR.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/// `FXRSTOR` (FXRSTOR). 
11/// Reloads the x87 FPU, MMX technology, XMM, and MXCSR registers from the 512-byte memory image specified in the source operand. This data should have been written to memory previously using the FXSAVE instruction, and in the same format as required by the operating modes. The first byte of the data should be located on a 16-byte boundary. There are three distinct layouts of the FXSAVE state map: one for legacy and compatibility mode, a second format for 64-bit mode FXSAVE/FXRSTOR with REX.W=0, and the third format is for 64-bit mode with FXSAVE64/FXRSTOR64. Table 3-43 shows the layout of the legacy/compatibility mode state information in memory and describes the fields in the memory image for the FXRSTOR and FXSAVE instructions. Table 3-46 shows the layout of the 64-bit mode state information when REX.W is set (FXSAVE64/FXRSTOR64). Table 3-47 shows the layout of the 64-bit mode state information when REX.W is clear (FXSAVE/FXRSTOR).
12///
13///
14/// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/FXRSTOR.html).
15///
16/// Supported operand variants:
17///
18/// ```text
19/// +---+----------+
20/// | # | Operands |
21/// +---+----------+
22/// | 1 | Mem      |
23/// +---+----------+
24/// ```
25pub trait FxrstorEmitter<A> {
26    fn fxrstor(&mut self, op0: A);
27}
28
29impl<'a> FxrstorEmitter<Mem> for Assembler<'a> {
30    fn fxrstor(&mut self, op0: Mem) {
31        self.emit(FXRSTOR32M, op0.as_operand(), &NOREG, &NOREG, &NOREG);
32    }
33}
34
35/// `FXSAVE` (FXSAVE). 
36/// Saves the current state of the x87 FPU, MMX technology, XMM, and MXCSR registers to a 512-byte memory location specified in the destination operand. The content layout of the 512 byte region depends on whether the processor is operating in non-64-bit operating modes or 64-bit sub-mode of IA-32e mode.
37///
38///
39/// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/FXSAVE.html).
40///
41/// Supported operand variants:
42///
43/// ```text
44/// +---+----------+
45/// | # | Operands |
46/// +---+----------+
47/// | 1 | Mem      |
48/// +---+----------+
49/// ```
50pub trait FxsaveEmitter<A> {
51    fn fxsave(&mut self, op0: A);
52}
53
54impl<'a> FxsaveEmitter<Mem> for Assembler<'a> {
55    fn fxsave(&mut self, op0: Mem) {
56        self.emit(FXSAVE32M, op0.as_operand(), &NOREG, &NOREG, &NOREG);
57    }
58}
59
60
61impl<'a> Assembler<'a> {
62    /// `FXRSTOR` (FXRSTOR). 
63    /// Reloads the x87 FPU, MMX technology, XMM, and MXCSR registers from the 512-byte memory image specified in the source operand. This data should have been written to memory previously using the FXSAVE instruction, and in the same format as required by the operating modes. The first byte of the data should be located on a 16-byte boundary. There are three distinct layouts of the FXSAVE state map: one for legacy and compatibility mode, a second format for 64-bit mode FXSAVE/FXRSTOR with REX.W=0, and the third format is for 64-bit mode with FXSAVE64/FXRSTOR64. Table 3-43 shows the layout of the legacy/compatibility mode state information in memory and describes the fields in the memory image for the FXRSTOR and FXSAVE instructions. Table 3-46 shows the layout of the 64-bit mode state information when REX.W is set (FXSAVE64/FXRSTOR64). Table 3-47 shows the layout of the 64-bit mode state information when REX.W is clear (FXSAVE/FXRSTOR).
64    ///
65    ///
66    /// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/FXRSTOR.html).
67    ///
68    /// Supported operand variants:
69    ///
70    /// ```text
71    /// +---+----------+
72    /// | # | Operands |
73    /// +---+----------+
74    /// | 1 | Mem      |
75    /// +---+----------+
76    /// ```
77    #[inline]
78    pub fn fxrstor<A>(&mut self, op0: A)
79    where Assembler<'a>: FxrstorEmitter<A> {
80        <Self as FxrstorEmitter<A>>::fxrstor(self, op0);
81    }
82    /// `FXSAVE` (FXSAVE). 
83    /// Saves the current state of the x87 FPU, MMX technology, XMM, and MXCSR registers to a 512-byte memory location specified in the destination operand. The content layout of the 512 byte region depends on whether the processor is operating in non-64-bit operating modes or 64-bit sub-mode of IA-32e mode.
84    ///
85    ///
86    /// For more details, see the [Intel manual](https://www.felixcloutier.com/x86/FXSAVE.html).
87    ///
88    /// Supported operand variants:
89    ///
90    /// ```text
91    /// +---+----------+
92    /// | # | Operands |
93    /// +---+----------+
94    /// | 1 | Mem      |
95    /// +---+----------+
96    /// ```
97    #[inline]
98    pub fn fxsave<A>(&mut self, op0: A)
99    where Assembler<'a>: FxsaveEmitter<A> {
100        <Self as FxsaveEmitter<A>>::fxsave(self, op0);
101    }
102}