2 * Copyright (C) 1996 Paul Mackerras.
3 * Copyright (C) 2000 Dan Malek.
4 * Quick hack of Paul's code to make XMON work on 8xx processors. Lots
5 * of assumptions, like the SMC1 is used, it has been initialized by the
6 * loader at some point, and we can just stuff and suck bytes.
7 * We rely upon the 8xx uart driver to support us, as the interface
8 * changes between boot up and operational phases of the kernel.
10 #include <linux/string.h>
11 #include <asm/machdep.h>
14 #include <linux/kernel.h>
15 #include <asm/processor.h>
16 #include <asm/8xx_immap.h>
17 #include <asm/mpc8xx.h>
18 #include <asm/commproc.h>
20 extern void xmon_printf(const char *fmt, ...);
21 extern int xmon_8xx_write(char *str, int nb);
22 extern int xmon_8xx_read_poll(void);
23 extern int xmon_8xx_read_char(void);
24 void prom_drawhex(uint);
25 void prom_drawstring(const char *str);
27 static int use_screen = 1; /* default */
29 #define TB_SPEED 25000000
31 static inline unsigned int readtb(void)
35 asm volatile("mftb %0" : "=r" (ret) :);
47 cpmp = (cpm8xx_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
50 prom_drawstring("xmon uses serial port\n");
53 static int scc_initialized = 0;
55 void xmon_init_scc(void);
58 xmon_write(void *handle, void *ptr, int nb)
66 return(xmon_8xx_write(ptr, nb));
72 xmon_read(void *handle, void *ptr, int nb)
80 for (i = 0; i < nb; ++i) {
81 *p++ = xmon_8xx_read_char();
89 return(xmon_8xx_read_poll());
99 extern int (*prom_entry)(void *);
109 args.service = "exit";
110 (*prom_entry)(&args);
125 xmon_putc(int c, void *f)
131 return xmon_write(f, &ch, 1) == 1? c: -1;
137 return xmon_putc(c, xmon_stdout);
141 xmon_fputs(char *str, void *f)
145 return xmon_write(f, str, n) == n? 0: -1;
154 switch (xmon_read(xmon_stdin, &ch, 1)) {
158 xmon_printf("read(stdin) returned -1\r\n", 0, 0);
164 static char line[256];
165 static char *lineptr;
169 int xmon_expect(const char *str, unsigned int timeout)
179 c = xmon_read_poll();
181 if (readtb() - t0 > timeout)
187 if (c != '\r' && lineptr < &line[sizeof(line) - 1])
191 } while (strstr(line, str) == NULL);
205 if (c == -1 || c == 4)
207 if (c == '\r' || c == '\n') {
215 if (lineptr > line) {
223 while (lineptr > line) {
231 if (lineptr >= &line[sizeof(line) - 1])
239 lineleft = lineptr - line;
249 xmon_fgets(char *str, int nb, void *f)
254 for (p = str; p < str + nb - 1; ) {
270 prom_drawhex(uint val)
272 unsigned char buf[10];
275 for (i = 7; i >= 0; i--)
277 buf[i] = "0123456789abcdef"[val & 0x0f];
281 xmon_fputs(buf, xmon_stdout);
285 prom_drawstring(const char *str)
287 xmon_fputs(str, xmon_stdout);