blob: f3850d5fcf3103d97ba9c0910bd81121b5b27381 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#![feature(stdsimd)]
#![no_main]
#![no_std]
extern crate cortex_m;
#[macro_use(entry, exception)]
extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as semihosting;
extern crate panic_abort;
extern crate unreachable;
use core::arch::arm;
use core::fmt::Write;
use rt::ExceptionFrame;
entry!(main);
fn main() -> ! {
let x = 42;
loop {
unsafe { arm::__NOP() }
// write something through semihosting interface
let mut hstdout = semihosting::hio::hstdout().unwrap();
write!(hstdout, "x = {}\n", x);
// exit from qemu
semihosting::debug::exit(semihosting::debug::EXIT_SUCCESS);
// hint to the optimizer that any code path which calls this function is statically unreachable
unsafe {
unreachable::unreachable();
}
}
}
// define the hard fault handler
exception!(HardFault, hard_fault);
#[inline(always)]
fn hard_fault(_ef: &ExceptionFrame) -> ! {
loop {
unsafe { arm::__NOP() }
}
}
// define the default exception handler
exception!(*, default_handler);
#[inline(always)]
fn default_handler(_irqn: i16) {}
|