Skip to content

Commit f77d64a

Browse files
bors[bot]hug-dev
andauthored
Merge #268
268: Add some Armv8-M assembly routines r=jonas-schievink a=hug-dev Adds access to `MSP_NS` and the `BXNS` instruction. Also adds `__dsb` which was missing. Executed `cargo xtask assemble` and pushed everything, I hope that's enough. Co-authored-by: Hugues de Valon <hugues.devalon@arm.com>
2 parents 43b9383 + 7102bd4 commit f77d64a

18 files changed

+49
-0
lines changed

asm/inline.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,23 @@ mod v8m {
308308
asm!("ttat {target}, {target}", target = inout(reg) target);
309309
target
310310
}
311+
312+
#[inline(always)]
313+
pub unsafe fn __msp_ns_r() -> u32 {
314+
let r;
315+
asm!("mrs {}, MSP_NS", out(reg) r);
316+
r
317+
}
318+
319+
#[inline(always)]
320+
pub unsafe fn __msp_ns_w(val: u32) {
321+
asm!("msr MSP_NS, {}", in(reg) val);
322+
}
323+
324+
#[inline(always)]
325+
pub unsafe fn __bxns(val: u32) {
326+
asm!("BXNS {}", in(reg) val);
327+
}
311328
}
312329

313330
#[cfg(armv8m_main)]

asm/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ shims! {
6060
fn __cpsie();
6161
fn __delay(cyc: u32);
6262
fn __dmb();
63+
fn __dsb();
6364
fn __isb();
6465
fn __msp_r() -> u32;
6566
fn __msp_w(val: u32);
@@ -97,6 +98,9 @@ shims! {
9798
fn __ttt(target: u32) -> u32;
9899
fn __tta(target: u32) -> u32;
99100
fn __ttat(target: u32) -> u32;
101+
fn __msp_ns_r() -> u32;
102+
fn __msp_ns_w(val: u32);
103+
fn __bxns(val: u32);
100104
}
101105

102106
// Mainline only.

bin/thumbv6m-none-eabi-lto.a

348 Bytes
Binary file not shown.

bin/thumbv6m-none-eabi.a

444 Bytes
Binary file not shown.

bin/thumbv7em-none-eabi-lto.a

348 Bytes
Binary file not shown.

bin/thumbv7em-none-eabi.a

448 Bytes
Binary file not shown.

bin/thumbv7em-none-eabihf-lto.a

352 Bytes
Binary file not shown.

bin/thumbv7em-none-eabihf.a

448 Bytes
Binary file not shown.

bin/thumbv7m-none-eabi-lto.a

336 Bytes
Binary file not shown.

bin/thumbv7m-none-eabi.a

444 Bytes
Binary file not shown.

bin/thumbv8m.base-none-eabi-lto.a

1.61 KB
Binary file not shown.

bin/thumbv8m.base-none-eabi.a

1.9 KB
Binary file not shown.

bin/thumbv8m.main-none-eabi-lto.a

1.58 KB
Binary file not shown.

bin/thumbv8m.main-none-eabi.a

1.89 KB
Binary file not shown.

bin/thumbv8m.main-none-eabihf-lto.a

1.59 KB
Binary file not shown.

bin/thumbv8m.main-none-eabihf.a

1.89 KB
Binary file not shown.

src/asm.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,13 @@ pub fn ttat(addr: *mut u32) -> u32 {
154154
let addr = addr as u32;
155155
call_asm!(__ttat(addr: u32) -> u32)
156156
}
157+
158+
/// Branch and Exchange Non-secure
159+
///
160+
/// See section C2.4.26 of Armv8-M Architecture Reference Manual for details.
161+
/// Undefined if executed in Non-Secure state.
162+
#[inline]
163+
#[cfg(armv8m)]
164+
pub unsafe fn bx_ns(addr: u32) {
165+
call_asm!(__bxns(addr: u32));
166+
}

src/register/msp.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,21 @@ pub fn read() -> u32 {
1111
pub unsafe fn write(bits: u32) {
1212
call_asm!(__msp_w(bits: u32));
1313
}
14+
15+
/// Reads the Non-Secure CPU register from Secure state.
16+
///
17+
/// Executing this function in Non-Secure state will return zeroes.
18+
#[cfg(armv8m)]
19+
#[inline]
20+
pub fn read_ns() -> u32 {
21+
call_asm!(__msp_ns_r() -> u32)
22+
}
23+
24+
/// Writes `bits` to the Non-Secure CPU register from Secure state.
25+
///
26+
/// Executing this function in Non-Secure state will be ignored.
27+
#[cfg(armv8m)]
28+
#[inline]
29+
pub unsafe fn write_ns(bits: u32) {
30+
call_asm!(__msp_ns_w(bits: u32));
31+
}

0 commit comments

Comments
 (0)