File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! `i386/ia32` intrinsics
2
+
3
+ /// Reads EFLAGS.
4
+ #[ cfg( target_arch = "x86" ) ]
5
+ #[ inline( always) ]
6
+ pub unsafe fn __readeflags ( ) -> u32 {
7
+ let eflags: u32 ;
8
+ asm ! ( "pushfd; popl $0" : "=r" ( eflags) : : : "volatile" ) ;
9
+ eflags
10
+ }
11
+
12
+ /// Reads EFLAGS.
13
+ #[ cfg( target_arch = "x86_64" ) ]
14
+ #[ inline( always) ]
15
+ pub unsafe fn __readeflags ( ) -> u64 {
16
+ let eflags: u64 ;
17
+ asm ! ( "pushfq; popq $0" : "=r" ( eflags) : : : "volatile" ) ;
18
+ eflags
19
+ }
20
+
21
+ /// Write EFLAGS.
22
+ #[ cfg( target_arch = "x86" ) ]
23
+ #[ inline( always) ]
24
+ pub unsafe fn __writeeflags ( eflags : u32 ) {
25
+ asm ! ( "pushl $0; popfd" : : "r" ( eflags) : "cc" , "flags" : "volatile" ) ;
26
+ }
27
+
28
+ /// Write EFLAGS.
29
+ #[ cfg( target_arch = "x86_64" ) ]
30
+ #[ inline( always) ]
31
+ pub unsafe fn __writeeflags ( eflags : u64 ) {
32
+ asm ! ( "pushq $0; popfq" : : "r" ( eflags) : "cc" , "flags" : "volatile" ) ;
33
+ }
34
+
35
+ #[ cfg( test) ]
36
+ mod tests {
37
+ use super :: * ;
38
+
39
+ #[ test]
40
+ fn test_eflags ( ) {
41
+ unsafe {
42
+ // reads eflags, writes them back, reads them again,
43
+ // and compare for equality:
44
+ let v = __readeflags ( ) ;
45
+ __writeeflags ( v) ;
46
+ let u = __readeflags ( ) ;
47
+ assert_eq ! ( v, u) ;
48
+ }
49
+ }
50
+ }
Original file line number Diff line number Diff line change 1
1
//! `x86` and `x86_64` intrinsics.
2
2
3
+ pub use self :: ia32:: * ;
3
4
pub use self :: xsave:: * ;
4
5
5
6
pub use self :: sse:: * ;
@@ -31,6 +32,7 @@ mod macros;
31
32
mod runtime;
32
33
33
34
mod xsave;
35
+ mod ia32;
34
36
35
37
mod sse;
36
38
mod sse2;
You can’t perform that action at this time.
0 commit comments