匿名管道重构&增加IrqArch trait以及IrqFlags及其守卫 (#253)

* 实现匿名管道

* 增加IrqArch trait以及IrqFlags及其守卫

---------

Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
hanjiezhou
2023-04-23 21:05:10 +08:00
committed by GitHub
parent 8a1e95abb5
commit f678331a33
14 changed files with 508 additions and 43 deletions

View File

@ -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);
}
}