|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
|
pub unsafe fn disable_and_store() -> usize {
|
|
|
|
|
let rflags: usize;
|
|
|
|
|
asm!("pushfq; popq $0; cli" : "=r"(rflags));
|
|
|
|
|
asm!("pushfq; popq $0; cli" : "=r"(rflags) ::: "volatile");
|
|
|
|
|
rflags & (1 << 9)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -10,20 +10,20 @@ pub unsafe fn disable_and_store() -> usize {
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
|
pub unsafe fn restore(flags: usize) {
|
|
|
|
|
if flags != 0 {
|
|
|
|
|
asm!("sti");
|
|
|
|
|
asm!("sti" :::: "volatile");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
|
|
|
|
|
pub unsafe fn disable_and_store() -> usize {
|
|
|
|
|
if option_env!("m_mode").is_some() {
|
|
|
|
|
if env!("M_MODE") == "1" {
|
|
|
|
|
let mstatus: usize;
|
|
|
|
|
asm!("csrci mstatus, 1 << 3" : "=r"(mstatus));
|
|
|
|
|
asm!("csrci mstatus, 1 << 3" : "=r"(mstatus) ::: "volatile");
|
|
|
|
|
mstatus & (1 << 3)
|
|
|
|
|
} else {
|
|
|
|
|
let sstatus: usize;
|
|
|
|
|
asm!("csrci sstatus, 1 << 1" : "=r"(sstatus));
|
|
|
|
|
asm!("csrci sstatus, 1 << 1" : "=r"(sstatus) ::: "volatile");
|
|
|
|
|
sstatus & (1 << 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -31,10 +31,10 @@ pub unsafe fn disable_and_store() -> usize {
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
|
|
|
|
|
pub unsafe fn restore(flags: usize) {
|
|
|
|
|
if option_env!("m_mode").is_some() {
|
|
|
|
|
asm!("csrs mstatus, $0" :: "r"(flags));
|
|
|
|
|
if env!("M_MODE") == "1" {
|
|
|
|
|
asm!("csrs mstatus, $0" :: "r"(flags) :: "volatile");
|
|
|
|
|
} else {
|
|
|
|
|
asm!("csrs sstatus, $0" :: "r"(flags));
|
|
|
|
|
asm!("csrs sstatus, $0" :: "r"(flags) :: "volatile");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -42,8 +42,7 @@ pub unsafe fn restore(flags: usize) {
|
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
|
pub unsafe fn disable_and_store() -> usize {
|
|
|
|
|
let daif: u32;
|
|
|
|
|
asm!("mrs $0, DAIF": "=r"(daif) ::: "volatile");
|
|
|
|
|
asm!("msr daifset, #2");
|
|
|
|
|
asm!("mrs $0, DAIF; msr daifset, #2": "=r"(daif) ::: "volatile");
|
|
|
|
|
daif as usize
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|