1 /*
2  * Semihosting Console Test
3  *
4  * Copyright (c) 2019 Linaro Ltd
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include <stdint.h>
10 #include <minilib.h>
11 
12 #define SYS_READC 0x7
13 
14 uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
15 {
16     register uintptr_t t asm("x0") = type;
17     register uintptr_t a0 asm("x1") = arg0;
18     asm("hlt 0xf000"
19         : "=r" (t)
20         : "r" (t), "r" (a0));
21 
22     return t;
23 }
24 
25 int main(void)
26 {
27     char c;
28 
29     ml_printf("Semihosting Console Test\n");
30     ml_printf("hit X to exit:");
31 
32     do {
33         c = __semi_call(SYS_READC, 0);
34         __sys_outc(c);
35     } while (c != 'X');
36 
37     return 0;
38 }
39