about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2024-09-13 14:56:29 +0200
committerFolkert de Vries <folkert@folkertdev.nl>2024-09-26 09:54:00 +0200
commit20c0067528a6b303fe99a753f3afa3703ebc1a68 (patch)
treebf70fe2b6674c3d6236af19462da6c50745d29b6
parent76ed7a1fa40c3f54d3fd3f834e12bf9c932d0146 (diff)
downloadrust-20c0067528a6b303fe99a753f3afa3703ebc1a68.tar.gz
rust-20c0067528a6b303fe99a753f3afa3703ebc1a68.zip
add a bootstrap variant of `naked_asm`
-rw-r--r--library/core/src/arch.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/library/core/src/arch.rs b/library/core/src/arch.rs
index be734d194be..4945c045bc6 100644
--- a/library/core/src/arch.rs
+++ b/library/core/src/arch.rs
@@ -3,6 +3,9 @@
 #[allow(unused_imports)]
 #[stable(feature = "simd_arch", since = "1.27.0")]
 pub use crate::core_arch::arch::*;
+#[unstable(feature = "naked_functions", issue = "90957")]
+#[cfg(bootstrap)]
+pub use crate::naked_asm;
 
 /// Inline assembly.
 ///
@@ -25,6 +28,37 @@ pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
 /// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
 /// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
 #[unstable(feature = "naked_functions", issue = "90957")]
+#[macro_export]
+#[cfg(bootstrap)]
+macro_rules! naked_asm {
+    ([$last:expr], [$($pushed:expr),*]) => {
+        #[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
+        {
+            core::arch::asm!($($pushed),*, options(att_syntax, noreturn))
+        }
+        #[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))]
+        {
+            core::arch::asm!($($pushed),* , $last, options(noreturn))
+        }
+    };
+
+    ([$first:expr $(, $rest:expr)*], [$($pushed:expr),*]) => {
+        naked_asm!([$($rest),*], [$($pushed,)* $first]);
+    };
+
+    ($($expr:expr),* $(,)?) => {
+        naked_asm!([$($expr),*], []);
+    };
+}
+
+/// Inline assembly used in combination with `#[naked]` functions.
+///
+/// Refer to [Rust By Example] for a usage guide and the [reference] for
+/// detailed information about the syntax and available options.
+///
+/// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
+/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
+#[unstable(feature = "naked_functions", issue = "90957")]
 #[rustc_builtin_macro]
 #[cfg(not(bootstrap))]
 pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?) {