1 /*
2  * Copyright (c) 2019 LuoZhongYao
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #include <zephyr/kernel.h>
7 #include <zephyr/device.h>
8 #include <zephyr/init.h>
9 #include <zephyr/arch/common/semihost.h>
10 #include <zephyr/sys/libc-hooks.h>
11 
arch_printk_char_out(int _c)12 int arch_printk_char_out(int _c)
13 {
14 	semihost_poll_out((char)_c);
15 	return 0;
16 }
17 
semihost_console_init(void)18 static int semihost_console_init(void)
19 {
20 	/*
21 	 * The printk output callback is arch_printk_char_out by default and
22 	 * is installed at link time. That makes printk() usable very early.
23 	 *
24 	 * We still need to install the stdout callback manually at run time.
25 	 */
26 	__stdout_hook_install(arch_printk_char_out);
27 
28 	return 0;
29 }
30 
31 SYS_INIT(semihost_console_init, PRE_KERNEL_1, CONFIG_CONSOLE_INIT_PRIORITY);
32