interrupts/imp/x86_64.rs
1use core::arch::asm;
2
3pub type Flags = bool;
4
5#[inline]
6pub fn read_disable() -> Flags {
7 let rflags: u64;
8
9 unsafe {
10 asm!(
11 "pushfq",
12 "pop {}",
13 "cli",
14 out(reg) rflags,
15 // Omit `nomem` to imitate a lock acquire.
16 // Otherwise, the compiler is free to move
17 // reads and writes through this asm block.
18 options(preserves_flags)
19 );
20 }
21
22 const INTERRUPT_FLAG: u64 = 1 << 9;
23
24 (rflags & INTERRUPT_FLAG) == INTERRUPT_FLAG
25}
26
27#[inline]
28pub fn restore(enable: Flags) {
29 if enable {
30 unsafe {
31 asm!(
32 "sti",
33 // Omit `nomem` to imitate a lock acquire.
34 // Otherwise, the compiler is free to move
35 // reads and writes through this asm block.
36 options(preserves_flags)
37 );
38 }
39 }
40}