diff options
| author | Tianhao Wang <shrik3@mailbox.org> | 2024-06-11 15:07:40 +0200 |
|---|---|---|
| committer | Tianhao Wang <shrik3@mailbox.org> | 2024-06-11 15:17:15 +0200 |
| commit | bed59f00a63e89abf1f82a6b10d5e8a493d54788 (patch) | |
| tree | 3f4b6d2c1c35267fdf004d9e1934db387f874b09 /src/arch/x86_64/interrupt/mod.rs | |
| parent | 49fc3b6df25bea2aaccbe2b26735204e3ee4b809 (diff) | |
interrupt: add irq_save/restore helpers
Signed-off-by: Tianhao Wang <shrik3@mailbox.org>
Diffstat (limited to 'src/arch/x86_64/interrupt/mod.rs')
| -rw-r--r-- | src/arch/x86_64/interrupt/mod.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/arch/x86_64/interrupt/mod.rs b/src/arch/x86_64/interrupt/mod.rs index ed08223..a3d9f89 100644 --- a/src/arch/x86_64/interrupt/mod.rs +++ b/src/arch/x86_64/interrupt/mod.rs @@ -1,6 +1,7 @@ pub mod pic_8259; pub mod pit; use crate::arch::x86_64::arch_regs::TrapFrame; +use crate::arch::x86_64::is_int_enabled; use crate::arch::x86_64::paging::fault; use crate::io::*; use core::arch::asm; @@ -103,6 +104,27 @@ pub fn interrupt_disable() { } } +#[inline] +/// irq_save() disables all interrupts and returns the previous state +pub fn irq_save() -> bool { + if is_int_enabled() { + interrupt_disable(); + return true; + } else { + return false; + } +} + +#[inline] +/// irq_restore only re-enable irq if was_enabled==true. +/// it will not disable irq regardless the was_enabled value. This function +/// should only be called to restore irq based on previous irq_save(); +pub fn irq_restore(was_enabled: bool) { + if was_enabled { + interrupt_enable(); + } +} + #[inline(always)] fn _idt_init() { println!("[init] idt: vectors_start: 0x{:x}", vectors_start as usize); |
