Conversation
0fe3a7c to
2abb7dd
Compare
ec6c7ef to
667de8f
Compare
b9cb8b5 to
74e91d2
Compare
The `cm7-r0p1` feature only works with the plateform feature `armv7em`. I added a compile error to help someone figure that out more redily if they accidentally combine those features.
This will allow getting all the asm in shape for edition 2024.
9cad22a to
256dc0f
Compare
|
Had a quick look on my phone - looks ok, just a few notes. I want to inspect the symbol table later when I get to a laptop. |
e7d07d2 to
29ef316
Compare
|
I removed the change to the clippy runs since I added the mock so that it can be run without issue with clippy targeting x86. |
|
If you want me to add that change to the tests back in for clippy I can. It was not really related to this change, so I didn't want to add more complexity. |
cortex-m/src/asm/inner.rs
Outdated
| use core::sync::atomic::{Ordering, compiler_fence}; | ||
|
|
||
| #[inline(always)] | ||
| pub unsafe fn __bkpt() { |
There was a problem hiding this comment.
These need marking with #[unsafe(no_mangle)] to ensure they have the same symbol as the old asm functions.
Perhaps like:
#[unsafe(link_section = ".text.__function_name_goes_here")]
#[cfg(not(feature = "inline-asm", unsafe(no_mangle)))]
#[inline(always)]
pub unsafe fn __bkpt() {
// inline asm goes here
}That way, anyone who has written code like the following example will still find their code works when not using inline-asm:
extern "C" {
fn __wfi();
}
unsafe {
__wfi();
}And anyone who is using inline-asm will find the following still works:
#[unsafe(no_mangle)]
pub extern "C" fn __wfi() {
// do stuff
}There was a problem hiding this comment.
OK, nah, we talked about this on Matrix and the __foo functions are not part of the public API - that's what the __ prefix means. So it's OK for the functions to be renamed.
There was a problem hiding this comment.
In fact you could remove the __ prefixes from all these functions (and the mock functions). It adds no value and suggests a backwards compatibility that isn't actually present.
There was a problem hiding this comment.
K. I'll remove those __'s.
| #[inline] | ||
| pub fn disable() { | ||
| call_asm!(__cpsid()); | ||
| unsafe { crate::asm::inner::__cpsid() }; |
There was a problem hiding this comment.
We should probably call the public api when we can
There was a problem hiding this comment.
This is the public API for turning interrupts on and off - cpsie and cpsid are not exposed as individual functions.
| #[inline] | ||
| pub unsafe fn enable() { | ||
| call_asm!(__cpsie()); | ||
| unsafe { crate::asm::inner::__cpsie() }; |
|
Since we are considering double underscored functions to be internal only, can I also get rid of this? The links keys have long been an proper way to do what this is trying to do. |
Maybe? But I wouldn't do it in this PR. |
We should get rid of this eventually, but it has to be handled carefully because the whole point is to prevent linking multiple versions of cortex-m-rt, and old versions don't have the |
Inline asm has been supported in stable rust for some time, so I removed the separate asm build infra and added that code to the normal crate code. I also crated a mock of the asm functions that were needed to run clippy with a non-arm target (like x86_64).
fd3ccb5 to
edb22b0
Compare
|
@thejpster @jonathanpallant @adamgreig Reviewers, please double check the new crate (in cortex-m/macros). I'm assuming that the cortex-m crate using the new crate will need to be updated to use an actual version once it is published. Can we just publish the new crate once this is landed so that I can make a PR to depend on the published version? |
edb22b0 to
e53eba0
Compare
|
You can depend on a version and a path at the same time. |
Can I depend on a path in a published crate, like "cortex-m"? |
|
As long as you have both. It uses the path if valid, and falls back to the version if not. |
The purpose of this attribute is to allow platforms that do not support the asm instructions to compile code code that calls those functions. This is needed so that clippy can be run once in CI and when testing locally.
e53eba0 to
63bee36
Compare
|
I have updated the dep spec for the new crate to include the version number. I use an exact version like the |
| @@ -0,0 +1,57 @@ | |||
| //! Internal implementation details of `cortex-m-rt`. | |||
There was a problem hiding this comment.
| //! Internal implementation details of `cortex-m-rt`. | |
| //! Internal implementation details of `cortex-m`. |
| @@ -2,17 +2,22 @@ | |||
|
|
|||
| // When inline assembly is enabled, pull in the assembly routines here. `call_asm!` will invoke | |||
There was a problem hiding this comment.
call_asm! doesn't exist any more
|
|
||
| /// A no-operation. Useful to prevent delay loops from being optimized away. | ||
| #[inline] | ||
| #[cortex_m_macros::asm_wrapper(any(armv6m, armv7m, armv7em, armv8m))] |
There was a problem hiding this comment.
Most of the public functions (in asm.rs) don't need #[asm_wrapper] on them, because they call inner functions which are wrapped with #[asm_wrapper]. So, even on non-cortex-m platforms, these functions will still compile.
| call_asm!(__sh_syscall(nr: u32, arg: u32) -> u32) | ||
| let mut nr = nr; | ||
| unsafe { | ||
| asm!("bkpt #0xab", inout("r0") nr, in("r1") arg, options(nomem, nostack, preserves_flags)) |
There was a problem hiding this comment.
I would move this inline assembly to the asm::inner module.
| #[inline] | ||
| pub fn disable() { | ||
| call_asm!(__cpsid()); | ||
| unsafe { crate::asm::inner::__cpsid() }; |
There was a problem hiding this comment.
This is the public API for turning interrupts on and off - cpsie and cpsid are not exposed as individual functions.
|
|
||
| // Should this be safe? | ||
| #[inline(always)] | ||
| pub unsafe fn __enable_icache() { |
There was a problem hiding this comment.
The asm::inner functions should not start with __. That's just a hold-over from assembly code not having the concept of public/private symbols.
This is a draft for updating the asm toolchain. It's based on my #628, so it shouldn't be landed before that is.