aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/xmon/nonstdio.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/xmon/nonstdio.c')
-rw-r--r--arch/powerpc/xmon/nonstdio.c53
1 files changed, 23 insertions, 30 deletions
diff --git a/arch/powerpc/xmon/nonstdio.c b/arch/powerpc/xmon/nonstdio.c
index bfac84fbe780..bce3dcfe5058 100644
--- a/arch/powerpc/xmon/nonstdio.c
+++ b/arch/powerpc/xmon/nonstdio.c
@@ -7,9 +7,23 @@
7 * 2 of the License, or (at your option) any later version. 7 * 2 of the License, or (at your option) any later version.
8 */ 8 */
9#include <linux/string.h> 9#include <linux/string.h>
10#include <asm/udbg.h>
10#include <asm/time.h> 11#include <asm/time.h>
11#include "nonstdio.h" 12#include "nonstdio.h"
12 13
14
15static int xmon_write(const void *ptr, int nb)
16{
17 return udbg_write(ptr, nb);
18}
19
20static int xmon_readchar(void)
21{
22 if (udbg_getc)
23 return udbg_getc();
24 return -1;
25}
26
13int xmon_putchar(int c) 27int xmon_putchar(int c)
14{ 28{
15 char ch = c; 29 char ch = c;
@@ -23,34 +37,7 @@ static char line[256];
23static char *lineptr; 37static char *lineptr;
24static int lineleft; 38static int lineleft;
25 39
26int xmon_expect(const char *str, unsigned long timeout) 40static int xmon_getchar(void)
27{
28 int c;
29 unsigned long t0;
30
31 /* assume 25MHz default timebase if tb_ticks_per_sec not set yet */
32 timeout *= tb_ticks_per_sec? tb_ticks_per_sec: 25000000;
33 t0 = get_tbl();
34 do {
35 lineptr = line;
36 for (;;) {
37 c = xmon_read_poll();
38 if (c == -1) {
39 if (get_tbl() - t0 > timeout)
40 return 0;
41 continue;
42 }
43 if (c == '\n')
44 break;
45 if (c != '\r' && lineptr < &line[sizeof(line) - 1])
46 *lineptr++ = c;
47 }
48 *lineptr = 0;
49 } while (strstr(line, str) == NULL);
50 return 1;
51}
52
53int xmon_getchar(void)
54{ 41{
55 int c; 42 int c;
56 43
@@ -124,13 +111,19 @@ char *xmon_gets(char *str, int nb)
124void xmon_printf(const char *format, ...) 111void xmon_printf(const char *format, ...)
125{ 112{
126 va_list args; 113 va_list args;
127 int n;
128 static char xmon_outbuf[1024]; 114 static char xmon_outbuf[1024];
115 int rc, n;
129 116
130 va_start(args, format); 117 va_start(args, format);
131 n = vsnprintf(xmon_outbuf, sizeof(xmon_outbuf), format, args); 118 n = vsnprintf(xmon_outbuf, sizeof(xmon_outbuf), format, args);
132 va_end(args); 119 va_end(args);
133 xmon_write(xmon_outbuf, n); 120
121 rc = xmon_write(xmon_outbuf, n);
122
123 if (n && rc == 0) {
124 /* No udbg hooks, fallback to printk() - dangerous */
125 printk(xmon_outbuf);
126 }
134} 127}
135 128
136void xmon_puts(const char *str) 129void xmon_puts(const char *str)