From 424136f1792dc0c0feb4ffcc15fc830aef2fd93e Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 7 Jul 2013 20:46:16 +0200 Subject: Add basic semihosting support. --- util/semihosting.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 util/semihosting.h 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 + +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 -- cgit v1.2.3