]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7f853352 | 2 | * polling mode stateless debugging stuff, originally for NS16550 Serial Ports |
1da177e4 LT |
3 | * |
4 | * c 2001 PPC 64 Team, IBM Corp | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the License, or (at your option) any later version. | |
10 | */ | |
11 | ||
12 | #include <stdarg.h> | |
1da177e4 LT |
13 | #include <linux/config.h> |
14 | #include <linux/types.h> | |
188d2ce7 | 15 | #include <linux/sched.h> |
8d927391 | 16 | #include <linux/console.h> |
1da177e4 | 17 | #include <asm/processor.h> |
1da177e4 | 18 | |
51d3082f | 19 | void (*udbg_putc)(char c); |
bb6b9b28 | 20 | int (*udbg_getc)(void); |
c8f1c8be MM |
21 | int (*udbg_getc_poll)(void); |
22 | ||
8d927391 | 23 | /* udbg library, used by xmon et al */ |
1da177e4 LT |
24 | void udbg_puts(const char *s) |
25 | { | |
c8f1c8be | 26 | if (udbg_putc) { |
1da177e4 LT |
27 | char c; |
28 | ||
29 | if (s && *s != '\0') { | |
30 | while ((c = *s++) != '\0') | |
c8f1c8be | 31 | udbg_putc(c); |
1da177e4 LT |
32 | } |
33 | } | |
34 | #if 0 | |
35 | else { | |
36 | printk("%s", s); | |
37 | } | |
38 | #endif | |
39 | } | |
40 | ||
41 | int udbg_write(const char *s, int n) | |
42 | { | |
43 | int remain = n; | |
44 | char c; | |
45 | ||
c8f1c8be | 46 | if (!udbg_putc) |
1da177e4 LT |
47 | return 0; |
48 | ||
49 | if (s && *s != '\0') { | |
50 | while (((c = *s++) != '\0') && (remain-- > 0)) { | |
c8f1c8be | 51 | udbg_putc(c); |
1da177e4 LT |
52 | } |
53 | } | |
54 | ||
55 | return n - remain; | |
56 | } | |
57 | ||
58 | int udbg_read(char *buf, int buflen) | |
59 | { | |
bb6b9b28 BH |
60 | char *p = buf; |
61 | int i, c; | |
1da177e4 | 62 | |
c8f1c8be | 63 | if (!udbg_getc) |
1da177e4 LT |
64 | return 0; |
65 | ||
66 | for (i = 0; i < buflen; ++i) { | |
67 | do { | |
c8f1c8be | 68 | c = udbg_getc(); |
bb6b9b28 BH |
69 | if (c == -1 && i == 0) |
70 | return -1; | |
71 | ||
1da177e4 | 72 | } while (c == 0x11 || c == 0x13); |
bb6b9b28 | 73 | if (c == 0 || c == -1) |
1da177e4 LT |
74 | break; |
75 | *p++ = c; | |
76 | } | |
77 | ||
78 | return i; | |
79 | } | |
80 | ||
1da177e4 LT |
81 | #define UDBG_BUFSIZE 256 |
82 | void udbg_printf(const char *fmt, ...) | |
83 | { | |
51d3082f | 84 | char buf[UDBG_BUFSIZE]; |
1da177e4 LT |
85 | va_list args; |
86 | ||
87 | va_start(args, fmt); | |
88 | vsnprintf(buf, UDBG_BUFSIZE, fmt, args); | |
89 | udbg_puts(buf); | |
90 | va_end(args); | |
91 | } | |
92 | ||
8d927391 MM |
93 | /* |
94 | * Early boot console based on udbg | |
95 | */ | |
96 | static void udbg_console_write(struct console *con, const char *s, | |
97 | unsigned int n) | |
98 | { | |
99 | udbg_write(s, n); | |
100 | } | |
101 | ||
102 | static struct console udbg_console = { | |
103 | .name = "udbg", | |
104 | .write = udbg_console_write, | |
463ce0e1 | 105 | .flags = CON_PRINTBUFFER | CON_ENABLED, |
8d927391 MM |
106 | .index = -1, |
107 | }; | |
108 | ||
38c0ff06 SR |
109 | static int early_console_initialized; |
110 | ||
8d927391 MM |
111 | void __init disable_early_printk(void) |
112 | { | |
38c0ff06 SR |
113 | if (!early_console_initialized) |
114 | return; | |
8d927391 | 115 | unregister_console(&udbg_console); |
38c0ff06 | 116 | early_console_initialized = 0; |
8d927391 MM |
117 | } |
118 | ||
119 | /* called by setup_system */ | |
120 | void register_early_udbg_console(void) | |
121 | { | |
51d3082f BH |
122 | if (early_console_initialized) |
123 | return; | |
38c0ff06 | 124 | early_console_initialized = 1; |
8d927391 MM |
125 | register_console(&udbg_console); |
126 | } | |
127 | ||
128 | #if 0 /* if you want to use this as a regular output console */ | |
129 | console_initcall(register_udbg_console); | |
130 | #endif |