From 484dcb3650b71d846ef71c45d78afe6c5a9ff4e3 Mon Sep 17 00:00:00 2001 From: yfblock <321353225@qq.com> Date: Mon, 13 Jan 2025 19:41:18 +0800 Subject: [PATCH] feat: Support loongarch64 and fmt clippy --- .github/workflows/ci.yml | 2 +- src/arch/loongarch64.rs | 17 +++++++++++++++++ src/arch/mod.rs | 3 +++ src/lib.rs | 1 - 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/arch/loongarch64.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 531ddd1..2133a4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: rust-toolchain: [nightly] - targets: [x86_64-unknown-linux-gnu, x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat] + targets: [x86_64-unknown-linux-gnu, x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat, loongarch64-unknown-none-softfloat] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly diff --git a/src/arch/loongarch64.rs b/src/arch/loongarch64.rs new file mode 100644 index 0000000..742f4bc --- /dev/null +++ b/src/arch/loongarch64.rs @@ -0,0 +1,17 @@ +use core::arch::asm; + +#[inline] +pub fn local_irq_save_and_disable() -> usize { + let mut flags: usize = 0; + let ie_mask: usize = 1 << 2; + // clear the `IE` bit, and return the old CSR + unsafe { asm!("csrxchg {}, {}, 0x0", inout(reg)flags, in(reg) ie_mask) }; + flags & ie_mask +} + +#[inline] +pub fn local_irq_restore(flags: usize) { + // restore the `IE` bit + let mask: usize = 1 << 2; + unsafe { asm!("csrxchg {}, {}, 0x0", in(reg)flags, in(reg) mask) }; +} diff --git a/src/arch/mod.rs b/src/arch/mod.rs index 58928d8..56b5d69 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -10,5 +10,8 @@ cfg_if::cfg_if! { } else if #[cfg(target_arch = "aarch64")] { mod aarch64; pub use self::aarch64::*; + } else if #[cfg(target_arch = "loongarch64")] { + mod loongarch64; + pub use self::loongarch64::*; } } diff --git a/src/lib.rs b/src/lib.rs index 97e6a8b..591ad02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,6 @@ //! ``` #![no_std] -#![feature(asm_const)] mod arch;