aarch64_cpu/
asm.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//
3// Copyright (c) 2018-2023 by the author(s)
4//
5// Author(s):
6//   - Jorge Aparicio
7//   - Andre Richter <andre.o.richter@gmail.com>
8
9//! Wrappers around ARMv8-A instructions.
10
11pub mod barrier;
12pub mod random;
13
14/// The classic no-op
15#[inline(always)]
16pub fn nop() {
17    #[cfg(target_arch = "aarch64")]
18    unsafe {
19        core::arch::asm!("nop", options(nomem, nostack))
20    }
21
22    #[cfg(not(target_arch = "aarch64"))]
23    unimplemented!()
24}
25
26/// Wait For Interrupt
27///
28/// For more details on wfi, refer to [here](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0802a/CIHEGBBF.html).
29#[inline(always)]
30pub fn wfi() {
31    #[cfg(target_arch = "aarch64")]
32    unsafe {
33        core::arch::asm!("wfi", options(nomem, nostack))
34    }
35
36    #[cfg(not(target_arch = "aarch64"))]
37    unimplemented!()
38}
39
40/// Wait For Event
41///
42/// For more details of wfe - sev pair, refer to [here](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0802a/CIHEGBBF.html).
43#[inline(always)]
44pub fn wfe() {
45    #[cfg(target_arch = "aarch64")]
46    unsafe {
47        core::arch::asm!("wfe", options(nomem, nostack))
48    }
49
50    #[cfg(not(target_arch = "aarch64"))]
51    unimplemented!()
52}
53
54/// Send EVent.Locally
55///
56/// SEV causes an event to be signaled to the local core within a multiprocessor system.
57///
58/// For more details of wfe - sev/sevl pair, refer to [here](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0802a/CIHEGBBF.html).
59#[inline(always)]
60pub fn sevl() {
61    #[cfg(target_arch = "aarch64")]
62    unsafe {
63        core::arch::asm!("sevl", options(nomem, nostack))
64    }
65
66    #[cfg(not(target_arch = "aarch64"))]
67    unimplemented!()
68}
69
70/// Send EVent.
71///
72/// SEV causes an event to be signaled to all cores within a multiprocessor system.
73///
74/// For more details of wfe - sev pair, refer to [here](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0802a/CIHEGBBF.html).
75#[inline(always)]
76pub fn sev() {
77    #[cfg(target_arch = "aarch64")]
78    unsafe {
79        core::arch::asm!("sev", options(nomem, nostack))
80    }
81
82    #[cfg(not(target_arch = "aarch64"))]
83    unimplemented!()
84}
85
86/// Exception return
87///
88/// Will jump to wherever the corresponding link register points to, and therefore never return.
89#[inline(always)]
90pub fn eret() -> ! {
91    #[cfg(target_arch = "aarch64")]
92    unsafe {
93        core::arch::asm!("eret", options(nomem, nostack));
94        core::hint::unreachable_unchecked()
95    }
96
97    #[cfg(not(target_arch = "aarch64"))]
98    unimplemented!()
99}
100
101/// Function return
102///
103/// Will jump to wherever the corresponding link register points to, and therefore never return.
104#[inline(always)]
105pub fn ret() -> ! {
106    #[cfg(target_arch = "aarch64")]
107    unsafe {
108        core::arch::asm!("ret", options(nomem, nostack));
109        core::hint::unreachable_unchecked()
110    }
111
112    #[cfg(not(target_arch = "aarch64"))]
113    unimplemented!()
114}