Skip to content

Commit 41b3882

Browse files
committed
fix: Unsafe at function level, refmt
1 parent 3de3250 commit 41b3882

1 file changed

Lines changed: 43 additions & 50 deletions

File tree

cortex-m/src/coprocessor.rs

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@
1111
/// - CRM: Coprocessor register M.
1212
/// - OP2: Second optional operation for the coprocessor.
1313
#[inline(always)]
14-
pub fn mcr<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const OP2: u32>(
14+
pub unsafe fn mcr<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const OP2: u32>(
1515
value: u32,
1616
) {
17-
unsafe {
18-
core::arch::asm!(
19-
"MCR p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}",
20-
in(reg) value,
21-
cp = const CP,
22-
op1 = const OP1,
23-
crn = const CRN,
24-
crm = const CRM,
25-
op2 = const OP2,
26-
options(nostack, nomem)
27-
)
28-
}
17+
core::arch::asm!(
18+
"MCR p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}",
19+
in(reg) value,
20+
cp = const CP,
21+
op1 = const OP1,
22+
crn = const CRN,
23+
crm = const CRM,
24+
op2 = const OP2,
25+
options(nostack, nomem)
26+
);
2927
}
3028

3129
/// This instruction moves one Coprocessor Register to a Register.
@@ -39,21 +37,20 @@ pub fn mcr<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const
3937
/// - CRM: Coprocessor register M.
4038
/// - OP2: Second optional operation for the coprocessor.
4139
#[inline(always)]
42-
pub fn mrc<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const OP2: u32>() -> u32 {
40+
pub unsafe fn mrc<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const OP2: u32>(
41+
) -> u32 {
4342
let a: u32;
4443

45-
unsafe {
46-
core::arch::asm!(
47-
"MRC p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}",
48-
out(reg) a,
49-
cp = const CP,
50-
op1 = const OP1,
51-
crn = const CRN,
52-
crm = const CRM,
53-
op2 = const OP2,
54-
options(nostack, nomem)
55-
)
56-
}
44+
core::arch::asm!(
45+
"MRC p{cp}, #{op1}, {0}, c{crn}, c{crm}, #{op2}",
46+
out(reg) a,
47+
cp = const CP,
48+
op1 = const OP1,
49+
crn = const CRN,
50+
crm = const CRM,
51+
op2 = const OP2,
52+
options(nostack, nomem)
53+
);
5754

5855
a
5956
}
@@ -67,18 +64,16 @@ pub fn mrc<const CP: u32, const OP1: u32, const CRN: u32, const CRM: u32, const
6764
/// - OP1: First optional operation for the coprocessor.
6865
/// - CRM: Coprocessor register M.
6966
#[inline(always)]
70-
pub fn mcrr<const CP: u32, const OP1: u32, const CRM: u32>(a: u32, b: u32) {
71-
unsafe {
72-
core::arch::asm!(
73-
"MCRR p{cp}, #{op1}, {0}, {1}, c{crm}",
74-
in(reg) a,
75-
in(reg) b,
76-
cp = const CP,
77-
op1 = const OP1,
78-
crm = const CRM,
79-
options(nostack, nomem)
80-
)
81-
}
67+
pub unsafe fn mcrr<const CP: u32, const OP1: u32, const CRM: u32>(a: u32, b: u32) {
68+
core::arch::asm!(
69+
"MCRR p{cp}, #{op1}, {0}, {1}, c{crm}",
70+
in(reg) a,
71+
in(reg) b,
72+
cp = const CP,
73+
op1 = const OP1,
74+
crm = const CRM,
75+
options(nostack, nomem)
76+
);
8277
}
8378

8479
/// This instruction moves two Coprocessor Registers to Registers.
@@ -90,22 +85,20 @@ pub fn mcrr<const CP: u32, const OP1: u32, const CRM: u32>(a: u32, b: u32) {
9085
/// - OP1: First optional operation for the coprocessor.
9186
/// - CRM: Coprocessor register M.
9287
#[inline(always)]
93-
pub fn mrrc<const CP: u32, const OPC: u32, const CRM: u32>() -> (u32, u32) {
88+
pub unsafe fn mrrc<const CP: u32, const OPC: u32, const CRM: u32>() -> (u32, u32) {
9489
// Preallocate the values.
9590
let a: u32;
9691
let b: u32;
9792

98-
unsafe {
99-
core::arch::asm!(
100-
"MRRC p{cp}, #{opc}, {0}, {1}, c{crm}",
101-
out(reg) a,
102-
out(reg) b,
103-
cp = const CP,
104-
opc = const OPC,
105-
crm = const CRM,
106-
options(nostack, nomem)
107-
)
108-
}
93+
core::arch::asm!(
94+
"MRRC p{cp}, #{opc}, {0}, {1}, c{crm}",
95+
out(reg) a,
96+
out(reg) b,
97+
cp = const CP,
98+
opc = const OPC,
99+
crm = const CRM,
100+
options(nostack, nomem)
101+
);
109102

110103
(a, b)
111104
}

0 commit comments

Comments
 (0)