Skip to content

Commit 3b184ea

Browse files
committed
asm.bootstrap: only set CONTROL.SPSEL, mark as divergent
1 parent 3a3a812 commit 3b184ea

17 files changed

+30
-20
lines changed

asm/inline.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,23 @@ pub unsafe fn __sh_syscall(mut nr: u32, arg: u32) -> u32 {
182182
nr
183183
}
184184

185-
/// Bootstrap: ensure we are using the main stack, then write `msp` to MSP and jump to `rv`.
185+
/// Set CONTROL.SPSEL to 0, write `msp` to MSP, branch to `rv`.
186186
#[inline(always)]
187-
pub unsafe fn __bootstrap(msp: u32, rv: u32) {
187+
pub unsafe fn __bootstrap(msp: u32, rv: u32) -> ! {
188188
asm!(
189-
"msr CONTROL, {}",
189+
"mrs {tmp}, CONTROL",
190+
"bics {tmp}, {spsel}",
191+
"msr CONTROL, {tmp}",
190192
"isb",
191-
"msr MSP, {}",
192-
"bx {}",
193-
in(reg) 0,
194-
in(reg) msp,
195-
in(reg) rv,
193+
"msr MSP, {msp}",
194+
"bx {rv}",
195+
// `out(reg) _` is not permitted in a `noreturn` asm! call,
196+
// so instead use `in(reg) 0` and don't restore it afterwards.
197+
tmp = in(reg) 0,
198+
spsel = in(reg) 2,
199+
msp = in(reg) msp,
200+
rv = in(reg) rv,
201+
options(noreturn),
196202
);
197203
}
198204

asm/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ shims! {
6969
fn __psp_r() -> u32;
7070
fn __psp_w(val: u32);
7171
fn __sev();
72-
fn __udf();
72+
fn __udf() -> !;
7373
fn __wfe();
7474
fn __wfi();
7575
fn __sh_syscall(nr: u32, arg: u32) -> u32;
76-
fn __bootstrap(msp: u32, rv: u32);
76+
fn __bootstrap(msp: u32, rv: u32) -> !;
7777
}
7878

7979
// v7m *AND* v8m.main, but *NOT* v8m.base

bin/thumbv6m-none-eabi-lto.a

68 Bytes
Binary file not shown.

bin/thumbv6m-none-eabi.a

40 Bytes
Binary file not shown.

bin/thumbv7em-none-eabi-lto.a

12 Bytes
Binary file not shown.

bin/thumbv7em-none-eabi.a

56 Bytes
Binary file not shown.

bin/thumbv7em-none-eabihf-lto.a

-28 Bytes
Binary file not shown.

bin/thumbv7em-none-eabihf.a

56 Bytes
Binary file not shown.

bin/thumbv7m-none-eabi-lto.a

52 Bytes
Binary file not shown.

bin/thumbv7m-none-eabi.a

56 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)