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("r0") = type; 17 register uintptr_t a0 asm("r1") = arg0; 18 #ifdef __thumb__ 19 # define SVC "svc 0xab" 20 #else 21 # define SVC "svc 0x123456" 22 #endif 23 asm(SVC : "=r" (t) 24 : "r" (t), "r" (a0)); 25 26 return t; 27 } 28 29 int main(void) 30 { 31 char c; 32 33 ml_printf("Semihosting Console Test\n"); 34 ml_printf("hit X to exit:"); 35 36 do { 37 c = __semi_call(SYS_READC, 0); 38 __sys_outc(c); 39 } while (c != 'X'); 40 41 return 0; 42 } 43