Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement coprocessor access instructions #531

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions cortex-m/src/coprocessor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//! Coprocessor access assembly instructions.



/// Internal function to create an inlined MCR instruction.
/// This instruction moves one Register to a Coprocessor Register.
#[inline(always)]
pub fn mcr<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const OP2: u32>(value: u32) {
unsafe {
core::arch::asm!(
"MCR p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}",

Check warning on line 11 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

formatting may not be suitable for sub-register argument

warning: formatting may not be suitable for sub-register argument --> cortex-m/src/coprocessor.rs:11:33 | 11 | "MCR p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}", | ^^^ 12 | in(reg) value, | ----- for this argument | = help: use `{0:e}` to have the register formatted as `eax` = help: or use `{0:r}` to keep the default formatting of `rax` = note: `#[warn(asm_sub_register)]` on by default
in(reg) value,
cp = const CP,

Check failure on line 13 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:13:13 | 13 | cp = const CP, | ^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
op1 = const OP1,

Check failure on line 14 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:14:13 | 14 | op1 = const OP1, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
crn = const CRN,

Check failure on line 15 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:15:13 | 15 | crn = const CRN, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
crm = const CRM,

Check failure on line 16 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:16:13 | 16 | crm = const CRM, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
op2 = const OP2,

Check failure on line 17 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:17:13 | 17 | op2 = const OP2, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
options(nostack, nomem)
)
}
}



/// Internal function to create an inlined MRC instruction.
/// This instruction moves one Coprocessor Register to a Register.
#[inline(always)]
pub fn mrc<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const OP2: u32>() -> u32 {
// Preallocate the value.
let a: u32;

unsafe {
core::arch::asm!(
"MRC p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}",

Check warning on line 34 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

formatting may not be suitable for sub-register argument

warning: formatting may not be suitable for sub-register argument --> cortex-m/src/coprocessor.rs:34:33 | 34 | "MRC p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}", | ^^^ 35 | out(reg) a, | - for this argument | = help: use `{0:e}` to have the register formatted as `eax` = help: or use `{0:r}` to keep the default formatting of `rax`
out(reg) a,
cp = const CP,

Check failure on line 36 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:36:13 | 36 | cp = const CP, | ^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
op1 = const OP1,

Check failure on line 37 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:37:13 | 37 | op1 = const OP1, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
crn = const CRN,

Check failure on line 38 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:38:13 | 38 | crn = const CRN, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
crm = const CRM,

Check failure on line 39 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:39:13 | 39 | crm = const CRM, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
op2 = const OP2,

Check failure on line 40 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:40:13 | 40 | op2 = const OP2, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
options(nostack, nomem)
)
}

a
}



/// Internal function to create an inlined MCRR instruction.
/// This instruction moves two Registers to Coprocessor Registers.
#[inline(always)]
pub fn mcrr<const CP: u32, const OP1: u32, const CRM: u32>(a: u32, b: u32) {
unsafe {
core::arch::asm!(
"MCRR p{cp}, #{op1}, {0}, {1}, c{crm}",

Check warning on line 56 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

formatting may not be suitable for sub-register argument

warning: formatting may not be suitable for sub-register argument --> cortex-m/src/coprocessor.rs:56:39 | 56 | "MCRR p{cp}, #{op1}, {0}, {1}, c{crm}", | ^^^ 57 | in(reg) a, 58 | in(reg) b, | - for this argument | = help: use `{1:e}` to have the register formatted as `eax` = help: or use `{1:r}` to keep the default formatting of `rax`

Check warning on line 56 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

formatting may not be suitable for sub-register argument

warning: formatting may not be suitable for sub-register argument --> cortex-m/src/coprocessor.rs:56:34 | 56 | "MCRR p{cp}, #{op1}, {0}, {1}, c{crm}", | ^^^ 57 | in(reg) a, | - for this argument | = help: use `{0:e}` to have the register formatted as `eax` = help: or use `{0:r}` to keep the default formatting of `rax`
in(reg) a,
in(reg) b,
cp = const CP,

Check failure on line 59 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:59:13 | 59 | cp = const CP, | ^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
op1 = const OP1,

Check failure on line 60 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:60:13 | 60 | op1 = const OP1, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
crm = const CRM,

Check failure on line 61 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:61:13 | 61 | crm = const CRM, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
options(nostack, nomem)
)
}
}



/// Internal function to create an inlined MRRC instruction.
/// This instruction moves two Coprocessor Registers to Registers.
#[inline(always)]
pub fn mrrc<const CP: u32, const OPC: u32, const CRM: u32>() -> (u32, u32) {
// Preallocate the values.
let a: u32;
let b: u32;

unsafe {
core::arch::asm!(
"MRRC p{cp}, #{opc}, {0}, {1}, c{crm}",

Check warning on line 79 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

formatting may not be suitable for sub-register argument

warning: formatting may not be suitable for sub-register argument --> cortex-m/src/coprocessor.rs:79:39 | 79 | "MRRC p{cp}, #{opc}, {0}, {1}, c{crm}", | ^^^ 80 | out(reg) a, 81 | out(reg) b, | - for this argument | = help: use `{1:e}` to have the register formatted as `eax` = help: or use `{1:r}` to keep the default formatting of `rax`

Check warning on line 79 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

formatting may not be suitable for sub-register argument

warning: formatting may not be suitable for sub-register argument --> cortex-m/src/coprocessor.rs:79:34 | 79 | "MRRC p{cp}, #{opc}, {0}, {1}, c{crm}", | ^^^ 80 | out(reg) a, | - for this argument | = help: use `{0:e}` to have the register formatted as `eax` = help: or use `{0:r}` to keep the default formatting of `rax`
out(reg) a,
out(reg) b,
cp = const CP,

Check failure on line 82 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:82:13 | 82 | cp = const CP, | ^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
opc = const OPC,

Check failure on line 83 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:83:13 | 83 | opc = const OPC, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
crm = const CRM,

Check failure on line 84 in cortex-m/src/coprocessor.rs

View workflow job for this annotation

GitHub Actions / clippy

const operands for inline assembly are unstable

error[E0658]: const operands for inline assembly are unstable --> cortex-m/src/coprocessor.rs:84:13 | 84 | crm = const CRM, | ^^^^^^^^^^^^^^^ | = note: see issue #93332 <https://github.com/rust-lang/rust/issues/93332> for more information
options(nostack, nomem)
)
}

(a, b)
}
2 changes: 2 additions & 0 deletions cortex-m/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ mod macros;
pub mod asm;
#[cfg(armv8m)]
pub mod cmse;
#[cfg(not(armv6m))]
pub mod coprocessor;
pub mod delay;
pub mod interrupt;
#[cfg(all(not(armv6m), not(armv8m_base)))]
Expand Down
Loading