mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-24 21:33:27 +00:00
匿名管道重构&增加IrqArch trait以及IrqFlags及其守卫 (#253)
* 实现匿名管道 * 增加IrqArch trait以及IrqFlags及其守卫 --------- Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -1,5 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
use core::arch::asm;
|
||||
use core::{
|
||||
arch::asm,
|
||||
sync::atomic::{compiler_fence, Ordering},
|
||||
};
|
||||
|
||||
use crate::exception::{InterruptArch, IrqFlags, IrqFlagsGuard};
|
||||
|
||||
use super::asm::irqflags::{local_irq_restore, local_irq_save};
|
||||
|
||||
/// @brief 关闭中断
|
||||
#[inline]
|
||||
@ -16,3 +23,39 @@ pub fn sti() {
|
||||
asm!("sti");
|
||||
}
|
||||
}
|
||||
|
||||
pub struct X86_64InterruptArch;
|
||||
|
||||
impl InterruptArch for X86_64InterruptArch {
|
||||
unsafe fn interrupt_enable() {
|
||||
sti();
|
||||
}
|
||||
|
||||
unsafe fn interrupt_disable() {
|
||||
cli();
|
||||
}
|
||||
|
||||
fn is_irq_enabled() -> bool {
|
||||
let rflags: u64;
|
||||
unsafe {
|
||||
asm!("pushfq; pop {}", out(reg) rflags);
|
||||
}
|
||||
return rflags & (1 << 9) != 0;
|
||||
}
|
||||
|
||||
unsafe fn save_and_disable_irq() -> IrqFlagsGuard {
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
let mut rflags: u64 = 0;
|
||||
local_irq_save(&mut rflags);
|
||||
let flags = IrqFlags::new(rflags);
|
||||
let guard = IrqFlagsGuard::new(flags);
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
return guard;
|
||||
}
|
||||
|
||||
unsafe fn restore_irq(flags: IrqFlags) {
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
local_irq_restore(&flags.flags());
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user