From cc5bca8e83b4fe372d8d87b35d82ff466d1a290a Mon Sep 17 00:00:00 2001 From: Peter Krull Date: Sun, 23 Apr 2023 15:50:46 +0200 Subject: [PATCH 1/4] Added feature flag to embassy-rp intrinsics to avoid conflicts with rp2040-hal --- embassy-rp/src/intrinsics.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/embassy-rp/src/intrinsics.rs b/embassy-rp/src/intrinsics.rs index 3b63846d..50934e04 100644 --- a/embassy-rp/src/intrinsics.rs +++ b/embassy-rp/src/intrinsics.rs @@ -402,6 +402,7 @@ macro_rules! division_function { }; } +#[cfg(all(target_arch = "arm", feature = "intrinsics"))] division_function! { unsigned_divmod __aeabi_uidivmod __aeabi_uidiv ( u32 ) { "str r0, [r2, #0x060]", // DIV_UDIVIDEND @@ -409,6 +410,7 @@ division_function! { } } +#[cfg(all(target_arch = "arm", feature = "intrinsics"))] division_function! { signed_divmod __aeabi_idivmod __aeabi_idiv ( i32 ) { "str r0, [r2, #0x068]", // DIV_SDIVIDEND @@ -416,6 +418,7 @@ division_function! { } } +#[cfg(all(target_arch = "arm", feature = "intrinsics"))] fn divider_unsigned(n: u32, d: u32) -> DivResult { let packed = unsafe { unsigned_divmod(n, d) }; DivResult { @@ -424,6 +427,7 @@ fn divider_unsigned(n: u32, d: u32) -> DivResult { } } +#[cfg(all(target_arch = "arm", feature = "intrinsics"))] fn divider_signed(n: i32, d: i32) -> DivResult { let packed = unsafe { signed_divmod(n, d) }; // Double casts to avoid sign extension @@ -441,6 +445,7 @@ struct DivResult { pub remainder: T, } +#[cfg(all(target_arch = "arm", feature = "intrinsics"))] intrinsics! { extern "C" fn __udivsi3(n: u32, d: u32) -> u32 { divider_unsigned(n, d).quotient From 8285263fc2178be409beff217cb6af4562ea5107 Mon Sep 17 00:00:00 2001 From: Peter Krull Date: Sun, 23 Apr 2023 15:59:56 +0200 Subject: [PATCH 2/4] embassy-rp : Added intrinsic feature flag to global_asm macro --- embassy-rp/src/intrinsics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-rp/src/intrinsics.rs b/embassy-rp/src/intrinsics.rs index 50934e04..04da74cf 100644 --- a/embassy-rp/src/intrinsics.rs +++ b/embassy-rp/src/intrinsics.rs @@ -284,7 +284,7 @@ macro_rules! intrinsics { // alias the division operators to these for a similar reason r0 is the // result either way and r1 a scratch register, so the caller can't assume it // retains the argument value. -#[cfg(target_arch = "arm")] +#[cfg(all(target_arch = "arm", feature = "intrinsics"))] core::arch::global_asm!( ".macro hwdivider_head", "ldr r2, =(0xd0000000)", // SIO_BASE From ba47fe9c416818b7fff5bca8092d9f0265407089 Mon Sep 17 00:00:00 2001 From: Peter Krull Date: Sun, 23 Apr 2023 16:37:44 +0200 Subject: [PATCH 3/4] embassy-rp : Added feature flag to otherwise unused definitions --- embassy-rp/src/intrinsics.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/embassy-rp/src/intrinsics.rs b/embassy-rp/src/intrinsics.rs index 04da74cf..d5cb5fe9 100644 --- a/embassy-rp/src/intrinsics.rs +++ b/embassy-rp/src/intrinsics.rs @@ -284,7 +284,7 @@ macro_rules! intrinsics { // alias the division operators to these for a similar reason r0 is the // result either way and r1 a scratch register, so the caller can't assume it // retains the argument value. -#[cfg(all(target_arch = "arm", feature = "intrinsics"))] +#[cfg(target_arch = "arm")] core::arch::global_asm!( ".macro hwdivider_head", "ldr r2, =(0xd0000000)", // SIO_BASE @@ -352,6 +352,7 @@ core::arch::global_asm!( ".endm", ); +#[cfg(all(target_arch = "arm", feature = "intrinsics"))] macro_rules! division_function { ( $name:ident $($intrinsic:ident)* ( $argty:ty ) { @@ -438,6 +439,7 @@ fn divider_signed(n: i32, d: i32) -> DivResult { } /// Result of divide/modulo operation +#[cfg(all(target_arch = "arm", feature = "intrinsics"))] struct DivResult { /// The quotient of divide/modulo operation pub quotient: T, From b283f213d99c5bfb888f450270dca699ae096fca Mon Sep 17 00:00:00 2001 From: Peter Krull Date: Sun, 23 Apr 2023 19:05:32 +0200 Subject: [PATCH 4/4] embassy-rs : @pennae Fix division intrinsics naming clash with rp2040-hal --- embassy-rp/src/intrinsics.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/embassy-rp/src/intrinsics.rs b/embassy-rp/src/intrinsics.rs index d5cb5fe9..3baabb28 100644 --- a/embassy-rp/src/intrinsics.rs +++ b/embassy-rp/src/intrinsics.rs @@ -352,7 +352,6 @@ core::arch::global_asm!( ".endm", ); -#[cfg(all(target_arch = "arm", feature = "intrinsics"))] macro_rules! division_function { ( $name:ident $($intrinsic:ident)* ( $argty:ty ) { @@ -362,10 +361,11 @@ macro_rules! division_function { #[cfg(all(target_arch = "arm", feature = "intrinsics"))] core::arch::global_asm!( // Mangle the name slightly, since this is a global symbol. - concat!(".global _rphal_", stringify!($name)), - concat!(".type _rphal_", stringify!($name), ", %function"), + concat!(".section .text._erphal_", stringify!($name)), + concat!(".global _erphal_", stringify!($name)), + concat!(".type _erphal_", stringify!($name), ", %function"), ".align 2", - concat!("_rphal_", stringify!($name), ":"), + concat!("_erphal_", stringify!($name), ":"), $( concat!(".global ", stringify!($intrinsic)), concat!(".type ", stringify!($intrinsic), ", %function"), @@ -380,10 +380,11 @@ macro_rules! division_function { #[cfg(all(target_arch = "arm", not(feature = "intrinsics")))] core::arch::global_asm!( // Mangle the name slightly, since this is a global symbol. - concat!(".global _rphal_", stringify!($name)), - concat!(".type _rphal_", stringify!($name), ", %function"), + concat!(".section .text._erphal_", stringify!($name)), + concat!(".global _erphal_", stringify!($name)), + concat!(".type _erphal_", stringify!($name), ", %function"), ".align 2", - concat!("_rphal_", stringify!($name), ":"), + concat!("_erphal_", stringify!($name), ":"), "hwdivider_head", $($begin),+ , @@ -393,7 +394,7 @@ macro_rules! division_function { #[cfg(target_arch = "arm")] extern "aapcs" { // Connect a local name to global symbol above through FFI. - #[link_name = concat!("_rphal_", stringify!($name)) ] + #[link_name = concat!("_erphal_", stringify!($name)) ] fn $name(n: $argty, d: $argty) -> u64; } @@ -403,7 +404,6 @@ macro_rules! division_function { }; } -#[cfg(all(target_arch = "arm", feature = "intrinsics"))] division_function! { unsigned_divmod __aeabi_uidivmod __aeabi_uidiv ( u32 ) { "str r0, [r2, #0x060]", // DIV_UDIVIDEND @@ -411,7 +411,6 @@ division_function! { } } -#[cfg(all(target_arch = "arm", feature = "intrinsics"))] division_function! { signed_divmod __aeabi_idivmod __aeabi_idiv ( i32 ) { "str r0, [r2, #0x068]", // DIV_SDIVIDEND @@ -419,7 +418,6 @@ division_function! { } } -#[cfg(all(target_arch = "arm", feature = "intrinsics"))] fn divider_unsigned(n: u32, d: u32) -> DivResult { let packed = unsafe { unsigned_divmod(n, d) }; DivResult { @@ -428,7 +426,6 @@ fn divider_unsigned(n: u32, d: u32) -> DivResult { } } -#[cfg(all(target_arch = "arm", feature = "intrinsics"))] fn divider_signed(n: i32, d: i32) -> DivResult { let packed = unsafe { signed_divmod(n, d) }; // Double casts to avoid sign extension @@ -439,7 +436,6 @@ fn divider_signed(n: i32, d: i32) -> DivResult { } /// Result of divide/modulo operation -#[cfg(all(target_arch = "arm", feature = "intrinsics"))] struct DivResult { /// The quotient of divide/modulo operation pub quotient: T, @@ -447,7 +443,6 @@ struct DivResult { pub remainder: T, } -#[cfg(all(target_arch = "arm", feature = "intrinsics"))] intrinsics! { extern "C" fn __udivsi3(n: u32, d: u32) -> u32 { divider_unsigned(n, d).quotient