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/8xx_immap.h>
16 #include <asm/mpc8xx.h>
19 extern void xmon_printf(const char *fmt
, ...);
20 extern int xmon_8xx_write(char *str
, int nb
);
21 extern int xmon_8xx_read_poll(void);
22 extern int xmon_8xx_read_char(void);
23 void prom_drawhex(uint
);
24 void prom_drawstring(const char *str
);
26 static int use_screen
= 1; /* default */
28 #define TB_SPEED 25000000
30 static inline unsigned int readtb(void)
34 asm volatile("mftb %0" : "=r" (ret
) :);
46 cpmp
= (cpm8xx_t
*)&(((immap_t
*)IMAP_ADDR
)->im_cpm
);
49 prom_drawstring("xmon uses serial port\n");
52 static int scc_initialized
= 0;
54 void xmon_init_scc(void);
57 xmon_write(void *handle
, void *ptr
, int nb
)
65 return(xmon_8xx_write(ptr
, nb
));
71 xmon_read(void *handle
, void *ptr
, int nb
)
79 for (i
= 0; i
< nb
; ++i
) {
80 *p
++ = xmon_8xx_read_char();
88 return(xmon_8xx_read_poll());
98 extern int (*prom_entry
)(void *);
108 args
.service
= "exit";
109 (*prom_entry
)(&args
);
124 xmon_putc(int c
, void *f
)
130 return xmon_write(f
, &ch
, 1) == 1? c
: -1;
136 return xmon_putc(c
, xmon_stdout
);
140 xmon_fputs(char *str
, void *f
)
144 return xmon_write(f
, str
, n
) == n
? 0: -1;
153 switch (xmon_read(xmon_stdin
, &ch
, 1)) {
157 xmon_printf("read(stdin) returned -1\r\n", 0, 0);
163 static char line
[256];
164 static char *lineptr
;
168 int xmon_expect(const char *str
, unsigned int timeout
)
178 c
= xmon_read_poll();
180 if (readtb() - t0
> timeout
)
186 if (c
!= '\r' && lineptr
< &line
[sizeof(line
) - 1])
190 } while (strstr(line
, str
) == NULL
);
204 if (c
== -1 || c
== 4)
206 if (c
== '\r' || c
== '\n') {
214 if (lineptr
> line
) {
222 while (lineptr
> line
) {
230 if (lineptr
>= &line
[sizeof(line
) - 1])
238 lineleft
= lineptr
- line
;
248 xmon_fgets(char *str
, int nb
, void *f
)
253 for (p
= str
; p
< str
+ nb
- 1; ) {
269 prom_drawhex(uint val
)
271 unsigned char buf
[10];
274 for (i
= 7; i
>= 0; i
--)
276 buf
[i
] = "0123456789abcdef"[val
& 0x0f];
280 xmon_fputs(buf
, xmon_stdout
);
284 prom_drawstring(const char *str
)
286 xmon_fputs(str
, xmon_stdout
);