1 /* Copyright 2018 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #include <metal/uart.h>
5 #include <metal/machine.h>
7 #if defined(__METAL_DT_STDOUT_UART_HANDLE)
8 /* This implementation serves as a small shim that interfaces with the first
10 int metal_tty_putc(unsigned char c)
13 int out = metal_uart_putc(__METAL_DT_STDOUT_UART_HANDLE, '\r');
17 return metal_uart_putc(__METAL_DT_STDOUT_UART_HANDLE, c);
20 #ifndef __METAL_DT_STDOUT_UART_BAUD
21 #define __METAL_DT_STDOUT_UART_BAUD 115200
24 static void metal_tty_init(void) __attribute__((constructor));
25 static void metal_tty_init(void)
27 metal_uart_init(__METAL_DT_STDOUT_UART_HANDLE, __METAL_DT_STDOUT_UART_BAUD);
30 /* This implementation of putc doesn't actually do anything, it's just there to
31 * provide a shim that eats all the characters so we can ensure that everything
32 * can link to metal_tty_putc. */
33 int nop_putc(unsigned char c) __attribute__((section(".text.metal.nop.putc")));
34 int nop_putc(unsigned char c) { return -1; }
35 int metal_tty_putc(unsigned char c) __attribute__((weak, alias("nop_putc")));
36 #warning "There is no default output device, metal_tty_putc() will throw away all input."