1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Common utility functions for working with RISC-V processors.

#![cfg_attr(feature = "std", allow(dead_code, unreachable_code))]

use core::cell::UnsafeCell;

extern "C" {
    static STACK_POINTER: UnsafeCell<usize>;
}

/// Initializes the Stack Pointer.
///
/// # Safety
///
/// This function reverts the state of the Stack Pointer.
pub unsafe fn stack_pointer_init() {
    #[cfg(feature = "std")]
    return unimplemented!();
    #[cfg(not(feature = "std"))]
    unsafe {
        asm!("mv sp, {}", in(reg) STACK_POINTER.get() as usize);
    }
}

/// Waits for interrupt.
///
/// This instruction provides a hint that the current HART can be stalled until
/// an interrupt might need servicing.
#[inline]
pub fn wait_for_int() {
    #[cfg(feature = "std")]
    return unimplemented!();
    #[cfg(not(feature = "std"))]
    unsafe {
        asm!("wfi", options(nomem, nostack, preserves_flags));
    }
}