1/* 2 * Copyright 2003-2006, Axel D��rfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2001, Travis Geiselbrecht. All rights reserved. 6 * Distributed under the terms of the NewOS License. 7 */ 8 9 10#include <arch/debug_console.h> 11#include <arch/generic/debug_uart.h> 12#include <arch/generic/debug_uart_8250.h> 13#include <arch/riscv64/arch_uart_sifive.h> 14#include <boot/kernel_args.h> 15#include <kernel.h> 16#include <vm/vm.h> 17#include <Htif.h> 18 19#include <string.h> 20 21 22static DebugUART* sArchDebugUART = NULL; 23 24 25void 26arch_debug_remove_interrupt_handler(uint32 line) 27{ 28} 29 30 31void 32arch_debug_install_interrupt_handlers(void) 33{ 34} 35 36 37int 38arch_debug_blue_screen_try_getchar(void) 39{ 40 return 0; 41} 42 43 44char 45arch_debug_blue_screen_getchar(void) 46{ 47 return 0; 48} 49 50 51int 52arch_debug_serial_try_getchar(void) 53{ 54 // TODO: Implement correctly! 55 return arch_debug_serial_getchar(); 56} 57 58 59char 60arch_debug_serial_getchar(void) 61{ 62 if (sArchDebugUART != NULL) 63 return sArchDebugUART->GetChar(false); 64 65 return 0; 66} 67 68 69void 70arch_debug_serial_putchar(const char c) 71{ 72 if (sArchDebugUART != NULL) { 73 sArchDebugUART->PutChar(c); 74 return; 75 } 76 77 HtifOutChar(c); 78} 79 80 81void 82arch_debug_serial_puts(const char *s) 83{ 84 while (*s != '\0') { 85 char ch = *s; 86 if (ch == '\n') { 87 arch_debug_serial_putchar('\r'); 88 arch_debug_serial_putchar('\n'); 89 } else if (ch != '\r') 90 arch_debug_serial_putchar(ch); 91 s++; 92 } 93} 94 95 96void 97arch_debug_serial_early_boot_message(const char *string) 98{ 99 arch_debug_serial_puts(string); 100} 101 102 103status_t 104arch_debug_console_init(kernel_args *args) 105{ 106 if (strncmp(args->arch_args.uart.kind, UART_KIND_8250, 107 sizeof(args->arch_args.uart.kind)) == 0) { 108 sArchDebugUART = arch_get_uart_8250(args->arch_args.uart.regs.start, 109 args->arch_args.uart.clock); 110 } else if (strncmp(args->arch_args.uart.kind, UART_KIND_SIFIVE, 111 sizeof(args->arch_args.uart.kind)) == 0) { 112 sArchDebugUART = arch_get_uart_sifive(args->arch_args.uart.regs.start, 113 args->arch_args.uart.clock); 114 } 115 116 if (sArchDebugUART != NULL) 117 sArchDebugUART->InitEarly(); 118 119 return B_OK; 120} 121 122 123status_t 124arch_debug_console_init_settings(kernel_args *args) 125{ 126 return B_OK; 127} 128