Skip to content

Commit 343382c

Browse files
committed
Add test case for proper placement of hard fault handler and trampoline
1 parent 99b5e89 commit 343382c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! This is not an example; this is a linker test that ensures
2+
//! that the jump from HardFault to _HardFault doesn't exceed
3+
//! the 2kB limit of the branch instruction.
4+
5+
#![deny(warnings)]
6+
#![no_main]
7+
#![no_std]
8+
9+
extern crate cortex_m_rt;
10+
extern crate panic_halt;
11+
12+
use core::arch::asm;
13+
use cortex_m_rt::{entry, exception, ExceptionFrame};
14+
15+
// This defines both `HardFault` and `_HardFault`. Both should have
16+
// link_section attributes placing them at the end of the .text section,
17+
// close to each other. If one of them is missing that attribute, they
18+
// will end up separated by `foo`, which will make the linker fail.
19+
#[exception(trampoline=true)]
20+
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
21+
loop {}
22+
}
23+
24+
#[entry]
25+
fn foo() -> ! {
26+
unsafe {
27+
// 2kB of NOP instructions to make the function artificially larger
28+
asm!(
29+
".fill 1024,2,0xbf00",
30+
);
31+
}
32+
loop {}
33+
}
34+

0 commit comments

Comments
 (0)