xref: /openbmc/qemu/tests/tcg/arm/semicall.h (revision 4e6b1384)
1 /*
2  * Semihosting Tests
3  *
4  * Copyright (c) 2019
5  * Written by Alex Bennée <alex.bennee@linaro.org>
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  */
9 
10 #define SYS_WRITE0      0x04
11 #define SYS_READC       0x07
12 #define SYS_REPORTEXC   0x18
13 
14 uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
15 {
16 #if defined(__arm__)
17     register uintptr_t t asm("r0") = type;
18     register uintptr_t a0 asm("r1") = arg0;
19 #ifdef __thumb__
20 #  define SVC  "svc 0xab"
21 #else
22 #  define SVC  "svc 0x123456"
23 #endif
24     asm(SVC : "=r" (t)
25         : "r" (t), "r" (a0));
26 #else
27     register uintptr_t t asm("x0") = type;
28     register uintptr_t a0 asm("x1") = arg0;
29     asm("hlt 0xf000"
30         : "=r" (t)
31         : "r" (t), "r" (a0));
32 #endif
33 
34     return t;
35 }
36