summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2013-07-07 20:46:16 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2013-07-07 20:46:16 +0200
commit424136f1792dc0c0feb4ffcc15fc830aef2fd93e (patch)
tree38afdaa3566caad180c2a0253506b8b4859f4cb2 /util
parentb5206743e61de16ce5acad6ef508862bc1017d96 (diff)
Add basic semihosting support.
Diffstat (limited to 'util')
-rw-r--r--util/semihosting.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/util/semihosting.h b/util/semihosting.h
new file mode 100644
index 0000000..8d91737
--- /dev/null
+++ b/util/semihosting.h
@@ -0,0 +1,23 @@
+#ifndef SEMIHOSTING_H
+#define SEMIHOSTING_H
+
+#include <stdint.h>
+
+inline uint32_t semihosting_call(uint32_t num, const uint32_t* args = nullptr) {
+ register uint32_t a asm("r0") = num;
+ register uint32_t b asm("r1") = (uint32_t)args;
+
+ asm volatile("bkpt 0xab" : "=r"(a) : "0"(a), "r"(b) : "memory");
+
+ return a;
+}
+
+inline void semihosting_print(const void *buf) {
+ semihosting_call(0x04, (const uint32_t*)buf);
+}
+
+inline void semihosting_exit() {
+ semihosting_call(0x18);
+}
+
+#endif