Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit f45f7d2

Browse files
committed
make sure main is not inlined into reset_handler when enabling the FPU
1 parent faba13d commit f45f7d2

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/lib.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,34 @@ unsafe extern "C" fn reset_handler() -> ! {
189189
r0::init_data(&mut _sdata, &mut _edata, &_sidata);
190190

191191
match () {
192+
#[cfg(not(has_fpu))]
193+
() => {
194+
// Neither `argc` or `argv` make sense in bare metal context so we just
195+
// stub them
196+
main(0, ::core::ptr::null());
197+
}
192198
#[cfg(has_fpu)]
193199
() => {
194200
// NOTE(safe) no exception / interrupt that also accesses the FPU
195201
// can occur here
196202
let scb = &*cortex_m::peripheral::SCB.get();
197203
scb.enable_fpu();
204+
205+
// Make sure the user main function never gets inlined into this
206+
// function as that may cause FPU related instructions like vpush to
207+
// be executed *before* enabling the FPU and that would generate an
208+
// exception
209+
#[inline(never)]
210+
fn main() {
211+
unsafe {
212+
::main(0, ::core::ptr::null());
213+
}
214+
}
215+
216+
main()
198217
}
199-
#[cfg(not(has_fpu))]
200-
() => {}
201218
}
202219

203-
// Neither `argc` or `argv` make sense in bare metal context so we just
204-
// stub them
205-
main(0, ::core::ptr::null());
206-
207220
// If `main` returns, then we go into "reactive" mode and simply attend
208221
// interrupts as they occur.
209222
loop {

0 commit comments

Comments
 (0)