1 /* 2 * Copyright 2007, François Revol, revol@free.fr. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de. 6 * Distributed under the terms of the MIT License. 7 * 8 * Copyright 2001, Travis Geiselbrecht. All rights reserved. 9 * Distributed under the terms of the NewOS License. 10 */ 11 12 13 #include <arch/debug_console.h> 14 #include <arch/generic/debug_uart.h> 15 #include <arch/generic/debug_uart_8250.h> 16 #include <arch/arm/arch_uart_8250_omap.h> 17 #include <arch/arm/arch_uart_pl011.h> 18 #include <boot/kernel_args.h> 19 #include <kernel.h> 20 #include <vm/vm.h> 21 #include <string.h> 22 23 24 static DebugUART *sArchDebugUART = NULL; 25 26 27 void 28 arch_debug_remove_interrupt_handler(uint32 line) 29 { 30 } 31 32 33 void 34 arch_debug_install_interrupt_handlers(void) 35 { 36 } 37 38 39 int 40 arch_debug_blue_screen_try_getchar(void) 41 { 42 // TODO: Implement correctly! 43 return arch_debug_blue_screen_getchar(); 44 } 45 46 47 char 48 arch_debug_blue_screen_getchar(void) 49 { 50 return arch_debug_serial_getchar(); 51 } 52 53 54 int 55 arch_debug_serial_try_getchar(void) 56 { 57 // TODO: Implement correctly! 58 return arch_debug_serial_getchar(); 59 } 60 61 62 char 63 arch_debug_serial_getchar(void) 64 { 65 if (sArchDebugUART == NULL) 66 return NULL; 67 68 return sArchDebugUART->GetChar(false); 69 } 70 71 72 void 73 arch_debug_serial_putchar(const char c) 74 { 75 if (sArchDebugUART == NULL) 76 return; 77 78 sArchDebugUART->PutChar(c); 79 } 80 81 82 void 83 arch_debug_serial_puts(const char *s) 84 { 85 while (*s != '\0') { 86 arch_debug_serial_putchar(*s); 87 s++; 88 } 89 } 90 91 92 void 93 arch_debug_serial_early_boot_message(const char *string) 94 { 95 // this function will only be called in fatal situations 96 arch_debug_serial_puts(string); 97 } 98 99 100 status_t 101 arch_debug_console_init(kernel_args *args) 102 { 103 if (strncmp(args->arch_args.uart.kind, UART_KIND_PL011, 104 sizeof(args->arch_args.uart.kind)) == 0) { 105 sArchDebugUART = arch_get_uart_pl011(args->arch_args.uart.regs.start, 106 args->arch_args.uart.clock); 107 } else if (strncmp(args->arch_args.uart.kind, UART_KIND_8250_OMAP, 108 sizeof(args->arch_args.uart.kind)) == 0) { 109 sArchDebugUART = arch_get_uart_8250_omap(args->arch_args.uart.regs.start, 110 args->arch_args.uart.clock); 111 } else if (strncmp(args->arch_args.uart.kind, UART_KIND_8250, 112 sizeof(args->arch_args.uart.kind)) == 0) { 113 sArchDebugUART = arch_get_uart_8250(args->arch_args.uart.regs.start, 114 args->arch_args.uart.clock); 115 } 116 117 // As a last try, lets assume qemu's pl011 at a sane address 118 if (sArchDebugUART == NULL) 119 sArchDebugUART = arch_get_uart_pl011(0x9000000, 0x16e3600); 120 121 // Oh well. 122 if (sArchDebugUART == NULL) 123 return B_ERROR; 124 125 sArchDebugUART->InitEarly(); 126 127 return B_OK; 128 } 129 130 131 status_t 132 arch_debug_console_init_settings(kernel_args *args) 133 { 134 return B_OK; 135 } 136