1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #include <metal/uart.h>
6 #include <metal/machine.h>
8 #if defined(__METAL_DT_STDOUT_UART_HANDLE)
9 /* This implementation serves as a small shim that interfaces with the first
10 * UART on a system. */
11 int metal_tty_putc(int c)
14 metal_tty_putc_raw( '\r' );
16 return metal_tty_putc_raw( c );
19 int metal_tty_putc_raw(int c)
21 return metal_uart_putc(__METAL_DT_STDOUT_UART_HANDLE, c);
24 int metal_tty_getc(int *c)
27 metal_uart_getc( __METAL_DT_STDOUT_UART_HANDLE, c );
28 /* -1 means no key pressed, getc waits */
34 #ifndef __METAL_DT_STDOUT_UART_BAUD
35 #define __METAL_DT_STDOUT_UART_BAUD 115200
38 static void metal_tty_init(void) __attribute__((constructor));
39 static void metal_tty_init(void)
41 metal_uart_init(__METAL_DT_STDOUT_UART_HANDLE, __METAL_DT_STDOUT_UART_BAUD);
44 /* This implementation of putc doesn't actually do anything, it's just there to
45 * provide a shim that eats all the characters so we can ensure that everything
46 * can link to metal_tty_putc. */
47 int nop_putc(int c) __attribute__((section(".text.metal.nop.putc")));
48 int nop_putc(int c) { return -1; }
49 int metal_tty_putc(int c) __attribute__((weak, alias("nop_putc")));
50 #pragma message("There is no default output device, metal_tty_putc() will throw away all input.")