From b4546d1827aad0c423499b80031a3ea557f0433b Mon Sep 17 00:00:00 2001 From: Vadim Kaushan Date: Sun, 14 Jun 2020 14:17:55 +0300 Subject: [PATCH] Remove asm and interrupt modules --- asm.S | 24 --------------- src/asm.rs | 77 ------------------------------------------------ src/interrupt.rs | 54 --------------------------------- src/lib.rs | 2 -- 4 files changed, 157 deletions(-) delete mode 100644 src/asm.rs delete mode 100644 src/interrupt.rs diff --git a/asm.S b/asm.S index e42d90c..373f704 100644 --- a/asm.S +++ b/asm.S @@ -40,31 +40,7 @@ __clear_ ## name: \ #define RW32(offset, name) #define RO32(offset, name) #endif -// ----------------------- // -.section .text.__ebreak -.global __ebreak -__ebreak: - ebreak - ret - -.section .text.__wfi -.global __wfi -__wfi: - wfi - ret - -.section .text.__sfence_vma_all -.global __sfence_vma_all -__sfence_vma_all: - sfence.vma - ret - -.section .text.__sfence_vma -.global __sfence_vma -__sfence_vma: - sfence.vma a0, a1 - ret // User Trap Setup RW(0x000, ustatus) // User status register diff --git a/src/asm.rs b/src/asm.rs deleted file mode 100644 index 8ce24b7..0000000 --- a/src/asm.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! Assembly instructions - -macro_rules! instruction { - ($(#[$attr:meta])*, $fnname:ident, $asm:expr, $asm_fn:ident) => ( - $(#[$attr])* - #[inline] - pub unsafe fn $fnname() { - match () { - #[cfg(all(riscv, feature = "inline-asm"))] - () => asm!($asm :::: "volatile"), - - #[cfg(all(riscv, not(feature = "inline-asm")))] - () => { - extern "C" { - fn $asm_fn(); - } - - $asm_fn(); - } - - #[cfg(not(riscv))] - () => unimplemented!(), - } - } - ) -} - - -instruction!( - /// `EBREAK` instruction wrapper - /// - /// Generates a breakpoint exception. - , ebreak, "ebreak", __ebreak); -instruction!( - /// `WFI` instruction wrapper - /// - /// Provides a hint to the implementation that the current hart can be stalled until an interrupt might need servicing. - /// The WFI instruction is just a hint, and a legal implementation is to implement WFI as a NOP. - , wfi, "wfi", __wfi); -instruction!( - /// `SFENCE.VMA` instruction wrapper (all address spaces and page table levels) - /// - /// Synchronizes updates to in-memory memory-management data structures with current execution. - /// Instruction execution causes implicit reads and writes to these data structures; however, these implicit references - /// are ordinarily not ordered with respect to loads and stores in the instruction stream. - /// Executing an `SFENCE.VMA` instruction guarantees that any stores in the instruction stream prior to the - /// `SFENCE.VMA` are ordered before all implicit references subsequent to the `SFENCE.VMA`. - , sfence_vma_all, "sfence.vma", __sfence_vma_all); - - -/// `SFENCE.VMA` instruction wrapper -/// -/// Synchronizes updates to in-memory memory-management data structures with current execution. -/// Instruction execution causes implicit reads and writes to these data structures; however, these implicit references -/// are ordinarily not ordered with respect to loads and stores in the instruction stream. -/// Executing an `SFENCE.VMA` instruction guarantees that any stores in the instruction stream prior to the -/// `SFENCE.VMA` are ordered before all implicit references subsequent to the `SFENCE.VMA`. -#[inline] -#[allow(unused_variables)] -pub unsafe fn sfence_vma(asid: usize, addr: usize) { - match () { - #[cfg(all(riscv, feature = "inline-asm"))] - () => asm!("sfence.vma $0, $1" :: "r"(asid), "r"(addr) :: "volatile"), - - #[cfg(all(riscv, not(feature = "inline-asm")))] - () => { - extern "C" { - fn __sfence_vma(asid: usize, addr: usize); - } - - __sfence_vma(asid, addr); - } - - #[cfg(not(riscv))] - () => unimplemented!(), - } -} diff --git a/src/interrupt.rs b/src/interrupt.rs deleted file mode 100644 index b569e11..0000000 --- a/src/interrupt.rs +++ /dev/null @@ -1,54 +0,0 @@ -//! Interrupts - -// NOTE: Adapted from cortex-m/src/interrupt.rs -pub use bare_metal::{CriticalSection, Mutex, Nr}; -use register::mstatus; - -/// Disables all interrupts -#[inline] -pub unsafe fn disable() { - match () { - #[cfg(riscv)] - () => mstatus::clear_mie(), - #[cfg(not(riscv))] - () => unimplemented!(), - } -} - -/// Enables all the interrupts -/// -/// # Safety -/// -/// - Do not call this function inside an `interrupt::free` critical section -#[inline] -pub unsafe fn enable() { - match () { - #[cfg(riscv)] - () => mstatus::set_mie(), - #[cfg(not(riscv))] - () => unimplemented!(), - } -} - -/// Execute closure `f` in an interrupt-free context. -/// -/// This as also known as a "critical section". -pub fn free(f: F) -> R -where - F: FnOnce(&CriticalSection) -> R, -{ - let mstatus = mstatus::read(); - - // disable interrupts - unsafe { disable(); } - - let r = f(unsafe { &CriticalSection::new() }); - - // If the interrupts were active before our `disable` call, then re-enable - // them. Otherwise, keep them disabled - if mstatus.mie() { - unsafe { enable(); } - } - - r -} diff --git a/src/lib.rs b/src/lib.rs index af24199..bae037b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,4 @@ extern crate bare_metal; extern crate bit_field; -pub mod asm; -pub mod interrupt; pub mod register;