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/device.h> 9 #include <zephyr/init.h> 10 11 #if defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE) 12 /** 13 * @brief Output one character to SIMULATOR console 14 * @param c Character to output 15 * @return The character passed as input. 16 */ console_out(int c)17static int console_out(int c) 18 { 19 register unsigned long x0 __asm__("x0") = 8; 20 register unsigned long x1 __asm__("x1") = c; 21 22 __asm__ volatile ("hvc #0x4a48\r\n" 23 : "+r" (x0), "+r" (x1) : : ); 24 return c; 25 } 26 #endif 27 28 #if defined(CONFIG_STDOUT_CONSOLE) 29 extern void __stdout_hook_install(int (*hook)(int)); 30 #else 31 #define __stdout_hook_install(x) \ 32 do {/* nothing */ \ 33 } while ((0)) 34 #endif 35 36 #if defined(CONFIG_PRINTK) 37 extern void __printk_hook_install(int (*fn)(int)); 38 #else 39 #define __printk_hook_install(x) \ 40 do {/* nothing */ \ 41 } while ((0)) 42 #endif 43 44 /** 45 * @brief Initialize the console/debug port 46 * @return 0 if successful, otherwise failed. 47 */ jailhouse_console_init(void)48static int jailhouse_console_init(void) 49 { 50 __stdout_hook_install(console_out); 51 __printk_hook_install(console_out); 52 return 0; 53 } 54 55 SYS_INIT(jailhouse_console_init, 56 PRE_KERNEL_1, 57 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); 58