1 /*
2  * Copyright 2022 NXP
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #include <zephyr/kernel.h>
7 #include <zephyr/sys/printk.h>
8 #include <zephyr/sys/printk-hooks.h>
9 #include <zephyr/sys/libc-hooks.h>
10 #include <zephyr/device.h>
11 #include <zephyr/init.h>
12 
13 #if defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE)
14 /**
15  * @brief Output one character to SIMULATOR console
16  * @param c Character to output
17  * @return The character passed as input.
18  */
console_out(int c)19 static int console_out(int c)
20 {
21 	register unsigned long x0 __asm__("x0") = 8;
22 	register unsigned long x1 __asm__("x1") = c;
23 
24 	__asm__ volatile ("hvc #0x4a48\r\n"
25 			  : "+r" (x0), "+r" (x1) : : );
26 	return c;
27 }
28 #endif
29 
30 /**
31  * @brief Initialize the console/debug port
32  * @return 0 if successful, otherwise failed.
33  */
jailhouse_console_init(void)34 static int jailhouse_console_init(void)
35 {
36 #if defined(CONFIG_STDOUT_CONSOLE)
37 	__stdout_hook_install(console_out);
38 #endif
39 #if defined(CONFIG_PRINTK)
40 	__printk_hook_install(console_out);
41 #endif
42 	return 0;
43 }
44 
45 SYS_INIT(jailhouse_console_init,
46 	 PRE_KERNEL_1,
47 	 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
48