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
24static DebugUART *sArchDebugUART = NULL;
25
26
27void
28arch_debug_remove_interrupt_handler(uint32 line)
29{
30}
31
32
33void
34arch_debug_install_interrupt_handlers(void)
35{
36}
37
38
39int
40arch_debug_blue_screen_try_getchar(void)
41{
42	// TODO: Implement correctly!
43	return arch_debug_blue_screen_getchar();
44}
45
46
47char
48arch_debug_blue_screen_getchar(void)
49{
50	return arch_debug_serial_getchar();
51}
52
53
54int
55arch_debug_serial_try_getchar(void)
56{
57	// TODO: Implement correctly!
58	return arch_debug_serial_getchar();
59}
60
61
62char
63arch_debug_serial_getchar(void)
64{
65	if (sArchDebugUART == NULL)
66		return NULL;
67
68	return sArchDebugUART->GetChar(false);
69}
70
71
72void
73arch_debug_serial_putchar(const char c)
74{
75	if (sArchDebugUART == NULL)
76		return;
77
78	sArchDebugUART->PutChar(c);
79}
80
81
82void
83arch_debug_serial_puts(const char *s)
84{
85	while (*s != '\0') {
86		char ch = *s;
87		if (ch == '\n') {
88			arch_debug_serial_putchar('\r');
89			arch_debug_serial_putchar('\n');
90		} else if (ch != '\r')
91			arch_debug_serial_putchar(ch);
92		s++;
93	}
94}
95
96
97void
98arch_debug_serial_early_boot_message(const char *string)
99{
100	// this function will only be called in fatal situations
101	arch_debug_serial_puts(string);
102}
103
104
105status_t
106arch_debug_console_init(kernel_args *args)
107{
108	if (strncmp(args->arch_args.uart.kind, UART_KIND_PL011,
109		sizeof(args->arch_args.uart.kind)) == 0) {
110		sArchDebugUART = arch_get_uart_pl011(args->arch_args.uart.regs.start,
111			args->arch_args.uart.clock);
112	} else if (strncmp(args->arch_args.uart.kind, UART_KIND_8250_OMAP,
113		sizeof(args->arch_args.uart.kind)) == 0) {
114		sArchDebugUART = arch_get_uart_8250_omap(args->arch_args.uart.regs.start,
115			args->arch_args.uart.clock);
116	} else if (strncmp(args->arch_args.uart.kind, UART_KIND_8250,
117		sizeof(args->arch_args.uart.kind)) == 0) {
118		sArchDebugUART = arch_get_uart_8250(args->arch_args.uart.regs.start,
119			args->arch_args.uart.clock);
120	}
121
122	// As a last try, lets assume qemu's pl011 at a sane address
123	if (sArchDebugUART == NULL)
124		sArchDebugUART = arch_get_uart_pl011(0x9000000, 0x16e3600);
125
126	// Oh well.
127	if (sArchDebugUART == NULL)
128		return B_ERROR;
129
130	sArchDebugUART->InitEarly();
131
132	return B_OK;
133}
134
135
136status_t
137arch_debug_console_init_settings(kernel_args *args)
138{
139	return B_OK;
140}
141