#![no_std]
#[doc(inline)]
pub use naked_function_macro::naked;
cfg_if::cfg_if! {
if #[cfg(all(target_arch = "arm", is_thumb))] {
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_arch_prefix {
() => { ".thumb\n.thumb_func" };
(arm::a32) => { ".arm" };
(arm::t32) => { ".thumb\n.thumb_func" };
($isa:path) => { compile_error!("invalid instruction set") };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_arch_suffix {
() => { ".thumb" };
}
} else if #[cfg(all(target_arch = "arm", not(is_thumb)))] {
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_arch_prefix {
() => { ".arm" };
(arm::a32) => { ".arm" };
(arm::t32) => { ".thumb\n.thumb_func" };
($isa:path) => { compile_error!("invalid instruction set") };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_arch_suffix {
() => { ".arm" };
}
} else {
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_arch_prefix {
() => { "" };
($isa:path) => { compile_error!("invalid instruction set") };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_arch_suffix {
() => { "" };
}
}
}
cfg_if::cfg_if! {
if #[cfg(any(
target_vendor = "apple",
all(windows, target_arch = "x86"),
))] {
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_mangle {
($symbol:expr) => { concat!("_", $symbol) };
}
} else {
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_mangle {
($symbol:expr) => { $symbol };
}
}
}
cfg_if::cfg_if! {
if #[cfg(windows)] {
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_function_begin {
($symbol:expr, $section:expr, ($($instruction_set:tt)*)) => {
concat!(
".pushsection ", $section, ",\"xr\"\n",
".balign 4\n",
".globl ", $crate::__asm_mangle!($symbol), "\n",
".def ", $crate::__asm_mangle!($symbol), "\n",
".scl 2\n",
".type 32\n",
".endef ", $crate::__asm_mangle!($symbol), "\n",
$crate::__asm_arch_prefix!($($instruction_set)*), "\n",
$crate::__asm_mangle!($symbol), ":\n",
)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_function_end {
($symbol:expr) => {
concat!(
".popsection\n",
$crate::__asm_arch_suffix!(), "\n",
)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_default_section {
($symbol:expr) => { concat!(".text.", $symbol) };
}
} else if #[cfg(target_vendor = "apple")] {
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_function_begin {
($symbol:expr, $section:expr, ($($instruction_set:tt)*)) => {
concat!(
".pushsection ", $section, ",regular,pure_instructions\n",
".balign 4\n",
".globl ", $crate::__asm_mangle!($symbol), "\n",
".private_extern ", $crate::__asm_mangle!($symbol), "\n",
$crate::__asm_arch_prefix!($($instruction_set)*), "\n",
$crate::__asm_mangle!($symbol), ":\n",
)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_function_end {
($symbol:expr) => {
concat!(
".popsection\n",
$crate::__asm_arch_suffix!(), "\n",
)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_default_section {
($symbol:expr) => { "__TEXT,__text" };
}
} else {
#[cfg(not(target_arch = "arm"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_type {
($ty:literal) => { concat!("@", $ty) }
}
#[cfg(target_arch = "arm")]
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_type {
($ty:literal) => { concat!("%", $ty) }
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_function_begin {
($symbol:expr, $section:expr, ($($instruction_set:tt)*)) => {
concat!(
".pushsection ", $section, ",\"ax\", ", $crate::__asm_type!("progbits"), "\n",
".balign 4\n",
".globl ", $crate::__asm_mangle!($symbol), "\n",
".hidden ", $crate::__asm_mangle!($symbol), "\n",
".type ", $crate::__asm_mangle!($symbol), ", ", $crate::__asm_type!("function"), "\n",
$crate::__asm_arch_prefix!($($instruction_set)*), "\n",
$crate::__asm_mangle!($symbol), ":\n",
)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_function_end {
($symbol:expr) => {
concat!(
".size ", $crate::__asm_mangle!($symbol), ", . - ", $crate::__asm_mangle!($symbol), "\n",
".popsection\n",
$crate::__asm_arch_suffix!(), "\n",
)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __asm_default_section {
($symbol:expr) => { concat!(".text.", $symbol) };
}
}
}