Skip to content

Commit cd704d4

Browse files
committed
add a bootstrap variant of naked_asm
1 parent f50b2ba commit cd704d4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

core/src/arch.rs

+34
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#[allow(unused_imports)]
44
#[stable(feature = "simd_arch", since = "1.27.0")]
55
pub use crate::core_arch::arch::*;
6+
#[unstable(feature = "naked_functions", issue = "90957")]
7+
#[cfg(bootstrap)]
8+
pub use crate::naked_asm;
69

710
/// Inline assembly.
811
///
@@ -17,6 +20,37 @@ pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
1720
/* compiler built-in */
1821
}
1922

23+
/// Inline assembly used in combination with `#[naked]` functions.
24+
///
25+
/// Refer to [Rust By Example] for a usage guide and the [reference] for
26+
/// detailed information about the syntax and available options.
27+
///
28+
/// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
29+
/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
30+
#[unstable(feature = "naked_functions", issue = "90957")]
31+
#[macro_export]
32+
#[cfg(bootstrap)]
33+
macro_rules! naked_asm {
34+
([$last:expr], [$($pushed:expr),*]) => {
35+
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
36+
{
37+
core::arch::asm!($($pushed),*, options(att_syntax, noreturn))
38+
}
39+
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
40+
{
41+
core::arch::asm!($($pushed),* , $last, options(noreturn))
42+
}
43+
};
44+
45+
([$first:expr $(, $rest:expr)*], [$($pushed:expr),*]) => {
46+
naked_asm!([$($rest),*], [$($pushed,)* $first]);
47+
};
48+
49+
($($expr:expr),* $(,)?) => {
50+
naked_asm!([$($expr),*], []);
51+
};
52+
}
53+
2054
/// Inline assembly used in combination with `#[naked]` functions.
2155
///
2256
/// Refer to [Rust By Example] for a usage guide and the [reference] for

0 commit comments

Comments
 (0)