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 <stdio.h>
11 #include <kernel/thread.h>
12 #include <dev/uart.h>
13 #include <platform/debug.h>
14 #include <platform/qemu-virt.h>
15 #include <target/debugconfig.h>
16 #include <lk/reg.h>
17 
18 /* DEBUG_UART must be defined to 0 or 1 */
19 #if defined(DEBUG_UART) && DEBUG_UART == 0
20 #define DEBUG_UART_BASE UART0_BASE
21 #elif defined(DEBUG_UART) && DEBUG_UART == 1
22 #define DEBUG_UART_BASE UART1_BASE
23 #else
24 #error define DEBUG_UART to something valid
25 #endif
26 
platform_dputc(char c)27 void platform_dputc(char c) {
28     if (c == '\n')
29         uart_putc(DEBUG_UART, '\r');
30     uart_putc(DEBUG_UART, c);
31 }
32 
platform_dgetc(char * c,bool wait)33 int platform_dgetc(char *c, bool wait) {
34     int ret = uart_getc(DEBUG_UART, wait);
35     if (ret == -1)
36         return -1;
37     *c = ret;
38     return 0;
39 }
40 
platform_pputc(char c)41 void platform_pputc(char c) {
42     if (c == '\n')
43         uart_pputc(DEBUG_UART, '\r');
44     uart_pputc(DEBUG_UART, c);
45 }
46 
platform_pgetc(char * c,bool wait)47 int platform_pgetc(char *c, bool wait) {
48     int ret = uart_pgetc(DEBUG_UART);
49     if (ret < 0)
50         return ret;
51     *c = ret;
52     return 0;
53 }
54 
55