1 /*
2  * Copyright (c) 2008-2014 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <stdarg.h>
9 #include <lk/reg.h>
10 #include <kernel/thread.h>
11 #include <dev/uart.h>
12 #include <platform/debug.h>
13 #include <platform/qemu-virt.h>
14 #include <target/debugconfig.h>
15 
16 /* DEBUG_UART must be defined to 0 or 1 */
17 #if defined(DEBUG_UART) && DEBUG_UART == 0
18 #define DEBUG_UART_BASE UART0_BASE
19 #elif defined(DEBUG_UART) && DEBUG_UART == 1
20 #define DEBUG_UART_BASE UART1_BASE
21 #else
22 #error define DEBUG_UART to something valid
23 #endif
24 
platform_dputc(char c)25 void platform_dputc(char c) {
26     if (c == '\n')
27         uart_putc(DEBUG_UART, '\r');
28     uart_putc(DEBUG_UART, c);
29 }
30 
platform_dgetc(char * c,bool wait)31 int platform_dgetc(char *c, bool wait) {
32     int ret = uart_getc(DEBUG_UART, wait);
33     if (ret < 0)
34         return ret;
35     *c = ret;
36     return 0;
37 }
38 
platform_pputc(char c)39 void platform_pputc(char c) {
40     if (c == '\n')
41         uart_pputc(DEBUG_UART, '\r');
42     uart_pputc(DEBUG_UART, c);
43 }
44 
platform_pgetc(char * c,bool wait)45 int platform_pgetc(char *c, bool wait) {
46     int ret = uart_pgetc(DEBUG_UART);
47     if (ret < 0)
48         return ret;
49     *c = ret;
50     return 0;
51 }
52 
53