aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt/examples/qemu.rs
diff options
context:
space:
mode:
authorGravatar Hideki Sekine <sekineh@me.com> 2018-09-19 10:17:29 +0900
committerGravatar Hideki Sekine <sekineh@me.com> 2018-09-19 10:17:29 +0900
commit87771282d1b87d1a1b40e18f9c8f829ad01a6e7f (patch)
treed4b7484129b2b6e24d232b6c0d25bd0dcf9c8449 /cortex-m-rt/examples/qemu.rs
parente7904c0754ad6970fe5923cceeb0595322ff899f (diff)
downloadcortex-m-87771282d1b87d1a1b40e18f9c8f829ad01a6e7f.tar.gz
cortex-m-87771282d1b87d1a1b40e18f9c8f829ad01a6e7f.tar.zst
cortex-m-87771282d1b87d1a1b40e18f9c8f829ad01a6e7f.zip
[rust/ci/qemu] main for qemu run.
- taken from japaric/lm3s6965evb
Diffstat (limited to 'cortex-m-rt/examples/qemu.rs')
-rw-r--r--cortex-m-rt/examples/qemu.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/cortex-m-rt/examples/qemu.rs b/cortex-m-rt/examples/qemu.rs
new file mode 100644
index 0000000..f3850d5
--- /dev/null
+++ b/cortex-m-rt/examples/qemu.rs
@@ -0,0 +1,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) {}