summaryrefslogtreecommitdiff
path: root/util/semihosting.h
blob: 8d91737cb4db9a02adbd8ed82ed8d349266e9a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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