2 * Copyright (C) 1996-2005 Paul Mackerras.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 #include <linux/string.h>
13 int xmon_putchar(int c
)
19 return xmon_write(&ch
, 1) == 1? c
: -1;
22 static char line
[256];
26 int xmon_expect(const char *str
, unsigned long timeout
)
31 /* assume 25MHz default timebase if tb_ticks_per_sec not set yet */
32 timeout
*= tb_ticks_per_sec
? tb_ticks_per_sec
: 25000000;
39 if (get_tbl() - t0
> timeout
)
45 if (c
!= '\r' && lineptr
< &line
[sizeof(line
) - 1])
49 } while (strstr(line
, str
) == NULL
);
53 int xmon_getchar(void)
61 if (c
== -1 || c
== 4)
63 if (c
== '\r' || c
== '\n') {
79 while (lineptr
> line
) {
87 if (lineptr
>= &line
[sizeof(line
) - 1])
95 lineleft
= lineptr
- line
;
104 char *xmon_gets(char *str
, int nb
)
109 for (p
= str
; p
< str
+ nb
- 1; ) {
124 void xmon_printf(const char *format
, ...)
128 static char xmon_outbuf
[1024];
130 va_start(args
, format
);
131 n
= vsnprintf(xmon_outbuf
, sizeof(xmon_outbuf
), format
, args
);
133 xmon_write(xmon_outbuf
, n
);
136 void xmon_puts(const char *str
)
138 xmon_write(str
, strlen(str
));