aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-semihosting/src/export.rs
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2020-10-13 23:32:15 +0000
committerGravatar GitHub <noreply@github.com> 2020-10-13 23:32:15 +0000
commit432e5f527430394570d1d07454e26cc41d5b2936 (patch)
treed3cde25a18eabfc5f0342dbf2d31ab767f21bab9 /cortex-m-semihosting/src/export.rs
parentf77d64a2d1505335e4a170d03a40993bb066fd02 (diff)
parentb51178fae6373d8dae95f2fb661e0635359e8bc0 (diff)
downloadcortex-m-432e5f527430394570d1d07454e26cc41d5b2936.tar.gz
cortex-m-432e5f527430394570d1d07454e26cc41d5b2936.tar.zst
cortex-m-432e5f527430394570d1d07454e26cc41d5b2936.zip
263: Import cortex-m-semihosting and panic-semihosting into this repo r=adamgreig a=jonas-schievink Motivation: * Allows writing QEMU tests for `cortex-m`'s functionality that use semihosting to control QEMU. Previously these crates would pull in another cortex-m version, which doesn't work. Now they have a `path` dependency on the root crate. * Lets us share the outline-inline-assembly setup and `cargo-xtask` in general. * Lets us share CI and bot setup between more crates. * 2 fewer repos to triage and keep track of (I'll transfer their issues after this is merged). I also want to import cortex-m-rt, but I'll do that in a later PR. CI was updated to build-test all crates with all or most feature combinations, like it did before. Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Diffstat (limited to 'cortex-m-semihosting/src/export.rs')
-rw-r--r--cortex-m-semihosting/src/export.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/cortex-m-semihosting/src/export.rs b/cortex-m-semihosting/src/export.rs
new file mode 100644
index 0000000..c188ab0
--- /dev/null
+++ b/cortex-m-semihosting/src/export.rs
@@ -0,0 +1,51 @@
+//! IMPLEMENTATION DETAILS USED BY MACROS
+
+use core::fmt::{self, Write};
+
+use cortex_m::interrupt;
+
+use crate::hio::{self, HStderr, HStdout};
+
+static mut HSTDOUT: Option<HStdout> = None;
+
+pub fn hstdout_str(s: &str) {
+ let _result = interrupt::free(|_| unsafe {
+ if HSTDOUT.is_none() {
+ HSTDOUT = Some(hio::hstdout()?);
+ }
+
+ HSTDOUT.as_mut().unwrap().write_str(s).map_err(drop)
+ });
+}
+
+pub fn hstdout_fmt(args: fmt::Arguments) {
+ let _result = interrupt::free(|_| unsafe {
+ if HSTDOUT.is_none() {
+ HSTDOUT = Some(hio::hstdout()?);
+ }
+
+ HSTDOUT.as_mut().unwrap().write_fmt(args).map_err(drop)
+ });
+}
+
+static mut HSTDERR: Option<HStderr> = None;
+
+pub fn hstderr_str(s: &str) {
+ let _result = interrupt::free(|_| unsafe {
+ if HSTDERR.is_none() {
+ HSTDERR = Some(hio::hstderr()?);
+ }
+
+ HSTDERR.as_mut().unwrap().write_str(s).map_err(drop)
+ });
+}
+
+pub fn hstderr_fmt(args: fmt::Arguments) {
+ let _result = interrupt::free(|_| unsafe {
+ if HSTDERR.is_none() {
+ HSTDERR = Some(hio::hstderr()?);
+ }
+
+ HSTDERR.as_mut().unwrap().write_fmt(args).map_err(drop)
+ });
+}