-
Notifications
You must be signed in to change notification settings - Fork 186
Implement coprocessor access instructions #531
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
Open
spcan
wants to merge
14
commits into
rust-embedded:master
Choose a base branch
from
spcan:coprocessor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−0
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0cd442d
feat: Add coprocessor access
spcan defd5cf
feat: Add feature gate to coprocessor access
spcan f04b8b6
feat: Add coprocessor access to all cortex-m excep ARMV6
spcan 7b3bc97
fix: Change pub(crate) to pub
spcan df5e0b5
doc: Remove compilation gaurantee
spcan 3139b37
fix: Remove feature gate
spcan ce42e2b
Merge branch 'master' of https://github.com/spcan/cortex-m into copro…
spcan 3de3250
feat: Update documentation, formatting
spcan 41b3882
fix: Unsafe at function level, refmt
spcan 4ab167f
Merge branch 'rust-embedded:master' into coprocessor
spcan 2f6baef
fix: Format, clippy
spcan e3ebba5
fix: Rerun cargo fmt after clippy, I really need to make a hook for this
spcan 8bd9668
fix: Add asm_cfg to all coprocessor instructions
spcan ef09ed2
fmt: Set inline before asm_cfg
spcan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| //! Coprocessor access assembly instructions. | ||
|
|
||
| use cortex_m_macros::asm_cfg; | ||
|
|
||
| /// This instruction moves one Register to a Coprocessor Register. | ||
| /// This function generates inline assembly and needs the instruction configuration | ||
| /// during compilation time (i.e. as `const`). | ||
| /// The values of the constants required by this function should be defined by | ||
| /// the coprocessor's reference manual. | ||
| /// - CP: The coprocessor's index. | ||
| /// - OP1: First optional operation for the coprocessor. | ||
| /// - CRN: Coprocessor register N. | ||
| /// - CRM: Coprocessor register M. | ||
| /// - OP2: Second optional operation for the coprocessor. | ||
| #[inline(always)] | ||
| #[asm_cfg(any(armv7m, armv8m))] | ||
| pub unsafe 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}", | ||
| in(reg) value, | ||
| cp = const CP, | ||
| op1 = const OP1, | ||
| crn = const CRN, | ||
| crm = const CRM, | ||
| op2 = const OP2, | ||
| options(nostack, nomem) | ||
| ) | ||
| }; | ||
| } | ||
|
|
||
| /// This instruction moves one Coprocessor Register to a Register. | ||
| /// This function generates inline assembly and needs the instruction configuration | ||
| /// during compilation time (i.e. as `const`). | ||
| /// The values of the constants required by this function should be defined by | ||
| /// the coprocessor's reference manual. | ||
| /// - CP: The coprocessor's index. | ||
| /// - OP1: First optional operation for the coprocessor. | ||
| /// - CRN: Coprocessor register N. | ||
| /// - CRM: Coprocessor register M. | ||
| /// - OP2: Second optional operation for the coprocessor. | ||
| #[inline(always)] | ||
| #[asm_cfg(any(armv7m, armv8m))] | ||
| pub unsafe fn mrc<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const OP2: u32>() | ||
| -> u32 { | ||
| let a: u32; | ||
|
|
||
| unsafe { | ||
| core::arch::asm!( | ||
| "MRC p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}", | ||
| out(reg) a, | ||
| cp = const CP, | ||
| op1 = const OP1, | ||
| crn = const CRN, | ||
| crm = const CRM, | ||
| op2 = const OP2, | ||
| options(nostack, nomem) | ||
| ) | ||
| }; | ||
|
|
||
| a | ||
| } | ||
|
|
||
| /// This instruction moves two Registers to Coprocessor Registers. | ||
| /// This function generates inline assembly and needs the instruction configuration | ||
| /// during compilation time (i.e. as `const`). | ||
| /// The values of the constants required by this function should be defined by | ||
| /// the coprocessor's reference manual. | ||
| /// - CP: The coprocessor's index. | ||
| /// - OP1: First optional operation for the coprocessor. | ||
| /// - CRM: Coprocessor register M. | ||
| #[inline(always)] | ||
| #[asm_cfg(any(armv7m, armv8m))] | ||
| pub unsafe 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}", | ||
| in(reg) a, | ||
| in(reg) b, | ||
| cp = const CP, | ||
| op1 = const OP1, | ||
| crm = const CRM, | ||
| options(nostack, nomem) | ||
| ) | ||
| }; | ||
| } | ||
|
|
||
| /// This instruction moves two Coprocessor Registers to Registers. | ||
| /// This function generates inline assembly and needs the instruction configuration | ||
| /// during compilation time (i.e. as `const`). | ||
| /// The values of the constants required by this function should be defined by | ||
| /// the coprocessor's reference manual. | ||
| /// - CP: The coprocessor's index. | ||
| /// - OP1: First optional operation for the coprocessor. | ||
| /// - CRM: Coprocessor register M. | ||
| #[inline(always)] | ||
| #[asm_cfg(any(armv7m, armv8m))] | ||
| pub unsafe 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}", | ||
| out(reg) a, | ||
| out(reg) b, | ||
| cp = const CP, | ||
| opc = const OPC, | ||
| crm = const CRM, | ||
| options(nostack, nomem) | ||
| ) | ||
| }; | ||
|
|
||
| (a, b) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.