aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86_64/mod.rs
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@mailbox.org>2024-06-11 15:07:40 +0200
committerTianhao Wang <shrik3@mailbox.org>2024-06-11 15:17:15 +0200
commitbed59f00a63e89abf1f82a6b10d5e8a493d54788 (patch)
tree3f4b6d2c1c35267fdf004d9e1934db387f874b09 /src/arch/x86_64/mod.rs
parent49fc3b6df25bea2aaccbe2b26735204e3ee4b809 (diff)
interrupt: add irq_save/restore helpers
Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
Diffstat (limited to 'src/arch/x86_64/mod.rs')
-rw-r--r--src/arch/x86_64/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs
index ee51338..38b08b1 100644
--- a/src/arch/x86_64/mod.rs
+++ b/src/arch/x86_64/mod.rs
@@ -4,3 +4,19 @@ pub mod io_port;
pub mod mem;
pub mod misc;
pub mod paging;
+use core::arch::asm;
+
+pub const RFLAGS_IF_MASK: u64 = 1 << 9;
+#[inline]
+pub fn read_rflags() -> u64 {
+ let rflags;
+ unsafe {
+ asm!("pushfq; popq {}", out(reg) rflags);
+ }
+ rflags
+}
+
+pub fn is_int_enabled() -> bool {
+ let rf = read_rflags();
+ return (rf & RFLAGS_IF_MASK) != 0;
+}