Remove asm and interrupt modules
This commit is contained in:
parent
9bf5caafc2
commit
b4546d1827
24
asm.S
24
asm.S
|
@ -40,31 +40,7 @@ __clear_ ## name: \
|
||||||
#define RW32(offset, name)
|
#define RW32(offset, name)
|
||||||
#define RO32(offset, name)
|
#define RO32(offset, name)
|
||||||
#endif
|
#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
|
// User Trap Setup
|
||||||
RW(0x000, ustatus) // User status register
|
RW(0x000, ustatus) // User status register
|
||||||
|
|
77
src/asm.rs
77
src/asm.rs
|
@ -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!(),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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, R>(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
|
|
||||||
}
|
|
|
@ -21,6 +21,4 @@
|
||||||
extern crate bare_metal;
|
extern crate bare_metal;
|
||||||
extern crate bit_field;
|
extern crate bit_field;
|
||||||
|
|
||||||
pub mod asm;
|
|
||||||
pub mod interrupt;
|
|
||||||
pub mod register;
|
pub mod register;
|
||||||
|
|
Loading…
Reference in New Issue