Skip to content

Conversation

@thejpster
Copy link
Contributor

Rust has this weird quirk where #[inline] functions are not compiled until they are used. Which means any inline-assembly code inside them isn't checked for correctness unless a function is used. For a library exporting a bunch of thin wrappers around inline-assembly, this is an issue.

This PR adds a feature to cortex-ar called check-asm, and if set, it disables the #[inline] attribute, forcing the functions to be checked.

Currently (and by default), we can build this for ARMv4T:

$ cargo +nightly build --target=armv4t-none-eabi -Zbuild-std                     
   Compiling cortex-ar v0.3.0 (/home/jonathan/Documents/github/rust-embedded/cortex-ar-patches/cortex-ar)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.45s

However, with this new feature, we see that a bunch of the barrier instructions are not available on that architecture:

$ cargo +nightly build --target=armv4t-none-eabi -Zbuild-std  --features=check-asm
   Compiling cortex-ar v0.3.0 (/home/jonathan/Documents/github/rust-embedded/cortex-ar-patches/cortex-ar)
error: instruction requires: data-barriers
  --> cortex-ar/src/asm.rs:14:27
   |
14 |         core::arch::asm!("dmb", options(nostack, preserves_flags));
   |                           ^^^
   |
note: instantiated into assembly here
  --> <inline asm>:1:2
   |
 1 |     dmb
   |     ^

error: instruction requires: data-barriers
  --> cortex-ar/src/asm.rs:30:27
   |
30 |         core::arch::asm!("dsb", options(nostack, preserves_flags));
   |                           ^^^
   |
note: instantiated into assembly here
  --> <inline asm>:1:2
   |
 1 |     dsb
   |     ^

error: instruction requires: data-barriers
  --> cortex-ar/src/asm.rs:43:27
   |
43 |         core::arch::asm!("isb", options(nostack, preserves_flags));
   |                           ^^^
   |
note: instantiated into assembly here
  --> <inline asm>:1:2
   |
 1 |     isb
   |     ^

error: could not compile `cortex-ar` (lib) due to 3 previous errors

Allows us to check functions that aren't used (but are 'pub' so other
people might use them).
@jonathanpallant
Copy link
Contributor

Ah, I think #67 broke things and we didn't notice.

Treat all BARs as u32 values - the user can cast to a pointer if they
wish. Resolves issues with serialising values containing pointers.
@thejpster
Copy link
Contributor Author

You should take this commit-by-commit because the last one is just a huge number of blank lines I added because they were missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants